-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grids): manually saving and restoring state
This commit introduces a new feature to manually save and restore a grid's state using `ui-grid-save-state`. The feature is prototyped in the Journal module and adds an entry to the utils dropdown. State is added as an additional Grid service that can be imported and used by any module that uses a UI-Grid.
- Loading branch information
Showing
6 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
angular.module('bhima.services') | ||
.service('GridStateService', GridStateService); | ||
|
||
GridStateService.$inject = [ | ||
'util', 'appcache', 'NotifyService' | ||
]; | ||
|
||
// responsible for - | ||
// - caching grid state seperately for each grid | ||
// - hooking into the grid api to apply the default size only when the grid is ready | ||
// - exposing the methods to save and restore grid state | ||
function GridStateService(util, AppCache, Notify) { | ||
/* @const */ | ||
var stateCacheKey = 'gridState'; | ||
|
||
function StateInstance(gridOptions, moduleCacheKey) { | ||
this._cacheKey = moduleCacheKey.concat(stateCacheKey); | ||
this._cache = new AppCache(this._cacheKey); | ||
|
||
util.after(gridOptions, 'onRegisterApi', function onRegisterApi(api) { | ||
this._gridApi = api; | ||
|
||
this._gridApi.core.on.rowsRendered(null, util.once(function () { | ||
this.restoreGridState(); | ||
}.bind(this))); | ||
}.bind(this)); | ||
|
||
this.saveGridState = saveGridState.bind(this); | ||
this.restoreGridState = restoreGridState.bind(this); | ||
} | ||
|
||
function saveGridState() { | ||
if (this._gridApi) { | ||
this._cache.gridState = this._gridApi.saveState.save(); | ||
Notify.success('FORM.INFO.GRID_STATE_SUCCESS'); | ||
} | ||
}; | ||
|
||
function restoreGridState() { | ||
if (this._gridApi && this._cache.gridState) { | ||
this._gridApi.saveState.restore(null, this._cache.gridState); | ||
} | ||
}; | ||
return StateInstance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters