Bug 40141

Summary: Add "Run" and "Test" buttons to data provider toolbar
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: ERMAssignee: Jan Kissig <jan.kissig>
Status: Pushed to main --- QA Contact: Paul Derscheid <paul.derscheid>
Severity: enhancement    
Priority: P5 - low CC: bibliothek, clemens.tubach, jonathan.druart, jonathan.field, lucas, martin.renvoize, mathsabypro, matt.blenkinsop, michaela.sieber, paul.derscheid, pedro.amorim
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
25.11.00
Circulation function:
Attachments: Bug 40141
Bug 40141
Bug 40141: This patch adds the SUSHI test and run options to the toolbar of the data providers detail page. If a provider is not active the buttons are disabled.
Bug 40141: Add "Run" and "Test" buttons to data provider toolbar

Description Katrin Fischer 2025-06-13 10:50:02 UTC
At the moment you can only "Test" and "Run" SUSHI connections and downloads from the data provider results list. It would be nice if these options would also be available directly from the detail view to save some clicks.
Comment 1 Jan Kissig 2025-10-13 09:01:43 UTC
Created attachment 187813 [details] [review]
Bug 40141

This patch adds the SUSHI test and run options to the toolbar of the data providers detail page.
If a provider is not active the buttons are disabled.
Comment 2 Jan Kissig 2025-10-13 17:40:24 UTC
missed the testplan:

- go to /cgi-bin/koha/erm/eusage/usage_data_providers
- add a dummy provider
- notice the toolbar on the data provider detail page: Only Edit and Delete are available
- apply the patch
- run 'yarn js:build'
- I needed to call 'restart_all'
- refresh the providers detail page and notice the two new buttons: Test and run now
- click on 'test' and wait for the result
- click on 'Run now' and enter some appropriate dates. 
- Click 'yes run' to see the jobs queued
- (Please do not dismiss the 'run now' dialog by clicking outside, as this triggers bug 41001)
Comment 3 Clemens Tubach 2025-10-14 09:22:47 UTC
Created attachment 187854 [details] [review]
Bug 40141

This patch adds the SUSHI test and run options to the toolbar of the data providers detail page.
If a provider is not active the buttons are disabled.

Signed-off-by: Clemens Tubach <clemens.tubach@kit.edu>
Comment 4 Michaela Sieber 2025-10-14 09:26:16 UTC
Thanks Jan! I have changed the Assignee from Jonathan to Jan. Tested and signed off :-)
Comment 5 Paul Derscheid 2025-10-14 13:59:01 UTC
Created attachment 187885 [details] [review]
Bug 40141: This patch adds the SUSHI test and run options to the toolbar of the data providers detail page.
If a provider is not active the buttons are disabled.

This patch adds the SUSHI test and run options to the toolbar of the data providers detail page.
If a provider is not active the buttons are disabled.

Signed-off-by: Clemens Tubach <clemens.tubach@kit.edu>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Comment 6 Paul Derscheid 2025-10-14 14:01:09 UTC
I have some things to note:
1. Maybe camel casing the functions would be more in line with the rest of the module.
2. I personally don't love the code duplication here but could maybe be consolidated in a follow up.

From a functionality standpoint this looks fine.
Comment 7 Pedro Amorim 2025-10-14 14:53:24 UTC
(In reply to Paul Derscheid from comment #6)
> I have some things to note:
> 1. Maybe camel casing the functions would be more in line with the rest of
> the module.
> 2. I personally don't love the code duplication here but could maybe be
> consolidated in a follow up.
> 
> From a functionality standpoint this looks fine.

I agree, but the eUsage part of ERM still needs to be moved into the bug 38201 framework. Until then I think these types of patches are to be expected.
Comment 8 Paul Derscheid 2025-10-14 14:56:49 UTC
Thanks for the additional context, Pedro! Was hoping one of you would take a peek :)
Comment 9 Jan Kissig 2025-10-14 16:19:34 UTC
(In reply to Paul Derscheid from comment #6)
> I have some things to note:
> 1. Maybe camel casing the functions would be more in line with the rest of
> the module.
> 2. I personally don't love the code duplication here but could maybe be
> consolidated in a follow up.
> 
> From a functionality standpoint this looks fine.

Thanks Paul, 
yeah I agree about that. I followed the kebab-case as the other functions were already kebab-case in UsageStatisticsDataProvidersShow.vue
Comment 10 Lucas Gass (lukeg) 2025-10-14 20:39:56 UTC
Can this patch include a description of what it does? "Bug 40141" isn't very descriptive.
Comment 11 Jan Kissig 2025-10-14 20:52:34 UTC
Comment on attachment 187813 [details] [review]
Bug 40141

>From c913963f4876dc89a77e064776f8464a86892295 Mon Sep 17 00:00:00 2001
>From: Jan Kissig <bibliothek@th-wildau.de>
>Date: Mon, 13 Oct 2025 08:31:58 +0000
>Subject: [PATCH] Bug 40141:
>
>This patch adds the SUSHI test and run options to the toolbar of the data providers detail page.
>If a provider is not active the buttons are disabled.
>---
> .../ERM/UsageStatisticsDataProvidersShow.vue  | 122 ++++++++++++++++++
> 1 file changed, 122 insertions(+)
>
>diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersShow.vue
>index f640f3ea659..95f3935f63e 100644
>--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersShow.vue
>+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersShow.vue
>@@ -23,6 +23,29 @@
>                 class="btn btn-default"
>                 ><font-awesome-icon icon="trash" /> {{ $__("Delete") }}</a
>             >
>+            <button
>+                @click="
>+                    test_usage_data_provider(
>+                        usage_data_provider.erm_usage_data_provider_id,
>+                        usage_data_provider.name
>+                    )
>+                "
>+                class="btn btn-default"
>+                :disabled="!usage_data_provider.active"
>+            >
>+                <i class="fa fa-check"></i> {{ $__("Test") }}
>+            </button>
>+            <button
>+                @click="
>+                    run_harvester(
>+                        usage_data_provider.erm_usage_data_provider_id
>+                    )
>+                "
>+                class="btn btn-default"
>+                :disabled="!usage_data_provider.active"
>+            >
>+                <i class="fa fa-play"></i> {{ $__("Run now") }}
>+            </button>
>         </Toolbar>
> 
>         <h2>
>@@ -220,6 +243,103 @@ export default {
>                 }
>             );
>         };
>+
>+        const test_usage_data_provider = (
>+            usage_data_provider_id,
>+            usage_data_provider_name
>+        ) => {
>+            const client = APIClient.erm;
>+            client.usage_data_providers.test(usage_data_provider_id).then(
>+                success => {
>+                    if (success) {
>+                        setMessage(
>+                            $__(
>+                                "Harvester connection was successful for usage data provider %s"
>+                            ).format(usage_data_provider_name),
>+                            true
>+                        );
>+                    } else {
>+                        setMessage(
>+                            $__(
>+                                "No connection for usage data provider %s, please check your credentials and try again."
>+                            ).format(usage_data_provider_name),
>+                            true
>+                        );
>+                    }
>+                },
>+                error => {}
>+            );
>+        };
>+
>+        const run_harvester = usage_data_provider_id => {
>+            let date = new Date();
>+            setConfirmationDialog(
>+                {
>+                    title: $__(
>+                        "Are you sure you want to run the harvester for this data provider?"
>+                    ),
>+                    message: name,
>+                    accept_label: $__("Yes, run"),
>+                    cancel_label: $__("No, do not run"),
>+                    inputs: [
>+                        {
>+                            name: "begin_date",
>+                            type: "date",
>+                            value: null,
>+                            label: $__("Begin date"),
>+                            required: true,
>+                            componentProps: {
>+                                required: {
>+                                    type: "boolean",
>+                                    value: true,
>+                                },
>+                            },
>+                        },
>+                        {
>+                            name: "end_date",
>+                            type: "date",
>+                            value: $date_to_rfc3339($date(date.toString())),
>+                            label: $__("End date"),
>+                            required: true,
>+                            componentProps: {
>+                                required: {
>+                                    type: "boolean",
>+                                    value: true,
>+                                },
>+                            },
>+                        },
>+                    ],
>+                },
>+                (callback_result, inputFields) => {
>+                    const client = APIClient.erm;
>+                    client.usage_data_providers
>+                        .process_SUSHI_response(
>+                            usage_data_provider_id,
>+                            inputFields
>+                        )
>+                        .then(
>+                            success => {
>+                                let message = "";
>+                                success.jobs.forEach((job, i) => {
>+                                    message +=
>+                                        "<li>" +
>+                                        $__(
>+                                            "Job for report type <strong>%s</strong> has been queued"
>+                                        ).format(job.report_type) +
>+                                        '. <a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=' +
>+                                        job.job_id +
>+                                        '" target="_blank">' +
>+                                        $__("Check job progress") +
>+                                        ".</a></li>";
>+                                });
>+                                setMessage(message, true);
>+                            },
>+                            error => {}
>+                        );
>+                }
>+            );
>+        };
>+
>         const change_tab_content = e => {
>             tab_content.value = e.target.getAttribute("data-content");
>         };
>@@ -235,6 +355,8 @@ export default {
>             tab_content,
>             available_data_types,
>             delete_usage_data_provider,
>+            test_usage_data_provider,
>+            run_harvester,
>             change_tab_content,
>         };
>     },
>-- 
>2.39.5
Comment 12 Jan Kissig 2025-10-14 20:53:17 UTC
please ignore last comment :/
Comment 13 Katrin Fischer 2025-10-15 07:54:30 UTC
You just need to fix the subject line, I can help with that a little later.
Comment 14 Paul Derscheid 2025-10-15 08:13:30 UTC
Just a side note, interestingly our QA script is fine with just:
But <number>

Maybe it should not be :)
Comment 15 Jan Kissig 2025-10-15 08:35:34 UTC
Created attachment 187901 [details] [review]
Bug 40141: Add "Run" and "Test" buttons to data provider toolbar

This patch adds the SUSHI test and run options to the toolbar of the data providers detail page.
If a provider is not active the buttons are disabled.

Testplan:
- go to /cgi-bin/koha/erm/eusage/usage_data_providers
- add a dummy provider
- notice the toolbar on the data provider detail page: Only Edit and Delete are available
- apply the patch
- run 'yarn js:build'
- I needed to call 'restart_all'
- refresh the providers detail page and notice the two new buttons: Test and run now
- click on 'test' and wait for the result
- click on 'Run now' and enter some appropriate dates.
- Click 'yes run' to see the jobs queued
- (Please do not dismiss the 'run now' dialog by clicking outside, as this triggers bug 41001)

Signed-off-by: Clemens Tubach <clemens.tubach@kit.edu>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>

If a provider is not active the buttons are disabled.
Comment 16 Lucas Gass (lukeg) 2025-10-16 20:55:58 UTC
With this applied DataProviders_spec.ts is failing:

  Data providers action buttons
    1) Should queue a harvest background job
    ✓ Should test a provider's SUSHI connection (2191ms)


  12 passing (58s)
  1 failing

  1) Data providers action buttons
       Should queue a harvest background job:
     AssertionError: Timed out retrying after 10000ms: Expected to find element: `main div[class='alert alert-info']`, but never found it.
      at Context.eval (webpack://koha/./t/cypress/integration/ERM/DataProviders_spec.ts:752:53)
Comment 17 Lucas Gass (lukeg) 2025-10-16 21:03:55 UTC
(In reply to Lucas Gass (lukeg) from comment #16)
> With this applied DataProviders_spec.ts is failing:
> 
>   Data providers action buttons
>     1) Should queue a harvest background job
>     ✓ Should test a provider's SUSHI connection (2191ms)
> 
> 
>   12 passing (58s)
>   1 failing
> 
>   1) Data providers action buttons
>        Should queue a harvest background job:
>      AssertionError: Timed out retrying after 10000ms: Expected to find
> element: `main div[class='alert alert-info']`, but never found it.
>       at Context.eval
> (webpack://koha/./t/cypress/integration/ERM/DataProviders_spec.ts:752:53)

Wait a minute, false alarm. For me that test is failing with or without this patch.
Comment 18 Lucas Gass (lukeg) 2025-10-16 21:21:50 UTC
Nice work everyone!

Pushed to main for 25.11