chg: [settings UI] add background update progress

This commit is contained in:
Terrtia 2019-04-17 14:39:29 +02:00
parent 68077316eb
commit 4bff603d4f
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
9 changed files with 112 additions and 24 deletions

View file

@ -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') r_serv.set('ail:update_error', 'Update v1.5 Failed, please relaunch the bin/update-background.py script')
else: else:
r_serv.delete('ail:update_in_progress') r_serv.delete('ail:update_in_progress')
r_serv_db.delete('ail:current_background_script')
r_serv.delete('ail:current_background_update', 'v1.5') r_serv.delete('ail:current_background_update', 'v1.5')

View file

@ -90,6 +90,8 @@ if __name__ == '__main__':
db=cfg.getint("ARDB_Onion", "db"), db=cfg.getint("ARDB_Onion", "db"),
decode_responses=True) decode_responses=True)
r_serv.set('ail:current_background_script', 'metadata')
## Update metadata ## ## Update metadata ##
print('Updating ARDB_Metadata ...') print('Updating ARDB_Metadata ...')
index = 0 index = 0

View file

@ -73,6 +73,8 @@ if __name__ == '__main__':
db=cfg.getint("ARDB_Onion", "db"), db=cfg.getint("ARDB_Onion", "db"),
decode_responses=True) decode_responses=True)
r_serv.set('ail:current_background_script', 'onions')
## Update Onion ## ## Update Onion ##
print('Updating ARDB_Onion ...') print('Updating ARDB_Onion ...')
index = 0 index = 0

View file

@ -57,6 +57,8 @@ if __name__ == '__main__':
db=2018, db=2018,
decode_responses=True) 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'): if r_serv.exists('v1.5:onions') and r_serv.exists('v1.5:metadata'):
print('Updating ARDB_Tags ...') print('Updating ARDB_Tags ...')

View file

@ -47,6 +47,8 @@ if __name__ == '__main__':
db=cfg.getint("ARDB_Tags", "db"), db=cfg.getint("ARDB_Tags", "db"),
decode_responses=True) decode_responses=True)
r_serv.set('ail:current_background_script', 'tags_background')
print('Updating ARDB_Tags ...') print('Updating ARDB_Tags ...')
start = time.time() start = time.time()

View file

@ -103,7 +103,7 @@
<div class="alert alert-warning alert-dismissible fade in"> <div class="alert alert-warning alert-dismissible fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>Warning!</strong> An Update is running on the background. Some informations like Tags, screenshot can be <strong>missing from the UI</strong>. <strong>Warning!</strong> An Update is running on the background. Some informations like Tags, screenshot can be <strong>missing from the UI</strong>.
(<a href="#">Check Update Status</a>) (<a href="{{ url_for('settings.settings_page') }}">Check Update Status</a>)
</div> </div>
{%endif%} {%endif%}

View file

@ -22,6 +22,8 @@ max_preview_char = Flask_config.max_preview_char
max_preview_modal = Flask_config.max_preview_modal max_preview_modal = Flask_config.max_preview_modal
REPO_ORIGIN = Flask_config.REPO_ORIGIN REPO_ORIGIN = Flask_config.REPO_ORIGIN
dict_update_stat = {'v1.5':{'nb_background_update': 4}}
settings = Blueprint('settings', __name__, template_folder='templates') 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_in_progress'] = r_serv_db.get('ail:update_in_progress')
dict_update['update_error'] = r_serv_db.get('ail:update_error') 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 return dict_update
# ============= ROUTES ============== # ============= ROUTES ==============
@ -74,11 +81,53 @@ def get_update_metadata():
@settings.route("/settings/", methods=['GET']) @settings.route("/settings/", methods=['GET'])
def settings_page(): def settings_page():
git_metadata = get_git_metadata() git_metadata = get_git_metadata()
current_version = r_serv_db.get('ail:version')
update_metadata = get_update_metadata() update_metadata = get_update_metadata()
return render_template("settings_index.html", git_metadata=git_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 ========= # ========= REGISTRATION =========
app.register_blueprint(settings, url_prefix=baseUrl) app.register_blueprint(settings, url_prefix=baseUrl)

View file

@ -25,7 +25,7 @@
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
{% include 'options/menu_sidebar.html' %} {% include 'settings/menu_sidebar.html' %}
<div class="col-12 col-lg-10" id="core_content"> <div class="col-12 col-lg-10" id="core_content">
@ -43,7 +43,7 @@
<tbody> <tbody>
<tr> <tr>
<td>AIL Version</td> <td>AIL Version</td>
<td>{{update_metadata['current_version']}}<a target="_blank" href="https://github.com/CIRCL/AIL-framework/releases/tag/{{update_metadata['current_version']}}" class="text-info"><small> (release note)</small></a></td> <td>{{current_version}}<a target="_blank" href="https://github.com/CIRCL/AIL-framework/releases/tag/{{current_version}}" class="text-info"><small> (release note)</small></a></td>
</tr> </tr>
<tr <tr
{%if git_metadata['current_branch'] != 'master'%} {%if git_metadata['current_branch'] != 'master'%}
@ -59,12 +59,6 @@
</td> </td>
</tr> </tr>
{%if git_metadata['is_clone']%} {%if git_metadata['is_clone']%}
{%if update_metadata['update_in_progress']%}
<tr>
<td>Update in progress</td>
<td>{{update_metadata['update_in_progress']}}</td>
</tr>
{%endif%}
<tr <tr
{%if git_metadata['new_git_update_available']%} {%if git_metadata['new_git_update_available']%}
class="table-warning" class="table-warning"
@ -103,22 +97,25 @@
</div> </div>
<div class="col-xl-6"> <div class="col-xl-6">
{%if update_metadata['update_in_progress']%} <div class="card text-center border-success" id="card_progress">
<div class="card text-center border-success"> <div class="card-body" id="card_progress_body">
<div class="card-body"> <h5 class="card-title">Backgroud Update: <span id="backgroud_update_version"></span></h5>
<h5 class="card-title">Backgroud Update: {{update_metadata['current_background_update']}}</h5> <div class="progress">
<img id="loading-gif-modal" src="{{url_for('static', filename='image/loading.gif') }}" height="26" width="26"> <div class="progress-bar bg-danger" role="progressbar" id="update_global_progress" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<hr class="my-1">
Updating: <strong id="backgroud_update_name"></strong> ...
<div class="progress">
<div class="progress-bar progress-bar-striped bg-warning progress-bar-animated" role="progressbar" id="update_background_progress" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="text-danger" id="update_error_div">
<hr>
<h5 class="card-title"><i class="fas fa-times-circle text-danger"></i> Update Error:</h5>
<p id="update_error_mess"></p>
</div> </div>
</div> </div>
{%elif update_metadata['update_error']%}
<div class="card text-center border-danger">
<div class="card-body text-danger">
<h5 class="card-title">Update Error: {{update_metadata['current_background_update']}}</h5>
<p>{{update_metadata['update_error']}}</p>
</div> </div>
</div> </div>
{%endif%}
</div>
</div> </div>
@ -167,6 +164,39 @@ function toggle_sidebar(){
$('#core_content').addClass('col-lg-10') $('#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);
</script> </script>
</html> </html>