From 4bff603d4fb63adde4fe84f67dea347658b8fdde Mon Sep 17 00:00:00 2001 From: Terrtia Date: Wed, 17 Apr 2019 14:39:29 +0200 Subject: [PATCH] chg: [settings UI] add background update progress --- bin/update-background.py | 1 + update/v1.4/Update-ARDB_Metadata.py | 2 + update/v1.4/Update-ARDB_Onions.py | 2 + update/v1.4/Update-ARDB_Tags.py | 2 + update/v1.4/Update-ARDB_Tags_background.py | 2 + .../modules/dashboard/templates/index.html | 2 +- var/www/modules/settings/Flask_settings.py | 53 +++++++++++++- .../settings/templates/settings_index.html | 72 +++++++++++++------ .../{options => settings}/menu_sidebar.html | 0 9 files changed, 112 insertions(+), 24 deletions(-) rename var/www/templates/{options => settings}/menu_sidebar.html (100%) diff --git a/bin/update-background.py b/bin/update-background.py index 6ca990e7..d6ea59b6 100755 --- a/bin/update-background.py +++ b/bin/update-background.py @@ -54,4 +54,5 @@ if __name__ == "__main__": r_serv.set('ail:update_error', 'Update v1.5 Failed, please relaunch the bin/update-background.py script') else: r_serv.delete('ail:update_in_progress') + r_serv_db.delete('ail:current_background_script') r_serv.delete('ail:current_background_update', 'v1.5') diff --git a/update/v1.4/Update-ARDB_Metadata.py b/update/v1.4/Update-ARDB_Metadata.py index 128b9bdf..eb6ae352 100755 --- a/update/v1.4/Update-ARDB_Metadata.py +++ b/update/v1.4/Update-ARDB_Metadata.py @@ -90,6 +90,8 @@ if __name__ == '__main__': db=cfg.getint("ARDB_Onion", "db"), decode_responses=True) + r_serv.set('ail:current_background_script', 'metadata') + ## Update metadata ## print('Updating ARDB_Metadata ...') index = 0 diff --git a/update/v1.4/Update-ARDB_Onions.py b/update/v1.4/Update-ARDB_Onions.py index dec17961..f48fa0b9 100755 --- a/update/v1.4/Update-ARDB_Onions.py +++ b/update/v1.4/Update-ARDB_Onions.py @@ -73,6 +73,8 @@ if __name__ == '__main__': db=cfg.getint("ARDB_Onion", "db"), decode_responses=True) + r_serv.set('ail:current_background_script', 'onions') + ## Update Onion ## print('Updating ARDB_Onion ...') index = 0 diff --git a/update/v1.4/Update-ARDB_Tags.py b/update/v1.4/Update-ARDB_Tags.py index 50c9ead3..31d002d1 100755 --- a/update/v1.4/Update-ARDB_Tags.py +++ b/update/v1.4/Update-ARDB_Tags.py @@ -57,6 +57,8 @@ if __name__ == '__main__': db=2018, decode_responses=True) + r_serv.set('ail:current_background_script', 'tags') + if r_serv.exists('v1.5:onions') and r_serv.exists('v1.5:metadata'): print('Updating ARDB_Tags ...') diff --git a/update/v1.4/Update-ARDB_Tags_background.py b/update/v1.4/Update-ARDB_Tags_background.py index 700d9022..1e117b65 100755 --- a/update/v1.4/Update-ARDB_Tags_background.py +++ b/update/v1.4/Update-ARDB_Tags_background.py @@ -47,6 +47,8 @@ if __name__ == '__main__': db=cfg.getint("ARDB_Tags", "db"), decode_responses=True) + r_serv.set('ail:current_background_script', 'tags_background') + print('Updating ARDB_Tags ...') start = time.time() diff --git a/var/www/modules/dashboard/templates/index.html b/var/www/modules/dashboard/templates/index.html index 11ed07a6..4e6d1a21 100644 --- a/var/www/modules/dashboard/templates/index.html +++ b/var/www/modules/dashboard/templates/index.html @@ -103,7 +103,7 @@
× Warning! An Update is running on the background. Some informations like Tags, screenshot can be missing from the UI. - (Check Update Status) + (Check Update Status)
{%endif%} diff --git a/var/www/modules/settings/Flask_settings.py b/var/www/modules/settings/Flask_settings.py index 0e735979..9d4d2d96 100644 --- a/var/www/modules/settings/Flask_settings.py +++ b/var/www/modules/settings/Flask_settings.py @@ -22,6 +22,8 @@ max_preview_char = Flask_config.max_preview_char max_preview_modal = Flask_config.max_preview_modal REPO_ORIGIN = Flask_config.REPO_ORIGIN +dict_update_stat = {'v1.5':{'nb_background_update': 4}} + settings = Blueprint('settings', __name__, template_folder='templates') @@ -66,7 +68,12 @@ def get_update_metadata(): dict_update['update_in_progress'] = r_serv_db.get('ail:update_in_progress') dict_update['update_error'] = r_serv_db.get('ail:update_error') - dict_update['update_in_progress']='v1.5' + if dict_update['update_in_progress']: + dict_update['update_progression'] = r_serv_db.scard('ail:update_{}'.format(dict_update['update_in_progress'])) + dict_update['update_nb'] = dict_update_stat[dict_update['update_in_progress']]['nb_background_update'] + dict_update['update_stat'] = int(dict_update['update_progression']*100/dict_update['update_nb']) + dict_update['current_background_script'] = r_serv_db.get('ail:current_background_script') + dict_update['current_background_script_stat'] = r_serv_db.get('ail:current_background_script_stat') return dict_update # ============= ROUTES ============== @@ -74,11 +81,53 @@ def get_update_metadata(): @settings.route("/settings/", methods=['GET']) def settings_page(): git_metadata = get_git_metadata() + current_version = r_serv_db.get('ail:version') update_metadata = get_update_metadata() return render_template("settings_index.html", git_metadata=git_metadata, - update_metadata=update_metadata) + current_version=current_version) + + +@settings.route("/settings/get_background_update_stats_json", methods=['GET']) +def get_background_update_stats_json(): + # handle :end, error + update_stats = {} + current_update = r_serv_db.get('ail:current_background_update') + update_in_progress = r_serv_db.get('ail:update_in_progress') + + + if current_update: + update_stats['update_version']= current_update + update_stats['background_name']= r_serv_db.get('ail:current_background_script') + update_stats['background_stats']= r_serv_db.get('ail:current_background_script_stat') + if update_stats['background_stats'] is None: + update_stats['background_stats'] = 0 + else: + update_stats['background_stats'] = int(update_stats['background_stats']) + + ## DEBUG: + update_stats['background_stats'] =12 + + update_progression = r_serv_db.scard('ail:update_{}'.format(current_update)) + update_nb_scripts = dict_update_stat[current_update]['nb_background_update'] + update_stats['update_stat'] = int(update_progression*100/update_nb_scripts) + update_stats['update_stat_label'] = '{}/{}'.format(update_progression, update_nb_scripts) + + if not update_in_progress: + update_stats['error'] = True + error_message = r_serv_db.get('ail:update_error') + if error_message: + update_stats['error_message'] = error_message + else: + update_stats['error_message'] = 'Please relaunch the bin/update-background.py script' + else: + update_stats['error'] = False + + return jsonify(update_stats) + + else: + return jsonify({}) # ========= REGISTRATION ========= app.register_blueprint(settings, url_prefix=baseUrl) diff --git a/var/www/modules/settings/templates/settings_index.html b/var/www/modules/settings/templates/settings_index.html index 9f5707a8..8d4f0103 100644 --- a/var/www/modules/settings/templates/settings_index.html +++ b/var/www/modules/settings/templates/settings_index.html @@ -25,7 +25,7 @@
- {% include 'options/menu_sidebar.html' %} + {% include 'settings/menu_sidebar.html' %}
@@ -43,7 +43,7 @@ AIL Version - {{update_metadata['current_version']}} (release note) + {{current_version}} (release note) {%if git_metadata['is_clone']%} - {%if update_metadata['update_in_progress']%} - - Update in progress - {{update_metadata['update_in_progress']}} - - {%endif%}
- {%if update_metadata['update_in_progress']%} -
-
-
Backgroud Update: {{update_metadata['current_background_update']}}
- -
-
- {%elif update_metadata['update_error']%} -
-
-
Update Error: {{update_metadata['current_background_update']}}
-

{{update_metadata['update_error']}}

+
+
+
Backgroud Update:
+
+
+
+
+ Updating: ... +
+
+
+
+
+
Update Error:
+

- {%endif%} +
@@ -167,6 +164,39 @@ function toggle_sidebar(){ $('#core_content').addClass('col-lg-10') } } + +function update_progress(){ + $.getJSON("{{ url_for('settings.get_background_update_stats_json') }}", function(data){ + if(! jQuery.isEmptyObject(data)){ + $('#card_progress').show(); + $('#backgroud_update_version').text(data['update_version']); + $('#backgroud_update_name').text(data['background_name']); + + $('#update_global_progress').attr('aria-valuenow', data['update_stat']).width(data['update_stat']+'%').text(data['update_stat_label']); + $('#update_background_progress').attr('aria-valuenow', data['background_stats']).width(data['background_stats']+'%').text(data['background_stats']+'%'); + + if(data['error']){ + $('#update_error_div').show(); + $('#update_error_mess').text(data['error_message']); + $('#card_progress').removeClass("border-success"); + $('#card_progress').addClass("border-danger"); + } else { + $('#update_error_div').hide(); + $('#card_progress').removeClass("border-danger"); + $('#card_progress').add("border-success"); + } + } else { + $('#card_progress').hide(); + clearInterval(progress_interval); + } + }); +} + +update_progress(); +//Interval +var progress_interval = setInterval(function(){ + update_progress() +}, 10000); diff --git a/var/www/templates/options/menu_sidebar.html b/var/www/templates/settings/menu_sidebar.html similarity index 100% rename from var/www/templates/options/menu_sidebar.html rename to var/www/templates/settings/menu_sidebar.html