Bugzilla – Attachment 152958 Details for
Bug 30708
Creation of a new 'Preservation' module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30708: Allow attributes to be multivalued
Bug-30708-Allow-attributes-to-be-multivalued.patch (text/plain), 11.31 KB, created by
Jonathan Druart
on 2023-07-03 13:30:02 UTC
(
hide
)
Description:
Bug 30708: Allow attributes to be multivalued
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-07-03 13:30:02 UTC
Size:
11.31 KB
patch
obsolete
>From 176190462321e29aed42a9c1da21668ecac9540d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 24 Apr 2023 15:30:31 +0200 >Subject: [PATCH] Bug 30708: Allow attributes to be multivalued > >This is not working as it, but we are going to fix the problem when >working on the "Set default values for items added in batch to a train" > >Sponsored-by: BULAC - http://www.bulac.fr/ > >Signed-off-by: BULAC - http://www.bulac.fr/ >--- > .../data/mysql/atomicupdate/bug_30708.pl | 3 +- > installer/data/mysql/kohastructure.sql | 3 +- > .../Preservation/TrainsFormAddItem.vue | 78 ++++++++++++++----- > .../components/Preservation/TrainsShow.vue | 19 ++--- > t/cypress/integration/Preservation/Trains.ts | 6 ++ > 5 files changed, 78 insertions(+), 31 deletions(-) > >diff --git a/installer/data/mysql/atomicupdate/bug_30708.pl b/installer/data/mysql/atomicupdate/bug_30708.pl >index 2817d9776e7..2f80c19c7b7 100755 >--- a/installer/data/mysql/atomicupdate/bug_30708.pl >+++ b/installer/data/mysql/atomicupdate/bug_30708.pl >@@ -97,10 +97,11 @@ return { > unless ( TableExists('preservation_processing_attributes_items') ) { > $dbh->do(q{ > CREATE TABLE `preservation_processing_attributes_items` ( >+ `processing_attribute_item_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', > `processing_attribute_id` int(11) NOT NULL COMMENT 'link with preservation_processing_attributes', > `train_item_id` int(11) NOT NULL COMMENT 'link with preservation_trains_items', > `value` varchar(255) NULL COMMENT 'value for this attribute', >- PRIMARY KEY (`processing_attribute_id`,`train_item_id`), >+ PRIMARY KEY (`processing_attribute_item_id`), > CONSTRAINT `preservation_processing_attributes_items_ibfk_1` FOREIGN KEY (`processing_attribute_id`) REFERENCES `preservation_processing_attributes` (`processing_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE, > CONSTRAINT `preservation_processing_attributes_items_ibfk_2` FOREIGN KEY (`train_item_id`) REFERENCES `preservation_trains_items` (`train_item_id`) ON DELETE CASCADE ON UPDATE CASCADE > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index d1e703bd0de..420695928ec 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -4806,10 +4806,11 @@ DROP TABLE IF EXISTS `preservation_processing_attributes_items`; > /*!40101 SET @saved_cs_client = @@character_set_client */; > /*!40101 SET character_set_client = utf8 */; > CREATE TABLE `preservation_processing_attributes_items` ( >+ `processing_attribute_item_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', > `processing_attribute_id` int(11) NOT NULL COMMENT 'link with preservation_processing_attributes', > `train_item_id` int(11) NOT NULL COMMENT 'link with preservation_trains_items', > `value` varchar(255) NULL COMMENT 'value for this attribute', >- PRIMARY KEY (`processing_attribute_id`,`train_item_id`), >+ PRIMARY KEY (`processing_attribute_item_id`), > CONSTRAINT `preservation_processing_attributes_items_ibfk_1` FOREIGN KEY (`processing_attribute_id`) REFERENCES `preservation_processing_attributes` (`processing_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE, > CONSTRAINT `preservation_processing_attributes_items_ibfk_2` FOREIGN KEY (`train_item_id`) REFERENCES `preservation_trains_items` (`train_item_id`) ON DELETE CASCADE ON UPDATE CASCADE > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsFormAddItem.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsFormAddItem.vue >index 7294fee78fc..0b1f010998a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsFormAddItem.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsFormAddItem.vue >@@ -60,6 +60,29 @@ > v-model="attribute.value" > /> > </span> >+ <a >+ v-if=" >+ attributes.length == counter + 1 || >+ attributes[counter + 1] >+ .processing_attribute_id != >+ attribute.processing_attribute_id >+ " >+ class="btn btn-link" >+ @click=" >+ addAttribute( >+ attribute.processing_attribute_id >+ ) >+ " >+ ><font-awesome-icon icon="plus" /> >+ {{ $__("Add") }}</a >+ > >+ <a >+ v-else >+ class="btn btn-link" >+ @click="removeAttribute(counter)" >+ ><font-awesome-icon icon="minus" /> >+ {{ $__("Remove") }}</a >+ > > </li> > </ol> > </fieldset> >@@ -238,28 +261,34 @@ export default { > error => {} > ) > this.updateDefaultValues() >- this.attributes = this.processing.attributes.map(attribute => { >- let value = "" >+ this.attributes = [] >+ this.processing.attributes.forEach(attribute => { >+ let values = [] > if (!apply_default_value) { >- let existing_attribute = this.train_item.attributes.find( >- a => >- a.processing_attribute_id == >- attribute.processing_attribute_id >- ) >- if (existing_attribute) { >- value = existing_attribute.value >- } >+ this.train_item.attributes >+ .filter( >+ a => >+ a.processing_attribute_id == >+ attribute.processing_attribute_id >+ ) >+ .forEach(a => values.push(a.value)) > } else if (attribute.type == "db_column") { >- value = >+ values.push( > this.default_values[attribute.processing_attribute_id] >+ ) >+ } else { >+ values.push("") > } >- return { >- processing_attribute_id: attribute.processing_attribute_id, >- name: attribute.name, >- type: attribute.type, >- option_source: attribute.option_source, >- value, >- } >+ values.forEach(value => >+ this.attributes.push({ >+ processing_attribute_id: >+ attribute.processing_attribute_id, >+ name: attribute.name, >+ type: attribute.type, >+ option_source: attribute.option_source, >+ value, >+ }) >+ ) > }) > const client_av = APIClient.authorised_values > let av_cat_array = this.processing.attributes >@@ -280,6 +309,19 @@ export default { > }) > .then(() => this.loaded()) > }, >+ addAttribute(processing_attribute_id) { >+ let last_index = this.attributes.findLastIndex( >+ attribute => >+ attribute.processing_attribute_id == processing_attribute_id >+ ) >+ let new_attribute = (({ value, ...keepAttrs }) => keepAttrs)( >+ this.attributes[last_index] >+ ) >+ this.attributes.splice(last_index + 1, 0, new_attribute) >+ }, >+ removeAttribute(counter) { >+ this.attributes.splice(counter, 1) >+ }, > onSubmit(e) { > e.preventDefault() > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >index 240c2551c80..50507eebf51 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue >@@ -264,21 +264,15 @@ export default { > let item_row = {} > this.train.default_processing.attributes.forEach( > attribute => { >- let v = "" >- if (item.attributes.length >= 0) { >- let a = item.attributes.find( >+ item_row[ >+ attribute.processing_attribute_id >+ ] = item.attributes >+ .filter( > a => > a.processing_attribute_id == > attribute.processing_attribute_id > ) >- if (a) { >- v = a.value >- } >- } >- >- item_row[ >- attribute.processing_attribute_id >- ] = v >+ .map(a => a.value) > } > ) > item_row.item = item >@@ -295,6 +289,9 @@ export default { > name: a.name, > title: a.name, > data: a.processing_attribute_id, >+ render: (data, type, row) => { >+ return data.join("<br/>") >+ }, > }) > ) > this.item_table.columns.push({ >diff --git a/t/cypress/integration/Preservation/Trains.ts b/t/cypress/integration/Preservation/Trains.ts >index 94bd7732966..fb5203e73bc 100644 >--- a/t/cypress/integration/Preservation/Trains.ts >+++ b/t/cypress/integration/Preservation/Trains.ts >@@ -99,6 +99,12 @@ function get_train_items() { > processing_attributes[0].processing_attribute_id, > value: "Argentina", > }, >+ { >+ processing_attribute: processing_attributes[0], >+ processing_attribute_id: >+ processing_attributes[0].processing_attribute_id, >+ value: "Paraguay", >+ }, > { > processing_attribute: processing_attributes[1], > processing_attribute_id: >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30708
:
134715
|
134716
|
134732
|
134733
|
134734
|
134736
|
134737
|
134738
|
134782
|
134783
|
134784
|
134785
|
152939
|
152940
|
152941
|
152942
|
152943
|
152944
|
152945
|
152946
|
152947
|
152948
|
152949
|
152950
|
152951
|
152952
|
152953
|
152954
|
152955
|
152956
|
152957
|
152958
|
152959
|
152960
|
152961
|
152962
|
152963
|
152964
|
152965
|
152966
|
152967
|
152968
|
152969
|
152970
|
153102
|
153576
|
154167
|
154168
|
154169
|
154170
|
154171
|
154172
|
154173
|
154174
|
154175
|
154176
|
154177
|
154178
|
154179
|
154180
|
154181
|
154182
|
154183
|
154184
|
154185
|
154186
|
154187
|
154188
|
154189
|
154190
|
154191
|
154192
|
154193
|
154194
|
154195
|
154196
|
154197
|
154198
|
154199
|
154200
|
154201
|
154202
|
154203
|
156592
|
156596
|
156597
|
156636
|
156637
|
156638
|
156639
|
156640
|
156641
|
156642
|
156643
|
156644
|
156645
|
156646
|
156647
|
156648
|
156649
|
156650
|
156651
|
156652
|
156653
|
156654
|
156655
|
156656
|
156657
|
156658
|
156659
|
156660
|
156661
|
156662
|
156663
|
156664
|
156665
|
156666
|
156667
|
156668
|
156669
|
156670
|
156671
|
156672
|
156673
|
156674
|
156675
|
157502
|
157503
|
157506
|
157508
|
157512
|
157514
|
157557