From 87d64ea38436280aef7060e2be1d24f4b037978f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 Jun 2022 14:32:02 +0200 Subject: [PATCH] Bug 32030: Some refactoring and improvements Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/Providers/EBSCO.pm | 99 +++++- Koha/REST/V1/ERM/EHoldings/Packages.pm | 2 +- Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm | 86 ++--- Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm | 107 +----- Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm | 43 +-- cypress/integration/Packages_spec.ts | 2 +- .../ERM/EHoldingsPackageTitlesList.vue | 188 ++++++----- .../components/ERM/EHoldingsPackagesList.vue | 318 +++++++++--------- .../ERM/EHoldingsTitlePackagesList.vue | 138 ++++---- .../ERM/EHoldingsTitlesFormConfirmDelete.vue | 2 +- .../components/ERM/EHoldingsTitlesList.vue | 305 +++++++++-------- 11 files changed, 623 insertions(+), 667 deletions(-) diff --git a/Koha/ERM/Providers/EBSCO.pm b/Koha/ERM/Providers/EBSCO.pm index 7326184814..bbac755ab9 100644 --- a/Koha/ERM/Providers/EBSCO.pm +++ b/Koha/ERM/Providers/EBSCO.pm @@ -52,7 +52,7 @@ sub build_title { my @contributors = @{ $result->{contributorsList} }; my $first_author = first { $_->{type} eq 'author' || $_->{type} eq 'Author' } @contributors; if ( $first_author ) { - $title->{first_author} = $first_author->{contributor} + $title->{first_author} = $first_author->{contributor}; } } for my $identifier ( @{ $result->{identifiersList} } ) { @@ -71,8 +71,9 @@ sub build_title { sub build_vendor { my ( $self, $result ) = @_; my $vendor = { - vendor_id => $result->{vendorId}, - name => $result->{vendorName}, + vendor_id => $result->{vendorId}, + name => $result->{vendorName}, + package_type => $result->{packageType}, }; return $vendor; } @@ -80,8 +81,13 @@ sub build_vendor { sub build_package { my ( $self, $result ) = @_; my $package = { - package_id => $result->{packageId}, - name => $result->{packageName}, + package_id => $result->{vendorId} . '-' . $result->{packageId}, + name => $result->{packageName}, + content_type => $result->{contentType}, # This does not exist in /vendors/1/packages/2/titles/3 + created_on => undef, + is_selected => $result->{isSelected}, + package_type => $result->{packageType}, + vendor_id => $result->{vendorId}, }; return $package; } @@ -89,11 +95,90 @@ sub build_package { sub build_resource { my ( $self, $result ) = @_; my $resource = { - resource_id => $result->{vendorId} . '-' . $result->{packageId} . '-'. $result->{titleId}, - is_selected => $result->{isSelected}, + resource_id => $result->{vendorId} . '-' + . $result->{packageId} . '-' + . $result->{titleId}, + package_id => $result->{vendorId} . '-' . $result->{packageId}, + title_id => $result->{titleId}, + is_selected => $result->{isSelected}, + started_on => $result->{managedCoverageList}->[0]->{beginCoverage}, + ended_on => $result->{managedCoverageList}->[0]->{endCoverage}, + }; + return $resource; +} + +sub build_additional_params { + my ( $self, $query_params ) = @_; + + my $additional_params; + if ( $query_params->{q} ) { + my $q = decode_json $query_params->{q}; + while ( my ( $attr, $value ) = each %$q ) { + $additional_params->{$attr} = $value; + } } + + return $additional_params; } +sub embed { + my ( $self, $object, $info, $embed_header ) = @_; + $embed_header ||= q{}; + + my @embed_resources; + foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { + if ( $embed_req eq 'vendor.name' ) { + $object->{vendor} = { name => $info->{vendorName}, }; + } + elsif ( $embed_req eq 'vendor' ) { + $object->{vendor} = $self->build_vendor($info); + } + elsif ( $embed_req eq 'title' ) { + $object->{title} = $self->build_title($info); + } + elsif ( $embed_req eq 'resources+count' ) { + $object->{resources_count} = $info->{titleCount}; + } + elsif ( $embed_req eq 'package' ) { + $object->{package} = $self->build_package($info); + } + elsif ( $embed_req eq 'package.name' ) { + $object->{package} = { name => $info->{packageName}, }; + } + if ( $embed_req eq 'resources' || $embed_req eq 'resources.package' ) { + push @embed_resources, $embed_req; + } + } + + if (@embed_resources) { + for my $r ( @{ $info->{customerResourcesList} } ) { + my $resource = {}; + for my $embed_req ( @embed_resources ) { + if ( $embed_req eq 'resources' ) { + $resource = $self->build_resource($r); + } + elsif ( $embed_req eq 'resources.package' ) { + unless ( %$resource ) { + $resource = $self->build_resource($r); + } + $resource->{package} = $self->build_package($r); + } + } + push @{$object->{resources}}, $resource; + } + } + return $object; +} + +sub build_query_pagination { + my ( $self, $params ) = @_; + my $per_page = $params->{_per_page} + // C4::Context->preference('RESTdefaultPageSize') // 20; + if ( $per_page == -1 || $per_page > 100 ) { $per_page = 100; } + my $page = $params->{_page} || 1; + + return ( $per_page, $page ); +} sub build_query { my ( $self, $url, $params ) = @_; diff --git a/Koha/REST/V1/ERM/EHoldings/Packages.pm b/Koha/REST/V1/ERM/EHoldings/Packages.pm index fa974fc4a8..7e7b983848 100644 --- a/Koha/REST/V1/ERM/EHoldings/Packages.pm +++ b/Koha/REST/V1/ERM/EHoldings/Packages.pm @@ -96,7 +96,7 @@ sub delete { if ( $provider eq 'ebsco' ) { die "invalid action"; } else { - return Koha::REST::V1::ERM::EHoldings::Packages::Manual::update(@_); + return Koha::REST::V1::ERM::EHoldings::Packages::Manual::delete(@_); } } diff --git a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm index ddb93b4c27..938ebcd45e 100644 --- a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm @@ -30,56 +30,30 @@ sub list { return try { - my $args = $c->validation->output; - my $params = '?orderby=packagename&offset=1&count=1'; - my $result = - Koha::ERM::Providers::EBSCO->request( GET => '/packages' . $params ); + my $args = $c->validation->output; + my $params = '?orderby=packagename&offset=1&count=1'; + my $ebsco = Koha::ERM::Providers::EBSCO->new; + my $result = $ebsco->request( GET => '/packages' . $params ); my $base_total = $result->{totalResults}; - my $per_page = $args->{_per_page} - // C4::Context->preference('RESTdefaultPageSize') // 20; - if ( $per_page == -1 || $per_page > 100 ) { $per_page = 100; } - my $page = $args->{_page} || 1; - - my ( $search, $content_type, $selection_type ); - my $query_params = $c->req->params->to_hash; - my $additional_params; - if ( $query_params->{q} ) { - my $q = decode_json $query_params->{q}; - while ( my ( $attr, $value ) = each %$q ) { - $additional_params->{$attr} = $value; - } - } + my ( $per_page, $page ) = $ebsco->build_query_pagination($args); + my $additional_params = + $ebsco->build_additional_params( $c->req->params->to_hash ); my $orderby = $additional_params->{name} ? 'relevance' : 'packagename'; - $params = sprintf '?orderby=%s&offset=%s&count=%s', $orderby, $page, - $per_page; - $result = Koha::ERM::Providers::EBSCO->request( + $params = sprintf '?orderby=%s&offset=%s&count=%s', $orderby, $page, $per_page; + + $result = $ebsco->request( GET => '/packages' . $params, $additional_params ); my @packages; for my $p ( @{ $result->{packagesList} } ) { - my $package = { - content_type => $p->{contentType}, - created_on => undef, - is_selected => $p->{isSelected}, - name => $p->{packageName}, - package_id => $p->{vendorId} . '-' . $p->{packageId}, - package_type => $p->{packageType}, - vendor_id => $p->{vendorId}, - }; - my $embed_header = $c->req->headers->header('x-koha-embed') || q{}; - foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { - if ( $embed_req eq 'vendor.name' ) { - $package->{vendor} = { name => $p->{vendorName}, }; - } - elsif ( $embed_req eq 'resources+count' ) { - $package->{resources_count} = $p->{titleCount}; - } - } - push @packages, $package; + my $package = $ebsco->build_package($p); + $package = + $ebsco->embed( $package, $p, $c->req->headers->header('x-koha-embed') ); + push @packages, $package; } my $total = $result->{totalResults}; $total = 10000 if $total > 10000; @@ -104,7 +78,8 @@ sub get { return try { my ( $vendor_id, $package_id ) = split '-', $c->validation->param('package_id'); - my $p = Koha::ERM::Providers::EBSCO->request( + my $ebsco = Koha::ERM::Providers::EBSCO->new; + my $p = $ebsco->request( GET => '/vendors/' . $vendor_id . '/packages/' . $package_id ); unless ($p) { return $c->render( @@ -113,31 +88,16 @@ sub get { ); } - my $package = { - content_type => $p->{contentType}, - name => $p->{packageName}, - package_id => $p->{vendorId} . '-' . $p->{packageId}, - package_type => $p->{packageType}, - vendor_id => $p->{vendorId}, - }; - - my $embed_header = $c->req->headers->header('x-koha-embed') || q{}; - foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { - if ( $embed_req eq 'vendor' ) { - $package->{vendor} = { - id => $p->{vendorId}, - name => $p->{vendorName}, - }; - } - elsif ( $embed_req eq 'resources+count' ) { - $package->{resources_count} = $p->{titleCount}; - } - } + my $package = $ebsco->build_package($p); - return $c->render( + $package = + $ebsco->embed( $package, $p, + $c->req->headers->header('x-koha-embed') ); + + return $c->render( status => 200, openapi => $package - ); + ); } catch { $c->unhandled_exception($_); diff --git a/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm index 555a6e3099..c378ddb69a 100644 --- a/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm @@ -39,8 +39,9 @@ sub list { return try { my $args = $c->validation->output; + my $ebsco = Koha::ERM::Providers::EBSCO->new; - # FIXME Do we need more validation here? Don't think so we have the API specs. + # FIXME Do we need more validation here? Don't think so we have the API specs. my ( $vendor_id, $package_id ) = split '-', $c->validation->param('package_id') || q{}; my $title_id = $c->validation->param('title_id') || q{}; @@ -55,7 +56,7 @@ sub list { my $result; try { $result = - Koha::ERM::Providers::EBSCO->request( GET => $url . $params ); + $ebsco->request( GET => $url . $params ); } catch { if ( blessed $_ ) { @@ -73,26 +74,17 @@ sub list { my $base_total = $result->{totalResults}; - my $per_page = $args->{_per_page} - // C4::Context->preference('RESTdefaultPageSize') // 20; - if ( $per_page == -1 || $per_page > 100 ) { $per_page = 100; } - my $page = $args->{_page} || 1; + my ( $per_page, $page ) = $ebsco->build_query_pagination($args); my ( $search, $content_type, $selection_type ); - my $query_params = $c->req->params->to_hash; - my $additional_params; - if ( $query_params->{q} ) { - my $q = decode_json $query_params->{q}; - while ( my ( $attr, $value ) = each %$q ) { - $additional_params->{$attr} = $value; - } - } + my $additional_params = $ebsco->build_additional_params( $c->req->params->to_hash ); my $searchfield = 'titlename'; $params = sprintf '?orderby=titlename&offset=%s&count=%s&searchfield=%s', $page, $per_page, $searchfield; - $result = Koha::ERM::Providers::EBSCO->request( + + $result = $ebsco->request( GET => $url . $params, $additional_params ); @@ -101,30 +93,12 @@ sub list { for my $t ( @{ $result->{titles} } ) { my $r = $t->{customerResourcesList}->[0]; # FIXME What about the others? - my $resource = { - resource_id => $r->{vendorId} . '-' - . $r->{packageId} . '-' - . $r->{titleId}, - package_id => $r->{vendorId} . '-' . $r->{packageId}, - title_id => $r->{titleId}, - is_selected => $r->{isSelected}, - started_on => $r->{managedCoverageList}->[0]->{beginCoverage}, - ended_on => $r->{managedCoverageList}->[0]->{endCoverage}, - }; - my $embed_header = $c->req->headers->header('x-koha-embed') || q{}; - foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { - if ( $embed_req eq 'title.publication_title' ) { - $resource->{title} = { - publication_title => $t->{titleName}, - publisher_name => $t->{publisherName}, - publication_type => $t->{pubType}, - }; - } - elsif ( $embed_req eq 'package.name' ) { - $resource->{package} = { name => $t->{packageName}, }; - } - } + my $resource = $ebsco->build_resource($r); + + $resource = $ebsco->embed( $resource, $t, + $c->req->headers->header('x-koha-embed') ); + push @resources, $resource; } my $total = $result->{totalResults}; @@ -153,10 +127,9 @@ sub get { return try { my ( $vendor_id, $package_id, $resource_id ) = split '-', $c->validation->param('resource_id'); - my $t; - try { - $t = - Koha::ERM::Providers::EBSCO->request( GET => '/vendors/' + my $ebsco = Koha::ERM::Providers::EBSCO->new; + my $t = try { + return $ebsco->request( GET => '/vendors/' . $vendor_id . '/packages/' . $package_id @@ -186,55 +159,9 @@ sub get { } my $r = $t->{customerResourcesList}->[0]; # FIXME What about the others? - my $resource = { - resource_id => $r->{vendorId} . '-' - . $r->{packageId} . '-' - . $r->{titleId}, - package_id => $r->{vendorId} . '-' . $r->{packageId}, - title_id => $r->{titleId}, - started_on => $r->{managedCoverageList}->[0]->{beginCoverage}, - ended_on => $r->{managedCoverageList}->[0]->{endCoverage}, - }; + my $resource = $ebsco->build_resource($r); - my $embed_header = $c->req->headers->header('x-koha-embed') || q{}; - foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { - if ( $embed_req eq 'title' ) { - $resource->{title} = { - publication_title => $t->{titleName}, - publisher_name => $t->{publisherName}, - publication_type => $t->{pubType}, - }; - for my $identifier ( @{ $t->{identifiersList} } ) { - - # FIXME $identifier->{type} : 0 for ISSN and 1 for ISBN - if ( $identifier->{subtype} == 1 ) { - $resource->{title}->{print_identifier} = - $identifier->{id}; - } - elsif ( $identifier->{subtype} == 1 ) { - $resource->{title}->{online_identifier} = - $identifier->{id}; - } - } - } - elsif ( $embed_req eq 'package' ) { - $resource->{package} = { - - #content_type => $e->{contentType}, FIXME We don't have that - name => $r->{packageName}, - package_id => $r->{vendorId} . '-' . $r->{packageId}, - package_type => $r->{packageType}, - vendor_id => $r->{vendorId}, - }; - } - elsif ( $embed_req eq 'vendor' ) { - $resource->{vendor} = { - name => $r->{vendorName}, - id => $r->{vendorId}, - package_type => $r->{packageType}, - }; - } - } + $resource = $ebsco->embed( $resource, {%$t, %$r}, $c->req->headers->header('x-koha-embed') ); return $c->render( status => 200, diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm index 3537a8b195..1fb79055eb 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm @@ -43,24 +43,11 @@ sub list { my $ebsco = Koha::ERM::Providers::EBSCO->new; # We cannot get base_total as a search kw is required by the API - #my $params = '?orderby=relevance&offset=1&count=1&searchfield=titlename&search=a'; - #my $result = $ebsco->request( GET => '/titles' . $params ); - #my $base_total = $result->{totalResults}; - my $per_page = $args->{_per_page} - // C4::Context->preference('RESTdefaultPageSize') // 20; - if ( $per_page == -1 || $per_page > 100 ) { $per_page = 100; } - my $page = $args->{_page} || 1; + my ( $per_page, $page ) = $ebsco->build_query_pagination($args); my ( $search, $content_type, $selection_type ); - my $query_params = $c->req->params->to_hash; - my $additional_params; - if ( $query_params->{q} ) { - my $q = decode_json $query_params->{q}; - while ( my ( $attr, $value ) = each %$q ) { - $additional_params->{$attr} = $value; - } - } + my $additional_params = $ebsco->build_additional_params( $c->req->params->to_hash ); unless ( defined $additional_params->{publication_title} ) { @@ -85,16 +72,11 @@ sub list { my $result = $ebsco->request( GET => '/titles' . $params, $additional_params ); + my $embed_header = $c->req->headers->header('x-koha-embed'); my @titles; for my $t ( @{ $result->{titles} } ) { my $title = $ebsco->build_title($t); - - my $embed_header = $c->req->headers->header('x-koha-embed') || q{}; - foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { - if ( $embed_req eq 'vendor.name' ) { - $title->{vendor} = $ebsco->build_vendor($t); - } - } + $title = $ebsco->embed( $title, $t, $embed_header ); push @titles, $title; } my $total = $result->{totalResults}; @@ -132,20 +114,9 @@ sub get { ); } - my $title = $ebsco->build_title($t); - my $embed_header = $c->req->headers->header('x-koha-embed') || q{}; - for my $r ( @{ $t->{customerResourcesList} } ) { - my $resource = {}; - foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { - if ( $embed_req eq 'resources' ) { - $resource = $ebsco->build_resource($r); - } - elsif ( $embed_req eq 'resources.package' ) { - $resource->{package} = $ebsco->build_package($r); - } - } - push @{ $title->{resources} }, $resource; - } + my $title = $ebsco->build_title($t); + $title = + $ebsco->embed( $title, $t, $c->req->headers->header('x-koha-embed') ); return $c->render( status => 200, diff --git a/cypress/integration/Packages_spec.ts b/cypress/integration/Packages_spec.ts index 29ef68e3e6..4cb17d0569 100644 --- a/cypress/integration/Packages_spec.ts +++ b/cypress/integration/Packages_spec.ts @@ -7,7 +7,7 @@ function get_package() { package_id: 1, name: "package 1", package_type: "complete", - content_type: "print", + content_type: "Print", package_agreements: [], }; } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsPackageTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsPackageTitlesList.vue index 39a60a93da..3871cf846f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsPackageTitlesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsPackageTitlesList.vue @@ -12,12 +12,16 @@
  • -
  • - @@ -69,6 +76,11 @@ export default { }, data() { return { + filters: { + publication_title: "", + publication_type: "", + selection_type: "", + }, display_filters: false, } }, @@ -83,101 +95,99 @@ export default { toggle_filters: function (e) { this.display_filters = !this.display_filters }, - }, - mounted() { - let show_resource = this.show_resource - let package_id = this.package_id - let get_lib_from_av = this.get_lib_from_av + build_datatable: function () { + let show_resource = this.show_resource + let package_id = this.package_id + let get_lib_from_av = this.get_lib_from_av + let filters = this.filters - window['av_title_publication_types'] = this.av_title_publication_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) + window['av_title_publication_types'] = this.av_title_publication_types.map(e => { + e['_id'] = e['authorised_value'] + e['_str'] = e['lib'] + return e + }) - let additional_filters = {} - if (erm_provider != 'manual') { - additional_filters = { - publication_title: function () { - let publication_title_search = $("#publication_title_filter").val() - if (!publication_title_search) return "" - return publication_title_search - }, - publication_type: function () { - let content_type_search = $("#publication_type_filter").val() - if (!content_type_search) return "" - return content_type_search - }, - selection_type: function () { - let selection_type_search = $("#selection_type_filter").val() - if (!selection_type_search) return "" - return selection_type_search - }, + let additional_filters = {} + if (erm_provider != 'manual') { + additional_filters = { + publication_title: function () { + return filters.publication_title || "" + }, + publication_type: function () { + return filters.publication_type || "" + }, + selection_type: function () { + return filters.selection_type || "" + }, + } } - } - $('#title_list').kohaTable({ - "ajax": { - "url": "/api/v1/erm/eholdings/packages/" + package_id + "/resources", - }, - ...(erm_provider != 'manual' ? { ordering: false } : {}), - ...(erm_provider != 'manual' ? { dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>' } : {}), - ...(erm_provider != 'manual' ? { lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]] } : {}), - "embed": ['title.publication_title'], - autoWidth: false, - "columns": [ - { - "title": __("Name"), - "data": "title.publication_title", - "searchable": (erm_provider == 'manual') ? 1 : 0, - "orderable": (erm_provider == 'manul') ? 1 : 0, - "render": function (data, type, row, meta) { - // Rendering done in drawCallback - return "" - } - }, - { - "title": __("Publication type"), - "data": "title.publication_type", - "searchable": (erm_provider == 'manual') ? 1 : 0, - "orderable": (erm_provider == 'manul') ? 1 : 0, - "render": function (data, type, row, meta) { - return escape_str(get_lib_from_av("av_title_publication_types", row.title.publication_type)) - } + $('#title_list').kohaTable({ + "ajax": { + "url": "/api/v1/erm/eholdings/packages/" + package_id + "/resources", }, - ], - drawCallback: function (settings) { + ...(erm_provider != 'manual' ? { ordering: false } : {}), + ...(erm_provider != 'manual' ? { dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>' } : {}), + ...(erm_provider != 'manual' ? { aLengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]] } : {}), + "embed": ['title'], + autoWidth: false, + "columns": [ + { + "title": __("Name"), + "data": "title.publication_title", + "searchable": (erm_provider == 'manual') ? 1 : 0, + "orderable": (erm_provider == 'manul') ? 1 : 0, + "render": function (data, type, row, meta) { + // Rendering done in drawCallback + return "" + } + }, + { + "title": __("Publication type"), + "data": "title.publication_type", + "searchable": (erm_provider == 'manual') ? 1 : 0, + "orderable": (erm_provider == 'manul') ? 1 : 0, + "render": function (data, type, row, meta) { + return escape_str(get_lib_from_av("av_title_publication_types", row.title.publication_type)) + } + }, + ], + drawCallback: function (settings) { - var api = new $.fn.dataTable.Api(settings) + var api = new $.fn.dataTable.Api(settings) - $.each($(this).find("tbody tr td:first-child"), function (index, e) { - let row = api.row(index).data() - if (!row) return // Happen if the table is empty - let n = createVNode("a", { - role: "button", - href: "/cgi-bin/koha/erm/eholdings/resources/" + row.resource_id, - onClick: (e) => { - e.preventDefault() - show_resource(row.resource_id) + $.each($(this).find("tbody tr td:first-child"), function (index, e) { + let row = api.row(index).data() + if (!row) return // Happen if the table is empty + let n = createVNode("a", { + role: "button", + href: "/cgi-bin/koha/erm/eholdings/resources/" + row.resource_id, + onClick: (e) => { + e.preventDefault() + show_resource(row.resource_id) + } + }, + `${row.title.publication_title}` + ) + if (row.is_selected) { + n = createVNode('span', {}, [n, " ", createVNode("i", { class: "fa fa-check-square-o", style: { color: "green" }, title: __("Is selected") })]) + } + render(n, e) + }) + }, + ...(erm_provider == 'manual' ? { + preDrawCallback: function (settings) { + var table_id = settings.nTable.id + if (erm_provider == 'manual') { + $("#" + table_id).find("thead th").eq(1).attr('data-filter', 'av_title_publication_types') } - }, - `${row.title.publication_title}` - ) - if (row.is_selected) { - n = createVNode('span', {}, [n, " ", createVNode("i", { class: "fa fa-check-square-o", style: { color: "green" }, title: __("Is selected") })]) - } - render(n, e) - }) - }, - ...(erm_provider == 'manual' ? { - preDrawCallback: function (settings) { - var table_id = settings.nTable.id - if (erm_provider == 'manual') { - $("#" + table_id).find("thead th").eq(1).attr('data-filter', 'av_title_publication_types') } - } - } : {}), - }, null, erm_provider == 'manual' ? 1 : 0, additional_filters) + } : {}), + }, null, erm_provider == 'manual' ? 1 : 0, additional_filters) + }, + }, + mounted() { + this.build_datatable() }, beforeUnmount() { $('#title_list') @@ -193,7 +203,7 @@ export default { \ No newline at end of file + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormConfirmDelete.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormConfirmDelete.vue index 1c2366d97c..8ff9e0dfc3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormConfirmDelete.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormConfirmDelete.vue @@ -55,7 +55,7 @@ export default { onSubmit(e) { e.preventDefault() - let apiUrl = '/api/v1/erm/eholdings/titles' + this.title_id + let apiUrl = '/api/v1/erm/eholdings/titles/' + this.eholding.title_id const options = { method: 'DELETE', diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesList.vue index dffb5ada29..710e3ceffb 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesList.vue @@ -3,14 +3,13 @@
    {{ $t("Loading") }}
    -
    +
    +
    +
    {{ $t("There are no titles defined") }}
    -
    -
    -
    @@ -94,7 +93,7 @@ export default { }, beforeRouteEnter(to, from, next) { next(vm => { - vm.getTitles() + vm.getTitles().then(() => vm.build_datatable()) }) }, inject: ['erm_provider'], @@ -123,170 +122,170 @@ export default { } else { this.cannot_search = true } - } - }, - updated() { - let show_title = this.show_title - let edit_title = this.edit_title - let delete_title = this.delete_title - let get_lib_from_av = this.get_lib_from_av - let filters = this.filters + }, + build_datatable: function () { + let show_title = this.show_title + let edit_title = this.edit_title + let delete_title = this.delete_title + let get_lib_from_av = this.get_lib_from_av + let filters = this.filters - window['vendors'] = this.vendors.map(e => { - e['_id'] = e['id'] - e['_str'] = e['name'] - return e - }) - let vendors_map = this.vendors.reduce((map, e) => { - map[e.id] = e - return map - }, {}) - window['av_title_publication_types'] = this.av_title_publication_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) + window['vendors'] = this.vendors.map(e => { + e['_id'] = e['id'] + e['_str'] = e['name'] + return e + }) + let vendors_map = this.vendors.reduce((map, e) => { + map[e.id] = e + return map + }, {}) + window['av_title_publication_types'] = this.av_title_publication_types.map(e => { + e['_id'] = e['authorised_value'] + e['_str'] = e['lib'] + return e + }) - let additional_filters = {} - if (erm_provider != 'manual') { - additional_filters = { - publication_title: function () { - return filters.publication_title || "" - }, - publication_type: function () { - return filters.content_type_search || "" - }, - selection_type: function () { - return filters.selection_type || "" - }, + let additional_filters = {} + if (erm_provider != 'manual') { + additional_filters = { + publication_title: function () { + return filters.publication_title || "" + }, + publication_type: function () { + return filters.content_type_search || "" + }, + selection_type: function () { + return filters.selection_type || "" + }, + } } - } - $('#title_list').kohaTable({ - "ajax": { - "url": "/api/v1/erm/eholdings/titles", - }, - embed: ["resources.package"], - ...(erm_provider == 'manual' ? { order: [[0, "asc"]] } : {}), - ...(erm_provider != 'manual' ? { ordering: false } : {}), - ...(erm_provider == 'manual' ? { search: { search: filters.publication_title } } : {}), - ...(erm_provider != 'manual' ? { dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>' } : {}), - ...(erm_provider != 'manual' ? { lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]] } : {}), - ...(erm_provider != 'manual' ? { deferLoading: true } : {}), - autoWidth: false, - "columns": [ - { - "title": __("Title"), - "data": "me.publication_title", - "searchable": (erm_provider == 'manual'), - "orderable": (erm_provider == 'manul'), - "render": function (data, type, row, meta) { - // Rendering done in drawCallback - return "" - } - }, - { - "title": __("Vendor"), - "data": "vendor_id", - "searchable": (erm_provider == 'manual'), - "orderable": (erm_provider == 'manul'), - "render": function (data, type, row, meta) { - return row.vendor_id != undefined ? escape_str(vendors_map[row.vendor_id].name) : "" - } - }, - { - "title": __("Publication type"), - "data": "publication_type", - "searchable": (erm_provider == 'manual'), - "orderable": (erm_provider == 'manul'), - "render": function (data, type, row, meta) { - return escape_str(get_lib_from_av("av_title_publication_types", row.publication_type)) - } - }, - { - "title": __("Identifier"), - "data": "print_identifier:online_identifier", - "searchable": (erm_provider == 'manual'), - "orderable": (erm_provider == 'manul'), - "render": function (data, type, row, meta) { - let print_identifier = row.print_identifier - let online_identifier = row.online_identifier - return (print_identifier ? escape_str(_("ISBN (Print): %s").format(print_identifier)) : "") + - (online_identifier ? escape_str(_("ISBN (Online): %s").format(online_identifier)) : "") - } + $('#title_list').kohaTable({ + "ajax": { + "url": "/api/v1/erm/eholdings/titles", }, - erm_provider == 'manual' ? { - "title": __("Actions"), - "data": function (row, type, val, meta) { - return '
    ' + embed: ["resources.package"], + ...(erm_provider == 'manual' ? { order: [[0, "asc"]] } : {}), + ...(erm_provider != 'manual' ? { ordering: false } : {}), + ...(erm_provider == 'manual' ? { search: { search: filters.publication_title } } : {}), + ...(erm_provider != 'manual' ? { dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>' } : {}), + ...(erm_provider != 'manual' ? { aLengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]] } : {}), + ...(erm_provider != 'manual' ? { deferLoading: true } : {}), + autoWidth: false, + "columns": [ + { + "title": __("Title"), + "data": "me.publication_title", + "searchable": (erm_provider == 'manual'), + "orderable": (erm_provider == 'manul'), + "render": function (data, type, row, meta) { + // Rendering done in drawCallback + return "" + } }, - "className": "actions noExport", - "searchable": false, - "orderable": false - } : null, - ].filter(Boolean), - drawCallback: function (settings) { - - var api = new $.fn.dataTable.Api(settings) - - $.each($(this).find("td .actions"), function (index, e) { - let title_id = api.row(index).data().title_id - let editButton = createVNode("a", { - class: "btn btn-default btn-xs", role: "button", onClick: () => { - edit_title(title_id) + { + "title": __("Vendor"), + "data": "vendor_id", + "searchable": (erm_provider == 'manual'), + "orderable": (erm_provider == 'manul'), + "render": function (data, type, row, meta) { + return row.vendor_id != undefined ? escape_str(vendors_map[row.vendor_id].name) : "" } }, - [createVNode("i", { class: "fa fa-pencil", 'aria-hidden': "true" }), __("Edit")]) - - let deleteButton = createVNode("a", { - class: "btn btn-default btn-xs", role: "button", onClick: () => { - delete_title(title_id) + { + "title": __("Publication type"), + "data": "publication_type", + "searchable": (erm_provider == 'manual'), + "orderable": (erm_provider == 'manul'), + "render": function (data, type, row, meta) { + return escape_str(get_lib_from_av("av_title_publication_types", row.publication_type)) } }, - [createVNode("i", { class: "fa fa-trash", 'aria-hidden': "true" }), __("Delete")]) - - let n = createVNode('span', {}, [editButton, " ", deleteButton]) - render(n, e) - }) - - $.each($(this).find("tbody tr td:first-child"), function (index, e) { - let row = api.row(index).data() - if (!row) return // Happen if the table is empty - let n = createVNode("a", { - role: "button", - onClick: (e) => { - e.preventDefault() - show_title(row.title_id) + { + "title": __("Identifier"), + "data": "print_identifier:online_identifier", + "searchable": (erm_provider == 'manual'), + "orderable": (erm_provider == 'manul'), + "render": function (data, type, row, meta) { + let print_identifier = row.print_identifier + let online_identifier = row.online_identifier + return (print_identifier ? escape_str(_("ISBN (Print): %s").format(print_identifier)) : "") + + (online_identifier ? escape_str(_("ISBN (Online): %s").format(online_identifier)) : "") } }, - `${row.publication_title} (#${row.title_id})` - ) - // TODO? We don't have is_selected at title level - //if (row.is_selected) { - // n = createVNode('span', {}, [n, " ", createVNode("i", { class: "fa fa-check-square-o", style: { color: "green" }, title: __("Is selected") })]) - //} - render(n, e) - }) - }, - ...(erm_provider == 'manual' ? { - preDrawCallback: function (settings) { - var table_id = settings.nTable.id - $("#" + table_id).find("thead th").eq(1).attr('data-filter', 'vendors') - } - } : {}), - }, eholdings_titles_table_settings, erm_provider == 'manual' ? 1 : 0, additional_filters) + erm_provider == 'manual' ? { + "title": __("Actions"), + "data": function (row, type, val, meta) { + return '
    ' + }, + "className": "actions noExport", + "searchable": false, + "orderable": false + } : null, + ].filter(Boolean), + drawCallback: function (settings) { - if (erm_provider != 'manual') { - if (filters.publication_title.length) { - this.filter_table() + var api = new $.fn.dataTable.Api(settings) + + $.each($(this).find("td .actions"), function (index, e) { + let title_id = api.row(index).data().title_id + let editButton = createVNode("a", { + class: "btn btn-default btn-xs", role: "button", onClick: () => { + edit_title(title_id) + } + }, + [createVNode("i", { class: "fa fa-pencil", 'aria-hidden': "true" }), __("Edit")]) + + let deleteButton = createVNode("a", { + class: "btn btn-default btn-xs", role: "button", onClick: () => { + delete_title(title_id) + } + }, + [createVNode("i", { class: "fa fa-trash", 'aria-hidden': "true" }), __("Delete")]) + + let n = createVNode('span', {}, [editButton, " ", deleteButton]) + render(n, e) + }) + + $.each($(this).find("tbody tr td:first-child"), function (index, e) { + let row = api.row(index).data() + if (!row) return // Happen if the table is empty + let n = createVNode("a", { + role: "button", + onClick: (e) => { + e.preventDefault() + show_title(row.title_id) + } + }, + `${row.publication_title} (#${row.title_id})` + ) + // TODO? We don't have is_selected at title level + //if (row.is_selected) { + // n = createVNode('span', {}, [n, " ", createVNode("i", { class: "fa fa-check-square-o", style: { color: "green" }, title: __("Is selected") })]) + //} + render(n, e) + }) + }, + ...(erm_provider == 'manual' ? { + preDrawCallback: function (settings) { + var table_id = settings.nTable.id + $("#" + table_id).find("thead th").eq(1).attr('data-filter', 'vendors') + } + } : {}), + }, eholdings_titles_table_settings, erm_provider == 'manual' ? 1 : 0, additional_filters) + + if (erm_provider != 'manual') { + if (filters.publication_title.length) { + this.filter_table() + } } - } + }, }, beforeUnmount() { - $('#title_list') - .DataTable() - .destroy(true) + //$('#title_list') + // .DataTable() + // .destroy(true) }, components: { Toolbar }, name: "EHoldingsTitlesList", } - \ No newline at end of file + -- 2.39.5