blob: fdb4b99b886d83f6cc4aeba2f3cfc07d05babd84 [file] [log] [blame]
Matteo Scandolocb466ed2017-01-04 17:16:24 -08001import {IXosModelDefsField} from '../../core/services/helpers/config.helpers';
Matteo Scandolo828d1e82017-01-17 14:49:38 -08002import {IXosAppConfig} from '../../../index';
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08003
Matteo Scandolo1aee1982017-02-17 08:33:23 -08004// Models interfaces
5export interface IXosModelDefsField {
Matteo Scandolof2c3ed62016-12-15 14:32:50 -08006 name: string;
Matteo Scandolo1aee1982017-02-17 08:33:23 -08007 type: string;
8 validators?: any;
9 hint?: string;
10 relation?: {
11 model: string;
12 type: string;
13 };
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080014}
15
Matteo Scandolo1aee1982017-02-17 08:33:23 -080016export interface IXosModelDefsRelation {
17 model: string; // model name
18 type: string; // relation type
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080019}
20
Matteo Scandolo1aee1982017-02-17 08:33:23 -080021export interface IXosModeldef {
22 fields: IXosModelDefsField[];
23 relations?: IXosModelDefsRelation[];
24 name: string;
25 app: string;
26}
27
28export interface IXosModeldefsService {
29 get(): Promise<IXosModeldef[]>;
30}
31
32export class XosModeldefsService implements IXosModeldefsService {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080033
34 static $inject = ['$http', '$q', 'AppConfig'];
35
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080036 constructor(
37 private $http: angular.IHttpService,
38 private $q: angular.IQService,
Matteo Scandolo828d1e82017-01-17 14:49:38 -080039 private AppConfig: IXosAppConfig
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080040 ) {
41 }
42
43 public get(): Promise<any> {
44 const d = this.$q.defer();
Matteo Scandolo1aee1982017-02-17 08:33:23 -080045 this.$http.get(`${this.AppConfig.apiEndpoint}/modeldefs`)
46 .then((res: any) => {
47 d.resolve(res.data.items);
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080048 })
49 .catch(e => {
50 d.reject(e);
51 });
52 return d.promise;
53 }
54}