
Now, when the application starts, only a blank page is shown. The home screen (summary graphs for all users) shows only after somebody logs in and out. With this change, the home screen is loaded automatically on the first start or on manual page reload. Together with this change, we split the home and user screens to separate templates (previously the home screen was the user screen with name unset). Hopefully, this change makes the UI logic a bit easier to follow. --- app.py | 20 +++++++++++--------- templates/home.html | 5 +++++ templates/main.js | 4 ++++ templates/user.html | 9 --------- 4 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 templates/home.html diff --git a/app.py b/app.py index cbdb9e9..64a39f6 100644 --- a/app.py +++ b/app.py @@ -83,12 +83,18 @@ app.jinja_env.filters['days'] = days_filter @app.route('/') def hello(): - if "uid" in session: - uid = session["uid"] - return render_template('hello.html', name=db.get_name(uid)) return render_template('hello.html') +@app.route('/home') +def home(): + # TODO: Replace stamp parameter with proper cache control HTTP + # headers in response + return render_template('home.html', + stamp=time.time(), + last_events=db.last_events()) + + @app.route('/login', methods=["POST"]) @app.route('/login/<iid>') def login(iid=None): @@ -112,7 +118,7 @@ def login(iid=None): def logout(): session.pop('uid', None) session.pop('iid', None) - return redirect(url_for('user')) + return redirect(url_for('home')) @app.route('/user') @@ -129,11 +135,7 @@ def user(): stamp=time.time(), last_events=db.last_events() ) - # TODO: Replace stamp parameter with proper cache control HTTP - # headers in response - return render_template('user.html', stamp=time.time(), - last_events=db.last_events(), - ) + return redirect(url_for('home')) @app.route('/user/rename') diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..48c0430 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,5 @@ + <p>Use your card/token to log in...</p> + + <img src="{{ url_for('coffee_graph_history', _external=True, stamp=stamp) }}"> + <img src="{{ url_for('coffee_graph_flavors', _external=True, stamp=stamp, days=7) }}"> + {% include "events.html" %} diff --git a/templates/main.js b/templates/main.js index 9cc11f5..0976a9e 100644 --- a/templates/main.js +++ b/templates/main.js @@ -106,6 +106,10 @@ function loadRemote(string) { replayOfflineQueue(); updateUI(); clearTimeout(reloadTimer); + if (id_user) + logout(); + else + ajax("GET", "home", "", "content"); // Load home screen on first load or reload } else { // Cancel current timer for the case when loadRemote() // was called multiple times (e.g. multiple ajax() diff --git a/templates/user.html b/templates/user.html index e10409a..28d6022 100644 --- a/templates/user.html +++ b/templates/user.html @@ -1,7 +1,6 @@ {###############} {# Graphs etc. #} {###############} -{% if name %} <form style="position: absolute; right: 15%; width: 15%; height: 15%;"> <button type="button" id="logout_button" onclick="logout()" style="width: 100%; height: 100%;">logout</button> </form> @@ -47,12 +46,6 @@ </form> {% endif %} </p> -{% else %} - <p>Use your card/token to log in...</p> - - <img src="{{ url_for('coffee_graph_history', _external=True, stamp=stamp) }}"> - <img src="{{ url_for('coffee_graph_flavors', _external=True, stamp=stamp, days=7) }}"> -{% endif %} {##########} {# Events #} @@ -63,7 +56,6 @@ {##################################} {# User name and chip idnetifiers #} {##################################} -{% if name %} <br /> <p> <form> @@ -92,4 +84,3 @@ </tr> </table> </form> -{% endif %} -- 2.28.0.rc2