import {PropertyModel, Component, ArtifactModel, Distribution, InputModel, DisplayModule, InputPropertyBase} from "../models"; import {IEmailModalModel} from "../view-models/modals/email-modal/email-modal-view-model"; import {IClientMessageModalModel} from "../view-models/modals/message-modal/message-client-modal/client-message-modal-view-model"; import {IServerMessageModalModel} from "../view-models/modals/message-modal/message-server-modal/server-message-modal-view-model"; import {IConfirmationModalModel} from "../view-models/modals/confirmation-modal/confirmation-modal-view-model"; import {ModalType} from "./constants"; import {AttributeModel} from "../models/attributes"; export interface IModalsHandler { openDistributionStatusModal (distribution:Distribution, status:string, component:Component):ng.IPromise; openConfirmationModal (title:string, message:string, showComment:boolean, size?:string):ng.IPromise; openAlertModal (title:string, message:string, size?:string):ng.IPromise; openEmailModal(emailModel:IEmailModalModel):ng.IPromise; openServerMessageModal(data:IServerMessageModalModel):ng.IPromise; openClientMessageModal(data:IClientMessageModalModel):ng.IPromise; openArtifactModal(artifact:ArtifactModel, component:Component):ng.IPromise; openEditPropertyModal(property:PropertyModel, component:Component, filteredProperties:Array, isPropertyOwnValue:boolean):ng.IPromise; } export class ModalsHandler implements IModalsHandler { static '$inject' = [ '$uibModal', '$q' ]; constructor(private $uibModal:ng.ui.bootstrap.IModalService, private $q:ng.IQService) { } openDistributionStatusModal = (distribution:Distribution, status:string, component:Component):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/workspace/tabs/distribution/disribution-status-modal/disribution-status-modal-view.html', controller: 'Sdc.ViewModels.DistributionStatusModalViewModel', size: 'sdc-xl', backdrop: 'static', resolve: { data: ():any => { return { 'distribution': distribution, 'status': status, 'component': component }; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openAlertModal = (title:string, message:string, size?:string):ng.IPromise => { return this.openConfirmationModalBase(title, message, false, ModalType.ALERT, size); }; openConfirmationModal = (title:string, message:string, showComment:boolean, size?:string):ng.IPromise => { return this.openConfirmationModalBase(title, message, showComment, ModalType.STANDARD, size); }; private openConfirmationModalBase = (title:string, message:string, showComment:boolean, type:ModalType, size?:string):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/modals/confirmation-modal/confirmation-modal-view.html', controller: 'Sdc.ViewModels.ConfirmationModalViewModel', size: size ? size : 'sdc-sm', backdrop: 'static', resolve: { confirmationModalModel: ():IConfirmationModalModel => { let model:IConfirmationModalModel = { title: title, message: message, showComment: showComment, type: type }; return model; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openEmailModal = (emailModel:IEmailModalModel):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/modals/email-modal/email-modal-view.html', controller: 'Sdc.ViewModels.EmailModalViewModel', size: 'sdc-sm', backdrop: 'static', resolve: { emailModalModel: ():IEmailModalModel => { return emailModel; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openServerMessageModal = (data:IServerMessageModalModel):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/modals/message-modal/message-server-modal/server-message-modal-view.html', controller: 'Sdc.ViewModels.ServerMessageModalViewModel', size: 'sdc-sm', backdrop: 'static', resolve: { serverMessageModalModel: ():IServerMessageModalModel => { return data; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openClientMessageModal = (data:IClientMessageModalModel):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/modals/message-modal/message-client-modal/client-message-modal-view.html', controller: 'Sdc.ViewModels.ClientMessageModalViewModel', size: 'sdc-sm', backdrop: 'static', resolve: { clientMessageModalModel: ():IClientMessageModalModel => { return data; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance); return deferred.promise; }; openOnboadrdingModal = (okButtonText:string, currentCsarUUID?:string):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/modals/onboarding-modal/onboarding-modal-view.html', controller: 'Sdc.ViewModels.OnboardingModalViewModel', size: 'sdc-xl', backdrop: 'static', resolve: { okButtonText: ():string=> { return okButtonText; }, currentCsarUUID: ():string=> { return currentCsarUUID || null; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openEditEnvParametersModal = (artifactResource:ArtifactModel, component?:Component):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/forms/env-parameters-form/env-parameters-form.html', controller: 'Sdc.ViewModels.EnvParametersFormViewModel', size: 'sdc-xl', backdrop: 'static', resolve: { artifact: ():ArtifactModel => { return artifactResource; }, component: ():Component => { return component; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openEditInputValueModal = (input:InputModel):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/forms/input-form/input-form-view.html', controller: 'Sdc.ViewModels.InputFormViewModel', size: 'sdc-md', backdrop: 'static', resolve: { input: ():InputModel => { return input; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openArtifactModal = (artifact:ArtifactModel, component:Component):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/forms/artifact-form/artifact-form-view.html', controller: 'Sdc.ViewModels.ArtifactResourceFormViewModel', size: 'sdc-md', backdrop: 'static', keyboard: false, resolve: { artifact: ():ArtifactModel => { return artifact; }, component: ():Component => { return component; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; /** * * This function openes up the edit property modal * * @param property - the property to edit * @param component - the component who is the owner of the property * @param filteredProperties - the filtered properties list to scroll between in the edit modal * @param isPropertyValueOwner - boolean telling if the component is eligible of editing the property * @returns {IPromise} - Promise telling if the modal has opened or not */ openEditPropertyModal = (property:PropertyModel, component:Component, filteredProperties:Array, isPropertyValueOwner:boolean):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html', controller: 'Sdc.ViewModels.PropertyFormViewModel', size: 'sdc-l', backdrop: 'static', keyboard: false, resolve: { property: ():PropertyModel => { return property; }, component: ():Component => { return component; }, filteredProperties: ():Array => { return filteredProperties; }, isPropertyValueOwner: ():boolean => { return isPropertyValueOwner; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openEditModulePropertyModal = (property:PropertyModel, component:Component, selectedModule:DisplayModule):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html', controller: 'Sdc.ViewModels.ModulePropertyView', size: 'sdc-l', backdrop: 'static', keyboard: false, resolve: { originalProperty: ():PropertyModel => { return property; }, component: ():Component => { return component; }, selectedModule: ():DisplayModule => { return selectedModule; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; openSelectDataTypeModal = (property:PropertyModel, component:Component, filteredProperties:Array, propertiesMap:Array):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html', controller: 'Sdc.ViewModels.SelectDataTypeViewModel', size: 'sdc-l', backdrop: 'static', keyboard: false, resolve: { originalProperty: ():PropertyModel => { return property; }, component: ():Component => { return component; }, filteredProperties: ():Array => { return filteredProperties; }, propertiesMap: ():Array=> { return propertiesMap; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; public openEditAttributeModal = (attribute:AttributeModel, component: Component):void => { let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/forms/attribute-form/attribute-form-view.html', controller: 'Sdc.ViewModels.AttributeFormViewModel', size: 'sdc-md', backdrop: 'static', keyboard: false, resolve: { attribute: ():AttributeModel => { return attribute; }, component: ():Component => { return component; } } }; this.$uibModal.open(modalOptions); }; public openUpdateComponentInstanceNameModal = (currentComponent: Component):ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/forms/resource-instance-name-form/resource-instance-name-view.html', controller: 'Sdc.ViewModels.ResourceInstanceNameViewModel', size: 'sdc-sm', backdrop: 'static', resolve: { component: ():Component => { return currentComponent; } } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; public openConformanceLevelModal = ():ng.IPromise => { let deferred = this.$q.defer(); let modalOptions:ng.ui.bootstrap.IModalSettings = { templateUrl: '../view-models/workspace/conformance-level-modal/conformance-level-modal-view.html', controller: 'Sdc.ViewModels.ConformanceLevelModalViewModel', size: 'sdc-sm', backdrop: 'static', resolve: { } }; let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); deferred.resolve(modalInstance.result); return deferred.promise; }; }