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

IgniteUI / igniteui-angular / 11741984483

08 Nov 2024 12:19PM CUT coverage: 91.57% (-0.04%) from 91.606%
11741984483

Pull #14999

github

web-flow
Merge dba70cfe6 into 7b8563221
Pull Request #14999: fix(grid): add coerceToInt attribute to IPinningConfig and pagingMode props

12947 of 15174 branches covered (85.32%)

26243 of 28659 relevant lines covered (91.57%)

33883.34 hits per line

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

91.14
/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,368✔
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,368✔
94

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

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

136
    public override set batchEditing(val: boolean) {
137
        if (val !== this._batchEditing) {
883✔
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,368✔
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,368✔
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 = [];
354✔
208
        const topLevelCols = cols.filter(c => c.level === 0);
1,313✔
209
        topLevelCols.forEach((col) => {
354✔
210
            const ref = this._createColumn(col);
1,313✔
211
            ref.changeDetectorRef.detectChanges();
1,313✔
212
            columns.push(ref.instance);
1,313✔
213
        });
214
        const result = flatten(columns);
354✔
215
        this.updateColumns(result);
354✔
216
        this.initPinning();
354✔
217

218
        result.forEach(col => {
354✔
219
            this.columnInit.emit(col);
1,396✔
220
        });
221

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

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

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

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

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

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

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

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