• 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

14.47
/projects/igniteui-angular/src/lib/grids/grid/grid-api.service.ts
1
import { GridBaseAPIService } from '../api.service';
2
import { IGroupByRecord } from '../../data-operations/groupby-record.interface';
3
import { IGroupByExpandState } from '../../data-operations/groupby-expand-state.interface';
4
import { DataUtil } from '../../data-operations/data-util';
5
import { cloneArray } from '../../core/utils';
6
import { IGroupingExpression } from '../../data-operations/grouping-expression.interface';
7
import { Injectable } from '@angular/core';
8
import { GridServiceType, GridType } from '../common/grid.interface';
9

10
@Injectable()
11
export class IgxGridAPIService extends GridBaseAPIService<GridType> implements GridServiceType {
2✔
12

13
    public groupBy(expression: IGroupingExpression): void {
UNCOV
14
        const groupingState = cloneArray(this.grid.groupingExpressions);
×
UNCOV
15
        this.prepare_grouping_expression([groupingState], expression);
×
UNCOV
16
        this.grid.groupingExpressions = groupingState;
×
UNCOV
17
        this.arrange_sorting_expressions();
×
18
    }
19

20
    public groupBy_multiple(expressions: IGroupingExpression[]): void {
UNCOV
21
        const groupingState = cloneArray(this.grid.groupingExpressions);
×
22

UNCOV
23
        for (const each of expressions) {
×
UNCOV
24
            this.prepare_grouping_expression([groupingState], each);
×
25
        }
26

UNCOV
27
        this.grid.groupingExpressions = groupingState;
×
UNCOV
28
        this.arrange_sorting_expressions();
×
29
    }
30

31
    public override clear_groupby(name?: string | Array<string>) {
32
        const groupingState = cloneArray(this.grid.groupingExpressions);
6✔
33

34
        if (name) {
6!
35
            const names = typeof name === 'string' ? [name] : name;
6!
36
            const groupedCols = groupingState.filter((state) => names.indexOf(state.fieldName) < 0);
6✔
37
            this.grid.groupingExpressions = groupedCols;
6✔
38
            names.forEach((colName) => {
6✔
39
                const grExprIndex = groupingState.findIndex((exp) => exp.fieldName === colName);
6✔
40
                const grpExpandState = this.grid.groupingExpansionState;
6✔
41
                /* remove expansion states related to the cleared group
42
                   and all with deeper hierarchy than the cleared group */
43
                const newExpandState = grpExpandState.filter((val) => val.hierarchy && val.hierarchy.length <= grExprIndex);
6!
44
                /* Do not set the new instance produced by filter
45
                    when there are no differences between expansion states */
46
                if (newExpandState.length !== grpExpandState.length) {
6!
UNCOV
47
                    this.grid.groupingExpansionState = newExpandState;
×
48
                }
49
            });
50
        } else {
51
            // clear all
UNCOV
52
            this.grid.groupingExpressions = [];
×
UNCOV
53
            this.grid.groupingExpansionState = [];
×
54
        }
55
    }
56

57
    public groupBy_get_expanded_for_group(groupRow: IGroupByRecord): IGroupByExpandState {
UNCOV
58
        const grState = this.grid.groupingExpansionState;
×
UNCOV
59
        const hierarchy = DataUtil.getHierarchy(groupRow);
×
UNCOV
60
        return grState.find((state) =>
×
UNCOV
61
            DataUtil.isHierarchyMatch(
×
62
                state.hierarchy || [{ fieldName: groupRow.expression.fieldName, value: groupRow.value }],
×
63
                hierarchy,
64
                this.grid.groupingExpressions));
65
    }
66

67
    public groupBy_is_row_in_group(groupRow: IGroupByRecord, rowID): boolean {
68
        const grid = this.grid;
×
69
        let rowInGroup = false;
×
70
        groupRow.records.forEach(row => {
×
71
            if (grid.primaryKey ? row[grid.primaryKey] === rowID : row === rowID) {
×
72
                rowInGroup = true;
×
73
            }
74
        });
75
        return rowInGroup;
×
76
    }
77

78
    public groupBy_toggle_group(groupRow: IGroupByRecord) {
UNCOV
79
        const grid = this.grid;
×
UNCOV
80
        if (grid.gridAPI.crudService.cellInEditMode) {
×
UNCOV
81
            this.crudService.endEdit(false);
×
82
        }
83

UNCOV
84
        const expansionState = grid.groupingExpansionState;
×
UNCOV
85
        const state: IGroupByExpandState = this.groupBy_get_expanded_for_group(groupRow);
×
UNCOV
86
        if (state) {
×
UNCOV
87
            state.expanded = !state.expanded;
×
88
        } else {
UNCOV
89
            expansionState.push({
×
90
                expanded: !grid.groupsExpanded,
91
                hierarchy: DataUtil.getHierarchy(groupRow)
92
            });
93
        }
UNCOV
94
        this.grid.groupingExpansionState = [...expansionState];
×
UNCOV
95
        if (grid.rowEditable) {
×
UNCOV
96
            grid.repositionRowEditingOverlay(grid.gridAPI.crudService.rowInEditMode);
×
97
        }
98
    }
99
    public set_grouprow_expansion_state(groupRow: IGroupByRecord, value: boolean) {
UNCOV
100
        if (this.grid.isExpandedGroup(groupRow) !== value) {
×
UNCOV
101
            this.groupBy_toggle_group(groupRow);
×
102
        }
103
    }
104

105
    public groupBy_fully_expand_group(groupRow: IGroupByRecord) {
UNCOV
106
        const state: IGroupByExpandState = this.groupBy_get_expanded_for_group(groupRow);
×
UNCOV
107
        const expanded = state ? state.expanded : this.grid.groupsExpanded;
×
UNCOV
108
        if (!expanded) {
×
UNCOV
109
            this.groupBy_toggle_group(groupRow);
×
110
        }
UNCOV
111
        if (groupRow.groupParent) {
×
UNCOV
112
            this.groupBy_fully_expand_group(groupRow.groupParent);
×
113
        }
114
    }
115

116
    public groupBy_select_all_rows_in_group(groupRow: IGroupByRecord, clearPrevSelection: boolean) {
UNCOV
117
        this.grid.selectionService.selectRowsWithNoEvent(this.grid.primaryKey ?
×
UNCOV
118
            groupRow.records.map(x => x[this.grid.primaryKey]) : groupRow.records, clearPrevSelection);
×
119
    }
120

121
    public groupBy_deselect_all_rows_in_group(groupRow: IGroupByRecord) {
UNCOV
122
        this.grid.selectionService.deselectRowsWithNoEvent(this.grid.primaryKey ?
×
UNCOV
123
            groupRow.records.map(x => x[this.grid.primaryKey]) : groupRow.records);
×
124
    }
125

126
    public arrange_sorting_expressions() {
UNCOV
127
        const groupingState = this.grid.groupingExpressions;
×
UNCOV
128
        const sortingState = cloneArray(this.grid.sortingExpressions);
×
UNCOV
129
        for (const grExpr of groupingState) {
×
UNCOV
130
            const sortExprIndex = sortingState.findIndex((exp) => exp.fieldName === grExpr.fieldName);
×
UNCOV
131
            if (sortExprIndex > -1) {
×
UNCOV
132
                sortingState.splice(sortExprIndex, 1);
×
133
            }
134
        }
UNCOV
135
        this.grid.sortingExpressions = sortingState;
×
136
    }
137

138
    public get_groupBy_record_id(gRow: IGroupByRecord): string {
UNCOV
139
        let recordId = '{ ';
×
UNCOV
140
        const hierrarchy = DataUtil.getHierarchy(gRow);
×
141

UNCOV
142
        for (let i = 0; i < hierrarchy.length; i++) {
×
UNCOV
143
            const groupByKey = hierrarchy[i];
×
UNCOV
144
            recordId += `'${groupByKey.fieldName}': '${groupByKey.value}'`;
×
145

UNCOV
146
            if (i < hierrarchy.length - 1) {
×
UNCOV
147
                recordId += ', ';
×
148
            }
149
        }
UNCOV
150
        recordId += ' }';
×
151

UNCOV
152
        return recordId;
×
153
    }
154

155
    public override remove_grouping_expression(fieldName: string) {
UNCOV
156
        const groupingExpressions = this.grid.groupingExpressions;
×
UNCOV
157
        const index = groupingExpressions.findIndex((expr) => expr.fieldName === fieldName);
×
UNCOV
158
        if (index !== -1) {
×
UNCOV
159
            groupingExpressions.splice(index, 1);
×
160
        }
161
    }
162
}
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