-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatatableFromToFilter.ts
115 lines (90 loc) · 2.71 KB
/
DatatableFromToFilter.ts
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { BaseFilterInputModel, DatatableFilterInputModel } from '@/models/datatable/DatatableFilterModels';
import { FilterType } from '@/enum/FilterType';
import DatatableBaseFilter from '@/filters/DatatableBaseFilter';
export default class DatatableFromToFilter extends DatatableBaseFilter {
from?: DatatableFilterInputModel;
to?: DatatableFilterInputModel;
constructor (
label: string,
exact?: DatatableFilterInputModel,
from?: DatatableFilterInputModel,
to?: DatatableFilterInputModel
) {
super(label, FilterType.fromTo, exact);
this.from = from;
this.to = to;
}
clearFromToValues (): void {
if (this.hasFromValue()) {
this.from!.value = undefined;
}
if (this.hasToValue()) {
this.to!.value = undefined;
}
}
findProp (prop: string): BaseFilterInputModel|undefined {
if (this.hasExact() && this.exact!.prop === prop) {
return this.exact;
}
if (this.hasFrom() && this.from!.prop === prop) {
return this.from;
}
if (this.hasTo() && this.to!.prop === prop) {
return this.to;
}
return undefined;
}
clearValues (): void {
if (this.hasExactValue()) {
this.exact!.value = undefined;
}
if (this.hasFromValue()) {
this.from!.value = undefined;
}
if (this.hasTo()) {
this.to!.value = undefined;
}
}
getFromLabel (): string|undefined {
return this.hasFromLabel() ? this.from!.label : undefined;
}
getFromProp (): string|undefined {
return this.hasFrom() ? this.from!.prop : undefined;
}
getFromValue (): string|undefined {
return this.hasFromValue() ? this.from!.value : undefined;
}
getToLabel (): string|undefined {
return this.hasToLabel() ? this.to!.label : undefined;
}
getToProp (): string|undefined {
return this.hasTo() ? this.to!.prop : undefined;
}
getToValue (): string|undefined {
return this.hasToValue() ? this.to!.value : undefined;
}
hasFrom (): boolean {
return this.from !== undefined;
}
hasFromLabel (): boolean {
return this.hasFrom() && this.from!.label !== undefined && this.from!.label !== '';
}
hasFromValue (): boolean {
return this.hasFrom() && this.from!.value !== undefined && this.from!.value !== '';
}
hasTo (): boolean {
return this.to !== undefined;
}
hasToLabel (): boolean {
return this.hasTo() && this.to!.label !== undefined && this.to!.label !== '';
}
hasToValue (): boolean {
return this.hasTo() && this.to!.value !== undefined && this.to!.value !== '';
}
hasFromToValues (): boolean {
return this.hasFromValue() && this.hasToValue();
}
hasValue (): boolean {
return this.hasExactValue() || this.hasFromValue() || this.hasToValue();
}
}