Koha/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt
Martin Renvoize a1543221bb
Bug 30982: (QA follow-up) Double quoting and console.log
This patch fixes the issues highlighted by the QA script; We use double
quotes for translatable strings in JS and remove an errant console.log
call.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-09-23 08:57:47 -03:00

479 lines
19 KiB
Text

[% USE raw %]
[% USE KohaDates %]
[% USE Asset %]
[% USE KohaDates %]
[% SET footerjs = 1 %]
[% BLOCK show_job_status %]
[% SWITCH job.status %]
[% CASE "new" %]
<span>New</span>
[% CASE "cancelled" %]
<span>Cancelled</span>
[% CASE "finished" %]
<span>Finished</span>
[% CASE "started" %]
<span>Started</span>
[% CASE "running" %]
<span>Running</span>
[% CASE "failed" %]
<span>Failed</span>
[% CASE # Default case %]
[% job.status | html %]
[% END -%]
[% END %]
[% BLOCK show_job_type %]
[% SWITCH job_type %]
[% CASE 'batch_biblio_record_modification' %]
<span>Batch bibliographic record modification</span>
[% CASE 'batch_biblio_record_deletion' %]
<span>Batch bibliographic record record deletion</span>
[% CASE 'batch_authority_record_modification' %]
<span>Batch authority record modification</span>
[% CASE 'batch_authority_record_deletion' %]
<span>Batch authority record deletion</span>
[% CASE 'batch_item_record_modification' %]
<span>Batch item record modification</span>
[% CASE 'batch_item_record_deletion' %]
<span>Batch item record deletion</span>
[% CASE "batch_hold_cancel" %]
<span>Batch hold cancellation</span>
[% CASE 'update_elastic_index' %]
<span>Update Elasticsearch index</span>
[% CASE 'update_holds_queue_for_biblios' %]
<span>Holds queue update</span>
[% CASE 'stage_marc_for_import' %]
<span>Staged MARC records for import</span>
[% CASE 'marc_import_commit_batch' %]
<span>Import MARC records</span>
[% CASE 'marc_import_revert_batch' %]
<span>Revert import MARC records</span>
[% CASE %]<span>Unknown job type '[% job_type | html %]'</span>
[% END %]
[% END %]
[% INCLUDE 'doc-head-open.inc' %]
<title>
[% IF op == 'view' %]
Details of job #[% job.id | html %] &rsaquo;
[% END %]
Background jobs &rsaquo;
Administration &rsaquo; Koha
</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body id="admin_background_jobs" class="admin">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'prefs-admin-search.inc' %]
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
<ol>
<li>
<a href="/cgi-bin/koha/mainpage.pl">Home</a>
</li>
[% IF CAN_user_parameters_manage_background_jobs %]
<li>
<a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
</li>
[% IF op == 'view' %]
<li>
<a href="/cgi-bin/koha/admin/background_jobs.pl">Background jobs</a>
</li>
<li>
<a href="#" aria-current="page">Details of job #[% job.id | html %]</a>
</li>
[% ELSE %]
<li>
<a href="#" aria-current="page">Background jobs</a>
</li>
[% END %]
[% ELSE %]
<li>
<a href="#" aria-current="page">Administration</a>
</li>
[% END %]
</ol>
</nav>
<div class="main container-fluid">
<div class="row">
<div class="col-sm-10 col-sm-push-2">
<main>
[% FOR m IN messages %]
<div class="dialog message">
[% SWITCH m.code %]
[% CASE 'cannot_view_job' %]
<div><i class="fa fa-exclamation error"></i>Insufficient permission to see this job.</div>
[% CASE %]
[% m.code | html %]
[% END %]
</div>
[% END %]
[% IF op == 'view' %]
<h1>Details of job #[% job.id | html %]</h1>
[% PROCESS "background_jobs/${job.type}.inc" %]
<fieldset class="rows">
<ol>
<li><span class="label">Job ID: </span>[% job.id | html %]</li>
<li>
<label for="job_status">Status: </label>
[% PROCESS show_job_status %]
</li>
<li><label for="job_progress">Progress: </label>[% job.progress || 0 | html %] / [% job.size | html %]</li>
<li>
<label for="job_type">Type: </label>
[% PROCESS show_job_type job_type => job.type %]
</li>
<li>
<label for="job_enqueued_on">Queued: </label>
[% job.enqueued_on | $KohaDates with_hours = 1 %]
</li>
<li>
<label for="job_started_on">Started: </label>
[% job.started_on | $KohaDates with_hours = 1 %]
</li>
<li>
<label for="job_ended_on">Ended: </label>
[% job.ended_on | $KohaDates with_hours = 1 %]
</li>
<li><label for="job_data">Report: </label>
[% IF job.status != 'new' %][% PROCESS 'report' %][% END %]
</li>
<li><label for="job_data">Detailed messages: </label>
[% IF job.status != 'new' %][% PROCESS 'detail' %][% END %]
</li>
</ol>
</fieldset>
[% IF CAN_user_parameters_manage_background_jobs %]
<fieldset class="action">
<a href="/cgi-bin/koha/admin/background_jobs.pl">Return to the job list</a>
</fieldset>
[% END %]
[% END %]
[% IF op == 'list' %]
<h1>Background jobs</h1>
<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 %]
</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>
</div>
<label for="include_last_hour">Only include jobs started in the last hour</label>
<input type="checkbox" id="include_last_hour" checked />
<table id="table_jobs">
<thead>
<tr>
<th>Job ID</th>
<th data-filter="job_statuses">Status</th>
<th>Progress</th>
<th data-filter="job_types">Type</th>
<th>Queued</th>
<th>Started</th>
<th>Ended</th>
<th class="noExport">Actions</th>
</tr>
</thead>
</table>
[% END %]
</main>
</div> <!-- /.col-sm-10.col-sm-push-2 -->
<div class="col-sm-2 col-sm-pull-10">
<aside>
[% INCLUDE 'admin-menu.inc' %]
</aside>
</div> <!-- /.col-sm-2.col-sm-pull-10 -->
</div> <!-- /.row -->
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/admin-menu.js") | $raw %]
[% INCLUDE 'js-date-format.inc' %]
[% INCLUDE 'datatables.inc' %]
<script>
$(document).ready(function() {
$("#table_queued_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
"aoColumnDefs": [
{ "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
],
"aaSorting": [[ 0, "desc" ]],
"iDisplayLength": 10,
"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"
}));
});
const job_statuses = [
{'_id': 'new', '_str': _("New")},
{'_id': 'cancelled', '_str': _("Cancelled")},
{'_id': 'finished', '_str': _("Finished")},
{'_id': 'started', '_str': _("Started")},
{'_id': 'running', '_str': _("Running")},
{'_id': 'failed', '_str': _("Failed")},
];
function get_job_status (status) {
let status_lib = job_statuses.find( s => s._id == status );
if (status_lib) {
return status_lib._str;
}
return status;
}
const job_types = [
{
'_id': 'batch_biblio_record_modification',
'_str': _("Batch bibliographic record modification")
},
{
'_id': 'batch_biblio_record_deletion',
'_str': _("Batch bibliographic record record deletion")
},
{
'_id': 'batch_authority_record_modification',
'_str': _("Batch authority record modification")
},
{
'_id': 'batch_authority_record_deletion',
'_str': _("Batch authority record deletion")
},
{
'_id': 'batch_item_record_modification',
'_str': _("Batch item record modification")
},
{
'_id': 'batch_item_record_deletion',
'_str': _("Batch item record deletion")
},
{
'_id': 'batch_hold_cancel',
'_str': _("Batch hold cancellation")
},
{
'_id': 'update_elastic_index'
, '_str': _("Update Elasticsearch index")
},
{
'_id': 'update_holds_queue_for_biblios',
'_str': _("Holds queue update")
}
];
function get_job_type (job_type) {
let job_type_lib = job_types.find( t => t._id == job_type );
if ( job_type_lib ) {
return job_type_lib._str;
}
return _("Unknown job type '%s'").format(job_type);
}
$(document).ready(function() {
let additional_filters = {
started_on: function(){
let now = new Date();
if ( $("#include_last_hour").is(":checked") ) {
now.setHours(now.getHours() - 1);
return { ">": now.toISOString() };
} else {
return { "<": now.toISOString() };
}
},
};
let jobs_table = $("#table_jobs").kohaTable({
"ajax": {
"url": "/api/v1/background_jobs"
},
"order": [[ 1, "desc" ]],
"columns": [
{
"data": "background_job_id",
"searchable": true,
"orderable": true
},
{
"data": "status",
"searchable": true,
"orderable": true,
"render": function(data, type, row, meta) {
return get_job_status(row.status).escapeHtml();
},
},
{
"data": "progress,size",
"searchable": false,
"orderable": true,
"render": function(data, type, row, meta) {
return "%s/%s".format(row.progress, row.size).escapeHtml();
},
},
{
"data": "type",
"searchable": true,
"orderable": true,
"render": function(data, type, row, meta) {
return get_job_type(row.type).escapeHtml();
},
},
{
"data": "enqueued_on",
"searchable": true,
"orderable": true,
"render": function(data, type, row, meta) {
return $datetime(row.enqueued_on);
},
},
{
"data": "started_on",
"searchable": true,
"orderable": true,
"render": function(data, type, row, meta) {
return $datetime(row.started_on);
},
},
{
"data": "ended_on",
"searchable": true,
"orderable": true,
"render": function(data, type, row, meta) {
return $datetime(row.ended_on);
},
},
{
"data": function( row, type, val, meta ) {
var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&amp;id='+ encodeURIComponent(row.background_job_id) +'"><i class="fa fa-eye" aria-hidden="true"></i> '+_("View")+'</a>'+"\n";
if ( row.status == 'new' || row.status == 'started' ) {
result += '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/bakcground_jobs.pl?op=cancel&amp;id='+ encodeURIComponent(row.background_job_id) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Cancel")+'</a>';
}
return result;
},
"searchable": false,
"orderable": false
}
]
}, null, 1, additional_filters);
$("#include_last_hour").on("change", function(){
jobs_table.DataTable().draw();
return false;
});
</script>
[% IF op == 'view' %]
[% PROCESS 'js' %]
[% END %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]