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, Input, OnInit} from '@angular/core';
23 import {DataTypeModel} from "../../../../models/data-types";
24 import {DataTypeService} from "../../../services/data-type.service";
25 import {PropertyBEModel} from "../../../../models/properties-inputs/property-be-model";
26 import { Subject } from "rxjs";
27 import {debounceTime, distinctUntilChanged} from "rxjs/operators";
30 selector: 'app-type-workspace-properties',
31 templateUrl: './type-workspace-properties.component.html',
32 styleUrls: ['./type-workspace-properties.component.less']
34 export class TypeWorkspacePropertiesComponent implements OnInit {
35 @Input() isViewOnly = true;
36 @Input() dataType: DataTypeModel = new DataTypeModel();
38 properties: Array<PropertyBEModel> = [];
39 filteredProperties: Array<PropertyBEModel> = [];
40 tableHeadersList: Array<TableHeader> = [];
41 tableSortBy: string = 'name';
42 tableColumnReverse: boolean = false;
43 tableFilterTerm: string = undefined;
44 tableSearchTermUpdate = new Subject<string>();
46 constructor(private dataTypeService: DataTypeService) { }
50 this.initProperties();
51 this.tableSearchTermUpdate.pipe(
53 distinctUntilChanged())
54 .subscribe(searchTerm => {
55 this.filter(searchTerm);
59 private initTable(): void {
60 this.tableHeadersList = [
61 {title: 'Name', property: 'name'},
62 {title: 'Type', property: 'type'},
63 {title: 'Schema', property: 'schema.property.type'},
64 {title: 'Description', property: 'description'},
67 this.tableSortBy = this.tableHeadersList[0].property;
70 private initProperties(): void {
71 this.dataTypeService.findAllProperties(this.dataType.uniqueId).subscribe(properties => {
72 this.properties = properties.map(value => new PropertyBEModel(value));
73 this.filteredProperties = Array.from(this.properties);
78 onUpdateSort(property: string): void {
79 if (this.tableSortBy === property) {
80 this.tableColumnReverse = !this.tableColumnReverse;
82 this.tableColumnReverse = false;
83 this.tableSortBy = property;
88 private sort(): void {
89 const field = this.tableSortBy;
90 this.filteredProperties = this.filteredProperties.sort((property1, property2) => {
91 const result = property1[field] > property2[field] ? 1 : property1[field] < property2[field] ? -1 : 0;
92 return this.tableColumnReverse ? result * -1 : result;
96 private filter(searchTerm: string): void {
98 searchTerm = searchTerm.toLowerCase();
99 this.filteredProperties = this.properties.filter(property =>
100 property.name.toLowerCase().includes(searchTerm)
101 || property.type.toLowerCase().includes(searchTerm)
102 || (property.getSchemaType() && property.getSchemaType().toLowerCase().includes(searchTerm))
103 || (property.description && property.description.toLowerCase().includes(searchTerm))
106 this.filteredProperties = Array.from(this.properties);
112 interface TableHeader {