From 16592d267ab3d7def36a99d1c9e19bfca2997764 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Tue, 8 Aug 2023 11:15:12 +0000 Subject: [PATCH] Bug 34587: Accept date inputs upon confirming 'run now' button Signed-off-by: Jessica Zairo Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- Koha/BackgroundJob/ErmSushiHarvester.pm | 2 ++ Koha/ERM/UsageDataProvider.pm | 14 +++++--- Koha/REST/V1/ERM/UsageDataProviders.pm | 13 +++++++- .../paths/erm_usage_data_providers.yaml | 28 +++++++++------- .../ERM/UsageStatisticsDataProvidersList.vue | 32 ++++++++++++++++--- .../prog/js/vue/fetch/erm-api-client.js | 16 ++++------ 6 files changed, 73 insertions(+), 32 deletions(-) diff --git a/Koha/BackgroundJob/ErmSushiHarvester.pm b/Koha/BackgroundJob/ErmSushiHarvester.pm index 2501bfecd0..0f8e2916b9 100644 --- a/Koha/BackgroundJob/ErmSushiHarvester.pm +++ b/Koha/BackgroundJob/ErmSushiHarvester.pm @@ -76,6 +76,8 @@ sub process { Koha::ERM::UsageDataProviders->find( $args->{ud_provider_id} ); $ud_provider->harvest( + $args->{begin_date}, + $args->{end_date}, $args->{report_type}, { report_info_callback => sub { $self->report_info(@_); }, diff --git a/Koha/ERM/UsageDataProvider.pm b/Koha/ERM/UsageDataProvider.pm index 62ade581c0..f7406e43b8 100644 --- a/Koha/ERM/UsageDataProvider.pm +++ b/Koha/ERM/UsageDataProvider.pm @@ -106,7 +106,9 @@ sub enqueue_sushi_harvest_jobs { my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue( { ud_provider_id => $self->erm_usage_data_provider_id, - report_type => $report_type + report_type => $report_type, + begin_date => $args->{begin_date}, + end_date => $args->{end_date}, } ); @@ -157,11 +159,13 @@ Receive background_job_callbacks to be able to update job =cut sub harvest { - my ( $self, $report_type, $background_job_callbacks ) = @_; + my ( $self, $begin_date, $end_date, $report_type, $background_job_callbacks ) = @_; # Set class wide vars $self->{job_callbacks} = $background_job_callbacks; - $self->{report_type} = $report_type; + $self->{report_type} = $report_type; + $self->{begin_date} = $begin_date; + $self->{end_date} = $end_date; my $url = $self->_build_url_query; my $request = HTTP::Request->new( 'GET' => $url ); @@ -274,8 +278,8 @@ sub _build_url_query { $url .= '?customer_id=' . $self->customer_id; $url .= '&requestor_id=' . $self->requestor_id if $self->requestor_id; $url .= '&api_key=' . $self->api_key if $self->api_key; - $url .= '&begin_date=' . $self->begin_date if $self->begin_date; - $url .= '&end_date=' . $self->end_date if $self->end_date; + $url .= '&begin_date=' . $self->{begin_date} if $self->{begin_date}; + $url .= '&end_date=' . $self->{end_date} if $self->{end_date}; return $url; } diff --git a/Koha/REST/V1/ERM/UsageDataProviders.pm b/Koha/REST/V1/ERM/UsageDataProviders.pm index 6a74145dd1..1a75a2b788 100644 --- a/Koha/REST/V1/ERM/UsageDataProviders.pm +++ b/Koha/REST/V1/ERM/UsageDataProviders.pm @@ -312,6 +312,17 @@ sub delete { sub run { my $c = shift->openapi->valid_input or return; + my $body = $c->validation->param('body'); + my $begin_date = $body->{begin_date}; + my $end_date = $body->{end_date}; + + unless ( $begin_date lt $end_date ) { + return $c->render( + status => 400, + openapi => { error => "Begin date must be before end date" } + ); + } + my $udprovider = Koha::ERM::UsageDataProviders->find( $c->validation->param('erm_usage_data_provider_id') ); unless ($udprovider) { @@ -322,7 +333,7 @@ sub run { } return try { - my $jobs = $udprovider->run; + my $jobs = $udprovider->run( { begin_date => $begin_date, end_date => $end_date } ); return $c->render( status => 200, diff --git a/api/v1/swagger/paths/erm_usage_data_providers.yaml b/api/v1/swagger/paths/erm_usage_data_providers.yaml index efcd91e3c1..779b335c5d 100644 --- a/api/v1/swagger/paths/erm_usage_data_providers.yaml +++ b/api/v1/swagger/paths/erm_usage_data_providers.yaml @@ -364,7 +364,7 @@ permissions: erm: 1 "/erm/usage_data_providers/{erm_usage_data_provider_id}/run": - get: + post: x-mojo-to: ERM::UsageDataProviders#run operationId: runUsageDataProviderHarvester tags: @@ -374,18 +374,22 @@ - application/json parameters: - $ref: "../swagger.yaml#/parameters/erm_usage_data_provider_id_pp" - - description: begin_date to run harvest - in: query - name: begin_date - required: true - type: string - format: date - - description: end_date to run harvest - in: query - name: end_date + - name: body + in: body + description: A JSON object with the begin and end dates required: true - type: string - format: date + schema: + type: object + properties: + begin_date: + type: string + description: begin date of the harvest + format: date + end_date: + type: string + description: end date of the harvest + format: date + additionalProperties: false responses: 200: description: Successful harvest run diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersList.vue index 86b23ac247..395ec9bd2d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersList.vue @@ -194,6 +194,7 @@ export default { } ) } else { + let date = new Date() this.setConfirmationDialog( { title: this.$__( @@ -202,13 +203,36 @@ export default { message: name, accept_label: this.$__("Yes, run"), cancel_label: this.$__("No, do not run"), + inputs: [ + { + id: "begin_date", + type: "Date", + value: null, + required: true, + label: this.$__("Begin date"), + }, + { + id: "end_date", + type: "Date", + value: $date_to_rfc3339($date(date.toString())), + required: true, + label: this.$__("End date"), + }, + ], }, - () => { + callback_result => { const client = APIClient.erm - // TODO: below begin_date and end_date need to be dynamic, or are they needed at all? - // FIXME: this is not even being used atm, API backend is using begin_date+end_date from data provider in database client.usage_data_providers - .run(id, "2022-01-01", "2023-06-15") + .run(id, { + begin_date: callback_result.inputs.find( + input => { + return input.id == "begin_date" + } + ).value, + end_date: callback_result.inputs.find(input => { + return input.id == "end_date" + }).value, + }) .then( success => { let message = "" diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js index 72ff91fe2e..379b2dce7c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js @@ -261,6 +261,7 @@ export class ERMAPIClient extends HttpClient { this.get({ endpoint: "usage_data_providers", query, + query, }), delete: id => this.delete({ @@ -276,15 +277,10 @@ export class ERMAPIClient extends HttpClient { endpoint: "usage_data_providers/" + id, body: usage_data_provider, }), - run: (id, begin_date, end_date) => - this.get({ - endpoint: - "usage_data_providers/" + - id + - "/run?begin_date=" + - begin_date + - "&end_date=" + - end_date, + run: (id, body) => + this.post({ + endpoint: "usage_data_providers/" + id + "/run", + body: body, }), test: id => this.get({ @@ -334,7 +330,7 @@ export class ERMAPIClient extends HttpClient { endpoint: "default_usage_reports", body: default_usage_report, }), - delete: (id) => + delete: id => this.delete({ endpoint: "default_usage_reports/" + id, }), -- 2.39.5