},
controller : [
- '$scope','egIDL','egAuth','egNet', 'egGridFlatDataProvider',
- 'egGridColumnsProvider','$filter','$window','egHatch',
- function($scope, egIDL, egAuth, egNet, egGridFlatDataProvider,
- egGridColumnsProvider , $filter , $window , egHatch) {
+ '$scope','$q','egCore','egGridFlatDataProvider',
+ 'egGridColumnsProvider','$filter','$window',
+ function($scope, $q , egCore, egGridFlatDataProvider,
+ egGridColumnsProvider , $filter , $window) {
var grid = this;
defaultToNoMultiSort : (features.indexOf('-multisort') > -1)
});
- $scope.columns = grid.columnsProvider.columns;
$scope.showAllColumns = function() {
grid.columnsProvider.showAllColumns();
}
}
if ($scope.autoFields) {
- grid.indexField = egIDL.classes[grid.idlClass].pkey;
+ grid.indexField = egCore.idl.classes[grid.idlClass].pkey;
if (grid.autoLabel)
- $scope.mainLabel = egIDL.classes[grid.idlClass].label;
+ $scope.mainLabel = egCore.idl.classes[grid.idlClass].label;
grid.columnsProvider.compileAutoColumns();
delete $scope.autoFields;
}
}
}
- grid.compileSort();
+ grid.loadConfig().then(function() {
+ // link columns to scope after loadConfig(), since it
+ // replaces the columns array.
+ $scope.columns = grid.columnsProvider.columns;
+ });
+ }
+
+ // save the columns configuration (position, sort, width) to
+ // eg.grid.<persist-key>
+ $scope.saveConfig = function() {
+ if (!grid.persistKey) {
+ console.warn(
+ "Cannot save settings without a grid persist-key");
+ return;
+ }
+ var conf = grid.columnsProvider.columns.map(
+ function(col) {
+ var c = {
+ name : col.name,
+ flex : col.flex,
+ };
+ // preserve prefs space by only storing values that
+ // are non-default
+ if (Number(col.sort)) c.sort = Number(col.sort);
+ if (Boolean(col.visible)) c.visible = true;
+ return c;
+ }
+ );
+
+ egCore.hatch.setItem('eg.grid.' + grid.persistKey, conf)
+ .then(function() {
+ // Save operation performed from the grid configuration UI.
+ // Hide the configuration UI and re-draw w/ sort applied
+ if ($scope.showGridConf)
+ $scope.toggleConfDisplay();
+ });
+ }
+
+ // load the columns configuration (position, sort, width) from
+ // eg.grid.<persist-key> and apply the loaded settings to the
+ // columns on our columnsProvider
+ grid.loadConfig = function() {
+ if (!grid.persistKey) return $q.when();
+
+ return egCore.hatch.getItem('eg.grid.' + grid.persistKey)
+ .then(function(conf) {
+ if (!conf) return;
+
+ var columns = grid.columnsProvider.columns;
+ var new_cols = [];
+
+ angular.forEach(conf, function(col) {
+ var grid_col = columns.filter(
+ function(c) {return c.name == col.name})[0];
+
+ if (!grid_col) {
+ // saved column does not match a column in the
+ // current grid. skip it.
+ return;
+ }
+
+ grid_col.flex = col.flex;
+ grid_col.sort = col.sort || 0;
+ grid_col.visible = col.visible || false;
+ new_cols.push(grid_col);
+ });
+
+ // check for new columns which are not yet expressed
+ // within the saved configuration and tack them onto
+ // the end of the columns list
+ angular.forEach(columns, function(col) {
+ var found = conf.filter(
+ function(c) {return (c.name == col.name)})[0];
+ if (!found) new_cols.push(col);
+ });
+
+ grid.columnsProvider.columns = new_cols;
+ grid.compileSort();
+ });
}
$scope.onContextMenu = function($event) {
// the columns array, then force a page refresh
grid.columnsProvider.columns.splice(srcIdx, 1);
grid.columnsProvider.columns.splice(targetIdx, 0, srcCol);
+ console.log(JSON.stringify(grid.columnsProvider.columns,'',2));
$scope.$apply();
}
}
$scope.printCSV = function() {
- egHatch.print('text/plain', grid.generateCSV())
+ egCore.hatch.print('text/plain', grid.generateCSV())
.then(function() { console.debug('print complete') });
}
};
})
-.factory('egGridColumnsProvider', ['egIDL', function(egIDL) {
+.factory('egGridColumnsProvider', ['egCore', function(egCore) {
function ColumnsProvider(args) {
var cols = this;
cols.compileAutoColumns = function() {
- var idl_class = egIDL.classes[cols.idlClass];
+ var idl_class = egCore.idl.classes[cols.idlClass];
angular.forEach(
idl_class.fields.sort(
// as the display field for the columns.
// flattener will take care of the fleshing.
if (field['class']) {
- var selector_field = egIDL.classes[field['class']].fields
+ var selector_field = egCore.idl.classes[field['class']].fields
.filter(function(f) { return Boolean(f.selector) })[0];
if (selector_field) {
field.path = field.name + '.' + selector_field.selector;
// finds the IDL field from the dotpath, using the columns
// idlClass as the base.
cols.idlFieldFromPath = function(dotpath) {
- var class_obj = egIDL.classes[cols.idlClass];
+ var class_obj = egCore.idl.classes[cols.idlClass];
var path_parts = dotpath.split(/\./);
// for() == early exit
if (idl_field && idl_field['class'] && (
idl_field.datatype == 'link' ||
idl_field.datatype == 'org_unit')) {
- class_obj = egIDL.classes[idl_field['class']];
+ class_obj = egCore.idl.classes[idl_field['class']];
} else {
if (path_idx < (path_parts.length - 1)) {
// we ran out of classes to hop through before
* meet the needs of each individual grid.
*/
.factory('egGridDataProvider',
- ['$q','$timeout','$filter','egNet','egAuth','egIDL',
- function($q , $timeout , $filter , egNet , egAuth , egIDL) {
+ ['$q','$timeout','$filter','egCore',
+ function($q , $timeout , $filter , egCore) {
function GridDataProvider(args) {
var gridData = this;
}
cls = obj.classname;
- if (cls && (clsobj = egIDL.classes[cls])) {
+ if (cls && (clsobj = egCore.idl.classes[cls])) {
idlField = clsobj.fields.filter(
function(f) { return f.name == step })[0];
obj = obj[step]();
// Factory service for egGridDataManager instances, which are
// responsible for collecting flattened grid data.
.factory('egGridFlatDataProvider',
- ['$q','egNet','egAuth','egGridDataProvider',
- function($q , egNet , egAuth , egGridDataProvider) {
+ ['$q','egCore','egGridDataProvider',
+ function($q , egCore , egGridDataProvider) {
return {
instance : function(args) {
}
);
- return egNet.request(
+ return egCore.net.request(
'open-ils.fielder',
'open-ils.fielder.flattened_search',
- egAuth.token(), provider.idlClass,
+ egCore.auth.token(), provider.idlClass,
queryFields, query,
{ sort : provider.sort,
limit : count,