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 | |
| 4 | export interface IModeldef { |
Matteo Scandolo | cb466ed | 2017-01-04 17:16:24 -0800 | [diff] [blame] | 5 | fields: IXosModelDefsField[]; |
| 6 | relations?: string[]; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 7 | name: string; |
| 8 | } |
| 9 | |
| 10 | export interface IModeldefsService { |
| 11 | get(): Promise<IModeldef[]>; |
| 12 | } |
| 13 | |
| 14 | export class ModeldefsService { |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame^] | 15 | |
| 16 | static $inject = ['$http', '$q', 'AppConfig']; |
| 17 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 18 | constructor( |
| 19 | private $http: angular.IHttpService, |
| 20 | private $q: angular.IQService, |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame^] | 21 | private AppConfig: IXosAppConfig |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 22 | ) { |
| 23 | } |
| 24 | |
| 25 | public get(): Promise<any> { |
| 26 | const d = this.$q.defer(); |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame^] | 27 | this.$http.get(`${this.AppConfig.apiEndpoint}/utility/modeldefs/`) |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 28 | .then((res) => { |
| 29 | d.resolve(res.data); |
| 30 | }) |
| 31 | .catch(e => { |
| 32 | d.reject(e); |
| 33 | }); |
| 34 | return d.promise; |
| 35 | } |
| 36 | } |