blob: b35c104aa2e4b455899e2766d75ef0e9c11a2bc7 [file] [log] [blame]
Matteo Scandolo9f87f302016-12-13 18:11:10 -08001import {IXosResourceService} from '../../rest/slices.rest';
2import {IXosTableCfg} from '../../core/table/table';
3export interface IXosCrudData {
4 title: string;
5 resource: string;
6 xosTableCfg: IXosTableCfg;
7}
8
9class 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
38export const xosCrud: angular.IComponentOptions = {
39 template: require('./crud.html'),
40 controllerAs: 'vm',
41 controller: CrudController
42};