Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 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 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 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>; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 39 | openEditPropertyModal(property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, isPropertyOwnValue:boolean, propertyOwnerType:string, propertyOwnerId:string):ng.IPromise<any>; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 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 | |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 169 | openOnboadrdingModal = (okButtonText:string, currentCsarUUID?:string, currentCsarVersion?:string):ng.IPromise<any> => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 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; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 182 | }, |
| 183 | currentCsarVersion: ():string=> { |
| 184 | return currentCsarVersion || null; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 185 | } |
| 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 Lando | 75aacbb | 2017-07-17 21:12:03 +0300 | [diff] [blame] | 193 | 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 Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 211 | 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(); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 252 | let modalOptions:ng.ui.bootstrap.IModalSettings = { |
| 253 | templateUrl: '../view-models/forms/artifact-form/artifact-form-view.html', |
| 254 | controller: 'Sdc.ViewModels.ArtifactResourceFormViewModel', |
| 255 | size: 'sdc-md', |
| 256 | backdrop: 'static', |
| 257 | keyboard: false, |
| 258 | resolve: { |
| 259 | artifact: ():ArtifactModel => { |
| 260 | return artifact; |
| 261 | }, |
| 262 | component: ():Component => { |
| 263 | return component; |
| 264 | } |
| 265 | } |
| 266 | }; |
| 267 | |
| 268 | let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
| 269 | deferred.resolve(modalInstance.result); |
| 270 | return deferred.promise; |
| 271 | }; |
| 272 | |
| 273 | |
| 274 | /** |
| 275 | * |
| 276 | * This function openes up the edit property modal |
| 277 | * |
| 278 | * @param property - the property to edit |
| 279 | * @param component - the component who is the owner of the property |
| 280 | * @param filteredProperties - the filtered properties list to scroll between in the edit modal |
| 281 | * @param isPropertyValueOwner - boolean telling if the component is eligible of editing the property |
| 282 | * @returns {IPromise<T>} - Promise telling if the modal has opened or not |
| 283 | */ |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 284 | openEditPropertyModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, isPropertyValueOwner:boolean, propertyOwnerType:string, propertyOwnerId:string):ng.IPromise<any> => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 285 | let deferred = this.$q.defer(); |
| 286 | |
| 287 | let modalOptions:ng.ui.bootstrap.IModalSettings = { |
| 288 | templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html', |
| 289 | controller: 'Sdc.ViewModels.PropertyFormViewModel', |
| 290 | size: 'sdc-l', |
| 291 | backdrop: 'static', |
| 292 | keyboard: false, |
| 293 | resolve: { |
| 294 | property: ():PropertyModel => { |
| 295 | return property; |
| 296 | }, |
| 297 | component: ():Component => { |
| 298 | return <Component> component; |
| 299 | }, |
| 300 | filteredProperties: ():Array<PropertyModel> => { |
| 301 | return filteredProperties; |
| 302 | }, |
| 303 | isPropertyValueOwner: ():boolean => { |
| 304 | return isPropertyValueOwner; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 305 | }, |
| 306 | propertyOwnerType: ():string => { |
| 307 | return propertyOwnerType; |
| 308 | }, |
| 309 | propertyOwnerId: ():string => { |
| 310 | return propertyOwnerId; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | }; |
| 314 | |
| 315 | let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
| 316 | deferred.resolve(modalInstance.result); |
| 317 | return deferred.promise; |
| 318 | }; |
| 319 | |
| 320 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 321 | openEditModulePropertyModal = (property:PropertyModel, component:Component, selectedModule:DisplayModule, filteredProperties:Array<PropertyModel>):ng.IPromise<any> => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 322 | let deferred = this.$q.defer(); |
| 323 | |
| 324 | let modalOptions:ng.ui.bootstrap.IModalSettings = { |
| 325 | templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html', |
| 326 | controller: 'Sdc.ViewModels.ModulePropertyView', |
| 327 | size: 'sdc-l', |
| 328 | backdrop: 'static', |
| 329 | keyboard: false, |
| 330 | resolve: { |
| 331 | originalProperty: ():PropertyModel => { |
| 332 | return property; |
| 333 | }, |
| 334 | component: ():Component => { |
| 335 | return <Component> component; |
| 336 | }, |
| 337 | selectedModule: ():DisplayModule => { |
| 338 | return selectedModule; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 339 | }, |
| 340 | filteredProperties: ():Array<PropertyModel> => { |
| 341 | return filteredProperties; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | }; |
| 345 | |
| 346 | let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
| 347 | deferred.resolve(modalInstance.result); |
| 348 | return deferred.promise; |
| 349 | }; |
| 350 | |
| 351 | openSelectDataTypeModal = (property:PropertyModel, component:Component, filteredProperties:Array<PropertyModel>, propertiesMap:Array<InputPropertyBase>):ng.IPromise<any> => { |
| 352 | let deferred = this.$q.defer(); |
| 353 | |
| 354 | let modalOptions:ng.ui.bootstrap.IModalSettings = { |
| 355 | templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html', |
| 356 | controller: 'Sdc.ViewModels.SelectDataTypeViewModel', |
| 357 | size: 'sdc-l', |
| 358 | backdrop: 'static', |
| 359 | keyboard: false, |
| 360 | resolve: { |
| 361 | originalProperty: ():PropertyModel => { |
| 362 | return property; |
| 363 | }, |
| 364 | component: ():Component => { |
| 365 | return <Component> component; |
| 366 | }, |
| 367 | filteredProperties: ():Array<PropertyModel> => { |
| 368 | return filteredProperties; |
| 369 | }, |
| 370 | propertiesMap: ():Array<InputPropertyBase>=> { |
| 371 | return propertiesMap; |
| 372 | } |
| 373 | } |
| 374 | }; |
| 375 | |
| 376 | let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
| 377 | deferred.resolve(modalInstance.result); |
| 378 | return deferred.promise; |
| 379 | }; |
| 380 | |
| 381 | public openEditAttributeModal = (attribute:AttributeModel, component: Component):void => { |
| 382 | |
| 383 | let modalOptions:ng.ui.bootstrap.IModalSettings = { |
| 384 | templateUrl: '../view-models/forms/attribute-form/attribute-form-view.html', |
| 385 | controller: 'Sdc.ViewModels.AttributeFormViewModel', |
| 386 | size: 'sdc-md', |
| 387 | backdrop: 'static', |
| 388 | keyboard: false, |
| 389 | resolve: { |
| 390 | attribute: ():AttributeModel => { |
| 391 | return attribute; |
| 392 | }, |
| 393 | component: ():Component => { |
| 394 | return component; |
| 395 | } |
| 396 | } |
| 397 | }; |
| 398 | this.$uibModal.open(modalOptions); |
| 399 | }; |
| 400 | |
| 401 | public openUpdateComponentInstanceNameModal = (currentComponent: Component):ng.IPromise<any> => { |
| 402 | let deferred = this.$q.defer(); |
| 403 | |
| 404 | let modalOptions:ng.ui.bootstrap.IModalSettings = { |
| 405 | templateUrl: '../view-models/forms/resource-instance-name-form/resource-instance-name-view.html', |
| 406 | controller: 'Sdc.ViewModels.ResourceInstanceNameViewModel', |
| 407 | size: 'sdc-sm', |
| 408 | backdrop: 'static', |
| 409 | resolve: { |
| 410 | component: ():Component => { |
| 411 | return currentComponent; |
| 412 | } |
| 413 | } |
| 414 | }; |
| 415 | |
| 416 | let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
| 417 | deferred.resolve(modalInstance.result); |
| 418 | return deferred.promise; |
| 419 | }; |
| 420 | |
| 421 | public openConformanceLevelModal = ():ng.IPromise<any> => { |
| 422 | let deferred = this.$q.defer(); |
| 423 | let modalOptions:ng.ui.bootstrap.IModalSettings = { |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 424 | templateUrl: '../view-models/modals/conformance-level-modal/conformance-level-modal-view.html', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 425 | controller: 'Sdc.ViewModels.ConformanceLevelModalViewModel', |
| 426 | size: 'sdc-sm', |
| 427 | backdrop: 'static', |
| 428 | resolve: { |
| 429 | |
| 430 | } |
| 431 | }; |
| 432 | |
| 433 | let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
| 434 | deferred.resolve(modalInstance.result); |
| 435 | return deferred.promise; |
| 436 | }; |
| 437 | |
| 438 | } |