From f24dedc207fc19d26b0589dc2c7e798affd2330d Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 8 Nov 2023 11:35:29 -0100 Subject: [PATCH] Bug 35287: Vue - Add additional fields support to ERM Licenses Test plan, k-t-d: 1) Add a new additional field for the newly supported 'erm_licenses', visit: /cgi-bin/koha/admin/additional-fields.pl?tablename=erm_licenses 2) Create 4 fields by clicking on '+ New field' 2.1) 'text non-repeatable' 2.2) 'text repeatable', check the 'repeatable' box 2.3) 'av non-repeatable', pick an authorised value category 2.4) 'av repeatable', pick an authorised value category and check the 'repeatable' box 3) Add a new ERM license, visit: /cgi-bin/koha/erm/licenses/add 4) Notice there is now a 'Additional fields' section at the bottom listing the fields we created 5) Fill in the mandatory regular license fields and play around with the additional fields 5.1) Put in some text in the text fields, test out the 'clear' and '+new' buttons 5.2) Select some AV options from the AV fields, deselect them, notice the repeatable one allows for multiple selection, the non-repeatable one does not 6) Save the license. On the list table, click on the license name (to navigate to the show page), or if license id=1, visit: /cgi-bin/koha/erm/licenses/1 7) Notice the additional fields are listed there, AV fields show their human readable description, not the AV code. Repeatable fields are shown comma separated 8) Edit the license, visit: /cgi-bin/koha/erm/licenses/edit/1 9) Play around again, do some more inserting and deletion of additional fields. Save. Notice everything is as expected. Searchable testing: 10) Go back to the additional fields admin panel, visit: /cgi-bin/koha/admin/additional-fields.pl?tablename=erm_licenses 11) Edit one field (AV or not) that you have inserted some data in, in the previous steps, and tick the 'searchable' box 12) Go back to licenses, visit: /cgi-bin/koha/erm/licenses 13) Notice the searchable additional field now has its own column in the licenses list table 14) If the searchable field is AV, it has a dropdown with the AV values of the same AV category 15) If the searchable field not AV, it has a text input that allows for normal text search 16) If the searchable field is repeatable and has multiple values, its displayed in comma separated Signed-off-by: Edith Speller --- .../js/vue/components/ERM/LicensesFormAdd.vue | 12 +++++ .../js/vue/components/ERM/LicensesList.vue | 51 ++++++++++++++++++- .../js/vue/components/ERM/LicensesShow.vue | 13 ++++- .../prog/js/vue/fetch/erm-api-client.js | 2 +- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue index b14f93bb25..8752224b38 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue @@ -109,6 +109,11 @@ + { - vm.getLicenseCount().then(() => (vm.initialized = true)) + vm.getLicenseCount().then(() => + vm + .getSearchableAdditionalFields() + .then(() => + vm + .getSearchableAVOptions() + .then(() => (vm.initialized = true)) + ) + ) }) }, methods: { @@ -102,6 +114,41 @@ export default { error => {} ) }, + async getSearchableAdditionalFields() { + const client = APIClient.additional_fields + await client.additional_fields.getAll("erm_licenses").then( + searchable_additional_fields => { + this.searchable_additional_fields = + searchable_additional_fields.filter( + field => field.searchable + ) + }, + error => {} + ) + }, + async getSearchableAVOptions() { + const client_av = APIClient.authorised_values + let av_cat_array = this.searchable_additional_fields + .filter(field => field.authorised_value_category) + .map(field => field.authorised_value_category) + + await client_av.values + .getCategoriesWithValues([ + ...new Set(av_cat_array.map(av_cat => '"' + av_cat + '"')), + ]) // unique + .then(av_categories => { + av_cat_array.forEach(av_cat => { + let av_match = av_categories.find( + element => element.category_name == av_cat + ) + this.searchable_av_options[av_cat] = + av_match.authorised_values.map(av => ({ + value: av.value, + label: av.description, + })) + }) + }) + }, doShow: function ({ license_id }, dt, event) { event.preventDefault() this.$router.push({ name: "LicensesShow", params: { license_id } }) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue index 19c853f4aa..3ba0e5c63d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue @@ -132,6 +132,12 @@ +
import { inject } from "vue" import { APIClient } from "../../fetch/api-client.js" +import AdditionalFieldsDisplay from "../AdditionalFieldsDisplay.vue" export default { setup() { @@ -177,6 +184,8 @@ export default { type: "", status: "", user_roles: [], + extended_attributes: [], + _strings: [], started_on: undefined, ended_on: undefined, }, @@ -227,7 +236,9 @@ export default { ) }, }, - components: {}, + components: { + AdditionalFieldsDisplay, + }, name: "LicensesShow", } 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 f563f61701..e10010d234 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 @@ -66,7 +66,7 @@ export class ERMAPIClient extends HttpClient { endpoint: "licenses/" + id, headers: { "x-koha-embed": - "user_roles,user_roles.patron,vendor,documents", + "user_roles,user_roles.patron,vendor,documents,extended_attributes,+strings", }, }), getAll: (query, params) => -- 2.30.2