Bugzilla – Attachment 169190 Details for
Bug 36217
Jobs page include last hour filter does not work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Fix background jobs page's include_last_hour filter
0001-Fix-background-jobs-page-s-include_last_hour-filter.patch (text/plain), 6.79 KB, created by
Johanna Räisä
on 2024-07-19 09:55:33 UTC
(
hide
)
Description:
Fix background jobs page's include_last_hour filter
Filename:
MIME Type:
Creator:
Johanna Räisä
Created:
2024-07-19 09:55:33 UTC
Size:
6.79 KB
patch
obsolete
>From 4f2c1b3823c795de08b4e1d591cf91a610a0e888 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Johanna=20R=C3=A4is=C3=A4?= <johanna.raisa@gmail.com> >Date: Tue, 25 Apr 2023 13:00:24 +0300 >Subject: [PATCH] Fix background jobs page's include_last_hour filter > >Test plan: >1) Create a background job >2) Go to the background jobs page >3) See your job listed >4) Unselect "include_last_hour" from the filter >5) Verify that the job is not listed >6) Apply the patch >7) Repeat steps 1-3 >8) Verify that the job is now listed > >Sponsored-by: Koha-Suomi Oy >--- > Koha/BackgroundJobs.pm | 18 +++++++++ > Koha/REST/V1/BackgroundJobs.pm | 6 +++ > api/v1/swagger/paths/jobs.yaml | 5 +++ > .../prog/en/modules/admin/background_jobs.tt | 37 ++++++------------- > t/db_dependent/Koha/BackgroundJobs.t | 21 ++++++++++- > 5 files changed, 61 insertions(+), 26 deletions(-) > >diff --git a/Koha/BackgroundJobs.pm b/Koha/BackgroundJobs.pm >index 48afbf68fa..a7a5c0ccd0 100644 >--- a/Koha/BackgroundJobs.pm >+++ b/Koha/BackgroundJobs.pm >@@ -72,6 +72,24 @@ sub filter_by_current { > ); > } > >+=head3 filter_by_last_hour >+ >+ my $current_jobs = $jobs->filter_by_last_hour; >+ >+Returns a new resultset, filtering out jobs that were enqueued more than an hour ago. >+ >+=cut >+ >+sub filter_by_last_hour { >+ my ($self) = @_; >+ >+ return $self->search( >+ { >+ enqueued_on => { '>', \"NOW() - INTERVAL 1 HOUR" } >+ } >+ ); >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/Koha/REST/V1/BackgroundJobs.pm b/Koha/REST/V1/BackgroundJobs.pm >index 87d715e880..4fde5fcb9d 100644 >--- a/Koha/REST/V1/BackgroundJobs.pm >+++ b/Koha/REST/V1/BackgroundJobs.pm >@@ -39,7 +39,9 @@ sub list { > return try { > > my $only_current = $c->param('only_current'); >+ my $only_last_hour = $c->param('only_last_hour'); > $c->req->params->remove('only_current'); >+ $c->req->params->remove('only_last_hour'); > > my $bj_rs = Koha::BackgroundJobs->new; > >@@ -47,6 +49,10 @@ sub list { > $bj_rs = $bj_rs->filter_by_current; > } > >+ if ($only_last_hour) { >+ $bj_rs = $bj_rs->filter_by_last_hour; >+ } >+ > return $c->render( > status => 200, > openapi => $c->objects->search($bj_rs) >diff --git a/api/v1/swagger/paths/jobs.yaml b/api/v1/swagger/paths/jobs.yaml >index 8fe7e04841..8cee721dc0 100644 >--- a/api/v1/swagger/paths/jobs.yaml >+++ b/api/v1/swagger/paths/jobs.yaml >@@ -14,6 +14,11 @@ > required: false > type: boolean > description: Only include current jobs >+ - name: only_last_hour >+ in: query >+ required: false >+ type: boolean >+ description: Only include jobs started in the last hour > - $ref: "../swagger.yaml#/parameters/match" > - $ref: "../swagger.yaml#/parameters/order_by" > - $ref: "../swagger.yaml#/parameters/page" >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 e23f04ba41..6cf4e07049 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 >@@ -259,29 +259,21 @@ > $("#job_details").show(); > [% END %] > >- let additional_filters = { >- enqueued_on: function(){ >- let now = new Date(); >- if ( $("#include_last_hour").is(":checked") ) { >- now.setHours(now.getHours() - 1); >- return { ">": now.toISOString() }; >- } else { >- return { "<": now.toISOString() }; >- } >- } >- }; >- >- let only_current_filter = function(){ >- if ( $("#only_current").is(":checked") ) { >- return 'only_current=1'; >+ let query_filters = function(){ >+ if ( $("#only_current").is(":checked") && !$("#include_last_hour").is(":checked") ) { >+ return 'only_current=1&only_last_hour=0'; >+ } else if ( $("#include_last_hour").is(":checked") && !$("#only_current").is(":checked")) { >+ return 'only_current=0&only_last_hour=1'; >+ } else if ( $("#only_current").is(":checked") && $("#include_last_hour").is(":checked") ) { >+ return 'only_current=1&only_last_hour=1'; > } else { >- return 'only_current=0'; >+ return 'only_current=0&only_last_hour=0'; > } > } > > let jobs_table = $("#table_jobs").kohaTable({ > "ajax": { >- "url": "/api/v1/jobs?" + only_current_filter() >+ "url": "/api/v1/jobs?" + query_filters(), > }, > "order": [[ 1, "desc" ]], > "columns": [ >@@ -350,15 +342,10 @@ > "orderable": false > } > ] >- }, null, 1, additional_filters); >- >- $("#include_last_hour").on("change", function(){ >- jobs_table.DataTable().draw(); >- return false; >- }); >+ }, null, 1); > >- $("#only_current").on("change", function(){ >- jobs_table.DataTable().ajax.url("/api/v1/jobs?" + only_current_filter()).load(); >+ $("#only_current, #include_last_hour").on("change", function(){ >+ jobs_table.DataTable().ajax.url("/api/v1/jobs?" + query_filters()).load(); > return false; > }); > }); >diff --git a/t/db_dependent/Koha/BackgroundJobs.t b/t/db_dependent/Koha/BackgroundJobs.t >index c8089d4488..4658bc33d2 100755 >--- a/t/db_dependent/Koha/BackgroundJobs.t >+++ b/t/db_dependent/Koha/BackgroundJobs.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 14; >+use Test::More tests => 15; > use Test::MockModule; > > use List::MoreUtils qw(any); >@@ -123,6 +123,25 @@ subtest 'filter_by_current() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'filter_by_last_hour() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $job_now = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { enqueued_on => dt_from_string } } ); >+ my $job_old = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { enqueued_on => dt_from_string->subtract( hours => 2 ) } } ); >+ my $rs = Koha::BackgroundJobs->search( { id => [ $job_now->id, $job_old->id ] } ); >+ >+ is( $rs->count, 2, '2 jobs in resultset' ); >+ >+ $rs = $rs->filter_by_last_hour; >+ >+ is( $rs->count, 1, 'Only 1 job in filtered resultset' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'search_limited' => sub { > plan tests => 3; > >-- >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 36217
:
167526
|
169190
|
169549
|
169635
|
169694
|
171018
|
171019
|
171020
|
171297
|
171298
|
171299