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
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions elekto/assets/scss/components/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@
&__footer {
position: absolute;
bottom: 0;
width: $sidebar-width;
text-align: center;
color: #a8a8a8;
font-weight: 300;
font-size: 10px;
padding-bottom: 10px;
&_version {
position: absolute;
bottom: 0;
right: 0;
padding-bottom: 10px;
font-weight: bold;
}
}

&-active {
Expand Down
19 changes: 17 additions & 2 deletions elekto/controllers/elections.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import secrets
import string
import flask as F
import subprocess

from nacl import utils, pwhash

Expand All @@ -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():
Expand All @@ -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();
return F.render_template("views/elections/index.html", elections=res, status=status,version=version)


@APP.route("/app/elections/<eid>") # Particular Election
Expand Down
2 changes: 1 addition & 1 deletion elekto/static/css/main.css

Large diffs are not rendered by default.

23 changes: 8 additions & 15 deletions elekto/templates/components/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,31 +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">copyright 2020 © elekto</div>
<div class="sidebar-item sidebar__footer_version">version: {{version}}</div>
</div>
117 changes: 66 additions & 51 deletions elekto/templates/layouts/app.html
Original file line number Diff line number Diff line change
@@ -1,56 +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);
}
</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>