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
|
/**
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FilterItem } from '../../model/filter_item';
import { FilterCondition } from '../../model/filter_condition';
@Component({
selector: 'app-filter',
templateUrl: './filter.component.html',
styleUrls: ['./filter.component.scss']
})
export class FilterComponent implements OnInit {
currentFilter: FilterItem;
applyingFilters: FilterItem[] = [];
applyingFilterChanged = false;
appliedFilters: FilterItem[] = [];
selectorList: string[];
filterMethods = [
{value: FilterCondition.EqualTo, text: 'is equal to', sign: '='},
{value: FilterCondition.LessThan, text: 'is less than', sign: '<'},
{value: FilterCondition.GreaterThan, text: 'is greater than', sign: '>'},
{value: FilterCondition.LessThanOrEqualTo, text: 'is less than or equal to', sign: '<='},
{value: FilterCondition.GreaterThanOrEqualTo, text: 'is greater than or equal to', sign: '>='},
{value: FilterCondition.NotEqualTo, text: 'is not equal to', sign: '!='},
{value: FilterCondition.Has, text: 'has', sign: 'has'},
];
@Output() applyFilters = new EventEmitter();
@Input() disabled: boolean;
panelOpenState = false;
ngOnInit(): void {
this.currentFilter = new FilterItem();
this.currentFilter.value = '';
}
/** Sets a filter key list with the given class. */
setSelectorList(typeOfClass: any) {
const instance = new typeOfClass();
this.selectorList = Object.getOwnPropertyNames(instance);
}
/** Adds the current filter to the list of filters to be applied. */
addFilter() {
this.applyingFilters.push(this.currentFilter);
this.currentFilter = new FilterItem();
this.currentFilter.value = '';
this.applyingFilterChanged = true;
}
/** Clears the current filter. */
clearCurrentFilter() {
this.currentFilter.key = undefined;
this.currentFilter.method = undefined;
this.currentFilter.value = '';
}
/** Removes the selected filter from the list of filters to be applied. */
removed(filter: FilterItem) {
const index = this.applyingFilters.indexOf(filter);
if (index >= 0) {
this.applyingFilters.splice(index, 1);
this.applyingFilterChanged = true;
}
}
/** Gets a filter sign with method value. */
getSign(filter: FilterItem) {
return this.filterMethods.find((x) => x.value === filter.method).sign;
}
/** Applies the list of filters. */
onApplyClicked() {
this.applyFilters.emit(this.applyingFilters);
this.appliedFilters = this.applyingFilters.slice();
this.applyingFilterChanged = false;
}
/** Cancels the current changes and roll back to the last applied filters. */
onCancelChangesClicked() {
this.applyingFilters = this.appliedFilters.slice();
this.applyingFilterChanged = false;
}
/** Reset all filters. */
onClearAllClicked() {
this.applyingFilters = [];
this.appliedFilters = [];
this.applyFilters.emit(this.appliedFilters);
this.applyingFilterChanged = false;
}
}
|