Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame^] | 1 | import {IXosResourceService} from '../../rest/slices.rest'; |
| 2 | import {IXosTableCfg} from '../../core/table/table'; |
| 3 | export interface IXosCrudData { |
| 4 | title: string; |
| 5 | resource: string; |
| 6 | xosTableCfg: IXosTableCfg; |
| 7 | } |
| 8 | |
| 9 | class CrudController { |
| 10 | static $inject = ['$state', '$injector']; |
| 11 | |
| 12 | public data: IXosCrudData; |
| 13 | public tableCfg: IXosTableCfg; |
| 14 | public title: string; |
| 15 | public resourceName: string; |
| 16 | public resource: ng.resource.IResourceClass<ng.resource.IResource<any>>; |
| 17 | public tableData: any[]; |
| 18 | |
| 19 | constructor( |
| 20 | private $state: angular.ui.IStateService, |
| 21 | private $injector: angular.Injectable<any> |
| 22 | ) { |
| 23 | this.data = this.$state.current.data; |
| 24 | console.log('xosCrud', this.data); |
| 25 | this.tableCfg = this.data.xosTableCfg; |
| 26 | this.title = this.data.title; |
| 27 | this.resourceName = this.data.resource; |
| 28 | this.resource = this.$injector.get(this.resourceName).getResource(); |
| 29 | |
| 30 | this.resource |
| 31 | .query().$promise |
| 32 | .then(res => { |
| 33 | this.tableData = res; |
| 34 | }); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export const xosCrud: angular.IComponentOptions = { |
| 39 | template: require('./crud.html'), |
| 40 | controllerAs: 'vm', |
| 41 | controller: CrudController |
| 42 | }; |