@@ -, +, @@ --- Koha/BackgroundJob.pm | 14 ++ Koha/REST/V1/BackgroundJobs.pm | 58 ++++++ admin/background_jobs.pl | 33 ---- .../prog/en/modules/admin/background_jobs.tt | 174 ++++++++++++++++++ 4 files changed, 246 insertions(+), 33 deletions(-) create mode 100644 Koha/REST/V1/BackgroundJobs.pm --- a/Koha/BackgroundJob.pm +++ a/Koha/BackgroundJob.pm @@ -469,6 +469,20 @@ sub plugin_types_to_classes { return $self->{_plugin_mapping}; } +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::BackgroundJob object +on the API. + +=cut + +sub to_api_mapping { + return { + id => 'background_job_id', + borrowernumber => 'patron_id', + }; +} + =head3 _type =cut --- a/Koha/REST/V1/BackgroundJobs.pm +++ a/Koha/REST/V1/BackgroundJobs.pm @@ -0,0 +1,58 @@ +package Koha::REST::V1::BackgroundJobs; + +# 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 Mojo::Base 'Mojolicious::Controller'; + +use Koha::BackgroundJobs; + +use Try::Tiny; + +=head1 API + +=head2 Methods + +=head3 list + +=cut + +sub list { + my $c = shift->openapi->valid_input or return; + + return try { + my $patron = $c->stash('koha.user'); + + my $can_manage_background_jobs = + $patron->has_permission( { parameters => 'manage_background_jobs' } ); + + my $background_jobs_set = + $can_manage_background_jobs + ? Koha::BackgroundJobs->new + : Koha::BackgroundJobs->search( + { borrowernumber => $patron->borrowernumber } ); + + my $background_jobs = $c->objects->search( $background_jobs_set ); + return $c->render( status => 200, openapi => $background_jobs ); + } + catch { + $c->unhandled_exception($_); + }; + +} + +1; --- a/admin/background_jobs.pl +++ a/admin/background_jobs.pl @@ -77,39 +77,6 @@ if ( $op eq 'cancel' ) { $op = 'list'; } - -if ( $op eq 'list' ) { - my $queued_jobs = - $can_manage_background_jobs - ? Koha::BackgroundJobs->search( { ended_on => undef }, - { order_by => { -desc => 'enqueued_on' } } ) - : Koha::BackgroundJobs->search( - { borrowernumber => $logged_in_user->borrowernumber, ended_on => undef }, - { order_by => { -desc => 'enqueued_on' } } - ); - $template->param( queued => $queued_jobs ); - - my $ended_since = dt_from_string->subtract( minutes => '60' ); - my $dtf = Koha::Database->new->schema->storage->datetime_parser; - - my $complete_jobs = - $can_manage_background_jobs - ? Koha::BackgroundJobs->search( - { - ended_on => { '>=' => $dtf->format_datetime($ended_since) } - }, - { order_by => { -desc => 'enqueued_on' } } - ) - : Koha::BackgroundJobs->search( - { - borrowernumber => $logged_in_user->borrowernumber, - ended_on => { '>=' => $dtf->format_datetime($ended_since) } - }, - { order_by => { -desc => 'enqueued_on' } } - ); - $template->param( complete => $complete_jobs ); -} - $template->param( messages => \@messages, op => $op, --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt @@ -256,6 +256,23 @@ + + + + + + + + + + + + + + + + +
Job IDStatusProgressTypeQueuedStartedEndedActions
[% END %] @@ -270,6 +287,7 @@ [% MACRO jsinclude BLOCK %] [% Asset.js("js/admin-menu.js") | $raw %] + [% INCLUDE 'js-date-format.inc' %] [% INCLUDE 'datatables.inc' %] [% IF op == 'view' %] [% PROCESS 'js' %] --