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";
30 selector: 'input-list',
31 templateUrl: './input-list.component.html',
32 styleUrls: ['./input-list.component.less']
34 export class InputListComponent {
36 @Input() set inputs(inputs: Array<InputOperationParameter>) {
37 this._inputs = new Array<InputOperationParameter>();
39 inputs.forEach(input => {
40 const inputCopy = new InputOperationParameter(input);
41 this.initValue(inputCopy);
43 this._inputs.push(inputCopy);
47 @Input() dataTypeMap: Map<string, DataTypeModel>;
48 @Input() isViewOnly: boolean;
49 @Input() title: string;
50 @Input() emptyMessage: string;
51 @Input() showToscaFunctionOption: boolean = false;
52 @Input() allowDeletion: boolean = false;
53 @Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map();
54 @Output('onInputsValidityChange') inputsValidityChangeEvent: EventEmitter<boolean> = new EventEmitter<boolean>();
55 @Output('onValueChange') inputValueChangeEvent: EventEmitter<InputOperationParameter> = new EventEmitter<InputOperationParameter>();
56 @Output('onDelete') inputDeleteEvent: EventEmitter<string> = new EventEmitter<string>();
58 _inputs: Array<InputOperationParameter> = [];
60 getDataType(type: string): DataTypeModel {
61 return this.dataTypeMap.get(type);
64 private initValue(input: InputOperationParameter): void {
67 input.value = JSON.parse(input.value);
69 console.debug('Could not parse value', input.value, e);
74 if (input.toscaDefaultValue) {
76 input.value = JSON.parse(input.toscaDefaultValue);
79 console.debug('Could not parse value', input.value, e);
83 if (this.isTypeComplex(input.type) || this.isTypeMap(input.type)) {
85 } else if (this.isTypeList(input.type)) {
88 input.value = undefined;
92 getType(typeName: string): DerivedPropertyType {
93 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(typeName) > -1) {
94 return DerivedPropertyType.SIMPLE;
95 } else if (typeName === PROPERTY_TYPES.LIST) {
96 return DerivedPropertyType.LIST;
97 } else if (typeName === PROPERTY_TYPES.MAP) {
98 return DerivedPropertyType.MAP;
100 return DerivedPropertyType.COMPLEX;
104 isTypeSimple(typeName: string): boolean {
105 return this.getType(typeName) == DerivedPropertyType.SIMPLE;
108 isTypeList(typeName: string): boolean {
109 return this.getType(typeName) == DerivedPropertyType.LIST;
112 isTypeMap(typeName: string): boolean {
113 return this.getType(typeName) == DerivedPropertyType.MAP;
116 isTypeComplex(typeName: string): boolean {
117 return !this.isTypeSimple(typeName) && !this.isTypeList(typeName) && !this.isTypeMap(typeName);
120 onValueChange($event: any) {
121 const inputOperationParameter = this._inputs.find(input => input.name == $event.name);
122 if (inputOperationParameter) {
123 inputOperationParameter.valid = true;
124 if ($event.isToscaFunction) {
125 inputOperationParameter.toscaFunction = $event.value;
126 if (!inputOperationParameter.toscaFunction) {
127 inputOperationParameter.valid = false;
130 inputOperationParameter.value = $event.value;
131 inputOperationParameter.toscaFunction = null;
133 this.inputsValidityChangeEvent.emit(this._inputs.every(input => input.valid === true));
134 this.inputValueChangeEvent.emit(new InputOperationParameter(inputOperationParameter));
138 onDelete(inputName: string) {
139 this.inputDeleteEvent.emit(inputName);