diff options
Diffstat (limited to 'catalog-ui')
4 files changed, 78 insertions, 43 deletions
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.html b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.html index f0db645b0e..b6b313d93c 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.html +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.html @@ -27,14 +27,14 @@ [ngValue]="toscaFunction">{{toscaFunction | lowercase}}</option> </select> </div> - <div class="i-sdc-form-item" *ngIf="toscaGetFunction.functionType === TOSCA_FUNCTION_GET_PROPERTY"> + <div class="i-sdc-form-item" *ngIf="showPropertySourceDropdown()"> <label class="i-sdc-form-label required">{{'TOSCA_FUNCTION_PROPERTY_SOURCE_LABEL' | translate}}</label> <select name="propertySource" [(ngModel)]="propertySource" (change)="onPropertySourceChange()"> <option *ngFor="let propertySource of propertySourceList" [ngValue]="propertySource">{{propertySource}}</option> </select> </div> - <div *ngIf="showDropdown()" class="i-sdc-form-item"> + <div *ngIf="showPropertyDropdown()" class="i-sdc-form-item"> <label class="i-sdc-form-label required">{{dropdownValuesLabel}}</label> <select [(ngModel)]="selectedProperty" name="selectedProperty" (change)="onPropertyChange()"> <option *ngFor="let value of propertyDropdownList" [ngValue]="value">{{value.propertyLabel}}</option> diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts index 4eefbcb467..b71a61dc01 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts @@ -18,7 +18,7 @@ */ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel} from 'app/models'; +import {AttributeModel, ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel} from 'app/models'; import {TopologyTemplateService} from "../../../services/component-services/topology-template.service"; import {WorkspaceService} from "../../workspace/workspace.service"; import {PropertiesService} from "../../../services/properties.service"; @@ -82,8 +82,6 @@ export class ToscaFunctionComponent implements OnInit { 'toscaGetFunction': this.toscaGetFunctionForm }); - TOSCA_FUNCTION_GET_PROPERTY = ToscaGetFunctionType.GET_PROPERTY; - selectedProperty: PropertyDropdownValue; isLoading: boolean = false; propertyDropdownList: Array<PropertyDropdownValue> = []; @@ -123,7 +121,7 @@ export class ToscaFunctionComponent implements OnInit { } this.toscaGetFunction = new ToscaGetFunction(this.property.toscaGetFunction); this.toscaGetFunctionForm.setValue(this.toscaGetFunction); - if (this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY) { + if (this.isGetPropertySelected() || this.isGetAttributeSelected()) { if (this.toscaGetFunction.propertySource === PropertySource.SELF) { this.propertySource = PropertySource.SELF; } else { @@ -138,6 +136,7 @@ export class ToscaFunctionComponent implements OnInit { } private loadToscaFunctions(): void { + this.toscaFunctions.push(ToscaGetFunctionType.GET_ATTRIBUTE); this.toscaFunctions.push(ToscaGetFunctionType.GET_INPUT); this.toscaFunctions.push(ToscaGetFunctionType.GET_PROPERTY); } @@ -210,6 +209,8 @@ export class ToscaFunctionComponent implements OnInit { this.dropdownValuesLabel = this.translateService.translate('INPUT_DROPDOWN_LABEL'); } else if (this.isGetPropertySelected()) { this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_PROPERTY_DROPDOWN_LABEL'); + } else if (this.isGetAttributeSelected()) { + this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_ATTRIBUTE_DROPDOWN_LABEL'); } } @@ -231,19 +232,20 @@ export class ToscaFunctionComponent implements OnInit { this.startLoading(); const propertiesObservable: Observable<ComponentGenericResponse> = this.getPropertyObservable(); propertiesObservable.subscribe( (response: ComponentGenericResponse) => { - const properties: PropertyBEModel[] = this.extractProperties(response); + const properties: Array<PropertyBEModel | AttributeModel> = this.extractProperties(response); if (!properties || properties.length === 0) { - const msgCode = this.isGetInputSelected() ? 'TOSCA_FUNCTION_NO_INPUT_FOUND' : 'TOSCA_FUNCTION_NO_PROPERTY_FOUND'; + const msgCode = this.getNotFoundMsgCode(); this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.propertyTypeToString()}); return; } this.addPropertiesToDropdown(properties); if (this.propertyDropdownList.length == 0) { - const msgCode = this.isGetInputSelected() ? 'TOSCA_FUNCTION_NO_INPUT_FOUND' : 'TOSCA_FUNCTION_NO_PROPERTY_FOUND'; + const msgCode = this.getNotFoundMsgCode(); this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.propertyTypeToString()}); } }, (error) => { console.error('An error occurred while loading properties.', error); + this.stopLoading(); }, () => { if (onComplete) { onComplete(); @@ -252,6 +254,20 @@ export class ToscaFunctionComponent implements OnInit { }); } + private getNotFoundMsgCode(): string { + if (this.isGetInputSelected()) { + return 'TOSCA_FUNCTION_NO_INPUT_FOUND'; + } + if (this.isGetAttributeSelected()) { + return 'TOSCA_FUNCTION_NO_ATTRIBUTE_FOUND'; + } + if (this.isGetPropertySelected()) { + return 'TOSCA_FUNCTION_NO_PROPERTY_FOUND'; + } + + return undefined; + } + private propertyTypeToString() { if (this.property.schemaType) { return `${this.property.type} of ${this.property.schemaType}`; @@ -259,7 +275,7 @@ export class ToscaFunctionComponent implements OnInit { return this.property.type; } - private extractProperties(componentGenericResponse: ComponentGenericResponse): PropertyBEModel[] { + private extractProperties(componentGenericResponse: ComponentGenericResponse): Array<PropertyBEModel | AttributeModel> { if (this.isGetInputSelected()) { return componentGenericResponse.inputs; } @@ -270,6 +286,10 @@ export class ToscaFunctionComponent implements OnInit { const componentInstanceProperties: PropertyModel[] = componentGenericResponse.componentInstancesProperties[this.instanceNameAndIdMap.get(this.propertySource)]; return this.removeSelectedProperty(componentInstanceProperties); } + if (this.propertySource === PropertySource.SELF) { + return componentGenericResponse.attributes; + } + return componentGenericResponse.componentInstancesAttributes[this.instanceNameAndIdMap.get(this.propertySource)]; } private getPropertyObservable(): Observable<ComponentGenericResponse> { @@ -282,6 +302,12 @@ export class ToscaFunctionComponent implements OnInit { } return this.topologyTemplateService.getComponentInstanceProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId); } + if (this.isGetAttributeSelected()) { + if (this.propertySource === PropertySource.SELF) { + return this.topologyTemplateService.findAllComponentAttributes(this.componentMetadata.componentType, this.componentMetadata.uniqueId); + } + return this.topologyTemplateService.findAllComponentInstanceAttributes(this.componentMetadata.componentType, this.componentMetadata.uniqueId); + } } private removeSelectedProperty(componentInstanceProperties: PropertyModel[]): PropertyModel[] { @@ -299,7 +325,7 @@ export class ToscaFunctionComponent implements OnInit { this.propertyDropdownList.sort((a, b) => a.propertyLabel.localeCompare(b.propertyLabel)); } - private addPropertiesToDropdown(properties: PropertyBEModel[]): void { + private addPropertiesToDropdown(properties: Array<PropertyBEModel | AttributeModel>): void { for (const property of properties) { if (this.hasSameType(property)) { this.addPropertyToDropdown({ @@ -314,7 +340,8 @@ export class ToscaFunctionComponent implements OnInit { } } - private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel, parentPropertyList: Array<PropertyBEModel> = []): void { + private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel | AttributeModel, + parentPropertyList: Array<PropertyBEModel | AttributeModel> = []): void { const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type); if (!dataTypeFound || !dataTypeFound.properties) { return; @@ -334,7 +361,7 @@ export class ToscaFunctionComponent implements OnInit { }); } - private hasSameType(property: PropertyBEModel) { + private hasSameType(property: PropertyBEModel | AttributeModel) { if (this.typeHasSchema(this.property.type)) { if (!property.schema || !property.schema.property) { return false; @@ -349,6 +376,10 @@ export class ToscaFunctionComponent implements OnInit { return this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY; } + private isGetAttributeSelected(): boolean { + return this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_ATTRIBUTE; + } + private isGetInputSelected(): boolean { return this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_INPUT; } @@ -369,8 +400,8 @@ export class ToscaFunctionComponent implements OnInit { this.isLoading = true; } - showDropdown(): boolean { - if (this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY) { + showPropertyDropdown(): boolean { + if (this.isGetPropertySelected() || this.isGetAttributeSelected()) { return this.toscaGetFunction.propertySource && !this.isLoading && !this.dropDownErrorMsg; } @@ -416,6 +447,10 @@ export class ToscaFunctionComponent implements OnInit { showClearButton(): boolean { return this.allowClear && this.toscaGetFunction.functionType !== undefined; } + + showPropertySourceDropdown(): boolean { + return this.isGetPropertySelected() || this.isGetAttributeSelected(); + } } export interface PropertyDropdownValue { diff --git a/catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts b/catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts index 92a12c8305..a2abb38f65 100644 --- a/catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts +++ b/catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts @@ -22,27 +22,28 @@ */ import * as _ from "lodash"; -import {Injectable, Inject} from '@angular/core'; +import {Inject, Injectable} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/toPromise'; import { + ArtifactModel, + AttributeModel, + Capability, Component, + FilterPropertiesAssignmentData, + IFileDownload, InputBEModel, InstancePropertiesAPIMap, - FilterPropertiesAssignmentData, - ArtifactModel, + OperationModel, PropertyModel, - IFileDownload, - AttributeModel, - Capability, Requirement, BEOperationModel, InterfaceModel + Requirement } from "app/models"; -import {ArtifactGroupType, COMPONENT_FIELDS} from "app/utils"; +import {API_QUERY_PARAMS, ArtifactGroupType, COMPONENT_FIELDS} from "app/utils"; import {ComponentGenericResponse} from "../responses/component-generic-response"; import {InstanceBePropertiesMap} from "../../../models/properties-inputs/property-fe-map"; -import {API_QUERY_PARAMS} from "app/utils"; import {ComponentType, ServerTypeUrl, SERVICE_FIELDS} from "../../../utils/constants"; -import {SdcConfigToken, ISdcConfig} from "../../config/sdc-config.config"; +import {ISdcConfig, SdcConfigToken} from "../../config/sdc-config.config"; import {IDependenciesServerResponse} from "../responses/dependencies-server-response"; import {AutomatedUpgradeGenericResponse} from "../responses/automated-upgrade-response"; import {IAutomatedUpgradeRequestObj} from "../../pages/automated-upgrade/automated-upgrade.service"; @@ -50,26 +51,15 @@ import {ComponentInstance} from "../../../models/componentsInstances/componentIn import {CommonUtils} from "../../../utils/common-utils"; import {RelationshipModel} from "../../../models/graph/relationship"; import {ServiceGenericResponse} from "../responses/service-generic-response"; -import { HttpClient, HttpParams, HttpHeaders } from "@angular/common/http"; -import { HttpHelperService } from "../http-hepler.service"; -import { - Component as TopologyTemplate, - FullComponentInstance, - Service, - OperationModel, -} from 'app/models'; -import { ConsumptionInput } from "../../components/logic/service-consumption/service-consumption.component"; -import { ConstraintObject } from "../../components/logic/service-dependencies/service-dependencies.component"; -import { ComponentMetadata } from "../../../models/component-metadata"; -import { PolicyInstance } from "../../../models/graph/zones/policy-instance"; -import { PropertyBEModel } from "../../../models/properties-inputs/property-be-model"; +import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http"; +import {HttpHelperService} from "../http-hepler.service"; +import {ConsumptionInput} from "../../components/logic/service-consumption/service-consumption.component"; +import {ConstraintObject} from "../../components/logic/service-dependencies/service-dependencies.component"; +import {PolicyInstance} from "../../../models/graph/zones/policy-instance"; +import {PropertyBEModel} from "../../../models/properties-inputs/property-be-model"; import {map} from "rxjs/operators"; import {CapabilitiesConstraintObject} from "../../components/logic/capabilities-constraint/capabilities-constraint.component"; -import { - BEInterfaceOperationModel, - ComponentInterfaceDefinitionModel, - InterfaceOperationModel -} from "../../../models/interfaceOperation"; +import {BEInterfaceOperationModel, InterfaceOperationModel} from "../../../models/interfaceOperation"; import {AttributeBEModel} from "../../../models/attributes-outputs/attribute-be-model"; import {InstanceAttributesAPIMap} from "../../../models/attributes-outputs/attribute-fe-map"; @@ -169,6 +159,10 @@ export class TopologyTemplateService { return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]); } + findAllComponentAttributes(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> { + return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]); + } + getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> { return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]); } @@ -393,7 +387,7 @@ export class TopologyTemplateService { } updateProperty = (componentType: string, componentId: string, property: PropertyModel): Observable<PropertyModel> => { - var propertiesList:PropertyBEModel[] = [property]; + const propertiesList: PropertyBEModel[] = [property]; return this.http.put<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', propertiesList) .map((response) => { return new PropertyModel(response[Object.keys(response)[0]]); @@ -470,6 +464,10 @@ export class TopologyTemplateService { return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]); } + findAllComponentInstanceAttributes(componentType: string, componentId: string): Observable<ComponentGenericResponse> { + return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]); + } + getComponentInstanceCapabilityProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> { return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]); diff --git a/catalog-ui/src/assets/languages/en_US.json b/catalog-ui/src/assets/languages/en_US.json index 238e09958f..96e01dbaf9 100644 --- a/catalog-ui/src/assets/languages/en_US.json +++ b/catalog-ui/src/assets/languages/en_US.json @@ -517,8 +517,10 @@ "TOSCA_FUNCTION_MODAL_TITLE": "Set value using TOSCA functions", "INPUT_DROPDOWN_LABEL": "Input", "TOSCA_FUNCTION_PROPERTY_DROPDOWN_LABEL": "Property", + "TOSCA_FUNCTION_ATTRIBUTE_DROPDOWN_LABEL": "Attribute", "TOSCA_FUNCTION_NO_INPUT_FOUND": "No input found with type {{type}}", "TOSCA_FUNCTION_NO_PROPERTY_FOUND": "No property found with type {{type}}", + "TOSCA_FUNCTION_NO_ATTRIBUTE_FOUND": "No attribute found with type {{type}}", "=========== AUTOMATED UPGRADE ===========": "", "RESOURCE_UPGRADE_TITLE": "Upgrade Services", "SERVICE_UPGRADE_TITLE": "Update Service References", |