webstaff: more changes to holdingsSvc
authorGalen Charlton <gmc@esilibrary.com>
Fri, 2 Oct 2015 20:50:03 +0000 (20:50 +0000)
committerKathy Lussier <klussier@masslnc.org>
Tue, 2 Feb 2016 19:58:48 +0000 (14:58 -0500)
- convert holdingsSvc from a singleton to a provider
  of holdings service instance objects
- adjust the catalog app accordingly
- add a new egVolumeList directive that displays
  a list of volumes attached to a bib record, including
  owning library, call number, and copies

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/templates/staff/cat/share/t_volume_list.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
Open-ILS/web/js/ui/default/staff/cat/services/holdings.js

diff --git a/Open-ILS/src/templates/staff/cat/share/t_volume_list.tt2 b/Open-ILS/src/templates/staff/cat/share/t_volume_list.tt2
new file mode 100644 (file)
index 0000000..db77586
--- /dev/null
@@ -0,0 +1,12 @@
+<eg-grid
+    id-field="index"
+    features="-menu,-index,-picker,-pagination,-action,-display,-sort,-multisort,-multiselect"
+    items-provider="holdingsGridDataProvider"
+    grid-controls="holdingsGridControls"
+    persist-key="cat.record_overlay.holdings">
+
+    <eg-grid-field label="[% l('Owning Library') %]" path="owner_label" flex="4" align="right" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Call Number') %]"    path="call_number.label" visible></eg-grid-field>
+    <eg-grid-field label="[% l('# Copies') %]"       path="copy_count" visible></eg-grid-field>
+
+</eg-grid>
index ae1303e..bdcacfc 100644 (file)
@@ -231,6 +231,8 @@ function($scope , $routeParams , $location , $window , $q , egCore) {
 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc,  egConfirmDialog,
          egGridDataProvider , egHoldGridActions , $timeout , $modal , holdingsSvc , egUser , conjoinedSvc) {
 
+    var holdingsSvcInst = new holdingsSvc();
+
     // set record ID on page load if available...
     $scope.record_id = $routeParams.record_id;
     $scope.summary_pane_record;
@@ -505,7 +507,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     $scope.holdingsGridControls = {};
     $scope.holdingsGridDataProvider = egGridDataProvider.instance({
         get : function(offset, count) {
-            return this.arrayNotifier(holdingsSvc.copies, offset, count);
+            return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
         }
     });
 
@@ -706,7 +708,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     $scope.holdings_record_id_changed = function(id) {
         if ($scope.record_id != id) $scope.record_id = id;
         console.log('record id changed to ' + id + ', loading new holdings');
-        holdingsSvc.fetch({
+        holdingsSvcInst.fetch({
             rid : $scope.record_id,
             org : $scope.holdings_ou,
             copy: $scope.holdings_show_copies,
@@ -721,7 +723,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
     $scope.holdings_ou_changed = function(org) {
         $scope.holdings_ou = org;
-        holdingsSvc.fetch({
+        holdingsSvcInst.fetch({
             rid : $scope.record_id,
             org : $scope.holdings_ou,
             copy: $scope.holdings_show_copies,
@@ -735,7 +737,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
         $scope[cb] = newVal;
         egCore.hatch.setItem('cat.' + cb, newVal);
-        if (!norefresh) holdingsSvc.fetch({
+        if (!norefresh) holdingsSvcInst.fetch({
             rid : $scope.record_id,
             org : $scope.holdings_ou,
             copy: $scope.holdings_show_copies,
@@ -979,7 +981,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
                 }
             ).then(function(success) {
                 if (success) {
-                    holdingsSvc.fetchAgain().then(function() {
+                    holdingsSvcInst.fetchAgain().then(function() {
                         $scope.holdingsGridDataProvider.refresh();
                     });
                 } else {
@@ -1017,13 +1019,13 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
                                 copy_ids,
                                 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
                             ).then(function(resp) {
-                                holdingsSvc.fetchAgain().then(function() {
+                                holdingsSvcInst.fetchAgain().then(function() {
                                     $scope.holdingsGridDataProvider.refresh();
                                 });
                             });
                         });
                     } else {
-                        holdingsSvc.fetchAgain().then(function() {
+                        holdingsSvcInst.fetchAgain().then(function() {
                             $scope.holdingsGridDataProvider.refresh();
                         });
                     }
@@ -1058,7 +1060,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
 
     $scope.selectedHoldingsDamaged = function () {
         egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
-            holdingsSvc.fetchAgain().then(function() {
+            holdingsSvcInst.fetchAgain().then(function() {
                 $scope.holdingsGridDataProvider.refresh();
             });
         });
@@ -1066,7 +1068,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
 
     $scope.selectedHoldingsMissing = function () {
         egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
-            holdingsSvc.fetchAgain().then(function() {
+            holdingsSvcInst.fetchAgain().then(function() {
                 $scope.holdingsGridDataProvider.refresh();
             });
         });
index 8da1443..9721425 100644 (file)
@@ -1,18 +1,18 @@
-angular.module('egHoldingsMod', ['egCoreMod'])
+angular.module('egHoldingsMod', ['egCoreMod','egGridMod'])
 
 .factory('holdingsSvc', 
        ['egCore','$q',
 function(egCore , $q) {
 
-    var service = {
-        ongoing : false,
-        copies : [], // record search results
-        index : 0, // search grid index
-        org : null,
-        rid : null
+    var service = function() {
+        this.ongoing = false;
+        this.copies = []; // record search results
+        this.index = 0; // search grid index
+        this.org = null;
+        this.rid = null;
     };
 
-    service.flesh = {   
+    service.prototype.flesh = {   
         flesh : 2, 
         flesh_fields : {
             acp : ['status','location'],
@@ -20,19 +20,20 @@ function(egCore , $q) {
         }
     }
 
-    service.fetchAgain = function() {
-        return service.fetch({
-            rid: service.rid,
-            org: service.org,
-            copy: service.copy,
-            vol: service.vol,
-            empty: service.empty
+    service.prototype.fetchAgain = function() {
+        return this.fetch({
+            rid: this.rid,
+            org: this.org,
+            copy: this.copy,
+            vol: this.vol,
+            empty: this.empty
         })
-    }
+    };
 
     // resolved with the last received copy
-    service.fetch = function(opts) {
-        if (service.ongoing) {
+    service.prototype.fetch = function(opts) {
+        var svc = this;
+        if (svc.ongoing) {
             console.log('Skipping fetch, ongoing = true');
             return $q.when();
         }
@@ -46,16 +47,16 @@ function(egCore , $q) {
         if (!rid) return $q.when();
         if (!org) return $q.when();
 
-        service.ongoing = true;
+        svc.ongoing = true;
 
-        service.rid = rid;
-        service.org = org;
-        service.copy = opts.copy;
-        service.vol = opts.vol;
-        service.empty = opts.empty;
+        svc.rid = rid;
+        svc.org = org;
+        svc.copy = opts.copy;
+        svc.vol = opts.vol;
+        svc.empty = opts.empty;
 
-        service.copies = [];
-        service.index = 0;
+        svc.copies = [];
+        svc.index = 0;
 
         var org_list = egCore.org.descendants(org.id(), true);
         console.log('Holdings fetch with: rid='+rid+' org='+org_list+' copy='+copy+' vol='+vol+' empty='+empty);
@@ -63,10 +64,10 @@ function(egCore , $q) {
         return egCore.pcrud.search(
             'acn',
             {record : rid, owning_lib : org_list, deleted : 'f'},
-            service.flesh
+            svc.flesh
         ).then(
             function() { // finished
-                service.copies = service.copies.sort(
+                svc.copies = svc.copies.sort(
                     function (a, b) {
                         function compare_array (x, y, i) {
                             if (x[i] && y[i]) { // both have values
@@ -108,7 +109,7 @@ function(egCore , $q) {
                 // create a label using just the unique part of the owner list
                 var index = 0;
                 var prev_owner_list;
-                angular.forEach(service.copies, function (cp) {
+                angular.forEach(svc.copies, function (cp) {
                     if (!prev_owner_list) {
                         cp.owner_label = cp.owner_list.join(' ... ');
                     } else {
@@ -124,7 +125,7 @@ function(egCore , $q) {
                     prev_owner_list = cp.owner_list.slice();
                 });
 
-                var new_list = service.copies;
+                var new_list = svc.copies;
                 if (!copy || !vol) { // collapse copy rows, supply a count instead
 
                     index = 0;
@@ -219,8 +220,8 @@ function(egCore , $q) {
                     }
                 }
 
-                service.copies = new_list;
-                service.ongoing = false;
+                svc.copies = new_list;
+                svc.ongoing = false;
             },
 
             null, // error
@@ -255,9 +256,9 @@ function(egCore , $q) {
                         flat.push(flat_cp);
                     });
 
-                    service.copies = service.copies.concat(flat);
+                    svc.copies = svc.copies.concat(flat);
                 } else if (empty) {
-                    service.copies.push({
+                    svc.copies.push({
                         owner_id   : owner_id,
                         owner_list : owner_name_list,
                         call_number: egCore.idl.toHash(cn),
@@ -268,7 +269,48 @@ function(egCore , $q) {
                 return cn;
             }
         );
-    }
+    };
 
     return service;
-}]);
+}])
+.directive("egVolumeList", function () {
+    return {
+        restrict:   'AE',
+        scope: {
+            recordId : '='
+        },
+        templateUrl: './cat/share/t_volume_list',
+        controller:
+                   ['$scope','holdingsSvc','egCore','egGridDataProvider',
+            function($scope , holdingsSvc , egCore , egGridDataProvider) {
+                var holdingsSvcInst = new holdingsSvc();
+
+                $scope.holdingsGridControls = {};
+                $scope.holdingsGridDataProvider = egGridDataProvider.instance({
+                    get : function(offset, count) {
+                        return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
+                    }
+                });
+                function load_holdings() {
+                    holdingsSvcInst.fetch({
+                        rid   : $scope.recordId,
+                        org   : egCore.org.get(egCore.auth.user().ws_ou()), // TOOD: use root OU?
+                        copy  : false,
+                        vol   : true,
+                        empty : true
+                    }).then(function() {
+                        $scope.holdingsGridDataProvider.refresh();
+                    });
+                };
+                $scope.$watch('recordId',
+                    function(newVal, oldVal) {
+                        if (newVal && newVal !== oldVal) {
+                            load_holdings();
+                        }
+                    }
+                );
+                load_holdings();
+            }]
+    }
+})
+;