2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
21 import {InstanceFeDetails} from "../../../../models/instance-fe-details";
22 import {ModalService} from "../../../services/modal.service";
23 import {DataTypeService} from "../../../services/data-type.service";
24 import {TranslateService} from "../../../shared/translator/translate.service";
25 import {InstanceFeAttributesMap} from "app/models/attributes-outputs/attribute-fe-map";
26 import {Select} from "@ngxs/store";
27 import {WorkspaceState} from "../../../store/states/workspace.state";
28 import {OutputFEModel} from "app/models/attributes-outputs/output-fe-model";
29 import {InputFEModel} from "../../../../models/properties-inputs/input-fe-model";
32 selector: 'outputs-table',
33 templateUrl: './outputs-table.component.html',
34 styleUrls: ['./outputs-table.component.less']
36 export class OutputsTableComponent implements OnInit {
37 @Select(WorkspaceState.isViewOnly)
40 @ViewChild('componentOutputsTable')
43 @Input() outputs: Array<OutputFEModel>;
44 @Input() instanceNamesMap: Map<string, InstanceFeDetails>;
45 @Input() readonly: boolean;
46 @Input() isLoading: boolean;
47 @Input() componentType: string;
48 @Output() outputChanged: EventEmitter<any> = new EventEmitter<any>();
49 @Output() deleteOutput: EventEmitter<any> = new EventEmitter<any>();
50 @Input() feAttributesMap: InstanceFeAttributesMap;
52 deleteMsgTitle: string;
53 deleteMsgBodyTxt: string;
54 modalDeleteBtn: string;
55 modalCancelBtn: string;
58 selectedOutputToDelete: OutputFEModel;
60 constructor(private modalService: ModalService,
61 private dataTypeService: DataTypeService,
62 private translateService: TranslateService) {
66 this.translateService.languageChangedObservable.subscribe((lang) => {
67 this.deleteMsgTitle = this.translateService.translate('DELETE_OUTPUT_TITLE');
68 this.modalDeleteBtn = this.translateService.translate('MODAL_DELETE');
69 this.modalCancelBtn = this.translateService.translate('MODAL_CANCEL');
75 this.reverse = (this.sortBy === sortBy) ? !this.reverse : true;
76 let reverse = this.reverse ? 1 : -1;
78 let instanceNameMapTemp = this.instanceNamesMap;
81 this.outputs.sort(function (itemIdx1, itemIdx2) {
82 if (sortBy == 'instanceUniqueId') {
83 itemIdx1Val = (itemIdx1[sortBy] && instanceNameMapTemp[itemIdx1[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx1[sortBy]].name : "";
84 itemIdx2Val = (itemIdx2[sortBy] && instanceNameMapTemp[itemIdx2[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx2[sortBy]].name : "";
86 itemIdx1Val = itemIdx1[sortBy];
87 itemIdx2Val = itemIdx2[sortBy];
89 if (itemIdx1Val < itemIdx2Val) {
91 } else if (itemIdx1Val > itemIdx2Val) {
99 onOutputChanged = (output, event) => {
100 output.updateDefaultValueObj(event.value, event.isValid);
101 this.outputChanged.emit(output);
104 onRequiredChanged = (output: OutputFEModel, event) => {
105 this.outputChanged.emit(output);
108 onDeleteOutput = () => {
109 this.deleteOutput.emit(this.selectedOutputToDelete);
110 this.modalService.closeCurrentModal();
113 openDeleteModal = (output: OutputFEModel) => {
114 this.selectedOutputToDelete = output;
115 this.modalService.createActionModal("Delete Output", "Are you sure you want to delete this output?", "Delete", this.onDeleteOutput, "Close").instance.open();
118 getConstraints(output: OutputFEModel): string[] {
119 if (output.outputPath) {
120 const pathValuesName = output.outputPath.split('#');
121 const rootPropertyName = pathValuesName[0];
122 const propertyName = pathValuesName[1];
123 let filteredRootPropertyType = _.values(this.feAttributesMap)[0].filter(property =>
124 property.name == rootPropertyName);
125 if (filteredRootPropertyType.length > 0) {
126 let rootPropertyType = filteredRootPropertyType[0].type;
127 return this.dataTypeService.getConstraintsByParentTypeAndUniqueID(rootPropertyType, propertyName);
137 checkInstanceFeAttributesMapIsFilled() {
138 return _.keys(this.feAttributesMap).length > 0