|
|
@ -1,5 +1,6 @@
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
Component,
|
|
|
|
|
|
|
|
ElementRef,
|
|
|
|
EventEmitter,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
Input,
|
|
|
|
Output,
|
|
|
|
Output,
|
|
|
@ -11,7 +12,7 @@ import { SchemaService } from 'src/app/services/schema.service';
|
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
|
|
import { customTableFilterFunction } from 'src/app/helperFunctions/customTableFilterFunction';
|
|
|
|
import { Subject } from 'rxjs/internal/Subject';
|
|
|
|
import { Subject } from 'rxjs/internal/Subject';
|
|
|
|
import { debounceTime } from 'rxjs/internal/operators/debounceTime';
|
|
|
|
import { debounceTime } from 'rxjs/internal/operators/debounceTime';
|
|
|
|
|
|
|
|
|
|
|
@ -28,6 +29,7 @@ export class ReferenceTableComponent {
|
|
|
|
translation: string;
|
|
|
|
translation: string;
|
|
|
|
sticky?: boolean;
|
|
|
|
sticky?: boolean;
|
|
|
|
type?: string;
|
|
|
|
type?: string;
|
|
|
|
|
|
|
|
list?: boolean; //whether the type is a list
|
|
|
|
link?: (row: any) => string;
|
|
|
|
link?: (row: any) => string;
|
|
|
|
}[] = [];
|
|
|
|
}[] = [];
|
|
|
|
|
|
|
|
|
|
|
@ -77,6 +79,9 @@ export class ReferenceTableComponent {
|
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild('filterRow', { read: ElementRef }) filterRow: ElementRef;
|
|
|
|
|
|
|
|
@ViewChild('headerRow', { read: ElementRef }) headerRow: ElementRef;
|
|
|
|
|
|
|
|
|
|
|
|
displayedColumns: string[] = [];
|
|
|
|
displayedColumns: string[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
/** data source of the table */
|
|
|
|
/** data source of the table */
|
|
|
@ -86,8 +91,9 @@ export class ReferenceTableComponent {
|
|
|
|
|
|
|
|
|
|
|
|
reloadingTable = false;
|
|
|
|
reloadingTable = false;
|
|
|
|
|
|
|
|
|
|
|
|
tableFilterString = '';
|
|
|
|
displayedFilterColumns = [];
|
|
|
|
filterStringChanged: Subject<string> = new Subject<string>();
|
|
|
|
filters: any = {};
|
|
|
|
|
|
|
|
filterChanged: Subject<any> = new Subject<any>();
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private schemaService: SchemaService) {}
|
|
|
|
constructor(private schemaService: SchemaService) {}
|
|
|
|
|
|
|
|
|
|
|
@ -99,16 +105,26 @@ export class ReferenceTableComponent {
|
|
|
|
if (this.editableReferences) {
|
|
|
|
if (this.editableReferences) {
|
|
|
|
this.displayedColumns.push('buttons');
|
|
|
|
this.displayedColumns.push('buttons');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.displayedFilterColumns = this.displayedColumns.map(
|
|
|
|
|
|
|
|
(columnName) => columnName + '.filter'
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
this.filterStringChanged
|
|
|
|
this.dataSource.filterPredicate = customTableFilterFunction;
|
|
|
|
.pipe(debounceTime(400))
|
|
|
|
this.resetFilters();
|
|
|
|
.subscribe(() => this.applyTableFilter());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
ngAfterViewInit() {
|
|
|
|
|
|
|
|
this.setTableFilterRowHeight();
|
|
|
|
|
|
|
|
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
this.dataSource.sort = this.sort;
|
|
|
|
this.dataSource.sort = this.sort;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.dataSource.filter = (this.filters as unknown) as string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.filterChanged.pipe(debounceTime(400)).subscribe(() => {
|
|
|
|
|
|
|
|
this.applyFilters();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.dataSource.sortingDataAccessor = (item, columnName) => {
|
|
|
|
this.dataSource.sortingDataAccessor = (item, columnName) => {
|
|
|
|
if (typeof item[columnName] === 'string') {
|
|
|
|
if (typeof item[columnName] === 'string') {
|
|
|
|
return item[columnName].toLocaleLowerCase();
|
|
|
|
return item[columnName].toLocaleLowerCase();
|
|
|
@ -152,9 +168,9 @@ export class ReferenceTableComponent {
|
|
|
|
(element) => element.id === row.id
|
|
|
|
(element) => element.id === row.id
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (index !== -1) {
|
|
|
|
if (index !== -1) {
|
|
|
|
this.dataSource.data.splice(index, 1);
|
|
|
|
this.dataSource.data.splice(index, 1);
|
|
|
|
this.dataSource.data = this.dataSource.data; //needed to trigger update lol
|
|
|
|
this.dataSource.data = this.dataSource.data; //needed to trigger update lol
|
|
|
|
this.onReferenceChange();
|
|
|
|
this.onReferenceChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// show it again in the selection
|
|
|
|
// show it again in the selection
|
|
|
@ -166,8 +182,7 @@ export class ReferenceTableComponent {
|
|
|
|
addReference(row: any) {
|
|
|
|
addReference(row: any) {
|
|
|
|
this.dataSource.data = [flatten(row), ...this.dataSource.data];
|
|
|
|
this.dataSource.data = [flatten(row), ...this.dataSource.data];
|
|
|
|
this.idsOfObjectsToHide = [row.id, ...this.idsOfObjectsToHide];
|
|
|
|
this.idsOfObjectsToHide = [row.id, ...this.idsOfObjectsToHide];
|
|
|
|
this.tableFilterString = '';
|
|
|
|
this.resetFilters();
|
|
|
|
this.applyTableFilter();
|
|
|
|
|
|
|
|
this.onReferenceChange();
|
|
|
|
this.onReferenceChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -175,14 +190,6 @@ export class ReferenceTableComponent {
|
|
|
|
return this.dataSource.data.find((row) => row.id === id);
|
|
|
|
return this.dataSource.data.find((row) => row.id === id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
newFilterStringValue(): void {
|
|
|
|
|
|
|
|
this.filterStringChanged.next(this.tableFilterString);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applyTableFilter() {
|
|
|
|
|
|
|
|
this.dataSource.filter = this.tableFilterString;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onReferenceChange() {
|
|
|
|
onReferenceChange() {
|
|
|
|
const ids = [];
|
|
|
|
const ids = [];
|
|
|
|
for (const element of this.data) {
|
|
|
|
for (const element of this.data) {
|
|
|
@ -190,4 +197,58 @@ export class ReferenceTableComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.referenceIds.emit(ids);
|
|
|
|
this.referenceIds.emit(ids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Filter functions **************************************************************/
|
|
|
|
|
|
|
|
newFilterValue(): void {
|
|
|
|
|
|
|
|
this.filterChanged.next(this.filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applyFilters(): void {
|
|
|
|
|
|
|
|
this.dataSource.filter = (this.filters as unknown) as string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
columnFiltersAreSet(): boolean {
|
|
|
|
|
|
|
|
for (const filterObject of Object.keys(this.filters.columnFilters)) {
|
|
|
|
|
|
|
|
if (this.filters.columnFilters[filterObject].isSet) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resetColumnFilters() {
|
|
|
|
|
|
|
|
this.filters['columnFilters'] = [];
|
|
|
|
|
|
|
|
for (const column of this.columnInfo) {
|
|
|
|
|
|
|
|
this.filters.columnFilters[column.dataPath] = {
|
|
|
|
|
|
|
|
isSet: false,
|
|
|
|
|
|
|
|
value: null,
|
|
|
|
|
|
|
|
minValue: {},
|
|
|
|
|
|
|
|
maxValue: {},
|
|
|
|
|
|
|
|
fromValue: {},
|
|
|
|
|
|
|
|
toValue: {},
|
|
|
|
|
|
|
|
type: column.type,
|
|
|
|
|
|
|
|
list: column.list,
|
|
|
|
|
|
|
|
options: {},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setTableFilterRowHeight();
|
|
|
|
|
|
|
|
this.applyFilters();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resetFilters() {
|
|
|
|
|
|
|
|
this.filters = [];
|
|
|
|
|
|
|
|
this.resetColumnFilters();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTableFilterRowHeight() {
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
const filterRowHeight = this.filterRow.nativeElement.clientHeight;
|
|
|
|
|
|
|
|
const headerRowCells = Array.from(
|
|
|
|
|
|
|
|
this.headerRow.nativeElement.children as HTMLCollectionOf<HTMLElement>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
for (let i = 0; i < headerRowCells.length; i++) {
|
|
|
|
|
|
|
|
headerRowCells[i].style.top = filterRowHeight + 'px';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|