From efe7a44da75b209d01111416df57adbfaedaf844 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Fri, 31 Jan 2025 12:55:59 +0000 Subject: [PATCH] Bug 38201: Introduce RelationshipTableDisplay for nested Kohatables Signed-off-by: Michaela Sieber Signed-off-by: Jonathan Druart Signed-off-by: Lucas Gass --- .../paths/erm_eholdings_resources.yaml | 11 +- .../prog/js/vue/components/BaseResource.vue | 36 ++ .../ERM/EHoldingsLocalTitleResource.vue | 97 +++-- .../ERM/EHoldingsLocalTitlesShow.vue | 345 ------------------ .../components/RelationshipTableDisplay.vue | 129 +++++++ .../js/vue/components/ResourceFormAdd.vue | 37 +- .../prog/js/vue/components/ResourceShow.vue | 26 +- .../prog/js/vue/components/ShowElement.vue | 21 +- .../intranet-tmpl/prog/js/vue/routes/erm.js | 5 +- 9 files changed, 265 insertions(+), 442 deletions(-) delete mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/RelationshipTableDisplay.vue diff --git a/api/v1/swagger/paths/erm_eholdings_resources.yaml b/api/v1/swagger/paths/erm_eholdings_resources.yaml index eb2aa6ae31..d5efafa127 100644 --- a/api/v1/swagger/paths/erm_eholdings_resources.yaml +++ b/api/v1/swagger/paths/erm_eholdings_resources.yaml @@ -44,6 +44,15 @@ name: proxy required: false type: string + - name: x-koha-embed + in: header + required: false + description: Embed list sent as a request header + type: array + items: + type: string + enum: + - package - $ref: "../swagger.yaml#/parameters/match" - $ref: "../swagger.yaml#/parameters/order_by" - $ref: "../swagger.yaml#/parameters/page" @@ -208,4 +217,4 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - erm: 1 + erm: 1 \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue index ff73a348e1..f64b0b3dc8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue @@ -192,6 +192,42 @@ export default { }); return filterOptions; }, + getFieldGroupings() { + const groupings = this.resourceAttrs.reduce((acc, attr) => { + if ( + attr.hasOwnProperty("group") && + attr.group !== null && + !acc.includes(attr.group) + ) { + return [...acc, attr.group]; + } + if (!attr.hasOwnProperty("group")) { + attr.group = "noGroupFound"; + if (!acc.includes("noGroupFound")) { + return [...acc, "noGroupFound"]; + } + } + return acc; + }, []); + if (groupings.length === 0) { + return [ + { + name: null, + fields: this.resourceAttrs, + }, + ]; + } + return groupings.reduce((acc, group) => { + const groupFields = this.resourceAttrs.filter( + ra => ra.group === group + ); + const groupInfo = { + name: group === "noGroupFound" ? null : group, + fields: groupFields, + }; + return [...acc, groupInfo]; + }, []); + }, }, computed: { newResource() { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitleResource.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitleResource.vue index 52411f6fcd..e2f8dc9e52 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitleResource.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitleResource.vue @@ -32,6 +32,7 @@ goToResourceEdit, doResourceDelete, resourceName, + getFieldGroupings, }" /> @@ -104,91 +106,76 @@ export default { name: "publication_title", required: true, type: "text", - style: { width: "25rem" }, label: __("Publication title"), }, { name: "print_identifier", type: "text", - style: { width: "25rem" }, label: __("Print-format identifier"), }, { name: "online_identifier", type: "text", - style: { width: "25rem" }, label: __("Online-format identifier"), }, { name: "date_first_issue_online", type: "text", - style: { width: "25rem" }, label: __("Date of first serial issue available online"), }, { name: "num_first_vol_online", type: "text", - style: { width: "25rem" }, label: __("Number of first volume available online"), }, { name: "num_first_issue_online", type: "text", - style: { width: "25rem" }, label: __("Number of first issue available online"), }, { name: "date_last_issue_online", type: "text", - style: { width: "25rem" }, label: __("Date of last issue available online"), }, { name: "num_last_vol_online", type: "text", - style: { width: "25rem" }, label: __("Number of last volume available online"), }, { name: "num_last_issue_online", type: "text", - style: { width: "25rem" }, label: __("Number of last issue available online"), }, { name: "title_url", type: "text", - style: { width: "25rem" }, label: __("Title-level URL"), }, { name: "first_author", type: "text", - style: { width: "25rem" }, label: __("First author"), }, { name: "embargo_info", type: "text", - style: { width: "25rem" }, label: __("Embargo information"), }, { name: "coverage_depth", type: "text", - style: { width: "25rem" }, label: __("Coverage depth"), }, { name: "notes", type: "text", - style: { width: "25rem" }, label: __("Notes"), }, { name: "publisher_name", type: "text", - style: { width: "25rem" }, label: __("Publisher name"), }, { @@ -196,48 +183,40 @@ export default { type: "select", label: __("Publication type"), avCat: "av_title_publication_types", - style: { width: "25rem" }, }, { name: "date_monograph_published_print", type: "text", - style: { width: "25rem" }, label: __("Date the monograph is first published in print"), }, { name: "date_monograph_published_online", type: "text", - style: { width: "25rem" }, label: __("Date the monograph is first published online"), }, { name: "monograph_volume", type: "text", - style: { width: "25rem" }, label: __("Number of volume for monograph"), }, { name: "monograph_edition", type: "text", - style: { width: "25rem" }, label: __("Edition of the monograph"), }, { name: "first_editor", type: "text", - style: { width: "25rem" }, label: __("First editor"), }, { name: "parent_publication_title_id", type: "text", - style: { width: "25rem" }, label: __("Title identifier of the parent publication"), }, { name: "preceding_publication_title_id", type: "text", - style: { width: "25rem" }, label: __( "Title identifier of any preceding publication title" ), @@ -245,7 +224,6 @@ export default { { name: "access_type", type: "text", - style: { width: "25rem" }, label: __("Access type"), }, { @@ -260,13 +238,69 @@ export default { ? __("Create bibliographic record") : __("Update bibliographic record"), value: false, - style: { width: "25rem" }, }, { name: "resources", type: "relationshipWidget", group: __("Packages"), apiClient: APIClient.erm.localPackages, + showElement: { + type: "component", + hidden: title => title.resources.length > 0, + componentPath: "./RelationshipTableDisplay.vue", + props: { + tableOptions: { + type: "object", + value: { + columns: [ + { + title: __("Name"), + data: "package.name", + searchable: true, + orderable: true, + render: function ( + data, + type, + row, + meta + ) { + return ( + '' + + escape_str( + `${row.package.name} (#${row.package.package_id})` + ) + + "" + ); + }, + }, + ], + options: { + embed: "package", + }, + url: + APIClient.erm._baseURL + + "eholdings/local/resources", + }, + }, + apiClient: { + type: "object", + value: APIClient.erm.localPackages, + }, + filters: { + type: "filter", + keys: { + title_id: { property: "title_id" }, + }, + }, + resource: { + type: "resource", + }, + resourceName: { + type: "string", + value: "package", + }, + }, + }, props: { newRelationship: { type: "object", @@ -338,10 +372,6 @@ export default { value: "started_on_", indexRequired: true, }, - required: { - type: "boolean", - value: true, - }, date_to: { type: "string", value: "ended_on_", @@ -594,3 +624,12 @@ export default { name: "EHoldingsLocalTitlesResource", }; + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue deleted file mode 100644 index b6b76f521e..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue +++ /dev/null @@ -1,345 +0,0 @@ - - - - diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/RelationshipTableDisplay.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/RelationshipTableDisplay.vue new file mode 100644 index 0000000000..4bcf5e6257 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/RelationshipTableDisplay.vue @@ -0,0 +1,129 @@ + + + + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ResourceFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ResourceFormAdd.vue index 59543ae16c..88d4ff6ae2 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ResourceFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ResourceFormAdd.vue @@ -66,6 +66,7 @@ export default { resource: Object, onSubmit: Function, resourceName: String, + getFieldGroupings: Function, }, created() { if (this.$route.params[this.idAttr]) { @@ -84,42 +85,6 @@ export default { error => {} ); }, - getFieldGroupings() { - const groupings = this.resourceAttrs.reduce((acc, attr) => { - if ( - attr.hasOwnProperty("group") && - attr.group !== null && - !acc.includes(attr.group) - ) { - return [...acc, attr.group]; - } - if (!attr.hasOwnProperty("group")) { - attr.group = "noGroupFound"; - if (!acc.includes("noGroupFound")) { - return [...acc, "noGroupFound"]; - } - } - return acc; - }, []); - if (groupings.length === 0) { - return [ - { - name: null, - fields: this.resourceAttrs, - }, - ]; - } - return groupings.reduce((acc, group) => { - const groupFields = this.resourceAttrs.filter( - ra => ra.group === group - ); - const groupInfo = { - name: group === "noGroupFound" ? null : group, - fields: groupFields, - }; - return [...acc, groupInfo]; - }, []); - }, }, computed: { resourceToAddOrEdit() { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ResourceShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ResourceShow.vue index 73f4eee28f..3779010fb3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ResourceShow.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ResourceShow.vue @@ -16,30 +16,21 @@ {{ i18n.displayName + " #" + resource[idAttr] }}
-
+
+ {{ group.name }}
  1. - +
-
-
-
-
+ + + +