Bug 18421: Add Coce to the staff intranet
authorCharles Farmer <charles.farmer@inLibro.com>
Fri, 30 Mar 2018 15:58:55 +0000 (11:58 -0400)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 7 Oct 2019 13:09:12 +0000 (14:09 +0100)
TEST PLAN:
    1) Apply the patch with git-bz
    2) Run updatedatabase.pl
        2.1) Console output should confirm database modification
    3) Visit the 'Enhanced Content' tab of admin/syspref
        3.1) ressource is /cgi-bin/koha/admin/preferences.pl?tab=enhanced_content
        3.2) You should see that the previous preference, Coce, is now CoceOPAC,
             and that a new preference was added, CoceIntranet
    4) Activate CoceIntranet
    5) Do a search for a book for which you have a Coce cover
        5.1) The cover image url should now point to a provider you defined in Coce
        5.2) Your Coce log should show a query
    6) Click on the book's name to visit the detail.pl page
        6.1) The book's cover should also be provided by Coce on that page

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
installer/data/mysql/atomicupdate/bug_18421_add_coce_intranet.perl [new file with mode: 0755]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
koha-tmpl/intranet-tmpl/prog/js/coce.js [new file with mode: 0644]
koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc
koha-tmpl/opac-tmpl/bootstrap/en/includes/shelfbrowser.inc
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt

diff --git a/installer/data/mysql/atomicupdate/bug_18421_add_coce_intranet.perl b/installer/data/mysql/atomicupdate/bug_18421_add_coce_intranet.perl
new file mode 100755 (executable)
index 0000000..af27757
--- /dev/null
@@ -0,0 +1,24 @@
+#! /usr/bin/perl
+
+use Modern::Perl;
+use C4::Context;
+
+my $dbh=C4::Context->dbh;
+
+################
+# IntranetCoce #
+################
+
+# validate systempreferences.Coce and save the config for OpacCoce
+my $current_coce_pref = C4::Context->preference('Coce') || 0;
+
+# add two new systempreferences in order to have distinct behavior between intranet and OPAC
+$dbh->do("INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES
+        ('IntranetCoce','0', NULL, 'If on, enables cover retrieval from the configured Coce server in the staff intranet', 'YesNo'),
+        ('OpacCoce','$current_coce_pref', NULL, 'If on, enables cover retrieval from the configured Coce server in the OPAC', 'YesNo')
+        ;") or die "Error applying Bug 18421: error inserting new values into database: ". $dbh->errstr . "\n";
+
+$dbh->do("DELETE IGNORE FROM systempreferences WHERE variable = 'Coce';")
+    or die "Error applying Bug 18421: error deleting the old syspref 'Coce': ". $dbh->errstr . "\n";
+
+print "Upgrade to XX.XX done (Bug 18421: Add Coce image cache to the Intranet)\n";
index bb3c809..cb172ff 100644 (file)
@@ -121,7 +121,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('CircControl','ItemHomeLibrary','PickupLibrary|PatronLibrary|ItemHomeLibrary','Specify the agency that controls the circulation and fines policy','Choice'),
 ('CircSidebar','0',NULL,'Activate or deactivate the navigation sidebar on all Circulation pages','YesNo'),
 ('ClaimsBccCopy','0','','Bcc the ClaimAcquisition and ClaimIssues alerts','YesNo'),
-('Coce','0', NULL, 'If on, enables cover retrieval from the configured Coce server', 'YesNo'),
 ('CoceHost', '', NULL, 'Coce server URL', 'Free'),
 ('CoceProviders', '', 'aws,gb,ol', 'Coce providers', 'multiple'),
 ('COinSinOPACResults','1','','If ON, use COinS in OPAC search results page.  NOTE: this can slow down search response time significantly','YesNo'),
@@ -248,6 +247,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('IntranetBiblioDefaultView','normal','normal|marc|isbd|labeled_marc','Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd','Choice'),
 ('intranetbookbag','1','','If ON, enables display of Cart feature in the intranet','YesNo'),
 ('IntranetCirculationHomeHTML', '', NULL, 'Show the following HTML in a div on the bottom of the reports home page', 'Free'),
+('IntranetCoce','0', NULL, 'If on, enables cover retrieval from the configured Coce server in the staff intranet', 'YesNo'),
 ('intranetcolorstylesheet','','50','Define the color stylesheet to use in the Staff Client','free'),
 ('IntranetFavicon','','','Enter a complete URL to an image to replace the default Koha favicon on the Staff client','free'),
 ('IntranetmainUserblock','','70|10','Add a block of HTML that will display on the intranet home page','Textarea'),
@@ -361,6 +361,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('OpacBrowseResults','1',NULL,'Disable/enable browsing and paging search results from the OPAC detail page.','YesNo'),
 ('OpacCloud','0',NULL,'If ON, enables subject cloud on OPAC','YesNo'),
 ('OpacAdditionalStylesheet','','','Define an auxiliary stylesheet for OPAC use, to override specified settings from the primary opac.css stylesheet. Enter the filename (if the file is in the server\'s css directory) or a complete URL beginning with http (if the file lives on a remote server).','free'),
+('OpacCoce','0', NULL, 'If on, enables cover retrieval from the configured Coce server in the OPAC', 'YesNo'),
 ('OpacCustomSearch','','70|10','Replace the search box on the OPAC with the provided HTML','Textarea'),
 ('opaccredits','','70|10','Define HTML Credits at the bottom of the OPAC page','Textarea'),
 ('OPACdefaultSortField','relevance','relevance|popularity|call_number|pubdate|acqdate|title|author','Specify the default field used for sorting','Choice'),
index f6e01e2..9f90d15 100644 (file)
@@ -412,11 +412,17 @@ Enhanced Content:
             - pref: RecordedBooksDomain
     Coce Cover images cache:
         -
-            - pref: Coce
+            - pref: OpacCoce
               choices:
                   yes: Enable
                   no: "Don't enable"
-            - a Coce image cache service.
+            - a Coce image cache service in the OPAC.
+        -
+            - pref: IntranetCoce
+              choices:
+                  yes: Enable
+                  no: "Don't enable"
+            - a Coce image cache service in the staff intranet.
         -
             - Coce server URL
             - pref: CoceHost
index 05f6ba3..c1dabf2 100644 (file)
   <div class="dialog message">The record you requested does not exist ([% biblionumber | html %]).</div>
 [% ELSE %]
 
+[%
+    IntranetCoce    = Koha.Preference('IntranetCoce')
+    CoceProviders   = Koha.Preference('CoceProviders')
+    CoceHost        = Koha.Preference('CoceHost')
+%]
+
 [% INCLUDE 'cat-toolbar.inc' %]
     [% IF ( ocoins ) %]
         <!-- COinS / OpenURL -->
         <span class="Z3988" title="[% ocoins | html %]"></span>
     [% END %]
 
-    [% IF ( AmazonCoverImages  || LocalCoverImages || AdlibrisEnabled ) %]
+    [% IF ( AmazonCoverImages  || LocalCoverImages || AdlibrisEnabled || IntranetCoce ) %]
         <div id="catalogue_detail_biblio" class="col-xs-9">
     [% ELSE %]
         <div id="catalogue_detail_biblio" class="col-xs-12">
             </span>
         [% END %]
 
-        [% IF ( AmazonCoverImages  || LocalCoverImages || AdlibrisEnabled ) %]
+        [% IF ( AmazonCoverImages  || LocalCoverImages || AdlibrisEnabled || IntranetCoce ) %]
         </div><div class="col-xs-3" id="bookcoverimg">
         [% IF ( LocalCoverImages ) %]
             <div title="[% biblionumber |url %]" class="[% biblionumber | html %]" id="local-thumbnail-preview"></div>
                 <img src="https://images-na.ssl-images-amazon.com/images/P/[% normalized_isbn | html %].01.MZZZZZZZ.jpg" alt="" />
         </a></div>
         [% END %]
+        [% IF ( IntranetCoce && CoceProviders ) %]
+          [% coce_id = normalized_ean || normalized_isbn %]
+            <a class="p1" href="/cgi-bin/koha/catalogue/[% DetailPage %]?biblionumber=[% biblionumber |url %]">
+          [% IF ( coce_id ) %]
+            <span style="block" title="[% biblionumber |url %]" class="[% coce_id %]" id="coce-thumbnail-preview"></span>
+          [% ELSE %]
+            <span class="no-image">No cover image available</span>
+          [% END %]
+            </a>
+        [% END %]
         [% END %]
 
 </div>
     [% INCLUDE 'catalog-strings.inc' %]
     [% Asset.js("js/catalog.js") | $raw %]
     [% INCLUDE 'greybox.inc' %]
+    <script type="text/javascript" src="[% interface %]/prog/js/coce_[% KOHA_VERSION %].js"></script>
     <script>
         var interface = "[% interface | html %]";
         var theme = "[% theme | html %]";
             [% IF LocalCoverImages %]
                 KOHA.LocalCover.GetCoverFromBibnumber(true);
             [% END %]
+            [% IF ( IntranetCoce && CoceProviders ) %]
+                KOHA.coce.getURL('[% CoceHost %]', '[% CoceProviders %]');
+            [% END %]
+
             $("body").on("click",".previewMARC", function(e){
                 e.preventDefault();
                 var page = $(this).attr("href");
index 3d9bbe9..46258cd 100644 (file)
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
 
+[%
+    IntranetCoce    = Koha.Preference('IntranetCoce')
+    CoceProviders   = Koha.Preference('CoceProviders')
+    CoceHost        = Koha.Preference('CoceHost')
+%]
+
 <div id="breadcrumbs">
     <a href="/cgi-bin/koha/mainpage.pl">Home</a>
     &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>
                                     [% SET MaxSearchResultsItemsPerRecordStatusCheck = Koha.Preference('MaxSearchResultsItemsPerRecordStatusCheck') %]
                                     [% FOREACH SEARCH_RESULT IN SEARCH_RESULTS %]
                                         <tr>
-                                            [% IF ( AmazonCoverImages || LocalCoverImages || AdlibrisEnabled ) %]
+                                            [% IF ( AmazonCoverImages || LocalCoverImages || AdlibrisEnabled || IntranetCoce ) %]
                                                 <td>
                                                     [% IF ( LocalCoverImages) %]
                                                         <a class="p1" href="/cgi-bin/koha/catalogue/[% DetailPage | html %]?biblionumber=[% SEARCH_RESULT.biblionumber |url %]">
                                                         [% END %]
                                                         </a>
                                                     [% END # /IF AmazonCoverImages %]
+                                                    [% IF ( IntranetCoce && CoceProviders ) %]
+                                                        [% coce_id = SEARCH_RESULT.normalized_ean || SEARCH_RESULT.normalized_isbn %]
+                                                            <a class="p1" href="/cgi-bin/koha/catalogue/[% DetailPage %]?biblionumber=[% SEARCH_RESULT.biblionumber |url %]">
+                                                        [% IF ( coce_id ) %]
+                                                            <span style="block" title="[% SEARCH_RESULT.biblionumber |url %]" class="[% coce_id %]" id="coce-thumbnail[% loop.count %]"></span>
+                                                        [% ELSE %]
+                                                            <span class="no-image">No cover image available</span>
+                                                        [% END %]
+                                                        </a>
+                                                    [% END %]
                                                 </td>
-                                            [% END # /IF( AmazonCoverImages || LocalCoverImages || AdlibrisEnabled )%]
+                                            [% END # /IF( AmazonCoverImages || LocalCoverImages || AdlibrisEnabled || IntranetCoce )%]
 
                                             <td>
                                                 <input type="checkbox" class="selection" id="bib[% SEARCH_RESULT.biblionumber | html %]" name="biblionumber" value="[% SEARCH_RESULT.biblionumber | html %]" style="display:none" />
     [% Asset.js("js/browser.js") | $raw %]
     [% Asset.js("lib/hc-sticky.js") | $raw %]
     [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
+    [% Asset.js("prog/js/coce.js") %]
     <script>
         var MSG_NO_ITEM_SELECTED = _("Nothing is selected.");
         var MSG_NON_RESERVES_SELECTED = _("One or more selected items cannot be placed on hold.");
                 KOHA.LocalCover.LoadResultsCovers();
             [% END %]
 
+            [% IF ( IntranetCoce && CoceProviders ) %]
+                KOHA.coce.getURL('[% CoceHost %]', '[% CoceProviders %]');
+            [% END %]
+
             $("#select_all").on("click",function(e){
                 e.preventDefault();
                 selectAll();
diff --git a/koha-tmpl/intranet-tmpl/prog/js/coce.js b/koha-tmpl/intranet-tmpl/prog/js/coce.js
new file mode 100644 (file)
index 0000000..95669a0
--- /dev/null
@@ -0,0 +1,43 @@
+if (KOHA === undefined || !KOHA) { var KOHA = {}; }
+
+
+/**
+ * A namespace for Coce cover images cache
+ */
+KOHA.coce = {
+
+  /**
+   * Search all:
+   *    <div title="biblionumber" id="isbn" class="coce-thumbnail"></div>
+   * or
+   *    <div title="biblionumber" id="isbn" class="coce-thumbnail-preview"></div>
+   * and run a search with all collected isbns to coce cover service.
+   * The result is asynchronously returned, and used to append <img>.
+   */
+  getURL: function(host,provider,newWindow) {
+    var ids = [];
+    $("[id^=coce-thumbnail]").each(function(i) {
+        var id = $(this).attr("class"); // id=isbn
+        if ( id !== '' ) { ids.push(id); }
+    });
+    if (ids.length == 0) return;
+    ids = ids.join(',');
+    var coceURL = host + '/cover?id=' + ids + '&provider=' + provider;
+    $.ajax({
+      url: coceURL,
+      dataType: 'jsonp',
+      success: function(urlPerID){
+        for (var id in urlPerID) {
+          var url = urlPerID[id];
+          $("[id^=coce-thumbnail]."+id).each(function() {
+            var img = document.createElement("img");
+            img.src = url;
+            img.title = url; //FIXME: to delete
+            $(this).html(img);
+         });
+        }
+      }
+    });
+  }
+
+};
index 8b8d9dd..f5f07ef 100644 (file)
@@ -231,7 +231,7 @@ $.widget.bridge('uitooltip', $.ui.tooltip);
         //]]>
     </script>
 [% END %]
-[% IF ( Koha.Preference('Coce') && Koha.Preference('CoceProviders') ) %]
+[% IF ( Koha.Preference('OpacCoce') && Koha.Preference('CoceProviders') ) %]
     [% Asset.js("js/coce.js") | $raw %]
     <script>
         //<![CDATA[
index 1396060..295d4a5 100644 (file)
@@ -49,7 +49,7 @@
                                         <span class="no-image">No cover image available</span>
                                     [% END %]
                                 [% END %]
-                                [% IF ( Koha.Preference('Coce') && Koha.Preference('CoceProviders') ) %]
+                                [% IF ( Koha.Preference('OpacCoce') && Koha.Preference('CoceProviders') ) %]
                                   [% coce_id = item.browser_normalized_ean || item.browser_normalized_isbn | html %]
                                   <div title="[% item.biblionumber |url %]" class="[% coce_id | html %]" id="coce-thumbnail-preview-[% coce_id | html %]"></div>
                                 [% END %]
index cd4c5da..ca0f5f3 100644 (file)
@@ -78,8 +78,8 @@
                     [% IF ( GoogleJackets ) %]
                         <div title="[% biblio.biblionumber | html %]" class="[% normalized_isbn | html %]" id="gbs-thumbnail-preview"></div>
                     [% END %]
-                    [% IF ( Koha.Preference('Coce') && Koha.Preference('CoceProviders') ) %]
-                      [% coce_id = normalized_ean || normalized_isbn %]
+                    [% IF ( Koha.Preference('OpacCoce') && Koha.Preference('CoceProviders') ) %]
+                      [% coce_id = normalized_ean || normalized_isbn | html %]
                       <div title="[% biblio.biblionumber | html %]" class="[% coce_id | html %]" id="coce-thumbnail-preview"></div>
                     [% END %]
                     [% IF OpenLibraryCovers %]
     [% IF ( GoogleJackets ) %]
         KOHA.Google.GetCoverFromIsbn([% covernewwindow | html %]);
     [% END %]
-    [% IF ( Koha.Preference('Coce') && Koha.Preference('CoceProviders') ) %]
+    [% IF ( Koha.Preference('OpacCoce') && Koha.Preference('CoceProviders') ) %]
         KOHA.coce.getURL('[% Koha.Preference('CoceHost') | html %]', '[% Koha.Preference('CoceProviders') | html %]',[% covernewwindow | html %]);
     [% END %]
 
                     [% IF ( GoogleJackets ) %]
                       KOHA.Google.GetCoverFromIsbn([% covernewwindow | html %]);
                     [% END %]
-                    [% IF ( Koha.Preference('Coce') && Koha.Preference('CoceProviders') ) %]
+                    [% IF ( Koha.Preference('OpacCoce') && Koha.Preference('CoceProviders') ) %]
                       KOHA.coce.getURL('[% Koha.Preference('CoceHost') | html %]', '[% Koha.Preference('CoceProviders') | html %]',[% covernewwindow | html %]);
                     [% END %]
                     [% IF OpenLibraryCovers %]
                     [% IF ( GoogleJackets ) %]
                       KOHA.Google.GetCoverFromIsbn([% covernewwindow | html %]);
                     [% END %]
-                    [% IF ( Koha.Preference('Coce') && Koha.Preference('CoceProviders') ) %]
+                    [% IF ( Koha.Preference('OpacCoce') && Koha.Preference('CoceProviders') ) %]
                       KOHA.coce.getURL('[% Koha.Preference('CoceHost') | html %]', '[% Koha.Preference('CoceProviders') | html %]',[% covernewwindow | html %]);
                     [% END %]
                     [% IF OpenLibraryCovers %]
index 5347a99..fc9df83 100644 (file)
                                                             [% END %]
                                                         [% END %]
 
-                                                        [% IF ( Koha.Preference('Coce') && Koha.Preference('CoceProviders') ) %]
-                                                          [% coce_id = SEARCH_RESULT.normalized_ean || SEARCH_RESULT.normalized_isbn %]
+                                                        [% IF ( Koha.Preference('OpacCoce') && Koha.Preference('CoceProviders') ) %]
+                                                          [% coce_id = SEARCH_RESULT.normalized_ean || SEARCH_RESULT.normalized_isbn | html %]
                                                           [% IF ( coce_id ) %]
                                                             <span title="[% SEARCH_RESULT.biblionumber |url %]" class="[% coce_id | html %]" id="coce-thumbnail[% loop.count | html %]"></span>
                                                           [% ELSE %]
@@ -1028,7 +1028,7 @@ $(document).ready(function(){
 [% IF OpenLibraryCovers %]KOHA.OpenLibrary.GetCoverFromIsbn();[% END %]
 [% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]
 [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
-[% IF ( Koha.Preference('Coce') && Koha.Preference('CoceProviders') ) %]
+[% IF ( Koha.Preference('OpacCoce') && Koha.Preference('CoceProviders') ) %]
     KOHA.coce.getURL('[% Koha.Preference('CoceHost') | html %]', '[% Koha.Preference('CoceProviders') | html %]');
 [% END %]