Matteo Scandolo | fb46ae6 | 2017-08-08 09:10:50 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 19 | // TODO test me hard!!! |
| 20 | |
| 21 | import * as _ from 'lodash'; |
Matteo Scandolo | d67adee | 2018-03-08 16:27:05 -0800 | [diff] [blame] | 22 | import {IXosModeldefsService, IXosModeldef, IXosModelDefsRelation} from '../rest/modeldefs.rest'; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 23 | import {IXosTableCfg} from '../../core/table/table'; |
| 24 | import {IXosFormCfg} from '../../core/form/form'; |
| 25 | import {IXosNavigationService} from '../../core/services/navigation'; |
Matteo Scandolo | d67adee | 2018-03-08 16:27:05 -0800 | [diff] [blame] | 26 | import {IXosConfigHelpersService, IXosModelDefsField} from '../../core/services/helpers/config.helpers'; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 27 | import {IXosRuntimeStatesService, IXosState} from '../../core/services/runtime-states'; |
| 28 | import {IXosModelStoreService} from '../stores/model.store'; |
Matteo Scandolo | 0f3692e | 2017-07-10 14:06:41 -0700 | [diff] [blame] | 29 | import {IXosAuthService} from '../rest/auth.rest'; |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 30 | import {IXosModeldefsCache} from './modeldefs.service'; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 31 | |
| 32 | export interface IXosModel { |
| 33 | name: string; // the model name |
| 34 | app: string; // the service to wich it belong |
| 35 | fields: IXosModelDefsField[]; |
| 36 | relations?: IXosModelDefsRelation[]; |
| 37 | backendUrl?: string; // the api endpoint |
| 38 | clientUrl?: string; // the view url |
| 39 | tableCfg?: IXosTableCfg; |
| 40 | formCfg?: IXosFormCfg; |
Matteo Scandolo | 580033a | 2017-08-17 11:16:39 -0700 | [diff] [blame] | 41 | description: string; |
| 42 | verbose_name: string; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // Service |
| 46 | export interface IXosModelDiscovererService { |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 47 | discover(): ng.IPromise<string>; |
Matteo Scandolo | 47c53fc | 2017-03-23 14:11:32 -0700 | [diff] [blame] | 48 | getApiUrlFromModel(model: IXosModel): string; |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 49 | areModelsLoaded(): boolean; |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 50 | getStatusMessage(): string; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | export class XosModelDiscovererService implements IXosModelDiscovererService { |
| 54 | static $inject = [ |
| 55 | '$log', |
| 56 | '$q', |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 57 | '$interval', |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 58 | 'XosModelDefs', |
| 59 | 'ConfigHelpers', |
| 60 | 'XosRuntimeStates', |
| 61 | 'XosNavigationService', |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 62 | 'XosModelStore', |
Matteo Scandolo | 0f3692e | 2017-07-10 14:06:41 -0700 | [diff] [blame] | 63 | 'ngProgressFactory', |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 64 | 'AuthService', |
| 65 | 'XosModeldefsCache' |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 66 | ]; |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 67 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 68 | private xosServices: string[] = []; // list of loaded services |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 69 | private progressBar; |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 70 | private modelsLoaded: boolean = false; |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 71 | private statusMessage: string = 'Loading models definition'; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 72 | |
| 73 | constructor ( |
| 74 | private $log: ng.ILogService, |
| 75 | private $q: ng.IQService, |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 76 | private $interval: ng.IIntervalService, |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 77 | private XosModelDefs: IXosModeldefsService, |
| 78 | private ConfigHelpers: IXosConfigHelpersService, |
| 79 | private XosRuntimeStates: IXosRuntimeStatesService, |
| 80 | private XosNavigationService: IXosNavigationService, |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 81 | private XosModelStore: IXosModelStoreService, |
Matteo Scandolo | 0f3692e | 2017-07-10 14:06:41 -0700 | [diff] [blame] | 82 | private ngProgressFactory: any, // check for type defs |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 83 | private AuthService: IXosAuthService, |
| 84 | private XosModeldefsCache: IXosModeldefsCache |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 85 | ) { |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 86 | this.progressBar = this.ngProgressFactory.createInstance(); |
| 87 | this.progressBar.setColor('#f6a821'); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 90 | public areModelsLoaded(): boolean { |
| 91 | return this.modelsLoaded; |
| 92 | } |
| 93 | |
Matteo Scandolo | 47c53fc | 2017-03-23 14:11:32 -0700 | [diff] [blame] | 94 | public getApiUrlFromModel(model: IXosModel): string { |
| 95 | if (model.app === 'core') { |
| 96 | return `/core/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`; |
| 97 | } |
| 98 | else { |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 99 | const serviceName = this.XosModeldefsCache.serviceNameFromAppName(model.app); |
Matteo Scandolo | 47c53fc | 2017-03-23 14:11:32 -0700 | [diff] [blame] | 100 | return `/${serviceName}/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`; |
| 101 | } |
| 102 | } |
| 103 | |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 104 | public getStatusMessage(): string { |
| 105 | return this.statusMessage; |
| 106 | } |
| 107 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 108 | public discover() { |
| 109 | const d = this.$q.defer(); |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 110 | // loading stats |
| 111 | let loadingSince = 0; |
| 112 | const modelDefInerval = this.$interval(() => { |
| 113 | loadingSince += 1; |
| 114 | this.setModelDefTimeMsg(loadingSince); |
| 115 | }, 1000); |
| 116 | this.progressBar.set(1); |
| 117 | |
| 118 | // start loading data |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 119 | this.XosModelDefs.get() |
| 120 | .then((modelsDef: IXosModeldef[]) => { |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 121 | const pArray = []; |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 122 | |
| 123 | // Setting up counters for the status message |
| 124 | this.$interval.cancel(modelDefInerval); |
| 125 | const modelsTotal = modelsDef.length; |
| 126 | let modelsLoaded = 0; |
| 127 | this.setModelsCountMsg(modelsLoaded, modelsTotal); |
| 128 | |
| 129 | // Setting up counters for the loading bar |
| 130 | this.progressBar.set(10); |
| 131 | const progressBarStep = 90 / modelsTotal; |
| 132 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 133 | _.forEach(modelsDef, (model: IXosModeldef) => { |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 134 | this.$log.debug(`[XosModelDiscovererService] Loading: ${model.name}`); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 135 | let p = this.cacheModelEntries(model) |
| 136 | .then(model => { |
| 137 | return this.addState(model); |
| 138 | }) |
| 139 | .then(model => { |
| 140 | return this.addNavItem(model); |
| 141 | }) |
| 142 | .then(model => { |
| 143 | return this.getTableCfg(model); |
| 144 | }) |
| 145 | .then(model => { |
| 146 | return this.getFormCfg(model); |
| 147 | }) |
| 148 | .then(model => { |
| 149 | return this.storeModel(model); |
| 150 | }) |
| 151 | .then(model => { |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 152 | // Updating the status message |
| 153 | modelsLoaded = modelsLoaded + 1; |
| 154 | this.setModelsCountMsg(modelsLoaded, modelsTotal); |
| 155 | |
| 156 | // Updating the progress bar |
| 157 | this.progressBar.set(10 + (modelsLoaded * progressBarStep)); |
| 158 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 159 | this.$log.debug(`[XosModelDiscovererService] Model ${model.name} stored`); |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 160 | return this.$q.resolve('true'); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 161 | }) |
| 162 | .catch(err => { |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 163 | this.$log.warn(`[XosModelDiscovererService] Model ${model.name} NOT stored`, err); |
| 164 | const isAuthError = this.AuthService.isAuthError(err); |
| 165 | if (isAuthError) { |
| 166 | this.$log.warn(`[XosModelDiscovererService] User is not authentincated`); |
| 167 | return this.$q.reject(err); |
| 168 | } |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 169 | return this.$q.resolve('false'); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 170 | }); |
| 171 | pArray.push(p); |
| 172 | }); |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 173 | |
| 174 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 175 | this.$q.all(pArray) |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 176 | .then((res) => { |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 177 | // the ModelLoader promise won't ever be reject, in case it will be resolve with value false, |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 178 | // that's because we want to wait anyway for all the models to be loaded |
| 179 | if (res.indexOf('false') > -1) { |
Matteo Scandolo | 0222938 | 2017-04-18 11:52:23 -0700 | [diff] [blame] | 180 | return d.resolve(false); |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 181 | } |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 182 | d.resolve(true); |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 183 | this.modelsLoaded = true; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 184 | }) |
Matteo Scandolo | 0222938 | 2017-04-18 11:52:23 -0700 | [diff] [blame] | 185 | .catch((e) => { |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 186 | this.XosModelStore.clean(); // reset all the observable otherwise they'll store login errors |
| 187 | this.$log.warn(`[XosModelDiscovererService]`, e); |
| 188 | // the ModelLoader promise will be rejected in case of authentication error |
| 189 | d.reject(e); |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 190 | }) |
| 191 | .finally(() => { |
| 192 | this.progressBar.complete(); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 193 | }); |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 194 | }) |
| 195 | .catch(err => { |
| 196 | this.progressBar.complete(); |
| 197 | this.$log.error(`[XosModelDiscovererService] Cannot load model defs`, err); |
| 198 | return d.resolve('chameleon'); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 199 | }); |
| 200 | return d.promise; |
| 201 | } |
| 202 | |
Matteo Scandolo | bf4e840 | 2019-06-24 12:22:49 -0700 | [diff] [blame] | 203 | private setModelDefTimeMsg(seconds: number) { |
| 204 | this.statusMessage = `Loading models definition for ${seconds} seconds...`; |
| 205 | } |
| 206 | |
| 207 | private setModelsCountMsg(loaded: number, modelsTotal: number) { |
| 208 | const percent = Math.round((100 * loaded) / modelsTotal); |
| 209 | this.statusMessage = `Loading data.... ${percent}% completed (${loaded} of ${modelsTotal} models)`; |
| 210 | } |
| 211 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 212 | private stateNameFromModel(model: IXosModel): string { |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 213 | return `xos.${this.XosModeldefsCache.serviceNameFromAppName(model.app)}.${model.name.toLowerCase()}`; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | private getParentStateFromModel(model: IXosModel): string { |
| 217 | let parentState: string; |
| 218 | if (model.app === 'core') { |
| 219 | parentState = 'xos.core'; |
| 220 | } |
| 221 | else { |
| 222 | const serviceName = this.addService(model); |
| 223 | parentState = `xos.${serviceName}`; |
| 224 | } |
| 225 | return parentState; |
| 226 | } |
| 227 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 228 | // add a service state and navigation item if it is not already there |
| 229 | private addService(model: IXosModel): string { |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 230 | const serviceName: string = this.XosModeldefsCache.serviceNameFromAppName(model.app); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 231 | if (!_.find(this.xosServices, n => n === serviceName)) { |
| 232 | const serviceState = { |
| 233 | url: serviceName, |
| 234 | parent: 'xos', |
| 235 | abstract: true, |
| 236 | template: '<div ui-view></div>' |
| 237 | }; |
| 238 | this.XosRuntimeStates.addState(`xos.${serviceName}`, serviceState); |
| 239 | |
| 240 | this.XosNavigationService.add({ |
| 241 | label: this.ConfigHelpers.toLabel(serviceName), |
| 242 | state: `xos.${serviceName}`, |
| 243 | }); |
| 244 | this.xosServices.push(serviceName); |
| 245 | } |
| 246 | return serviceName; |
| 247 | } |
| 248 | |
| 249 | private addState(model: IXosModel): ng.IPromise<IXosModel> { |
| 250 | const d = this.$q.defer(); |
| 251 | const clientUrl = `/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}/:id?`; |
| 252 | const state: IXosState = { |
| 253 | parent: this.getParentStateFromModel(model), |
| 254 | url: clientUrl, |
| 255 | params: { |
| 256 | id: null |
| 257 | }, |
| 258 | data: { |
Matteo Scandolo | 5d962a3 | 2017-08-01 18:16:14 -0700 | [diff] [blame] | 259 | model: model.name, |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 260 | }, |
| 261 | component: 'xosCrud', |
| 262 | }; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 263 | |
Matteo Scandolo | 5d962a3 | 2017-08-01 18:16:14 -0700 | [diff] [blame] | 264 | if (angular.isDefined(model.relations)) { |
| 265 | state.data.relations = model.relations; |
| 266 | } |
| 267 | |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 268 | try { |
| 269 | this.XosRuntimeStates.addState( |
| 270 | this.stateNameFromModel(model), |
| 271 | state |
| 272 | ); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 273 | |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 274 | // extend model |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 275 | model.clientUrl = `${this.XosModeldefsCache.serviceNameFromAppName(model.app)}${clientUrl}`; |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 276 | |
| 277 | d.resolve(model); |
| 278 | } catch (e) { |
| 279 | d.reject(e); |
| 280 | } |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 281 | return d.promise; |
| 282 | } |
| 283 | |
| 284 | private addNavItem(model: IXosModel): ng.IPromise<IXosModel> { |
| 285 | const d = this.$q.defer(); |
| 286 | |
| 287 | const stateName = this.stateNameFromModel(model); |
| 288 | |
| 289 | const parentState: string = this.getParentStateFromModel(model); |
| 290 | |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 291 | try { |
Matteo Scandolo | 580033a | 2017-08-17 11:16:39 -0700 | [diff] [blame] | 292 | const name = model.verbose_name ? model.verbose_name : model.name; |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 293 | this.XosNavigationService.add({ |
Matteo Scandolo | 580033a | 2017-08-17 11:16:39 -0700 | [diff] [blame] | 294 | label: this.ConfigHelpers.pluralize(name), |
Matteo Scandolo | c80ccbd | 2017-02-27 16:24:33 -0800 | [diff] [blame] | 295 | state: stateName, |
| 296 | parent: parentState |
| 297 | }); |
| 298 | d.resolve(model); |
| 299 | } catch (e) { |
| 300 | d.reject(e); |
| 301 | } |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 302 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 303 | |
| 304 | return d.promise; |
| 305 | } |
| 306 | |
| 307 | private cacheModelEntries(model: IXosModel): ng.IPromise<IXosModel> { |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 308 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 309 | const d = this.$q.defer(); |
| 310 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 311 | const apiUrl = this.getApiUrlFromModel(model); |
| 312 | this.XosModelStore.query(model.name, apiUrl) |
Matteo Scandolo | 29edc0f | 2018-04-26 17:19:10 +0200 | [diff] [blame] | 313 | .skip(1) // NOTE observables returns as first an empty array, so skip it |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 314 | .subscribe( |
| 315 | () => { |
Matteo Scandolo | 38e94a8 | 2017-03-02 12:17:27 -0800 | [diff] [blame] | 316 | return d.resolve(model); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 317 | }, |
| 318 | err => { |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 319 | return d.reject(err); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 320 | } |
| 321 | ); |
| 322 | |
| 323 | return d.promise; |
| 324 | } |
| 325 | |
| 326 | private getTableCfg(model: IXosModel): ng.IPromise<IXosModel> { |
| 327 | |
| 328 | const d = this.$q.defer(); |
| 329 | |
| 330 | const stateUrl = this.stateNameFromModel(model); |
| 331 | |
| 332 | model.tableCfg = this.ConfigHelpers.modelToTableCfg(model, stateUrl); |
| 333 | |
| 334 | d.resolve(model); |
| 335 | |
| 336 | return d.promise; |
| 337 | } |
| 338 | |
| 339 | private getFormCfg(model: IXosModel): ng.IPromise<IXosModel> { |
| 340 | |
| 341 | const d = this.$q.defer(); |
| 342 | |
| 343 | model.formCfg = this.ConfigHelpers.modelToFormCfg(model); |
| 344 | |
| 345 | d.resolve(model); |
| 346 | |
| 347 | return d.promise; |
| 348 | } |
| 349 | |
| 350 | private storeModel(model: IXosModel): ng.IPromise<IXosModel> { |
| 351 | |
| 352 | const d = this.$q.defer(); |
| 353 | |
Matteo Scandolo | 6349847 | 2017-09-26 17:21:41 -0700 | [diff] [blame] | 354 | this.XosModeldefsCache.cache(model); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 355 | |
| 356 | d.resolve(model); |
| 357 | |
| 358 | return d.promise; |
| 359 | } |
| 360 | } |