View | Details | Raw Unified | Return to bug 32333
Collapse All | Expand All

(-)a/koha-tmpl/opac-tmpl/bootstrap/js/idref.js (-38 / +64 lines)
Lines 1-15 Link Here
1
if (KOHA === undefined || !KOHA) { var KOHA = {}; }
1
if (KOHA === undefined || !KOHA) {
2
2
    var KOHA = {};
3
}
3
4
4
/**
5
/**
5
 * A namespace for idref
6
 * A namespace for idref
6
 */
7
 */
7
KOHA.idref = {
8
KOHA.idref = {
8
9
    /**
9
    /**
10
     * Set a click handler for all anchors <a class="idref-link">.
10
     * Set a click handler for all anchors <a class="idref-link">.
11
     */
11
     */
12
    init: function() {
12
    init: function () {
13
        $("a[class='idref-link']").click(this.click);
13
        $("a[class='idref-link']").click(this.click);
14
    },
14
    },
15
15
Lines 17-83 KOHA.idref = { Link Here
17
     * Get the publications from author identified by its ppn, using Koha svc
17
     * Get the publications from author identified by its ppn, using Koha svc
18
     * webservice. Display the result in a new tab of the holdings table.
18
     * webservice. Display the result in a new tab of the holdings table.
19
     */
19
     */
20
    click: function(e) {
20
    click: function (e) {
21
        const ppn = $(this).attr("ppn");
21
        const ppn = $(this).attr("ppn");
22
        const url = '/cgi-bin/koha/svc/idref?ppn=' + ppn;
22
        const url = "/cgi-bin/koha/svc/idref?ppn=" + ppn;
23
        $.getJSON(url, function(publications) {
23
        $.getJSON(url, function (publications) {
24
            let html;
24
            let html;
25
            if (publications.name === '') {
25
            if (publications.name === "") {
26
                html = __('Author not found in IdRef');
26
                html = __("Author not found in IdRef");
27
            } else {
27
            } else {
28
                const navig = publications.roles.map(role => '<a href="#idref-role-' + role.code + '" style="font-size: 90%;">' + role.label + ' (' + role.docs.length + ')</a>');
28
                const navig = publications.roles.map(
29
                    role =>
30
                        '<a href="#idref-role-' +
31
                        role.code +
32
                        '" style="font-size: 90%;">' +
33
                        role.label +
34
                        " (" +
35
                        role.docs.length +
36
                        ")</a>"
37
                );
29
                html =
38
                html =
30
                    "<h2>" + publications.name + " / <small>" +
39
                    "<h2>" +
31
                    "<a href=\"https://www.idref.fr/" + publications.ppn + "\" target=\"_blank\">" +
40
                    publications.name +
32
                    publications.ppn + "</a></small></h2>" +
41
                    " / <small>" +
33
                    "<div><div style=\"margin-bottom: 5px;\"> " + navig.join(' • ') + "</div>";
42
                    '<a href="https://www.idref.fr/' +
34
                publications.roles.forEach((role) => {
43
                    publications.ppn +
44
                    '" target="_blank">' +
45
                    publications.ppn +
46
                    "</a></small></h2>" +
47
                    '<div><div style="margin-bottom: 5px;"> ' +
48
                    navig.join(" • ") +
49
                    "</div>";
50
                publications.roles.forEach(role => {
35
                    html +=
51
                    html +=
36
                        "<h3 id=\"idref-role-" + role.code + "\">" + role.label + "</h3>" +
52
                        '<h3 id="idref-role-' +
37
                        "<table class=\"table table-striped table-hover table-sm\"><tbody>";
53
                        role.code +
38
                    role.docs.forEach((doc) => {
54
                        '">' +
55
                        role.label +
56
                        "</h3>" +
57
                        '<table class="table table-striped table-hover table-sm"><tbody>';
58
                    role.docs.forEach(doc => {
39
                        html +=
59
                        html +=
40
                            "<tr><td>" +
60
                            "<tr><td>" +
41
                            "<a href=\"https://www.sudoc.fr/" + doc.ppn + " target=\"_blank\" rel=\"noreferrer\">" +
61
                            '<a href="https://www.sudoc.fr/' +
42
                            "<img title=\"" +
62
                            doc.ppn +
43
                            __('Publication In Sudoc Catalog') +
63
                            ' target="_blank" rel="noreferrer">' +
44
                            "\" src=\"/opac-tmpl/bootstrap/images/sudoc.png\" />" +
64
                            '<img title="' +
65
                            __("Publication In Sudoc Catalog") +
66
                            '" src="/opac-tmpl/bootstrap/images/sudoc.png" />' +
45
                            "</a>";
67
                            "</a>";
46
                        if (doc.bib) {
68
                        if (doc.bib) {
47
                            html +=
69
                            html +=
48
                                "<a href=\"/cgi-bin/koha/opac-detail.pl?biblionumber=" + doc.bib + " target=\"_blank\">" +
70
                                '<a href="/cgi-bin/koha/opac-detail.pl?biblionumber=' +
49
                                "<img title=\"" +
71
                                doc.bib +
50
                                __('Publication In Local Catalog') +
72
                                ' target="_blank">' +
51
                                "\" src=\"/opac-tmpl/bootstrap/images/favicon.ico\" />" +
73
                                '<img title="' +
74
                                __("Publication In Local Catalog") +
75
                                '" src="/opac-tmpl/bootstrap/images/favicon.ico" />' +
52
                                "</a>";
76
                                "</a>";
53
                        }
77
                        }
54
                        html += "</td><td>" + doc.citation + "</td></tr>";
78
                        html += "</td><td>" + doc.citation + "</td></tr>";
55
                    });
79
                    });
56
                    html += '</tbody></table>';
80
                    html += "</tbody></table>";
57
                });
81
                });
58
                html += '</div>';
82
                html += "</div>";
59
            }
83
            }
60
            const idrefDiv = $('#idref-publications');
84
            const idrefDiv = $("#idref-publications");
61
            if (idrefDiv.length) {
85
            if (idrefDiv.length) {
62
                idrefDiv.html(html);
86
                idrefDiv.html(html);
63
            } else {
87
            } else {
64
                html = "<div id=\"idref-publications\">" + html + "</div>";
88
                html = '<div id="idref-publications">' + html + "</div>";
65
                const tabMenu =
89
                const tabMenu =
66
                    '<li id="tab_idref_publications" class="nav-item" role="presentation">' +
90
                    '<li id="tab_idref_publications" class="nav-item" role="presentation">' +
67
                    '<a href="#idref-publications" class="nav-link" id="idref-publications-tab" data-toggle="tab" role="tab" aria-selected="false">' +
91
                    '<a href="#idref-publications" class="nav-link" id="idref-publications-tab" data-toggle="tab" role="tab" aria-selected="false">' +
68
                    '<img src="/opac-tmpl/bootstrap/images/idref.svg" style="height: 20px;"/>' +
92
                    '<img src="/opac-tmpl/bootstrap/images/idref.svg" style="height: 20px;"/>' +
69
                    '</a></li>';
93
                    "</a></li>";
70
                const tabs = $('#bibliodescriptions');
94
                const tabs = $("#bibliodescriptions");
71
                const ul = tabs.find("ul");
95
                const ul = tabs.find("ul");
72
                $(ul).append(tabMenu);
96
                $(ul).append(tabMenu);
73
                $('.tab-content').append(html);
97
                $(".tab-content").append(html);
74
                showBsTab("bibliodescriptions", "idref-publications");
98
                showBsTab("bibliodescriptions", "idref-publications");
75
            }
99
            }
76
            $('a[href="#idref-publications"]').click();
100
            $('a[href="#idref-publications"]').click();
77
            $([document.documentElement, document.body]).animate({
101
            $([document.documentElement, document.body]).animate(
78
                scrollTop: $("#idref-publications").offset().top
102
                {
79
            }, 2000);
103
                    scrollTop: $("#idref-publications").offset().top,
104
                },
105
                2000
106
            );
80
        });
107
        });
81
    }
108
    },
82
83
};
109
};
(-)a/opac/svc/idref (-26 / +24 lines)
Lines 25-46 use C4::Context; Link Here
25
use C4::Output qw( output_with_http_headers );
25
use C4::Output qw( output_with_http_headers );
26
use Search::Elasticsearch;
26
use Search::Elasticsearch;
27
27
28
29
my $cgi = CGI->new;
28
my $cgi = CGI->new;
30
29
31
# See http://documentation.abes.fr/aideidrefdeveloppeur/index.html#MicroWebBiblio
30
# See http://documentation.abes.fr/aideidrefdeveloppeur/index.html#MicroWebBiblio
32
my $base = 'http://www.idref.fr/services/biblio/';
31
my $base     = 'http://www.idref.fr/services/biblio/';
33
my $unimarc3 = $cgi->param('ppn');
32
my $unimarc3 = $cgi->param('ppn');
34
33
35
my $publications = { name => '', ppn => $unimarc3, roles => [] };
34
my $publications = { name => '', ppn => $unimarc3, roles => [] };
36
my $send_result = sub {
35
my $send_result  = sub {
37
    my $json = to_json($publications);
36
    my $json = to_json($publications);
38
    utf8::encode($json);
37
    utf8::encode($json);
39
    output_with_http_headers($cgi, undef, $json, 'json');
38
    output_with_http_headers( $cgi, undef, $json, 'json' );
40
    exit;
39
    exit;
41
};
40
};
42
41
43
my $ua = LWP::UserAgent->new;
42
my $ua      = LWP::UserAgent->new;
44
my $request = HTTP::Request->new(
43
my $request = HTTP::Request->new(
45
    'GET',
44
    'GET',
46
    $base . $unimarc3 . ".json",
45
    $base . $unimarc3 . ".json",
Lines 49-105 $request->protocol('HTTP/1.1'); Link Here
49
my $response = $ua->request($request);
48
my $response = $ua->request($request);
50
$send_result->() if not $response->is_success;
49
$send_result->() if not $response->is_success;
51
50
52
my $content = Encode::decode("utf8", $response->content);
51
my $content = Encode::decode( "utf8", $response->content );
53
my $json = from_json($content);
52
my $json    = from_json($content);
54
my $result = $json->{sudoc}->{result};
53
my $result  = $json->{sudoc}->{result};
55
$send_result->() if $result->{countRoles} == 0;
54
$send_result->() if $result->{countRoles} == 0;
56
55
57
$publications->{name} = $result->{name};
56
$publications->{name} = $result->{name};
58
$result->{role} = [ $result->{role} ] if ref($result->{role}) ne 'ARRAY';
57
$result->{role}       = [ $result->{role} ] if ref( $result->{role} ) ne 'ARRAY';
59
my $ppn;
58
my $ppn;
60
for my $r (@{$result->{role}}) {
59
for my $r ( @{ $result->{role} } ) {
61
    my $role = {
60
    my $role = {
62
        code => $r->{unimarcCode},
61
        code  => $r->{unimarcCode},
63
        label => $r->{roleName},
62
        label => $r->{roleName},
64
        docs => [],
63
        docs  => [],
65
    };
64
    };
66
    $r->{doc} = [ $r->{doc} ] if ref $r->{doc} ne 'ARRAY';
65
    $r->{doc} = [ $r->{doc} ] if ref $r->{doc} ne 'ARRAY';
67
    for my $doc ( @{$r->{doc}} ) {
66
    for my $doc ( @{ $r->{doc} } ) {
68
        push @{$role->{docs}}, {
67
        push @{ $role->{docs} }, {
69
            ppn => $doc->{ppn},
68
            ppn      => $doc->{ppn},
70
            citation => $doc->{citation},
69
            citation => $doc->{citation},
71
        };
70
        };
72
        push @$ppn, $doc->{ppn};
71
        push @$ppn, $doc->{ppn};
73
    }
72
    }
74
    push @{$publications->{roles}}, $role;
73
    push @{ $publications->{roles} }, $role;
75
}
74
}
76
75
77
my $ec = C4::Context->config('elasticsearch');
76
my $ec    = C4::Context->config('elasticsearch');
78
my $e = Search::Elasticsearch->new( nodes => $ec->{server} );
77
my $e     = Search::Elasticsearch->new( nodes => $ec->{server} );
79
my $query = {
78
my $query = {
80
    index => $ec->{index_name} . '_biblios',
79
    index => $ec->{index_name} . '_biblios',
81
    body => {
80
    body  => {
82
        _source => ["ppn"],
81
        _source => ["ppn"],
83
        size => '10000',
82
        size    => '10000',
84
        query => { terms => { ppn => $ppn } }
83
        query   => { terms => { ppn => $ppn } }
85
    }
84
    }
86
};
85
};
87
my $res = $e->search($query);
86
my $res  = $e->search($query);
88
my $hits = $res->{hits}->{hits};
87
my $hits = $res->{hits}->{hits};
89
my $ppn_to_bib;
88
my $ppn_to_bib;
90
for my $hit (@$hits) {
89
for my $hit (@$hits) {
91
    my $ppn = $hit->{_source}->{ppn}->[0];
90
    my $ppn = $hit->{_source}->{ppn}->[0];
92
    $ppn_to_bib->{$ppn} = $hit->{_id};
91
    $ppn_to_bib->{$ppn} = $hit->{_id};
93
}
92
}
94
for my $role (@{$publications->{roles}}) {
93
for my $role ( @{ $publications->{roles} } ) {
95
    my @docs = @{$role->{docs}};
94
    my @docs = @{ $role->{docs} };
96
    for my $d (@docs) {
95
    for my $d (@docs) {
97
        my $bib = $ppn_to_bib->{ $d->{ppn} };
96
        my $bib = $ppn_to_bib->{ $d->{ppn} };
98
        $d->{bib} = $bib if $bib;
97
        $d->{bib} = $bib if $bib;
99
    }
98
    }
100
    my $key = sub {
99
    my $key = sub {
101
        my $doc = shift;
100
        my $doc = shift;
102
        ($doc->{bib} ? 'a' : 'b') . $doc->{citation};
101
        ( $doc->{bib} ? 'a' : 'b' ) . $doc->{citation};
103
    };
102
    };
104
    @docs = sort { $key->($a) cmp $key->($b) } @docs;
103
    @docs = sort { $key->($a) cmp $key->($b) } @docs;
105
    $role->{docs} = \@docs;
104
    $role->{docs} = \@docs;
106
- 

Return to bug 32333