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 } 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";
33 selector: 'inputs-table',
34 templateUrl: './inputs-table.component.html',
35 styleUrls: ['../inputs-table/inputs-table.component.less'],
37 export class InputsTableComponent {
39 @Input() inputs: Array<InputFEModel>;
40 @Input() instanceNamesMap: Map<string, InstanceFeDetails>;
41 @Input() readonly: boolean;
42 @Input() isLoading: boolean;
43 @Output() inputChanged: EventEmitter<any> = new EventEmitter<any>();
44 @Output() deleteInput: EventEmitter<any> = new EventEmitter<any>();
46 @Input() fePropertiesMap: InstanceFePropertiesMap;
50 selectedInputToDelete: InputFEModel;
53 this.reverse = (this.sortBy === sortBy) ? !this.reverse : true;
54 let reverse = this.reverse ? 1 : -1;
56 let instanceNameMapTemp = this.instanceNamesMap;
59 this.inputs.sort(function (itemIdx1, itemIdx2) {
60 if (sortBy == 'instanceUniqueId') {
61 itemIdx1Val = (itemIdx1[sortBy] && instanceNameMapTemp[itemIdx1[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx1[sortBy]].name : "";
62 itemIdx2Val = (itemIdx2[sortBy] && instanceNameMapTemp[itemIdx2[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx2[sortBy]].name : "";
65 itemIdx1Val = itemIdx1[sortBy];
66 itemIdx2Val = itemIdx2[sortBy];
68 if (itemIdx1Val < itemIdx2Val) {
71 else if (itemIdx1Val > itemIdx2Val) {
81 constructor(private modalService: ModalService, private dataTypeService: DataTypeService){
86 onInputChanged = (input, event) => {
87 input.updateDefaultValueObj(event.value, event.isValid);
88 this.inputChanged.emit(input);
91 onDeleteInput = () => {
92 this.deleteInput.emit(this.selectedInputToDelete);
93 this.modalService.closeCurrentModal();
96 openDeleteModal = (input: InputFEModel) => {
97 console.log('exist inputs: ' + this.inputs)
100 this.selectedInputToDelete = input;
101 this.modalService.createActionModal("Delete Input", "Are you sure you want to delete this input?", "Delete", this.onDeleteInput, "Close").instance.open();
104 getConstraints(input:InputFEModel): string[]{
106 if (input.inputPath){
107 const pathValuesName = input.inputPath.split('#');
108 const rootPropertyName = pathValuesName[0];
109 const propertyName = pathValuesName[1];
110 let filterredRootPropertyType = _.values(this.fePropertiesMap)[0].filter(property =>
111 property.name == rootPropertyName);
112 if (filterredRootPropertyType.length > 0){
113 let rootPropertyType = filterredRootPropertyType[0].type;
114 return this.dataTypeService.getConstraintsByParentTypeAndUniqueID(rootPropertyType, propertyName);
120 // else if(input.constraints.length > 0){
121 // return input.constraints[0].validValues
128 checkInstanceFePropertiesMapIsFilled(){
129 return _.keys(this.fePropertiesMap).length > 0