blob: 981cac217cb6ac787f96920783dbd2d985414eae [file] [log] [blame]
Matteo Scandolofb46ae62017-08-08 09:10:50 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolocb466ed2017-01-04 17:16:24 -080019import {IXosModelDefsField} from '../../core/services/helpers/config.helpers';
Matteo Scandolo828d1e82017-01-17 14:49:38 -080020import {IXosAppConfig} from '../../../index';
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080021
Matteo Scandolo1aee1982017-02-17 08:33:23 -080022// Models interfaces
23export interface IXosModelDefsField {
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080024 name: string;
Matteo Scandolo1aee1982017-02-17 08:33:23 -080025 type: string;
26 validators?: any;
27 hint?: string;
28 relation?: {
29 model: string;
30 type: string;
31 };
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080032}
33
Matteo Scandolo1aee1982017-02-17 08:33:23 -080034export interface IXosModelDefsRelation {
35 model: string; // model name
36 type: string; // relation type
Matteo Scandolo5d962a32017-08-01 18:16:14 -070037 on_field: string; // the field that is containing the relation
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080038}
39
Matteo Scandolo1aee1982017-02-17 08:33:23 -080040export interface IXosModeldef {
41 fields: IXosModelDefsField[];
42 relations?: IXosModelDefsRelation[];
43 name: string;
44 app: string;
45}
46
47export interface IXosModeldefsService {
48 get(): Promise<IXosModeldef[]>;
49}
50
51export class XosModeldefsService implements IXosModeldefsService {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080052
53 static $inject = ['$http', '$q', 'AppConfig'];
54
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080055 constructor(
56 private $http: angular.IHttpService,
57 private $q: angular.IQService,
Matteo Scandolo828d1e82017-01-17 14:49:38 -080058 private AppConfig: IXosAppConfig
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080059 ) {
60 }
61
62 public get(): Promise<any> {
63 const d = this.$q.defer();
Matteo Scandolo1aee1982017-02-17 08:33:23 -080064 this.$http.get(`${this.AppConfig.apiEndpoint}/modeldefs`)
65 .then((res: any) => {
66 d.resolve(res.data.items);
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080067 })
68 .catch(e => {
69 d.reject(e);
70 });
71 return d.promise;
72 }
73}