• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.3
/projects/igniteui-angular/src/lib/grids/filtering/base/grid-filtering-cell.component.ts
1
import {
2
    AfterViewInit,
3
    ChangeDetectionStrategy,
4
    ChangeDetectorRef,
5
    Component,
6
    DoCheck,
7
    ElementRef,
8
    HostBinding,
9
    Input,
10
    OnInit,
11
    TemplateRef,
12
    ViewChild
13
} from '@angular/core';
14
import { IFilteringExpression } from '../../../data-operations/filtering-expression.interface';
15
import { IgxFilteringService } from '../grid-filtering.service';
16
import { ExpressionUI } from '../excel-style/common';
17
import { IgxChipsAreaComponent } from '../../../chips/chips-area.component';
18
import { IBaseChipEventArgs, IgxChipComponent } from '../../../chips/chip.component';
19
import { ColumnType } from '../../common/grid.interface';
20
import { IgxBadgeComponent } from '../../../badge/badge.component';
21
import { NgFor, NgIf, NgClass, NgTemplateOutlet } from '@angular/common';
22
import { IgxPrefixDirective } from '../../../directives/prefix/prefix.directive';
23
import { IgxIconComponent } from '../../../icon/icon.component';
24
import { Size } from '../../common/enums';
25

26
/**
27
 * @hidden
28
 */
29
@Component({
30
    changeDetection: ChangeDetectionStrategy.OnPush,
31
    selector: 'igx-grid-filtering-cell',
32
    templateUrl: './grid-filtering-cell.component.html',
33
    imports: [
34
        IgxChipsAreaComponent,
35
        IgxChipComponent,
36
        IgxIconComponent,
37
        IgxPrefixDirective,
38
        NgFor,
39
        NgIf,
40
        NgClass,
41
        IgxBadgeComponent,
42
        NgTemplateOutlet
43
    ]
44
})
45
export class IgxGridFilteringCellComponent implements AfterViewInit, OnInit, DoCheck {
2✔
46
    @Input()
47
    public column: ColumnType;
48

49
    @ViewChild('emptyFilter', { read: TemplateRef, static: true })
50
    protected emptyFilter: TemplateRef<any>;
51

52
    @ViewChild('defaultFilter', { read: TemplateRef, static: true })
53
    protected defaultFilter: TemplateRef<any>;
54

55
    @ViewChild('complexFilter', { read: TemplateRef, static: true })
56
    protected complexFilter: TemplateRef<any>;
57

58
    @ViewChild('chipsArea', { read: IgxChipsAreaComponent })
59
    protected chipsArea: IgxChipsAreaComponent;
60

61
    @ViewChild('moreIcon', { read: ElementRef })
62
    protected moreIcon: ElementRef;
63

64
    @ViewChild('ghostChip', { read: IgxChipComponent })
65
    protected ghostChip: IgxChipComponent;
66

67
    @ViewChild('complexChip', { read: IgxChipComponent })
68
    protected complexChip: IgxChipComponent;
69

70

71
    @HostBinding('class')
72
    public get styleClasses(): string {
UNCOV
73
        return this.column && this.column.selected ?
×
74
            'igx-grid__filtering-cell--selected' :
75
            'igx-grid__filtering-cell';
76
    }
77

78
    public expressionsList: ExpressionUI[];
UNCOV
79
    public moreFiltersCount = 0;
×
80

UNCOV
81
    private baseClass = 'igx-grid__filtering-cell-indicator';
×
82

83
    constructor(
UNCOV
84
        public cdr: ChangeDetectorRef,
×
UNCOV
85
        public filteringService: IgxFilteringService,
×
86
    ) {
UNCOV
87
        this.filteringService.subscribeToEvents();
×
88
    }
89

90
    public ngOnInit(): void {
UNCOV
91
        this.filteringService.columnToMoreIconHidden.set(this.column.field, true);
×
92
    }
93

94
    public ngAfterViewInit(): void {
UNCOV
95
        this.updateFilterCellArea();
×
96
    }
97

98
    public ngDoCheck() {
UNCOV
99
        this.updateFilterCellArea();
×
100
    }
101

102
    /**
103
     * Returns whether a chip with a given index is visible or not.
104
     */
105
    public isChipVisible(index: number) {
UNCOV
106
        const expression = this.expressionsList[index];
×
UNCOV
107
        return !!(expression && expression.isVisible);
×
108
    }
109

110
    /**
111
     * Updates the filtering cell area.
112
     */
113
    public updateFilterCellArea() {
UNCOV
114
        this.expressionsList = this.filteringService.getExpressions(this.column.field);
×
UNCOV
115
        this.updateVisibleFilters();
×
116
    }
117

118
    public get template(): TemplateRef<any> {
UNCOV
119
        if (!this.column.filterable) {
×
UNCOV
120
            return null;
×
121
        }
UNCOV
122
        if (this.column.filterCellTemplate) {
×
UNCOV
123
            return this.column.filterCellTemplate;
×
124
        }
UNCOV
125
        const expressionTree = this.column.filteringExpressionsTree;
×
UNCOV
126
        if (!expressionTree || expressionTree.filteringOperands.length === 0) {
×
UNCOV
127
            return this.emptyFilter;
×
128
        }
UNCOV
129
        if (this.filteringService.isFilterComplex(this.column.field)) {
×
130
            return this.complexFilter;
×
131
        }
UNCOV
132
        return this.defaultFilter;
×
133
    }
134

135
    /**
136
     * Gets the context passed to the filter template.
137
     *
138
     * @memberof IgxGridFilteringCellComponent
139
     */
140
    public get context() {
UNCOV
141
        return { $implicit: this.column, column: this.column};
×
142
    }
143

144
    /**
145
     * Chip clicked event handler.
146
     */
147
    public onChipClicked(expression?: IFilteringExpression) {
UNCOV
148
        if (expression) {
×
UNCOV
149
            this.expressionsList.forEach((item) => {
×
UNCOV
150
                item.isSelected = (item.expression === expression);
×
151
            });
UNCOV
152
        } else if (this.expressionsList.length > 0) {
×
UNCOV
153
            this.expressionsList.forEach((item) => {
×
UNCOV
154
                item.isSelected = false;
×
155
            });
UNCOV
156
            this.expressionsList[0].isSelected = true;
×
157
        }
UNCOV
158
        this.filteringService.grid.navigation.performHorizontalScrollToCell(this.column.visibleIndex);
×
UNCOV
159
        this.filteringService.filteredColumn = this.column;
×
UNCOV
160
        this.filteringService.isFilterRowVisible = true;
×
UNCOV
161
        this.filteringService.selectedExpression = expression;
×
162
    }
163

164
    /**
165
     * Chip removed event handler.
166
     */
167
    public onChipRemoved(eventArgs: IBaseChipEventArgs, item: ExpressionUI): void {
UNCOV
168
        const indexToRemove = this.expressionsList.indexOf(item);
×
UNCOV
169
        this.removeExpression(indexToRemove);
×
UNCOV
170
        this.filteringService.grid.theadRow.nativeElement.focus();
×
171
    }
172

173
    /**
174
     * Clears the filtering.
175
     */
176
    public clearFiltering(): void {
UNCOV
177
        this.filteringService.clearFilter(this.column.field);
×
UNCOV
178
        this.cdr.detectChanges();
×
179
    }
180

181
    /**
182
     * Returns the filtering indicator class.
183
     */
184
    public filteringIndicatorClass() {
UNCOV
185
        return {
×
186
            [this.baseClass]: !this.isMoreIconHidden(),
187
            [`${this.baseClass}--hidden`]: this.isMoreIconHidden()
188
        };
189
    }
190

191
    protected get filteringElementsSize(): Size {
UNCOV
192
        return this.column.grid.gridSize === Size.Large ? Size.Medium : this.column.grid.gridSize;
×
193
    }
194

195
    private removeExpression(indexToRemove: number) {
UNCOV
196
        if (indexToRemove === 0 && this.expressionsList.length === 1) {
×
UNCOV
197
            this.clearFiltering();
×
UNCOV
198
            return;
×
199
        }
200

UNCOV
201
        this.filteringService.removeExpression(this.column.field, indexToRemove);
×
202

UNCOV
203
        this.updateVisibleFilters();
×
UNCOV
204
        this.filteringService.filterInternal(this.column.field);
×
205
    }
206

207
    private isMoreIconHidden(): boolean {
UNCOV
208
        return this.filteringService.columnToMoreIconHidden.get(this.column.field);
×
209
    }
210

211
    private updateVisibleFilters() {
UNCOV
212
        this.expressionsList.forEach((ex) => ex.isVisible = true);
×
213

UNCOV
214
        if (this.moreIcon) {
×
UNCOV
215
            this.filteringService.columnToMoreIconHidden.set(this.column.field, true);
×
216
        }
UNCOV
217
        this.cdr.detectChanges();
×
218

UNCOV
219
        if (this.chipsArea && this.expressionsList.length > 1) {
×
UNCOV
220
            const areaWidth = this.chipsArea.element.nativeElement.offsetWidth;
×
UNCOV
221
            let viewWidth = 0;
×
UNCOV
222
            const chipsAreaElements = this.chipsArea.element.nativeElement.children;
×
UNCOV
223
            let visibleChipsCount = 0;
×
UNCOV
224
            const moreIconWidth = this.moreIcon.nativeElement.offsetWidth -
×
225
                parseInt(this.column?.grid.document.defaultView.getComputedStyle(this.moreIcon.nativeElement)['margin-left'], 10);
226

UNCOV
227
            for (let index = 0; index < chipsAreaElements.length - 1; index++) {
×
UNCOV
228
                if (viewWidth + chipsAreaElements[index].offsetWidth < areaWidth) {
×
UNCOV
229
                    viewWidth += chipsAreaElements[index].offsetWidth;
×
UNCOV
230
                    if (index % 2 === 0) {
×
UNCOV
231
                        visibleChipsCount++;
×
232
                    } else {
UNCOV
233
                        viewWidth += parseInt(this.column?.grid.document.defaultView.getComputedStyle(chipsAreaElements[index])['margin-left'], 10);
×
UNCOV
234
                        viewWidth += parseInt(this.column?.grid.document.defaultView.getComputedStyle(chipsAreaElements[index])['margin-right'], 10);
×
235
                    }
236
                } else {
UNCOV
237
                    if (index % 2 !== 0 && viewWidth + moreIconWidth > areaWidth) {
×
238
                        visibleChipsCount--;
×
UNCOV
239
                    } else if (visibleChipsCount > 0 && viewWidth - chipsAreaElements[index - 1].offsetWidth + moreIconWidth > areaWidth) {
×
UNCOV
240
                        visibleChipsCount--;
×
241
                    }
UNCOV
242
                    this.moreFiltersCount = this.expressionsList.length - visibleChipsCount;
×
UNCOV
243
                    this.filteringService.columnToMoreIconHidden.set(this.column.field, false);
×
UNCOV
244
                    break;
×
245
                }
246
            }
247

UNCOV
248
            for (let i = visibleChipsCount; i < this.expressionsList.length; i++) {
×
UNCOV
249
                this.expressionsList[i].isVisible = false;
×
250
            }
UNCOV
251
            this.cdr.detectChanges();
×
252
        }
253
    }
254
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc