diff --git a/projects/fleet-management-grid/src/app/fleet-management-grid/fleet-management-grid.component.ts b/projects/fleet-management-grid/src/app/fleet-management-grid/fleet-management-grid.component.ts index 3827cbe..fd1b68e 100644 --- a/projects/fleet-management-grid/src/app/fleet-management-grid/fleet-management-grid.component.ts +++ b/projects/fleet-management-grid/src/app/fleet-management-grid/fleet-management-grid.component.ts @@ -101,7 +101,7 @@ export class FleetManagementGridComponent implements OnInit { costPerMeterPeriod: Period.YTD, fuelCostPeriod: Period.YTD } */ - protected periods: { [vehicleId: string]: { costPerTypePeriod: Period, costPerMeterPeriod: Period, fuelCostPeriod: Period } } = {}; + protected periods: { [vehicleId: string]: { costPerTypePeriod: Period, costPerMeterPeriod: Period, fuelCostPeriod: Period } | null } = {}; //driver details for detail overlay protected driverDetails: DriverDetails = { diff --git a/projects/sales-grid/src/app/sales-grid/sales-grid.component.html b/projects/sales-grid/src/app/sales-grid/sales-grid.component.html index c9bbc67..321e0ee 100644 --- a/projects/sales-grid/src/app/sales-grid/sales-grid.component.html +++ b/projects/sales-grid/src/app/sales-grid/sales-grid.component.html @@ -2,19 +2,20 @@
Sales Dashboard
- - - Brands: HM and HM Home - Stores: Bulgaria + @for (configInfo of availableConfigs; track configInfo[0]) { + {{availableConfigs.get(configInfo[0])?.title}} + } Export to Excel @@ -42,3 +43,7 @@
+ +
+ Change pivot configuration. +
diff --git a/projects/sales-grid/src/app/sales-grid/sales-grid.component.ts b/projects/sales-grid/src/app/sales-grid/sales-grid.component.ts index 9c8f819..c2a06ad 100644 --- a/projects/sales-grid/src/app/sales-grid/sales-grid.component.ts +++ b/projects/sales-grid/src/app/sales-grid/sales-grid.component.ts @@ -25,11 +25,21 @@ import { FilteringLogic, IPivotValue, THEME_TOKEN, - ThemeToken + ThemeToken, + IgxDropDownItemNavigationDirective, + IgxTooltipDirective, + IgxTooltipTargetDirective } from 'igniteui-angular'; import FLAGS from './data/flags.json' import SALES_DATA from './data/SalesData.json'; +enum PivotViews { + BrandsSeparate = 'brandsOr', + BrandsCombined = 'jeansAnd', + Stores = 'stores' +} + +// Custom aggregator to calculate profit value export class IgxSaleProfitAggregate { public static totalProfit = (_, data: any[] | undefined) => data?.reduce((accumulator, value) => accumulator + (value.Sale - value.Cost), 0) || 0; @@ -71,7 +81,8 @@ export class IgxSaleProfitAggregate { @Component({ standalone: true, selector: 'app-sales-grid', - imports: [CommonModule, IgxPivotGridComponent, IgxPivotDataSelectorComponent, IgxButtonDirective, IgxIconComponent, IgxToggleActionDirective, IgxDropDownComponent, IgxDropDownItemComponent, IgxCellHeaderTemplateDirective], + imports: [CommonModule, IgxPivotGridComponent, IgxPivotDataSelectorComponent, IgxButtonDirective, IgxIconComponent, IgxTooltipDirective, IgxTooltipTargetDirective, + IgxToggleActionDirective, IgxDropDownComponent, IgxDropDownItemComponent, IgxCellHeaderTemplateDirective, IgxDropDownItemNavigationDirective], templateUrl: './sales-grid.component.html', providers: [ { @@ -93,8 +104,9 @@ export class SalesGridComponent { public currencyPipe = new CurrencyPipe('en-US'); public brandFilter = new FilteringExpressionsTree(FilteringLogic.Or, 'Brand'); public bulgariaCountryFilter = new FilteringExpressionsTree(FilteringLogic.And); - public fileName = 'SalesGridApp'; + + // #region Various configurations for the grid that can be toggled public saleValue: IPivotValue = { enabled: true, member: 'Sale', @@ -211,6 +223,44 @@ export class SalesGridComponent { this.profitValue ] }; + public pivotConfigBrandsCombined: IPivotConfiguration = { + columns: [ + { + enabled: true, + memberName: 'Country', + displayName: 'Country' + }, + { + enabled: false, + memberName: 'Store', + displayName: 'Store' + }, + ], + rows: [ + new IgxPivotDateDimension({ + memberName: 'Date', + displayName: 'All Periods', + enabled: true + }, + { + fullDate: true, + quarters: true, + months: false, + }) + ], + values: [ + this.saleValue, + this.profitValue + ], + filters: [ + { + enabled: true, + memberName: 'Brand', + displayName: 'Brand', + filter: this.brandFilter + }, + ] + }; public pivotConfigStores: IPivotConfiguration = { columns: [ new IgxPivotDateDimension({ @@ -251,6 +301,15 @@ export class SalesGridComponent { } ] }; + // #endregion + + public PivotViews = PivotViews; + public selectedConfig = PivotViews.BrandsSeparate; + public availableConfigs = new Map([ + [ PivotViews.BrandsSeparate, { title: 'Brands: HM and HM Home', config: this.pivotConfigBrands} ], + [ PivotViews.BrandsCombined, { title: 'Brands: HM + HM Home', config: this.pivotConfigBrandsCombined} ], + [ PivotViews.Stores, { title: 'Stores: Bulgaria', config: this.pivotConfigStores} ] + ]); public flagsData = FLAGS; public data: any = SALES_DATA; @@ -280,12 +339,8 @@ export class SalesGridComponent { } public onViewSelection(event: ISelectionEventArgs) { - const newId = event.newSelection.id; - if (newId === 'brands') { - this.pivotGrid.pivotConfiguration = this.pivotConfigBrands; - } else if (newId === 'stores') { - this.pivotGrid.pivotConfiguration = this.pivotConfigStores; - } + this.selectedConfig = event.newSelection.id; + this.pivotGrid.pivotConfiguration = this.availableConfigs.get(this.selectedConfig)?.config || this.pivotConfigBrands; } public onExportSelection(event: ISelectionEventArgs) {