2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2022 Nordix Foundation. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 import {Component, Input} from '@angular/core';
22 import {DataTypeService} from "app/ng2/services/data-type.service";
32 } from "app/ng2/components/ui/form-components/dropdown/ui-element-dropdown.component";
33 import {WorkspaceService} from "../../../workspace/workspace.service";
35 class DropdownValueType extends DropdownValue {
38 constructor(value: string, label: string, type?: string) {
47 selector: 'param-row',
48 templateUrl: './param-row.component.html',
49 styleUrls: ['./param-row.component.less']
52 export class ParamRowComponent {
53 @Input() param: OperationParameter;
54 @Input() inputProps: Array<InputBEModel>;
55 @Input() operationOutputs: Array<OperationModel>;
56 @Input() capabilitiesProps: Array<Capability>;
57 @Input() onRemoveParam: Function;
58 @Input() isAssociateWorkflow: boolean;
59 @Input() readonly: boolean;
60 @Input() isInputParam: boolean;
61 @Input() validityChanged: Function;
63 propTypeEnum: Array<string> = [];
64 operationOutputCats: Array<{ operationName: string, outputs: Array<DropdownValueType> }> = [];
65 filteredInputProps: Array<DropdownValue> = [];
66 filteredCapabilitiesProps: Array<{ capabilityName: string, properties: Array<DropdownValueType> }> = [];
68 constructor(private dataTypeService: DataTypeService, protected workspaceService: WorkspaceService) {
72 if (this.isInputParam) {
73 this.propTypeEnum = _.uniq(
76 this.getPrimitiveSubtypes(),
78 this.operationOutputs,
79 (acc, op) => [...acc, ...op.outputs.listToscaDataDefinition],
82 this.capabilitiesProps,
83 (acc, capab) => [...acc, ...capab.properties],
90 const dataTypes: Array<DataTypeModel> = _.toArray(this.dataTypeService.getDataTypeByModel(this.workspaceService.metadata.model));
91 this.propTypeEnum = _.concat(
95 type => this.isTypePrimitive(type.name)
102 type => !this.isTypePrimitive(type.name)
110 this.validityChanged();
114 this.validityChanged();
118 if (!this.isInputParam) {
119 this.validityChanged();
123 this.filteredInputProps = _.map(
125 this.getPrimitiveSubtypes(),
126 prop => !this.param.type || prop.type === this.param.type
128 prop => new DropdownValue(prop.uniqueId, prop.name)
130 this.filteredInputProps.unshift(new DropdownValue("", ""));
132 this.operationOutputCats = _.filter(
134 this.operationOutputs,
137 operationName: `${op.displayType()}.${op.name}`,
139 _.filter(op.outputs.listToscaDataDefinition, output => !this.param.type || output.type === this.param.type),
140 output => new DropdownValueType(
141 `${op.interfaceType}.${op.name}.${output.name}`,
149 category => category.outputs.length > 0
152 this.filteredCapabilitiesProps = _.filter(
154 this.capabilitiesProps,
157 capabilityName: cap.name,
159 _.filter(cap.properties, prop => !this.param.type || prop.type === this.param.type),
160 prop => new DropdownValueType(
169 capability => capability.properties.length > 0
172 if (this.param.inputId) {
173 const selProp = this.getSelectedProp();
174 if (selProp && selProp.type === this.param.type) {
175 this.param.inputId = '-1';
176 setTimeout(() => this.param.inputId = selProp.uniqueId || selProp.value);
178 this.param.inputId = null;
182 this.validityChanged();
186 const newProp = this.getSelectedProp();
188 if (!this.param.type) {
189 this.param.type = newProp.type;
193 if (!this.param.name) {
194 this.param.name = newProp.name || newProp.label;
197 this.validityChanged();
200 getPrimitiveSubtypes(): Array<InputBEModel> {
201 const flattenedProps: Array<any> = [];
202 const dataTypes = this.dataTypeService.getDataTypeByModel(this.workspaceService.metadata.model);
204 _.forEach(this.inputProps, prop => {
205 const type: DataTypeModel = _.find(
206 _.toArray(dataTypes),
207 (type: DataTypeModel) => type.name === prop.type
209 flattenedProps.push(prop);
211 console.error('Could not find prop in dataTypes: ', prop);
213 if (type.properties) {
214 _.forEach(type.properties, subType => {
215 if (this.isTypePrimitive(subType.type)) {
216 flattenedProps.push({
218 name: `${prop.name}.${subType.name}`,
219 uniqueId: `${prop.uniqueId}.${subType.name}`
227 return flattenedProps;
232 this.getPrimitiveSubtypes(),
233 prop => this.param.inputId === prop.uniqueId
236 this.operationOutputCats,
237 (acc, cat) => [...acc, ...cat.outputs],
239 (out: DropdownValueType) => this.param.inputId === out.value
242 this.filteredCapabilitiesProps,
243 (acc, cap) => [...acc, ...cap.properties],
245 (prop: DropdownValueType) => this.param.inputId === prop.value
249 isTypePrimitive(type: string): boolean {
252 type === 'integer' ||