blob: 001d35d3862317a8799cfce6dfc176635cfa812d [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>;
Michael Lando5b593492018-07-29 16:13:45 +030039 openEditPropertyModal(property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, isPropertyOwnValue:boolean, propertyOwnerType:string, propertyOwnerId:string):ng.IPromise<any>;
Michael Landoed64b5e2017-06-09 03:19:04 +030040}
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
Michael Lando5b593492018-07-29 16:13:45 +0300169 openOnboadrdingModal = (okButtonText:string, currentCsarUUID?:string, currentCsarVersion?:string):ng.IPromise<any> => {
Michael Landoed64b5e2017-06-09 03:19:04 +0300170 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;
Michael Lando5b593492018-07-29 16:13:45 +0300182 },
183 currentCsarVersion: ():string=> {
184 return currentCsarVersion || null;
Michael Landoed64b5e2017-06-09 03:19:04 +0300185 }
186 }
187 };
188 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
189 deferred.resolve(modalInstance.result);
190 return deferred.promise;
191 };
192
Michael Lando75aacbb2017-07-17 21:12:03 +0300193 openUpdateIconModal = (component: Component):ng.IPromise<any> => {
194 let deferred = this.$q.defer();
195 let modalOptions:ng.ui.bootstrap.IModalSettings = {
196 templateUrl: '../view-models/modals/icons-modal/icons-modal-view.html',
197 controller: 'Sdc.ViewModels.IconsModalViewModel',
198 size: 'sdc-auto',
199 backdrop: 'static',
200 resolve: {
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
Michael Landoed64b5e2017-06-09 03:19:04 +0300211 openEditEnvParametersModal = (artifactResource:ArtifactModel, component?:Component):ng.IPromise<any> => {
212 let deferred = this.$q.defer();
213 let modalOptions:ng.ui.bootstrap.IModalSettings = {
214 templateUrl: '../view-models/forms/env-parameters-form/env-parameters-form.html',
215 controller: 'Sdc.ViewModels.EnvParametersFormViewModel',
216 size: 'sdc-xl',
217 backdrop: 'static',
218 resolve: {
219 artifact: ():ArtifactModel => {
220 return artifactResource;
221 },
222 component: ():Component => {
223 return component;
224 }
225 }
226 };
227 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
228 deferred.resolve(modalInstance.result);
229 return deferred.promise;
230 };
231
232 openEditInputValueModal = (input:InputModel):ng.IPromise<any> => {
233 let deferred = this.$q.defer();
234 let modalOptions:ng.ui.bootstrap.IModalSettings = {
235 templateUrl: '../view-models/forms/input-form/input-form-view.html',
236 controller: 'Sdc.ViewModels.InputFormViewModel',
237 size: 'sdc-md',
238 backdrop: 'static',
239 resolve: {
240 input: ():InputModel => {
241 return input;
242 }
243 }
244 };
245 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
246 deferred.resolve(modalInstance.result);
247 return deferred.promise;
248 };
249
250 openArtifactModal = (artifact:ArtifactModel, component:Component):ng.IPromise<any> => {
251 let deferred = this.$q.defer();
252
253 let modalOptions:ng.ui.bootstrap.IModalSettings = {
254 templateUrl: '../view-models/forms/artifact-form/artifact-form-view.html',
255 controller: 'Sdc.ViewModels.ArtifactResourceFormViewModel',
256 size: 'sdc-md',
257 backdrop: 'static',
258 keyboard: false,
259 resolve: {
260 artifact: ():ArtifactModel => {
261 return artifact;
262 },
263 component: ():Component => {
264 return component;
265 }
266 }
267 };
268
269 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
270 deferred.resolve(modalInstance.result);
271 return deferred.promise;
272 };
273
274
275 /**
276 *
277 * This function openes up the edit property modal
278 *
279 * @param property - the property to edit
280 * @param component - the component who is the owner of the property
281 * @param filteredProperties - the filtered properties list to scroll between in the edit modal
282 * @param isPropertyValueOwner - boolean telling if the component is eligible of editing the property
283 * @returns {IPromise<T>} - Promise telling if the modal has opened or not
284 */
Michael Lando5b593492018-07-29 16:13:45 +0300285 openEditPropertyModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, isPropertyValueOwner:boolean, propertyOwnerType:string, propertyOwnerId:string):ng.IPromise<any> => {
Michael Landoed64b5e2017-06-09 03:19:04 +0300286 let deferred = this.$q.defer();
287
288 let modalOptions:ng.ui.bootstrap.IModalSettings = {
289 templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html',
290 controller: 'Sdc.ViewModels.PropertyFormViewModel',
291 size: 'sdc-l',
292 backdrop: 'static',
293 keyboard: false,
294 resolve: {
295 property: ():PropertyModel => {
296 return property;
297 },
298 component: ():Component => {
299 return <Component> component;
300 },
301 filteredProperties: ():Array<PropertyModel> => {
302 return filteredProperties;
303 },
304 isPropertyValueOwner: ():boolean => {
305 return isPropertyValueOwner;
Michael Lando5b593492018-07-29 16:13:45 +0300306 },
307 propertyOwnerType: ():string => {
308 return propertyOwnerType;
309 },
310 propertyOwnerId: ():string => {
311 return propertyOwnerId;
Michael Landoed64b5e2017-06-09 03:19:04 +0300312 }
313 }
314 };
315
316 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
317 deferred.resolve(modalInstance.result);
318 return deferred.promise;
319 };
320
321
Michael Landoa5445102018-03-04 14:53:33 +0200322 openEditModulePropertyModal = (property:PropertyModel, component:Component, selectedModule:DisplayModule, filteredProperties:Array<PropertyModel>):ng.IPromise<any> => {
Michael Landoed64b5e2017-06-09 03:19:04 +0300323 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.ModulePropertyView',
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 selectedModule: ():DisplayModule => {
339 return selectedModule;
Michael Landoa5445102018-03-04 14:53:33 +0200340 },
341 filteredProperties: ():Array<PropertyModel> => {
342 return filteredProperties;
Michael Landoed64b5e2017-06-09 03:19:04 +0300343 }
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 openSelectDataTypeModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, propertiesMap:Array<InputPropertyBase>):ng.IPromise<any> => {
353 let deferred = this.$q.defer();
354
355 let modalOptions:ng.ui.bootstrap.IModalSettings = {
356 templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html',
357 controller: 'Sdc.ViewModels.SelectDataTypeViewModel',
358 size: 'sdc-l',
359 backdrop: 'static',
360 keyboard: false,
361 resolve: {
362 originalProperty: ():PropertyModel => {
363 return property;
364 },
365 component: ():Component => {
366 return <Component> component;
367 },
368 filteredProperties: ():Array<PropertyModel> => {
369 return filteredProperties;
370 },
371 propertiesMap: ():Array<InputPropertyBase>=> {
372 return propertiesMap;
373 }
374 }
375 };
376
377 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
378 deferred.resolve(modalInstance.result);
379 return deferred.promise;
380 };
381
382 public openEditAttributeModal = (attribute:AttributeModel, component: Component):void => {
383
384 let modalOptions:ng.ui.bootstrap.IModalSettings = {
385 templateUrl: '../view-models/forms/attribute-form/attribute-form-view.html',
386 controller: 'Sdc.ViewModels.AttributeFormViewModel',
387 size: 'sdc-md',
388 backdrop: 'static',
389 keyboard: false,
390 resolve: {
391 attribute: ():AttributeModel => {
392 return attribute;
393 },
394 component: ():Component => {
395 return component;
396 }
397 }
398 };
399 this.$uibModal.open(modalOptions);
400 };
401
402 public openUpdateComponentInstanceNameModal = (currentComponent: Component):ng.IPromise<any> => {
403 let deferred = this.$q.defer();
404
405 let modalOptions:ng.ui.bootstrap.IModalSettings = {
406 templateUrl: '../view-models/forms/resource-instance-name-form/resource-instance-name-view.html',
407 controller: 'Sdc.ViewModels.ResourceInstanceNameViewModel',
408 size: 'sdc-sm',
409 backdrop: 'static',
410 resolve: {
411 component: ():Component => {
412 return currentComponent;
413 }
414 }
415 };
416
417 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
418 deferred.resolve(modalInstance.result);
419 return deferred.promise;
420 };
421
422 public openConformanceLevelModal = ():ng.IPromise<any> => {
423 let deferred = this.$q.defer();
424 let modalOptions:ng.ui.bootstrap.IModalSettings = {
Michael Landob3d48982017-06-11 14:22:02 +0300425 templateUrl: '../view-models/modals/conformance-level-modal/conformance-level-modal-view.html',
Michael Landoed64b5e2017-06-09 03:19:04 +0300426 controller: 'Sdc.ViewModels.ConformanceLevelModalViewModel',
427 size: 'sdc-sm',
428 backdrop: 'static',
429 resolve: {
430
431 }
432 };
433
434 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
435 deferred.resolve(modalInstance.result);
436 return deferred.promise;
437 };
438
439}