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