From 372aa0fb8a7710c5ec5ae92a67dbd1bf5611ff22 Mon Sep 17 00:00:00 2001 From: Axel Amghar Date: Mon, 29 Apr 2019 11:27:49 +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 "ElasticSearch" as value - Search whatever you want in Search the catalog and select a record - 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) - note fields are alphabetized - from the command line delete the es record: curl -XDELETE es:9200/koha_kohadev_biblios/data/5 - click the preview link, it syas record not found - check the logs - you see the error on missing record Signed-off-by: Fridolin Somers Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- catalogue/showelastic.pl | 76 +++++++++++++++++++ .../prog/en/modules/catalogue/detail.tt | 34 ++++++++- .../prog/en/modules/catalogue/showelastic.tt | 35 +++++++++ 3 files changed, 143 insertions(+), 2 deletions(-) create mode 100755 catalogue/showelastic.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/showelastic.tt diff --git a/catalogue/showelastic.pl b/catalogue/showelastic.pl new file mode 100755 index 0000000000..1b9318cc3a --- /dev/null +++ b/catalogue/showelastic.pl @@ -0,0 +1,76 @@ +#!/usr/bin/perl + +# Koha library project www.koha-community.org + +# Copyright 2020 Koha Development Team +# +# 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, see . + + +use Modern::Perl; + +# standard or CPAN modules used +use CGI qw(:standard -utf8); +use DBI; +use Encode; +use JSON; +use Try::Tiny; + +# 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", + flagsrequired => { catalogue => 1 }, + debug => 1, + } +); + +my $biblionumber = $input->param('id'); + +my $es = Koha::SearchEngine::Elasticsearch->new({index=>'biblios'}); + +my $es_record; +my @es_fields; + +try { + $es_record = $es->get_elasticsearch()->get({ + index => $es->index_name, + type => 'data', + id => $biblionumber, + }); +} +catch{ + @es_fields = ("Error fetching record: see logs for details"); + warn $_; +}; + +for my $field (sort keys %{$es_record} ){ + push @es_fields, { $field, $es_record->{$field} }; +}; +$template->param( esrecord => to_json( \@es_fields ) ); +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 44b0a39349..d971366778 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -148,6 +148,10 @@ [% END %] + [% IF ( Koha.Preference('SearchEngine') == 'Elasticsearch' ) %] + Elasticsearch Record : Show + [% END %] + [% IF ( holdcount ) %] Holds: @@ -1118,6 +1122,23 @@ Note that permanent location is a code, and location may be an authval. + + @@ -1710,10 +1731,18 @@ Note that permanent location is a code, and location may be an authval. 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(e){ + e.preventDefault(); + var 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 %]', @@ -2421,5 +2450,6 @@ Note that permanent location is a code, and location may be an authval. }); [% 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 0000000000..cf818aded9 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/showelastic.tt @@ -0,0 +1,35 @@ +[% INCLUDE 'doc-head-open.inc' %] +[% USE raw %] +Koha › Cataloging › MARC import + + + +
+
+    
+ + + -- 2.39.5