• 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

4.44
/projects/igniteui-angular/src/lib/grids/grouping/group-by-area.directive.ts
1
import {
2
    Directive,
3
    ElementRef,
4
    EventEmitter,
5
    HostBinding,
6
    Input,
7
    Output,
8
    Pipe,
9
    PipeTransform,
10
    QueryList,
11
    TemplateRef,
12
    ViewChildren
13
} from '@angular/core';
14
import { IChipsAreaReorderEventArgs, IgxChipComponent } from '../../chips/public_api';
15
import { PlatformUtil } from '../../core/utils';
16
import { IGroupingExpression } from '../../data-operations/grouping-expression.interface';
17
import { SortingDirection } from '../../data-operations/sorting-strategy';
18
import { FlatGridType, GridType } from '../common/grid.interface';
19
import { IgxColumnMovingDragDirective } from '../moving/moving.drag.directive';
20

21
/**
22
 * An internal component representing a base group-by drop area.
23
 *
24
 * @hidden @internal
25
 */
26
@Directive()
27
export abstract class IgxGroupByAreaDirective {
2✔
28
    /**
29
     * The drop area template if provided by the parent grid.
30
     * Otherwise, uses the default internal one.
31
     */
32
    @Input()
33
    public dropAreaTemplate: TemplateRef<void>;
34

35
    @HostBinding('class.igx-grid-grouparea')
UNCOV
36
    public defaultClass = true;
×
37

38
    /** The parent grid containing the component. */
39
    @Input()
40
    public grid: FlatGridType | GridType;
41

42
    /**
43
     * The group-by expressions provided by the parent grid.
44
     */
45
    @Input()
46
    public get expressions(): IGroupingExpression[] {
UNCOV
47
        return this._expressions;
×
48
    }
49

50
    public set expressions(value: IGroupingExpression[]) {
UNCOV
51
        this._expressions = value;
×
UNCOV
52
        this.chipExpressions = this._expressions;
×
UNCOV
53
        this.expressionsChanged();
×
UNCOV
54
        this.expressionsChange.emit(this._expressions);
×
55
    }
56

57
    /**
58
     * The default message for the default drop area template.
59
     * Obviously, if another template is provided, this is ignored.
60
     */
61
    @Input()
62
    public get dropAreaMessage(): string {
UNCOV
63
        return this._dropAreaMessage ?? this.grid.resourceStrings.igx_grid_groupByArea_message;
×
64
    }
65

66
    public set dropAreaMessage(value: string) {
UNCOV
67
        this._dropAreaMessage = value;
×
68
    }
69

70
    @Output()
UNCOV
71
    public expressionsChange = new EventEmitter<IGroupingExpression[]>();
×
72

73
    @ViewChildren(IgxChipComponent)
74
    public chips: QueryList<IgxChipComponent>;
75

76
    public chipExpressions: IGroupingExpression[];
77

78
    /** The native DOM element. Used in sizing calculations. */
79
    public get nativeElement() {
UNCOV
80
        return this.ref.nativeElement;
×
81
    }
82

UNCOV
83
    private _expressions: IGroupingExpression[] = [];
×
84
    private _dropAreaMessage: string;
85

UNCOV
86
    constructor(private ref: ElementRef<HTMLElement>, protected platform: PlatformUtil) { }
×
87

88

89
    public get dropAreaVisible(): boolean {
UNCOV
90
        return (this.grid.columnInDrag && this.grid.columnInDrag.groupable) ||
×
91
            !this.expressions.length;
92
    }
93

94
    public handleKeyDown(id: string, event: KeyboardEvent) {
95
        if (this.platform.isActivationKey(event)) {
×
96
            this.updateGroupSorting(id);
×
97
        }
98
    }
99

100
    public handleClick(id: string) {
UNCOV
101
        if (!this.grid.getColumnByName(id).groupable) {
×
UNCOV
102
            return;
×
103
        }
UNCOV
104
        this.updateGroupSorting(id);
×
105
    }
106

107
    public onDragDrop(event) {
UNCOV
108
        const drag: IgxColumnMovingDragDirective = event.detail.owner;
×
UNCOV
109
        if (drag instanceof IgxColumnMovingDragDirective) {
×
UNCOV
110
            const column = drag.column;
×
UNCOV
111
            if (!this.grid.columns.find(c => c === column)) {
×
112
                return;
×
113
            }
114

UNCOV
115
            const isGrouped = this.expressions.findIndex((item) => item.fieldName === column.field) !== -1;
×
UNCOV
116
            if (column.groupable && !isGrouped && !column.columnGroup && !!column.field) {
×
UNCOV
117
                const groupingExpression = {
×
118
                    fieldName: column.field,
UNCOV
119
                    dir: this.grid.sortingExpressions.find(expr => expr.fieldName === column.field)?.dir || SortingDirection.Asc,
×
120
                    ignoreCase: column.sortingIgnoreCase,
121
                    strategy: column.sortStrategy,
122
                    groupingComparer: column.groupingComparer
123
                };
124

UNCOV
125
                this.groupBy(groupingExpression);
×
126
            }
127
        }
128
    }
129

130
    protected getReorderedExpressions(chipsArray: IgxChipComponent[]) {
UNCOV
131
        const newExpressions = [];
×
132

UNCOV
133
        chipsArray.forEach(chip => {
×
UNCOV
134
            const expr = this.expressions.find(item => item.fieldName === chip.id);
×
135

136
            // disallow changing order if there are columns with groupable: false
UNCOV
137
            if (!this.grid.getColumnByName(expr.fieldName)?.groupable) {
×
138
                return;
×
139
            }
140

UNCOV
141
            newExpressions.push(expr);
×
142
        });
143

UNCOV
144
        return newExpressions;
×
145
    }
146

147
    protected updateGroupSorting(id: string) {
UNCOV
148
        const expr = this.expressions.find(e => e.fieldName === id);
×
UNCOV
149
        expr.dir = 3 - expr.dir;
×
UNCOV
150
        const expressionsChangeEvent = this.grid.groupingExpressionsChange || this.expressionsChange;
×
UNCOV
151
        expressionsChangeEvent.emit(this.expressions);
×
UNCOV
152
        this.grid.pipeTrigger++;
×
UNCOV
153
        this.grid.notifyChanges();
×
154
    }
155

156
    protected expressionsChanged() {
157
    }
158

159
    public abstract handleReorder(event: IChipsAreaReorderEventArgs);
160

161
    public abstract handleMoveEnd();
162

163
    public abstract groupBy(expression: IGroupingExpression);
164

165
    public abstract clearGrouping(name: string);
166

167
}
168

169
/**
170
 * A pipe to circumvent the use of getters/methods just to get some additional
171
 * information from the grouping expression and pass it to the chip representing
172
 * that expression.
173
 *
174
 * @hidden @internal
175
 */
176
@Pipe({
177
    name: 'igxGroupByMeta',
178
    standalone: true
179
})
180
export class IgxGroupByMetaPipe implements PipeTransform {
2✔
181

182
    public transform(key: string, grid: GridType, _pipeTrigger?: number) {
UNCOV
183
        const column = grid.getColumnByName(key);
×
UNCOV
184
        return { groupable: !!column?.groupable, title: column?.header || key };
×
185
    }
186
}
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