Bug 30982: Rename 'Background Jobs' => 'Jobs'
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / background_jobs.tt
1 [% USE raw %]
2 [% USE KohaDates %]
3 [% USE Asset %]
4 [% USE KohaDates %]
5 [% SET footerjs = 1 %]
6 [% BLOCK show_job_status %]
7     [% SWITCH job.status %]
8         [% CASE "new" %]
9             <span>New</span>
10         [% CASE "cancelled" %]
11             <span>Cancelled</span>
12         [% CASE "finished" %]
13             <span>Finished</span>
14         [% CASE "started" %]
15             <span>Started</span>
16         [% CASE "running" %]
17             <span>Running</span>
18         [% CASE "failed" %]
19             <span>Failed</span>
20         [% CASE # Default case %]
21             [% job.status | html %]
22     [% END -%]
23 [% END %]
24 [% BLOCK show_job_type %]
25     [% SWITCH job_type %]
26     [% CASE 'batch_biblio_record_modification' %]
27         <span>Batch bibliographic record modification</span>
28     [% CASE 'batch_biblio_record_deletion' %]
29         <span>Batch bibliographic record record deletion</span>
30     [% CASE 'batch_authority_record_modification' %]
31         <span>Batch authority record modification</span>
32     [% CASE 'batch_authority_record_deletion' %]
33         <span>Batch authority record deletion</span>
34     [% CASE 'batch_item_record_modification' %]
35         <span>Batch item record modification</span>
36     [% CASE 'batch_item_record_deletion' %]
37         <span>Batch item record deletion</span>
38     [% CASE "batch_hold_cancel" %]
39         <span>Batch hold cancellation</span>
40     [% CASE 'update_elastic_index' %]
41         <span>Update Elasticsearch index</span>
42     [% CASE 'update_holds_queue_for_biblios' %]
43         <span>Holds queue update</span>
44     [% CASE 'stage_marc_for_import' %]
45         <span>Staged MARC records for import</span>
46     [% CASE 'marc_import_commit_batch' %]
47         <span>Import MARC records</span>
48     [% CASE 'marc_import_revert_batch' %]
49         <span>Revert import MARC records</span>
50     [% CASE %]<span>Unknown job type '[% job_type | html %]'</span>
51     [% END %]
52
53 [% END %]
54 [% INCLUDE 'doc-head-open.inc' %]
55 <title>
56     [% IF op == 'view' %]
57         Details of job #[% job.id | html %] &rsaquo;
58     [% END %]
59     Jobs &rsaquo;
60     Administration &rsaquo; Koha
61 </title>
62
63 [% INCLUDE 'doc-head-close.inc' %]
64 </head>
65
66 <body id="admin_background_jobs" class="admin">
67 [% INCLUDE 'header.inc' %]
68 [% INCLUDE 'prefs-admin-search.inc' %]
69
70 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
71     <ol>
72         <li>
73             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
74         </li>
75
76     [% IF CAN_user_parameters_manage_background_jobs %]
77         <li>
78             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
79         </li>
80         [% IF op == 'view' %]
81             <li>
82                 <a href="/cgi-bin/koha/admin/background_jobs.pl">Jobs</a>
83             </li>
84             <li>
85                 <a href="#" aria-current="page">Details of job #[% job.id | html %]</a>
86             </li>
87         [% ELSE %]
88             <li>
89                 <a href="#" aria-current="page">Jobs</a>
90             </li>
91         [% END %]
92     [% ELSE %]
93         <li>
94             <a href="#" aria-current="page">Administration</a>
95         </li>
96     [% END %]
97     </ol>
98 </nav>
99
100 <div class="main container-fluid">
101     <div class="row">
102         <div class="col-sm-10 col-sm-push-2">
103             <main>
104
105 [% FOR m IN messages %]
106     <div class="dialog message">
107         [% SWITCH m.code %]
108         [% CASE 'cannot_view_job' %]
109             <div><i class="fa fa-exclamation error"></i>Insufficient permission to see this job.</div>
110         [% CASE %]
111             [% m.code | html %]
112         [% END %]
113     </div>
114 [% END %]
115
116 [% IF op == 'view' %]
117     <h1>Details of job #[% job.id | html %]</h1>
118
119     [% PROCESS "background_jobs/${job.type}.inc" %]
120
121     <fieldset class="rows">
122         <ol>
123             <li><span class="label">Job ID: </span>[% job.id | html %]</li>
124             <li>
125                 <label for="job_status">Status: </label>
126                 [% PROCESS show_job_status %]
127             </li>
128             <li><label for="job_progress">Progress: </label>[% job.progress || 0 | html %] / [% job.size | html %]</li>
129             <li>
130                 <label for="job_type">Type: </label>
131                 [% PROCESS show_job_type job_type => job.type %]
132             </li>
133             <li>
134                 <label for="job_enqueued_on">Queued: </label>
135                 [% job.enqueued_on | $KohaDates with_hours = 1 %]
136             </li>
137             <li>
138                 <label for="job_started_on">Started: </label>
139                 [% job.started_on | $KohaDates with_hours = 1 %]
140             </li>
141             <li>
142                 <label for="job_ended_on">Ended: </label>
143                 [% job.ended_on | $KohaDates with_hours = 1 %]
144             </li>
145             <li><label for="job_data">Report: </label>
146                 [% IF job.status != 'new' %][% PROCESS 'report' %][% END %]
147             </li>
148             <li><label for="job_data">Detailed messages: </label>
149                 [% IF job.status != 'new' %][% PROCESS 'detail' %][% END %]
150             </li>
151         </ol>
152     </fieldset>
153
154     [% IF CAN_user_parameters_manage_background_jobs %]
155         <fieldset class="action">
156             <a href="/cgi-bin/koha/admin/background_jobs.pl">Return to the job list</a>
157         </fieldset>
158     [% END %]
159 [% END %]
160
161 [% IF op == 'list' %]
162
163     <h1>Jobs</h1>
164
165     <div>
166         <input type="checkbox" id="only_current" checked />
167         <label for="only_current">Current jobs only</label>
168     </div>
169
170     <div>
171         <input type="checkbox" id="include_last_hour" checked />
172         <label for="include_last_hour">Only include jobs started in the last hour</label>
173     </div>
174
175     <table id="table_jobs">
176         <thead>
177             <tr>
178                 <th>Job ID</th>
179                 <th data-filter="job_statuses">Status</th>
180                 <th>Progress</th>
181                 <th data-filter="job_types">Type</th>
182                 <th>Queued</th>
183                 <th>Started</th>
184                 <th>Ended</th>
185                 <th class="noExport">Actions</th>
186             </tr>
187         </thead>
188     </table>
189 [% END %]
190
191             </main>
192         </div> <!-- /.col-sm-10.col-sm-push-2 -->
193
194         <div class="col-sm-2 col-sm-pull-10">
195             <aside>
196                 [% INCLUDE 'admin-menu.inc' %]
197             </aside>
198         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
199      </div> <!-- /.row -->
200
201 [% MACRO jsinclude BLOCK %]
202     [% Asset.js("js/admin-menu.js") | $raw %]
203     [% INCLUDE 'js-date-format.inc' %]
204     [% INCLUDE 'datatables.inc' %]
205     <script>
206         const job_statuses = [
207             {'_id': 'new',       '_str': _("New")},
208             {'_id': 'cancelled', '_str': _("Cancelled")},
209             {'_id': 'finished',  '_str': _("Finished")},
210             {'_id': 'started',   '_str': _("Started")},
211             {'_id': 'running',   '_str': _("Running")},
212             {'_id': 'failed',    '_str': _("Failed")},
213         ];
214         function get_job_status (status) {
215             let status_lib = job_statuses.find( s => s._id == status );
216             if (status_lib) {
217                 return status_lib._str;
218             }
219             return status;
220         }
221
222         const job_types = [
223             {
224                 '_id': 'batch_biblio_record_modification',
225                 '_str': _("Batch bibliographic record modification")
226             },
227             {
228                 '_id': 'batch_biblio_record_deletion',
229                 '_str': _("Batch bibliographic record record deletion")
230             },
231             {
232                 '_id': 'batch_authority_record_modification',
233                 '_str': _("Batch authority record modification")
234             },
235             {
236                 '_id': 'batch_authority_record_deletion',
237                 '_str': _("Batch authority record deletion")
238             },
239             {
240                 '_id': 'batch_item_record_modification',
241                 '_str': _("Batch item record modification")
242             },
243             {
244                 '_id': 'batch_item_record_deletion',
245                 '_str': _("Batch item record deletion")
246             },
247             {
248                 '_id': 'batch_hold_cancel',
249                 '_str': _("Batch hold cancellation")
250             },
251             {
252                 '_id': 'update_elastic_index'
253                 , '_str': _("Update Elasticsearch index")
254             },
255             {
256                 '_id': 'update_holds_queue_for_biblios',
257                 '_str': _("Holds queue update")
258             }
259         ];
260
261         function get_job_type (job_type) {
262             let job_type_lib = job_types.find( t => t._id == job_type );
263             if ( job_type_lib ) {
264                 return job_type_lib._str;
265             }
266             return _("Unknown job type '%s'").format(job_type);
267         }
268
269         $(document).ready(function() {
270             let additional_filters = {
271                 started_on: function(){
272                     let now = new Date();
273                     if ( $("#include_last_hour").is(":checked") ) {
274                         now.setHours(now.getHours() - 1);
275                         return { ">": now.toISOString() };
276                     } else {
277                         return { "<": now.toISOString() };
278                     }
279                 }
280             };
281
282             let only_current_filter = function(){
283                 if ( $("#only_current").is(":checked") ) {
284                     return 'only_current=1';
285                 } else {
286                     return 'only_current=0';
287                 }
288             }
289
290             let jobs_table = $("#table_jobs").kohaTable({
291                 "ajax": {
292                     "url": "/api/v1/jobs?" + only_current_filter()
293                 },
294                 "order": [[ 1, "desc" ]],
295                 "columns": [
296                     {
297                         "data": "job_id",
298                         "searchable": true,
299                         "orderable": true
300                     },
301                     {
302                         "data": "status",
303                         "searchable": true,
304                         "orderable": true,
305                         "render": function(data, type, row, meta) {
306                             return get_job_status(row.status).escapeHtml();
307                         }
308                     },
309                     {
310                         "data": "progress,size",
311                         "searchable": false,
312                         "orderable": true,
313                         "render": function(data, type, row, meta) {
314                             return "%s/%s".format(row.progress, row.size).escapeHtml();
315                         }
316                     },
317                     {
318                         "data": "type",
319                         "searchable": true,
320                         "orderable": true,
321                         "render": function(data, type, row, meta) {
322                             return get_job_type(row.type).escapeHtml();
323                         }
324                     },
325                     {
326                         "data": "enqueued_date",
327                         "searchable": true,
328                         "orderable": true,
329                         "render": function(data, type, row, meta) {
330                             return $datetime(row.enqueued_date);
331                         }
332                     },
333                     {
334                         "data": "started_date",
335                         "searchable": true,
336                         "orderable": true,
337                         "render": function(data, type, row, meta) {
338                             return $datetime(row.started_date);
339                         }
340                     },
341                     {
342                         "data": "ended_date",
343                         "searchable": true,
344                         "orderable": true,
345                         "render": function(data, type, row, meta) {
346                             return $datetime(row.ended_date);
347                         }
348                     },
349                     {
350                         "data": function( row, type, val, meta ) {
351                             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.job_id) +'"><i class="fa fa-eye" aria-hidden="true"></i> '+_("View")+'</a>'+"\n";
352                             if ( row.status == 'new' || row.status == 'started' ) {
353                                 result += '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/bakcground_jobs.pl?op=cancel&amp;id='+ encodeURIComponent(row.job_id) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Cancel")+'</a>';
354                             }
355                             return result;
356                         },
357                         "searchable": false,
358                         "orderable": false
359                     }
360                 ]
361             }, null, 1, additional_filters);
362
363             $("#include_last_hour").on("change", function(){
364                 jobs_table.DataTable().draw();
365                 return false;
366             });
367
368             $("#only_current").on("change", function(){
369                 jobs_table.DataTable().ajax.url("/api/v1/jobs?" + only_current_filter()).load();
370                 return false;
371             });
372         });
373     </script>
374     [% IF op == 'view' %]
375         [% PROCESS 'js' %]
376     [% END %]
377 [% END %]
378
379 [% INCLUDE 'intranet-bottom.inc' %]