From 451a3400b76511393c62a444f588a4ed15f4a549 Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sun, 19 Feb 2017 10:28:42 +0200 Subject: Initial OpenECOMP SDC commit Change-Id: I0924d5a6ae9cdc161ae17c68d3689a30d10f407b Signed-off-by: Michael Lando --- .../artifact-form/artifact-form-view-model.ts | 354 +++++++++++++++++++++ .../forms/artifact-form/artifact-form-view.html | 169 ++++++++++ .../forms/artifact-form/artifact-form.less | 44 +++ .../forms/attribute-form/attribute-form-view.html | 153 +++++++++ .../attribute-form/attribute-from-view-model.ts | 255 +++++++++++++++ .../env-parameters-form/env-parameters-form.html | 39 +++ .../env-parameters-form/env-parameters-form.less | 74 +++++ .../env-parameters-form/env-parameters-form.ts | 149 +++++++++ .../property-form/property-form-view-model.ts | 330 +++++++++++++++++++ .../forms/property-form/property-form-view.html | 219 +++++++++++++ .../forms/property-form/property-form.less | 63 ++++ .../resource-instance-name-model.ts | 105 ++++++ .../resource-instance-name-view.html | 72 +++++ .../resource-instance-name.less | 29 ++ 14 files changed, 2055 insertions(+) create mode 100644 catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form-view-model.ts create mode 100644 catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form-view.html create mode 100644 catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form.less create mode 100644 catalog-ui/app/scripts/view-models/forms/attribute-form/attribute-form-view.html create mode 100644 catalog-ui/app/scripts/view-models/forms/attribute-form/attribute-from-view-model.ts create mode 100644 catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.html create mode 100644 catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.less create mode 100644 catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.ts create mode 100644 catalog-ui/app/scripts/view-models/forms/property-form/property-form-view-model.ts create mode 100644 catalog-ui/app/scripts/view-models/forms/property-form/property-form-view.html create mode 100644 catalog-ui/app/scripts/view-models/forms/property-form/property-form.less create mode 100644 catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name-model.ts create mode 100644 catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name-view.html create mode 100644 catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name.less (limited to 'catalog-ui/app/scripts/view-models/forms') diff --git a/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form-view-model.ts b/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form-view-model.ts new file mode 100644 index 0000000000..092594b0d5 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form-view-model.ts @@ -0,0 +1,354 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +/// + +module Sdc.ViewModels { + 'use strict'; + import Resource = Sdc.Models.Components.Resource; + + export interface IEditArtifactModel { + artifactResource: Models.ArtifactModel; + artifactTypes: Array; + artifactFile: any; + } + + export interface IArtifactResourceFormViewModelScope extends ng.IScope { + forms:any; + $$childTail: any; + isNew: boolean; + isLoading: boolean; + validationPattern: RegExp; + urlValidationPattern: RegExp; + labelValidationPattern: RegExp; + integerValidationPattern: RegExp; + commentValidationPattern: RegExp; + artifactType: string; + editArtifactResourceModel: IEditArtifactModel; + defaultHeatTimeout: number; + validExtensions: any; + originalArtifactName: string; + editForm: ng.IFormController; + footerButtons: Array; + modalInstanceArtifact:ng.ui.bootstrap.IModalServiceInstance; + + fileExtensions():string; + save(doNotCloseModal?:boolean): void; + saveAndAnother(): void; + close(): void; + getOptions(): Array; + isDeploymentHeat(): boolean; + onFileChange(): void; + setDefaultTimeout(): void; + openEditEnvParametersModal(artifact:Models.ArtifactModel):void; + getFormTitle():string; + fileUploadRequired():string; + isArtifactOwner():boolean; + } + + export class ArtifactResourceFormViewModel { + + private artifactArr:Array; + + static '$inject' = [ + '$scope', + '$modalInstance', + 'artifact', + 'Sdc.Services.CacheService', + 'ValidationPattern', + 'UrlValidationPattern', + 'LabelValidationPattern', + 'IntegerValidationPattern', + 'CommentValidationPattern', + 'ValidationUtils', + '$base64', + '$state', + 'ArtifactsUtils', + '$modal', + '$templateCache', + 'component' + ]; + + private formState:Utils.Constants.FormState; + private entityId:string; + + constructor(private $scope:IArtifactResourceFormViewModelScope, + private $modalInstance:ng.ui.bootstrap.IModalServiceInstance, + private artifact:Models.ArtifactModel, + private cacheService:Services.CacheService, + private ValidationPattern:RegExp, + private UrlValidationPattern:RegExp, + private LabelValidationPattern:RegExp, + private IntegerValidationPattern : RegExp, + private CommentValidationPattern: RegExp, + private ValidationUtils: Sdc.Utils.ValidationUtils, + private $base64:any, + private $state:any, + private artifactsUtils:Sdc.Utils.ArtifactsUtils, + private $modal:ng.ui.bootstrap.IModalService, + private $templateCache:ng.ITemplateCacheService, + private component:Models.Components.Component) { + + + this.entityId = this.component.uniqueId; + this.artifactArr = []; + this.formState = angular.isDefined(artifact.artifactLabel) ? Utils.Constants.FormState.UPDATE : Utils.Constants.FormState.CREATE; + this.initScope(); + } + + private initEntity = ():void => { + this.$scope.editArtifactResourceModel.artifactResource = this.artifact; + this.$scope.originalArtifactName = this.artifact.artifactName; + }; + + + private initFooterButtons = ():void =>{ + + this.$scope.footerButtons = [ + {'name': 'Done', 'css': 'blue', 'callback': this.$scope.save} + ]; + if (this.$scope.isNew){ + this.$scope.footerButtons.push( {'name': 'Add Another', 'css': 'grey', 'disabled': !this.$scope.isNew && 'deployment' === this.$scope.artifactType, 'callback': this.$scope.saveAndAnother}); + } + + }; + + + private initArtifactTypes = ():void => { + + let artifactTypes:any = this.cacheService.get('UIConfiguration'); + + if('deployment' === this.$scope.artifactType) { + + this.$scope.validExtensions = ('HEAT_ENV' == this.artifact.artifactType||this.component.selectedInstance)?//to remove the first condition? + artifactTypes.artifacts.deployment.resourceInstanceDeploymentArtifacts + : this.component.isResource() ? artifactTypes.artifacts.deployment.resourceDeploymentArtifacts + : artifactTypes.artifacts.deployment.serviceDeploymentArtifacts; + + if(this.$scope.validExtensions) { + this.$scope.editArtifactResourceModel.artifactTypes = Object.keys(this.$scope.validExtensions); + } + this.$scope.defaultHeatTimeout = artifactTypes.defaultHeatTimeout; + if(this.$scope.isNew) { + let isHeat='HEAT_ENV' == this.artifact.artifactType; + _.remove(this.$scope.editArtifactResourceModel.artifactTypes, (item:string)=> { + return 'HEAT' == item.substring(0,4)||(!isHeat && item == "VF_MODULES_METADATA") || + _.has(Utils.Constants.ArtifactType.THIRD_PARTY_RESERVED_TYPES, item); + }); + } + + }if (this.$scope.artifactType === 'normal') { + this.$scope.editArtifactResourceModel.artifactTypes = artifactTypes.artifacts.other.map((element:any)=> { + return element.name; + }); + _.remove(this.$scope.editArtifactResourceModel.artifactTypes, (item:string)=> { + return _.has(Utils.Constants.ArtifactType.THIRD_PARTY_RESERVED_TYPES, item) || + _.has(Utils.Constants.ArtifactType.TOSCA, item); + }) + } + + if(this.component.isResource() && (this.component).isCsarComponent()) { + _.remove(this.$scope.editArtifactResourceModel.artifactTypes, (item:string) => { + return this.artifactsUtils.isLicenseType(item); + }) + } + + }; + + private initEditArtifactResourceModel = ():void => { + this.$scope.editArtifactResourceModel = { + artifactResource: null, + artifactTypes: null, + artifactFile:{} + }; + + this.initEntity(); + }; + + private initScope = ():void => { + + this.$scope.validationPattern = this.ValidationPattern; + this.$scope.urlValidationPattern = this.UrlValidationPattern; + this.$scope.labelValidationPattern = this.LabelValidationPattern; + this.$scope.integerValidationPattern = this.IntegerValidationPattern; + this.$scope.commentValidationPattern = this.CommentValidationPattern; + this.$scope.isLoading = false; + this.$scope.isNew = (this.formState === Utils.Constants.FormState.CREATE); + this.$scope.artifactType = this.artifactsUtils.getArtifactTypeByState(this.$state.current.name); + this.$scope.modalInstanceArtifact = this.$modalInstance; + + this.initEditArtifactResourceModel(); + this.initArtifactTypes(); + + // In case of edit, show the file name in browse. + if (this.artifact.artifactName!=="" && 'HEAT_ENV'!==this.artifact.artifactType){ + this.$scope.editArtifactResourceModel.artifactFile = {}; + this.$scope.editArtifactResourceModel.artifactFile.filename = this.artifact.artifactName; + } + + //scope methods + this.$scope.isDeploymentHeat = ():boolean => { + return !this.$scope.isNew && this.$scope.artifactType === 'deployment' && + 'HEAT' === this.$scope.editArtifactResourceModel.artifactResource.artifactType.substring(0,4); + }; + this.$scope.onFileChange = ():void => { + if(this.$scope.editArtifactResourceModel.artifactFile && this.$scope.editArtifactResourceModel.artifactFile.filename) { + this.$scope.editArtifactResourceModel.artifactResource.artifactName = this.$scope.editArtifactResourceModel.artifactFile.filename; + } else { + this.$scope.editArtifactResourceModel.artifactResource.artifactName = this.$scope.originalArtifactName; + } + }; + this.$scope.setDefaultTimeout = ():void => { + if(this.$scope.isDeploymentHeat() && !this.$scope.editArtifactResourceModel.artifactResource.timeout) { + this.$scope.editArtifactResourceModel.artifactResource.timeout = this.$scope.defaultHeatTimeout; + } + }; + + this.$scope.fileExtensions = ():string => { + let type:string = this.$scope.editArtifactResourceModel.artifactResource.artifactType; + return type && this.$scope.validExtensions && this.$scope.validExtensions[type].acceptedTypes ? + this.$scope.validExtensions[type].acceptedTypes.join(',') : ""; + }; + + this.$scope.save = (doNotCloseModal?:boolean):void => { + this.$scope.isLoading = true; + this.$scope.editArtifactResourceModel.artifactResource.description = this.ValidationUtils.stripAndSanitize(this.$scope.editArtifactResourceModel.artifactResource.description); + + if (!this.$scope.isDeploymentHeat()) { + this.$scope.editArtifactResourceModel.artifactResource.timeout = null; + } + + if (this.$scope.editArtifactResourceModel.artifactFile) { + this.$scope.editArtifactResourceModel.artifactResource.payloadData = this.$scope.editArtifactResourceModel.artifactFile.base64; + this.$scope.editArtifactResourceModel.artifactResource.artifactName = this.$scope.editArtifactResourceModel.artifactFile.filename; + } + + let onFaild = (response):void => { + this.$scope.isLoading = false; + console.info('onFaild', response); + }; + + let onSuccess = (artifactResource:Models.ArtifactModel):void => { + this.$scope.isLoading = false; + this.$scope.originalArtifactName = ""; + + if(this.$scope.isDeploymentHeat()){ + if(artifactResource.heatParameters) { + this.$scope.openEditEnvParametersModal(artifactResource); + } + } + + if (!doNotCloseModal) { + this.$modalInstance.close(); + //this.artifactArr = []; + } else { + this.$scope.editArtifactResourceModel.artifactFile = null; + angular.element("input[type='file']").val(null); // for support chrome when upload the same file + this.artifactsUtils.addAnotherAfterSave(this.$scope); + } + + }; + + if('HEAT_ENV' == this.artifact.artifactType){ + this.component.uploadInstanceEnvFile(this.$scope.editArtifactResourceModel.artifactResource).then(onSuccess, onFaild); + }else if(this.$scope.isArtifactOwner()){ + this.component.addOrUpdateInstanceArtifact(this.$scope.editArtifactResourceModel.artifactResource).then(onSuccess, onFaild); + }else { + this.component.addOrUpdateArtifact(this.$scope.editArtifactResourceModel.artifactResource).then(onSuccess, onFaild); + } + }; + + this.$scope.isArtifactOwner = ():boolean=> { + return this.component.isService() && !!this.component.selectedInstance; + }; + + this.$scope.saveAndAnother = ():void => { + this.$scope.save(true); + }; + + this.$scope.close = ():void => { + this.$modalInstance.close(); + this.artifactArr = []; + }; + + this.$scope.fileUploadRequired = ():string => { + if (this.$scope.editArtifactResourceModel.artifactFile.filename){ + // This is edit mode + return 'false'; + } else { + return 'true'; + } + }; + + this.$scope.getFormTitle =(): string =>{ + if('HEAT_ENV' == this.artifact.artifactType){ + return 'Update HEAT ENV'; + } + if(this.$scope.isDeploymentHeat()){ + if(!this.$scope.editArtifactResourceModel.artifactResource.artifactChecksum){ + return 'Add HEAT Template'; + } + return 'Update HEAT Template'; + } + if(this.$scope.isNew){ + return 'Add Artifact'; + } + return 'Update Artifact'; + }; + + this.$scope.openEditEnvParametersModal = (artifactResource:Models.ArtifactModel):void => { + + let modalOptions:ng.ui.bootstrap.IModalSettings = { + template: this.$templateCache.get('/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.html'), + controller: 'Sdc.ViewModels.EnvParametersFormViewModel', + size: 'sdc-md', + backdrop: 'static', + resolve: { + artifact: ():Models.ArtifactModel => { + return artifactResource; + }, + component: ():Models.Components.Component => { + return this.component; + } + } + }; + + let modalInstance:ng.ui.bootstrap.IModalServiceInstance = this.$modal.open(modalOptions); + modalInstance + .result + .then(():void => { + }); + }; + + this.$scope.forms = {}; + + this.initFooterButtons(); + + + this.$scope.$watch("forms.editForm.$invalid", (newVal, oldVal) => { + this.$scope.footerButtons[0].disabled = this.$scope.forms.editForm.$invalid; + if(this.$scope.isNew){ + this.$scope.footerButtons[1].disabled = this.$scope.forms.editForm.$invalid; + } + }); + + } + + } +} diff --git a/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form-view.html b/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form-view.html new file mode 100644 index 0000000000..74a19c8776 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form-view.html @@ -0,0 +1,169 @@ + + + + +
+
+ + +
+ + + +
+ + + + +
+
+ + +
+ +
+ +
+ + + +
+ + + +
+ +
+ +
+ + + +
+ +
+ +
+ +
+ + + +
+ + + +
+ +
+ +
+ +
+ +
+ + + +
+ + + +
+ +
+ +
+ +
+ +
+ + + +
+ + + +
+ +
+ UUID +
+ Version +
+
+ +
+ +
+ + + +
+
+
+ diff --git a/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form.less b/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form.less new file mode 100644 index 0000000000..1f77958c88 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/artifact-form/artifact-form.less @@ -0,0 +1,44 @@ +.sdc-edit-artifact-form-container { + + .w-sdc-form-note { + .h_9; + display: block; + position: relative; + top: 13px; + } + + .i-sdc-form-textarea{ + min-height: 95px; + } + + .i-sdc-form-url { + padding-bottom: 0px; + } + + &.mandatory-artifact { + .w-sdc-form-column { + width: 100%; + padding: 0; + min-height: initial; + } + } + .w-sdc-form .i-sdc-form-item.upload input[type="file"] { + display: none + } + + .artifact-info { + text-align: left; + color: rgb(140, 140, 140); + font-size: 13px; + margin-top: -10px; + margin-bottom: 5px; + width: 100%; + min-height: initial; + + span { + color: #666666; + padding-left: 4px; + } + } + +} diff --git a/catalog-ui/app/scripts/view-models/forms/attribute-form/attribute-form-view.html b/catalog-ui/app/scripts/view-models/forms/attribute-form/attribute-form-view.html new file mode 100644 index 0000000000..432b32fbd3 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/attribute-form/attribute-form-view.html @@ -0,0 +1,153 @@ + + +
+
+ +
+ +
+ + +
+ + +
+ + + + +
+
+ + +
+ + +
+ + + +
+
+ + +
+ +
+ +
+ + +
+ +
+
+ + +
+ + + +
+ +
+
+ + +
+ + + +
+ + + + +
+
+ + +
+ + +
+
+ +
+ +
+
+ +
diff --git a/catalog-ui/app/scripts/view-models/forms/attribute-form/attribute-from-view-model.ts b/catalog-ui/app/scripts/view-models/forms/attribute-form/attribute-from-view-model.ts new file mode 100644 index 0000000000..d369cfa5d1 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/attribute-form/attribute-from-view-model.ts @@ -0,0 +1,255 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +/// + +module Sdc.ViewModels { + 'use strict'; + + export interface IEditAttributeModel { + attribute: Models.AttributeModel; + types: Array; + simpleTypes: Array; + } + + interface IAttributeFormViewModelScope extends ng.IScope { + $$childTail: any; + forms:any; + editForm:ng.IFormController; + footerButtons: Array; + isService: boolean; + editAttributeModel: IEditAttributeModel; + modalInstanceAttribute:ng.ui.bootstrap.IModalServiceInstance; + isNew: boolean; + listRegex: Sdc.Utils.IMapRegex; + mapRegex: Sdc.Utils.IMapRegex; + propertyNameValidationPattern: RegExp; + commentValidationPattern: RegExp; + isLoading: boolean; + validationPattern: RegExp; + + save():void; + close(): void; + onTypeChange():void; + onValueChange(): void; + isAttributeValueOwner():boolean; + validateIntRange(value:string):boolean; + validateUniqueKeys(viewValue:string):boolean; + getValidationTranslate(): string; + showSchema(): boolean; + isSchemaEditable(): boolean; + validateName():void; + } + + export class AttributeFormViewModel { + + static '$inject' = [ + '$scope', + '$modalInstance', + 'attribute', + 'ValidationUtils', + 'CommentValidationPattern', + 'PropertyNameValidationPattern', + 'component' + ]; + + private formState: Sdc.Utils.Constants.FormState; + + + constructor(private $scope:IAttributeFormViewModelScope, + private $modalInstance:ng.ui.bootstrap.IModalServiceInstance, + private attribute: Models.AttributeModel, + private ValidationUtils:Sdc.Utils.ValidationUtils, + private CommentValidationPattern:RegExp, + private PropertyNameValidationPattern: RegExp, + private component: Models.Components.Component) { + this.formState = angular.isDefined(attribute.name) ? Utils.Constants.FormState.UPDATE : Utils.Constants.FormState.CREATE; + this.initScope(); + } + + private initResource = ():void => { + this.$scope.editAttributeModel.attribute = new Sdc.Models.AttributeModel(this.attribute); + if (this.$scope.editAttributeModel.types.indexOf(this.attribute.type) === -1) {//attribute defaulte type is string too? + this.attribute.type = "string"; + } + }; + + private initEditAttributeModel = ():void => { + this.$scope.editAttributeModel = { + attribute: null, + types: ['integer', 'string', 'float', 'boolean', 'list', 'map'], + simpleTypes: ['integer', 'string', 'float', 'boolean'] + }; + + this.initResource(); + }; + + private initScope = ():void => { + + //scope attributes + this.$scope.forms = {}; + this.$scope.propertyNameValidationPattern = this.PropertyNameValidationPattern; + this.$scope.commentValidationPattern = this.CommentValidationPattern; + + this.$scope.modalInstanceAttribute = this.$modalInstance; + this.$scope.listRegex = this.ValidationUtils.getPropertyListPatterns(); + this.$scope.mapRegex = this.ValidationUtils.getPropertyMapPatterns(); + + this.$scope.isNew = (this.formState === Utils.Constants.FormState.CREATE); + this.$scope.isLoading = false; + + this.initEditAttributeModel(); + this.setValidationPattern(); + + //scope methods + this.$scope.save = ():void => { + if(!this.$scope.forms.editForm.$invalid){ + let attribute:Models.AttributeModel = this.$scope.editAttributeModel.attribute; + this.$scope.editAttributeModel.attribute.description = this.ValidationUtils.stripAndSanitize(this.$scope.editAttributeModel.attribute.description); + ////if read only - just closes the modal + if (this.$scope.editAttributeModel.attribute.readonly && !this.$scope.isAttributeValueOwner()) { + this.$modalInstance.close(); + return; + } + this.$scope.isLoading = true; + let onAttributeFaild = (response):void => { + console.info('onFaild', response); + this.$scope.isLoading = false; + }; + + let onAttributeSuccess = (attributeFromBE:Models.AttributeModel):void => { + console.info('onAttributeResourceSuccess : ', attributeFromBE); + this.$scope.isLoading = false; + this.$modalInstance.close(); + }; + + //in case we have uniqueId we call update method + if (this.$scope.isAttributeValueOwner()) { + this.component.updateInstanceAttribute(attribute).then(onAttributeSuccess, onAttributeFaild); + } else { + this.component.addOrUpdateAttribute(attribute).then(onAttributeSuccess, onAttributeFaild); + } + } + }; + + this.$scope.close = ():void => { + this.$modalInstance.close(); + }; + + this.$scope.validateName = ():void => { + let existsAttr: Models.AttributeModel = _.find(this.component.attributes, (attribute:Models.AttributeModel) => { + return attribute.name === this.$scope.editAttributeModel.attribute.name; + }); + if(existsAttr){ + this.$scope.forms.editForm["attributeName"].$setValidity('nameExist', false); + }else{ + this.$scope.forms.editForm["attributeName"].$setValidity('nameExist', true); + } + + }; + + this.$scope.onTypeChange = ():void => { + this.$scope.editAttributeModel.attribute.value = ''; + this.$scope.editAttributeModel.attribute.defaultValue = ''; + this.setValidationPattern(); + }; + + this.$scope.isAttributeValueOwner = ():boolean=> { + return this.component.isService() || !!this.component.selectedInstance; + }; + + this.$scope.onValueChange = ():void => { + if (!this.$scope.editAttributeModel.attribute.value) { + if (this.$scope.isAttributeValueOwner()) { + this.$scope.editAttributeModel.attribute.value = this.$scope.editAttributeModel.attribute.defaultValue; + } + } + }; + + + this.$scope.validateUniqueKeys = (viewValue:string) : boolean => { + if(this.$scope.editAttributeModel.attribute.type === 'map') { + return this.ValidationUtils.validateUniqueKeys(viewValue); + } + else { + return true; //always valid if not a map + } + }; + + this.$scope.validateIntRange = (value:string):boolean => { + return !value || this.ValidationUtils.validateIntRange(value); + }; + + this.$scope.isSchemaEditable = () :boolean => { + let schemaType=this.$scope.editAttributeModel.attribute.schema.property.type; + return this.$scope.editAttributeModel.simpleTypes.indexOf(schemaType) > -1||!schemaType; + }; + + this.$scope.showSchema = () :boolean => { + return ['list', 'map'].indexOf(this.$scope.editAttributeModel.attribute.type) > -1; + }; + + this.$scope.getValidationTranslate = () : string => { + let result = "ATTRIBUTE_EDIT_PATTERN"; + if (this.$scope.showSchema()) { + + result = "ATTRIBUTE_EDIT_" + this.$scope.editAttributeModel.attribute.type.toUpperCase(); + + if(this.$scope.editAttributeModel.attribute.schema.property.type === Utils.Constants.PROPERTY_TYPES.STRING) { + result += "_STRING"; + }else if(this.$scope.editAttributeModel.attribute.schema.property.type === Utils.Constants.PROPERTY_TYPES.BOOLEAN) { + result += "_BOOLEAN"; + } else { + result += "_GENERIC"; + } + } + + return result; + }; + + // Add the done button at the footer. + this.$scope.footerButtons = [ + {'name': 'Done', 'css':'blue', 'callback': this.$scope.save}, + {'name':'Cancel', 'css':'grey', 'callback': this.$scope.close} + ]; + + this.$scope.$watchCollection("forms.editForm.$invalid", (newVal, oldVal) => { + this.$scope.footerButtons[0].disabled = this.$scope.forms.editForm.$invalid; + }); + + } + + + private setValidationPattern = ():void => { + + if(this.$scope.editAttributeModel.attribute.type === 'list') { + this.$scope.validationPattern = this.$scope.listRegex[this.$scope.editAttributeModel.attribute.schema.property.type]; + } + else if(this.$scope.editAttributeModel.attribute.type === 'map') { + this.$scope.validationPattern = this.$scope.mapRegex[this.$scope.editAttributeModel.attribute.schema.property.type]; + } + else{ + this.$scope.validationPattern = this.ValidationUtils.getValidationPattern(this.$scope.editAttributeModel.attribute.type); + } + + }; + + + } +} diff --git a/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.html b/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.html new file mode 100644 index 0000000000..69367dc68c --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.html @@ -0,0 +1,39 @@ + +
+
+ +
+ +
+
+ + + + +
+ + + +
+
+
+
+ +
+
+
+
+
+
+
+
diff --git a/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.less b/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.less new file mode 100644 index 0000000000..c58c94ab22 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.less @@ -0,0 +1,74 @@ + +.sdc-env-form-container{ + .w-sdc-modal-body{ + padding: 20px 10px 2px 10px; + } + .w-sdc-modal-body-content{ + .b_6; + display: block; + } + + .env-file-generation-label{ + .p_9; + .bold; + margin-bottom: 20px; + } +} + +.w-sdc-env-form-container { + border-top: 1px solid #cdcdcd; + border-bottom: 1px solid #cdcdcd; + height: 356px; + margin: 35px 0 10px 0; + + .w-sdc-form { + text-align: left; + } + .i-sdc-form-item{ + display: inline-block; + .description{ + margin-bottom: 2px; + vertical-align: baseline; + padding: 32px 0 0 0; + text-transform: capitalize; + .b_1; + } + } + .left-column-container{ + width: 250px; + float: left; + .i-sdc-env-form-label { + overflow: hidden; + max-width: 100%; + text-overflow: ellipsis; + display: inline-block; + white-space: nowrap; + + &.required::before { + color: #f33; + content: '*'; + margin-right: 4px; + } + } + } + .i-sdc-env-form-label-description { + float: right; + + .i-sdc-env-form-label { + .p_9; + // height: 20px; + margin: 30px 0px 0px 30px; + overflow: hidden; + max-width: 245px; + text-overflow: ellipsis; + display: inline-block; + white-space: nowrap; + + &.required::before { + color: #f33; + content: '*'; + margin-right: 4px; + } + } + } +} diff --git a/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.ts b/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.ts new file mode 100644 index 0000000000..d1bae440cc --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/env-parameters-form/env-parameters-form.ts @@ -0,0 +1,149 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +/// + +module Sdc.ViewModels { + 'use strict'; + + export interface IEnvParametersFormViewModelScope extends ng.IScope { + isLoading: boolean; + type:string; + heatParameters:any; + editForm:ng.IFormController; + artifactResource:Models.ArtifactModel; + saveButton: Array; + envParametersModal: ng.ui.bootstrap.IModalServiceInstance; + + getValidationPattern(type:string):RegExp; + isInstance():boolean; + validateJson(json:string):boolean; + close(): void; + save():void; + } + + export class EnvParametersFormViewModel { + + + static '$inject' = [ + '$scope', + '$state', + '$modalInstance', + 'artifact', + // 'ArtifactsUtils', + 'ValidationUtils', + 'component' + ]; + + + constructor(private $scope:IEnvParametersFormViewModelScope, + private $state:any, + private $modalInstance:ng.ui.bootstrap.IModalServiceInstance, + private artifact:Models.ArtifactModel, + // private artifactsUtils:Sdc.Utils.ArtifactsUtils, + private ValidationUtils: Sdc.Utils.ValidationUtils, + private component:Models.Components.Component) { + + + this.initScope(); + } + + private updateInstanceHeat = ():void => { + let success =(responseArtifact:Models.ArtifactModel): void => { + this.$scope.isLoading = false; + this.$modalInstance.close(); + }; + + let error = ():void => { + this.$scope.isLoading = false; + console.info('Failed to load save artifact'); + }; + + this.component.addOrUpdateInstanceArtifact(this.$scope.artifactResource).then(success, error); + + }; + + private initScope = ():void => { + this.$scope.envParametersModal = this.$modalInstance; + this.$scope.artifactResource= this.artifact; + this.$scope.heatParameters = angular.copy(this.artifact.heatParameters); + + this.$scope.getValidationPattern = (validationType:string , parameterType?:string):RegExp => { + return this.ValidationUtils.getValidationPattern(validationType, parameterType); + }; + + this.$scope.validateJson = (json:string):boolean => { + if(!json){ + return true; + } + return this.ValidationUtils.validateJson(json); + }; + + this.$scope.isInstance =(): boolean =>{ + return !!this.component.selectedInstance; + }; + + + this.$scope.save = ():void => { + this.$scope.isLoading = true; + this.artifact.heatParameters = this.$scope.heatParameters; + this.artifact.heatParameters.forEach((parameter:any):void => { + /* if ("" === parameter.currentValue) { + parameter.currentValue = null; + }else */ + if(!parameter.currentValue && parameter.defaultValue) { + parameter.currentValue = parameter.defaultValue; + } + }); + + if(this.$scope.isInstance()){ + this.updateInstanceHeat(); + return; + } + + let success =(responseArtifact:Models.ArtifactModel): void => { + this.$scope.isLoading = false; + this.$modalInstance.close(); + + }; + + let error = ():void => { + this.$scope.isLoading = false; + console.info('Failed to load save artifact'); + }; + + this.component.addOrUpdateArtifact(this.$scope.artifactResource).then(success, error); + }; + + this.$scope.saveButton = [ + {'name': 'Save', 'css': 'blue', 'callback': this.$scope.save} + ]; + + this.$scope.close = ():void => { + //this.artifact.heatParameters.forEach((parameter:any):void => { + // if (!parameter.currentValue && parameter.defaultValue) { + // parameter.currentValue = parameter.defaultValue; + // } + //}); + this.$modalInstance.dismiss(); + }; + + }; + } +} diff --git a/catalog-ui/app/scripts/view-models/forms/property-form/property-form-view-model.ts b/catalog-ui/app/scripts/view-models/forms/property-form/property-form-view-model.ts new file mode 100644 index 0000000000..c9732aa9a6 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/property-form/property-form-view-model.ts @@ -0,0 +1,330 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +/// + +module Sdc.ViewModels { + 'use strict'; + + export interface IEditPropertyModel { + property: Models.PropertyModel; + types: Array; + simpleTypes: Array; + sources: Array; + } + + interface IPropertyFormViewModelScope extends ng.IScope { + forms:any; + editForm:ng.IFormController; + footerButtons: Array; + isNew: boolean; + isLoading: boolean; + isService: boolean; + validationPattern: RegExp; + propertyNameValidationPattern: RegExp; + commentValidationPattern: RegExp; + editPropertyModel: IEditPropertyModel; + modalInstanceProperty:ng.ui.bootstrap.IModalServiceInstance; + currentPropertyIndex:number; + isLastProperty:boolean; + myValue:any; + nonPrimitiveTypes:Array; + dataTypes:Models.DataTypesMap; + isTypeDataType:boolean; + maxLength:number; + + save(doNotCloseModal?:boolean): void; + getValidationPattern(type:string): RegExp; + validateIntRange(value:string):boolean; + close(): void; + onValueChange(): void; + onSchemaTypeChange():void; + onTypeChange(resetSchema:boolean): void; + isPropertyValueOwner():boolean; + showSchema(): boolean; + delete(property:Models.PropertyModel): void; + getPrev(): void; + getNext(): void; + isSimpleType(typeName:string):boolean; + getDefaultValue():any; + } + + export class PropertyFormViewModel { + + static '$inject' = [ + '$scope', + 'Sdc.Services.DataTypesService', + '$modalInstance', + 'property', + 'ValidationPattern', + 'PropertyNameValidationPattern', + 'CommentValidationPattern', + 'ValidationUtils', + 'component', + '$filter', + 'ModalsHandler', + 'filteredProperties', + '$timeout' + ]; + + private formState: Sdc.Utils.Constants.FormState; + + constructor(private $scope:IPropertyFormViewModelScope, + private DataTypesService:Sdc.Services.DataTypesService, + private $modalInstance:ng.ui.bootstrap.IModalServiceInstance, + private property: Models.PropertyModel, + private ValidationPattern:RegExp, + private PropertyNameValidationPattern: RegExp, + private CommentValidationPattern:RegExp, + private ValidationUtils:Sdc.Utils.ValidationUtils, + private component: Models.Components.Component, + private $filter:ng.IFilterService, + private ModalsHandler:Utils.ModalsHandler, + private filteredProperties: Array, + private $timeout: ng.ITimeoutService) { + + this.formState = angular.isDefined(property.name) ? Utils.Constants.FormState.UPDATE : Utils.Constants.FormState.CREATE; + this.initScope(); + } + + private initResource = ():void => { + this.$scope.editPropertyModel.property = new Sdc.Models.PropertyModel(this.property); + this.$scope.editPropertyModel.property.type = this.property.type? this.property.type: null; + this.setMaxLength(); + // if (this.$scope.editPropertyModel.types.indexOf(this.property.type) === -1 && !this.$scope.isNew) { + // this.property.type = "string"; + // } + }; + + private initEditPropertyModel = ():void => { + this.$scope.editPropertyModel = { + property: null, + types: Utils.Constants.PROPERTY_DATA.TYPES, + simpleTypes: Utils.Constants.PROPERTY_DATA.SIMPLE_TYPES, + sources: Utils.Constants.PROPERTY_DATA.SOURCES + }; + + this.initResource(); + }; + + private initForNotSimpleType = ():void => { + let property = this.$scope.editPropertyModel.property; + this.$scope.isTypeDataType=this.DataTypesService.isDataTypeForPropertyType(this.$scope.editPropertyModel.property,this.$scope.dataTypes); + if(property.type && this.$scope.editPropertyModel.simpleTypes.indexOf(property.type)==-1){ + if(!(property.value||property.defaultValue)) { + switch (property.type) { + case Utils.Constants.PROPERTY_TYPES.MAP: + this.$scope.myValue = {'':null}; + break; + case Utils.Constants.PROPERTY_TYPES.LIST: + this.$scope.myValue = []; + break; + default: + this.$scope.myValue = {}; + } + }else{ + this.$scope.myValue = JSON.parse(property.value||property.defaultValue); + } + } + }; + + private setMaxLength = ():void => { + switch (this.$scope.editPropertyModel.property.type) { + case Utils.Constants.PROPERTY_TYPES.MAP: + case Utils.Constants.PROPERTY_TYPES.LIST: + this.$scope.maxLength = this.$scope.editPropertyModel.property.schema.property.type == Utils.Constants.PROPERTY_TYPES.JSON? + Utils.Constants.PROPERTY_VALUE_CONSTRAINTS.JSON_MAX_LENGTH: + Utils.Constants.PROPERTY_VALUE_CONSTRAINTS.MAX_LENGTH; + break; + case Utils.Constants.PROPERTY_TYPES.JSON: + this.$scope.maxLength = Utils.Constants.PROPERTY_VALUE_CONSTRAINTS.JSON_MAX_LENGTH; + break; + default: + this.$scope.maxLength = Utils.Constants.PROPERTY_VALUE_CONSTRAINTS.MAX_LENGTH; + } + }; + + + private initScope = ():void => { + + //scope properties + this.$scope.forms = {}; + this.$scope.validationPattern = this.ValidationPattern; + this.$scope.propertyNameValidationPattern = this.PropertyNameValidationPattern; + this.$scope.commentValidationPattern = this.CommentValidationPattern; + this.$scope.isLoading = false; + this.$scope.isNew = (this.formState === Utils.Constants.FormState.CREATE); + this.$scope.isService = this.component.isService(); + this.$scope.modalInstanceProperty = this.$modalInstance; + this.$scope.currentPropertyIndex = _.findIndex(this.filteredProperties, i=> i.name == this.property.name ); + this.$scope.isLastProperty= this.$scope.currentPropertyIndex==(this.filteredProperties.length-1); + + this.initEditPropertyModel(); + + this.DataTypesService.getAllDataTypes().then((response:any) => { + this.$scope.dataTypes = response; + delete response['tosca.datatypes.Root']; + this.$scope.nonPrimitiveTypes =_.filter(Object.keys(response),(type:string)=>{ + return this.$scope.editPropertyModel.types.indexOf(type)==-1; + }); + this.initForNotSimpleType(); + }, (err)=> {}); + + + + + + //scope methods + this.$scope.save = (doNotCloseModal?:boolean):void => { + let property:Models.PropertyModel = this.$scope.editPropertyModel.property; + this.$scope.editPropertyModel.property.description = this.ValidationUtils.stripAndSanitize(this.$scope.editPropertyModel.property.description); + ////if read only - just closes the modal + if (this.$scope.editPropertyModel.property.readonly && !this.$scope.isPropertyValueOwner()) { + this.$modalInstance.close(); + return; + } + + this.$scope.isLoading = true; + + let onPropertyFaild = (response):void => { + console.info('onFaild', response); + this.$scope.isLoading = false; + }; + + let onPropertySuccess = (propertyFromBE:Models.PropertyModel):void => { + console.info('onPropertyResourceSuccess : ', propertyFromBE); + this.$scope.isLoading = false; + + if (!doNotCloseModal) { + this.$modalInstance.close(); + } else { + this.$scope.forms.editForm.$setPristine(); + this.$scope.editPropertyModel.property = new Models.PropertyModel(); + } + }; + + //in case we have uniqueId we call update method + if (this.$scope.isPropertyValueOwner()) { + if(!this.$scope.editPropertyModel.property.simpleType && !this.$scope.isSimpleType(property.type)){ + let myValueString:string = JSON.stringify(this.$scope.myValue); + property.value = myValueString; + } + this.component.updateInstanceProperty(property).then(onPropertySuccess, onPropertyFaild); + } else { + if(!this.$scope.editPropertyModel.property.simpleType && !this.$scope.isSimpleType(property.type)){ + let myValueString:string = JSON.stringify(this.$scope.myValue); + property.defaultValue = myValueString; + }else{ + this.$scope.editPropertyModel.property.defaultValue = this.$scope.editPropertyModel.property.value; + } + this.component.addOrUpdateProperty(property).then(onPropertySuccess, onPropertyFaild); + } + }; + + + this.$scope.isPropertyValueOwner = ():boolean=> { + return this.component.isService() || !!this.component.selectedInstance; + }; + + this.$scope.getPrev = ():void=> { + this.property = this.filteredProperties[--this.$scope.currentPropertyIndex]; + this.initResource(); + this.initForNotSimpleType(); + this.$scope.isLastProperty=false; + }; + + this.$scope.getNext = ():void=> { + this.property = this.filteredProperties[++this.$scope.currentPropertyIndex]; + this.initResource(); + this.initForNotSimpleType(); + this.$scope.isLastProperty= this.$scope.currentPropertyIndex==(this.filteredProperties.length-1); + }; + + this.$scope.isSimpleType = (typeName:string):boolean=>{ + return typeName && this.$scope.editPropertyModel.simpleTypes.indexOf(typeName)!=-1; + }; + + this.$scope.showSchema = () :boolean => { + return [Utils.Constants.PROPERTY_TYPES.LIST, Utils.Constants.PROPERTY_TYPES.MAP].indexOf(this.$scope.editPropertyModel.property.type) > -1; + }; + + this.$scope.getValidationPattern = (type:string):RegExp => { + return this.ValidationUtils.getValidationPattern(type); + }; + + this.$scope.validateIntRange = (value:string):boolean => { + return !value || this.ValidationUtils.validateIntRange(value); + }; + + this.$scope.close = ():void => { + this.$modalInstance.close(); + }; + + // put default value when instance value is empty + this.$scope.onValueChange = ():void => { + if (!this.$scope.editPropertyModel.property.value) { + if (this.$scope.isPropertyValueOwner()) { + this.$scope.editPropertyModel.property.value = this.$scope.editPropertyModel.property.defaultValue; + } + } + }; + + // Add the done button at the footer. + this.$scope.footerButtons = [ + {'name': 'Save', 'css': 'blue', 'callback': this.$scope.save }, + {'name': 'Cancel', 'css': 'grey', 'callback':this.$scope.close } + ]; + + this.$scope.$watch("forms.editForm.$invalid", (newVal, oldVal) => { + this.$scope.footerButtons[0].disabled = this.$scope.forms.editForm.$invalid; + }); + + this.$scope.getDefaultValue = ():any => { + return this.$scope.isPropertyValueOwner() ? this.$scope.editPropertyModel.property.defaultValue : null; + }; + + this.$scope.onTypeChange = ():void => { + this.$scope.editPropertyModel.property.value = ''; + this.$scope.editPropertyModel.property.defaultValue = ''; + this.setMaxLength(); + this.initForNotSimpleType(); + }; + + this.$scope.onSchemaTypeChange = ():void => { + if(this.$scope.editPropertyModel.property.type==Utils.Constants.PROPERTY_TYPES.MAP){ + this.$scope.myValue={'':null}; + }else if(this.$scope.editPropertyModel.property.type==Utils.Constants.PROPERTY_TYPES.LIST){ + this.$scope.myValue=[]; + } + this.setMaxLength(); + }; + + this.$scope.delete = (property:Models.PropertyModel):void => { + let onOk = ():void => { + this.component.deleteProperty(property.uniqueId).then( + this.$scope.close + ); + }; + let title:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TITLE"); + let message:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TEXT", "{'name': '" + property.name + "'}"); + this.ModalsHandler.openConfirmationModal(title, message, false).then(onOk); + }; + } + } +} diff --git a/catalog-ui/app/scripts/view-models/forms/property-form/property-form-view.html b/catalog-ui/app/scripts/view-models/forms/property-form/property-form-view.html new file mode 100644 index 0000000000..d593d47a77 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/property-form/property-form-view.html @@ -0,0 +1,219 @@ + +
+
+ Delete + + Previous + Next +
+
+ +
+ +
+ +
+ +
+ + +
+ + + +
+ + + +
+ +
+ + + + + +
+ +
+
+
+ +
+ + + +
+ +
+
+
+
+ +
+ + + +
+ +
+
+
+
+ + +
+ +
+ Should be constraints by type(TBD) +
+
+ +
+ +
+ +
+ + + +
+ + + +
+
+ + +
+ +
+ + +
+
+
+ +
+
+ +
+
+
+ + + +
+ + + + +
+
+
+
+
+ +
+
+
+ +
diff --git a/catalog-ui/app/scripts/view-models/forms/property-form/property-form.less b/catalog-ui/app/scripts/view-models/forms/property-form/property-form.less new file mode 100644 index 0000000000..15e30af4ee --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/property-form/property-form.less @@ -0,0 +1,63 @@ +.sdc-edit-property-container { + .scrollbar-container{ + height: 415px; + width: 830px; + .perfect-scrollbar; + } + + form{ + width: 813px; + [name="description"]{ + min-height:50px; + } + } + + .sdc-modal-top-bar{ + height: 40px; + .sdc-modal-top-bar-buttons { + float: right; + + > span:not(.delimiter){ + vertical-align: middle; + .hand; + + &.sprite-new { + text-indent: 100%; + } + &.disabled, &:hover.disabled { + pointer-events: none; + } + } + + .delete-btn{ + margin-right: 6px; + } + + .left-arrow{ + margin-right: 8px; + } + + .delimiter { + height: 20px; + width: 1px; + background-color: #959595; + display: inline-block; + vertical-align: middle; + margin-right: 10px; + } + } + } + + .w-sdc-form-note { + .h_9; + display: block; + position: relative; + top: 13px; + } + + .default-value-section{ + border-top: solid 1px @main_color_a; + padding-top: 15px; + margin-top: 15px; + } +} diff --git a/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name-model.ts b/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name-model.ts new file mode 100644 index 0000000000..b69bf4a2a6 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name-model.ts @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +/// + +module Sdc.ViewModels { + 'use strict'; + + interface IResourceInstanceViewModelScope extends ng.IScope { + + componentInstanceModel: Sdc.Models.ComponentsInstances.ComponentInstance; + validationPattern: RegExp; + oldName:string; + isAlreadyPressed:boolean; + footerButtons: Array; + forms:any; + modalInstanceName:ng.ui.bootstrap.IModalServiceInstance; + + save(): void; + close(): void; + } + + export class ResourceInstanceNameViewModel { + + static '$inject' = [ + '$scope', + 'ValidationPattern', + '$modalInstance', + 'ComponentInstanceFactory', + 'component' + ]; + + + constructor(private $scope:IResourceInstanceViewModelScope, + private ValidationPattern:RegExp, + private $modalInstance:ng.ui.bootstrap.IModalServiceInstance, + private ComponentInstanceFactory:Utils.ComponentInstanceFactory, + private component:Models.Components.Component) { + + this.initScope(); + } + + + private initScope = ():void => { + this.$scope.forms = {}; + this.$scope.validationPattern = this.ValidationPattern; + this.$scope.componentInstanceModel = Utils.ComponentInstanceFactory.createComponentInstance(this.component.selectedInstance); + this.$scope.oldName = this.component.selectedInstance.name; + this.$scope.modalInstanceName = this.$modalInstance; + + this.$scope.isAlreadyPressed = false; + + + this.$scope.close = ():void => { + this.$modalInstance.dismiss(); + }; + + this.$scope.save = ():void => { + + let onFailed = () => { + this.$scope.isAlreadyPressed = true; + }; + + let onSuccess = (componentInstance:Models.ComponentsInstances.ComponentInstance) => { + this.$modalInstance.close(); + this.$scope.isAlreadyPressed = false; + this.$scope.componentInstanceModel = componentInstance; + //this.component.name = componentInstance.name;//DE219124 + this.component.selectedInstance.name = componentInstance.name; + + }; + + this.$scope.isAlreadyPressed = true; + if (this.$scope.oldName != this.$scope.componentInstanceModel.name) { + this.component.updateComponentInstance(this.$scope.componentInstanceModel).then(onSuccess, onFailed); + } + }; + + this.$scope.footerButtons = [ + {'name': 'OK', 'css': 'blue', 'callback': this.$scope.save, 'disabled': (!this.$scope.componentInstanceModel.name || this.$scope.componentInstanceModel.name === this.$scope.oldName) || this.$scope.isAlreadyPressed}, + {'name': 'Cancel', 'css': 'grey', 'callback': this.$scope.close} + ]; + + this.$scope.$watch("forms.editNameForm.$invalid", (newVal, oldVal) => { + this.$scope.footerButtons[0].disabled = this.$scope.forms.editNameForm.$invalid; + }); + } + } +} diff --git a/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name-view.html b/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name-view.html new file mode 100644 index 0000000000..e04343adbd --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name-view.html @@ -0,0 +1,72 @@ + + +
+
+ + + +
+ + + +
+ +
+
+ +
+ + + + diff --git a/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name.less b/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name.less new file mode 100644 index 0000000000..57698bef17 --- /dev/null +++ b/catalog-ui/app/scripts/view-models/forms/resource-instance-name-form/resource-instance-name.less @@ -0,0 +1,29 @@ +.w-sdc-modal-resource-instance-name { + + .w-sdc-modal-body { + overflow: visible; + } + + .w-sdc-modal-action { + display: flex; + align-items: center; + justify-content: center; + } + + .w-sdc-modal-resource-instance-input { + .p_1; + border: solid 1px @color_p; + height: 45px; + padding: 0 20px; + margin: 0 auto 0 auto; + display: block; + } + .w-sdc-modal-body { + border-bottom: none; + } + + .w-sdc-form .i-sdc-form-item.error::after { + top: 13px; + } + +} -- cgit 1.2.3-korg