From 04c8d1e05a020a16b903da7a20e89c9458b95b96 Mon Sep 17 00:00:00 2001 From: iago-dev Date: Fri, 9 Jan 2026 19:51:02 -0300 Subject: [PATCH 1/2] refac: resolve code smells ANY and LF --- src/app/grid-export/data/gridData.ts | 24 ++ src/app/grid-export/data/hGridData.ts | 75 +++++ src/app/grid-export/{ => data}/tGridData.ts | 3 +- src/app/grid-export/grid-export.sample.ts | 131 ++------ src/app/grid-export/gridData.ts | 303 ------------------ src/app/grid-export/hGridData.ts | 267 --------------- src/app/grid-export/models/grid-models.ts | 20 ++ .../models/product-category.interface.ts | 8 + .../grid-export/models/singer.interfaces.ts | 43 +++ src/app/grid-export/services/data.service.ts | 21 ++ .../grid-export/summaries/grid-summaries.ts | 36 +++ 11 files changed, 260 insertions(+), 671 deletions(-) create mode 100644 src/app/grid-export/data/gridData.ts create mode 100644 src/app/grid-export/data/hGridData.ts rename src/app/grid-export/{ => data}/tGridData.ts (96%) delete mode 100644 src/app/grid-export/gridData.ts delete mode 100644 src/app/grid-export/hGridData.ts create mode 100644 src/app/grid-export/models/grid-models.ts create mode 100644 src/app/grid-export/models/product-category.interface.ts create mode 100644 src/app/grid-export/models/singer.interfaces.ts create mode 100644 src/app/grid-export/services/data.service.ts create mode 100644 src/app/grid-export/summaries/grid-summaries.ts diff --git a/src/app/grid-export/data/gridData.ts b/src/app/grid-export/data/gridData.ts new file mode 100644 index 00000000000..07244542e7e --- /dev/null +++ b/src/app/grid-export/data/gridData.ts @@ -0,0 +1,24 @@ +import { IProduct } from "../models/grid-models"; +export const GRID_DATA: IProduct[] = [ + { ProductID: 1, ProductName: "Chai", SupplierID: 1, CategoryID: 1, QuantityPerUnit: "10 boxes x 20 bags", UnitPrice: 18.0000, UnitsInStock: 39, UnitsOnOrder: 30, ReorderLevel: 10, Discontinued: false, OrderDate: new Date("2012-02-12"), ProductionDate: new Date("2011-02-12 10:15:35"), PackagedAt: new Date("2011-02-12 10:15:35"), PercentInStock: 0.6807 }, + { ProductID: 2, ProductName: "Chang", SupplierID: 1, CategoryID: 1, QuantityPerUnit: "24 - 12 oz bottles", UnitPrice: 19.0000, UnitsInStock: 17, UnitsOnOrder: 40, ReorderLevel: 25, Discontinued: true, OrderDate: new Date("2003-03-17"), ProductionDate: new Date("2002-03-17 13:35:25"), PackagedAt: new Date("2002-03-17 13:35:25"), PercentInStock: 0.7006 }, + { ProductID: 3, ProductName: "Aniseed Syrup", SupplierID: 1, CategoryID: 2, QuantityPerUnit: "12 - 550 ml bottles", UnitPrice: 10.0000, UnitsInStock: 13, UnitsOnOrder: 70, ReorderLevel: 25, Discontinued: false, OrderDate: new Date("2006-03-17"), ProductionDate: new Date("2005-03-17 12:16:33"), PackagedAt: new Date("2005-03-17 12:16:33"), PercentInStock: 0.1634 }, + { ProductID: 4, ProductName: "Chef Antons Cajun Seasoning", SupplierID: 2, CategoryID: 2, QuantityPerUnit: "48 - 6 oz jars", UnitPrice: 22.0000, UnitsInStock: 53, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: false, OrderDate: new Date("2016-03-17"), ProductionDate: new Date("2015-03-17 13:24:28"), PackagedAt: new Date("2015-03-17 13:24:28"), PercentInStock: 0.7523 }, + { ProductID: 5, ProductName: "Chef Antons Gumbo Mix", SupplierID: 2, CategoryID: 2, QuantityPerUnit: "36 boxes", UnitPrice: 21.3500, UnitsInStock: 0, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: true, OrderDate: new Date("2011-11-11"), ProductionDate: new Date("2010-11-11 09:15:25"), PackagedAt: new Date("2010-11-11 09:15:25"), PercentInStock: 0.5 }, + { ProductID: 6, ProductName: "Grandmas Boysenberry Spread", SupplierID: 3, CategoryID: 2, QuantityPerUnit: "12 - 8 oz jars", UnitPrice: 25.0000, UnitsInStock: 0, UnitsOnOrder: 30, ReorderLevel: 25, Discontinued: false, OrderDate: new Date("2017-12-17"), ProductionDate: new Date("2016-12-17 10:10:30"), PackagedAt: new Date("2016-12-17 10:10:30"), PercentInStock: 0.5642 }, + { ProductID: 7, ProductName: "Uncle Bobs Organic Dried Pears", SupplierID: 3, CategoryID: 7, QuantityPerUnit: "12 - 1 lb pkgs.", UnitPrice: 30.0000, UnitsInStock: 150, UnitsOnOrder: 30, ReorderLevel: 10, Discontinued: false, OrderDate: new Date("2016-07-17"), ProductionDate: new Date("2015-07-17 11:11:11"), PackagedAt: new Date("2015-07-17 11:11:11"), PercentInStock: 0.1707 }, + { ProductID: 8, ProductName: "Northwoods Cranberry Sauce", SupplierID: 3, CategoryID: 2, QuantityPerUnit: "12 - 12 oz jars", UnitPrice: 40.0000, UnitsInStock: 6, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: false, OrderDate: new Date("2018-01-17"), ProductionDate: new Date("2017-01-17 12:12:32"), PackagedAt: new Date("2017-01-17 12:12:32"), PercentInStock: 0.0717 }, + { ProductID: 9, ProductName: "Mishi Kobe Niku", SupplierID: 4, CategoryID: 6, QuantityPerUnit: "18 - 500 g pkgs.", UnitPrice: 97.0000, UnitsInStock: 29, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: true, OrderDate: new Date("2010-02-17"), ProductionDate: new Date("2009-02-17 15:16:35"), PackagedAt: new Date("2009-02-17 15:16:35"), PercentInStock: 0.1219 }, + { ProductID: 10, ProductName: "Ikura", SupplierID: 4, CategoryID: 8, QuantityPerUnit: "12 - 200 ml jars", UnitPrice: 31.0000, UnitsInStock: 31, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: false, OrderDate: new Date("2008-05-17"), ProductionDate: new Date("2007-05-17 19:29:35"), PackagedAt: new Date("2007-05-17 19:29:35"), PercentInStock: 0.9812 }, + { ProductID: 11, ProductName: "Queso Cabrales", SupplierID: 5, CategoryID: 4, QuantityPerUnit: "1 kg pkg.", UnitPrice: 21.0000, UnitsInStock: 22, UnitsOnOrder: 30, ReorderLevel: 30, Discontinued: false, OrderDate: new Date("2009-01-17"), ProductionDate: new Date("2008-01-17 17:17:35"), PackagedAt: new Date("2008-01-17 17:17:35"), PercentInStock: 0.1912 }, + { ProductID: 12, ProductName: "Queso Manchego La Pastora", SupplierID: 5, CategoryID: 4, QuantityPerUnit: "10 - 500 g pkgs.", UnitPrice: 38.0000, UnitsInStock: 86, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: false, OrderDate: new Date("2015-11-17"), ProductionDate: new Date("2014-11-17 15:25:35"), PackagedAt: new Date("2014-11-17 15:25:35"), PercentInStock: 0.1717 }, + { ProductID: 13, ProductName: "Konbu", SupplierID: 6, CategoryID: 8, QuantityPerUnit: "2 kg box", UnitPrice: 6.0000, UnitsInStock: 24, UnitsOnOrder: 30, ReorderLevel: 5, Discontinued: false, OrderDate: new Date("2015-03-17"), ProductionDate: new Date("2014-03-17 03:05:35"), PackagedAt: new Date("2014-03-17 03:05:35"), PercentInStock: 0.3788 }, + { ProductID: 14, ProductName: "Tofu", SupplierID: 6, CategoryID: 7, QuantityPerUnit: "40 - 100 g pkgs.", UnitPrice: 23.2500, UnitsInStock: 35, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: false, OrderDate: new Date("2017-06-17"), ProductionDate: new Date("2016-06-17 05:03:35"), PackagedAt: new Date("2016-06-17 05:03:35"), PercentInStock: 0.0128 }, + { ProductID: 15, ProductName: "Genen Shouyu", SupplierID: 6, CategoryID: 2, QuantityPerUnit: "24 - 250 ml bottles", UnitPrice: 15.5000, UnitsInStock: 39, UnitsOnOrder: 30, ReorderLevel: 5, Discontinued: false, OrderDate: new Date("2014-03-17"), ProductionDate: new Date("2013-03-17 06:15:25"), PackagedAt: new Date("2013-03-17 06:15:25"), PercentInStock: 0.892 }, + { ProductID: 16, ProductName: "Pavlova", SupplierID: 7, CategoryID: 3, QuantityPerUnit: "32 - 500 g boxes", UnitPrice: 17.4500, UnitsInStock: 29, UnitsOnOrder: 30, ReorderLevel: 10, Discontinued: false, OrderDate: new Date("2018-03-28"), ProductionDate: new Date("2017-03-28 08:17:35"), PackagedAt: new Date("2017-03-28 08:17:35"), PercentInStock: 0.9124 }, + { ProductID: 17, ProductName: "Alice Mutton", SupplierID: 7, CategoryID: 6, QuantityPerUnit: "20 - 1 kg tins", UnitPrice: 39.0000, UnitsInStock: 0, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: true, OrderDate: new Date("2015-08-17 10:15:35"), ProductionDate: new Date("2014-08-17 16:15:35"), PackagedAt: new Date("2014-08-17 16:15:35"), PercentInStock: 0.2634 }, + { ProductID: 18, ProductName: "Carnarvon Tigers", SupplierID: 7, CategoryID: 8, QuantityPerUnit: "16 kg pkg.", UnitPrice: 62.5000, UnitsInStock: 42, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: false, OrderDate: new Date("2005-09-27"), ProductionDate: new Date("2004-09-27 16:48:35"), PackagedAt: new Date("2004-09-27 16:48:35"), PercentInStock: 0.4632 }, + { ProductID: 19, ProductName: "Teatime Chocolate Biscuits", SupplierID: 8, CategoryID: 3, QuantityPerUnit: "", UnitPrice: 9.2000, UnitsInStock: 25, UnitsOnOrder: 30, ReorderLevel: 5, Discontinued: false, OrderDate: new Date("2001-03-17"), ProductionDate: new Date("2000-03-17 14:34:35"), PackagedAt: new Date("2000-03-17 14:34:35"), PercentInStock: 0.069 }, + { ProductID: 20, ProductName: "Sir Rodneys Marmalade", SupplierID: 8, CategoryID: 3, QuantityPerUnit: undefined, UnitPrice: 4.5, UnitsInStock: 40, UnitsOnOrder: 30, ReorderLevel: 0, Discontinued: false, OrderDate: new Date("2005-03-17"), ProductionDate: new Date("2004-03-17 11:17:35"), PackagedAt: new Date("2004-03-17 11:17:35"), PercentInStock: 0.234 } +]; +/* tslint:enable */ diff --git a/src/app/grid-export/data/hGridData.ts b/src/app/grid-export/data/hGridData.ts new file mode 100644 index 00000000000..16a9382a231 --- /dev/null +++ b/src/app/grid-export/data/hGridData.ts @@ -0,0 +1,75 @@ +import { ISinger } from '../models/singer.interfaces'; + +export const HGRID_DATA: ISinger[] = [ + { + id: 1, + artist: 'Naomí Yepes', + debut: 2011, + grammyNominations: 6, + grammyAwards: 0, + hasGrammyAward: false, + tours: [ + { + tour: 'Faithful Tour', + startedOn: new Date('2025-09-12'), + location: 'Worldwide', + headliner: 'NO', + touredBy: 'Naomí Yepes', + tourData: [ + { country: 'Belgium', ticketsSold: 10000, attendants: 10000 }, + { country: 'USA', ticketsSold: 192300, attendants: 186523 } + ] + } + ], + albums: [ + { + album: 'Pushing up daisies', + launchDate: new Date('2000-05-31'), + billboardReview: 86, + usBillboard200: 42, + artist: 'Naomí Yepes', + songs: [ + { + number: 1, + title: 'Wood Shavings Forever', + released: new Date('2019-06-09'), + genre: 'Alternative', + album: 'Pushing up daisies' + } + ] + } + ] + }, + { + id: 2, + artist: 'Babila Ebwélé', + debut: 2009, + grammyNominations: 0, + grammyAwards: 11, + hasGrammyAward: true, + tours: [ + { + tour: 'Astroworld', + startedOn: new Date('2021-07-21'), + location: 'Worldwide', + headliner: 'NO', + touredBy: 'Babila Ebwélé', + tourData: [ + { country: 'Bulgaria', ticketsSold: 25000, attendants: 19822 } + ] + } + ], + albums: [ + { + album: 'Fahrenheit', + launchDate: new Date('2000-05-31'), + billboardReview: 86, + usBillboard200: 42, + artist: 'Babila Ebwélé', + songs: [ + { number: 1, title: 'Show Out', released: new Date('2020-07-17'), genre: 'Hip-Hop', album: 'Fahrenheit' } + ] + } + ] + } +]; \ No newline at end of file diff --git a/src/app/grid-export/tGridData.ts b/src/app/grid-export/data/tGridData.ts similarity index 96% rename from src/app/grid-export/tGridData.ts rename to src/app/grid-export/data/tGridData.ts index b24382f54c2..9d6eeb12ccd 100644 --- a/src/app/grid-export/tGridData.ts +++ b/src/app/grid-export/data/tGridData.ts @@ -1,4 +1,5 @@ -export const TGRID_DATA = [ +import { IProductNode } from "../models/product-category.interface"; +export const TGRID_DATA: IProductNode[] = [ { ID: 1, ParentID: -1, Name: 'Foods', UnitPrice: 0, AddedDate: new Date('2009-06-19'), Discontinued: false }, { ID: 101, ParentID: 1, Name: 'Chef Antons Gumbo Mix', UnitPrice: 21.35, AddedDate: new Date('2011-11-11'), Discontinued: true }, { ID: 102, ParentID: 1, Name: 'Grandmas Boysenberry Spread', UnitPrice: 25, AddedDate: new Date('2017-12-17'), Discontinued: false }, diff --git a/src/app/grid-export/grid-export.sample.ts b/src/app/grid-export/grid-export.sample.ts index fe79e6e772e..bc1d675d262 100644 --- a/src/app/grid-export/grid-export.sample.ts +++ b/src/app/grid-export/grid-export.sample.ts @@ -1,114 +1,45 @@ -import { Component, ViewChild } from '@angular/core'; -import { DatePipe } from '@angular/common'; - -import { HGRID_DATA } from './hGridData'; -import { GRID_DATA } from './gridData'; -import { TGRID_DATA } from './tGridData'; -import { ColumnType, IGridToolbarExportEventArgs, IgxCellHeaderTemplateDirective, IgxCellTemplateDirective, IgxColumnComponent, IgxGridComponent, IgxGridToolbarComponent, IgxGridToolbarExporterComponent, IgxHierarchicalGridComponent, IgxIconComponent, IgxNumberSummaryOperand, IgxPaginatorComponent, IgxRowIslandComponent, IgxSummaryResult, IgxTreeGridComponent } from 'igniteui-angular'; - -class GridSummary { - public operate(data?: any[]): IgxSummaryResult[] { - const result = new IgxNumberSummaryOperand().operate(data); - result.push({ - key: 'test', - label: 'Custom summary', - summaryResult: data.filter((rec) => rec > 10 && rec < 30).length - }); - - return result; - } -} - -class HGridSummary { - public operate(data?: any[]): IgxSummaryResult[] { - const result = []; - result.push( - { - key: 'min', - label: 'Min', - summaryResult: IgxNumberSummaryOperand.min(data) - }, - { - key: 'max', - label: 'Max', - summaryResult: IgxNumberSummaryOperand.max(data) - }, - { - key: 'avg', - label: 'Avg', - summaryResult: IgxNumberSummaryOperand.average(data) - }); - return result; - } -} - -class HGridChildSummary { - public operate(data?: any[]): IgxSummaryResult[] { - const result = []; - result.push( - { - key: 'count', - label: 'Count', - summaryResult: IgxNumberSummaryOperand.count(data) - }); - return result; - } -} +import { Component, OnInit, ViewChild } from '@angular/core'; +import { ColumnType, IGridToolbarExportEventArgs, IgxGridComponent } from 'igniteui-angular'; +import { CustomGridSummary, HierarchicalGridSummary } from './summaries/grid-summaries'; +import { GridDataService } from './services/data.service'; +import { IProduct } from './models/grid-models'; @Component({ selector: 'app-grid-export-sample', templateUrl: 'grid-export.sample.html', - imports: [IgxGridComponent, IgxGridToolbarComponent, IgxGridToolbarExporterComponent, IgxPaginatorComponent, IgxColumnComponent, IgxCellTemplateDirective, IgxCellHeaderTemplateDirective, IgxIconComponent, IgxTreeGridComponent, IgxHierarchicalGridComponent, IgxRowIslandComponent, DatePipe] + styleUrls: ['./grid-export.sample.scss'] }) -export class GridExportComponent { - @ViewChild('grid', { static: true }) - private grid: IgxGridComponent; +export class GridExportComponent implements OnInit { + @ViewChild('grid', { static: true }) public grid!: IgxGridComponent; - @ViewChild('tGrid', { static: true }) - private tGrid: IgxTreeGridComponent; + // Injeção de dependência e tipagem forte + public gridData: IProduct[] = []; + public productId: number = 0; + + // Referências de classe para o template + public readonly gridSummary = CustomGridSummary; + public readonly hGridSummary = HierarchicalGridSummary; - public gridSummary = GridSummary; - public hGridSummary = HGridSummary; - public hGridChildSummary = HGridChildSummary; - public gridData; - public tGridData; - public hGridData; - public productId = 0; + constructor(private dataService: GridDataService) {} - constructor() { - this.gridData = GRID_DATA; - this.tGridData = TGRID_DATA; - this.hGridData = HGRID_DATA; - this.productId = GRID_DATA.length; + public ngOnInit(): void { + this.loadData(); } - public toggleSummary(column: ColumnType) { - column.hasSummary = !column.hasSummary; + private loadData(): void { + this.gridData = this.dataService.getFlatGridData(); + this.productId = this.gridData.length; } - public configureExport(args: IGridToolbarExportEventArgs) { - console.log(args); - // const options: IgxExporterOptionsBase = args.options; - - // // Change exporter options - - // options.fileName = `Report_${new Date().toDateString()}`; - // options.exportSummaries = false; - - // // Cancel column exporting - - // args.exporter.columnExporting.subscribe((colExportingArgs: IColumnExportingEventArgs) => { - // if (colExportingArgs.columnIndex === 1) { - // colExportingArgs.cancel = true; - // } - // }); - - // // Cancel row exporting + public toggleSummary(column: ColumnType): void { + column.hasSummary = !column.hasSummary; + } - // args.exporter.rowExporting.subscribe((rowExportingArgs: IRowExportingEventArgs) => { - // if (rowExportingArgs.rowIndex === 1) { - // rowExportingArgs.cancel = true; - // } - // }); + public configureExport(args: IGridToolbarExportEventArgs): void { + // Encapsular lógica de exportação em um Helper se ficar muito complexa + console.log('Exporting with args:', args); + + const options = args.options; + options.fileName = `Report_${new Date().toLocaleDateString()}`; } -} +} \ No newline at end of file diff --git a/src/app/grid-export/gridData.ts b/src/app/grid-export/gridData.ts deleted file mode 100644 index f0559ac7fa5..00000000000 --- a/src/app/grid-export/gridData.ts +++ /dev/null @@ -1,303 +0,0 @@ -export const GRID_DATA: any[] = [{ - ProductID: 1, - ProductName: "Chai", - SupplierID: 1, - CategoryID: 1, - QuantityPerUnit: "10 boxes x 20 bags", - UnitPrice: 18.0000, - UnitsInStock: 39, - UnitsOnOrder: 30, - ReorderLevel: 10, - Discontinued: false, - OrderDate: new Date("2012-02-12"), - ProductionDate: new Date("2011-02-12 10:15:35"), - PackagedAt: new Date("2011-02-12 10:15:35"), - PercentInStock: 0.6807 - }, { - ProductID: 2, - ProductName: "Chang", - SupplierID: 1, - CategoryID: 1, - QuantityPerUnit: "24 - 12 oz bottles", - UnitPrice: 19.0000, - UnitsInStock: 17, - UnitsOnOrder: 40, - ReorderLevel: 25, - Discontinued: true, - OrderDate: new Date("2003-03-17"), - ProductionDate: new Date("2002-03-17 13:35:25"), - PackagedAt: new Date("2002-03-17 13:35:25"), - PercentInStock: 0.7006 - }, { - ProductID: 3, - ProductName: "Aniseed Syrup", - SupplierID: 1, - CategoryID: 2, - QuantityPerUnit: "12 - 550 ml bottles", - UnitPrice: 10.0000, - UnitsInStock: 13, - UnitsOnOrder: 70, - ReorderLevel: 25, - Discontinued: false, - OrderDate: new Date("2006-03-17"), - ProductionDate: new Date("2005-03-17 12:16:33"), - PackagedAt: new Date("2005-03-17 12:16:33"), - PercentInStock: 0.1634 - }, { - ProductID: 4, - ProductName: "Chef Antons Cajun Seasoning", - SupplierID: 2, - CategoryID: 2, - QuantityPerUnit: "48 - 6 oz jars", - UnitPrice: 22.0000, - UnitsInStock: 53, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: false, - OrderDate: new Date("2016-03-17"), - ProductionDate: new Date("2015-03-17 13:24:28"), - PackagedAt: new Date("2015-03-17 13:24:28"), - PercentInStock: 0.7523 - }, { - ProductID: 5, - ProductName: "Chef Antons Gumbo Mix", - SupplierID: 2, - CategoryID: 2, - QuantityPerUnit: "36 boxes", - UnitPrice: 21.3500, - UnitsInStock: 0, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: true, - OrderDate: new Date("2011-11-11"), - ProductionDate: new Date("2010-11-11 09:15:25"), - PackagedAt: new Date("2010-11-11 09:15:25"), - PercentInStock: 0.5 - }, { - ProductID: 6, - ProductName: "Grandmas Boysenberry Spread", - SupplierID: 3, - CategoryID: 2, - QuantityPerUnit: "12 - 8 oz jars", - UnitPrice: 25.0000, - UnitsInStock: 0, - UnitsOnOrder: 30, - ReorderLevel: 25, - Discontinued: false, - OrderDate: new Date("2017-12-17"), - ProductionDate: new Date("2016-12-17 10:10:30"), - PackagedAt: new Date("2016-12-17 10:10:30"), - PercentInStock: 0.5642 - }, { - ProductID: 7, - ProductName: "Uncle Bobs Organic Dried Pears", - SupplierID: 3, - CategoryID: 7, - QuantityPerUnit: "12 - 1 lb pkgs.", - UnitPrice: 30.0000, - UnitsInStock: 150, - UnitsOnOrder: 30, - ReorderLevel: 10, - Discontinued: false, - OrderDate: new Date("2016-07-17"), - ProductionDate: new Date("2015-07-17 11:11:11"), - PackagedAt: new Date("2015-07-17 11:11:11"), - PercentInStock: 0.1707 - }, { - ProductID: 8, - ProductName: "Northwoods Cranberry Sauce", - SupplierID: 3, - CategoryID: 2, - QuantityPerUnit: "12 - 12 oz jars", - UnitPrice: 40.0000, - UnitsInStock: 6, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: false, - OrderDate: new Date("2018-01-17"), - ProductionDate: new Date("2017-01-17 12:12:32"), - PackagedAt: new Date("2017-01-17 12:12:32"), - PercentInStock: 0.0717 - }, { - ProductID: 9, - ProductName: "Mishi Kobe Niku", - SupplierID: 4, - CategoryID: 6, - QuantityPerUnit: "18 - 500 g pkgs.", - UnitPrice: 97.0000, - UnitsInStock: 29, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: true, - OrderDate: new Date("2010-02-17"), - ProductionDate: new Date("2009-02-17 15:16:35"), - PackagedAt: new Date("2009-02-17 15:16:35"), - PercentInStock: 0.1219 - }, { - ProductID: 10, - ProductName: "Ikura", - SupplierID: 4, - CategoryID: 8, - QuantityPerUnit: "12 - 200 ml jars", - UnitPrice: 31.0000, - UnitsInStock: 31, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: false, - OrderDate: new Date("2008-05-17"), - ProductionDate: new Date("2007-05-17 19:29:35"), - PackagedAt: new Date("2007-05-17 19:29:35"), - PercentInStock: 0.9812 - }, { - ProductID: 11, - ProductName: "Queso Cabrales", - SupplierID: 5, - CategoryID: 4, - QuantityPerUnit: "1 kg pkg.", - UnitPrice: 21.0000, - UnitsInStock: 22, - UnitsOnOrder: 30, - ReorderLevel: 30, - Discontinued: false, - OrderDate: new Date("2009-01-17"), - ProductionDate: new Date("2008-01-17 17:17:35"), - PackagedAt: new Date("2008-01-17 17:17:35"), - PercentInStock: 0.1912 - }, { - ProductID: 12, - ProductName: "Queso Manchego La Pastora", - SupplierID: 5, - CategoryID: 4, - QuantityPerUnit: "10 - 500 g pkgs.", - UnitPrice: 38.0000, - UnitsInStock: 86, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: false, - OrderDate: new Date("2015-11-17"), - ProductionDate: new Date("2014-11-17 15:25:35"), - PackagedAt: new Date("2014-11-17 15:25:35"), - PercentInStock: 0.1717 - }, { - ProductID: 13, - ProductName: "Konbu", - SupplierID: 6, - CategoryID: 8, - QuantityPerUnit: "2 kg box", - UnitPrice: 6.0000, - UnitsInStock: 24, - UnitsOnOrder: 30, - ReorderLevel: 5, - Discontinued: false, - OrderDate: new Date("2015-03-17"), - ProductionDate: new Date("2014-03-17 03:05:35"), - PackagedAt: new Date("2014-03-17 03:05:35"), - PercentInStock: 0.3788 - }, { - ProductID: 14, - ProductName: "Tofu", - SupplierID: 6, - CategoryID: 7, - QuantityPerUnit: "40 - 100 g pkgs.", - UnitPrice: 23.2500, - UnitsInStock: 35, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: false, - OrderDate: new Date("2017-06-17"), - ProductionDate: new Date("2016-06-17 05:03:35"), - PackagedAt: new Date("2016-06-17 05:03:35"), - PercentInStock: 0.0128 - }, { - ProductID: 15, - ProductName: "Genen Shouyu", - SupplierID: 6, - CategoryID: 2, - QuantityPerUnit: "24 - 250 ml bottles", - UnitPrice: 15.5000, - UnitsInStock: 39, - UnitsOnOrder: 30, - ReorderLevel: 5, - Discontinued: false, - OrderDate: new Date("2014-03-17"), - ProductionDate: new Date("2013-03-17 06:15:25"), - PackagedAt: new Date("2013-03-17 06:15:25"), - PercentInStock: 0.892 - }, { - ProductID: 16, - ProductName: "Pavlova", - SupplierID: 7, - CategoryID: 3, - QuantityPerUnit: "32 - 500 g boxes", - UnitPrice: 17.4500, - UnitsInStock: 29, - UnitsOnOrder: 30, - ReorderLevel: 10, - Discontinued: false, - OrderDate: new Date("2018-03-28"), - ProductionDate: new Date("2017-03-28 08:17:35"), - PackagedAt: new Date("2017-03-28 08:17:35"), - PercentInStock: 0.9124 - }, { - ProductID: 17, - ProductName: "Alice Mutton", - SupplierID: 7, - CategoryID: 6, - QuantityPerUnit: "20 - 1 kg tins", - UnitPrice: 39.0000, - UnitsInStock: 0, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: true, - OrderDate: new Date("2015-08-17 10:15:35"), - ProductionDate: new Date("2014-08-17 16:15:35"), - PackagedAt: new Date("2014-08-17 16:15:35"), - PercentInStock: 0.2634 - }, { - ProductID: 18, - ProductName: "Carnarvon Tigers", - SupplierID: 7, - CategoryID: 8, - QuantityPerUnit: "16 kg pkg.", - UnitPrice: 62.5000, - UnitsInStock: 42, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: false, - OrderDate: new Date("2005-09-27"), - ProductionDate: new Date("2004-09-27 16:48:35"), - PackagedAt: new Date("2004-09-27 16:48:35"), - PercentInStock: 0.4632 - }, { - ProductID: 19, - ProductName: "Teatime Chocolate Biscuits", - SupplierID: 8, - CategoryID: 3, - QuantityPerUnit: "", - UnitPrice: 9.2000, - UnitsInStock: 25, - UnitsOnOrder: 30, - ReorderLevel: 5, - Discontinued: false, - OrderDate: new Date("2001-03-17"), - ProductionDate: new Date("2000-03-17 14:34:35"), - PackagedAt: new Date("2000-03-17 14:34:35"), - PercentInStock: 0.069 - }, { - ProductID: 20, - ProductName: "Sir Rodneys Marmalade", - SupplierID: 8, - CategoryID: 3, - QuantityPerUnit: undefined, - UnitPrice: 4.5, - UnitsInStock: 40, - UnitsOnOrder: 30, - ReorderLevel: 0, - Discontinued: false, - OrderDate: new Date("2005-03-17"), - ProductionDate: new Date("2004-03-17 11:17:35"), - PackagedAt: new Date("2004-03-17 11:17:35"), - PercentInStock: 0.234, - } - ]; - /* tslint:enable */ diff --git a/src/app/grid-export/hGridData.ts b/src/app/grid-export/hGridData.ts deleted file mode 100644 index 8098a62922e..00000000000 --- a/src/app/grid-export/hGridData.ts +++ /dev/null @@ -1,267 +0,0 @@ -export interface Song { - Number: number; - Title: string; - Released: Date; - Genre: string; - Album: string; -} -export interface Tour { - Tour: string; - StartedOn: string; - Location: string; - Headliner: string; - TouredBy: string; -} -export interface Album { - Album: string; - LaunchDate: Date; - BillboardReview: number; - USBillboard200: number; - Artist: string; - Songs?: Song[]; -} -export interface Singer { - ID: number; - Artist: string; - Photo?: string; - Debut: number; - GrammyNominations: number; - GrammyAwards: number; - HasGrammyAward: boolean; - Tours?: Tour[]; - Albums?: Album[]; -} - -export const HGRID_DATA = [ - { - Artist: 'Naomí Yepes', - Debut: 2011, - GrammyNominations: 6, - GrammyAwards: 0, - HasGrammyAward: false, - Tours: [ - { - Tour: 'Faithful Tour', - StartedOn: 'Sep 12', - Location: 'Worldwide', - Headliner: 'NO', - TouredBy: 'Naomí Yepes', - TourData: [ - { - Country: 'Belgium', - TicketsSold: 10000, - Attendants: 10000, - }, - { - Country: 'USA', - TicketsSold: 192300, - Attendants: 186523, - } - ] - }, - { - Tour: 'Faithful Tour', - StartedOn: 'Sep 12', - Location: 'Worldwide', - Headliner: 'NO', - TouredBy: 'Naomí Yepes' - }, - { - Tour: 'Faithful Tour', - StartedOn: 'Sep 12', - Location: 'Worldwide', - Headliner: 'NO', - TouredBy: 'Naomí Yepes' - }, - { - Tour: 'Faithful Tour', - StartedOn: 'Sep 12', - Location: 'Worldwide', - Headliner: 'NO', - TouredBy: 'Naomí Yepes' - } - ], - Albums: [ - { - Album: 'Pushing up daisies', - LaunchDate: new Date('May 31, 2000'), - BillboardReview: 86, - USBillboard200: 42, - Artist: 'Naomí Yepes', - Songs: [ - { - Number: 1, - Title: 'Wood Shavifdsafdsafsangs Forever', - Released: new Date('9 Jun 2019'), - Genre: '*fdasfsa', - Album: 'Pushing up daisies' - }, - { - Number: 2, - Title: 'Wood Shavifdsafdsafsavngs Forever', - Released: new Date('9 Jun 2019'), - Genre: '*vxzvczx', - Album: 'Pushing up daisies' - }, - { - Number: 3, - Title: 'Wfdsafsaings Forever', - Released: new Date('9 Jun 2019'), - Genre: '*fdsacewwwqwq', - Album: 'Pushing up daisies' - }, - { - Number: 4, - Title: 'Wood Shavings Forever', - Released: new Date('9 Jun 2019'), - Genre: '*rewqrqcxz', - Album: 'Pushing up daisies' - }, - ] - }, - { - Album: 'Pushing up daisies - Deluxe', - LaunchDate: new Date('May 31, 2001'), - BillboardReview: 12, - USBillboard200: 2, - Artist: 'Naomí Yepes', - Songs: [ - { - Number: 1, - Title: 'Wood Shavings Forever - Remix', - Released: new Date('9 Jun 2020'), - Genre: 'Punk', - Album: 'Pushing up daisies' - }, - ] - }, - { - Album: 'Utopia', - LaunchDate: new Date('Dec 19, 2021'), - BillboardReview: 1, - USBillboard200: 1, - Artist: 'Naomí Yepes', - Songs: [ - { - Number: 1, - Title: 'SANTORINI', - Released: new Date('19 Dec 2021'), - Genre: 'Hip-Hop', - Album: 'Utopia' - }, - { - Number: 2, - Title: 'HEARTBEAT', - Released: new Date('19 Dec 2021'), - Genre: 'Hip-Hop', - Album: 'Utopia' - }, - { - Number: 3, - Title: 'OVERSEAS', - Released: new Date('19 Dec 2021'), - Genre: 'Hip-Hop', - Album: 'Utopia' - }, - ] - }, - { - Album: 'Wish You Were Here', - LaunchDate: new Date('Jul 17, 2020'), - BillboardReview: 5, - USBillboard200: 3, - Artist: 'Naomí Yepes', - Songs: [ - { - Number: 1, - Title: 'Zoom', - Released: new Date('17 Jul 2020'), - Genre: 'Hip-Hop', - Album: 'Wish You Were Here' - }, - { - Number: 2, - Title: 'Do You?', - Released: new Date('17 Jul 2020'), - Genre: 'Hip-Hop', - Album: 'Wish You Were Here' - }, - { - Number: 3, - Title: 'No Photos', - Released: new Date('17 Jul 2020'), - Genre: 'Hip-Hop', - Album: 'Wish You Were Here' - }, - ] - } - ] - }, - { - Artist: 'Babila Ebwélé', - Debut: 2009, - GrammyNominations: 0, - GrammyAwards: 11, - HasGrammyAward: true, - Albums: [ - { - Album: 'Fahrenheit', - LaunchDate: new Date('May 31, 2000'), - BillboardReview: 86, - USBillboard200: 42, - Artist: 'Babila Ebwélé', - Songs: [ - { - Number: 1, - Title: 'Show Out', - Released: new Date('17 Jul 2020'), - Genre: 'Hip-Hop', - Album: 'Fahrenheit' - }, - { - Number: 2, - Title: 'Mood Swings', - Released: new Date('17 Jul 2020'), - Genre: 'Hip-Hop', - Album: 'Fahrenheit' - }, - { - Number: 3, - Title: 'Scenario', - Released: new Date('17 Jul 2020'), - Genre: 'Hip-Hop', - Album: 'Fahrenheit' - }, - ] - } - ], - Tours: [ - { - Tour: 'Astroworld', - StartedOn: 'Jul 21', - Location: 'Worldwide', - Headliner: 'NO', - TouredBy: 'Babila Ebwélé', - TourData: [ - { - Country: 'Bulgaria', - TicketsSold: 25000, - Attendants: 19822, - }, - { - Country: 'Romania', - TicketsSold: 65021, - Attendants: 63320, - } - ] - }, - ] - }, - { - Artist: 'Chloe', - Debut: 2015, - GrammyNominations: 3, - GrammyAwards: 1, - HasGrammyAward: true, - } -] diff --git a/src/app/grid-export/models/grid-models.ts b/src/app/grid-export/models/grid-models.ts new file mode 100644 index 00000000000..1f859b23ea2 --- /dev/null +++ b/src/app/grid-export/models/grid-models.ts @@ -0,0 +1,20 @@ +export interface IProduct { + ProductID: number; + ProductName: string; + SupplierID: number; + CategoryID: number; + QuantityPerUnit: string; + UnitPrice: number; + UnitsInStock: number; + UnitsOnOrder: number; + ReorderLevel: number; + Discontinued: boolean; + OrderDate: Date; + ProductionDate: Date; + PackagedAt: Date; + PercentInStock: number; +} + +export interface ITreeData extends IProduct { + ChildData?: ITreeData[]; +} \ No newline at end of file diff --git a/src/app/grid-export/models/product-category.interface.ts b/src/app/grid-export/models/product-category.interface.ts new file mode 100644 index 00000000000..cdf532b474e --- /dev/null +++ b/src/app/grid-export/models/product-category.interface.ts @@ -0,0 +1,8 @@ +export interface IProductNode { + ID: number; + ParentID: number; // Referência ao ID do pai (-1 para raízes) + Name: string; + UnitPrice: number; + AddedDate: Date; + Discontinued: boolean; +} \ No newline at end of file diff --git a/src/app/grid-export/models/singer.interfaces.ts b/src/app/grid-export/models/singer.interfaces.ts new file mode 100644 index 00000000000..effcedc691c --- /dev/null +++ b/src/app/grid-export/models/singer.interfaces.ts @@ -0,0 +1,43 @@ +export interface ITourPerformance { + country: string; + ticketsSold: number; + attendants: number; +} + +export interface ISong { + number: number; + title: string; + released: Date; + genre: string; + album: string; +} + +export interface ITour { + tour: string; + startedOn: Date; + location: string; + headliner: string; + touredBy: string; + tourData?: ITourPerformance[]; +} + +export interface IAlbum { + album: string; + launchDate: Date; + billboardReview: number; + usBillboard200: number; + artist: string; + songs?: ISong[]; +} + +export interface ISinger { + id: number; + artist: string; + photo?: string; + debut: number; + grammyNominations: number; + grammyAwards: number; + hasGrammyAward: boolean; + tours?: ITour[]; + albums?: IAlbum[]; +} \ No newline at end of file diff --git a/src/app/grid-export/services/data.service.ts b/src/app/grid-export/services/data.service.ts new file mode 100644 index 00000000000..7aa890225b3 --- /dev/null +++ b/src/app/grid-export/services/data.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { IProduct } from '../models/grid-models'; +import { GRID_DATA } from '../data/gridData'; +import { TGRID_DATA } from '../data/tGridData'; +import { HGRID_DATA } from '../data/hGridData'; +import { IProductNode } from '../models/product-category.interface'; +import { ISinger } from '../models/singer.interfaces'; + + +@Injectable({ providedIn: 'root' }) +export class GridDataService { + public getFlatGridData(): IProduct[] { + return GRID_DATA; + } + public getTreeGridData(): IProductNode[] { + return TGRID_DATA; + } + public getHierarchicalGridData(): ISinger[] { + return HGRID_DATA; + } +} \ No newline at end of file diff --git a/src/app/grid-export/summaries/grid-summaries.ts b/src/app/grid-export/summaries/grid-summaries.ts new file mode 100644 index 00000000000..2390656ac5d --- /dev/null +++ b/src/app/grid-export/summaries/grid-summaries.ts @@ -0,0 +1,36 @@ +import { IgxNumberSummaryOperand, IgxSummaryResult } from 'igniteui-angular'; + +export class CustomGridSummary extends IgxNumberSummaryOperand { + public override operate(data: number[] = []): IgxSummaryResult[] { + const result = super.operate(data); + result.push({ + key: 'test', + label: 'Custom summary', + summaryResult: data.filter((rec) => rec > 10 && rec < 30).length + }); + return result; + } +} + +export class HierarchicalGridSummary extends IgxNumberSummaryOperand { + public override operate(data: number[] = []): IgxSummaryResult[] { + return [ + { key: 'min', label: 'Min', summaryResult: IgxNumberSummaryOperand.min(data) }, + { key: 'max', label: 'Max', summaryResult: IgxNumberSummaryOperand.max(data) }, + { key: 'avg', label: 'Avg', summaryResult: IgxNumberSummaryOperand.average(data) } + ]; + } +} + +export class HGridChildSummary extends IgxNumberSummaryOperand { + public override operate(data?: any[]): IgxSummaryResult[] { + const result = []; + result.push( + { + key: 'count', + label: 'Count', + summaryResult: IgxNumberSummaryOperand.count(data) + }); + return result; + } +} \ No newline at end of file From 758f1135c168515aa3d1f1b725c9a05c2545a675 Mon Sep 17 00:00:00 2001 From: iago-dev Date: Sun, 11 Jan 2026 16:03:21 -0300 Subject: [PATCH 2/2] refactor(core): resolve code smells over using any types --- src/app/grid-cellEditing/earliest.summary.ts | 22 ++ .../grid-cellEditing.component.ts | 335 ++++-------------- src/app/grid-cellEditing/grid-config.model.ts | 6 + src/app/grid-cellEditing/grid.facade.ts | 24 ++ 4 files changed, 116 insertions(+), 271 deletions(-) create mode 100644 src/app/grid-cellEditing/earliest.summary.ts create mode 100644 src/app/grid-cellEditing/grid-config.model.ts create mode 100644 src/app/grid-cellEditing/grid.facade.ts diff --git a/src/app/grid-cellEditing/earliest.summary.ts b/src/app/grid-cellEditing/earliest.summary.ts new file mode 100644 index 00000000000..7c1dad44fec --- /dev/null +++ b/src/app/grid-cellEditing/earliest.summary.ts @@ -0,0 +1,22 @@ +import { IgxDateSummaryOperand, IgxSummaryResult } from 'igniteui-angular'; + +export class EarliestSummary extends IgxDateSummaryOperand { + public override operate( + summaries?: IgxSummaryResult[] + ): IgxSummaryResult[] { + return super.operate(summaries).filter(obj => { + if (obj.key === 'earliest') { + const date = obj.summaryResult + ? new Date(obj.summaryResult) + : undefined; + + obj.summaryResult = date + ? new Intl.DateTimeFormat('en-US').format(date) + : undefined; + + return obj; + } + return false; + }); + } +} diff --git a/src/app/grid-cellEditing/grid-cellEditing.component.ts b/src/app/grid-cellEditing/grid-cellEditing.component.ts index bbae42e5430..89f5bbfdc7f 100644 --- a/src/app/grid-cellEditing/grid-cellEditing.component.ts +++ b/src/app/grid-cellEditing/grid-cellEditing.component.ts @@ -1,279 +1,72 @@ import { Component, HostBinding, ViewChild } from '@angular/core'; -import { FormsModule } from '@angular/forms'; -import { - GridSelectionMode, - IGX_SELECT_DIRECTIVES, - IgxButtonDirective, - IgxButtonGroupComponent, - IgxCellEditorTemplateDirective, - IgxCellTemplateDirective, - IgxColumnComponent, - IgxColumnRequiredValidatorDirective, - IgxDateSummaryOperand, - IgxGridComponent, - IgxPaginatorComponent, - IgxSummaryResult, - IgxSwitchComponent, -} from 'igniteui-angular'; - +import { IgxGridComponent, GridSelectionMode } from 'igniteui-angular'; +import { Product } from './product.model'; +import { GridConfig } from './grid-config.model'; +import { GridFacade } from './grid.facade'; import { data, dataWithoutPK } from '../shared/data'; +import { EarliestSummary } from './earliest.summary'; @Component({ - selector: 'app-grid-cellediting', - templateUrl: 'grid-cellEditing.component.html', - styleUrl: 'grid-cellEditing.component.scss', - imports: [ - FormsModule, - IGX_SELECT_DIRECTIVES, - IgxButtonDirective, - IgxButtonGroupComponent, - IgxCellEditorTemplateDirective, - IgxCellTemplateDirective, - IgxColumnComponent, - IgxColumnRequiredValidatorDirective, - IgxGridComponent, - IgxPaginatorComponent, - IgxSwitchComponent, - ] + selector: 'app-grid-cellediting', + templateUrl: 'grid-cellEditing.component.html', + styleUrl: 'grid-cellEditing.component.scss', + providers: [GridFacade] }) export class GridCellEditingComponent { - @ViewChild('grid1', { read: IgxGridComponent, static: true }) - private gridWithPK: IgxGridComponent; - @ViewChild('grid', { read: IgxGridComponent, static: true }) - private gridWithoutPK: IgxGridComponent; - - @HostBinding('style.--ig-size') - protected get sizeStyle() { - return `var(--ig-size-${this.size})`; - } - - public orderDateHidden = false; - public data: any; - public dataWithoutPK: any; - public size : "large" | "medium" | "small" = "small"; - public selectionModes = ['none', 'single', 'multiple']; - public sizes; - public options = { - timezone: '+0430', - format: 'longTime', - digitsInfo: '1.3-4' - }; - public options2 = { - timezone: 'UTC', - format: 'mediumDate', - digitsInfo: '1.0-2' - }; - public formatOptions = this.options; - - public groupable = false; - public exitEditOnBlur = false; - public pname = 'ProductName'; - public selectionMode; - public earliest = EarliestSummary; - - constructor() { - this.data = data; - this.dataWithoutPK = dataWithoutPK; - this.sizes = [ - { label: 'large', selected: this.size === "large", togglable: true }, - { label: 'medium', selected: this.size === "medium", togglable: true }, - { label: 'small', selected: this.size === "small", togglable: true } - ]; - this.selectionMode = GridSelectionMode.multiple; - } - - - - public cellEdit(evt) { - if (!evt.valid) { - evt.cancel = true; - } - } - - public rowEdit(evt) { - if (!evt.valid) { - evt.cancel = true; - } - } - - public addRow() { - this.gridWithPK.addRow({ - ProductID: 21, - ProductName: 'Sir Rodneys Marmalade', - SupplierID: 8, - CategoryID: 3, - QuantityPerUnit: undefined, - UnitPrice: undefined, - UnitsInStock: 999, - UnitsOnOrder: 0, - ReorderLevel: 0, - Discontinued: false, - OrderDate: new Date('1905-03-17') - }); - } - - public changeFormatOptions() { - if (this.formatOptions === this.options) { - this.formatOptions = this.options2; - } else { - this.formatOptions = this.options; - } - } - - public enDisSummaries() { - if (this.gridWithPK.getColumnByName('ReorderLevel').hasSummary) { - this.gridWithPK.disableSummaries([{ fieldName: 'ReorderLevel' }]); - } else { - this.gridWithPK.enableSummaries([{ fieldName: 'ReorderLevel' }]); - } - } - - public deleteRow(event, rowID) { - event.stopPropagation(); - this.gridWithPK.deleteRow(rowID); - } - public updateCell() { - this.gridWithPK.updateCell('Updated', 1, 'ProductName'); - } - public updateRow(rowID) { - this.gridWithPK.updateRow({ - ProductID: rowID + 96, - ProductName: 'UpdatedRow', - SupplierID: 8, - CategoryID: 3, - QuantityPerUnit: undefined, - UnitPrice: undefined, - UnitsInStock: -99 + rowID, - UnitsOnOrder: 0 + rowID, - ReorderLevel: -12 + rowID, - Discontinued: false, - OrderDate: new Date('2005-03-17') - }, rowID); - } - public pin() { - for (const name of ['UnitsInStock', 'Discontinued']) { - if (this.gridWithPK.getColumnByName(name).pinned) { - this.gridWithPK.unpinColumn(name); - } else { - this.gridWithPK.pinColumn(name); - } - } - } - - public hideColumn() { - this.orderDateHidden = !this.orderDateHidden; - } - - public updRecord() { - const newData = 'UPDATED'; - const selectedCell = this.gridWithPK.selectedCells[0]; - if (selectedCell) { - selectedCell.update(newData); - } - } - - public deleteRowbyIndex(index) { - const row = this.gridWithoutPK.getRowByIndex(index); - row.delete(); - } - public updateRowbyIndex(index) { - const row = this.gridWithoutPK.getRowByIndex(index); - row.update({ - ProductID: index + 53, - ProductName: 'UpdatedRow', - SupplierID: 8, - CategoryID: 3, - QuantityPerUnit: undefined, - UnitPrice: undefined, - UnitsInStock: -99 + index, - UnitsOnOrder: 0 + index, - ReorderLevel: -12 + index, - Discontinued: false, - OrderDate: new Date('2005-03-17') - }); - } - public moveColumns() { - const column = this.gridWithoutPK.getColumnByName('ProductName'); - const secColumn = this.gridWithoutPK.getColumnByName('OrderDate'); - this.gridWithoutPK.moveColumn(column, secColumn); - } - public updateSelectedCell() { - let newValue; - const selectedCell = this.gridWithoutPK.selectedCells[0]; - switch (selectedCell.column.dataType) { - case 'string': newValue = 'UpdatedCell'; break; - case 'number': newValue = 0; break; - case 'boolean': newValue = false; break; - case 'date': newValue = new Date('2027-07-31'); break; - } - selectedCell.update(newValue); - } - - public updateSpecificRow() { - this.gridWithPK.updateRow({ - ProductID: 225 + 96, - ProductName: 'UpdatedRow', - SupplierID: 8, - CategoryID: 3, - QuantityPerUnit: undefined, - UnitPrice: undefined, - UnitsInStock: -99 + 225, - UnitsOnOrder: 0 + 225, - ReorderLevel: -12 + 225, - Discontinued: false, - OrderDate: new Date('2005-03-17') - }, 1); - } - - public selectDensity(event) { - this.size = this.sizes[event.index].label; - } - - public customKeydown(args) { - const target = args.target; - const type = args.targetType; - if (type === 'dataCell' && target.editMode && args.event.key.toLowerCase() === 'tab') { - args.event.preventDefault(); - if (target.column.dataType === 'number' && target.editValue < 10) { - args.cancel = true; - alert('The value should be bigger than 10'); - return; - } - const cell = args.event.shiftKey ? - this.gridWithPK.getPreviousCell(target.rowIndex, target.visibleColumnIndex, (col) => col.editable) : - this.gridWithPK.getNextCell(target.rowIndex, target.visibleColumnIndex, (col) => col.editable); - this.gridWithPK.navigateTo(cell.rowIndex, cell.visibleColumnIndex, (obj) => obj.target.nativeElement.focus()); - } else if (type === 'dataCell' && args.event.key.toLowerCase() === 'enter') { - args.cancel = true; - this.gridWithPK.navigateTo(target.rowIndex + 1, target.visibleColumnIndex, (obj) => obj.target.nativeElement.focus()); - } - } - - public handleFocusOut = (event: FocusEvent) => { - if (!this.exitEditOnBlur) return; - - if (!event.relatedTarget || !this.gridWithPK.nativeElement.contains(event.relatedTarget as Node)) { - this.gridWithPK.endEdit(true); - this.gridWithPK.clearCellSelection(); - } - } -} - -class EarliestSummary extends IgxDateSummaryOperand { - constructor() { - super(); - } - - public override operate(summaries?: any[]): IgxSummaryResult[] { - const result = super.operate(summaries).filter((obj) => { - if (obj.key === 'earliest') { - const date = obj.summaryResult ? new Date(obj.summaryResult) : undefined; - obj.summaryResult = date ? new Intl.DateTimeFormat('en-US').format(date) : undefined; - return obj; - } - }); - return result; - } + @ViewChild('grid1', { static: true }) + private gridWithPK!: IgxGridComponent; + + @HostBinding('style.--ig-size') + protected get sizeStyle() { + return `var(--ig-size-${this.config.size})`; + } + + + public data: Product[] = data; + public dataWithoutPK: Product[] = dataWithoutPK; + + + public config: GridConfig = { + selectionMode: 'multiple', + size: 'small', + exitEditOnBlur: false + }; + + public earliest = EarliestSummary; + + constructor(private gridFacade: GridFacade) {} + + public ngAfterViewInit() { + // ✅ EPC reduzido → facade controla grid + this.gridFacade.register(this.gridWithPK); + } + + public addRow() { + this.gridFacade.addRow({ + ProductID: 21, + ProductName: 'Sir Rodneys Marmalade', + SupplierID: 8, + CategoryID: 3, + UnitsInStock: 999, + UnitsOnOrder: 0, + ReorderLevel: 0, + Discontinued: false, + OrderDate: new Date('1905-03-17') + }); + } + + public deleteRow(event: Event, rowID: number) { + event.stopPropagation(); + this.gridFacade.deleteRow(rowID); + } + + public updateCell() { + this.gridFacade.updateCell('Updated', 1, 'ProductName'); + } + + public selectDensity(index: number) { + const sizes: GridConfig['size'][] = ['large', 'medium', 'small']; + this.config = { ...this.config, size: sizes[index] }; + } } - diff --git a/src/app/grid-cellEditing/grid-config.model.ts b/src/app/grid-cellEditing/grid-config.model.ts new file mode 100644 index 00000000000..f9b13135af4 --- /dev/null +++ b/src/app/grid-cellEditing/grid-config.model.ts @@ -0,0 +1,6 @@ +export interface GridConfig { + selectionMode: 'none' | 'single' | 'multiple'; + size: 'large' | 'medium' | 'small'; + exitEditOnBlur: boolean; + } + \ No newline at end of file diff --git a/src/app/grid-cellEditing/grid.facade.ts b/src/app/grid-cellEditing/grid.facade.ts new file mode 100644 index 00000000000..e8565dca4c7 --- /dev/null +++ b/src/app/grid-cellEditing/grid.facade.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { IgxGridComponent } from 'igniteui-angular'; +import { Product } from './product.model'; + +@Injectable() +export class GridFacade { + private grid!: IgxGridComponent; + + public register(grid: IgxGridComponent) { + this.grid = grid; + } + + public addRow(row: Product) { + this.grid.addRow(row); + } + + public deleteRow(id: number) { + this.grid.deleteRow(id); + } + + public updateCell(value: unknown, row: number, field: string) { + this.grid.updateCell(value, row, field); + } +}