Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Component, Input, ChangeDetectionStrategy, Output, EventEmitter, ViewEncapsulation, OnInit } from '@angular/core';
// import { SearchQueryParams } from '../../store/model';
import { Attribute, Dataset } from 'src/app/metamodel/model';
@Component({
selector: 'app-datatable',
templateUrl: 'datatable.component.html',
styleUrls: ['datatable.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
})
export class DatatableComponent implements OnInit {
@Input() dataset: Dataset;
// @Input() queryParams: SearchQueryParams;
@Input() datasetAttributeList: Attribute[];
@Input() outputList: number[];
@Input() data: any[];
@Input() dataLength: number;
@Input() selectedData: any[] = [];
@Input() processWip: boolean = false;
@Input() processDone: boolean = false;
@Input() processId: string = null;
@Output() getData: EventEmitter<[number, number, number, string]> = new EventEmitter();
@Output() addSelectedData: EventEmitter<number | string> = new EventEmitter();
@Output() deleteSelectedData: EventEmitter<number | string> = new EventEmitter();
@Output() executeProcess: EventEmitter<string> = new EventEmitter();
nbItems = 10;
page = 1;
sortedCol: number = null;
sortedOrder: string = null;
ngOnInit() {
this.sortedCol = this.datasetAttributeList.find(a => a.search_flag === 'ID').id;
this.sortedOrder = 'a';
this.getData.emit([this.page, this.nbItems, this.sortedCol, this.sortedOrder]);
}
getOutputList(): Attribute[] {
return this.datasetAttributeList
.filter(a => this.outputList.includes(a.id))
.sort((a, b) => a.output_display - b.output_display);
}
getAttributeId(attributeName: string): number {
const attribute = this.datasetAttributeList.find(a => a.name === attributeName);
return attribute.id;
}
toggleSelection(datum: any): void {
const attribute = this.datasetAttributeList.find(a => a.search_flag === 'ID');
const index = this.selectedData.indexOf(datum[attribute.label]);
if (index > -1) {
this.deleteSelectedData.emit(datum[attribute.label]);
} else {
this.addSelectedData.emit(datum[attribute.label]);
}
}
isSelected(datum: any): boolean {
const attribute = this.datasetAttributeList.find(a => a.search_flag === 'ID');
if (this.selectedData.indexOf(datum[attribute.label]) > -1) {
return true;
}
return false;
}
noSelectedData(): boolean {
return this.selectedData.length < 1;
}
emitProcess(typeProcess: string): void {
this.executeProcess.emit(typeProcess);
}
changePage(nb: number): void {
this.page = nb;
this.getData.emit([this.page, this.nbItems, this.sortedCol, this.sortedOrder]);
}
changeNbItems(nb: number): void {
this.nbItems = nb;
this.getData.emit([this.page, this.nbItems, this.sortedCol, this.sortedOrder]);
}
sort(id: number): void {
if (id === this.sortedCol) {
this.sortedOrder = this.sortedOrder === 'a' ? 'd' : 'a';
} else {
this.sortedCol = id;
this.sortedOrder = 'a';
}
this.getData.emit([this.page, this.nbItems, this.sortedCol, this.sortedOrder]);
}
}