Skip to content
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
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

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
Diwaz committed Nov 28, 2024
commit a58647ab54d099f63070e15d892c56e740bc6ebc
19 changes: 17 additions & 2 deletions elekto/controllers/elections.py
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)

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.

Copy link
Author

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

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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = get_version();
version = get_version()

Choose a reason for hiding this comment

The 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
26 changes: 8 additions & 18 deletions elekto/templates/components/sidebar.html
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>
132 changes: 66 additions & 66 deletions elekto/templates/layouts/app.html
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>