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