Z39.50 webstaff WIP: more functionality and fixes
authorGalen Charlton <gmc@esilibrary.com>
Thu, 16 Jul 2015 18:17:04 +0000 (18:17 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 16 Jul 2015 22:16:23 +0000 (22:16 +0000)
* check for empty query correctly
* retain reference to target list
* preserve search query input when toggling Z39.50 target selection
* implement clear form handler
* allow enter key to submit search
* track index of Z39.50 results so that individual ones can be selected
* note results of experiences to make the title be conditionally a hyperlink
* implement show in catalog
* implement direct import

Open-ILS/src/templates/staff/cat/z3950/t_list.tt2
Open-ILS/web/js/ui/default/staff/cat/services/z3950.js
Open-ILS/web/js/ui/default/staff/cat/z3950/app.js

index 0158c45..dcd5840 100644 (file)
@@ -1,7 +1,9 @@
 <div class="row">
     <div class="col-xs-6">
         <strong>[% l('Query') %]</strong>
+        <form ng-keyup="$event.keyCode == 13 && search()">
         <eg-z3950-search-field-list></eg-z3950-search-field-list>
+        </form>
     </div>
     <div class="col-xs-6">
         <strong>[% l('Service and Credentials') %]</strong>
   grid-controls="gridControls"
   persist-key="cat.z3950_results">
 
+  <eg-grid-menu-item handler="showInCatalog" disabled="cant_showInCatalog"
+    label="[% l('Show in Catalog') %]"></eg-grid-menu>
+  <eg-grid-menu-item handler="import" disabled="cant_import"
+    label="[% l('Import') %]"></eg-grid-menu>
+
+    <!-- 
+      FIXME: it would be nice to make this column link
+      to record display page when the service is
+      'native-evergreen-catalog', but can't do ng-if
+      inside of column value templates at the moment
+    -->
     <eg-grid-field label="[% l('Title') %]" path="title" visible></eg-grid-field>
     <eg-grid-field label="[% l('Author') %]" path="author" visible></eg-grid-field>
     <eg-grid-field label="[% l('Edition') %]" path="edition" visible></eg-grid-field>
index 9cd97af..4ef7e70 100644 (file)
@@ -14,7 +14,8 @@ function($q,   egCore,   egAuth) {
             'open-ils.search.z3950.retrieve_services',
             egAuth.token()
         ).then(function(res) {
-            service.targets = [];
+            // keep the reference, just clear the list
+            service.targets.length = 0;
             // native Evergreen search goes first
             var localTarget = res['native-evergreen-catalog'];
             delete res['native-evergreen-catalog'];
@@ -46,7 +47,9 @@ function($q,   egCore,   egAuth) {
         // don't want to throw away the reference, otherwise
         // directives bound to searchFields won't
         // refresh
+        var curFormInput = {};
         for (var field in service.searchFields) {
+            curFormInput[field] = service.searchFields[field].query;
             delete service.searchFields[field];
         }
         angular.forEach(service.targets, function(target, idx) {
@@ -54,13 +57,19 @@ function($q,   egCore,   egAuth) {
                 angular.forEach(target.settings.attrs, function(attr, key) {
                     if (!(key in service.searchFields)) service.searchFields[key] = {
                         label : attr.label,
-                        query : ''
+                        query : (key in curFormInput) ? curFormInput[key] : ''
                     };
                 });
             }
         });
     };
 
+    service.clearSearchFields = function() {
+        for (var field in service.searchFields) {
+            service.searchFields[field].query = '';
+        }
+    }
+
     // return the selected Z39.50 targets and search strings
     // in a format suitable for passing directly to
     // open-ils.search.z3950.search_class
index 1e63d4e..8a6d7d6 100644 (file)
@@ -26,8 +26,8 @@ angular.module('egCatZ3950Search',
  * List view - grid stuff
  */
 .controller('Z3950SearchCtrl',
-       ['$scope','$q','$location','$timeout','egCore','egGridDataProvider','egZ3950TargetSvc',
-function($scope , $q , $location , $timeout , egCore , egGridDataProvider,  egZ3950TargetSvc ) {
+       ['$scope','$q','$location','$timeout','$window','egCore','egGridDataProvider','egZ3950TargetSvc',
+function($scope , $q , $location , $timeout , $window,  egCore , egGridDataProvider,  egZ3950TargetSvc ) {
 
     // get list of targets
     egZ3950TargetSvc.loadTargets();
@@ -39,14 +39,14 @@ function($scope , $q , $location , $timeout , egCore , egGridDataProvider,  egZ3
         var deferred = $q.defer();
 
         var query = egZ3950TargetSvc.currentQuery();
-        console.debug(query);
-        if (query.search.length == 0) {
+        if (Object.keys(query.search).length == 0) {
             return $q.when();
         }
 
         query['limit'] = count;
         query['offset'] = offset;
 
+        var resultIndex = offset;
         egCore.net.request(
             'open-ils.search',
             'open-ils.search.z3950.search_class',
@@ -58,6 +58,8 @@ function($scope , $q , $location , $timeout , egCore , egGridDataProvider,  egZ3
             function(result) {
                 for (var i in result.records) {
                     result.records[i].mvr['service'] = result.service;
+                    result.records[i].mvr['index'] = resultIndex++;
+                    result.records[i].mvr['marcxml'] = result.records[i].marcxml;
                     deferred.notify(result.records[i].mvr);
                 }
             }
@@ -67,8 +69,51 @@ function($scope , $q , $location , $timeout , egCore , egGridDataProvider,  egZ3
     };
 
     $scope.z3950SearchGridProvider = provider;
+    $scope.gridControls = {};
 
     $scope.search = function() {
         $scope.z3950SearchGridProvider.refresh();
     };
+    $scope.clearForm = function() {
+        egZ3950TargetSvc.clearSearchFields();
+    };
+
+    $scope.showInCatalog = function() {
+        var items = $scope.gridControls.selectedItems();
+        // relying on cant_showInCatalog to protect us
+        var url = egCore.env.basePath +
+                  'cat/catalog/record/' + items[0].tcn();
+        $timeout(function() { $window.open(url, '_blank') });        
+    };
+    $scope.cant_showInCatalog = function() {
+        var items = $scope.gridControls.selectedItems();
+        if (items.length != 1) return true;
+        if (items[0]['service'] == 'native-evergreen-catalog') return false;
+        return true;
+    };
+
+    $scope.import = function() {
+        var deferred = $q.defer();
+        var items = $scope.gridControls.selectedItems();
+        egCore.net.request(
+            'open-ils.cat',
+            'open-ils.cat.biblio.record.xml.import',
+            egCore.auth.token(),
+            items[0]['marcxml']
+            // FIXME and more
+        ).then(
+            function() { deferred.resolve() },
+            null, // onerror
+            function(result) {
+                console.debug('imported');
+            }
+        );
+
+        return deferred.promise;
+    };
+    $scope.cant_import = function() {
+        var items = $scope.gridControls.selectedItems();
+        if (items.length == 1) return false;
+        return true;
+    };
 }])