From 1fb2f3ff63434e43e40652a4b5734f92057755f5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 8 Mar 2017 12:47:55 -0500 Subject: [PATCH] LP#1373690 EDI attribute sets admin UI 1. Create new attribute sets 2. Rename attribute Sets. 3. Enable / Disable attributes for each attributes set. Found under Admin -> Acquisitions -> EDI Attribute Sets. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- .../src/templates/staff/admin/acq/index.tt2 | 8 + .../staff/admin/acq/t_edi_attr_set.tt2 | 67 ++++++ .../templates/staff/admin/acq/t_splash.tt2 | 1 + .../src/templates/staff/css/style.css.tt2 | 7 + .../web/js/ui/default/staff/admin/acq/app.js | 192 ++++++++++++++++++ .../web/js/ui/default/staff/services/pcrud.js | 10 +- .../web/js/ui/default/staff/services/ui.js | 1 + 7 files changed, 283 insertions(+), 3 deletions(-) create mode 100644 Open-ILS/src/templates/staff/admin/acq/t_edi_attr_set.tt2 diff --git a/Open-ILS/src/templates/staff/admin/acq/index.tt2 b/Open-ILS/src/templates/staff/admin/acq/index.tt2 index f5a8b7a371..437893543f 100644 --- a/Open-ILS/src/templates/staff/admin/acq/index.tt2 +++ b/Open-ILS/src/templates/staff/admin/acq/index.tt2 @@ -8,8 +8,16 @@ + [% END %] +
[% END %] diff --git a/Open-ILS/src/templates/staff/admin/acq/t_edi_attr_set.tt2 b/Open-ILS/src/templates/staff/admin/acq/t_edi_attr_set.tt2 new file mode 100644 index 0000000000..c70baef076 --- /dev/null +++ b/Open-ILS/src/templates/staff/admin/acq/t_edi_attr_set.tt2 @@ -0,0 +1,67 @@ +
+
+ [% l('EDI Attribute Sets') %] +
+
+ +
+
+
+
+ + +
+ + +
+
+
+ + + + + + + + [% l('Currently used by [_1] EDI account(s).', '{{cur_attr_set_uses}}') %] + +
+
+ +
+
+
+ + + + {{attr.key()}} +
+
{{attr.label()}}
+
+
+ + diff --git a/Open-ILS/src/templates/staff/admin/acq/t_splash.tt2 b/Open-ILS/src/templates/staff/admin/acq/t_splash.tt2 index a8737243a8..e9d2894422 100644 --- a/Open-ILS/src/templates/staff/admin/acq/t_splash.tt2 +++ b/Open-ILS/src/templates/staff/admin/acq/t_splash.tt2 @@ -19,6 +19,7 @@ ,[ l('Distribution Formulas'), "./admin/acq/conify/distribution_formula" ] ,[ l('EDI Accounts'), "./admin/acq/conify/edi_account" ] ,[ l('EDI Messages'), "./admin/acq/po/edi_messages" ] + ,[ l('EDI Attribute Sets'), "./admin/acq/edi_attr_set" ] ,[ l('Exchange Rates'), "./admin/acq/conify/exchange_rate" ] ,[ l('Fund Tags'), "./admin/acq/conify/fund_tag" ] ,[ l('Funding Sources'), "./admin/acq/funding_source/list" ] diff --git a/Open-ILS/src/templates/staff/css/style.css.tt2 b/Open-ILS/src/templates/staff/css/style.css.tt2 index 9aa3eda411..2369cd4415 100644 --- a/Open-ILS/src/templates/staff/css/style.css.tt2 +++ b/Open-ILS/src/templates/staff/css/style.css.tt2 @@ -199,6 +199,13 @@ table.list tr.selected td { /* deprecated? */ padding: 0px; } +/* Useful for grid-like things that aren't proper grids. + * Mimics the grids color scheme. */ +.selected-row { + background-color: rgb(248, 248, 248); +} + + /* ---------------------------------------------------------------------- * Grid * ---------------------------------------------------------------------- */ diff --git a/Open-ILS/web/js/ui/default/staff/admin/acq/app.js b/Open-ILS/web/js/ui/default/staff/admin/acq/app.js index 14dbe847f9..de8dddc532 100644 --- a/Open-ILS/web/js/ui/default/staff/admin/acq/app.js +++ b/Open-ILS/web/js/ui/default/staff/admin/acq/app.js @@ -8,6 +8,12 @@ angular.module('egAcqAdmin', $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); var resolver = {delay : function(egStartup) {return egStartup.go()}}; + $routeProvider.when('/admin/acq/edi_attr_set', { + templateUrl: './admin/acq/t_edi_attr_set', + controller: 'EDIAttrSet', + resolve : resolver + }); + var eframe_template = ''; @@ -60,3 +66,189 @@ function($scope , $routeParams , $location , egCore) { }]) +.controller('EDIAttrSet', + ['$scope','$q','egCore','ngToast','egConfirmDialog', +function($scope , $q , egCore , ngToast , egConfirmDialog) { + + $scope.cur_attr_set = null; + + // fetch all the data needed to render the page. + function load_data() { + + return egCore.pcrud.retrieveAll('aea', {}, + {atomic : true, authoritative : true}) + .then( + function(attrs) { + $scope.attrs = attrs + return egCore.pcrud.retrieveAll('aeas', + {flesh : 1, flesh_fields : {'aeas' : ['attr_maps']}}, + {atomic : true, authoritative : true} + ) + } + + ).then(function(sets) { + $scope.attr_sets = sets.sort(function(a, b) { + return a.label() < b.label() ? -1 : 1; + }); + + // create a simple true/false attr_set => attr mapping + var select_me; + angular.forEach(sets, function(set) { + set._local_map = {}; + angular.forEach(set.attr_maps(), function(map) { + set._local_map[map.attr()] = true; + }) + + if ($scope.cur_attr_set && set.id() + == $scope.cur_attr_set.id()) { + select_me = set; + } + }); + + $scope.select_set(select_me || $scope.attr_sets[0]); + }); + } + + function create_sets() { + var new_sets = $scope.attr_sets.filter(function(set) { + if (set.isnew() && set.label()) { + console.debug('creating new set: ' + set.label()); + return true; + } + return false; + }); + + if (new_sets.length == 0) return $q.when(); + + // create the new attrs sets and collect the newly generated + // ID in the local data store. + return egCore.pcrud.apply(new_sets).then( + null, + function() { + $scope.attr_sets = $scope.attr_sets.filter( + function(set) { return (set.label() && !set.isnew()) }); + return $q.reject(); + }, + function(new_set) { + var old_set = new_sets.filter(function(s) { + return (s.isnew() && s.label() == new_set.label()) })[0]; + old_set.id(new_set.id()); + old_set.isnew(false); + } + ); + } + + function modify_maps() { + var update_maps = []; + + angular.forEach($scope.attr_sets, function(set) { + console.debug('inspecting attr set ' + set.label()); + + // find maps that need deleting + angular.forEach(set.attr_maps(), function(oldmap) { + if (!set._local_map[oldmap.attr()]) { + console.debug('\tdeleting map for ' + oldmap.attr()); + oldmap.isdeleted(true); + update_maps.push(oldmap); + } + }); + + // find maps that need creating + angular.forEach(set._local_map, function(value, key) { + if (!value) return; + + var existing = set.attr_maps().filter( + function(emap) { return emap.attr() == key })[0]; + + if (existing) return; + + console.debug('\tcreating map for ' + key); + + var newmap = new egCore.idl.aeasm(); + newmap.isnew(true); + newmap.attr(key); + newmap.attr_set(set.id()); + update_maps.push(newmap); + }); + }); + + return egCore.pcrud.apply(update_maps); + } + + // mark the currently selected attr set as the main display set. + $scope.select_set = function(set) { + $scope.cur_attr_set_uses = 0; // how many edi accounts use this set + if (set.isnew()) { + $scope.cur_attr_set = set; + } else { + egCore.pcrud.search('acqedi', {attr_set : set.id()}, {}, + {idlist : true, atomic : true} + ).then(function(accts) { + $scope.cur_attr_set_uses = accts.length; + $scope.cur_attr_set = set; + }); + } + } + + $scope.new_set = function() { + var set = new egCore.idl.aeas(); + set.isnew(true); + set.attr_maps([]); + set._local_map = {}; + $scope.select_set(set); + $scope.attr_sets.push(set); + } + + $scope.apply = function() { + $scope.save_in_progress = true; + create_sets() + .then(modify_maps) + .then( + function() { + ngToast.create(egCore.strings.ATTR_SET_SUCCESS) + }, + function() { + ngToast.warning(egCore.strings.ATTR_SET_ERROR); + return $q.reject(); + }) + .then(load_data) + .finally( + function() { $scope.save_in_progress = false; } + ); + } + + // Delete the currently selected attr set. + // Attr set maps will cascade delete. + $scope.remove = function() { + egConfirmDialog.open( + egCore.strings.ATTR_SET_DELETE_CONFIRM, + $scope.cur_attr_set.label() + ).result.then(function() { + $scope.save_in_progress = true; + ( // remove from server if necessary + $scope.cur_attr_set.isnew() ? + $q.when() : + egCore.pcrud.remove($scope.cur_attr_set) + ).then( + // remove from the local att_sets list + function() { + ngToast.create(egCore.strings.ATTR_SET_SUCCESS); + $scope.attr_sets = $scope.attr_sets.filter( + function(set) { + return set.id() != $scope.cur_attr_set.id() + } + ); + $scope.cur_attr_set = $scope.attr_sets[0]; + }, + function() { ngToast.warning(egCore.strings.ATTR_SET_ERROR) } + + ).finally( + function() { $scope.save_in_progress = false; } + ); + }); + } + + load_data(); +}]) + + diff --git a/Open-ILS/web/js/ui/default/staff/services/pcrud.js b/Open-ILS/web/js/ui/default/staff/services/pcrud.js index 66fdba928b..72cb94ec84 100644 --- a/Open-ILS/web/js/ui/default/staff/services/pcrud.js +++ b/Open-ILS/web/js/ui/default/staff/services/pcrud.js @@ -91,7 +91,9 @@ angular.module('egCoreMod') this.session.disconnect(); }; - this.retrieve = function(fm_class, pkey, pcrud_ops) { + this.retrieve = function(fm_class, pkey, pcrud_ops, req_ops) { + req_ops = req_ops || {}; + this.authoritative = req_ops.authoritative; return this._dispatch( 'open-ils.pcrud.retrieve.' + fm_class, [egAuth.token(), pkey, pcrud_ops] @@ -106,6 +108,7 @@ angular.module('egCoreMod') this.search = function (fm_class, search, pcrud_ops, req_ops) { req_ops = req_ops || {}; + this.authoritative = req_ops.authoritative; var return_type = req_ops.idlist ? 'id_list' : 'search'; var method = 'open-ils.pcrud.' + return_type + '.' + fm_class; @@ -179,7 +182,7 @@ angular.module('egCoreMod') }, // main body error handler - function() {}, + function() {deferred.reject()}, // main body notify() handler function(data) {deferred.notify(data)} @@ -287,7 +290,8 @@ angular.module('egCoreMod') self.cud_last = data; self.cud_deferred.notify(data); self._CUD_next_request(); - } + }, + self.cud_deferred.reject ); }; diff --git a/Open-ILS/web/js/ui/default/staff/services/ui.js b/Open-ILS/web/js/ui/default/staff/services/ui.js index 51aac05ad7..0c385fa2bc 100644 --- a/Open-ILS/web/js/ui/default/staff/services/ui.js +++ b/Open-ILS/web/js/ui/default/staff/services/ui.js @@ -398,6 +398,7 @@ function($uibModal, $interpolate) { var service = {}; service.open = function(title, message, msg_scope, ok_button_label, cancel_button_label) { + msg_scope = msg_scope || {}; return $uibModal.open({ templateUrl: './share/t_confirm_dialog', controller: ['$scope', '$uibModalInstance', -- 2.43.2