From ec9478d5be59175fb941c2a73ee8b80ca209f1e8 Mon Sep 17 00:00:00 2001 From: Axel Amghar Date: Tue, 30 Apr 2019 14:55:11 +0200 Subject: [PATCH] Bug 18829: Elasticsearch - Put a better display for the view of ES indexed record To test: - apply the patch - go to global sysPref - make sure that SearchEngine have "ElsaticSearch" as value - Search whatever you want in Search the catalog and select a notice - Search the link (Ctrl f) : "Elasticsearch Record :" , click on the link - make sure that the pop-up open and you should see the elasticsearch result in JSON (the pop-up look the same as MARC preview) --- catalogue/detail.pl | 14 ----- catalogue/showelastic.pl | 64 ++++++++++++++++++++++ .../prog/en/modules/catalogue/detail.tt | 64 ++++++++++++---------- .../prog/en/modules/catalogue/showelastic.tt | 35 ++++++++++++ 4 files changed, 133 insertions(+), 44 deletions(-) create mode 100755 catalogue/showelastic.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/showelastic.tt diff --git a/catalogue/detail.pl b/catalogue/detail.pl index b446d6c..027ca52 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -46,8 +46,6 @@ use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; use Koha::Virtualshelves; -use LWP::Simple; -use Koha::SearchEngine::Elasticsearch; use Koha::Plugins; my $query = CGI->new(); @@ -545,16 +543,4 @@ $template->param (countdeletedorders => $count_deletedorders_using_biblio); $template->param (basketsorders => \@baskets_orders); $template->param (basketsdeletedorders => \@baskets_deletedorders); -if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) { - my $es_conf = Koha::SearchEngine::Elasticsearch->new({index=>'biblios'})->get_elasticsearch_params(); - my $es_url; - my $es_record; - foreach my $es_node ( @{$es_conf->{nodes}} ){ - $es_url = "http://".$es_node."/".$es_conf->{index_name}."/data/$biblionumber"; - $es_record = get($es_url); - last if defined $es_record; #can quit once we find the record (should be same in any node) - } - $template->param( esrecord => $es_record ); -} - output_html_with_http_headers $query, $cookie, $template->output; diff --git a/catalogue/showelastic.pl b/catalogue/showelastic.pl new file mode 100755 index 0000000..17e6fc9 --- /dev/null +++ b/catalogue/showelastic.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +# Koha library project www.koha-community.org + +# Copyright 2007 Liblime +# Parts copyright 2010 BibLibre +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +# standard or CPAN modules used +use CGI qw(:standard -utf8); +use DBI; +use Encode; + +# Koha modules used +use C4::Context; +use C4::Output; +use C4::Auth; +use C4::Biblio; +use C4::ImportBatch; +use C4::XSLT ; +use Koha::SearchEngine::Elasticsearch; +use LWP::Simple qw/get/; + +my $input= new CGI; +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "catalogue/showelastic.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { catalogue => 1 }, + debug => 1, + } +); + +my $biblionumber = $input->param('id'); + +my $es_conf = Koha::SearchEngine::Elasticsearch->new({index=>'biblios'})->get_elasticsearch_params(); +my $es_url; +my $es_record; + +foreach my $es_node ( @{$es_conf->{nodes}} ){ + $es_url = "http://".$es_node."/".$es_conf->{index_name}."/data/$biblionumber"; + $es_record = get($es_url); +} + +$template->param( esrecord => $es_record); +output_html_with_http_headers $input, $cookie, $template->output; 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 3f13207..b24d843 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -97,7 +97,12 @@ [% END %] [% END %] - MARC Preview: Show + + MARC Preview: Show + + [% IF ( Koha.Preference('SearchEngine') == 'Elasticsearch' ) %] + Elasticsearch Record : Show + [% END %] [% IF ( holdcount ) %] @@ -169,7 +174,6 @@ [% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && Koha.Preference('NovelistSelectStaffView') == 'tab' ) %] [% END %] -[% IF ( Koha.Preference('SearchEngine') == 'Elasticsearch' ) %]
  • Elasticsearch Record
  • [% END %] [% items_table_block_iter = 0 %] @@ -699,18 +703,6 @@ [% END %] -[% IF ( Koha.Preference('SearchEngine') == 'Elasticsearch' ) %] -
    -
    - [% IF esrecord %] -

    [% esrecord %]

    - - [% ELSE %] -

    "This record was not found in the ES index"

    - [% END %] -
    -[% END %] -
    @@ -749,6 +741,23 @@
    + + @@ -932,10 +941,18 @@ var page = $(this).attr("href"); $("#marcPreview .modal-body").load(page + " table"); $('#marcPreview').modal({show:true}); + }); - $("#marcPreview").on("hidden.bs.modal", function(){ - $("#marcPreview .modal-body").html("
    \"\" "+_("Loading")+"
    "); + + [% IF ( Koha.Preference('SearchEngine') == 'Elasticsearch' ) %] + $("body").on("click",".previewElastic", function(event){ + event.preventDefault(); + let pageElastic = $(this).attr("href"); + $("#elasticPreview .modal-body").load(pageElastic); + $('#elasticPreview').modal({show:true}); }); + [% END %] + [% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && ( normalized_isbn || normalized_upc ) ) %] novSelect.loadContentForQuery({ ClientIdentifier : '[% IF normalized_isbn %][% normalized_isbn | html %][% ELSE %][% normalized_upc | html %][% END %]', @@ -957,20 +974,6 @@ verify_images(); });[% END %] - [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' && 1==0 %] - function ESRecord (biblionumber) { - $.getJSON("http://localhost:9200/koha_kohadev_biblios/data/", biblionumber, function( data ){ - $.each( data, function( key, val ) { - console.log("key "+key+"val "+val); - }); - }); - } - $(document).ready( function(){ - var esid = [% biblionumber %]; - ESRecord( esid ); - }); - [% END %] - [% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && ( normalized_isbn || normalized_upc ) ) %] @@ -1017,5 +1020,6 @@ [% END %] }); + [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/showelastic.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/showelastic.tt new file mode 100644 index 0000000..5abdd1f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/showelastic.tt @@ -0,0 +1,35 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Cataloging › MARC import + + + +
    +
    +    
    + + + -- 2.7.4