From: Bill Erickson Date: Mon, 10 Mar 2014 20:12:52 +0000 (-0400) Subject: web staff: autogrid experiments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1f2f69c7c671c3ddb0449a926e0cca935a7175ed;p=working%2FEvergreen.git web staff: autogrid experiments Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/templates/staff/parts/t_autogrid.tt2 b/Open-ILS/src/templates/staff/parts/t_autogrid.tt2 new file mode 100644 index 0000000000..70ea9aea48 --- /dev/null +++ b/Open-ILS/src/templates/staff/parts/t_autogrid.tt2 @@ -0,0 +1,19 @@ + + + +
+ +
+
+
+ {{dataList.fieldValue(item, field.name)}} +
+
+
+ + diff --git a/Open-ILS/src/templates/staff/parts/t_autogrid_field.tt2 b/Open-ILS/src/templates/staff/parts/t_autogrid_field.tt2 new file mode 100644 index 0000000000..4dc5b9d17c --- /dev/null +++ b/Open-ILS/src/templates/staff/parts/t_autogrid_field.tt2 @@ -0,0 +1 @@ +
{{column.label}}
diff --git a/Open-ILS/src/templates/staff/test/index.tt2 b/Open-ILS/src/templates/staff/test/index.tt2 new file mode 100644 index 0000000000..68d48020a8 --- /dev/null +++ b/Open-ILS/src/templates/staff/test/index.tt2 @@ -0,0 +1,17 @@ +[% + WRAPPER "staff/t_base.tt2"; + ctx.page_title = l("Test"); + ctx.page_app = "egTestApp"; + ctx.page_ctrl = "egTestCtrl"; +%] + +[% BLOCK APP_JS %] + + + + +[% END %] + +
+ +[% END %] diff --git a/Open-ILS/src/templates/staff/test/t_autogrid.tt2 b/Open-ILS/src/templates/staff/test/t_autogrid.tt2 new file mode 100644 index 0000000000..2b0d102aef --- /dev/null +++ b/Open-ILS/src/templates/staff/test/t_autogrid.tt2 @@ -0,0 +1,14 @@ + +

AutoGrid Test

+
+
+
+
+
+
+
+
diff --git a/Open-ILS/web/js/ui/default/staff/services/autogrid.js b/Open-ILS/web/js/ui/default/staff/services/autogrid.js new file mode 100644 index 0000000000..cee91ca948 --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/services/autogrid.js @@ -0,0 +1,144 @@ + +angular.module('egGridMod', ['egCoreMod', 'egListMod']) + +.directive('egGrid', function() { + return { + restrict : 'A', + transclude : true, + scope : { + idlClass : '@', + query : '=', + sort : '=', + }, + templateUrl : '/eg/staff/parts/t_autogrid', // TODO: abs url + controller : function($scope, $timeout, egIDL, egAuth, egNet, egList) { // TODO: reqs list + var self = this; + $scope.dataList = egList.create(); + + this.addField = function(fieldScope) { + var field = { + name : fieldScope.name, + label : fieldScope.label, + path : fieldScope.path, + display : true + }; + self.applyFieldLabel(field); + $scope.dataList.addColumn(field); + return {dataList : $scope.dataList, column : field}; + } + + this.applyFieldLabel = function(field) { + if (field.label) return; // label already applied + + var class_obj = egIDL.classes[$scope.idlClass]; + if (!field.path) field.path = field.name; + var path_parts = field.path.split(/\./); + + // note: use of for() is intentional for early exit + var field_obj; + for (var path_idx in path_parts) { + var part = path_parts[path_idx]; + + // find the field object matching the path component + for (var field_idx in class_obj.fields) { + if (class_obj.fields[field_idx].name == part) { + field_obj = class_obj.fields[field_idx]; + break; + } + } + + // unless we're at the end of the list, this field should + // link to another class. + + if (field_obj && field_obj['class'] && ( + field_obj.datatype == 'link' || + field_obj.datatype == 'org_unit')) { + class_obj = egIDL.classes[field_obj['class']]; + } else { + if (path_idx < (path_parts.length - 1)) { + // we ran out of classes to hop through before + // we ran out of path components + console.error("egGrid: invalid IDL path: " + field.path); + } + } + } + + field.label = field_obj ? field_obj.label : field.name; + } + + this.fetchData = function() { + + if (!$scope.query) { + console.error("egGrid requires a query"); + return; + } + + if (!$scope.idlClass) { + console.error("egGrid requires an idlClass"); + return; + } + + var queryFields = {} + angular.forEach($scope.dataList.allColumns, function(field) { + if ($scope.dataList.displayColumns[field.name]) + queryFields[field.name] = field.path || field.name; + }); + + egNet.request( + 'open-ils.fielder', + 'open-ils.fielder.flattened_search', + egAuth.token(), $scope.idlClass, queryFields, + $scope.query, + { sort : $scope.sort, + limit : 10, // TODO + offset : 0 // TODO + } + ).then(null, null, function(item) { + $scope.dataList.items.push(item); + } + ); + } + + // Don't call fetchData until we know what the fields are + // TODO: this is a hack which polls to see if our eg-grid-field's + // have been processed. There has to be a better way... + readycheck = 0; + this.checkReadyForDraw = function() { + if ($scope.dataList.allColumns.length) { + self.fetchData(); + } else { + if (++readycheck > 10000) return; // failsafe, no fields defined + // check again after the next $digest loop + $scope.$evalAsync(function() {self.checkReadyForDraw()}); + } + } + this.checkReadyForDraw(); + } + }; +}) + +.directive('egGridField', function() { + return { + require : '^egGrid', + restrict : 'A', + transclude : true, + scope : { + name : '@', + path : '@', + label : '@' + }, + templateUrl : '/eg/staff/parts/t_autogrid_field', + + // pass field info from the UI into the grid. The grid stores + // the field data within its dataList and returns a link to the + // dataList. From there, our visibility, etc. is based on the + // dispostion of the dataList. + link : function(scope, element, attrs, egGridCtrl) { + var ctx = egGridCtrl.addField(scope); + scope.dataList = ctx.dataList; + scope.column = ctx.column; + } + }; +}); + + diff --git a/Open-ILS/web/js/ui/default/staff/test/app.js b/Open-ILS/web/js/ui/default/staff/test/app.js new file mode 100644 index 0000000000..28ca01c0ef --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/test/app.js @@ -0,0 +1,38 @@ +angular.module('egTestApp', ['ngRoute', 'ui.bootstrap', + 'egCoreMod', 'egUiMod', 'egListMod', 'egGridMod']) + +.config(function($routeProvider, $locationProvider) { + $locationProvider.html5Mode(true); + + var resolver = {delay : function(egStartup) { return egStartup.go() }}; + + $routeProvider.when('/test/autogrid', { + templateUrl: './test/t_autogrid', + controller: 'TestGridCtrl', + resolve : resolver + }); + + //$routeProvider.otherwise({redirectTo : '/circ/patron/search'}); +}) + +.controller('egTestCtrl', ['$scope', function($scope) { + /* + $scope.$on('$viewContentLoaded', function() { + console.debug("viewContentLoaded"); + }); + */ +}]) + +.controller('TestGridCtrl', + ['$scope', +function($scope) { + + console.log('TestGridCtrl'); + $scope.testGridQuery = {id : {'<>' : null}}; + $scope.testGridSort = ['depth', 'parent_ou_id', 'name'] + + //$scope.fmClass="aou"; +}]); + + +