d326d7090232aecb9e61176a2344e3ced5463df0
[koha-ffzg.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 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
25     <ol>
26         <li>
27             <a href="/cgi-bin/koha/mainpage.pl"><i class="fa fa-home"></i></a>
28         </li>
29
30     [% IF CAN_user_parameters_manage_background_jobs %]
31         <li>
32             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
33         </li>
34         [% IF op == 'view' %]
35             <li>
36                 <a href="/cgi-bin/koha/admin/background_jobs.pl">Jobs</a>
37             </li>
38             <li>
39                 <a href="#" aria-current="page">Details of job #[% job.id | html %]</a>
40             </li>
41         [% ELSE %]
42             <li>
43                 <a href="#" aria-current="page">Jobs</a>
44             </li>
45         [% END %]
46     [% ELSE %]
47         <li>
48             <a href="#" aria-current="page">Administration</a>
49         </li>
50     [% END %]
51     </ol>
52 </nav>
53 [% END %]
54
55 <div class="main container-fluid">
56     <div class="row">
57         <div class="col-sm-10 col-sm-push-2">
58             <main>
59
60 [% FOR m IN messages %]
61     <div class="dialog message">
62         [% SWITCH m.code %]
63         [% CASE 'cannot_view_job' %]
64             <div><i class="fa fa-exclamation error"></i>Insufficient permission to see this job.</div>
65         [% CASE %]
66             [% m.code | html %]
67         [% END %]
68     </div>
69 [% END %]
70
71 [% IF op == 'view' %]
72     <h1>Details of job #[% job.id | html %]</h1>
73
74     [% PROCESS "background_jobs/${job.type}.inc" %]
75
76     <fieldset class="rows" style="display:none;">
77         <ol>
78             <li><span class="label">Job ID: </span>[% job.id | html %]</li>
79             <li>
80                 <label for="job_status">Status: </label>
81                 <span id="job_status_description"></span>
82             </li>
83             <li><label for="job_progress">Progress: </label>[% job.progress || 0 | html %] / [% job.size | html %]</li>
84             <li>
85                 <label for="job_type">Type: </label>
86                 <span id="job_type_description"></span>
87             </li>
88             <li>
89                 <label for="job_enqueued_on">Queued: </label>
90                 [% job.enqueued_on | $KohaDates with_hours = 1 %]
91             </li>
92             <li>
93                 <label for="job_started_on">Started: </label>
94                 [% job.started_on | $KohaDates with_hours = 1 %]
95             </li>
96             <li>
97                 <label for="job_ended_on">Ended: </label>
98                 [% job.ended_on | $KohaDates with_hours = 1 %]
99             </li>
100             <li><label for="job_data">Report: </label>
101                 [% IF job.status != 'new' %][% PROCESS 'report' %][% END %]
102             </li>
103             <li><label for="job_data">Detailed messages: </label>
104                 [% IF job.status != 'new' %][% PROCESS 'detail' %][% END %]
105             </li>
106         </ol>
107     </fieldset>
108
109     [% IF CAN_user_parameters_manage_background_jobs %]
110         <fieldset class="action">
111             <a href="/cgi-bin/koha/admin/background_jobs.pl">Return to the job list</a>
112         </fieldset>
113     [% END %]
114 [% END %]
115
116 [% IF op == 'list' %]
117
118     <h1>Jobs</h1>
119
120     <div>
121         <input type="checkbox" id="only_current" checked />
122         <label for="only_current">Current jobs only</label>
123     </div>
124
125     <div>
126         <input type="checkbox" id="include_last_hour" checked />
127         <label for="include_last_hour">Only include jobs started in the last hour</label>
128     </div>
129
130     <table id="table_jobs">
131         <thead>
132             <tr>
133                 <th>Job ID</th>
134                 <th data-filter="job_statuses">Status</th>
135                 <th>Progress</th>
136                 <th data-filter="job_types">Type</th>
137                 <th>Queued</th>
138                 <th>Started</th>
139                 <th>Ended</th>
140                 <th class="noExport">Actions</th>
141             </tr>
142         </thead>
143     </table>
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 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': 'update_elastic_index',
208                 '_str': _("Update Elasticsearch index")
209             },
210             {
211                 '_id': 'update_holds_queue_for_biblios',
212                 '_str': _("Holds queue update")
213             },
214             {
215                 '_id': 'stage_marc_for_import',
216                 '_str': _("Staged MARC records for import")
217             },
218             {
219                 '_id': 'marc_import_commit_batch',
220                 '_str': _("Import MARC records")
221             },
222             {
223                 '_id': 'marc_import_revert_batch',
224                 '_str': _("Revert import MARC records")
225             },
226         ];
227
228         function get_job_type (job_type) {
229             let job_type_lib = job_types.find( t => t._id == job_type );
230             if ( job_type_lib ) {
231                 return job_type_lib._str;
232             }
233             return _("Unknown job type '%s'").format(job_type);
234         }
235
236         $(document).ready(function() {
237             [% IF op == 'view' %]
238                 $("#job_status_description").html( get_job_status("[% job.status | html %]") );
239                 $("#job_type_description").html( get_job_type("[% job.type | html %]") );
240                 $("fieldset.rows").show();
241             [% END %]
242
243             let additional_filters = {
244                 started_on: function(){
245                     let now = new Date();
246                     if ( $("#include_last_hour").is(":checked") ) {
247                         now.setHours(now.getHours() - 1);
248                         return { ">": now.toISOString() };
249                     } else {
250                         return { "<": now.toISOString() };
251                     }
252                 }
253             };
254
255             let only_current_filter = function(){
256                 if ( $("#only_current").is(":checked") ) {
257                     return 'only_current=1';
258                 } else {
259                     return 'only_current=0';
260                 }
261             }
262
263             let jobs_table = $("#table_jobs").kohaTable({
264                 "ajax": {
265                     "url": "/api/v1/jobs?" + only_current_filter()
266                 },
267                 "order": [[ 1, "desc" ]],
268                 "columns": [
269                     {
270                         "data": "job_id",
271                         "searchable": true,
272                         "orderable": true
273                     },
274                     {
275                         "data": "status",
276                         "searchable": true,
277                         "orderable": true,
278                         "render": function(data, type, row, meta) {
279                             return get_job_status(row.status).escapeHtml();
280                         }
281                     },
282                     {
283                         "data": "progress,size",
284                         "searchable": false,
285                         "orderable": true,
286                         "render": function(data, type, row, meta) {
287                             return "%s/%s".format(row.progress, row.size).escapeHtml();
288                         }
289                     },
290                     {
291                         "data": "type",
292                         "searchable": true,
293                         "orderable": true,
294                         "render": function(data, type, row, meta) {
295                             return get_job_type(row.type).escapeHtml();
296                         }
297                     },
298                     {
299                         "data": "enqueued_date",
300                         "searchable": true,
301                         "orderable": true,
302                         "render": function(data, type, row, meta) {
303                             return $datetime(row.enqueued_date);
304                         }
305                     },
306                     {
307                         "data": "started_date",
308                         "searchable": true,
309                         "orderable": true,
310                         "render": function(data, type, row, meta) {
311                             return $datetime(row.started_date);
312                         }
313                     },
314                     {
315                         "data": "ended_date",
316                         "searchable": true,
317                         "orderable": true,
318                         "render": function(data, type, row, meta) {
319                             return $datetime(row.ended_date);
320                         }
321                     },
322                     {
323                         "data": function( row, type, val, meta ) {
324                             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";
325                             if ( row.status == 'new' || row.status == 'started' ) {
326                                 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>';
327                             }
328                             return result;
329                         },
330                         "searchable": false,
331                         "orderable": false
332                     }
333                 ]
334             }, null, 1, additional_filters);
335
336             $("#include_last_hour").on("change", function(){
337                 jobs_table.DataTable().draw();
338                 return false;
339             });
340
341             $("#only_current").on("change", function(){
342                 jobs_table.DataTable().ajax.url("/api/v1/jobs?" + only_current_filter()).load();
343                 return false;
344             });
345         });
346     </script>
347     [% IF op == 'view' %]
348         [% PROCESS 'js' %]
349     [% END %]
350 [% END %]
351
352 [% INCLUDE 'intranet-bottom.inc' %]