webstaff transit list: switch to egGridFlatDataProvider
authorGalen Charlton <gmc@esilibrary.com>
Tue, 15 Nov 2016 19:27:20 +0000 (14:27 -0500)
committerKathy Lussier <klussier@masslnc.org>
Tue, 22 Nov 2016 19:10:05 +0000 (14:10 -0500)
This gets us sorting "for free", or at least more easily than
with a custom-written data provider.  The following fields
are marked sortable for now:

- barcode
- title
- source library
- destination library
- send date/time

Because egGridFlatDataProvider gives us flattened hashes, not
fieldmapper objects, various tweaks were required to compensate.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/templates/staff/circ/transits/t_list.tt2
Open-ILS/web/js/ui/default/staff/circ/services/transits.js
Open-ILS/web/js/ui/default/staff/circ/transits/list.js

index 5c240db..6d598f0 100644 (file)
@@ -29,7 +29,6 @@
   id-field="id"
   idl-class="atc"
   features="-sort,-multisort"
-  items-provider="grid_data_provider"
   grid-controls="grid_controls"
   persist-key="circ.transits.list"
 >
   <eg-grid-menu-item handler="abort_transit" 
     label="[% l('Abort Transit') %]"></eg-grid-menu-item>
 
-  <eg-grid-field path='id' hidden></eg-grid-field>
-  <eg-grid-field path='target_copy.barcode' label="[% l('Barcode') %]">
-    <a target="_self" href='./cat/item/{{item.target_copy().id()}}'>{{item.target_copy().barcode()}}</a>
+  <eg-grid-field path='id' hidden required></eg-grid-field>
+  <eg-grid-field path='target_copy.id' hidden required></eg-grid-field>
+  <eg-grid-field path='target_copy.call_number.record.simple_record.id' hidden required></eg-grid-field>
+  <eg-grid-field path='hold_transit_copy.hold.id' hidden required></eg-grid-field>
+  <eg-grid-field path='target_copy.barcode' label="[% l('Barcode') %]" sortable>
+    <a target="_self" href="./cat/item/{{item['target_copy.id']}}">{{item['target_copy.barcode']}}</a>
   </eg-grid-field>
   <eg-grid-field path='target_copy.circ_lib.shortname' hidden></eg-grid-field>
   <eg-grid-field path='target_copy.call_number.label' hidden></eg-grid-field>
-  <eg-grid-field path='target_copy.call_number.record.simple_record.title' label="[% l('Title') %]">
-    <a target="_self" href="[% ctx.base_path %]/staff/cat/catalog/record/{{item.target_copy().call_number().record().simple_record().id()}}">
-      {{item.target_copy().call_number().record().simple_record().title()}}
+  <eg-grid-field path='target_copy.call_number.record.simple_record.title' label="[% l('Title') %]" sortable>
+    <a target="_self" href="[% ctx.base_path %]/staff/cat/catalog/record/{{item['target_copy.call_number.record.simple_record.id']}}">
+      {{item['target_copy.call_number.record.simple_record.title']}}
     </a>
   </eg-grid-field>
   <eg-grid-field path='target_copy.call_number.record.simple_record.author' hidden></eg-grid-field>
-  <eg-grid-field path='source.shortname' label="[% l('Source Library') %]"></eg-grid-field>
-  <eg-grid-field path='dest.shortname' label="[% l('Destination Library') %]"></eg-grid-field>
-  <eg-grid-field path='source_send_time' dateformat='short''></eg-grid-field>
+  <eg-grid-field path='source.shortname' label="[% l('Source Library') %]" sortable></eg-grid-field>
+  <eg-grid-field path='dest.shortname' label="[% l('Destination Library') %]" sortable></eg-grid-field>
+  <eg-grid-field path='source_send_time' dateformat='short' sortable></eg-grid-field>
   <eg-grid-field path='hold_transit_copy.hold.hold_type'></eg-grid-field>
   <eg-grid-field path='hold_transit_copy.hold.request_time' hidden></eg-grid-field>
   <eg-grid-field path='hold_transit_copy.hold.capture_time' hidden></eg-grid-field>
index ec2499e..001de63 100644 (file)
@@ -22,7 +22,7 @@ function($uibModal , $q , egCore , egConfirmDialog , egAlertDialog) {
                     $scope.num_transits = transits.length;
                     $scope.num_hold_transits = 0;
                     angular.forEach(transits, function(t) {
-                        if (t.hold_transit_copy()) {
+                        if (t['hold_transit_copy.hold.id']) {
                             $scope.num_hold_transits++;
                         }
                     });
@@ -42,7 +42,7 @@ function($uibModal , $q , egCore , egConfirmDialog , egAlertDialog) {
                             }
                             egCore.net.request(
                                 'open-ils.circ', 'open-ils.circ.transit.abort',
-                                egCore.auth.token(), { 'transitid' : transit.id() }
+                                egCore.auth.token(), { 'transitid' : transit['id'] }
                             ).then(function(resp) {
                                 if (evt = egCore.evt.parse(resp)) {
                                     egCore.audio.play('warning.transit.abort_failed');
index e11a77a..5e6550a 100644 (file)
@@ -21,9 +21,6 @@ angular.module('egTransitListApp',
        ['$scope','$q','$routeParams','$window','egCore','egTransits','egGridDataProvider','$uibModal','$timeout',
 function($scope , $q , $routeParams , $window , egCore , egTransits , egGridDataProvider , $uibModal , $timeout) {
 
-    var transits = [];
-    var provider = egGridDataProvider.instance({});
-    $scope.grid_data_provider = provider;
     $scope.transit_direction = 'to';
 
     function init_dates() {
@@ -90,10 +87,10 @@ function($scope , $q , $routeParams , $window , egCore , egTransits , egGridData
         abort_transit(transits);
     }
 
-    $scope.add_copies_to_bucket = function(transits) {
+    $scope.add_copies_to_bucket = function() {
         var copy_list = [];
         angular.forEach($scope.grid_controls.selectedItems(), function(transit) {
-            copy_list.push(transit.target_copy().id());
+            copy_list.push(transit['target_copy.id']);
         });
         if (copy_list.length == 0) return;
 
@@ -167,8 +164,8 @@ function($scope , $q , $routeParams , $window , egCore , egTransits , egGridData
         angular.forEach(
             $scope.grid_controls.selectedItems(),
             function (item) {
-                if (rid_list.indexOf(item.target_copy().call_number().record().simple_record().id()) == -1)
-                    rid_list.push(item.target_copy().call_number().record().simple_record().id());
+                if (rid_list.indexOf(item['target_copy.call_number.record.simple_record.id']) == -1)
+                    rid_list.push(item['target_copy.call_number.record.simple_record.id']);
             }
         );
         return rid_list;
@@ -178,8 +175,8 @@ function($scope , $q , $routeParams , $window , egCore , egTransits , egGridData
         angular.forEach(
             $scope.grid_controls.selectedItems(),
             function (item) {
-                if (rid && item.target_copy().call_number().record().simple_record().id() != rid) return;
-                cp_id_list.push(item.target_copy().id());
+                if (rid && item['target_copy.call_number.record.simple_record.id'] != rid) return;
+                cp_id_list.push(item['target_copy.id']);
             }
         );
         return cp_id_list;
@@ -212,54 +209,24 @@ function($scope , $q , $routeParams , $window , egCore , egTransits , egGridData
         spawnHoldingsEdit(true, false);
     }
 
-    $scope.grid_controls = {
-        activateItem : load_item
-    }
-
-    function refresh_page() {
-        transits = [];
-        provider.refresh();
-    }
-
-    provider.get = function(offset, count) {
-        var deferred = $q.defer();
-        var recv_index = 0;
-
+    function current_query() {
         var filter = {
             'source_send_time' : { 'between' : date_range() },
             'dest_recv_time'   : null
         };
         if ($scope.transit_direction == 'to') { filter['dest'] = $scope.context_org.id(); }
         if ($scope.transit_direction == 'from') { filter['source'] = $scope.context_org.id(); }
+        return filter;
+    }
 
-        egCore.pcrud.search('atc',
-            filter, {
-                'flesh' : 5,
-                // atc -> target_copy       -> call_number -> record -> simple_record
-                // atc -> hold_transit_copy -> hold        -> usr    -> card
-                'flesh_fields' : {
-                    'atc' : ['target_copy','dest','source','hold_transit_copy'],
-                    'acp' : ['call_number','location','circ_lib'],
-                    'acn' : ['record'],
-                    'bre' : ['simple_record'],
-                    'ahtc' : ['hold'],
-                    'ahr' : ['usr'],
-                    'au' : ['card']
-                },
-                'select' : { 'bre' : ['id'] },
-                order_by : { atc : 'source_send_time' },
-                limit  : count,
-                offset : offset,
-            }
-        ).then(
-            deferred.resolve, null, 
-            function(transit) {
-                transits[offset + recv_index++] = transit;
-                deferred.notify(transit);
-            }
-        );
+    $scope.grid_controls = {
+        activateItem : load_item,
+        setQuery : current_query
+    }
 
-        return deferred.promise;
+    function refresh_page() {
+        $scope.grid_controls.setQuery(current_query());
+        $scope.grid_controls.refresh();
     }
 
     $scope.context_org = egCore.org.get(egCore.auth.user().ws_ou());