From: Bill Erickson Date: Mon, 10 Mar 2014 21:15:29 +0000 (-0400) Subject: web staff: autogrid experiments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2d6ba96bffcb69f01bd43e58cc9574593e8e9961;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 index 70ea9aea48..f0c09af204 100644 --- a/Open-ILS/src/templates/staff/parts/t_autogrid.tt2 +++ b/Open-ILS/src/templates/staff/parts/t_autogrid.tt2 @@ -4,11 +4,18 @@ .eg-grid-header-row { font-weight: bold; } .eg-grid div.row {padding: 3px; border-right: 2px solid rgb(248, 248, 248);} .eg-grid div.row:nth-child(odd) {background-color: rgb(248, 248, 248);} + .eg-grid div[class*="col-"] {border-right: 1px solid rgb(248, 248, 248);}
- -
+ +
+
+
+ {{column.label}} +
+
{{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 deleted file mode 100644 index 4dc5b9d17c..0000000000 --- a/Open-ILS/src/templates/staff/parts/t_autogrid_field.tt2 +++ /dev/null @@ -1 +0,0 @@ -
{{column.label}}
diff --git a/Open-ILS/src/templates/staff/test/t_autogrid.tt2 b/Open-ILS/src/templates/staff/test/t_autogrid.tt2 index 2b0d102aef..12729b28e5 100644 --- a/Open-ILS/src/templates/staff/test/t_autogrid.tt2 +++ b/Open-ILS/src/templates/staff/test/t_autogrid.tt2 @@ -1,14 +1,18 @@

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 index cee91ca948..261342458f 100644 --- a/Open-ILS/web/js/ui/default/staff/services/autogrid.js +++ b/Open-ILS/web/js/ui/default/staff/services/autogrid.js @@ -8,11 +8,17 @@ angular.module('egGridMod', ['egCoreMod', 'egListMod']) scope : { idlClass : '@', query : '=', - sort : '=', + sort : '@', + autoFields : '=' }, templateUrl : '/eg/staff/parts/t_autogrid', // TODO: abs url controller : function($scope, $timeout, egIDL, egAuth, egNet, egList) { // TODO: reqs list var self = this; + + // if we stick w/ Bootstrap grids for display, we're + // limited to 12 visible columns at a time. + this.maxFieldCount = 12; + $scope.dataList = egList.create(); this.addField = function(fieldScope) { @@ -20,11 +26,43 @@ angular.module('egGridMod', ['egCoreMod', 'egListMod']) name : fieldScope.name, label : fieldScope.label, path : fieldScope.path, - display : true + display : (fieldScope === false) ? false : true }; self.applyFieldLabel(field); $scope.dataList.addColumn(field); - return {dataList : $scope.dataList, column : field}; + } + + /** + * Caller wants to display all fields for the selected IDL class + * Find the fields and, when a field is a link, fetch the label + * from the "selector" field as well. + */ + this.compileAutoFields = function() { + if ($scope.dataList.allColumns.length) return; + + angular.forEach( + egIDL.classes[$scope.idlClass].fields.sort( + function(a, b) { return a.name < b.name ? -1 : 1 }), + function(field) { + if (field.virtual) return; + if (field.datatype == 'link' || field.datatype == 'org_unit') { + // if the field is a link and the linked class has a + // "selector" field specified, use the selector field + // as the display field for the grid. + // flattener will take care of the fleshing. + if (field['class']) { + var selectorField = egIDL.classes[field['class']].fields + .filter(function(f) { return Boolean(f.selector) })[0]; + if (selectorField) { + field.path = field.name + '.' + selectorField.selector; + } + } + } + if ($scope.dataList.allColumns.length >= self.maxFieldCount) + field.display = false; + self.addField(field); + } + ); } this.applyFieldLabel = function(field) { @@ -78,6 +116,9 @@ angular.module('egGridMod', ['egCoreMod', 'egListMod']) return; } + if ($scope.autoFields) + self.compileAutoFields(); + var queryFields = {} angular.forEach($scope.dataList.allColumns, function(field) { if ($scope.dataList.displayColumns[field.name]) @@ -104,7 +145,7 @@ angular.module('egGridMod', ['egCoreMod', 'egListMod']) // have been processed. There has to be a better way... readycheck = 0; this.checkReadyForDraw = function() { - if ($scope.dataList.allColumns.length) { + if ($scope.autoFields || $scope.dataList.allColumns.length) { self.fetchData(); } else { if (++readycheck > 10000) return; // failsafe, no fields defined @@ -117,26 +158,20 @@ angular.module('egGridMod', ['egCoreMod', 'egListMod']) }; }) +/** + * eg-grid-field : used for collecting custom field data from the templates. + * This directive does not direct display, it just passes data up to the + * parent grid. + */ .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. + scope : {name : '@', path : '@', label : '@'}, + template : '
', // NOOP template link : function(scope, element, attrs, egGridCtrl) { - var ctx = egGridCtrl.addField(scope); - scope.dataList = ctx.dataList; - scope.column = ctx.column; + egGridCtrl.addField(scope); } }; });