From fb802405ec7f2e1ec8968042fd680701b0130444 Mon Sep 17 00:00:00 2001 From: elias Date: Mon, 27 Oct 2025 08:23:35 +0000 Subject: [PATCH] Bug 40906: Redesign Mana report import UI Why : This patch is a revamp of the interface of the menue "Import SQL from Mana". It is supposed to make it feel more like a marketplace of plugin or apps. I believe it is more coherent visually and fonctionally with what this feature is doing. Also, reports are immediatly displayed when the modal opens, inviting the user to explore report, while maintaining the ability to search for it. When the patch 40826 will be applied, we'll be able to sort reports based on the number of imports they recieved. It also includes : - Moving the search of report from the deprecated svc to the rest API - Paginating results so it doesn't load 1300 reports each time we search for reports. - In follow up, adds a drop down button to sort reports - Pagination makes it future proof in case of an augmentation of available reports. Test plan : - Clone the mana repo on your machine (from https://gitlab.com/koha-community/koha-mana) - By default there is no report loaded in mana, so you will want to create sample reports to be able to test the patch. You can simply uncomment the line in the `compose/base.yml`, under db -> volumes to add the sample reports. - Add the bin/mana utility to your path - run `mana up` to launch mana and create a docker network koha will connect to (see how to use the mana utility here : https://gitlab.com/koha-community/koha-mana/-/tree/main/compose?ref_type=heads) - run `ktd --mana up` to connect koha to mana - in koha > Administration > ManaKB settings, enable Mana (no need to create a secority token to test this patch) - In the report section, select new SQL report, and then in the dropdown menu, New SQL from mana. To be able to export your reports from koha to mana requires that you create a librarian account, wich can be done from koha administration page, and that you verify that account, which can only be done directly with SQL or by allowing mana to send emails for now, wich is not configurable easely. If you already have a mana instance running, you can use the --mana-url option of ktd to choose the url of your mana instance. --- Koha/REST/V1/Mana/Reports.pm | 66 +++++++++ api/v1/swagger/definitions/mana_comment.yaml | 27 ++++ api/v1/swagger/definitions/mana_report.yaml | 63 +++++++++ api/v1/swagger/paths/mana.yaml | 50 +++++++ api/v1/swagger/swagger.yaml | 12 ++ koha-tmpl/intranet-tmpl/prog/css/reports.css | 88 ++++++++++++ .../mana/mana-report-search-result.inc | 116 --------------- .../prog/en/includes/reports-toolbar.inc | 34 +++-- .../en/modules/mana/mana-report-details.tt | 25 ++++ .../modules/mana/mana-report-search-result.tt | 1 - .../modules/reports/guided_reports_start.tt | 51 ------- koha-tmpl/intranet-tmpl/prog/js/mana.js | 132 ++++++++++++++++++ reports/mana_report_details.pl | 43 ++++++ svc/mana/search | 6 +- 14 files changed, 529 insertions(+), 185 deletions(-) create mode 100644 Koha/REST/V1/Mana/Reports.pm create mode 100644 api/v1/swagger/definitions/mana_comment.yaml create mode 100644 api/v1/swagger/definitions/mana_report.yaml create mode 100644 api/v1/swagger/paths/mana.yaml delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-details.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-search-result.tt create mode 100755 reports/mana_report_details.pl diff --git a/Koha/REST/V1/Mana/Reports.pm b/Koha/REST/V1/Mana/Reports.pm new file mode 100644 index 00000000000..6a254154cd7 --- /dev/null +++ b/Koha/REST/V1/Mana/Reports.pm @@ -0,0 +1,66 @@ + +package Koha::REST::V1::Mana::Reports; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Mojo::Base 'Mojolicious::Controller'; + +use Try::Tiny qw( catch try ); + +use Koha::SharedContent; + +=head1 API + +=head2 Methods + +=head3 list + +=cut + +sub list { + my $c = shift->openapi->valid_input or return; + + my $per_page = $c->param('_per_page'); + my $page = $c->param('_page'); + my $orderby = $c->param('_order_by'); + + my $query = $c->param('q'); + + my $params = { + per_page => $per_page, + page => $page, + orderby => $orderby + }; + + if ($query) { + $params->{query} = $query; + } + + my $result = Koha::SharedContent::search_entities( 'report', $params ); + if ( $result->{pagination} ) { + $c->res->headers->header( "x-total-count" => $result->{pagination}->{total} ); + } + + return try { + return $c->render( status => 200, openapi => $result->{data} ); + } catch { + $c->unhandled_exception($_); + }; +} + +1; diff --git a/api/v1/swagger/definitions/mana_comment.yaml b/api/v1/swagger/definitions/mana_comment.yaml new file mode 100644 index 00000000000..bc73cd060ca --- /dev/null +++ b/api/v1/swagger/definitions/mana_comment.yaml @@ -0,0 +1,27 @@ +--- +type: object +properties: + id: + description: The id of the comment in the mana debit + type: integer + resource_id: + description: The id of the resource in mana the comment is linked to + type: integer + resource_type: + description: The type of resource the comment is attached to + type: string + message: + description: The content of the comment + type: string + creationdate: + description: date of creation + type: string + format: date + + + + + + +additionalProperties: false + diff --git a/api/v1/swagger/definitions/mana_report.yaml b/api/v1/swagger/definitions/mana_report.yaml new file mode 100644 index 00000000000..7395697073a --- /dev/null +++ b/api/v1/swagger/definitions/mana_report.yaml @@ -0,0 +1,63 @@ +--- +type: object +properties: + id: + type: integer + description: report id in mana + readOnly: true + report_name: + description: The name of the report + type: string + notes: + description: A description of the report + type: + - string + - "null" + lastimport: + description: The last time the report was imported from mana + format: date + type: + - string + - "null" + creationdate: + description: The day the report was exported to mana + type: string + format: date + savedsql: + description: The sql of the report + type: + - string + language: + description: The language the sql report has + type: + - string + - "null" + report_group: + description: The report group the report belongs to + type: + - string + - "null" + kohaversion: + description: The version of Koha from which the report was exported to mana + type: + - string + - "null" + nbofusers: + description: The number of import of a report + type: + - integer + # Do not leave as is ! + type: + description: Type + type: + - string + - "null" + comments: + description: Comments added by users to the reports + type: + - array + items: + $ref: "../swagger.yaml#/definitions/mana_comment" + +additionalProperties: false + diff --git a/api/v1/swagger/paths/mana.yaml b/api/v1/swagger/paths/mana.yaml new file mode 100644 index 00000000000..13f5868cd2f --- /dev/null +++ b/api/v1/swagger/paths/mana.yaml @@ -0,0 +1,50 @@ +--- +/mana/reports: + get: + x-mojo-to: Mana::Reports#list + operationId: searchReports + tags: + - mana + - reports + summary: List reports registered in the mana database + produces: + - application/json + parameters: + - $ref: "../swagger.yaml#/parameters/match" + - $ref: "../swagger.yaml#/parameters/order_by" + - $ref: "../swagger.yaml#/parameters/page" + - $ref: "../swagger.yaml#/parameters/per_page" + - $ref: "../swagger.yaml#/parameters/q_str" + - $ref: "../swagger.yaml#/parameters/request_id_header" + responses: + "200": + description: A List of reports + schema: + type: array + items: + $ref: "../swagger.yaml#/definitions/mana_report" + "400": + description: | + Bad request. Possible `error_code` attribute values: + + * `invalid_query` + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + "503": + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + catalogue: "1" \ No newline at end of file diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 9a9b7af7565..8e854741e7d 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -140,6 +140,10 @@ definitions: $ref: ./definitions/library.yaml list: $ref: ./definitions/list.yaml + mana_comment: + $ref: ./definitions/mana_comment.yaml + mana_report: + $ref: ./definitions/mana_report.yaml merge_biblios: $ref: ./definitions/merge_biblios.yaml order: @@ -485,6 +489,8 @@ paths: $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1cash_registers" "/libraries/{library_id}/desks": $ref: "./paths/libraries.yaml#/~1libraries~1{library_id}~1desks" + "/mana/reports": + $ref: "./paths/mana.yaml#/~1mana~1reports" "/oauth/login/{provider_code}/{interface}": $ref: ./paths/oauth.yaml#/~1oauth~1login~1{provider_code}~1{interface} /oauth/token: @@ -967,6 +973,12 @@ parameters: items: type: string collectionFormat: multi + q_str: + description: Query string sent as a request parameter + in: query + name: q + required: false + type: string quote_id_pp: description: Quote internal identifier in: path diff --git a/koha-tmpl/intranet-tmpl/prog/css/reports.css b/koha-tmpl/intranet-tmpl/prog/css/reports.css index 80cc39da514..09016f6be40 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/reports.css +++ b/koha-tmpl/intranet-tmpl/prog/css/reports.css @@ -21,6 +21,94 @@ del { background-color: #ffe6e6; } +#mana_results_datatable tbody { + display:flex; + flex-wrap: wrap; + justify-content: center; +} + +#mana-search-result-modal-body { + height: 80vh; +} + +#overlay-report-details { + display: none; +} + +#overlay-report-details .CodeMirror { + height: auto; +} + +.return-div { + font-size: 13px; + cursor: pointer; +} + +#mana_results_datatable td{ + width: 100%; + display: inline-block; + border: none; + background-color: transparent; + text-align: left; +} + +#mana_results_datatable tr { + display: flex; + flex-wrap: wrap; + justify-content: space-between; + clear:both; + text-align:left; + width: 19rem; + padding: 0.25rem; + margin: 0.25rem; + background-color: #E6E6E6; + border: none; + border-radius: 0.25rem; + margin-top: 1rem; + font-size: 11px; + height: 14rem; +} + +#mana_results_datatable tr:hover { + cursor: pointer; +} + +.report_name { + height: 3rem; + font-weight: bold; +} + + + +.mana-report-comments { + padding: 1rem; + margin: 4px; + background-color: #E6E6E6; + border: none; + display: flex; + align-items: center; + justify-content: space-between; +} + +.report-description { + height:5rem; + word-wrap: break-word; +} + +#mana_results_datatable .w-40 { + width: 40%; +} + +.report_info { + color: #696969; + text-align: right; + margin: 0 5px; +} + +#mana_results_datatable .text-end { + text-align: right; +} + #col1, #col2 { float: left; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc deleted file mode 100644 index 21598281b06..00000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc +++ /dev/null @@ -1,116 +0,0 @@ -[% USE Asset %] -[% USE KohaDates %] -[% USE Koha %] -[% USE AuthorisedValues %] -[% USE Branches %] -[% USE raw %] -[% PROCESS 'i18n.inc' %] -[% INCLUDE 'doc-head-open.inc' %] -[% FILTER collapse %] - [% t("Mana Knowledge Base reports search") | html %] - › [% t("Reports") | html %] › [% t("Koha") | html %] - [% END %] -[% INCLUDE 'doc-head-close.inc' %] -[% Asset.css("css/reports.css") | $raw %] - - - -[% WRAPPER 'header.inc' %] - [% INCLUDE 'circ-search.inc' %] -[% END %] - - - -[% WRAPPER 'main-container.inc' aside='guided-reports-view' %] -

Mana Knowledge Base report search results

- -
- [% IF statuscode == "200" AND reports %] - - - - - - - - - - [% UNLESS search_only %] - - [% END %] - - - - [% FOREACH report IN reports %] - [% UNLESS report.cannotdisplay %] - [% IF report.nbofcomment > highWarned %] - [% SET tr_class = 'high-warned-row' %] - [% ELSIF report.nbofcomment > warned %] - [% SET tr_class = 'warned-row' %] - [% ELSIF report.nbofcomment > lowWarned %] - [% SET tr_class = 'highlighted-row' %] - [% ELSE %] - [% SET tr_class = '' %] - [% END %] - - - - - - - - - [% UNLESS search_only %] - - [% END %] - - [% END %] - [% END %] - -
Report nameNotesType# of usersLast import Comments Actions
- - [% IF ( report.report_name ) %] - [% report.report_name | html %] - [% END %] - - [% IF report.notes.length > 200 %] -
- [% report.notes.substr(0,200) | html %]... Show more -
-
- [% report.notes | html %] - Show less -
- [% ELSE %] - [% report.notes | html %] - [% END %] -
[% report.type | html %] - [% IF ( report.nbofusers ) %] - [% report.nbofusers | html %] - [% END %] - [% report.lastimport | $KohaDates %] - [% FOREACH comment IN report.comments %] - [% comment.message | html %] - ([% comment.nb | html %])
- [% END %] -
- -
- [% ELSE %] -

- [% IF ( msg ) %] - [% msg | html %] (Status code: [% statuscode | html %]) - [% ELSE %] - No results found - [% END %] -

- [% END %] -
-[% END %] -[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc index 37f73fcee21..88a7ed98d22 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc @@ -185,15 +185,18 @@ [% IF Koha.Preference('Mana')==1 %] + + [% INCLUDE 'js-date-format.inc' %]