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

IgniteUI / igniteui-angular / 13548823408

26 Feb 2025 04:36PM CUT coverage: 91.555% (-0.04%) from 91.599%
13548823408

Pull #15223

github

web-flow
Merge 3ac8087aa into 786685675
Pull Request #15223: fix(pivot-grid): added createRow method for grid based events - 19.0

12997 of 15250 branches covered (85.23%)

0 of 18 new or added lines in 2 files covered. (0.0%)

135 existing lines in 23 files now uncovered.

26344 of 28774 relevant lines covered (91.55%)

34046.37 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
     * @remark
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,376✔
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,376✔
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
     * @remark
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();
37,908!
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,376✔
131

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

136
    public override set batchEditing(val: boolean) {
137
        if (val !== this._batchEditing) {
888✔
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,376✔
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,376✔
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
    /**
204
     * @hidden
205
     */
206
    public createColumnsList(cols: Array<any>) {
207
        const columns = [];
357✔
208
        const topLevelCols = cols.filter(c => c.level === 0);
1,320✔
209
        topLevelCols.forEach((col) => {
357✔
210
            col.grid = this;
1,320✔
211
            const ref = this._createColumn(col);
1,320✔
212
            ref.changeDetectorRef.detectChanges();
1,320✔
213
            columns.push(ref.instance);
1,320✔
214
        });
215
        const result = flatten(columns);
357✔
216
        this.updateColumns(result);
357✔
217
        this.initPinning();
357✔
218

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

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

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

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

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

285
    protected getGridsForIsland(rowIslandID: string) {
286
        return this.gridAPI.getChildGridsForRowIsland(rowIslandID);
222✔
287
    }
288

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

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

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