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";
29 selector: 'input-list',
30 templateUrl: './input-list.component.html',
31 styleUrls: ['./input-list.component.less']
33 export class InputListComponent {
35 @Input() set inputs(inputs: Array<InputOperationParameter>) {
36 this._inputs = new Array<InputOperationParameter>();
38 inputs.forEach(input => {
39 const inputCopy = new InputOperationParameter(input);
40 this.initValue(inputCopy);
42 this._inputs.push(inputCopy);
46 @Input() dataTypeMap: Map<string, DataTypeModel>;
47 @Input() isViewOnly: boolean;
48 @Input() title: string;
49 @Input() emptyMessage: string;
50 @Input() allowDeletion: boolean = false;
51 @Output('onValueChange') inputValueChangeEvent: EventEmitter<InputOperationParameter> = new EventEmitter<InputOperationParameter>();
52 @Output('onDelete') inputDeleteEvent: EventEmitter<string> = new EventEmitter<string>();
54 _inputs: Array<InputOperationParameter> = [];
56 getDataType(type: string): DataTypeModel {
57 return this.dataTypeMap.get(type);
60 private initValue(input: InputOperationParameter): void {
63 input.value = JSON.parse(input.value);
65 console.debug('Could not parse value', input.value, e);
70 if (input.toscaDefaultValue) {
72 input.value = JSON.parse(input.toscaDefaultValue);
75 console.debug('Could not parse value', input.value, e);
79 if (this.isTypeComplex(input.type) || this.isTypeMap(input.type)) {
81 } else if (this.isTypeList(input.type)) {
84 input.value = undefined;
88 getType(typeName: string): DerivedPropertyType {
89 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(typeName) > -1) {
90 return DerivedPropertyType.SIMPLE;
91 } else if (typeName === PROPERTY_TYPES.LIST) {
92 return DerivedPropertyType.LIST;
93 } else if (typeName === PROPERTY_TYPES.MAP) {
94 return DerivedPropertyType.MAP;
96 return DerivedPropertyType.COMPLEX;
100 isTypeSimple(typeName: string): boolean {
101 return this.getType(typeName) == DerivedPropertyType.SIMPLE;
104 isTypeList(typeName: string): boolean {
105 return this.getType(typeName) == DerivedPropertyType.LIST;
108 isTypeMap(typeName: string): boolean {
109 return this.getType(typeName) == DerivedPropertyType.MAP;
112 isTypeComplex(typeName: string): boolean {
113 return !this.isTypeSimple(typeName) && !this.isTypeList(typeName) && !this.isTypeMap(typeName);
116 onValueChange($event: any) {
117 const inputOperationParameter = this._inputs.find(input => input.name == $event.name);
118 if (inputOperationParameter) {
119 inputOperationParameter.value = $event.value;
120 this.inputValueChangeEvent.emit(new InputOperationParameter(inputOperationParameter));
124 onDelete(inputName: string) {
125 this.inputDeleteEvent.emit(inputName);