View | Details | Raw Unified | Return to bug 30982
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt (-140 / +39 lines)
Lines 162-269 Link Here
162
162
163
    <h1>Background jobs</h1>
163
    <h1>Background jobs</h1>
164
164
165
    <div id="taskstabs" class="toptabs">
165
    <div>
166
        <ul class="nav nav-tabs" role="tablist">
166
        <input type="checkbox" id="only_current" checked />
167
            <li role="presentation" class="active"><a href="#queued" aria-controls="queued" role="tab" data-toggle="tab">Queued jobs</a></li>
167
        <label for="only_current">Current jobs only</label>
168
            <li role="presentation"><a href="#complete" aria-controls="complete" role="tab" data-toggle="tab">Completed jobs</a></li>
169
        </ul>
170
171
        <div class="tab-content">
172
            <div role="tabpanel" class="tab-pane active" id="queued">
173
                [% IF queued.count %]
174
                    <table id="table_queued_jobs">
175
                        <thead>
176
                            <tr>
177
                                <th>Job ID</th>
178
                                <th>Status</th>
179
                                <th>Progress</th>
180
                                <th>Type</th>
181
                                <th>Queued</th>
182
                                <th>Started</th>
183
                                <th class="noExport">Actions</th>
184
                            </tr>
185
                        </thead>
186
                        <tbody>
187
                            [% FOREACH job IN queued %]
188
                            <tr>
189
                                <td>[% job.id | html %]</td>
190
                                <td>
191
                                    [% PROCESS show_job_status %]
192
                                </td>
193
                                <td>[% job.progress || 0 | html %] / [% job.size | html %]</td>
194
                                <td>
195
                                    [% PROCESS show_job_type job_type => job.type %]
196
                                </td>
197
                                <td>[% job.enqueued_on | $KohaDates with_hours = 1 %]</td>
198
                                <td>[% job.started_on| $KohaDates with_hours = 1 %]</td>
199
                                <td class="actions">
200
                                    <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>
201
                                    [% IF job.status == 'new' || job.status == 'started' %]
202
                                        <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>
203
                                    [% END %]
204
                                </td>
205
                            </tr>
206
                            [% END %]
207
                        </tbody>
208
                    </table>
209
                [% ELSE %]
210
                    <div class="dialog message">
211
                        There are no queued background jobs yet.
212
                    </div>
213
                [% END %]
214
            </div>
215
216
            <div role="tabpanel" class="tab-pane" id="complete">
217
                [% IF complete.count %]
218
                    <p>Jobs completed in the last 60 minutes.</p>
219
                    <table id="table_complete_jobs">
220
                        <thead>
221
                            <tr>
222
                                <th>Job ID</th>
223
                                <th>Status</th>
224
                                <th>Progress</th>
225
                                <th>Type</th>
226
                                <th>Queued</th>
227
                                <th>Started</th>
228
                                <th>Ended</th>
229
                                <th class="noExport">Actions</th>
230
                            </tr>
231
                        </thead>
232
                        <tbody>
233
                            [% FOREACH job IN complete %]
234
                            <tr>
235
                                <td>[% job.id | html %]</td>
236
                                <td>
237
                                    [% PROCESS show_job_status %]
238
                                </td>
239
                                <td>[% job.progress || 0 | html %] / [% job.size | html %]</td>
240
                                <td>
241
                                    [% PROCESS show_job_type job_type => job.type %]
242
                                </td>
243
                                <td>[% job.enqueued_on | $KohaDates with_hours = 1 %]</td>
244
                                <td>[% job.started_on| $KohaDates with_hours = 1 %]</td>
245
                                <td>[% job.ended_on| $KohaDates with_hours = 1 %]</td>
246
                                <td class="actions">
247
                                    <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>
248
                                    [% IF job.status == 'new' || job.status == 'started' %]
249
                                        <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>
250
                                    [% END %]
251
                                </td>
252
                            </tr>
253
                            [% END %]
254
                        </tbody>
255
                    </table>
256
                [% ELSE %]
257
                    <div class="dialog message">
258
                        There were no completed background jobs completed in the last 60 minutes.
259
                    </div>
260
                [% END %]
261
            </div>
262
        </div>
263
    </div>
168
    </div>
264
169
265
    <label for="include_last_hour">Only include jobs started in the last hour</label>
170
    <div>
266
    <input type="checkbox" id="include_last_hour" checked />
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>
267
174
268
    <table id="table_jobs">
175
    <table id="table_jobs">
269
        <thead>
176
        <thead>
Lines 296-321 Link Here
296
    [% INCLUDE 'js-date-format.inc' %]
203
    [% INCLUDE 'js-date-format.inc' %]
297
    [% INCLUDE 'datatables.inc' %]
204
    [% INCLUDE 'datatables.inc' %]
298
    <script>
205
    <script>
299
        $(document).ready(function() {
300
            $("#table_queued_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
301
                "aoColumnDefs": [
302
                    { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
303
                ],
304
                "aaSorting": [[ 0, "desc" ]],
305
                "iDisplayLength": 10,
306
                "sPaginationType": "full_numbers"
307
            }));
308
309
            $("#table_complete_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
310
                "aoColumnDefs": [
311
                    { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
312
                ],
313
                "aaSorting": [[ 0, "desc" ]],
314
                "iDisplayLength": 10,
315
                "sPaginationType": "full_numbers"
316
            }));
317
        });
318
319
        const job_statuses = [
206
        const job_statuses = [
320
            {'_id': 'new',       '_str': _("New")},
207
            {'_id': 'new',       '_str': _("New")},
321
            {'_id': 'cancelled', '_str': _("Cancelled")},
208
            {'_id': 'cancelled', '_str': _("Cancelled")},
Lines 389-404 Link Here
389
                    } else {
276
                    } else {
390
                        return { "<": now.toISOString() };
277
                        return { "<": now.toISOString() };
391
                    }
278
                    }
392
                },
279
                }
393
            };
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
394
            let jobs_table = $("#table_jobs").kohaTable({
290
            let jobs_table = $("#table_jobs").kohaTable({
395
                "ajax": {
291
                "ajax": {
396
                    "url": "/api/v1/background_jobs"
292
                    "url": "/api/v1/jobs?" + only_current_filter()
397
                },
293
                },
398
                "order": [[ 1, "desc" ]],
294
                "order": [[ 1, "desc" ]],
399
                "columns": [
295
                "columns": [
400
                    {
296
                    {
401
                        "data": "background_job_id",
297
                        "data": "job_id",
402
                        "searchable": true,
298
                        "searchable": true,
403
                        "orderable": true
299
                        "orderable": true
404
                    },
300
                    },
Lines 408-414 Link Here
408
                        "orderable": true,
304
                        "orderable": true,
409
                        "render": function(data, type, row, meta) {
305
                        "render": function(data, type, row, meta) {
410
                            return get_job_status(row.status).escapeHtml();
306
                            return get_job_status(row.status).escapeHtml();
411
                        },
307
                        }
412
                    },
308
                    },
413
                    {
309
                    {
414
                        "data": "progress,size",
310
                        "data": "progress,size",
Lines 416-422 Link Here
416
                        "orderable": true,
312
                        "orderable": true,
417
                        "render": function(data, type, row, meta) {
313
                        "render": function(data, type, row, meta) {
418
                            return "%s/%s".format(row.progress, row.size).escapeHtml();
314
                            return "%s/%s".format(row.progress, row.size).escapeHtml();
419
                        },
315
                        }
420
                    },
316
                    },
421
                    {
317
                    {
422
                        "data": "type",
318
                        "data": "type",
Lines 424-464 Link Here
424
                        "orderable": true,
320
                        "orderable": true,
425
                        "render": function(data, type, row, meta) {
321
                        "render": function(data, type, row, meta) {
426
                            return get_job_type(row.type).escapeHtml();
322
                            return get_job_type(row.type).escapeHtml();
427
                        },
323
                        }
428
                    },
324
                    },
429
                    {
325
                    {
430
                        "data": "enqueued_on",
326
                        "data": "enqueued_date",
431
                        "searchable": true,
327
                        "searchable": true,
432
                        "orderable": true,
328
                        "orderable": true,
433
                        "render": function(data, type, row, meta) {
329
                        "render": function(data, type, row, meta) {
434
                            return $datetime(row.enqueued_on);
330
                            return $datetime(row.enqueued_date);
435
                        },
331
                        }
436
                    },
332
                    },
437
                    {
333
                    {
438
                        "data": "started_on",
334
                        "data": "started_date",
439
                        "searchable": true,
335
                        "searchable": true,
440
                        "orderable": true,
336
                        "orderable": true,
441
                        "render": function(data, type, row, meta) {
337
                        "render": function(data, type, row, meta) {
442
                            return $datetime(row.started_on);
338
                            return $datetime(row.started_date);
443
                        },
339
                        }
444
                    },
340
                    },
445
446
                    {
341
                    {
447
                        "data": "ended_on",
342
                        "data": "ended_date",
448
                        "searchable": true,
343
                        "searchable": true,
449
                        "orderable": true,
344
                        "orderable": true,
450
                        "render": function(data, type, row, meta) {
345
                        "render": function(data, type, row, meta) {
451
                            return $datetime(row.ended_on);
346
                            return $datetime(row.ended_date);
452
                        },
347
                        }
453
                    },
348
                    },
454
                    {
349
                    {
455
                        "data": function( row, type, val, meta ) {
350
                        "data": function( row, type, val, meta ) {
456
                            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";
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";
457
                            if ( row.status == 'new' || row.status == 'started' ) {
352
                            if ( row.status == 'new' || row.status == 'started' ) {
458
                                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>';
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>';
459
                            }
354
                            }
460
                            return result;
355
                            return result;
461
462
                        },
356
                        },
463
                        "searchable": false,
357
                        "searchable": false,
464
                        "orderable": false
358
                        "orderable": false
Lines 470-475 Link Here
470
                jobs_table.DataTable().draw();
364
                jobs_table.DataTable().draw();
471
                return false;
365
                return false;
472
            });
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
        });
473
    </script>
373
    </script>
474
    [% IF op == 'view' %]
374
    [% IF op == 'view' %]
475
        [% PROCESS 'js' %]
375
        [% PROCESS 'js' %]
476
- 

Return to bug 30982