Bugzilla – Attachment 141261 Details for
Bug 31666
Add job progress bar to stage-marc-import.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31666: Add job progress bar to stage-marc-import.pl
Bug-31666-Add-job-progress-bar-to-stage-marc-impor.patch (text/plain), 5.60 KB, created by
David Nind
on 2022-10-03 13:02:50 UTC
(
hide
)
Description:
Bug 31666: Add job progress bar to stage-marc-import.pl
Filename:
MIME Type:
Creator:
David Nind
Created:
2022-10-03 13:02:50 UTC
Size:
5.60 KB
patch
obsolete
>From 76b115647969af894a40a86b16dd64abb313415b Mon Sep 17 00:00:00 2001 >From: Kyle Hall <kyle@bywatersolutions.com> >Date: Fri, 30 Sep 2022 12:35:00 -0400 >Subject: [PATCH] Bug 31666: Add job progress bar to stage-marc-import.pl > >It would be nice if we had progress bars to indicate the progress of background jobs for scripts that utilize them. > >This patch implements a reusable bootstrap based progess bar. > >Test Plan: >1) Apply this patch >2) Stage a marc batch ( preferrably a large one to show the progress updating ) >3) Note the new progess bar, verify it functions correctly. > >Signed-off-by: David Nind <david@davidnind.com> >--- > .../prog/en/includes/job_progress.inc | 5 +++ > .../prog/en/includes/str/job_progess.inc | 7 ++++ > .../en/modules/tools/stage-marc-import.tt | 9 ++--- > .../intranet-tmpl/prog/js/job_progess.js | 34 +++++++++++++++++++ > 4 files changed, 51 insertions(+), 4 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/job_progress.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/str/job_progess.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/job_progess.js > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/job_progress.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/job_progress.inc >new file mode 100644 >index 0000000000..8741bab4d0 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/job_progress.inc >@@ -0,0 +1,5 @@ >+<div class="progress"> >+ <div id="progress-bar-[% job_id %]" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:100%"> >+ <span id="job-percent-[% job_id %]">0</span>% <span id="job-status-[% job_id %]"></span> >+ </div> >+</div> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/str/job_progess.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/str/job_progess.inc >new file mode 100644 >index 0000000000..9e85c25810 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/str/job_progess.inc >@@ -0,0 +1,7 @@ >+<!-- str/job_progess.inc --> >+<script> >+ var JOB_PROGRESS_NOT_STARTED = _("Not started"); >+ var JOB_PROGRESS_STARTED = _("Started"); >+ var JOB_PROGRESS_FINISHED = _("Finished"); >+ var JOB_PROGRESS_FAILED = _("Failed"); >+</script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >index 8a23682952..c790fd0f1e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt >@@ -74,6 +74,7 @@ > <h1>MARC staging</h1> > <div class="dialog message"> > <p>The job has been enqueued! It will be processed as soon as possible.</p> >+ [% INCLUDE "job_progress.inc" job_id=job_id %] > <p><a class="job_details" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]" title="View detail of the enqueued job">View detail of the enqueued job</a> > </div> > [% ELSE %] >@@ -258,6 +259,9 @@ > [% Asset.js("js/tools-menu.js") | $raw %] > [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] > [% Asset.js("js/file-upload.js") | $raw %] >+ >+ [% INCLUDE 'str/job_progess.inc' job_id=job_id %] >+ [% Asset.js("js/job_progess.js") | $raw %] > <script> > var xhr; > var PROFILE_SAVE_MSG = _("Profile saved"); >@@ -422,10 +426,7 @@ > }) > }); > [% IF job_enqueued %] >- setTimeout( >- function() { window.location.href=$('a.job_details').attr('href'); }, >- 5000, // 5 secs to read >- ); >+ updateProgress([% job_id %]); > [% END %] > }); > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/job_progess.js b/koha-tmpl/intranet-tmpl/prog/js/job_progess.js >new file mode 100644 >index 0000000000..2504fcf686 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/job_progess.js >@@ -0,0 +1,34 @@ >+function updateProgress(job_id) { >+ $.getJSON('/api/v1/jobs/' + job_id, function(job){ >+ let recheck = true; >+ >+ if ( job.status == "new" ) { >+ $(`#job-percent-${job_id}`).text(0); >+ $(`#job-status-${job_id}`).text(JOB_PROGRESS_NOT_STARTED); >+ $(`#progress-bar-${job_id}`).attr('aria-valuenow', 0).css("width", "100%"); >+ } else if ( job.status == "started" ) { >+ const progress = job["progress"]; >+ const size = job["size"]; >+ const percent = progress > 0 ? ( progress / size ) * 100 : 0; >+ $(`#job-percent-${job_id}`).text(percent.toFixed(2)); >+ $(`#job-status-${job_id}`).text(JOB_PROGRESS_STARTED); >+ $(`#progress-bar-${job_id}`).attr('aria-valuenow', percent).css("width", `${percent}%`); >+ } else if ( job.status == "finished" ) { >+ $(`#job-percent-${job_id}`).text(100); >+ $(`#job-status-${job_id}`).text(JOB_PROGRESS_FINISHED); >+ $(`#progress-bar-${job_id}`).addClass("progress-bar-success"); >+ $(`#progress-bar-${job_id}`).attr('aria-valuenow', 100).css("width", "100%"); >+ recheck = false; >+ } else if ( job.status == "failed" ) { >+ $(`#job-percent-${job_id}`).text(0); >+ $(`#job-status-${job_id}`).text(JOB_PROGRESS_FAILED); >+ $(`#progress-bar-${job_id}`).addClass("progress-bar-danger"); >+ $(`#progress-bar-${job_id}`).attr('aria-valuenow', 0).css("width", "100%"); >+ recheck = false; >+ } >+ >+ if ( recheck ) { >+ setTimeout(function(){updateProgress(job_id)}, 1 * 1000); >+ } >+ }); >+} >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31666
:
141172
|
141173
|
141174
|
141261
|
141308
|
141309
|
141310
|
141397
|
141398
|
141399