Bugzilla – Attachment 140497 Details for
Bug 30982
Use the REST API for background job list view
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30982: Adapt table to new API spec
Bug-30982-Adapt-table-to-new-API-spec.patch (text/plain), 13.39 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-09-12 18:09:38 UTC
(
hide
)
Description:
Bug 30982: Adapt table to new API spec
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-09-12 18:09:38 UTC
Size:
13.39 KB
patch
obsolete
>From 354af20bf1389a8fc1f6368ce708d177c203d3d9 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 12 Sep 2022 14:54:08 -0300 >Subject: [PATCH] Bug 30982: Adapt table to new API spec > >Disclaimer: this patch is highly opinionated :-D > >When I started looking at this patch I felt like the two tables >(current/past jobs) implemented on bug 30462 was the way to go. > >In order to make this patches apply after it I had to redo all the >things. Or most of them. > >But I decided to keep the idea of filtering out completed tasks, not >just having the option to display 'the last hour' tasks. For the task I >added some required helper methods and the relevant tests as well. So a >behavior change. > >Hope you all agree with it. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > .../prog/en/modules/admin/background_jobs.tt | 178 ++++-------------- > 1 file changed, 39 insertions(+), 139 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >index 3456fed233..7922a2e80e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >@@ -156,108 +156,15 @@ > > <h1>Background jobs</h1> > >- <div id="taskstabs" class="toptabs"> >- <ul class="nav nav-tabs" role="tablist"> >- <li role="presentation" class="active"><a href="#queued" aria-controls="queued" role="tab" data-toggle="tab">Queued jobs</a></li> >- <li role="presentation"><a href="#complete" aria-controls="complete" role="tab" data-toggle="tab">Completed jobs</a></li> >- </ul> >- >- <div class="tab-content"> >- <div role="tabpanel" class="tab-pane active" id="queued"> >- [% IF queued.count %] >- <table id="table_queued_jobs"> >- <thead> >- <tr> >- <th>Job ID</th> >- <th>Status</th> >- <th>Progress</th> >- <th>Type</th> >- <th>Queued</th> >- <th>Started</th> >- <th class="noExport">Actions</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH job IN queued %] >- <tr> >- <td>[% job.id | html %]</td> >- <td> >- [% PROCESS show_job_status %] >- </td> >- <td>[% job.progress || 0 | html %] / [% job.size | html %]</td> >- <td> >- [% PROCESS show_job_type job_type => job.type %] >- </td> >- <td>[% job.enqueued_on | $KohaDates with_hours = 1 %]</td> >- <td>[% job.started_on| $KohaDates with_hours = 1 %]</td> >- <td class="actions"> >- <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a> >- [% IF job.status == 'new' || job.status == 'started' %] >- <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&id=[% job.id | html %]"><i class="fa fa-trash"></i> Cancel</a> >- [% END %] >- </td> >- </tr> >- [% END %] >- </tbody> >- </table> >- [% ELSE %] >- <div class="dialog message"> >- There are no queued background jobs yet. >- </div> >- [% END %] >- </div> >- >- <div role="tabpanel" class="tab-pane" id="complete"> >- [% IF complete.count %] >- <p>Jobs completed in the last 60 minutes.</p> >- <table id="table_complete_jobs"> >- <thead> >- <tr> >- <th>Job ID</th> >- <th>Status</th> >- <th>Progress</th> >- <th>Type</th> >- <th>Queued</th> >- <th>Started</th> >- <th>Ended</th> >- <th class="noExport">Actions</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH job IN complete %] >- <tr> >- <td>[% job.id | html %]</td> >- <td> >- [% PROCESS show_job_status %] >- </td> >- <td>[% job.progress || 0 | html %] / [% job.size | html %]</td> >- <td> >- [% PROCESS show_job_type job_type => job.type %] >- </td> >- <td>[% job.enqueued_on | $KohaDates with_hours = 1 %]</td> >- <td>[% job.started_on| $KohaDates with_hours = 1 %]</td> >- <td>[% job.ended_on| $KohaDates with_hours = 1 %]</td> >- <td class="actions"> >- <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a> >- [% IF job.status == 'new' || job.status == 'started' %] >- <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&id=[% job.id | html %]"><i class="fa fa-trash"></i> Cancel</a> >- [% END %] >- </td> >- </tr> >- [% END %] >- </tbody> >- </table> >- [% ELSE %] >- <div class="dialog message"> >- There were no completed background jobs completed in the last 60 minutes. >- </div> >- [% END %] >- </div> >- </div> >+ <div> >+ <input type="checkbox" id="only_current" checked /> >+ <label for="only_current">Current jobs only</label> > </div> > >- <label for="include_last_hour">Only include jobs started in the last hour</label> >- <input type="checkbox" id="include_last_hour" checked /> >+ <div> >+ <input type="checkbox" id="include_last_hour" checked /> >+ <label for="include_last_hour">Only include jobs started in the last hour</label> >+ </div> > > <table id="table_jobs"> > <thead> >@@ -290,26 +197,6 @@ > [% INCLUDE 'js-date-format.inc' %] > [% INCLUDE 'datatables.inc' %] > <script> >- $(document).ready(function() { >- $("#table_queued_jobs").dataTable($.extend(true, {}, dataTablesDefaults, { >- "aoColumnDefs": [ >- { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false }, >- ], >- "aaSorting": [[ 0, "desc" ]], >- "iDisplayLength": 10, >- "sPaginationType": "full_numbers" >- })); >- >- $("#table_complete_jobs").dataTable($.extend(true, {}, dataTablesDefaults, { >- "aoColumnDefs": [ >- { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false }, >- ], >- "aaSorting": [[ 0, "desc" ]], >- "iDisplayLength": 10, >- "sPaginationType": "full_numbers" >- })); >- }); >- > const job_statuses = [ > {'_id': 'new', '_str': _("New")}, > {'_id': 'cancelled', '_str': _("Cancelled")}, >@@ -383,16 +270,25 @@ > } else { > return { "<": now.toISOString() }; > } >- }, >+ } > }; >+ >+ let only_current_filter = function(){ >+ if ( $("#only_current").is(":checked") ) { >+ return 'only_current=1'; >+ } else { >+ return 'only_current=0'; >+ } >+ } >+ > let jobs_table = $("#table_jobs").kohaTable({ > "ajax": { >- "url": "/api/v1/background_jobs" >+ "url": "/api/v1/jobs?" + only_current_filter() > }, > "order": [[ 1, "desc" ]], > "columns": [ > { >- "data": "background_job_id", >+ "data": "job_id", > "searchable": true, > "orderable": true > }, >@@ -402,7 +298,7 @@ > "orderable": true, > "render": function(data, type, row, meta) { > return get_job_status(row.status).escapeHtml(); >- }, >+ } > }, > { > "data": "progress,size", >@@ -410,7 +306,7 @@ > "orderable": true, > "render": function(data, type, row, meta) { > return "%s/%s".format(row.progress, row.size).escapeHtml(); >- }, >+ } > }, > { > "data": "type", >@@ -418,41 +314,39 @@ > "orderable": true, > "render": function(data, type, row, meta) { > return get_job_type(row.type).escapeHtml(); >- }, >+ } > }, > { >- "data": "enqueued_on", >+ "data": "enqueued_date", > "searchable": true, > "orderable": true, > "render": function(data, type, row, meta) { >- return $datetime(row.enqueued_on); >- }, >+ return $datetime(row.enqueued_date); >+ } > }, > { >- "data": "started_on", >+ "data": "started_date", > "searchable": true, > "orderable": true, > "render": function(data, type, row, meta) { >- return $datetime(row.started_on); >- }, >+ return $datetime(row.started_date); >+ } > }, >- > { >- "data": "ended_on", >+ "data": "ended_date", > "searchable": true, > "orderable": true, > "render": function(data, type, row, meta) { >- return $datetime(row.ended_on); >- }, >+ return $datetime(row.ended_date); >+ } > }, > { > "data": function( row, type, val, meta ) { >- var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id='+ encodeURIComponent(row.background_job_id) +'"><i class="fa fa-eye" aria-hidden="true"></i> '+_("View")+'</a>'+"\n"; >+ var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id='+ encodeURIComponent(row.job_id) +'"><i class="fa fa-eye" aria-hidden="true"></i> '+_("View")+'</a>'+"\n"; > if ( row.status == 'new' || row.status == 'started' ) { >- result += '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/bakcground_jobs.pl?op=cancel&id='+ encodeURIComponent(row.background_job_id) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Cancel")+'</a>'; >+ result += '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/bakcground_jobs.pl?op=cancel&id='+ encodeURIComponent(row.job_id) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Cancel")+'</a>'; > } > return result; >- > }, > "searchable": false, > "orderable": false >@@ -464,6 +358,12 @@ > jobs_table.DataTable().draw(); > return false; > }); >+ >+ $("#only_current").on("change", function(){ >+ jobs_table.DataTable().ajax.url("/api/v1/jobs?" + only_current_filter()).load(); >+ return false; >+ }); >+ }); > </script> > [% IF op == 'view' %] > [% PROCESS 'js' %] >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30982
:
136245
|
136246
|
136670
|
136671
|
136672
|
136707
|
136708
|
136715
|
138114
|
139636
|
139637
|
139638
|
139639
|
139640
|
139641
|
140488
|
140489
|
140490
|
140491
|
140492
|
140493
|
140494
|
140495
|
140496
|
140497
|
140498
|
140589
|
140590
|
140591
|
140592
|
140593
|
140594
|
140595
|
140596
|
140597
|
140598
|
140599
|
140789
|
140884
|
140885
|
140886
|
140887
|
140888
|
140889
|
140890
|
140891
|
140892
|
140893
|
140894
|
140895
|
140896
|
140897
|
142859