--- /dev/null
+
+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;
+ }
+ };
+});
+
+
--- /dev/null
+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";
+}]);
+
+
+