blob: 078eede34b6150fdbc004f959b2c1f3b4781eccf [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 Scandolo29edc0f2018-04-26 17:19:10 +020021import IPromise = angular.IPromise;
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080022
Matteo Scandolo1aee1982017-02-17 08:33:23 -080023export interface IXosModelDefsRelation {
24 model: string; // model name
25 type: string; // relation type
Matteo Scandolo5d962a32017-08-01 18:16:14 -070026 on_field: string; // the field that is containing the relation
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080027}
28
Matteo Scandolo1aee1982017-02-17 08:33:23 -080029export interface IXosModeldef {
30 fields: IXosModelDefsField[];
31 relations?: IXosModelDefsRelation[];
32 name: string;
33 app: string;
Matteo Scandolo580033a2017-08-17 11:16:39 -070034 description: string;
35 verbose_name: string;
vigneshethiraj98b2b892019-05-25 16:43:08 +053036 sync_implemented?: string;
37 policy_implemented?: string;
Matteo Scandolo1aee1982017-02-17 08:33:23 -080038}
39
40export interface IXosModeldefsService {
Matteo Scandolo29edc0f2018-04-26 17:19:10 +020041 get(): IPromise<IXosModeldef[]>;
Matteo Scandolo1aee1982017-02-17 08:33:23 -080042}
43
44export class XosModeldefsService implements IXosModeldefsService {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080045
46 static $inject = ['$http', '$q', 'AppConfig'];
47
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080048 constructor(
49 private $http: angular.IHttpService,
50 private $q: angular.IQService,
Matteo Scandolo828d1e82017-01-17 14:49:38 -080051 private AppConfig: IXosAppConfig
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080052 ) {
53 }
54
Matteo Scandolo29edc0f2018-04-26 17:19:10 +020055 public get(): IPromise<IXosModeldef[]> {
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080056 const d = this.$q.defer();
Matteo Scandolodedfbda2018-05-17 16:23:39 -070057 this.$http.get(`${this.AppConfig.apiEndpoint}/modeldefs`, {timeout: 10 * 1000})
Matteo Scandolo1aee1982017-02-17 08:33:23 -080058 .then((res: any) => {
59 d.resolve(res.data.items);
Matteo Scandolof2c3ed62016-12-15 14:32:50 -080060 })
61 .catch(e => {
62 d.reject(e);
63 });
64 return d.promise;
65 }
66}