From f6426747f7a8ae87ac4b819fab52045b7243cb08 Mon Sep 17 00:00:00 2001 From: MKirova Date: Thu, 17 Feb 2022 14:25:55 +0200 Subject: [PATCH 1/2] chore(*): Minor refactor. Move common code to util and re-use in selector and header. --- .../pivot-data-selector.component.ts | 50 +------------------ .../pivot-grid/pivot-header-row.component.ts | 41 +-------------- .../src/lib/grids/pivot-grid/pivot-util.ts | 44 +++++++++++++++- 3 files changed, 45 insertions(+), 90 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-data-selector.component.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-data-selector.component.ts index 0c8f76d2f97..0fc90a8279a 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-data-selector.component.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-data-selector.component.ts @@ -38,6 +38,7 @@ import { IPivotValue, PivotDimensionType } from "./pivot-grid.interface"; +import { PivotUtil } from './pivot-util'; interface IDataSelectorPanel { name: string; @@ -378,7 +379,7 @@ export class IgxPivotDataSelectorComponent { ) { this.value = value; dropdown.width = "200px"; - this.aggregateList = this.getAggregateList(value); + this.aggregateList = PivotUtil.getAggregateList(value, this.grid); dropdown.open(this._subMenuOverlaySettings); } @@ -405,53 +406,6 @@ export class IgxPivotDataSelectorComponent { } } - /** - * @hidden - * @internal - */ - protected getAggregatorsForValue(value: IPivotValue): IPivotAggregator[] { - const dataType = - value.dataType || - this.grid.resolveDataTypes(this.grid.data[0][value.member]); - switch (dataType) { - case GridColumnDataType.Number: - case GridColumnDataType.Currency: - return IgxPivotDateAggregate.aggregators(); - case GridColumnDataType.Date: - case GridColumnDataType.DateTime: - return IgxPivotDateAggregate.aggregators(); - case GridColumnDataType.Time: - return IgxPivotTimeAggregate.aggregators(); - default: - return IgxPivotAggregate.aggregators(); - } - } - - /** - * @hidden - * @internal - */ - public getAggregateList(val: IPivotValue): IPivotAggregator[] { - if (!val.aggregateList) { - let defaultAggr = this.getAggregatorsForValue(val); - const isDefault = defaultAggr.find( - (x) => x.key === val.aggregate.key - ); - // resolve custom aggregations - if (!isDefault && this.grid.data[0][val.member] !== undefined) { - // if field exists, then we can apply default aggregations and add the custom one. - defaultAggr.unshift(val.aggregate); - } else if (!isDefault) { - // otherwise this is a custom aggregation that is not compatible - // with the defaults, since it operates on field that is not in the data - // leave only the custom one. - defaultAggr = [val.aggregate]; - } - val.aggregateList = defaultAggr; - } - return val.aggregateList; - } - /** * @hidden * @internal diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts index 114bf5a2442..8834b89f44c 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts @@ -277,29 +277,6 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem return chips && chips.length > 0 ? chips.first.nativeElement.clientHeight : 0; } - /** - * @hidden - * @internal - */ - public getAggregateList(val: IPivotValue): IPivotAggregator[] { - if (!val.aggregateList) { - let defaultAggr = this.getAggregatorsForValue(val); - const isDefault = defaultAggr.find(x => x.key === val.aggregate.key); - // resolve custom aggregations - if (!isDefault && this.grid.data[0][val.member] !== undefined) { - // if field exists, then we can apply default aggregations and add the custom one. - defaultAggr.unshift(val.aggregate); - } else if (!isDefault) { - // otherwise this is a custom aggregation that is not compatible - // with the defaults, since it operates on field that is not in the data - // leave only the custom one. - defaultAggr = [val.aggregate]; - } - val.aggregateList = defaultAggr; - } - return val.aggregateList; - } - /** * @hidden * @internal @@ -592,26 +569,10 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem return isColumn ? PivotDimensionType.Column : isRow ? PivotDimensionType.Row : PivotDimensionType.Filter; } - protected getAggregatorsForValue(value: IPivotValue): IPivotAggregator[] { - const dataType = value.dataType || this.grid.resolveDataTypes(this.grid.data[0][value.member]); - switch (dataType) { - case GridColumnDataType.Number: - case GridColumnDataType.Currency: - return IgxPivotNumericAggregate.aggregators(); - case GridColumnDataType.Date: - case GridColumnDataType.DateTime: - return IgxPivotDateAggregate.aggregators(); - case GridColumnDataType.Time: - return IgxPivotTimeAggregate.aggregators(); - default: - return IgxPivotAggregate.aggregators(); - } - } - protected updateDropDown(value: IPivotValue, dropdown: IgxDropDownComponent, chip: IgxChipComponent) { this.value = value; dropdown.width = chip.nativeElement.clientWidth + 'px'; - this.aggregateList = this.getAggregateList(value); + this.aggregateList = PivotUtil.getAggregateList(value, this.grid); dropdown.open(this._subMenuOverlaySettings); } } diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts index fd8495996ce..91ae0442649 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts @@ -1,10 +1,13 @@ import { cloneValue } from '../../core/utils'; -import { DataUtil } from '../../data-operations/data-util'; +import { DataUtil, GridColumnDataType } from '../../data-operations/data-util'; import { FilteringLogic } from '../../data-operations/filtering-expression.interface'; import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree'; import { ISortingExpression } from '../../data-operations/sorting-strategy'; +import { PivotGridType } from '../common/grid.interface'; import { IGridSortingStrategy, IgxSorting } from '../common/strategy'; -import { IPivotConfiguration, IPivotDimension, IPivotKeys, IPivotValue, PivotDimensionType } from './pivot-grid.interface'; +import { IgxPivotAggregate, IgxPivotDateAggregate, IgxPivotNumericAggregate, IgxPivotTimeAggregate } from './pivot-grid-aggregate'; +import { IgxPivotGridComponent } from './pivot-grid.component'; +import { IPivotAggregator, IPivotConfiguration, IPivotDimension, IPivotKeys, IPivotValue, PivotDimensionType } from './pivot-grid.interface'; export class PivotUtil { public static assignLevels(dims) { @@ -482,4 +485,41 @@ export class PivotUtil { } } } + + public static getAggregateList(val: IPivotValue, grid: PivotGridType): IPivotAggregator[] { + if (!val.aggregateList) { + let defaultAggr = this.getAggregatorsForValue(val, grid); + const isDefault = defaultAggr.find( + (x) => x.key === val.aggregate.key + ); + // resolve custom aggregations + if (!isDefault && grid.data[0][val.member] !== undefined) { + // if field exists, then we can apply default aggregations and add the custom one. + defaultAggr.unshift(val.aggregate); + } else if (!isDefault) { + // otherwise this is a custom aggregation that is not compatible + // with the defaults, since it operates on field that is not in the data + // leave only the custom one. + defaultAggr = [val.aggregate]; + } + val.aggregateList = defaultAggr; + } + return val.aggregateList; + } + + public static getAggregatorsForValue(value: IPivotValue, grid: PivotGridType): IPivotAggregator[] { + const dataType = value.dataType || grid.resolveDataTypes(grid.data[0][value.member]); + switch (dataType) { + case GridColumnDataType.Number: + case GridColumnDataType.Currency: + return IgxPivotNumericAggregate.aggregators(); + case GridColumnDataType.Date: + case GridColumnDataType.DateTime: + return IgxPivotDateAggregate.aggregators(); + case GridColumnDataType.Time: + return IgxPivotTimeAggregate.aggregators(); + default: + return IgxPivotAggregate.aggregators(); + } + } } From a2e7d45ef6951381b1283b670520d8f583ac1361 Mon Sep 17 00:00:00 2001 From: MKirova Date: Fri, 18 Feb 2022 16:52:53 +0200 Subject: [PATCH 2/2] chore(*): Fix build. --- projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts index 2689350d06e..e95155ff85e 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts @@ -6,7 +6,6 @@ import { ISortingExpression } from '../../data-operations/sorting-strategy'; import { PivotGridType } from '../common/grid.interface'; import { IGridSortingStrategy, IgxSorting } from '../common/strategy'; import { IgxPivotAggregate, IgxPivotDateAggregate, IgxPivotNumericAggregate, IgxPivotTimeAggregate } from './pivot-grid-aggregate'; -import { IgxPivotGridComponent } from './pivot-grid.component'; import { IPivotAggregator, IPivotConfiguration, IPivotDimension, IPivotGridRecord, IPivotKeys, IPivotValue, PivotDimensionType } from './pivot-grid.interface'; export class PivotUtil {