2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 import {Component} from '@angular/core';
22 ComponentMetadata, DataTypeModel, PropertyBEModel
24 import {TopologyTemplateService} from "../../../services/component-services/topology-template.service";
25 import {WorkspaceService} from "../../workspace/workspace.service";
26 import {PropertiesService} from "../../../services/properties.service";
27 import {PROPERTY_DATA} from "../../../../utils/constants";
28 import {DataTypeService} from "../../../services/data-type.service";
29 import {ToscaGetFunctionType} from "../../../../models/tosca-get-function-type.enum";
30 import {TranslateService} from "../../../shared/translator/translate.service";
33 selector: 'tosca-function',
34 templateUrl: './tosca-function.component.html',
35 styleUrls: ['./tosca-function.component.less'],
38 export class ToscaFunctionComponent {
44 dropdownValues: Array<PropertyBEModel> = [];
45 toscaFunctions: Array<string> = [];
46 dropdownValuesLabel: string;
48 private dataTypeProperties: Array<PropertyBEModel> = [];
49 private componentMetadata: ComponentMetadata;
51 constructor(private topologyTemplateService: TopologyTemplateService,
52 private workspaceService: WorkspaceService,
53 private propertiesService: PropertiesService,
54 private dataTypeService: DataTypeService,
55 private translateService: TranslateService) {
59 this.componentMetadata = this.workspaceService.metadata;
60 this.propertyType = this.propertiesService.getCheckedPropertyType();
61 this.loadToscaFunctions();
64 private loadToscaFunctions(): void {
65 this.toscaFunctions.push(ToscaGetFunctionType.GET_INPUT.toLowerCase());
68 onToscaFunctionChange(): void {
69 this.loadDropdownValueLabel();
70 this.loadDropdownValues();
73 private loadDropdownValueLabel(): void {
74 if (this.selectToscaFunction) {
75 if (this.selectToscaFunction === ToscaGetFunctionType.GET_INPUT.toLowerCase()) {
76 this.dropdownValuesLabel = this.translateService.translate('INPUT_DROPDOWN_LABEL');
81 private loadDropdownValues(): void {
82 if (this.selectToscaFunction) {
83 this.dropdownValues = [];
84 if (this.selectToscaFunction === ToscaGetFunctionType.GET_INPUT.toLowerCase()) {
85 this.loadInputValues(this.propertyType);
90 private loadInputValues(propertyType: string): void {
91 this.isLoading = true;
92 this.topologyTemplateService.getComponentInputsValues(this.componentMetadata.componentType, this.componentMetadata.uniqueId)
93 .subscribe((response) => {
94 response.inputs.forEach((inputProperty: any) => {
95 if (propertyType === inputProperty.type) {
96 this.dropdownValues.push(inputProperty);
97 } else if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(inputProperty.type) === -1 && inputProperty.type !== propertyType) {
98 this.buildInputDataForComplexType(inputProperty, propertyType);
104 this.isLoading = false;
108 private buildInputDataForComplexType(inputProperty: PropertyBEModel, propertyType: string) {
109 let dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type);
110 if (dataTypeFound && dataTypeFound.properties) {
111 dataTypeFound.properties.forEach(dataTypeProperty => {
112 let inputData = inputProperty.name + "->" + dataTypeProperty.name;
113 dataTypeProperty.name = inputData;
114 if (this.dataTypeProperties.indexOf(dataTypeProperty) === -1 && dataTypeProperty.type === propertyType) {
115 this.dropdownValues.push(dataTypeProperty);