-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: elekto version in UI #102
Open
Diwaz
wants to merge
3
commits into
elekto-io:main
Choose a base branch
from
Diwaz:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−71
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
update on getting UI version
now the current app version is fetched instead of latest version
commit a58647ab54d099f63070e15d892c56e740bc6ebc
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ | |||||
import secrets | ||||||
import string | ||||||
import flask as F | ||||||
import subprocess | ||||||
|
||||||
from nacl import utils, pwhash | ||||||
|
||||||
|
@@ -34,6 +35,20 @@ | |||||
from elekto.middlewares.election import * # noqa | ||||||
|
||||||
|
||||||
def get_version(): | ||||||
"""Retrieve the app version using `git describe --tags`.""" | ||||||
try: | ||||||
process = subprocess.Popen(['git', 'describe', '--tags'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||||||
stdout, stderr = process.communicate() | ||||||
|
||||||
if process.returncode != 0: | ||||||
return f"Error retrieving version: {stderr.strip()}" | ||||||
|
||||||
cleanVersion = stdout.strip().split('-')[0] | ||||||
return cleanVersion | ||||||
except Exception as e: | ||||||
return f"Exception occurred: {str(e)}" | ||||||
|
||||||
@APP.route("/app") | ||||||
@auth_guard | ||||||
def app(): | ||||||
|
@@ -50,8 +65,8 @@ def elections(): | |||||
meta.Election.all() if status is None else meta.Election.where("status", status) | ||||||
) | ||||||
res.sort(key=lambda e: e["start_datetime"], reverse=True) | ||||||
|
||||||
return F.render_template("views/elections/index.html", elections=res, status=status) | ||||||
version = get_version(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error is not caught |
||||||
return F.render_template("views/elections/index.html", elections=res, status=status,version=version) | ||||||
|
||||||
|
||||||
@APP.route("/app/elections/<eid>") # Particular Election | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,24 @@ | ||
<div class="sidebar border--right" id="sidebar"> | ||
<div class="sidebar__user border--bottom"> | ||
<!-- <img src="{{ g.user['avatar_url'] }}" alt="" srcset="" class="sidebar__user-img bordered"> --> | ||
<a href="https://github.com/{{ g.user.username }}"><h3 class="sidebar__user-title"> | ||
{{ g.user['name'] }} | ||
</h3></a> | ||
<a href="https://github.com/{{ g.user.username }}" | ||
><h3 class="sidebar__user-title">{{ g.user['name'] }}</h3></a | ||
> | ||
</div> | ||
<div class="sidebar-item"> | ||
<a href="{{ url_for('elections') }}"> | ||
<span> | ||
Explore Election | ||
</span> | ||
<span> Explore Election </span> | ||
</a> | ||
</div> | ||
<div class="sidebar-divider border--bottom mt-2rem"> | ||
<span> | ||
Past Elections | ||
</span> | ||
<span> Past Elections </span> | ||
</div> | ||
{% for e in g.past_elections %} | ||
<div class="sidebar-item"> | ||
<span> | ||
{{ e['name'] }} | ||
</span> | ||
<span> {{ e['name'] }} </span> | ||
</div> | ||
{% endfor %} | ||
|
||
<div class="sidebar-item sidebar__footer"> | ||
copyright 2020 © elekto | ||
</div> | ||
<div class="sidebar-item sidebar__footer_version"> | ||
version: x.x.x | ||
</div> | ||
<div class="sidebar-item sidebar__footer">copyright 2020 © elekto</div> | ||
<div class="sidebar-item sidebar__footer_version">version: {{version}}</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link | ||
rel="shortcut icon" | ||
href="{{ url_for('static', filename='favicon.ico') }}" | ||
/> | ||
<title>{% block title %}{% endblock %} | Elekto</title> | ||
<link | ||
rel="stylesheet" | ||
type="text/css" | ||
href="{{ url_for('static', filename='css/main.css') }}" | ||
/> | ||
</head> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}"> | ||
<title>{% block title %}{% endblock %} | Elekto</title> | ||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/main.css') }}"> | ||
</head> | ||
|
||
<body onload="onload()"> | ||
<section class="d-flex"> | ||
{% include "components/sidebar.html" %} | ||
<div class="content-container content-has-sidebar" id="content"> | ||
<nav class="nav"> | ||
<div> | ||
<a href="{{ url_for('app') }}" class="breadcrums">elekto ({{g.NAME}})</a> | ||
{% block breadcrums %}{% endblock %} | ||
</div> | ||
<div class=""> | ||
<a class="text-dark" href="{{ url_for('logout') }}">Logout</a> | ||
</div> | ||
</nav> | ||
<div class="content"> | ||
<section id="message"> | ||
<div class="space--sm"> | ||
{% for message in get_flashed_messages() %} | ||
<div class="flash">{{ message }}</div> | ||
{% endfor %} | ||
<body onload="onload()"> | ||
<section class="d-flex"> | ||
{% include "components/sidebar.html" %} | ||
<div class="content-container content-has-sidebar" id="content"> | ||
<nav class="nav"> | ||
<div> | ||
<a href="{{ url_for('app') }}" class="breadcrums" | ||
>elekto ({{g.NAME}})</a | ||
> | ||
{% block breadcrums %}{% endblock %} | ||
</div> | ||
</section> | ||
{% block content %}{% endblock %} | ||
<div class=""> | ||
<a class="text-dark" href="{{ url_for('logout') }}" | ||
>Logout</a | ||
> | ||
</div> | ||
</nav> | ||
<div class="content"> | ||
<section id="message"> | ||
<div class="space--sm"> | ||
{% for message in get_flashed_messages() %} | ||
<div class="flash">{{ message }}</div> | ||
{% endfor %} | ||
</div> | ||
</section> | ||
{% block content %}{% endblock %} | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" | ||
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" | ||
crossorigin="anonymous"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" | ||
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" | ||
crossorigin="anonymous"></script> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" | ||
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" | ||
crossorigin="anonymous"></script> | ||
<script> | ||
const onload = () => { | ||
setTimeout(() => { | ||
document.getElementById('message').hidden = true | ||
}, 10000); | ||
} | ||
document.addEventListener('DOMContentLoaded', function () { | ||
// Fetch the version from the Flask API | ||
fetch('https://api.github.com/repos/elekto-io/elekto/releases/latest') | ||
.then(response => response.json()) | ||
.then(data => { | ||
// Update the version in the sidebar | ||
const versionElement = document.querySelector('.sidebar__footer_version'); | ||
versionElement.textContent = `version: ${data.tag_name}`; | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching version:', error); | ||
const versionElement = document.getElementById('version'); | ||
versionElement.textContent = 'Version: Unavailable'; | ||
}); | ||
}); | ||
</script> | ||
{% block script %}{% endblock %} | ||
</body> | ||
|
||
</section> | ||
<script | ||
src="https://code.jquery.com/jquery-3.2.1.slim.min.js" | ||
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" | ||
crossorigin="anonymous" | ||
></script> | ||
<script | ||
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" | ||
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" | ||
crossorigin="anonymous" | ||
></script> | ||
<script | ||
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" | ||
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" | ||
crossorigin="anonymous" | ||
></script> | ||
<script> | ||
const onload = () => { | ||
setTimeout(() => { | ||
document.getElementById("message").hidden = true; | ||
}, 10000); | ||
}; | ||
</script> | ||
{% block script %}{% endblock %} | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will run the subprocess everytime rendering happens. This is not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you so much for the feedback ,iam new to open source contributions i should implement new static way to fetch the app version