2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
23 * Created by rc2122 on 5/4/2017.
25 import { Component, Input, Output, EventEmitter, ViewChildren, QueryList } from "@angular/core";
26 import { InputFEModel } from "app/models";
27 import { ModalService } from "../../../services/modal.service";
28 import { InstanceFeDetails } from "app/models/instance-fe-details";
29 import { InstanceFePropertiesMap } from "../../../../models/properties-inputs/property-fe-map";
30 import { DataTypeService } from "../../../services/data-type.service";
31 import { MetadataEntry } from "app/models/metadataEntry";
32 import { DynamicElementComponent } from "../../ui/dynamic-element/dynamic-element.component";
35 selector: 'inputs-table',
36 templateUrl: './inputs-table.component.html',
37 styleUrls: ['../inputs-table/inputs-table.component.less'],
39 export class InputsTableComponent {
41 @Input() inputs: Array<InputFEModel>;
42 @Input() instanceNamesMap: Map<string, InstanceFeDetails>;
43 @Input() readonly: boolean;
44 @Input() isLoading: boolean;
45 @Input() componentType: string;
47 @Output() inputChanged: EventEmitter<any> = new EventEmitter<any>();
48 @Output() deleteInput: EventEmitter<any> = new EventEmitter<any>();
50 @Input() fePropertiesMap: InstanceFePropertiesMap;
52 @ViewChildren('metadataViewChildren') public metadataViewChildren: QueryList<DynamicElementComponent>;
56 selectedInputToDelete: InputFEModel;
59 this.reverse = (this.sortBy === sortBy) ? !this.reverse : true;
60 let reverse = this.reverse ? 1 : -1;
62 let instanceNameMapTemp = this.instanceNamesMap;
65 this.inputs.sort(function (itemIdx1, itemIdx2) {
66 if (sortBy == 'instanceUniqueId') {
67 itemIdx1Val = (itemIdx1[sortBy] && instanceNameMapTemp[itemIdx1[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx1[sortBy]].name : "";
68 itemIdx2Val = (itemIdx2[sortBy] && instanceNameMapTemp[itemIdx2[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx2[sortBy]].name : "";
71 itemIdx1Val = itemIdx1[sortBy];
72 itemIdx2Val = itemIdx2[sortBy];
74 if (itemIdx1Val < itemIdx2Val) {
77 else if (itemIdx1Val > itemIdx2Val) {
87 constructor(private modalService: ModalService, private dataTypeService: DataTypeService){
92 onInputChanged = (input, event) => {
93 input.updateDefaultValueObj(event.value, event.isValid);
94 this.inputChanged.emit(input);
97 onRequiredChanged = (input: InputFEModel, event) => {
98 this.inputChanged.emit(input);
101 onMetadataKeyChanged = (input: InputFEModel, event, metadataEntry: MetadataEntry) => {
102 let dynamicElementComponent = this.metadataViewChildren.filter(element => element.name == input.name + "_" + metadataEntry.key).pop();
104 input.updateMetadataKey(metadataEntry, event.value);
105 this.inputChanged.emit(input);
107 var mapKeyError = input.metadataMapKeyError;
108 if(input.metadataMapKeyError){
109 dynamicElementComponent.cmpRef.instance.control.setErrors({mapKeyError});
113 onMetadataValueChanged = (input: InputFEModel, event, metadataEntry: MetadataEntry) => {
114 input.updateMetadataValue(metadataEntry, event.value);
115 this.inputChanged.emit(input);
119 createNewMetadataEntry = (input: InputFEModel): void => {
120 let metadataEntry = new MetadataEntry("", "");
121 input.addMetadataEntry(metadataEntry);
122 this.inputChanged.emit(input);
125 deleteMetadataEntry = (input: InputFEModel, metadataEntry: MetadataEntry) => {
126 input.deleteMetadataEntry(metadataEntry);
127 this.inputChanged.emit(input);
130 onDeleteInput = () => {
131 this.deleteInput.emit(this.selectedInputToDelete);
132 this.modalService.closeCurrentModal();
135 openDeleteModal = (input: InputFEModel) => {
136 console.log('exist inputs: ' + this.inputs)
137 this.selectedInputToDelete = input;
138 this.modalService.createActionModal("Delete Input", "Are you sure you want to delete this input?", "Delete", this.onDeleteInput, "Close").instance.open();
141 getConstraints(input:InputFEModel): string[]{
143 if (input.inputPath){
144 const pathValuesName = input.inputPath.split('#');
145 const rootPropertyName = pathValuesName[0];
146 const propertyName = pathValuesName[1];
147 let filterredRootPropertyType = _.values(this.fePropertiesMap)[0].filter(property =>
148 property.name == rootPropertyName);
149 if (filterredRootPropertyType.length > 0){
150 let rootPropertyType = filterredRootPropertyType[0].type;
151 return this.dataTypeService.getConstraintsByParentTypeAndUniqueID(rootPropertyType, propertyName);
157 // else if(input.constraints.length > 0){
158 // return input.constraints[0].validValues
165 checkInstanceFePropertiesMapIsFilled(){
166 return _.keys(this.fePropertiesMap).length > 0
170 for(let input of this.inputs){
171 if (input.metadataEntries.length > 0){