blob: 4663b5941b398fff6a210afa3848b131428671df [file] [log] [blame]
Matteo Scandolo9f87f302016-12-13 18:11:10 -08001import {IXosTableCfg} from '../../core/table/table';
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08002import {IModelStoreService} from '../../datasources/stores/model.store';
Matteo Scandolo9f87f302016-12-13 18:11:10 -08003export interface IXosCrudData {
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08004 model: string;
Matteo Scandolo9f87f302016-12-13 18:11:10 -08005 xosTableCfg: IXosTableCfg;
6}
7
8class CrudController {
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08009 static $inject = ['$state', '$scope', 'ModelStore'];
Matteo Scandolo9f87f302016-12-13 18:11:10 -080010
11 public data: IXosCrudData;
12 public tableCfg: IXosTableCfg;
13 public title: string;
Matteo Scandolo9f87f302016-12-13 18:11:10 -080014 public tableData: any[];
15
16 constructor(
17 private $state: angular.ui.IStateService,
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080018 private $scope: angular.IScope,
19 private store: IModelStoreService
Matteo Scandolo9f87f302016-12-13 18:11:10 -080020 ) {
21 this.data = this.$state.current.data;
Matteo Scandolo9f87f302016-12-13 18:11:10 -080022 this.tableCfg = this.data.xosTableCfg;
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080023 this.title = this.data.model;
Matteo Scandolo9f87f302016-12-13 18:11:10 -080024
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080025 this.store.query(this.data.model)
Matteo Scandolo035c5932016-12-14 09:55:15 -080026 .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 Scandolo9f87f302016-12-13 18:11:10 -080034 }
35}
36
37export const xosCrud: angular.IComponentOptions = {
38 template: require('./crud.html'),
39 controllerAs: 'vm',
40 controller: CrudController
41};