From 8c2b842528dd680e4b60cd8c11c0ea59d1690a49 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. - Pagination makes it future proof in case of an augmentation of available reports. Test plan : - Clone the test-bug-40906 branch from my repo of mana : https://gitlab.com/elorgnier/koha-mana/-/tree/test-bug-40906?ref_type=heads - Run docker compose up in the repo - in the .env file of ktd, for the MANA_URL option, use 127.17.0.1:5000 (if you have the default host ip defined in the docker bridge network) - run ktd - in koha > Administration, configure a mana account with random username and email (no need to validate it) - In the report section, select new SQL report, and then in the dropdown menu, New SQL from mana. By default there is no report loaded in mana, so you will want to create sample reports to be able to test it, i'll push a sample to the test branch of mana as soon as possible. You can create your own sample or mount a dump of the existing database in the docker compose of mana by mounting the sql dump in the place of the /sql/schema.sql --- 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 | 87 ++++++++++++ .../mana/mana-report-search-result.inc | 130 ----------------- .../prog/en/includes/reports-toolbar.inc | 32 +++-- .../en/modules/mana/mana-report-details.tt | 28 ++++ .../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(+), 199 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 100644 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..a0a2e9c6863 --- /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; \ No newline at end of file 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 dcb0a3cc66e..2ccf5ba8354 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: @@ -483,6 +487,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: @@ -965,6 +971,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..893884e598e 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/reports.css +++ b/koha-tmpl/intranet-tmpl/prog/css/reports.css @@ -21,6 +21,93 @@ 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; +} + +#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 8edca6cc48a..00000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc +++ /dev/null @@ -1,130 +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 %] - - - -
-
-
-
-

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 %] -
-
-
- - -
- -
- -
- - - [% 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..853c73f45b5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc @@ -186,14 +186,15 @@ [% IF Koha.Preference('Mana')==1 %]