From d4d2f42e8674f93284d2932e171bf9a4f9cc8cf4 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 24 Feb 2016 17:19:14 -0500 Subject: [PATCH] LP#1549505: add admin interface to manage badges Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander Signed-off-by: Kathy Lussier --- Open-ILS/examples/fm_IDL.xml | 2 +- .../staff/admin/local/rating/badge.tt2 | 60 ++++++ .../staff/admin/local/rating/edit_badge.tt2 | 42 ++++ .../templates/staff/admin/local/t_splash.tt2 | 1 + .../src/templates/staff/css/style.css.tt2 | 3 + .../default/staff/admin/local/rating/badge.js | 189 ++++++++++++++++++ 6 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/templates/staff/admin/local/rating/badge.tt2 create mode 100644 Open-ILS/src/templates/staff/admin/local/rating/edit_badge.tt2 create mode 100644 Open-ILS/web/js/ui/default/staff/admin/local/rating/badge.js diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 6f86b517de..9ab8eefed5 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -304,7 +304,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + diff --git a/Open-ILS/src/templates/staff/admin/local/rating/badge.tt2 b/Open-ILS/src/templates/staff/admin/local/rating/badge.tt2 new file mode 100644 index 0000000000..a67249d65a --- /dev/null +++ b/Open-ILS/src/templates/staff/admin/local/rating/badge.tt2 @@ -0,0 +1,60 @@ +[% + WRAPPER 'staff/base.tt2'; + ctx.page_type = l('Statistical Popularity Badges'); + ctx.page_app = 'egAdminRating'; + ctx.page_ctrl = 'Badges'; +%] + +[% BLOCK APP_JS %] + + + + + +[% END %] + +
+
+ [% l('Statistical Popularity Badges') %] +
+
+ + + + + + + + + + + + + + + + + +[% END %] diff --git a/Open-ILS/src/templates/staff/admin/local/rating/edit_badge.tt2 b/Open-ILS/src/templates/staff/admin/local/rating/edit_badge.tt2 new file mode 100644 index 0000000000..9a1426b622 --- /dev/null +++ b/Open-ILS/src/templates/staff/admin/local/rating/edit_badge.tt2 @@ -0,0 +1,42 @@ +
+ + + + +
diff --git a/Open-ILS/src/templates/staff/admin/local/t_splash.tt2 b/Open-ILS/src/templates/staff/admin/local/t_splash.tt2 index 8dcb28fa6e..f6b7da32c4 100644 --- a/Open-ILS/src/templates/staff/admin/local/t_splash.tt2 +++ b/Open-ILS/src/templates/staff/admin/local/t_splash.tt2 @@ -31,6 +31,7 @@ ,[ l('Search Filter Groups'), "./admin/local/actor/search_filter_group" ] ,[ l('Standing Penalties'), "./admin/local/config/standing_penalty" ] ,[ l('Statistical Categories Editor'), "./admin/local/asset/stat_cat_editor" ] + ,[ l('Statistical Popularity Badges'), "./admin/local/rating/badge" ] ]; USE table(interfaces, rows=9); diff --git a/Open-ILS/src/templates/staff/css/style.css.tt2 b/Open-ILS/src/templates/staff/css/style.css.tt2 index c2ff924c0c..d4e4ae53c9 100644 --- a/Open-ILS/src/templates/staff/css/style.css.tt2 +++ b/Open-ILS/src/templates/staff/css/style.css.tt2 @@ -97,6 +97,9 @@ .form-validated input.ng-valid.ng-dirty { background-color: #78FA89; } +.form-validated input.ng-invalid-required { + background-color: #FACDCF; +} /* -------------------------------------------------------------------------- * Local style diff --git a/Open-ILS/web/js/ui/default/staff/admin/local/rating/badge.js b/Open-ILS/web/js/ui/default/staff/admin/local/rating/badge.js new file mode 100644 index 0000000000..3df43e9a1d --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/admin/local/rating/badge.js @@ -0,0 +1,189 @@ +angular.module('egAdminRating', + ['ngRoute','ui.bootstrap','egCoreMod','egUiMod','egGridMod']) + +.controller('Badges', + ['$scope','$q','$timeout','$location','$window','$modal', + 'egCore','egGridDataProvider','egConfirmDialog', +function($scope , $q , $timeout , $location , $window , $modal , + egCore , egGridDataProvider , egConfirmDialog) { + + egCore.startup.go(); + + function get_record_label() { + return egCore.idl.classes['rb'].label; + } + + function flatten_linked_values(cls, list) { + var results = []; + var fields = egCore.idl.classes[cls].fields; + var id_field; + var selector; + angular.forEach(fields, function(fld) { + if (fld.datatype == 'id') { + id_field = fld.name; + selector = fld.selector ? fld.selector : id_field; + return; + } + }); + angular.forEach(list, function(item) { + var rec = egCore.idl.toHash(item); + results.push({ + id : rec[id_field], + name : rec[selector] + }); + }); + return results; + } + + horizon_required = {}; + percentile_required = {}; + function get_popularity_with_required() { + egCore.pcrud.retrieveAll( + 'rp', {}, {atomic : true} + ).then(function(list) { + angular.forEach(list, function(item) { + horizon_required[item.id()] = item.require_horizon(); + percentile_required[item.id()] = item.require_percentile(); + }); + }); + } + + function get_field_list(rec) { + var fields = egCore.idl.classes['rb'].fields; + + var promises = []; + // flesh selectors + angular.forEach(fields, function(fld) { + if (fld.datatype == 'link') { + egCore.pcrud.retrieveAll( + fld.class, {}, {atomic : true} + ).then(function(list) { + fld.linked_values = flatten_linked_values(fld.class, list); + }); + } + if (fld.datatype == 'org_unit') { + rec[fld.name + '_ou'] = {}; + rec[fld.name + '_ou']['org'] = egCore.org.get(rec[fld.name]); + rec[fld.name + '_ou']['update_org'] = function(org) { + rec[fld.name] = org.id(); + }; + } + if (fld.name == 'last_calc') { + fld['readonly'] = true; + } + fld.is_required = function(record) { + return false; + }; + if (fld.name == 'name') { + fld.is_required = function(record) { + return true; + }; + } + if (fld.name == 'horizon_age') { + fld.is_required = function(record) { + return horizon_required[record['popularity_parameter']] == 't'; + }; + } + if (fld.name == 'percentile') { + fld.is_required = function(record) { + return percentile_required[record['popularity_parameter']] == 't'; + }; + } + }); + return fields; + } + + function spawn_editor(rb, action) { + var deferred = $q.defer(); + $modal.open({ + templateUrl: './admin/local/rating/edit_badge', + controller: + ['$scope', '$modalInstance', function($scope, $modalInstance) { + $scope.focusMe = true; + $scope.record = egCore.idl.toHash(rb); + // non-integer numeric field require parseFloat + $scope.record.percentile = parseFloat($scope.record.percentile); + $scope.record_label = get_record_label(); + $scope.fields = get_field_list($scope.record); + get_popularity_with_required(); + $scope.ok = function(args) { $modalInstance.close(args) } + $scope.cancel = function () { $modalInstance.dismiss() } + }] + }).result.then(function(args) { + var rb = new egCore.idl.rb(); + if (action == 'update') rb.id(args.id); + rb.name(args.name); + rb.description(args.description); + rb.scope(args.scope); + rb.weight(args.weight); + rb.horizon_age(args.horizon_age); + rb.importance_age(args.importance_age); + rb.importance_interval(args.importance_interval); + rb.importance_scale(args.importance_scale); + rb.recalc_interval(args.recalc_interval); + rb.attr_filter(args.attr_filter); + rb.src_filter(args.src_filter); + rb.circ_mod_filter(args.circ_mod_filter); + rb.loc_grp_filter(args.loc_grp_filter); + rb.popularity_parameter(args.popularity_parameter); + rb.fixed_rating(args.fixed_rating); + rb.percentile(args.percentile); + rb.discard(args.discard); + rb.last_calc(args.last_calc); + if (action == 'create') { + egCore.pcrud.create(rb).then(function() { deferred.resolve(); }); + } else { + egCore.pcrud.update(rb).then(function() { deferred.resolve(); }); + } + }); + return deferred.promise; + } + + $scope.create_rb = function() { + var rb = new egCore.idl.rb(); + + // make sure an OU is selected by default + rb.scope(egCore.auth.user().ws_ou()); + + spawn_editor(rb, 'create').then(function() { + $scope.gridControls.refresh(); + }); + } + + $scope.update_rb = function(selected) { + if (!selected || !selected.length) return; + + egCore.pcrud.retrieve('rb', selected[0].id).then(function(rb) { + spawn_editor(rb, 'update').then(function() { + $scope.gridControls.refresh(); + }); + }); + } + + $scope.delete_rb = function(selected) { + if (!selected || !selected.length) return; + + egCore.pcrud.retrieve('rb', selected[0].id).then(function(rb) { + egConfirmDialog.open( + egCore.strings.CONFIRM_DELETE_BADGE_TITLE, + egCore.strings.CONFIRM_DELETE_BADGE_BODY, + { name : rb.name(), id : rb.id() } + ).result.then(function() { + egCore.pcrud.remove(rb).then(function() { + $scope.gridControls.refresh(); + }); + }); + }); + } + + $scope.gridControls = { + activateItem : function (item) { + $scope.update_rb([item]); + }, + setQuery : function() { + return { + 'id' : {'!=' : null} + } + } + } +}]) -- 2.43.2