From 3efff2fa42c41cb6929742a1086aee201a6405a2 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 27 Jun 2020 00:30:48 -0700 Subject: [PATCH] js: Simplify auto-refresh page logic - Implement ability to refresh page at the framework level so that every page does not need to handle it. - Refresh after number of seconds specified in context of the view. Tests performed: - Trigger the following functions and ensure that page reload after 3 seconds during the running operation while it does refresh before and after the operation. - Diagnostics tests from the module. - Gitweb repository cloning. - Monkeysphere publish key to server. - OpenVPN setup. - Tor configuration update. - Manual software update. - App installation. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- .../diagnostics/templates/diagnostics.html | 19 ---------- plinth/modules/diagnostics/views.py | 6 ++-- .../gitweb/templates/gitweb_configure.html | 9 ----- plinth/modules/gitweb/views.py | 1 + .../monkeysphere/templates/monkeysphere.html | 13 ------- plinth/modules/monkeysphere/views.py | 3 +- plinth/modules/openvpn/templates/openvpn.html | 17 --------- plinth/modules/openvpn/views.py | 2 ++ plinth/modules/tor/templates/tor.html | 14 -------- plinth/modules/tor/views.py | 1 + .../templates/upgrades_configure.html | 14 -------- plinth/modules/upgrades/views.py | 1 + plinth/templates/base.html | 11 +++++- plinth/templates/setup.html | 25 ------------- plinth/views.py | 6 ++++ static/themes/default/js/main.js | 18 ++++++++++ static/themes/default/js/refresh.js | 36 ------------------- .../themes/default/js/refresh_immediately.js | 25 ------------- 18 files changed, 45 insertions(+), 176 deletions(-) delete mode 100644 static/themes/default/js/refresh.js delete mode 100644 static/themes/default/js/refresh_immediately.js diff --git a/plinth/modules/diagnostics/templates/diagnostics.html b/plinth/modules/diagnostics/templates/diagnostics.html index f2212c096..e87525db6 100644 --- a/plinth/modules/diagnostics/templates/diagnostics.html +++ b/plinth/modules/diagnostics/templates/diagnostics.html @@ -6,17 +6,6 @@ {% load i18n %} {% load static %} -{% block page_head %} - - {% if is_running %} - - {% endif %} - -{% endblock %} - - {% block configuration %} {% if not is_running %} @@ -61,11 +50,3 @@ {% endif %} {% endblock %} - - -{% block page_js %} - {% if is_running %} - - {% endif %} -{% endblock %} - diff --git a/plinth/modules/diagnostics/views.py b/plinth/modules/diagnostics/views.py index 9b441032e..0c81f7440 100644 --- a/plinth/modules/diagnostics/views.py +++ b/plinth/modules/diagnostics/views.py @@ -17,11 +17,13 @@ def index(request): if request.method == 'POST' and not diagnostics.running_task: diagnostics.start_task() + is_running = diagnostics.running_task is not None return TemplateResponse( request, 'diagnostics.html', { 'app_info': diagnostics.app.info, - 'is_running': diagnostics.running_task is not None, - 'results': diagnostics.current_results + 'is_running': is_running, + 'results': diagnostics.current_results, + 'refresh_page_sec': 3 if is_running else None }) diff --git a/plinth/modules/gitweb/templates/gitweb_configure.html b/plinth/modules/gitweb/templates/gitweb_configure.html index 888241a64..93813c452 100644 --- a/plinth/modules/gitweb/templates/gitweb_configure.html +++ b/plinth/modules/gitweb/templates/gitweb_configure.html @@ -82,12 +82,3 @@ {% endblock %} - - -{% block page_js %} - - {% if cloning %} - - {% endif %} - -{% endblock %} diff --git a/plinth/modules/gitweb/views.py b/plinth/modules/gitweb/views.py index 9affd6baf..26027579f 100644 --- a/plinth/modules/gitweb/views.py +++ b/plinth/modules/gitweb/views.py @@ -31,6 +31,7 @@ class GitwebAppView(views.AppView): repos = gitweb.app.get_repo_list() context['repos'] = repos context['cloning'] = any('clone_progress' in repo for repo in repos) + context['refresh_page_sec'] = 3 if context['cloning'] else None return context diff --git a/plinth/modules/monkeysphere/templates/monkeysphere.html b/plinth/modules/monkeysphere/templates/monkeysphere.html index 16647a098..76c170181 100644 --- a/plinth/modules/monkeysphere/templates/monkeysphere.html +++ b/plinth/modules/monkeysphere/templates/monkeysphere.html @@ -9,12 +9,6 @@ {% block page_head %} - {% if running %} - - {% endif %} -