[SDC] rebase 1710 code
[sdc.git] / catalog-ui / src / app / utils / modals-handler.ts
1 /*-
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
21 import {PropertyModel, Component, ArtifactModel, Distribution, InputModel, DisplayModule, InputPropertyBase} from "../models";
22 import {IEmailModalModel} from "../view-models/modals/email-modal/email-modal-view-model";
23 import {IClientMessageModalModel} from "../view-models/modals/message-modal/message-client-modal/client-message-modal-view-model";
24 import {IServerMessageModalModel} from "../view-models/modals/message-modal/message-server-modal/server-message-modal-view-model";
25 import {IConfirmationModalModel} from "../view-models/modals/confirmation-modal/confirmation-modal-view-model";
26 import {ModalType} from "./constants";
27 import {AttributeModel} from "../models/attributes";
28
29 export 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
42 export 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     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
208     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
313     openEditModulePropertyModal = (property:PropertyModel, component:Component, selectedModule:DisplayModule):ng.IPromise<any> => {
314         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;
331                 }
332             }
333         };
334
335         let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
336         deferred.resolve(modalInstance.result);
337         return deferred.promise;
338     };
339
340     openSelectDataTypeModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, propertiesMap:Array<InputPropertyBase>):ng.IPromise<any> => {
341         let deferred = this.$q.defer();
342
343         let modalOptions:ng.ui.bootstrap.IModalSettings = {
344             templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html',
345             controller: 'Sdc.ViewModels.SelectDataTypeViewModel',
346             size: 'sdc-l',
347             backdrop: 'static',
348             keyboard: false,
349             resolve: {
350                 originalProperty: ():PropertyModel => {
351                     return property;
352                 },
353                 component: ():Component => {
354                     return <Component> component;
355                 },
356                 filteredProperties: ():Array<PropertyModel> => {
357                     return filteredProperties;
358                 },
359                 propertiesMap: ():Array<InputPropertyBase>=> {
360                     return propertiesMap;
361                 }
362             }
363         };
364
365         let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
366         deferred.resolve(modalInstance.result);
367         return deferred.promise;
368     };
369
370     public openEditAttributeModal = (attribute:AttributeModel, component: Component):void => {
371
372         let modalOptions:ng.ui.bootstrap.IModalSettings = {
373             templateUrl: '../view-models/forms/attribute-form/attribute-form-view.html',
374             controller: 'Sdc.ViewModels.AttributeFormViewModel',
375             size: 'sdc-md',
376             backdrop: 'static',
377             keyboard: false,
378             resolve: {
379                 attribute: ():AttributeModel => {
380                     return attribute;
381                 },
382                 component: ():Component => {
383                     return component;
384                 }
385             }
386         };
387         this.$uibModal.open(modalOptions);
388     };
389
390     public openUpdateComponentInstanceNameModal = (currentComponent: Component):ng.IPromise<any> => {
391         let deferred = this.$q.defer();
392
393         let modalOptions:ng.ui.bootstrap.IModalSettings = {
394             templateUrl: '../view-models/forms/resource-instance-name-form/resource-instance-name-view.html',
395             controller: 'Sdc.ViewModels.ResourceInstanceNameViewModel',
396             size: 'sdc-sm',
397             backdrop: 'static',
398             resolve: {
399                 component: ():Component => {
400                     return currentComponent;
401                 }
402             }
403         };
404
405         let modalInstance:ng.ui.bootstrap.IModalServiceInstance =  this.$uibModal.open(modalOptions);
406         deferred.resolve(modalInstance.result);
407         return deferred.promise;
408     };
409
410     public openConformanceLevelModal = ():ng.IPromise<any> => {
411         let deferred = this.$q.defer();
412         let modalOptions:ng.ui.bootstrap.IModalSettings = {
413             templateUrl: '../view-models/modals/conformance-level-modal/conformance-level-modal-view.html',
414             controller: 'Sdc.ViewModels.ConformanceLevelModalViewModel',
415             size: 'sdc-sm',
416             backdrop: 'static',
417             resolve: {
418
419             }
420         };
421
422         let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
423         deferred.resolve(modalInstance.result);
424         return deferred.promise;
425     };
426
427 }