mirror of
https://github.com/chibicitiberiu/ytsm.git
synced 2024-02-24 05:43:31 +00:00
Improved notification system.
This commit is contained in:
@ -9,8 +9,6 @@
|
||||
{% block scripts %}
|
||||
<script src="{% static 'YtManagerApp/import/jstree/dist/jstree.min.js' %}"></script>
|
||||
<script>
|
||||
let LAST_NOTIFICATION_ID = {{ current_notification_id }};
|
||||
|
||||
{% include 'YtManagerApp/js/index.js' %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
@ -178,63 +178,43 @@ function videos_Submit(e)
|
||||
///
|
||||
/// Notifications
|
||||
///
|
||||
const NOTIFICATION_INTERVAL = 1000;
|
||||
const STATUS_UPDATE = 'st-up';
|
||||
const STATUS_OPERATION_PROGRESS = 'st-op-prog';
|
||||
const STATUS_OPERATION_END = 'st-op-end';
|
||||
const OPERATION_LIST = {};
|
||||
const JOB_QUERY_INTERVAL = 1500;
|
||||
|
||||
function notifications_update_progress_bar() {
|
||||
|
||||
var count = 0;
|
||||
var percent = 0;
|
||||
|
||||
for(op in OPERATION_LIST) {
|
||||
count++;
|
||||
percent += OPERATION_LIST[op];
|
||||
}
|
||||
|
||||
let progress = $('#status-progress');
|
||||
if (count > 0) {
|
||||
progress.removeClass('invisible');
|
||||
let bar = progress.find('.progress-bar');
|
||||
bar.width(percent * 100 + '%');
|
||||
bar.text(count + ' operations in progress');
|
||||
}
|
||||
else {
|
||||
progress.addClass('invisible');
|
||||
}
|
||||
}
|
||||
|
||||
function get_and_process_notifications()
|
||||
{
|
||||
$.get("{% url 'ajax_get_notifications' 12345 %}".replace("12345", LAST_NOTIFICATION_ID))
|
||||
$.get("{% url 'ajax_get_running_jobs' %}")
|
||||
.done(function(data) {
|
||||
for (let entry of data)
|
||||
{
|
||||
LAST_NOTIFICATION_ID = entry.id;
|
||||
let dt = new Date(entry.time);
|
||||
|
||||
// Status update
|
||||
if (entry.msg === STATUS_UPDATE) {
|
||||
let txt = `<span class="status-timestamp">${dt.getHours()}:${zeroFill(dt.getMinutes(), 2)}</span>${entry.status}`;
|
||||
$('#status-message').html(txt);
|
||||
}
|
||||
else if (entry.msg === STATUS_OPERATION_PROGRESS) {
|
||||
let txt = `<span class="status-timestamp">${dt.getHours()}:${zeroFill(dt.getMinutes(), 2)}</span>${entry.status}`;
|
||||
$('#status-message').html(txt);
|
||||
let progress = $('#status-progress');
|
||||
|
||||
OPERATION_LIST[entry.operation] = entry.progress;
|
||||
notifications_update_progress_bar();
|
||||
}
|
||||
else if (entry.msg === STATUS_OPERATION_END) {
|
||||
let txt = `<span class="status-timestamp">${dt.getHours()}:${dt.getMinutes()}</span>${entry.status}`;
|
||||
$('#status-message').html(txt);
|
||||
if (data.length > 0) {
|
||||
|
||||
delete OPERATION_LIST[entry.operation];
|
||||
notifications_update_progress_bar();
|
||||
let statusTxt = "";
|
||||
if (data.length > 1) {
|
||||
statusTxt = `Running ${data.length} jobs...`;
|
||||
}
|
||||
|
||||
else {
|
||||
statusTxt = `${data[0].description} | ${data[0].message}`;
|
||||
}
|
||||
|
||||
let combinedProgress = 0;
|
||||
for (let entry of data) {
|
||||
combinedProgress += entry.progress;
|
||||
}
|
||||
|
||||
let percent = 100 * combinedProgress / data.length;
|
||||
|
||||
progress.removeClass('invisible');
|
||||
let bar = progress.find('.progress-bar');
|
||||
bar.width(percent + '%');
|
||||
bar.text(`${percent.toFixed(0)}%`);
|
||||
$('#status-message').text(statusTxt);
|
||||
}
|
||||
else {
|
||||
progress.addClass('invisible');
|
||||
$('#status-message').text("");
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -280,5 +260,5 @@ $(document).ready(function ()
|
||||
videos_Reload();
|
||||
|
||||
// Notification manager
|
||||
setInterval(get_and_process_notifications, NOTIFICATION_INTERVAL);
|
||||
setInterval(get_and_process_notifications, JOB_QUERY_INTERVAL);
|
||||
});
|
||||
|
Reference in New Issue
Block a user