Merge pull request #88 from cyberjacob/task-status-on-video-page

Fix task statuses on the video and other pages
This commit is contained in:
chibicitiberiu 2019-11-30 12:43:24 +02:00 committed by GitHub
commit 89499c75ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 82 deletions

View File

@ -198,6 +198,85 @@ function ajaxLink_Clicked() {
return false;
}
///
/// Notifications
///
const JOB_QUERY_INTERVAL = 1500;
function get_and_process_running_jobs()
{
$.get("{% url 'ajax_get_running_jobs' %}")
.done(function(data) {
let progress = $('#status-progress');
let jobPanel = $('#job_panel');
let jobTitle = jobPanel.find('#job_panel_title');
let jobTitleNoJobs = jobPanel.find('#job_panel_no_jobs_title');
let jobTemplate = jobPanel.find('#job_panel_item_template');
if (data.length > 0) {
// Update status bar
if (data.length > 1) {
$('#status-message').text(`Running ${data.length} jobs...`);
}
else {
$('#status-message').text(`${data[0].description} | ${data[0].message}`);
}
// Update global progress bar
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)}%`);
// Update entries in job list
jobTitle.removeClass('collapse');
jobTitleNoJobs.addClass('collapse');
data.sort(function (a, b) { return a.id - b.id });
jobPanel.find('.job_entry').remove();
for (let entry of data) {
let jobEntry = jobTemplate.clone();
jobEntry.attr('id', `job_${entry.id}`);
jobEntry.addClass('job_entry');
jobEntry.removeClass('collapse');
jobEntry.find('#job_panel_item_title').text(entry.description);
jobEntry.find('#job_panel_item_subtitle').text(entry.message);
let entryPercent = 100 * entry.progress;
let jobEntryProgress = jobEntry.find('#job_panel_item_progress');
jobEntryProgress.width(entryPercent + '%');
jobEntryProgress.text(`${entryPercent.toFixed(0)}%`);
jobEntry.appendTo(jobPanel);
}
$('#btn_toggle_job_panel').dropdown('update');
}
else {
progress.addClass('invisible');
$('#status-message').text("");
jobTitle.addClass('collapse');
jobTitleNoJobs.removeClass('collapse');
jobPanel.find('.job_entry').remove();
$('#btn_toggle_job_panel').dropdown('update');
}
});
}
///
/// Initialization
///
@ -205,4 +284,9 @@ $(document).ready(function ()
{
$(".ajax-link").on("click", ajaxLink_Clicked);
$("#btn_sync_now").on("click", syncNow);
$('[data-toggle="tooltip"]').tooltip()
// Notifications
get_and_process_running_jobs();
setInterval(get_and_process_running_jobs, JOB_QUERY_INTERVAL);
});

View File

@ -175,84 +175,6 @@ function videos_Submit(e)
e.preventDefault();
}
///
/// Notifications
///
const JOB_QUERY_INTERVAL = 1500;
function get_and_process_running_jobs()
{
$.get("{% url 'ajax_get_running_jobs' %}")
.done(function(data) {
let progress = $('#status-progress');
let jobPanel = $('#job_panel');
let jobTitle = jobPanel.find('#job_panel_title');
let jobTitleNoJobs = jobPanel.find('#job_panel_no_jobs_title');
let jobTemplate = jobPanel.find('#job_panel_item_template');
if (data.length > 0) {
// Update status bar
if (data.length > 1) {
$('#status-message').text(`Running ${data.length} jobs...`);
}
else {
$('#status-message').text(`${data[0].description} | ${data[0].message}`);
}
// Update global progress bar
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)}%`);
// Update entries in job list
jobTitle.removeClass('collapse');
jobTitleNoJobs.addClass('collapse');
data.sort(function (a, b) { return a.id - b.id });
jobPanel.find('.job_entry').remove();
for (let entry of data) {
let jobEntry = jobTemplate.clone();
jobEntry.attr('id', `job_${entry.id}`);
jobEntry.addClass('job_entry');
jobEntry.removeClass('collapse');
jobEntry.find('#job_panel_item_title').text(entry.description);
jobEntry.find('#job_panel_item_subtitle').text(entry.message);
let entryPercent = 100 * entry.progress;
let jobEntryProgress = jobEntry.find('#job_panel_item_progress');
jobEntryProgress.width(entryPercent + '%');
jobEntryProgress.text(`${entryPercent.toFixed(0)}%`);
jobEntry.appendTo(jobPanel);
}
$('#btn_toggle_job_panel').dropdown('update');
}
else {
progress.addClass('invisible');
$('#status-message').text("");
jobTitle.addClass('collapse');
jobTitleNoJobs.removeClass('collapse');
jobPanel.find('.job_entry').remove();
$('#btn_toggle_job_panel').dropdown('update');
}
});
}
///
/// Initialization
///
@ -292,8 +214,4 @@ $(document).ready(function ()
filters_form.find('select[name=results_per_page]').on('change', videos_ResetPageAndReloadWithTimer);
videos_Reload();
// Notifications
get_and_process_running_jobs();
setInterval(get_and_process_running_jobs, JOB_QUERY_INTERVAL);
});