*/
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";
'toscaGetFunction': this.toscaGetFunctionForm
});
- TOSCA_FUNCTION_GET_PROPERTY = ToscaGetFunctionType.GET_PROPERTY;
-
selectedProperty: PropertyDropdownValue;
isLoading: boolean = false;
propertyDropdownList: Array<PropertyDropdownValue> = [];
}
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 {
}
private loadToscaFunctions(): void {
+ this.toscaFunctions.push(ToscaGetFunctionType.GET_ATTRIBUTE);
this.toscaFunctions.push(ToscaGetFunctionType.GET_INPUT);
this.toscaFunctions.push(ToscaGetFunctionType.GET_PROPERTY);
}
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');
}
}
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();
});
}
+ 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}`;
return this.property.type;
}
- private extractProperties(componentGenericResponse: ComponentGenericResponse): PropertyBEModel[] {
+ private extractProperties(componentGenericResponse: ComponentGenericResponse): Array<PropertyBEModel | AttributeModel> {
if (this.isGetInputSelected()) {
return componentGenericResponse.inputs;
}
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> {
}
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[] {
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({
}
}
- 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;
});
}
- private hasSameType(property: PropertyBEModel) {
+ private hasSameType(property: PropertyBEModel | AttributeModel) {
if (this.typeHasSchema(this.property.type)) {
if (!property.schema || !property.schema.property) {
return false;
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;
}
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;
}
showClearButton(): boolean {
return this.allowClear && this.toscaGetFunction.functionType !== undefined;
}
+
+ showPropertySourceDropdown(): boolean {
+ return this.isGetPropertySelected() || this.isGetAttributeSelected();
+ }
}
export interface PropertyDropdownValue {