• 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

17.5
/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;
3✔
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>();
3✔
94

95
    /** @hidden @internal */
96
    public override get type(): GridType["type"] {
97
        return 'hierarchical';
1✔
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();
40!
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>();
3✔
131

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

136
    public override set batchEditing(val: boolean) {
137
        if (val !== this._batchEditing) {
1!
UNCOV
138
            delete this._transactions;
×
UNCOV
139
            this.switchTransactionService(val);
×
UNCOV
140
            this.subscribeToTransactions();
×
UNCOV
141
            this.batchEditingChange.emit(val);
×
UNCOV
142
            this._batchEditing = val;
×
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,
3✔
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(
3✔
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>) {
UNCOV
209
        const columns = [];
×
UNCOV
210
        const topLevelCols = cols.filter(c => c.level === 0);
×
UNCOV
211
        topLevelCols.forEach((col) => {
×
UNCOV
212
            col.grid = this;
×
UNCOV
213
            const ref = this._createColumn(col);
×
UNCOV
214
            ref.changeDetectorRef.detectChanges();
×
UNCOV
215
            columns.push(ref.instance);
×
216
        });
UNCOV
217
        const result = flatten(columns);
×
UNCOV
218
        this.updateColumns(result);
×
UNCOV
219
        this.initPinning();
×
220

UNCOV
221
        result.forEach(col => {
×
UNCOV
222
            this.columnInit.emit(col);
×
223
        });
224

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

241
    protected _createColumn(col) {
242
        let ref;
UNCOV
243
        if (col instanceof IgxColumnGroupComponent) {
×
UNCOV
244
            ref = this._createColGroupComponent(col);
×
245
        } else {
UNCOV
246
            ref = this._createColComponent(col);
×
247
        }
UNCOV
248
        return ref;
×
249
    }
250

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

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

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

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

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

UNCOV
302
    arr.forEach(el => {
×
UNCOV
303
        result.push(el);
×
UNCOV
304
        if (el.children) {
×
UNCOV
305
            result = result.concat(flatten(el.children.toArray()));
×
306
        }
307
    });
UNCOV
308
    return result;
×
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