• 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.79
/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.summary.pipe.ts
1
import { Inject, Pipe, PipeTransform } from '@angular/core';
2
import { ITreeGridRecord } from './tree-grid.interfaces';
3
import { ISummaryRecord } from '../summaries/grid-summary';
4
import { GridSummaryCalculationMode, GridSummaryPosition } from '../common/enums';
5
import { GridType, IGX_GRID_BASE } from '../common/grid.interface';
6

7
/** @hidden */
8
@Pipe({
9
    name: 'treeGridSummary',
10
    standalone: true
11
})
12
export class IgxTreeGridSummaryPipe implements PipeTransform {
2✔
13

UNCOV
14
    constructor(@Inject(IGX_GRID_BASE) private grid: GridType) {}
×
15

16
    public transform(flatData: ITreeGridRecord[],
17
        hasSummary: boolean,
18
        summaryCalculationMode: GridSummaryCalculationMode,
19
        summaryPosition: GridSummaryPosition, showSummaryOnCollapse: boolean, _: number, __: number): any[] {
20

UNCOV
21
        if (!flatData || !hasSummary || summaryCalculationMode === GridSummaryCalculationMode.rootLevelOnly) {
×
UNCOV
22
            return flatData;
×
23
        }
24

UNCOV
25
        return this.addSummaryRows(this.grid, flatData, summaryPosition, showSummaryOnCollapse);
×
26
    }
27

28
    private addSummaryRows(grid: GridType, collection: ITreeGridRecord[],
29
        summaryPosition: GridSummaryPosition, showSummaryOnCollapse: boolean): any[] {
UNCOV
30
        const recordsWithSummary = [];
×
UNCOV
31
        const maxSummaryHeight = grid.summaryService.calcMaxSummaryHeight();
×
32

UNCOV
33
        for (const record of collection) {
×
UNCOV
34
            recordsWithSummary.push(record);
×
35

UNCOV
36
            const isCollapsed = !record.expanded && record.children && record.children.length > 0 && showSummaryOnCollapse;
×
UNCOV
37
            if (isCollapsed) {
×
UNCOV
38
                let childData = record.children.filter(r => !r.isFilteredOutParent).map(r => r.data);
×
UNCOV
39
                childData = this.removeDeletedRecord(grid, record.key, childData);
×
UNCOV
40
                const summaries = grid.summaryService.calculateSummaries(record.key, childData);
×
UNCOV
41
                const summaryRecord: ISummaryRecord = {
×
42
                    summaries,
43
                    max: maxSummaryHeight,
44
                    cellIndentation: record.level + 1
45
                };
UNCOV
46
                recordsWithSummary.push(summaryRecord);
×
47
            }
UNCOV
48
            const isExpanded = record.children && record.children.length > 0 && record.expanded;
×
UNCOV
49
            if (summaryPosition === GridSummaryPosition.bottom && !isExpanded) {
×
UNCOV
50
                let childRecord = record;
×
UNCOV
51
                let parent = record.parent;
×
52

UNCOV
53
                while (parent) {
×
UNCOV
54
                    const children = parent.children;
×
55

UNCOV
56
                    if (children[children.length - 1] === childRecord ) {
×
UNCOV
57
                        let childData = children.filter(r => !r.isFilteredOutParent).map(r => r.data);
×
UNCOV
58
                        childData = this.removeDeletedRecord(grid, parent.key, childData);
×
UNCOV
59
                        const summaries = grid.summaryService.calculateSummaries(parent.key, childData);
×
UNCOV
60
                        const summaryRecord: ISummaryRecord = {
×
61
                            summaries,
62
                            max: maxSummaryHeight,
63
                            cellIndentation: parent.level + 1
64
                        };
UNCOV
65
                        recordsWithSummary.push(summaryRecord);
×
66

UNCOV
67
                        childRecord = parent;
×
UNCOV
68
                        parent = childRecord.parent;
×
69
                    } else {
UNCOV
70
                        break;
×
71
                    }
72
                }
UNCOV
73
            } else if (summaryPosition === GridSummaryPosition.top && isExpanded) {
×
UNCOV
74
                let childData = record.children.filter(r => !r.isFilteredOutParent).map(r => r.data);
×
UNCOV
75
                childData = this.removeDeletedRecord(grid, record.key, childData);
×
UNCOV
76
                const summaries = grid.summaryService.calculateSummaries(record.key, childData);
×
UNCOV
77
                const summaryRecord: ISummaryRecord = {
×
78
                    summaries,
79
                    max: maxSummaryHeight,
80
                    cellIndentation: record.level + 1
81
                };
UNCOV
82
                recordsWithSummary.push(summaryRecord);
×
83
            }
84
        }
UNCOV
85
        return recordsWithSummary;
×
86
    }
87

88
    private removeDeletedRecord(grid, rowId, data) {
UNCOV
89
        if (!grid.transactions.enabled || !grid.cascadeOnDelete) {
×
UNCOV
90
            return data;
×
91
        }
UNCOV
92
        const deletedRows = grid.transactions.getTransactionLog().filter(t => t.type === 'delete').map(t => t.id);
×
UNCOV
93
        let row = grid.records.get(rowId);
×
UNCOV
94
        if (!row && deletedRows.lenght === 0) {
×
95
            return [];
×
96
        }
UNCOV
97
        row = row.children ? row : row.parent;
×
UNCOV
98
        while (row) {
×
UNCOV
99
            rowId = row.key;
×
UNCOV
100
            if (deletedRows.indexOf(rowId) !== -1) {
×
UNCOV
101
                return [];
×
102
            }
UNCOV
103
            row = row.parent;
×
104
        }
UNCOV
105
        deletedRows.forEach(rowID => {
×
UNCOV
106
            const tempData = grid.primaryKey ? data.map(rec => rec[grid.primaryKey]) : data;
×
UNCOV
107
            const index = tempData.indexOf(rowID);
×
UNCOV
108
            if (index !== -1) {
×
UNCOV
109
                data.splice(index, 1);
×
110
            }
111
        });
UNCOV
112
        return data;
×
113
    }
114
}
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