From e02f41bb3881763348a9dafc3e640bd4e4ffcb49 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 13 Apr 2023 15:26:00 +0200 Subject: [PATCH] Bug 33568: Cover images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Owen Leonard Signed-off-by: Laurence Rault Signed-off-by: Emily Lamancusa Signed-off-by: Tomás Cohen Arazi --- Koha/Item.pm | 16 +++++++++--- api/v1/swagger/definitions/item.yaml | 4 +++ api/v1/swagger/paths/biblios.yaml | 1 + .../prog/en/modules/catalogue/detail.tt | 26 ++++++++++++++++--- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 59edeb752d8..ba261bfa006 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1214,9 +1214,19 @@ Return the cover images associated with this item. sub cover_images { my ( $self ) = @_; - my $cover_image_rs = $self->_result->cover_images; - return unless $cover_image_rs; - return Koha::CoverImages->_new_from_dbic($cover_image_rs); + my $cover_images_rs = $self->_result->cover_images; + return Koha::CoverImages->_new_from_dbic($cover_images_rs); +} + +=head3 cover_image_ids + +Return the cover image ids associated with this item. + +=cut + +sub cover_image_ids { + my ($self) = @_; + return [ $self->cover_images->get_column('imagenumber') ]; } =head3 columns_to_str diff --git a/api/v1/swagger/definitions/item.yaml b/api/v1/swagger/definitions/item.yaml index 1d0ed7ac95f..6f4a9d12e80 100644 --- a/api/v1/swagger/definitions/item.yaml +++ b/api/v1/swagger/definitions/item.yaml @@ -230,6 +230,10 @@ properties: type: - object - "null" + cover_image_ids: + type: + - array + - "null" _strings: type: - object diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml index 30702535577..1277166a8b8 100644 --- a/api/v1/swagger/paths/biblios.yaml +++ b/api/v1/swagger/paths/biblios.yaml @@ -423,6 +423,7 @@ type: string enum: - +strings + - cover_image_ids collectionFormat: csv - $ref: "../swagger.yaml#/parameters/match" - $ref: "../swagger.yaml#/parameters/order_by" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 4f60d86bbe8..e605c8e12b5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -2495,10 +2495,14 @@ const can_edit_items_from = [% To.json(can_edit_items_from) | $raw %]; const item_type_image_locations = [% To.json(item_type_image_locations) | $raw %]; let table_url = "/api/v1/biblios/[% biblio.biblionumber | uri %]/items?"; + let embed = ["+strings"]; + [% IF Koha.Preference('LocalCoverImages') %] + embed.push('cover_image_ids'); + [% END %] var items_table = $("#table_items").kohaTable({ ajax: { url: table_url }, order: [[ 0, "asc" ]], - embed: ["+strings"], + embed, bAutoWidth: false, columns: [ [% IF (StaffDetailItemSelection) %] @@ -2519,10 +2523,24 @@ { data: "", className: "cover", - searchable: true, - orderable: true, + searchable: false, + orderable: false, render: function (data, type, row, meta) { - return ""; // FIXME Build cover images + if ( !row.cover_image_ids.length > 0 ) { + return ''; + } + let node = '
'; + node += '
'; + row.cover_image_ids.forEach(id => { + node += ''; + }); + node += '
'; + node += '
'; + return node; } }, [% END %] -- 2.34.1