1 | import {Bean, Autowired, PostConstruct} from "../context/context";
|
2 | import {RowNode} from "../entities/rowNode";
|
3 | import {FilterManager} from "../filter/filterManager";
|
4 | import {GridOptionsWrapper} from "../gridOptionsWrapper";
|
5 | @Bean("filterService")
|
6 | export class FilterService {
|
7 |
|
8 | @Autowired('filterManager') private filterManager: FilterManager;
|
9 | @Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
|
10 |
|
11 | private doingTreeData: boolean;
|
12 |
|
13 | @PostConstruct
|
14 | private postConstruct(): void {
|
15 | this.doingTreeData = this.gridOptionsWrapper.isTreeData();
|
16 | }
|
17 |
|
18 | public filterAccordingToColumnState(rowNode: RowNode): void {
|
19 | let filterActive: boolean = this.filterManager.isAnyFilterPresent();
|
20 | this.filter (rowNode, filterActive);
|
21 | }
|
22 |
|
23 | public filter(rowNode: RowNode, filterActive: boolean): void {
|
24 |
|
25 |
|
26 | if (rowNode.hasChildren()) {
|
27 |
|
28 | rowNode.childrenAfterGroup.forEach( node => this.filter(node, filterActive));
|
29 |
|
30 |
|
31 | if (filterActive) {
|
32 | rowNode.childrenAfterFilter = rowNode.childrenAfterGroup.filter(childNode => {
|
33 |
|
34 |
|
35 | let passBecauseChildren = childNode.childrenAfterFilter && childNode.childrenAfterFilter.length > 0;
|
36 |
|
37 |
|
38 |
|
39 | let passBecauseDataPasses = childNode.data && this.filterManager.doesRowPassFilter(childNode);
|
40 |
|
41 |
|
42 |
|
43 | return passBecauseChildren || passBecauseDataPasses;
|
44 | });
|
45 | } else {
|
46 |
|
47 | rowNode.childrenAfterFilter = rowNode.childrenAfterGroup;
|
48 | }
|
49 |
|
50 | this.setAllChildrenCount(rowNode);
|
51 |
|
52 | } else {
|
53 | rowNode.childrenAfterFilter = rowNode.childrenAfterGroup;
|
54 | rowNode.setAllChildrenCount(null);
|
55 | }
|
56 | }
|
57 |
|
58 | private setAllChildrenCountTreeData(rowNode: RowNode) {
|
59 |
|
60 | let allChildrenCount = 0;
|
61 | rowNode.childrenAfterFilter.forEach((child: RowNode) => {
|
62 |
|
63 | allChildrenCount++;
|
64 |
|
65 | allChildrenCount += child.allChildrenCount;
|
66 | });
|
67 | rowNode.setAllChildrenCount(allChildrenCount);
|
68 | }
|
69 |
|
70 | private setAllChildrenCountGridGrouping(rowNode: RowNode) {
|
71 |
|
72 | let allChildrenCount = 0;
|
73 | rowNode.childrenAfterFilter.forEach((child: RowNode) => {
|
74 | if (child.group) {
|
75 | allChildrenCount += child.allChildrenCount;
|
76 | } else {
|
77 | allChildrenCount++;
|
78 | }
|
79 | });
|
80 | rowNode.setAllChildrenCount(allChildrenCount);
|
81 | }
|
82 |
|
83 | private setAllChildrenCount(rowNode: RowNode) {
|
84 | if (this.doingTreeData) {
|
85 | this.setAllChildrenCountTreeData(rowNode);
|
86 | } else {
|
87 | this.setAllChildrenCountGridGrouping(rowNode);
|
88 | }
|
89 | }
|
90 | } |
\ | No newline at end of file |