From 9135186930ff57c39d1ade7ae75cff1d8fba0dac Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 25 Feb 2019 21:45:35 -0300 Subject: [PATCH] Bug 22417: Add GUI to watch the progress of jobs Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Cook --- admin/background_jobs.pl | 67 +++++++++ .../prog/en/modules/admin/background_jobs.tt | 165 +++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100755 admin/background_jobs.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt diff --git a/admin/background_jobs.pl b/admin/background_jobs.pl new file mode 100755 index 0000000000..2b4ca03dbf --- /dev/null +++ b/admin/background_jobs.pl @@ -0,0 +1,67 @@ +#! /usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use CGI qw ( -utf8 ); +use JSON qw( decode_json ); +use C4::Context; +use C4::Auth; +use C4::Output; + +use Koha::BackgroundJob; +use Koha::BackgroundJobs; + +my $input = new CGI; +my $op = $input->param('op') || 'list'; +my @messages; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "admin/background_jobs.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { parameters => 'manage_background_jobs' }, # TODO Add this new permission, so far only works for superlibrarians + debug => 1, + } +); + +my $dbh = C4::Context->dbh; + +if ( $op eq 'view' ) { + my $id = $input->param('id'); + if ( my $job = Koha::BackgroundJobs->find($id) ) { + $template->param( + job => $job, + ); + } else { + $op = 'list'; + } + +} + +if ( $op eq 'list' ) { + my $jobs = Koha::BackgroundJobs->search({}, { order_by => { -desc => 'enqueued_on' }}); + $template->param( jobs => $jobs, ); +} + +$template->param( + messages => \@messages, + op => $op, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt new file mode 100644 index 0000000000..5d42f4ad08 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt @@ -0,0 +1,165 @@ +[% USE raw %] +[% USE Asset %] +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › [% IF op =='add_form' %]Background jobs› [% IF job %] View background job[% ELSE %] Background jobs[% END %][% END %] +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] + + + +
+
+
+
+ +[% FOR m IN messages %] +
+ [% SWITCH m.code %] + [% CASE %] + [% m.code | html %] + [% END %] +
+[% END %] + +[% IF op == 'view' %] +

Detail of job #[% job.id | html %]

+ +
+
    +
  1. Job ID: [% job.id | html %]
  2. +
  3. [% job.status | html %]
  4. +
  5. [% job.progress || 0 | html %] / [% job.size | html %]
  6. +
  7. [% job.type | html %]
  8. +
  9. [% job.enqueued_on | html %]
  10. +
  11. [% job.started_on | html %]
  12. +
  13. [% job.ended_on | html %]
  14. +
  15. + [% SWITCH job.type %] + [% CASE 'batch_biblio_record_modification' %] + [% SET report = job.report %] + [% IF report %] + [% IF report.total_records == report.total_success %] +
    + All records have successfully been modified! New batch record modification +
    + [% ELSE %] +
    + [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. New batch record modification +
    + [% END %] + [% END %] + [% CASE %][% job.type | html %] + [% END %] +
  16. +
  17. + [% SWITCH job.type %] + [% CASE 'batch_biblio_record_modification' %] + [% FOR m IN job.messages %] +
    + [% IF m.type == 'success' %] + + [% ELSIF m.type == 'warning' %] + + [% ELSIF m.type == 'error' %] + + [% END %] + [% SWITCH m.code %] + [% CASE 'biblio_not_modified' %] + Bibliographic record [% m.biblionumber | html %] has not been modified. An error occurred on modifying it. + [% CASE 'biblio_modified' %] + Bibliographic record [% m.biblionumber | html %] has successfully been modified. + [% END %] +
    + [% END %] + [% CASE %][% job.type | html %] + [% END %] +
  18. +
+
+ + Return to the job list +[% END %] + +[% IF op == 'list' %] + +

Background jobs

+ + [% IF jobs.count %] + + + + + + + + + + + + + + + [% FOREACH job IN jobs %] + + + + + + + + + + + [% END %] + +
Job IDStatusProgressTypeEnqueued onStarted onEnded onActions (NIY)
[% job.id | html %][% job.status | html %][% job.progress || 0 | html %] / [% job.size | html %] + [% SWITCH job.type %] + [% CASE 'batch_biblio_record_modification' %]Batch bibliographic record modification + [% CASE %][% job.type | html %] + [% END %] + [% job.enqueued_on | html %][% job.started_on| html %][% job.ended_on| html %] + Delete + Replay +
+ [% ELSE %] +
+ There are no background jobs yet. +
+ [% END %] +[% END %] + +
+
+ +
+ +
+
+ +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/admin-menu.js") | $raw %] + [% INCLUDE 'datatables.inc' %] + +[% END %] +[% INCLUDE 'intranet-bottom.inc' %] -- 2.11.0