From 5dae3d5965fd7751f050df463ff210c7a436f252 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 6 Jun 2023 15:14:36 +0200 Subject: [PATCH] Bug 30708: Display AV descriptions instead of codes Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: BULAC - http://www.bulac.fr/ Signed-off-by: Heather Hernandez Signed-off-by: Laurence Rault Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- Koha/Preservation/Train/Item/Attribute.pm | 28 ++++++++++++++++- api/v1/swagger/paths/preservation_trains.yaml | 1 + .../components/Preservation/TrainsShow.vue | 12 ++++---- .../js/vue/fetch/preservation-api-client.js | 30 ++++++++++--------- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/Koha/Preservation/Train/Item/Attribute.pm b/Koha/Preservation/Train/Item/Attribute.pm index b99b84e6c8..1618dc582e 100644 --- a/Koha/Preservation/Train/Item/Attribute.pm +++ b/Koha/Preservation/Train/Item/Attribute.pm @@ -20,7 +20,7 @@ use Modern::Perl; use JSON qw( to_json ); use Try::Tiny; -use Koha::Database; +use Koha::AuthorisedValues; use base qw(Koha::Object); @@ -50,6 +50,32 @@ sub processing_attribute { return Koha::Preservation::Processing::Attribute->_new_from_dbic($processing_attribute_rs) } +=head3 strings_map + +Returns a map of column name to string representations including the string. + +=cut + +sub strings_map { + my ($self) = @_; + my $str = $self->value; + if ( $self->processing_attribute->type eq 'authorised_value' ) { + my $av = Koha::AuthorisedValues->search( + { + category => $self->processing_attribute->option_source, + authorised_value => $self->value, + } + ); + if ( $av->count ) { + $str = $av->next->lib || $self->value; + } + } + + return { + value => { str => $str, type => 'authorised_value' }, + }; +} + =head2 Internal methods =head3 _type diff --git a/api/v1/swagger/paths/preservation_trains.yaml b/api/v1/swagger/paths/preservation_trains.yaml index dd4058e475..a8563e8769 100644 --- a/api/v1/swagger/paths/preservation_trains.yaml +++ b/api/v1/swagger/paths/preservation_trains.yaml @@ -165,6 +165,7 @@ enum: - items - items.attributes + - items.attributes+strings - items.attributes.processing_attribute - default_processing - default_processing.attributes 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 3126273b80..43bd0d00ba 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 @@ -173,9 +173,8 @@ ) in item.attributes" v-bind:key="counter_attribute" > - {{ attribute.processing_attribute.name }}={{ - attribute.value + attribute._strings.value.str }} @@ -238,6 +237,7 @@ export default { train_list: [], train_id_selected_for_copy: null, train_item_id_to_copy: null, + av_options: {}, } }, beforeRouteEnter(to, from, next) { @@ -252,12 +252,12 @@ export default { await client.trains.get(train_id).then( train => { this.train = train - let display = this.train.items.every( + let display_table = this.train.items.every( item => item.processing_id == this.train.default_processing_id ) - if (display) { + if (display_table) { this.item_table.data = [] this.train.items.forEach(item => { let item_row = {} @@ -271,7 +271,7 @@ export default { a.processing_attribute_id == attribute.processing_attribute_id ) - .map(a => a.value) + .map(a => a._strings.value.str) } ) item_row.item = item @@ -305,7 +305,7 @@ export default { }) } this.initialized = true - this.item_table.display = display + this.item_table.display = display_table }, error => {} ) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js index 356adfac4b..329a01455c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js @@ -9,27 +9,28 @@ export class PreservationAPIClient extends HttpClient { get trains() { return { - get: (id) => + get: id => this.get({ endpoint: "trains/" + id, headers: { "x-koha-embed": - "default_processing,default_processing.attributes,items,items.attributes,items.attributes.processing_attribute", + "default_processing,default_processing.attributes,items,items.attributes,items.attributes+strings,items.attributes.processing_attribute", }, }), getAll: (query = {}) => this.get({ - endpoint: "trains?" + + endpoint: + "trains?" + new URLSearchParams({ _per_page: -1, ...(query && { q: JSON.stringify(query) }), }), }), - delete: (id) => + delete: id => this.delete({ endpoint: "trains/" + id, }), - create: (train) => + create: train => this.post({ endpoint: "trains", body: train, @@ -54,27 +55,28 @@ export class PreservationAPIClient extends HttpClient { get processings() { return { - get: (id) => + get: id => this.get({ endpoint: "processings/" + id, headers: { "x-koha-embed": "attributes", }, }), - getAll: (query) => + getAll: query => this.get({ - endpoint: "processings?" + + endpoint: + "processings?" + new URLSearchParams({ _per_page: -1, ...(query && { q: JSON.stringify(query) }), }), }), - delete: (id) => + delete: id => this.delete({ endpoint: "processings/" + id, }), - create: (processing) => + create: processing => this.post({ endpoint: "processings", body: processing, @@ -148,7 +150,7 @@ export class PreservationAPIClient extends HttpClient { get waiting_list_items() { return { - get_from_barcode: (barcode) => { + get_from_barcode: barcode => { const q = { "me.barcode": barcode, }; @@ -164,15 +166,15 @@ export class PreservationAPIClient extends HttpClient { headers: { "x-koha-embed": "biblio", }, - }).then((response) => { + }).then(response => { return response.length ? response[0] : undefined; }); }, - delete: (id) => + delete: id => this.delete({ endpoint: "waiting-list/items/" + id, }), - createAll: (items) => + createAll: items => this.post({ endpoint: "waiting-list/items", body: items, -- 2.39.5