LP#1715697: Show libraries without holdings when requested
authorMike Rylander <mrylander@gmail.com>
Tue, 24 Apr 2018 19:21:37 +0000 (15:21 -0400)
committerDan Wells <dbw2@calvin.edu>
Fri, 25 May 2018 17:08:41 +0000 (13:08 -0400)
When chosen, display subordinate libraries of the context library that do not
have any holdings or empty volumes.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
Open-ILS/web/js/ui/default/staff/cat/services/holdings.js

index c6bf4e0..222ea20 100644 (file)
     grid-controls="holdingsGridControls"
     persist-key="cat.holdings">
 
-     <eg-grid-menu-item handler="holdings_checkbox_handler"
+    <eg-grid-menu-item handler="holdings_checkbox_handler"
       label="[% l('Show empty volumes') %]"
       checkbox="holdings_show_empty"
       checked="holdings_show_empty"/>
+
+    <eg-grid-menu-item handler="holdings_checkbox_handler"
+      label="[% l('Show empty libraries') %]"
+      checkbox="holdings_show_empty_org"
+      checked="holdings_show_empty_org"/>
+
     <eg-grid-menu-item handler="holdings_checkbox_handler"
       label="[% l('Show copy detail') %]"
       checkbox="holdings_show_copies"
index 4b3d186..780d734 100644 (file)
@@ -1038,7 +1038,8 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
             org : $scope.holdings_ou,
             copy: $scope.holdings_show_copies,
             vol : $scope.holdings_show_vols,
-            empty: $scope.holdings_show_empty
+            empty: $scope.holdings_show_empty,
+            empty_org: $scope.holdings_show_empty_org
         }).then(function() {
             $scope.holdingsGridDataProvider.refresh();
         });
@@ -1053,7 +1054,8 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
             org : $scope.holdings_ou,
             copy: $scope.holdings_show_copies,
             vol : $scope.holdings_show_vols,
-            empty: $scope.holdings_show_empty
+            empty: $scope.holdings_show_empty,
+            empty_org: $scope.holdings_show_empty_org
         }).then(function() {
             $scope.holdingsGridDataProvider.refresh();
         });
@@ -1067,7 +1069,8 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
             org : $scope.holdings_ou,
             copy: $scope.holdings_show_copies,
             vol : $scope.holdings_show_vols,
-            empty: $scope.holdings_show_empty
+            empty: $scope.holdings_show_empty,
+            empty_org: $scope.holdings_show_empty_org
         }).then(function() {
             $scope.holdingsGridDataProvider.refresh();
         });
@@ -1087,6 +1090,12 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
                 if (typeof x ==  'undefined') x = true;
                 $scope.holdings_cb_changed('holdings_show_empty',x);
                 $('#holdings_show_empty').prop('checked', x);
+            }).then(function(){
+                egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
+                    if (typeof x ==  'undefined') x = true;
+                    $scope.holdings_cb_changed('holdings_show_empty_org',x);
+                    $('#holdings_show_empty_org').prop('checked', x);
+                })
             })
         })
     });
@@ -1099,6 +1108,10 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         return !$scope.holdings_show_copies;
     }
 
+    $scope.empty_org_not_shown = function () {
+        return !$scope.holdings_show_empty_org;
+    }
+
     $scope.holdings_checkbox_handler = function (item) {
         $scope.holdings_cb_changed(item.checkbox,item.checked);
     }
index eb835f5..2a642ca 100644 (file)
@@ -26,7 +26,8 @@ function(egCore , $q) {
             org: this.org,
             copy: this.copy,
             vol: this.vol,
-            empty: this.empty
+            empty: this.empty,
+            empty_org: this.empty_org
         })
     };
 
@@ -41,6 +42,7 @@ function(egCore , $q) {
         }
 
         var rid = opts.rid;
+        var empty_org = opts.empty_org;
         var org = opts.org;
         var copy = opts.copy;
         var vol = opts.vol;
@@ -52,6 +54,7 @@ function(egCore , $q) {
         svc.ongoing = true;
 
         svc.rid = rid;
+        svc.empty_org = opts.empty_org;
         svc.org = org;
         svc.copy = opts.copy;
         svc.vol = opts.vol;
@@ -63,6 +66,9 @@ function(egCore , $q) {
         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);
 
+        svc.org_use_map = {};
+        org_list.map(function(o){svc.org_use_map[''+o]=0;})
+
         var p = egCore.pcrud.search(
             'acn',
             {record : rid, owning_lib : org_list, deleted : 'f'},
@@ -70,6 +76,7 @@ function(egCore , $q) {
         ).then(
             function() { // finished
                 if (p.cancel) return;
+
                 svc.copies = svc.copies.sort(
                     function (a, b) {
                         function compare_array (x, y, i) {
@@ -237,6 +244,40 @@ function(egCore , $q) {
                     }
                 }
 
+                if (empty_org) {
+
+                    var empty_org_list = [];
+                    angular.forEach(svc.org_use_map,function(v,k){
+                        if (v == 0) empty_org_list.push(k);
+                    });
+
+                    angular.forEach(empty_org_list, function (oid) {
+                        var owner = egCore.org.get(oid);
+                        if (owner.ou_type().can_have_vols() != 't') return;
+
+                        var owner_list = [];
+                        while (owner.parent_ou()) { // we're going to skip the top of the tree...
+                            owner_list.unshift(owner.shortname());
+                            owner = egCore.org.get(owner.parent_ou());
+                        }
+
+                        var owner_label = owner_list.join(' ... ');
+
+                        new_list.push({
+                            index      : index++,
+                            id_list    : [],
+                            call_number: { label : '' },
+                            barcode    : '',
+                            owner_id   : oid,
+                            owner_list : owner_list,
+                            owner_label: owner_label,
+                            copy_count : 0,
+                            cn_count   : 0,
+                            copy_alert_count : 0
+                        });
+                    });
+                }
+
                 svc.copies = new_list;
                 svc.ongoing = false;
             },
@@ -256,6 +297,7 @@ function(egCore , $q) {
 
                 var owner_id = cn.owning_lib();
                 var owner = egCore.org.get(owner_id);
+                svc.org_use_map[''+owner_id] += 1;
 
                 var owner_name_list = [];
                 while (owner.parent_ou()) { // we're going to skip the top of the tree...