Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 1 | import {IXosTableCfg} from '../../core/table/table'; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 2 | import {IModelStoreService} from '../../datasources/stores/model.store'; |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 3 | export interface IXosCrudData { |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 4 | model: string; |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 5 | xosTableCfg: IXosTableCfg; |
| 6 | } |
| 7 | |
| 8 | class CrudController { |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 9 | static $inject = ['$state', '$scope', 'ModelStore']; |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 10 | |
| 11 | public data: IXosCrudData; |
| 12 | public tableCfg: IXosTableCfg; |
| 13 | public title: string; |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 14 | public tableData: any[]; |
| 15 | |
| 16 | constructor( |
| 17 | private $state: angular.ui.IStateService, |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 18 | private $scope: angular.IScope, |
| 19 | private store: IModelStoreService |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 20 | ) { |
| 21 | this.data = this.$state.current.data; |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 22 | this.tableCfg = this.data.xosTableCfg; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 23 | this.title = this.data.model; |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 24 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 25 | this.store.query(this.data.model) |
Matteo Scandolo | 035c593 | 2016-12-14 09:55:15 -0800 | [diff] [blame] | 26 | .subscribe( |
| 27 | (event) => { |
| 28 | // NOTE Observable mess with $digest cycles, we need to schedule the expression later |
| 29 | $scope.$evalAsync(() => { |
| 30 | this.tableData = event; |
| 31 | }); |
| 32 | } |
| 33 | ); |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
| 37 | export const xosCrud: angular.IComponentOptions = { |
| 38 | template: require('./crud.html'), |
| 39 | controllerAs: 'vm', |
| 40 | controller: CrudController |
| 41 | }; |