Bug 30462: [22.05.x] Separate Queued and Complete jobs

This patch updates the background jobs management page to display
queued and completed jobs in their own tabs on the page.

JD Amended patch:
Fix QA failures:
 FAIL   koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt
   FAIL   forbidden patterns
                forbidden pattern: trailing space char (line 158)
                forbidden pattern: trailing space char (line 256)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Bug 30462: (follow-up) Limit completed to 60 minutes

This follow-up reduces the completed jobs list to only those jobs
completed within the last 60 minutes.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Bug 30462: Remove 'Ended' column for current jobs

This column will always be empty

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Bug 30462: Fix display of the complete jobs

We want to display the jobs terminated in the last hour, not today.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Bug 30462: (QA follow-up) Tab name change

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2022-06-07 11:08:32 +01:00 committed by Lucas Gass
parent 3d6607567c
commit ae9d3b0477
2 changed files with 132 additions and 46 deletions

View file

@ -19,6 +19,7 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Context;
use Koha::DateUtils qw( dt_from_string );
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
@ -78,15 +79,35 @@ if ( $op eq 'cancel' ) {
if ( $op eq 'list' ) {
my $jobs =
my $queued_jobs =
$can_manage_background_jobs
? Koha::BackgroundJobs->search( {},
? Koha::BackgroundJobs->search( { ended_on => undef },
{ order_by => { -desc => 'enqueued_on' } } )
: Koha::BackgroundJobs->search(
{ borrowernumber => $logged_in_user->borrowernumber },
{ borrowernumber => $logged_in_user->borrowernumber, ended_on => undef },
{ order_by => { -desc => 'enqueued_on' } }
);
$template->param( jobs => $jobs );
$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(

View file

@ -156,49 +156,106 @@
<h1>Background jobs</h1>
[% IF jobs.count %]
<table id="table_background_jobs">
<thead>
<tr>
<th>Job ID</th>
<th>Status</th>
<th>Progress</th>
<th>Type</th>
<th>Queued</th>
<th>Started</th>
<th>Ended</th>
<th class="noExport">Actions</th>
</tr>
</thead>
<tbody>
[% FOREACH job IN jobs %]
<tr>
<td>[% job.id | html %]</td>
<td>
[% PROCESS show_job_status %]
</td>
<td>[% job.progress || 0 | html %] / [% job.size | html %]</td>
<td>
[% PROCESS show_job_type job_type => job.type %]
</td>
<td>[% job.enqueued_on | $KohaDates with_hours = 1 %]</td>
<td>[% job.started_on| $KohaDates with_hours = 1 %]</td>
<td>[% job.ended_on| $KohaDates with_hours = 1 %]</td>
<td class="actions">
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&amp;id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a>
[% IF job.status == 'new' || job.status == 'started' %]
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&amp;id=[% job.id | html %]"><i class="fa fa-trash"></i> Cancel</a>
[% END %]
</td>
</tr>
<div id="taskstabs" class="toptabs">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#queued" aria-controls="queued" role="tab" data-toggle="tab">Queued jobs</a></li>
<li role="presentation"><a href="#complete" aria-controls="complete" role="tab" data-toggle="tab">Completed jobs</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="queued">
[% IF queued.count %]
<table id="table_queued_jobs">
<thead>
<tr>
<th>Job ID</th>
<th>Status</th>
<th>Progress</th>
<th>Type</th>
<th>Queued</th>
<th>Started</th>
<th class="noExport">Actions</th>
</tr>
</thead>
<tbody>
[% FOREACH job IN queued %]
<tr>
<td>[% job.id | html %]</td>
<td>
[% PROCESS show_job_status %]
</td>
<td>[% job.progress || 0 | html %] / [% job.size | html %]</td>
<td>
[% PROCESS show_job_type job_type => job.type %]
</td>
<td>[% job.enqueued_on | $KohaDates with_hours = 1 %]</td>
<td>[% job.started_on| $KohaDates with_hours = 1 %]</td>
<td class="actions">
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&amp;id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a>
[% IF job.status == 'new' || job.status == 'started' %]
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&amp;id=[% job.id | html %]"><i class="fa fa-trash"></i> Cancel</a>
[% END %]
</td>
</tr>
[% END %]
</tbody>
</table>
[% ELSE %]
<div class="dialog message">
There are no queued background jobs yet.
</div>
[% END %]
</tbody>
</table>
[% ELSE %]
<div class="dialog message">
There are no background jobs yet.
</div>
<div role="tabpanel" class="tab-pane" id="complete">
[% IF complete.count %]
<p>Jobs completed in the last 60 minutes.</p>
<table id="table_complete_jobs">
<thead>
<tr>
<th>Job ID</th>
<th>Status</th>
<th>Progress</th>
<th>Type</th>
<th>Queued</th>
<th>Started</th>
<th>Ended</th>
<th class="noExport">Actions</th>
</tr>
</thead>
<tbody>
[% FOREACH job IN complete %]
<tr>
<td>[% job.id | html %]</td>
<td>
[% PROCESS show_job_status %]
</td>
<td>[% job.progress || 0 | html %] / [% job.size | html %]</td>
<td>
[% PROCESS show_job_type job_type => job.type %]
</td>
<td>[% job.enqueued_on | $KohaDates with_hours = 1 %]</td>
<td>[% job.started_on| $KohaDates with_hours = 1 %]</td>
<td>[% job.ended_on| $KohaDates with_hours = 1 %]</td>
<td class="actions">
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&amp;id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a>
[% IF job.status == 'new' || job.status == 'started' %]
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&amp;id=[% job.id | html %]"><i class="fa fa-trash"></i> Cancel</a>
[% END %]
</td>
</tr>
[% END %]
</tbody>
</table>
[% ELSE %]
<div class="dialog message">
There were no completed background jobs completed in the last 60 minutes.
</div>
[% END %]
</div>
</div>
[% END %]
</div>
[% END %]
</main>
@ -216,7 +273,7 @@
[% INCLUDE 'datatables.inc' %]
<script>
$(document).ready(function() {
$("#table_background_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
$("#table_queued_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
"aoColumnDefs": [
{ "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
],
@ -225,6 +282,14 @@
"sPaginationType": "full_numbers"
}));
$("#table_complete_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
"aoColumnDefs": [
{ "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
],
"aaSorting": [[ 0, "desc" ]],
"iDisplayLength": 10,
"sPaginationType": "full_numbers"
}));
});
</script>
[% IF op == 'view' %]