blob: ae91b2acb7ecd593996105f7cdb365fc838ed8b1 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
Michael Landoed64b5e2017-06-09 03:19:04 +030021import {PropertyModel, Component, ArtifactModel, Distribution, InputModel, DisplayModule, InputPropertyBase} from "../models";
22import {IEmailModalModel} from "../view-models/modals/email-modal/email-modal-view-model";
23import {IClientMessageModalModel} from "../view-models/modals/message-modal/message-client-modal/client-message-modal-view-model";
24import {IServerMessageModalModel} from "../view-models/modals/message-modal/message-server-modal/server-message-modal-view-model";
25import {IConfirmationModalModel} from "../view-models/modals/confirmation-modal/confirmation-modal-view-model";
26import {ModalType} from "./constants";
27import {AttributeModel} from "../models/attributes";
28
29export interface IModalsHandler {
30
31
32 openDistributionStatusModal (distribution:Distribution, status:string, component:Component):ng.IPromise<any>;
33 openConfirmationModal (title:string, message:string, showComment:boolean, size?:string):ng.IPromise<any>;
34 openAlertModal (title:string, message:string, size?:string):ng.IPromise<any>;
35 openEmailModal(emailModel:IEmailModalModel):ng.IPromise<any>;
36 openServerMessageModal(data:IServerMessageModalModel):ng.IPromise<any>;
37 openClientMessageModal(data:IClientMessageModalModel):ng.IPromise<ng.ui.bootstrap.IModalServiceInstance>;
38 openArtifactModal(artifact:ArtifactModel, component:Component):ng.IPromise<any>;
39 openEditPropertyModal(property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, isPropertyOwnValue:boolean):ng.IPromise<any>;
40}
41
42export class ModalsHandler implements IModalsHandler {
43
44 static '$inject' = [
45 '$uibModal',
46 '$q'
47 ];
48
49 constructor(private $uibModal:ng.ui.bootstrap.IModalService,
50 private $q:ng.IQService) {
51 }
52
53
54
55
56 openDistributionStatusModal = (distribution:Distribution, status:string, component:Component):ng.IPromise<any> => {
57 let deferred = this.$q.defer();
58 let modalOptions:ng.ui.bootstrap.IModalSettings = {
59 templateUrl: '../view-models/workspace/tabs/distribution/disribution-status-modal/disribution-status-modal-view.html',
60 controller: 'Sdc.ViewModels.DistributionStatusModalViewModel',
61 size: 'sdc-xl',
62 backdrop: 'static',
63 resolve: {
64 data: ():any => {
65 return {
66 'distribution': distribution,
67 'status': status,
68 'component': component
69 };
70 }
71 }
72 };
73 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
74 deferred.resolve(modalInstance.result);
75 return deferred.promise;
76 };
77
78
79 openAlertModal = (title:string, message:string, size?:string):ng.IPromise<any> => {
80 return this.openConfirmationModalBase(title, message, false, ModalType.ALERT, size);
81 };
82
83 openConfirmationModal = (title:string, message:string, showComment:boolean, size?:string):ng.IPromise<any> => {
84 return this.openConfirmationModalBase(title, message, showComment, ModalType.STANDARD, size);
85 };
86
87 private openConfirmationModalBase = (title:string, message:string, showComment:boolean, type:ModalType, size?:string):ng.IPromise<any> => {
88 let deferred = this.$q.defer();
89 let modalOptions:ng.ui.bootstrap.IModalSettings = {
90 templateUrl: '../view-models/modals/confirmation-modal/confirmation-modal-view.html',
91 controller: 'Sdc.ViewModels.ConfirmationModalViewModel',
92 size: size ? size : 'sdc-sm',
93 backdrop: 'static',
94 resolve: {
95 confirmationModalModel: ():IConfirmationModalModel => {
96 let model:IConfirmationModalModel = {
97 title: title,
98 message: message,
99 showComment: showComment,
100 type: type
101 };
102 return model;
103 }
104 }
105 };
106
107 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
108 deferred.resolve(modalInstance.result);
109 return deferred.promise;
110 };
111
112 openEmailModal = (emailModel:IEmailModalModel):ng.IPromise<any> => {
113
114 let deferred = this.$q.defer();
115 let modalOptions:ng.ui.bootstrap.IModalSettings = {
116 templateUrl: '../view-models/modals/email-modal/email-modal-view.html',
117 controller: 'Sdc.ViewModels.EmailModalViewModel',
118 size: 'sdc-sm',
119 backdrop: 'static',
120 resolve: {
121 emailModalModel: ():IEmailModalModel => {
122 return emailModel;
123 }
124 }
125 };
126 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
127 deferred.resolve(modalInstance.result);
128 return deferred.promise;
129
130 };
131
132 openServerMessageModal = (data:IServerMessageModalModel):ng.IPromise<any> => {
133 let deferred = this.$q.defer();
134 let modalOptions:ng.ui.bootstrap.IModalSettings = {
135 templateUrl: '../view-models/modals/message-modal/message-server-modal/server-message-modal-view.html',
136 controller: 'Sdc.ViewModels.ServerMessageModalViewModel',
137 size: 'sdc-sm',
138 backdrop: 'static',
139 resolve: {
140 serverMessageModalModel: ():IServerMessageModalModel => {
141 return data;
142 }
143 }
144 };
145
146 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
147 deferred.resolve(modalInstance.result);
148 return deferred.promise;
149 };
150
151 openClientMessageModal = (data:IClientMessageModalModel):ng.IPromise<any> => {
152 let deferred = this.$q.defer();
153 let modalOptions:ng.ui.bootstrap.IModalSettings = {
154 templateUrl: '../view-models/modals/message-modal/message-client-modal/client-message-modal-view.html',
155 controller: 'Sdc.ViewModels.ClientMessageModalViewModel',
156 size: 'sdc-sm',
157 backdrop: 'static',
158 resolve: {
159 clientMessageModalModel: ():IClientMessageModalModel => {
160 return data;
161 }
162 }
163 };
164 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
165 deferred.resolve(modalInstance);
166 return deferred.promise;
167 };
168
169 openOnboadrdingModal = (okButtonText:string, currentCsarUUID?:string):ng.IPromise<any> => {
170 let deferred = this.$q.defer();
171 let modalOptions:ng.ui.bootstrap.IModalSettings = {
172 templateUrl: '../view-models/modals/onboarding-modal/onboarding-modal-view.html',
173 controller: 'Sdc.ViewModels.OnboardingModalViewModel',
174 size: 'sdc-xl',
175 backdrop: 'static',
176 resolve: {
177 okButtonText: ():string=> {
178 return okButtonText;
179 },
180 currentCsarUUID: ():string=> {
181 return currentCsarUUID || null;
182 }
183 }
184 };
185 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
186 deferred.resolve(modalInstance.result);
187 return deferred.promise;
188 };
189
190 openEditEnvParametersModal = (artifactResource:ArtifactModel, component?:Component):ng.IPromise<any> => {
191 let deferred = this.$q.defer();
192 let modalOptions:ng.ui.bootstrap.IModalSettings = {
193 templateUrl: '../view-models/forms/env-parameters-form/env-parameters-form.html',
194 controller: 'Sdc.ViewModels.EnvParametersFormViewModel',
195 size: 'sdc-xl',
196 backdrop: 'static',
197 resolve: {
198 artifact: ():ArtifactModel => {
199 return artifactResource;
200 },
201 component: ():Component => {
202 return component;
203 }
204 }
205 };
206 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
207 deferred.resolve(modalInstance.result);
208 return deferred.promise;
209 };
210
211 openEditInputValueModal = (input:InputModel):ng.IPromise<any> => {
212 let deferred = this.$q.defer();
213 let modalOptions:ng.ui.bootstrap.IModalSettings = {
214 templateUrl: '../view-models/forms/input-form/input-form-view.html',
215 controller: 'Sdc.ViewModels.InputFormViewModel',
216 size: 'sdc-md',
217 backdrop: 'static',
218 resolve: {
219 input: ():InputModel => {
220 return input;
221 }
222 }
223 };
224 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
225 deferred.resolve(modalInstance.result);
226 return deferred.promise;
227 };
228
229 openArtifactModal = (artifact:ArtifactModel, component:Component):ng.IPromise<any> => {
230 let deferred = this.$q.defer();
231
232 let modalOptions:ng.ui.bootstrap.IModalSettings = {
233 templateUrl: '../view-models/forms/artifact-form/artifact-form-view.html',
234 controller: 'Sdc.ViewModels.ArtifactResourceFormViewModel',
235 size: 'sdc-md',
236 backdrop: 'static',
237 keyboard: false,
238 resolve: {
239 artifact: ():ArtifactModel => {
240 return artifact;
241 },
242 component: ():Component => {
243 return component;
244 }
245 }
246 };
247
248 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
249 deferred.resolve(modalInstance.result);
250 return deferred.promise;
251 };
252
253
254 /**
255 *
256 * This function openes up the edit property modal
257 *
258 * @param property - the property to edit
259 * @param component - the component who is the owner of the property
260 * @param filteredProperties - the filtered properties list to scroll between in the edit modal
261 * @param isPropertyValueOwner - boolean telling if the component is eligible of editing the property
262 * @returns {IPromise<T>} - Promise telling if the modal has opened or not
263 */
264 openEditPropertyModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, isPropertyValueOwner:boolean):ng.IPromise<any> => {
265 let deferred = this.$q.defer();
266
267 let modalOptions:ng.ui.bootstrap.IModalSettings = {
268 templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html',
269 controller: 'Sdc.ViewModels.PropertyFormViewModel',
270 size: 'sdc-l',
271 backdrop: 'static',
272 keyboard: false,
273 resolve: {
274 property: ():PropertyModel => {
275 return property;
276 },
277 component: ():Component => {
278 return <Component> component;
279 },
280 filteredProperties: ():Array<PropertyModel> => {
281 return filteredProperties;
282 },
283 isPropertyValueOwner: ():boolean => {
284 return isPropertyValueOwner;
285 }
286 }
287 };
288
289 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
290 deferred.resolve(modalInstance.result);
291 return deferred.promise;
292 };
293
294
295 openEditModulePropertyModal = (property:PropertyModel, component:Component, selectedModule:DisplayModule):ng.IPromise<any> => {
296 let deferred = this.$q.defer();
297
298 let modalOptions:ng.ui.bootstrap.IModalSettings = {
299 templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html',
300 controller: 'Sdc.ViewModels.ModulePropertyView',
301 size: 'sdc-l',
302 backdrop: 'static',
303 keyboard: false,
304 resolve: {
305 originalProperty: ():PropertyModel => {
306 return property;
307 },
308 component: ():Component => {
309 return <Component> component;
310 },
311 selectedModule: ():DisplayModule => {
312 return selectedModule;
313 }
314 }
315 };
316
317 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
318 deferred.resolve(modalInstance.result);
319 return deferred.promise;
320 };
321
322 openSelectDataTypeModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, propertiesMap:Array<InputPropertyBase>):ng.IPromise<any> => {
323 let deferred = this.$q.defer();
324
325 let modalOptions:ng.ui.bootstrap.IModalSettings = {
326 templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html',
327 controller: 'Sdc.ViewModels.SelectDataTypeViewModel',
328 size: 'sdc-l',
329 backdrop: 'static',
330 keyboard: false,
331 resolve: {
332 originalProperty: ():PropertyModel => {
333 return property;
334 },
335 component: ():Component => {
336 return <Component> component;
337 },
338 filteredProperties: ():Array<PropertyModel> => {
339 return filteredProperties;
340 },
341 propertiesMap: ():Array<InputPropertyBase>=> {
342 return propertiesMap;
343 }
344 }
345 };
346
347 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
348 deferred.resolve(modalInstance.result);
349 return deferred.promise;
350 };
351
352 public openEditAttributeModal = (attribute:AttributeModel, component: Component):void => {
353
354 let modalOptions:ng.ui.bootstrap.IModalSettings = {
355 templateUrl: '../view-models/forms/attribute-form/attribute-form-view.html',
356 controller: 'Sdc.ViewModels.AttributeFormViewModel',
357 size: 'sdc-md',
358 backdrop: 'static',
359 keyboard: false,
360 resolve: {
361 attribute: ():AttributeModel => {
362 return attribute;
363 },
364 component: ():Component => {
365 return component;
366 }
367 }
368 };
369 this.$uibModal.open(modalOptions);
370 };
371
372 public openUpdateComponentInstanceNameModal = (currentComponent: Component):ng.IPromise<any> => {
373 let deferred = this.$q.defer();
374
375 let modalOptions:ng.ui.bootstrap.IModalSettings = {
376 templateUrl: '../view-models/forms/resource-instance-name-form/resource-instance-name-view.html',
377 controller: 'Sdc.ViewModels.ResourceInstanceNameViewModel',
378 size: 'sdc-sm',
379 backdrop: 'static',
380 resolve: {
381 component: ():Component => {
382 return currentComponent;
383 }
384 }
385 };
386
387 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
388 deferred.resolve(modalInstance.result);
389 return deferred.promise;
390 };
391
392 public openConformanceLevelModal = ():ng.IPromise<any> => {
393 let deferred = this.$q.defer();
394 let modalOptions:ng.ui.bootstrap.IModalSettings = {
Michael Landob3d48982017-06-11 14:22:02 +0300395 templateUrl: '../view-models/modals/conformance-level-modal/conformance-level-modal-view.html',
Michael Landoed64b5e2017-06-09 03:19:04 +0300396 controller: 'Sdc.ViewModels.ConformanceLevelModalViewModel',
397 size: 'sdc-sm',
398 backdrop: 'static',
399 resolve: {
400
401 }
402 };
403
404 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
405 deferred.resolve(modalInstance.result);
406 return deferred.promise;
407 };
408
409}