blob: 48ce487f9d929b5ec65c5d4cd8fe1d63eabc8749 [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
Michael Lando75aacbb2017-07-17 21:12:03 +0300190 openUpdateIconModal = (component: Component):ng.IPromise<any> => {
191 let deferred = this.$q.defer();
192 let modalOptions:ng.ui.bootstrap.IModalSettings = {
193 templateUrl: '../view-models/modals/icons-modal/icons-modal-view.html',
194 controller: 'Sdc.ViewModels.IconsModalViewModel',
195 size: 'sdc-auto',
196 backdrop: 'static',
197 resolve: {
198 component: ():Component => {
199 return component;
200 }
201 }
202 };
203 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
204 deferred.resolve(modalInstance.result);
205 return deferred.promise;
206 };
207
Michael Landoed64b5e2017-06-09 03:19:04 +0300208 openEditEnvParametersModal = (artifactResource:ArtifactModel, component?:Component):ng.IPromise<any> => {
209 let deferred = this.$q.defer();
210 let modalOptions:ng.ui.bootstrap.IModalSettings = {
211 templateUrl: '../view-models/forms/env-parameters-form/env-parameters-form.html',
212 controller: 'Sdc.ViewModels.EnvParametersFormViewModel',
213 size: 'sdc-xl',
214 backdrop: 'static',
215 resolve: {
216 artifact: ():ArtifactModel => {
217 return artifactResource;
218 },
219 component: ():Component => {
220 return component;
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 openEditInputValueModal = (input:InputModel):ng.IPromise<any> => {
230 let deferred = this.$q.defer();
231 let modalOptions:ng.ui.bootstrap.IModalSettings = {
232 templateUrl: '../view-models/forms/input-form/input-form-view.html',
233 controller: 'Sdc.ViewModels.InputFormViewModel',
234 size: 'sdc-md',
235 backdrop: 'static',
236 resolve: {
237 input: ():InputModel => {
238 return input;
239 }
240 }
241 };
242 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
243 deferred.resolve(modalInstance.result);
244 return deferred.promise;
245 };
246
247 openArtifactModal = (artifact:ArtifactModel, component:Component):ng.IPromise<any> => {
248 let deferred = this.$q.defer();
249
250 let modalOptions:ng.ui.bootstrap.IModalSettings = {
251 templateUrl: '../view-models/forms/artifact-form/artifact-form-view.html',
252 controller: 'Sdc.ViewModels.ArtifactResourceFormViewModel',
253 size: 'sdc-md',
254 backdrop: 'static',
255 keyboard: false,
256 resolve: {
257 artifact: ():ArtifactModel => {
258 return artifact;
259 },
260 component: ():Component => {
261 return component;
262 }
263 }
264 };
265
266 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
267 deferred.resolve(modalInstance.result);
268 return deferred.promise;
269 };
270
271
272 /**
273 *
274 * This function openes up the edit property modal
275 *
276 * @param property - the property to edit
277 * @param component - the component who is the owner of the property
278 * @param filteredProperties - the filtered properties list to scroll between in the edit modal
279 * @param isPropertyValueOwner - boolean telling if the component is eligible of editing the property
280 * @returns {IPromise<T>} - Promise telling if the modal has opened or not
281 */
282 openEditPropertyModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, isPropertyValueOwner:boolean):ng.IPromise<any> => {
283 let deferred = this.$q.defer();
284
285 let modalOptions:ng.ui.bootstrap.IModalSettings = {
286 templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html',
287 controller: 'Sdc.ViewModels.PropertyFormViewModel',
288 size: 'sdc-l',
289 backdrop: 'static',
290 keyboard: false,
291 resolve: {
292 property: ():PropertyModel => {
293 return property;
294 },
295 component: ():Component => {
296 return <Component> component;
297 },
298 filteredProperties: ():Array<PropertyModel> => {
299 return filteredProperties;
300 },
301 isPropertyValueOwner: ():boolean => {
302 return isPropertyValueOwner;
303 }
304 }
305 };
306
307 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
308 deferred.resolve(modalInstance.result);
309 return deferred.promise;
310 };
311
312
Michael Landoa5445102018-03-04 14:53:33 +0200313 openEditModulePropertyModal = (property:PropertyModel, component:Component, selectedModule:DisplayModule, filteredProperties:Array<PropertyModel>):ng.IPromise<any> => {
Michael Landoed64b5e2017-06-09 03:19:04 +0300314 let deferred = this.$q.defer();
315
316 let modalOptions:ng.ui.bootstrap.IModalSettings = {
317 templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html',
318 controller: 'Sdc.ViewModels.ModulePropertyView',
319 size: 'sdc-l',
320 backdrop: 'static',
321 keyboard: false,
322 resolve: {
323 originalProperty: ():PropertyModel => {
324 return property;
325 },
326 component: ():Component => {
327 return <Component> component;
328 },
329 selectedModule: ():DisplayModule => {
330 return selectedModule;
Michael Landoa5445102018-03-04 14:53:33 +0200331 },
332 filteredProperties: ():Array<PropertyModel> => {
333 return filteredProperties;
Michael Landoed64b5e2017-06-09 03:19:04 +0300334 }
335 }
336 };
337
338 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
339 deferred.resolve(modalInstance.result);
340 return deferred.promise;
341 };
342
343 openSelectDataTypeModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, propertiesMap:Array<InputPropertyBase>):ng.IPromise<any> => {
344 let deferred = this.$q.defer();
345
346 let modalOptions:ng.ui.bootstrap.IModalSettings = {
347 templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html',
348 controller: 'Sdc.ViewModels.SelectDataTypeViewModel',
349 size: 'sdc-l',
350 backdrop: 'static',
351 keyboard: false,
352 resolve: {
353 originalProperty: ():PropertyModel => {
354 return property;
355 },
356 component: ():Component => {
357 return <Component> component;
358 },
359 filteredProperties: ():Array<PropertyModel> => {
360 return filteredProperties;
361 },
362 propertiesMap: ():Array<InputPropertyBase>=> {
363 return propertiesMap;
364 }
365 }
366 };
367
368 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
369 deferred.resolve(modalInstance.result);
370 return deferred.promise;
371 };
372
373 public openEditAttributeModal = (attribute:AttributeModel, component: Component):void => {
374
375 let modalOptions:ng.ui.bootstrap.IModalSettings = {
376 templateUrl: '../view-models/forms/attribute-form/attribute-form-view.html',
377 controller: 'Sdc.ViewModels.AttributeFormViewModel',
378 size: 'sdc-md',
379 backdrop: 'static',
380 keyboard: false,
381 resolve: {
382 attribute: ():AttributeModel => {
383 return attribute;
384 },
385 component: ():Component => {
386 return component;
387 }
388 }
389 };
390 this.$uibModal.open(modalOptions);
391 };
392
393 public openUpdateComponentInstanceNameModal = (currentComponent: Component):ng.IPromise<any> => {
394 let deferred = this.$q.defer();
395
396 let modalOptions:ng.ui.bootstrap.IModalSettings = {
397 templateUrl: '../view-models/forms/resource-instance-name-form/resource-instance-name-view.html',
398 controller: 'Sdc.ViewModels.ResourceInstanceNameViewModel',
399 size: 'sdc-sm',
400 backdrop: 'static',
401 resolve: {
402 component: ():Component => {
403 return currentComponent;
404 }
405 }
406 };
407
408 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
409 deferred.resolve(modalInstance.result);
410 return deferred.promise;
411 };
412
413 public openConformanceLevelModal = ():ng.IPromise<any> => {
414 let deferred = this.$q.defer();
415 let modalOptions:ng.ui.bootstrap.IModalSettings = {
Michael Landob3d48982017-06-11 14:22:02 +0300416 templateUrl: '../view-models/modals/conformance-level-modal/conformance-level-modal-view.html',
Michael Landoed64b5e2017-06-09 03:19:04 +0300417 controller: 'Sdc.ViewModels.ConformanceLevelModalViewModel',
418 size: 'sdc-sm',
419 backdrop: 'static',
420 resolve: {
421
422 }
423 };
424
425 let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
426 deferred.resolve(modalInstance.result);
427 return deferred.promise;
428 };
429
430}