From 057c0aa9f95ac533d07b9b14457b4fc70010441a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 8 Mar 2017 12:51:58 -0500 Subject: [PATCH] LP1373690 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 --- Open-ILS/src/templates/staff/admin/acq/index.tt2 | 7 + .../templates/staff/admin/acq/t_edi_attr_set.tt2 | 28 +++- .../src/templates/staff/admin/acq/t_splash.tt2 | 1 + Open-ILS/src/templates/staff/css/style.css.tt2 | 7 + Open-ILS/web/js/ui/default/staff/admin/acq/app.js | 181 +++++++++++++++++++++ 5 files changed, 219 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/templates/staff/admin/acq/index.tt2 b/Open-ILS/src/templates/staff/admin/acq/index.tt2 index f5a8b7a371..a437bf664e 100644 --- a/Open-ILS/src/templates/staff/admin/acq/index.tt2 +++ b/Open-ILS/src/templates/staff/admin/acq/index.tt2 @@ -8,8 +8,15 @@ + [% 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 index 8e533ad8b6..4a8b4607f3 100644 --- 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 @@ -9,10 +9,15 @@
    +
  • + + [% l('New Attribute Set...') %] +
  • +
  • {{set.label()}}
  • @@ -22,13 +27,26 @@ class="form-control" disabled="disabled" value="[% l('No Attribute Set Selected') %]"/> + class="form-control" + placeholder="[% l('Attribute Set Name...') %]" + ng-model-options="{ getterSetter: true }" + ng-model="cur_attr_set.label"/>
- + + + + + + + + [% l('Currently used by [_1] EDI account(s).', '{{cur_attr_set_uses}}') %] +
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 bdfd64dd5a..8636175040 100644 --- a/Open-ILS/src/templates/staff/css/style.css.tt2 +++ b/Open-ILS/src/templates/staff/css/style.css.tt2 @@ -222,6 +222,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..33b52f0be3 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,178 @@ function($scope , $routeParams , $location , egCore) { }]) +.controller('EDIAttrSet', + ['$scope','$q','egCore','ngToast', +function($scope , $q , egCore , ngToast) { + + $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.auto(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.auto(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() { + ( $scope.cur_attr_set.isnew() ? + $q.when() : + egCore.pcrud.remove($scope.cur_attr_set) + ).then( + 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) } + ); + } + + load_data(); +}]) + + -- 2.11.0