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";
31 selector: 'outputs-table',
32 templateUrl: './outputs-table.component.html',
33 styleUrls: ['./outputs-table.component.less']
35 export class OutputsTableComponent implements OnInit {
36 @Select(WorkspaceState.isViewOnly)
39 @ViewChild('componentOutputsTable')
42 @Input() outputs: Array<OutputFEModel>;
43 @Input() instanceNamesMap: Map<string, InstanceFeDetails>;
44 @Input() readonly: boolean;
45 @Input() isLoading: boolean;
46 @Input() componentType: string;
47 @Output() outputChanged: EventEmitter<any> = new EventEmitter<any>();
48 @Output() deleteOutput: EventEmitter<any> = new EventEmitter<any>();
49 @Input() feAttributesMap: InstanceFeAttributesMap;
51 deleteMsgTitle: string;
52 modalDeleteBtn: string;
53 modalCancelBtn: string;
56 selectedOutputToDelete: OutputFEModel;
58 constructor(private modalService: ModalService,
59 private dataTypeService: DataTypeService,
60 private translateService: TranslateService) {
64 this.translateService.languageChangedObservable.subscribe((lang) => {
65 this.deleteMsgTitle = this.translateService.translate('DELETE_OUTPUT_TITLE');
66 this.modalDeleteBtn = this.translateService.translate('MODAL_DELETE');
67 this.modalCancelBtn = this.translateService.translate('MODAL_CANCEL');
73 this.reverse = (this.sortBy === sortBy) ? !this.reverse : true;
74 let reverse = this.reverse ? 1 : -1;
76 let instanceNameMapTemp = this.instanceNamesMap;
79 this.outputs.sort(function (itemIdx1, itemIdx2) {
80 if (sortBy == 'instanceUniqueId') {
81 itemIdx1Val = (itemIdx1[sortBy] && instanceNameMapTemp[itemIdx1[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx1[sortBy]].name : "";
82 itemIdx2Val = (itemIdx2[sortBy] && instanceNameMapTemp[itemIdx2[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx2[sortBy]].name : "";
84 itemIdx1Val = itemIdx1[sortBy];
85 itemIdx2Val = itemIdx2[sortBy];
87 if (itemIdx1Val < itemIdx2Val) {
89 } else if (itemIdx1Val > itemIdx2Val) {
97 onOutputChanged = (output, event) => {
98 output.updateDefaultValueObj(event.value, event.isValid);
99 this.outputChanged.emit(output);
102 onRequiredChanged = (output: OutputFEModel, event) => {
103 this.outputChanged.emit(output);
106 onDeleteOutput = () => {
107 this.deleteOutput.emit(this.selectedOutputToDelete);
108 this.modalService.closeCurrentModal();
111 openDeleteModal = (output: OutputFEModel) => {
112 this.selectedOutputToDelete = output;
113 this.modalService.createActionModal("Delete Output", "Are you sure you want to delete this output?", "Delete", this.onDeleteOutput, "Close").instance.open();
116 getConstraints(output: OutputFEModel): string[] {
117 if (output.outputPath) {
118 const pathValuesName = output.outputPath.split('#');
119 const rootPropertyName = pathValuesName[0];
120 const propertyName = pathValuesName[1];
121 let filteredRootPropertyType = _.values(this.feAttributesMap)[0].filter(property =>
122 property.name == rootPropertyName);
123 if (filteredRootPropertyType.length > 0) {
124 let rootPropertyType = filteredRootPropertyType[0].type;
125 return this.dataTypeService.getConstraintsByParentTypeAndUniqueID(rootPropertyType, propertyName);
135 checkInstanceFeAttributesMapIsFilled() {
136 return _.keys(this.feAttributesMap).length > 0