Matteo Scandolo | cb466ed | 2017-01-04 17:16:24 -0800 | [diff] [blame] | 1 | import {IXosModelDefsField} from '../../core/services/helpers/config.helpers'; |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 2 | import {IXosAppConfig} from '../../../index'; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 3 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 4 | // Models interfaces |
| 5 | export interface IXosModelDefsField { |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 6 | name: string; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 7 | type: string; |
| 8 | validators?: any; |
| 9 | hint?: string; |
| 10 | relation?: { |
| 11 | model: string; |
| 12 | type: string; |
| 13 | }; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 14 | } |
| 15 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 16 | export interface IXosModelDefsRelation { |
| 17 | model: string; // model name |
| 18 | type: string; // relation type |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 19 | } |
| 20 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 21 | export interface IXosModeldef { |
| 22 | fields: IXosModelDefsField[]; |
| 23 | relations?: IXosModelDefsRelation[]; |
| 24 | name: string; |
| 25 | app: string; |
| 26 | } |
| 27 | |
| 28 | export interface IXosModeldefsService { |
| 29 | get(): Promise<IXosModeldef[]>; |
| 30 | } |
| 31 | |
| 32 | export class XosModeldefsService implements IXosModeldefsService { |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 33 | |
| 34 | static $inject = ['$http', '$q', 'AppConfig']; |
| 35 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 36 | constructor( |
| 37 | private $http: angular.IHttpService, |
| 38 | private $q: angular.IQService, |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 39 | private AppConfig: IXosAppConfig |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 40 | ) { |
| 41 | } |
| 42 | |
| 43 | public get(): Promise<any> { |
| 44 | const d = this.$q.defer(); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 45 | this.$http.get(`${this.AppConfig.apiEndpoint}/modeldefs`) |
| 46 | .then((res: any) => { |
| 47 | d.resolve(res.data.items); |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 48 | }) |
| 49 | .catch(e => { |
| 50 | d.reject(e); |
| 51 | }); |
| 52 | return d.promise; |
| 53 | } |
| 54 | } |