webstasff: start serials Issues tab
authorMike Rylander <mrylander@gmail.com>
Wed, 10 May 2017 19:27:58 +0000 (15:27 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 May 2017 16:06:44 +0000 (12:06 -0400)
Just a grid for now.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/serials/index.tt2
Open-ILS/src/templates/staff/serials/t_item_manager.tt2 [new file with mode: 0644]
Open-ILS/src/templates/staff/serials/t_manage.tt2
Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/serials/directives/item_manager.js [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/serials/services/core.js
Open-ILS/web/js/ui/default/staff/services/idl.js

index 63e7f3a..c50b432 100644 (file)
@@ -12,6 +12,8 @@
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/directives/sub_selector.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/directives/prediction_manager.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/directives/prediction_wizard.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/directives/item_manager.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/directives/view-items-grid.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/cat/services/record.js"></script>
 <script>
 angular.module('egCoreMod').run(['egStrings', function(s) {
diff --git a/Open-ILS/src/templates/staff/serials/t_item_manager.tt2 b/Open-ILS/src/templates/staff/serials/t_item_manager.tt2
new file mode 100644 (file)
index 0000000..8c7227a
--- /dev/null
@@ -0,0 +1,7 @@
+<div>
+<eg-sub-selector bib-id="bibId" ssub-id="ssubId"></eg-sub-selector>
+</div>
+
+<div>
+<eg-item-grid bib-id="bibId" ssub-id="ssubId"></eg-item-grid>
+</div>
index 38758d0..40cadb3 100644 (file)
@@ -17,7 +17,9 @@
         </eg-prediction-manager>
       </uib-tab>
       <uib-tab index="'view-issues'" heading="[% l('View Issues') %]">
-        <p>View Issues TODO</p>
+        <eg-item-manager ng-if="active_tab == 'view-issues'"
+            bib-id="bib_id" ssub-id="ssub.id">
+        </eg-item-manager>
       </uib-tab>
       <uib-tab index="'receive'" heading="[% l('Receive') %]">
         <p>Receive TODO</p>
diff --git a/Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2 b/Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2
new file mode 100644 (file)
index 0000000..24228ec
--- /dev/null
@@ -0,0 +1,31 @@
+<div>
+  <eg-grid
+    id-field="index"
+    features="-display,-sort,-multisort"
+    items-provider="itemGridProvider"
+    grid-controls="itemGridControls"
+    persist-key="serials.view_item_grid">
+
+    <eg-grid-action handler="edit_items"
+      label="[% l('Edit Items') %]"></eg-grid-action>
+    <eg-grid-action handler="delete_items"
+      label="[% l('Delete Items') %]"></eg-grid-action>
+
+    <eg-grid-field label="[% l('Distribution Library') %]" path="stream.distribution.holding_lib.name" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Issuance') %]" path="issuance.label" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Publication Date') %]" path="issuance.date_published" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Holding Type') %]" path="issuance.holding_type" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Route To') %]" path="stream.routing_label"></eg-grid-field>
+    <eg-grid-field label="[% l('Receiving Template') %]" path="stream.distribution.receive_unit_template.name" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Summary Display') %]" path="stream.distribution.summary_method" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Receiving Call Number') %]" path="stream.distribution.receive_call_number.label"></eg-grid-field>
+    <eg-grid-field label="[% l('Binding Call Number') %]" path="stream.distribution.bind_call_number.label"></eg-grid-field>
+    <eg-grid-field label="[% l('Binding Template') %]" path="stream.distribution.bind_unit_template.name"></eg-grid-field>
+    <eg-grid-field label="[% l('Unit Label Prefix') %]" path="stream.distribution.unit_label_prefix"></eg-grid-field>
+    <eg-grid-field label="[% l('Unit Label Suffix') %]" path="stream.distribution.unit_label_suffix"></eg-grid-field>
+    <eg-grid-field label="[% l('Display Grouping') %]" path="stream.distribution.display_grouping"></eg-grid-field>
+    <eg-grid-field label="[% l('Subscription ID') %]" path="stream.distribution.subscription.id"></eg-grid-field>
+    <eg-grid-field label="[% l('Distribution ID') %]" path="stream.distribution.id"></eg-grid-field>
+  </eg-grid>
+</div>
+
diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/item_manager.js b/Open-ILS/web/js/ui/default/staff/serials/directives/item_manager.js
new file mode 100644 (file)
index 0000000..2ada6a4
--- /dev/null
@@ -0,0 +1,59 @@
+angular.module('egSerialsAppDep')
+
+.directive('egItemManager', function() {
+    return {
+        transclude: true,
+        restrict:   'E',
+        scope: {
+            bibId  : '=',
+            ssubId : '='
+        },
+        templateUrl: './serials/t_item_manager',
+        controller:
+       ['$scope','$q','egSerialsCoreSvc','egCore','$uibModal',
+function($scope , $q , egSerialsCoreSvc , egCore , $uibModal) {
+
+    egSerialsCoreSvc.fetch($scope.bibId);
+
+    // convert to sitem funcs
+    $scope.createScap = function(pred) {
+        var scap = egCore.idl.fromTypedHash(pred);
+        egCore.pcrud.create(scap).then(function() {
+            // completely reset the model in order to reset the
+            // forms; causes a blink, alas
+            $scope.predictions = [];
+            $scope.new_prediction = null;
+            egSerialsCoreSvc.fetch($scope.bibId).then(function() {
+                reload($scope.ssubId);
+            });
+        });
+    }
+    $scope.updateScap = function(pred) {
+        var scap = egCore.idl.fromTypedHash(pred);
+        egCore.pcrud.update(scap).then(function() {
+            // completely reset the model in order to reset the
+            // forms; causes a blink, alas
+            $scope.predictions = [];
+            egSerialsCoreSvc.fetch($scope.bibId).then(function() {
+                reload($scope.ssubId);
+            });
+        });
+    }
+    $scope.deleteScap = function(pred) {
+        var scap = egCore.idl.fromTypedHash(pred);
+        // TODO ask to confirm
+        // TODO check whether there are linked issuances
+        egCore.pcrud.remove(scap).then(function() {
+            // completely reset the model in order to reset the
+            // forms; causes a blink, alas
+            $scope.predictions = [];
+            egSerialsCoreSvc.fetch($scope.bibId).then(function() {
+                reload($scope.ssubId);
+            });
+        });
+    }
+
+
+}]
+    }
+})
diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js b/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js
new file mode 100644 (file)
index 0000000..1ce60b4
--- /dev/null
@@ -0,0 +1,57 @@
+angular.module('egSerialsAppDep')
+
+.directive('egItemGrid', function() {
+    return {
+        transclude: true,
+        restrict:   'E',
+        scope: {
+            bibId  : '=',
+            ssubId : '='
+        },
+        templateUrl: './serials/t_view_items_grid',
+        controller:
+       ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider',
+        '$uibModal',
+function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
+         $uibModal) {
+
+    $scope.svc = egSerialsCoreSvc; // just for debugging
+
+    function reload(ssubId) {
+        return egSerialsCoreSvc.fetchItemsForSub(ssubId).then(function(list) {
+            $scope.itemGridProvider.refresh();
+        });
+    }
+
+    $scope.$watch('ssubId', function(newVal, oldVal) {
+        if (newVal && newVal != oldVal) return reload(newVal);
+    });
+
+    $scope.itemGridControls = {
+        activateItem : function (item) { } // TODO
+    };
+
+    $scope.itemGridProvider = egGridDataProvider.instance({
+        get : function(offset, count) {
+            return this.arrayNotifier(egSerialsCoreSvc.itemList, offset, count);
+        }
+    });
+
+    $scope.need_one_selected = function() {
+        var items = $scope.itemGridControls.selectedItems();
+        if (items.length == 1) return false;
+        return true;
+    };
+
+    if (!egSerialsCoreSvc.subTree.length) {
+        egSerialsCoreSvc.fetch($scope.bibId).then(function() {
+            return reload($scope.ssubId);
+        });
+    } else if ($scope.ssubId) {
+        reload($scope.ssubId);
+    }
+
+}]
+
+    }
+})
index 3394585..f3fc525 100644 (file)
@@ -7,7 +7,9 @@ function(egCore , orderByFilter , $q) {
         subId : null,
         subTree : [],
         subList : [],
-        sptList : []
+        sptList : [],
+        itemTree : [],
+        itemList : []
     };
 
     // fetch subscription, distributions, streams, captions,
@@ -34,6 +36,65 @@ function(egCore , orderByFilter , $q) {
             update_flat_sdist_sstr_list();
         });
     }
+    // Creates an inverted tree from item to sub
+    service.fetchItemsForSub = function(subId) {
+
+        if (!subId && service.subId) subId = service.subId;
+        if (!subId) return $q.reject('fetchItemsForSub: no subscription id');
+
+        var sub = service.get_ssub(subId);
+        if (!sub) return $q.reject('fetchItemsForSub: unknown subscription id');
+
+        var streams = [];
+        angular.forEach(sub.distributions(), function(dist) {
+            angular.forEach(
+                dist.streams().map(
+                    function (stream) { return stream.id() }
+                ),
+                function (sid) { streams.push(sid) }
+            );
+        });
+
+        return egCore.pcrud.search(
+            'sitem',
+            { stream : streams },
+            { 
+                flesh : 1,
+                flesh_fields : {
+                    sitem : ['issuance','editor','creator','unit','url']
+                }
+            },
+            { atomic : true }
+        ).then(function(list) {
+            service.subId = subId;
+            service.itemTree = list;
+
+            // map items by stream for faster lookup
+            var tmp = {};
+            angular.forEach(list, function(item) {
+                if (!tmp[item.stream()]) tmp[item.stream()] = [];
+                tmp[item.stream()].push(item);
+            });
+            angular.forEach(sub.distributions(), function(dist) {
+                angular.forEach(dist.streams(), function(stream) {
+                    angular.forEach(tmp[stream.id()], function (item) {
+                        var st = egCore.idl.Clone(stream,1);
+                        var d = egCore.idl.Clone(dist,1);
+                        var ss = egCore.idl.Clone(sub,1);
+                        ss.distributions([]);
+                        d.subscription(ss);
+                        d.streams([]);
+                        st.distribution(d);
+                        item.stream(st);
+                    });
+                });
+            });
+
+            service.itemList = egCore.idl.toHash(list);
+            return $q.when(list);
+        });
+    }
 
     // create/update a flat version of the subscription/distribution/stream
     // tree for feeding to the distribution and stream grid
@@ -156,6 +217,7 @@ function(egCore , orderByFilter , $q) {
     }
 
     service.get_ssub = function(ssubId) {
+        if (!ssubId) return;
         for (var i = 0; i <= service.subTree.length; i++) {
             if (service.subTree[i].id() == ssubId) {
                 return service.subTree[i];
index a62b031..444b820 100644 (file)
@@ -37,6 +37,8 @@ angular.module('egCoreMod')
                 } else if (thing._isfieldmapper) {
                     obj.a[i] = service.Clone(thing);
                 } else {
+                    if(angular.isArray(thing)) {
+                        obj.a[i] = [];
 
                     if(angular.isArray(thing)) {
                         obj.a[i] = [];
@@ -62,7 +64,7 @@ angular.module('egCoreMod')
                     if (typeof old[j] == 'undefined')
                         obj[j] = old[j];
                     else if( old[j]._isfieldmapper )
-                        obj[j] = service.Clone(old[j]);
+                        obj[j] = service.Clone(old[j], depth - 1);
                     else
                         obj[j] = angular.copy(old[j]);
                 }
@@ -72,7 +74,7 @@ angular.module('egCoreMod')
                     if (typeof old[j] == 'undefined')
                         obj[j] = old[j];
                     else if( old[j]._isfieldmapper )
-                        obj[j] = service.Clone(old[j]);
+                        obj[j] = service.Clone(old[j], depth - 1);
                     else
                         obj[j] = angular.copy(old[j]);
                 }