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

Return to bug 30982