From 7648464cfd06edd3eb293012a742304d7a7e86d2 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 17 Jul 2025 11:29:10 +0000 Subject: [PATCH] Bug 32333: (follow-up) Tidy --- koha-tmpl/opac-tmpl/bootstrap/js/idref.js | 102 ++++++++++++++-------- opac/svc/idref | 49 +++++------ 2 files changed, 88 insertions(+), 63 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/idref.js b/koha-tmpl/opac-tmpl/bootstrap/js/idref.js index 80fcb40ac52..2a166b85404 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/idref.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/idref.js @@ -1,15 +1,15 @@ -if (KOHA === undefined || !KOHA) { var KOHA = {}; } - +if (KOHA === undefined || !KOHA) { + var KOHA = {}; +} /** * A namespace for idref */ KOHA.idref = { - /** * Set a click handler for all anchors . */ - init: function() { + init: function () { $("a[class='idref-link']").click(this.click); }, @@ -17,67 +17,93 @@ KOHA.idref = { * Get the publications from author identified by its ppn, using Koha svc * webservice. Display the result in a new tab of the holdings table. */ - click: function(e) { + click: function (e) { const ppn = $(this).attr("ppn"); - const url = '/cgi-bin/koha/svc/idref?ppn=' + ppn; - $.getJSON(url, function(publications) { + const url = "/cgi-bin/koha/svc/idref?ppn=" + ppn; + $.getJSON(url, function (publications) { let html; - if (publications.name === '') { - html = __('Author not found in IdRef'); + if (publications.name === "") { + html = __("Author not found in IdRef"); } else { - const navig = publications.roles.map(role => '' + role.label + ' (' + role.docs.length + ')'); + const navig = publications.roles.map( + role => + '' + + role.label + + " (" + + role.docs.length + + ")" + ); html = - "

" + publications.name + " / " + - "" + - publications.ppn + "

" + - "
" + navig.join(' • ') + "
"; - publications.roles.forEach((role) => { + "

" + + publications.name + + " / " + + '' + + publications.ppn + + "

" + + '
' + + navig.join(" • ") + + "
"; + publications.roles.forEach(role => { html += - "

" + role.label + "

" + - ""; - role.docs.forEach((doc) => { + '

' + + role.label + + "

" + + '
'; + role.docs.forEach(doc => { html += ""; }); - html += '
" + - "" + - "" + + '' + + '' + ""; if (doc.bib) { html += - "" + - "" + + '' + + '' + ""; } html += "" + doc.citation + "
'; + html += ""; }); - html += '
'; + html += "
"; } - const idrefDiv = $('#idref-publications'); + const idrefDiv = $("#idref-publications"); if (idrefDiv.length) { idrefDiv.html(html); } else { - html = "
" + html + "
"; + html = '
' + html + "
"; const tabMenu = ''; - const tabs = $('#bibliodescriptions'); + ""; + const tabs = $("#bibliodescriptions"); const ul = tabs.find("ul"); $(ul).append(tabMenu); - $('.tab-content').append(html); + $(".tab-content").append(html); showBsTab("bibliodescriptions", "idref-publications"); } $('a[href="#idref-publications"]').click(); - $([document.documentElement, document.body]).animate({ - scrollTop: $("#idref-publications").offset().top - }, 2000); + $([document.documentElement, document.body]).animate( + { + scrollTop: $("#idref-publications").offset().top, + }, + 2000 + ); }); - } - + }, }; diff --git a/opac/svc/idref b/opac/svc/idref index b29cde474f8..aca99d5c3a9 100755 --- a/opac/svc/idref +++ b/opac/svc/idref @@ -25,22 +25,21 @@ use C4::Context; use C4::Output qw( output_with_http_headers ); use Search::Elasticsearch; - my $cgi = CGI->new; # See http://documentation.abes.fr/aideidrefdeveloppeur/index.html#MicroWebBiblio -my $base = 'http://www.idref.fr/services/biblio/'; +my $base = 'http://www.idref.fr/services/biblio/'; my $unimarc3 = $cgi->param('ppn'); my $publications = { name => '', ppn => $unimarc3, roles => [] }; -my $send_result = sub { +my $send_result = sub { my $json = to_json($publications); utf8::encode($json); - output_with_http_headers($cgi, undef, $json, 'json'); + output_with_http_headers( $cgi, undef, $json, 'json' ); exit; }; -my $ua = LWP::UserAgent->new; +my $ua = LWP::UserAgent->new; my $request = HTTP::Request->new( 'GET', $base . $unimarc3 . ".json", @@ -49,57 +48,57 @@ $request->protocol('HTTP/1.1'); my $response = $ua->request($request); $send_result->() if not $response->is_success; -my $content = Encode::decode("utf8", $response->content); -my $json = from_json($content); -my $result = $json->{sudoc}->{result}; +my $content = Encode::decode( "utf8", $response->content ); +my $json = from_json($content); +my $result = $json->{sudoc}->{result}; $send_result->() if $result->{countRoles} == 0; $publications->{name} = $result->{name}; -$result->{role} = [ $result->{role} ] if ref($result->{role}) ne 'ARRAY'; +$result->{role} = [ $result->{role} ] if ref( $result->{role} ) ne 'ARRAY'; my $ppn; -for my $r (@{$result->{role}}) { +for my $r ( @{ $result->{role} } ) { my $role = { - code => $r->{unimarcCode}, + code => $r->{unimarcCode}, label => $r->{roleName}, - docs => [], + docs => [], }; $r->{doc} = [ $r->{doc} ] if ref $r->{doc} ne 'ARRAY'; - for my $doc ( @{$r->{doc}} ) { - push @{$role->{docs}}, { - ppn => $doc->{ppn}, + for my $doc ( @{ $r->{doc} } ) { + push @{ $role->{docs} }, { + ppn => $doc->{ppn}, citation => $doc->{citation}, }; push @$ppn, $doc->{ppn}; } - push @{$publications->{roles}}, $role; + push @{ $publications->{roles} }, $role; } -my $ec = C4::Context->config('elasticsearch'); -my $e = Search::Elasticsearch->new( nodes => $ec->{server} ); +my $ec = C4::Context->config('elasticsearch'); +my $e = Search::Elasticsearch->new( nodes => $ec->{server} ); my $query = { index => $ec->{index_name} . '_biblios', - body => { + body => { _source => ["ppn"], - size => '10000', - query => { terms => { ppn => $ppn } } + size => '10000', + query => { terms => { ppn => $ppn } } } }; -my $res = $e->search($query); +my $res = $e->search($query); my $hits = $res->{hits}->{hits}; my $ppn_to_bib; for my $hit (@$hits) { my $ppn = $hit->{_source}->{ppn}->[0]; $ppn_to_bib->{$ppn} = $hit->{_id}; } -for my $role (@{$publications->{roles}}) { - my @docs = @{$role->{docs}}; +for my $role ( @{ $publications->{roles} } ) { + my @docs = @{ $role->{docs} }; for my $d (@docs) { my $bib = $ppn_to_bib->{ $d->{ppn} }; $d->{bib} = $bib if $bib; } my $key = sub { my $doc = shift; - ($doc->{bib} ? 'a' : 'b') . $doc->{citation}; + ( $doc->{bib} ? 'a' : 'b' ) . $doc->{citation}; }; @docs = sort { $key->($a) cmp $key->($b) } @docs; $role->{docs} = \@docs; -- 2.39.5