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

IgniteUI / igniteui-angular / 13416627295

19 Feb 2025 03:46PM CUT coverage: 91.615% (+0.02%) from 91.595%
13416627295

Pull #15246

github

web-flow
Merge 2a114cdda into 10ddb05cf
Pull Request #15246: fix(excel-export): Get correct grid column collection from row island…

12987 of 15218 branches covered (85.34%)

3 of 3 new or added lines in 1 file covered. (100.0%)

380 existing lines in 31 files now uncovered.

26385 of 28800 relevant lines covered (91.61%)

34358.69 hits per line

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

91.25
/projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid-base.directive.ts
1
import {
2
    booleanAttribute,
3
    ChangeDetectorRef,
4
    createComponent,
5
    Directive,
6
    ElementRef,
7
    EnvironmentInjector,
8
    EventEmitter,
9
    Inject,
10
    Injector,
11
    Input,
12
    IterableDiffers,
13
    LOCALE_ID,
14
    NgZone,
15
    Optional,
16
    Output,
17
    reflectComponentType,
18
    ViewContainerRef
19
} from '@angular/core';
20
import { IgxGridBaseDirective } from '../grid-base.directive';
21
import { IgxHierarchicalGridAPIService } from './hierarchical-grid-api.service';
22
import { IgxRowIslandComponent } from './row-island.component';
23
import { IgxFilteringService } from '../filtering/grid-filtering.service';
24
import { IgxSummaryOperand } from '../summaries/grid-summary';
25
import { DOCUMENT } from '@angular/common';
26
import { IgxHierarchicalGridNavigationService } from './hierarchical-grid-navigation.service';
27
import { IgxGridSummaryService } from '../summaries/grid-summary.service';
28
import { IgxGridSelectionService } from '../selection/selection.service';
29
import { IgxColumnResizingService } from '../resizing/resizing.service';
30
import { GridType, IGX_GRID_SERVICE_BASE, IPathSegment } from '../common/grid.interface';
31
import { IgxColumnGroupComponent } from '../columns/column-group.component';
32
import { IgxColumnComponent } from '../columns/column.component';
33
import { IForOfState } from '../../directives/for-of/for_of.directive';
34
import { takeUntil } from 'rxjs/operators';
35
import { PlatformUtil } from '../../core/utils';
36
import { IgxFlatTransactionFactory } from '../../services/transaction/transaction-factory.service';
37
import { IgxTransactionService } from '../../services/transaction/igx-transaction';
38
import { IgxOverlayService } from '../../services/overlay/overlay';
39
import { State, Transaction, TransactionService } from '../../services/transaction/transaction';
40
import { IgxGridTransaction } from '../common/types';
41
import { IgxGridValidationService } from '../grid/grid-validation.service';
42
import { IgxTextHighlightService } from '../../directives/text-highlight/text-highlight.service';
43

44
export const hierarchicalTransactionServiceFactory = () => new IgxTransactionService();
2✔
45

46
export const IgxHierarchicalTransactionServiceFactory = {
2✔
47
    provide: IgxGridTransaction,
48
    useFactory: hierarchicalTransactionServiceFactory
49
};
50

51
/* blazorIndirectRender
52
   blazorComponent
53
   omitModule
54
   wcSkipComponentSuffix */
55
@Directive()
56
export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirective implements GridType {
2✔
57
    /**
58
     * Gets/Sets the key indicating whether a row has children. If row has no children it does not render an expand indicator.
59
     *
60
     * @example
61
     * ```html
62
     * <igx-hierarchical-grid #grid [data]="localData" [hasChildrenKey]="'hasEmployees'">
63
     * </igx-hierarchical-grid>
64
     * ```
65
     */
66
    @Input()
67
    public hasChildrenKey: string;
68

69
    /**
70
     * Gets/Sets whether the expand/collapse all button in the header should be rendered.
71
     *
72
     * @remarks
73
     * The default value is false.
74
     * @example
75
     * ```html
76
     * <igx-hierarchical-grid #grid [data]="localData" [showExpandAll]="true">
77
     * </igx-hierarchical-grid>
78
     * ```
79
     */
80
    @Input({ transform: booleanAttribute })
81
    public showExpandAll = false;
1,410✔
82

83
    /**
84
     * Emitted when a new chunk of data is loaded from virtualization.
85
     *
86
     * @example
87
     * ```typescript
88
     *  <igx-hierarchical-grid [id]="'igx-grid-1'" [data]="Data" [autoGenerate]="true" (dataPreLoad)="handleEvent()">
89
     *  </igx-hierarchical-grid>
90
     * ```
91
     */
92
    @Output()
93
    public dataPreLoad = new EventEmitter<IForOfState>();
1,410✔
94

95
    /** @hidden @internal */
96
    public override get type(): GridType["type"] {
97
        return 'hierarchical';
1,770✔
98
    }
99

100
    /**
101
     * @hidden
102
     */
103
    public override get maxLevelHeaderDepth() {
104
        if (this._maxLevelHeaderDepth === null) {
×
105
            this._maxLevelHeaderDepth = this.columns.reduce((acc, col) => Math.max(acc, col.level), 0);
×
106
        }
107
        return this._maxLevelHeaderDepth;
×
108
    }
109

110
    /* blazorSuppress */
111
    /**
112
     * Gets the outlet used to attach the grid's overlays to.
113
     *
114
     * @remarks
115
     * If set, returns the outlet defined outside the grid. Otherwise returns the grid's internal outlet directive.
116
     */
117
    public override get outlet() {
118
        return this.rootGrid ? this.rootGrid.resolveOutlet() : this.resolveOutlet();
38,801!
119
    }
120

121
    /* blazorSuppress */
122
    /**
123
     * Sets the outlet used to attach the grid's overlays to.
124
     */
125
    public override set outlet(val: any) {
126
        this._userOutletDirective = val;
×
127
    }
128

129
    /** @hidden @internal */
130
    public batchEditingChange: EventEmitter<boolean> = new EventEmitter<boolean>();
1,410✔
131

132
    public override get batchEditing(): boolean {
133
        return this._batchEditing;
4,697✔
134
    }
135

136
    public override set batchEditing(val: boolean) {
137
        if (val !== this._batchEditing) {
916✔
138
            delete this._transactions;
92✔
139
            this.switchTransactionService(val);
92✔
140
            this.subscribeToTransactions();
92✔
141
            this.batchEditingChange.emit(val);
92✔
142
            this._batchEditing = val;
92✔
143
        }
144
    }
145

146
    /**
147
     * @hidden
148
     */
149
    public parentIsland: IgxRowIslandComponent;
150
    public abstract rootGrid: GridType;
151

152
    /* blazorSuppress */
153
    public abstract expandChildren: boolean;
154

155
    constructor(
156
        validationService: IgxGridValidationService,
157
        selectionService: IgxGridSelectionService,
158
        colResizingService: IgxColumnResizingService,
159
        @Inject(IGX_GRID_SERVICE_BASE) public override gridAPI: IgxHierarchicalGridAPIService,
1,410✔
160
        transactionFactory: IgxFlatTransactionFactory,
161
        elementRef: ElementRef<HTMLElement>,
162
        zone: NgZone,
163
        @Inject(DOCUMENT) document,
164
        cdr: ChangeDetectorRef,
165
        differs: IterableDiffers,
166
        viewRef: ViewContainerRef,
167
        injector: Injector,
168
        envInjector: EnvironmentInjector,
169
        navigation: IgxHierarchicalGridNavigationService,
170
        filteringService: IgxFilteringService,
171
        textHighlightService: IgxTextHighlightService,
172
        @Inject(IgxOverlayService) overlayService: IgxOverlayService,
173
        summaryService: IgxGridSummaryService,
174
        @Inject(LOCALE_ID) localeId: string,
175
        platform: PlatformUtil,
176
        @Optional() @Inject(IgxGridTransaction) _diTransactions?: TransactionService<Transaction, State>,
177
    ) {
178
        super(
1,410✔
179
            validationService,
180
            selectionService,
181
            colResizingService,
182
            gridAPI,
183
            transactionFactory,
184
            elementRef,
185
            zone,
186
            document,
187
            cdr,
188
            differs,
189
            viewRef,
190
            injector,
191
            envInjector,
192
            navigation,
193
            filteringService,
194
            textHighlightService,
195
            overlayService,
196
            summaryService,
197
            localeId,
198
            platform,
199
            _diTransactions,
200
        );
201
    }
202

203
    public override navigation: IgxHierarchicalGridNavigationService;
204

205
    /**
206
     * @hidden
207
     */
208
    public createColumnsList(cols: Array<any>) {
209
        const columns = [];
357✔
210
        const topLevelCols = cols.filter(c => c.level === 0);
1,320✔
211
        topLevelCols.forEach((col) => {
357✔
212
            col.grid = this;
1,320✔
213
            const ref = this._createColumn(col);
1,320✔
214
            ref.changeDetectorRef.detectChanges();
1,320✔
215
            columns.push(ref.instance);
1,320✔
216
        });
217
        const result = flatten(columns);
357✔
218
        this.updateColumns(result);
357✔
219
        this.initPinning();
357✔
220

221
        result.forEach(col => {
357✔
222
            this.columnInit.emit(col);
1,406✔
223
        });
224

225
        const mirror = reflectComponentType(IgxColumnComponent);
357✔
226
        const outputs = mirror.outputs.filter(o => o.propName !== 'columnChange');
2,499✔
227
        outputs.forEach(output => {
357✔
228
            this.columns.forEach(column => {
2,142✔
229
                if (column[output.propName]) {
8,436✔
230
                    column[output.propName].pipe(takeUntil(column.destroy$)).subscribe((args) => {
8,436✔
231
                        const rowIslandColumn = this.parentIsland.columnList.find((col) => col.field
218✔
232
                            ? col.field === column.field
233
                            : col.header === column.header);
234
                        rowIslandColumn[output.propName].emit({ args, owner: this });
67✔
235
                    });
236
                }
237
            });
238
        });
239
    }
240

241
    protected _createColumn(col) {
242
        let ref;
243
        if (col instanceof IgxColumnGroupComponent) {
1,406✔
244
            ref = this._createColGroupComponent(col);
41✔
245
        } else {
246
            ref = this._createColComponent(col);
1,365✔
247
        }
248
        return ref;
1,406✔
249
    }
250

251
    protected _createColGroupComponent(col: IgxColumnGroupComponent) {
252
        const ref = createComponent(IgxColumnGroupComponent, { environmentInjector: this.envInjector, elementInjector: this.injector });
41✔
253
        ref.changeDetectorRef.detectChanges();
41✔
254
        const mirror = reflectComponentType(IgxColumnGroupComponent);
41✔
255
        mirror.inputs.forEach((input) => {
41✔
256
            const propName = input.propName;
2,132✔
257
            ref.instance[propName] = col[propName];
2,132✔
258
        });
259
        if (col.children.length > 0) {
41✔
260
            const newChildren = [];
41✔
261
            col.children.forEach(child => {
41✔
262
                const newCol = this._createColumn(child).instance;
86✔
263
                newCol.parent = ref.instance;
86✔
264
                newChildren.push(newCol);
86✔
265
            });
266
            ref.instance.children.reset(newChildren);
41✔
267
            ref.instance.children.notifyOnChanges();
41✔
268
        }
269
        return ref;
41✔
270
    }
271

272
    protected _createColComponent(col) {
273
        const ref = createComponent(IgxColumnComponent, { environmentInjector: this.envInjector, elementInjector: this.injector });
1,365✔
274
        const mirror = reflectComponentType(IgxColumnComponent);
1,365✔
275
        mirror.inputs.forEach((input) => {
1,365✔
276
            const propName = input.propName;
68,250✔
277
            if (!(col[propName] instanceof IgxSummaryOperand)) {
68,250✔
278
                ref.instance[propName] = col[propName];
66,891✔
279
            } else {
280
                ref.instance[propName] = col[propName].constructor;
1,359✔
281
            }
282
        });
283
        ref.instance.validators = col.validators;
1,365✔
284
        return ref;
1,365✔
285
    }
286

287
    protected getGridsForIsland(rowIslandID: string) {
288
        return this.gridAPI.getChildGridsForRowIsland(rowIslandID);
224✔
289
    }
290

291
    protected getChildGrid(path: Array<IPathSegment>) {
UNCOV
292
        if (!path) {
×
293
            return;
×
294
        }
UNCOV
295
        return this.gridAPI.getChildGrid(path);
×
296
    }
297
}
298

299
const flatten = (arr: any[]) => {
2✔
300
    let result = [];
398✔
301

302
    arr.forEach(el => {
398✔
303
        result.push(el);
1,406✔
304
        if (el.children) {
1,406✔
305
            result = result.concat(flatten(el.children.toArray()));
41✔
306
        }
307
    });
308
    return result;
398✔
309
};
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