3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2022 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * 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=========================================================
22 import {Component, EventEmitter, Input, Output} from '@angular/core';
23 import {InputOperationParameter} from "../../../../../../models/interfaceOperation";
24 import {DataTypeModel} from "../../../../../../models/data-types";
25 import {DerivedPropertyType} from "../../../../../../models/properties-inputs/property-be-model";
26 import {PROPERTY_DATA, PROPERTY_TYPES} from "../../../../../../utils/constants";
27 import {InstanceFeDetails} from "../../../../../../models/instance-fe-details";
28 import {CustomToscaFunction} from "../../../../../../models/default-custom-functions";
31 selector: 'input-list',
32 templateUrl: './input-list.component.html',
33 styleUrls: ['./input-list.component.less']
35 export class InputListComponent {
37 @Input() set inputs(inputs: Array<InputOperationParameter>) {
38 this._inputs = new Array<InputOperationParameter>();
40 inputs.forEach(input => {
41 const inputCopy = new InputOperationParameter(input);
42 this.initValue(inputCopy);
44 this._inputs.push(inputCopy);
48 @Input() dataTypeMap: Map<string, DataTypeModel>;
49 @Input() isViewOnly: boolean;
50 @Input() title: string;
51 @Input() emptyMessage: string;
52 @Input() showToscaFunctionOption: boolean = false;
53 @Input() allowDeletion: boolean = false;
54 @Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map();
55 @Input() customToscaFunctions: Array<CustomToscaFunction> = [];
56 @Output('onInputsValidityChange') inputsValidityChangeEvent: EventEmitter<boolean> = new EventEmitter<boolean>();
57 @Output('onValueChange') inputValueChangeEvent: EventEmitter<InputOperationParameter> = new EventEmitter<InputOperationParameter>();
58 @Output('onDelete') inputDeleteEvent: EventEmitter<string> = new EventEmitter<string>();
60 _inputs: Array<InputOperationParameter> = [];
62 getDataType(type: string): DataTypeModel {
63 return this.dataTypeMap.get(type);
66 private initValue(input: InputOperationParameter): void {
69 input.value = JSON.parse(input.value);
71 console.debug('Could not parse value', input.value, e);
76 if (input.toscaDefaultValue) {
78 input.value = JSON.parse(input.toscaDefaultValue);
81 console.debug('Could not parse value', input.value, e);
85 if (this.isTypeComplex(input.type) || this.isTypeMap(input.type)) {
87 } else if (this.isTypeList(input.type)) {
90 input.value = undefined;
94 getType(typeName: string): DerivedPropertyType {
95 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(typeName) > -1) {
96 return DerivedPropertyType.SIMPLE;
97 } else if (typeName === PROPERTY_TYPES.LIST) {
98 return DerivedPropertyType.LIST;
99 } else if (typeName === PROPERTY_TYPES.MAP) {
100 return DerivedPropertyType.MAP;
102 return DerivedPropertyType.COMPLEX;
106 isTypeSimple(typeName: string): boolean {
107 return this.getType(typeName) == DerivedPropertyType.SIMPLE;
110 isTypeList(typeName: string): boolean {
111 return this.getType(typeName) == DerivedPropertyType.LIST;
114 isTypeMap(typeName: string): boolean {
115 return this.getType(typeName) == DerivedPropertyType.MAP;
118 isTypeComplex(typeName: string): boolean {
119 return !this.isTypeSimple(typeName) && !this.isTypeList(typeName) && !this.isTypeMap(typeName);
122 onValueChange($event: any) {
123 const inputOperationParameter = this._inputs.find(input => input.name == $event.name);
124 if (inputOperationParameter) {
125 inputOperationParameter.valid = true;
126 if ($event.isToscaFunction) {
127 inputOperationParameter.toscaFunction = $event.value;
128 if (!inputOperationParameter.toscaFunction) {
129 inputOperationParameter.valid = false;
132 inputOperationParameter.value = $event.value;
133 inputOperationParameter.toscaFunction = null;
135 this.inputsValidityChangeEvent.emit(this._inputs.every(input => input.valid === true));
136 this.inputValueChangeEvent.emit(new InputOperationParameter(inputOperationParameter));
140 onDelete(inputName: string) {
141 this.inputDeleteEvent.emit(inputName);