From 141d01ac9aa52ffe182453c31318456f67c74788 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Fri, 31 Jan 2020 16:04:03 -0500 Subject: [PATCH] feat(menus): add "onAfterMenuShow" event to all possible menu plugins (#389) --- .../__tests__/cellMenuExtension.spec.ts | 50 ++++++++++++++--- .../__tests__/contextMenuExtension.spec.ts | 50 ++++++++++++++--- .../__tests__/gridMenuExtension.spec.ts | 53 +++++++++++++++---- .../__tests__/headerMenuExtension.spec.ts | 34 ++++++++++-- .../extensions/cellMenuExtension.ts | 38 +++++++------ .../extensions/contextMenuExtension.ts | 39 +++++++------- .../extensions/gridMenuExtension.ts | 20 ++++--- .../extensions/headerMenuExtension.ts | 14 +++-- .../angular-slickgrid/global-grid-options.ts | 8 ++- .../models/cellMenu.interface.ts | 11 ++-- .../models/contextMenu.interface.ts | 11 ++-- .../models/gridMenu.interface.ts | 15 ++++-- .../models/headerMenu.interface.ts | 9 ++-- .../modules/angular-slickgrid/models/index.ts | 1 - .../menuOnBeforeMenuShowArgs.interface.ts | 21 -------- .../angular-slickgrid/slickgrid-config.ts | 3 +- 16 files changed, 252 insertions(+), 125 deletions(-) delete mode 100644 src/app/modules/angular-slickgrid/models/menuOnBeforeMenuShowArgs.interface.ts diff --git a/src/app/modules/angular-slickgrid/extensions/__tests__/cellMenuExtension.spec.ts b/src/app/modules/angular-slickgrid/extensions/__tests__/cellMenuExtension.spec.ts index ddabaaad8..ef68e9bde 100644 --- a/src/app/modules/angular-slickgrid/extensions/__tests__/cellMenuExtension.spec.ts +++ b/src/app/modules/angular-slickgrid/extensions/__tests__/cellMenuExtension.spec.ts @@ -29,6 +29,7 @@ const gridStub = { const mockAddon = jest.fn().mockImplementation(() => ({ init: jest.fn(), destroy: jest.fn(), + onAfterMenuShow: new Slick.Event(), onBeforeMenuClose: new Slick.Event(), onBeforeMenuShow: new Slick.Event(), onColumnsChanged: new Slick.Event(), @@ -68,10 +69,11 @@ describe('CellMenuExtension', () => { maxHeight: 'none', width: 'auto', onExtensionRegistered: jest.fn(), - onCommand: (e, args: MenuCommandItemCallbackArgs) => { }, - onBeforeMenuShow: (e, args: { cell: number; row: number; grid: any; }) => { }, - onBeforeMenuClose: (e, args: { cell: number; row: number; grid: any; menu: any; }) => { }, - onOptionSelected: (e, args: MenuOptionItemCallbackArgs) => { }, + onCommand: () => { }, + onAfterMenuShow: () => { }, + onBeforeMenuShow: () => { }, + onBeforeMenuClose: () => { }, + onOptionSelected: () => { }, }, multiColumnSort: true, pagination: { @@ -160,6 +162,7 @@ describe('CellMenuExtension', () => { onOptionSelected: expect.anything(), onBeforeMenuClose: expect.anything(), onBeforeMenuShow: expect.anything(), + onAfterMenuShow: expect.anything(), onExtensionRegistered: expect.anything(), }); expect(onRegisteredSpy).toHaveBeenCalledWith(instance); @@ -170,13 +173,14 @@ describe('CellMenuExtension', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuClose'); const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onAfterMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onCommand'); const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onOptionSelected'); const instance = extension.register(); instance.onBeforeMenuShow.notify({ cell: 0, row: 0, grid: gridStub }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() @@ -185,12 +189,14 @@ describe('CellMenuExtension', () => { expect(onb4CloseSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); expect(onOptionSpy).not.toHaveBeenCalled(); + expect(onAfterShowSpy).not.toHaveBeenCalled(); }); it('should call internal event handler subscribe and expect the "onBeforeMenuClose" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuClose'); const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onAfterMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onCommand'); const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onOptionSelected'); @@ -198,12 +204,36 @@ describe('CellMenuExtension', () => { const instance = extension.register(); instance.onBeforeMenuClose.notify({ cell: 0, row: 0, grid: gridStub, menu: menuElm }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() ); expect(onb4CloseSpy).toHaveBeenCalledWith(expect.anything(), { cell: 0, row: 0, grid: gridStub, menu: menuElm }); + expect(onAfterShowSpy).not.toHaveBeenCalled(); + expect(onb4ShowSpy).not.toHaveBeenCalled(); + expect(onCommandSpy).not.toHaveBeenCalled(); + expect(onOptionSpy).not.toHaveBeenCalled(); + }); + + it('should call internal event handler subscribe and expect the "onAfterMenuShow" option to be called when addon notify is called', () => { + const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); + const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuClose'); + const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onAfterMenuShow'); + const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onCommand'); + const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onOptionSelected'); + + const instance = extension.register(); + instance.onAfterMenuShow.notify({ cell: 0, row: 0, grid: gridStub }, new Slick.EventData(), gridStub); + + expect(handlerSpy).toHaveBeenCalledTimes(5); + expect(handlerSpy).toHaveBeenCalledWith( + { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, + expect.anything() + ); + expect(onAfterShowSpy).toHaveBeenCalledWith(expect.anything(), { cell: 0, row: 0, grid: gridStub }); + expect(onb4CloseSpy).not.toHaveBeenCalled(); expect(onb4ShowSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); expect(onOptionSpy).not.toHaveBeenCalled(); @@ -213,13 +243,14 @@ describe('CellMenuExtension', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuClose'); const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onAfterMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onCommand'); const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onOptionSelected'); const instance = extension.register(); instance.onCommand.notify({ grid: gridStub, command: 'help' }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() @@ -228,19 +259,21 @@ describe('CellMenuExtension', () => { expect(onOptionSpy).not.toHaveBeenCalled(); expect(onb4CloseSpy).not.toHaveBeenCalled(); expect(onb4ShowSpy).not.toHaveBeenCalled(); + expect(onAfterShowSpy).not.toHaveBeenCalled(); }); it('should call internal event handler subscribe and expect the "onOptionSelected" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuClose'); const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onAfterMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onCommand'); const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onOptionSelected'); const instance = extension.register(); instance.onOptionSelected.notify({ grid: gridStub, command: 'help' }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() @@ -249,6 +282,7 @@ describe('CellMenuExtension', () => { expect(onCommandSpy).not.toHaveBeenCalled(); expect(onb4CloseSpy).not.toHaveBeenCalled(); expect(onb4ShowSpy).not.toHaveBeenCalled(); + expect(onAfterShowSpy).not.toHaveBeenCalled(); }); it('should dispose of the addon', () => { diff --git a/src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts b/src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts index 721e68d21..24f3a130c 100644 --- a/src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts +++ b/src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts @@ -48,6 +48,7 @@ const mockAddon = jest.fn().mockImplementation(() => ({ setOptions: jest.fn(), onBeforeMenuClose: new Slick.Event(), onBeforeMenuShow: new Slick.Event(), + onAfterMenuShow: new Slick.Event(), onColumnsChanged: new Slick.Event(), onCommand: new Slick.Event(), onOptionSelected: new Slick.Event(), @@ -92,10 +93,11 @@ describe('contextMenuExtension', () => { hideMenuOnScroll: true, hideOptionSection: false, onExtensionRegistered: jest.fn(), - onCommand: (e, args: MenuCommandItemCallbackArgs) => { }, - onBeforeMenuShow: (e, args: { cell: number; row: number; grid: any; }) => { }, - onBeforeMenuClose: (e, args: { cell: number; row: number; grid: any; menu: any; }) => { }, - onOptionSelected: (e, args: MenuOptionItemCallbackArgs) => { }, + onCommand: () => { }, + onBeforeMenuShow: () => { }, + onBeforeMenuClose: () => { }, + onAfterMenuShow: () => { }, + onOptionSelected: () => { }, }, pagination: { totalItems: 0 @@ -215,6 +217,7 @@ describe('contextMenuExtension', () => { onOptionSelected: expect.anything(), onBeforeMenuClose: expect.anything(), onBeforeMenuShow: expect.anything(), + onAfterMenuShow: expect.anything(), onExtensionRegistered: expect.anything(), }); }); @@ -223,13 +226,14 @@ describe('contextMenuExtension', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuClose'); const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onAfterMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onCommand'); const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onOptionSelected'); const instance = extension.register(); instance.onBeforeMenuShow.notify({ cell: 0, row: 0, grid: gridStub }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() @@ -238,12 +242,14 @@ describe('contextMenuExtension', () => { expect(onb4CloseSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); expect(onOptionSpy).not.toHaveBeenCalled(); + expect(onAfterShowSpy).not.toHaveBeenCalled(); }); it('should call internal event handler subscribe and expect the "onBeforeMenuClose" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuClose'); const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onAfterMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onCommand'); const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onOptionSelected'); @@ -251,7 +257,7 @@ describe('contextMenuExtension', () => { const instance = extension.register(); instance.onBeforeMenuClose.notify({ cell: 0, row: 0, grid: gridStub, menu: menuElm }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() @@ -260,19 +266,44 @@ describe('contextMenuExtension', () => { expect(onb4ShowSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); expect(onOptionSpy).not.toHaveBeenCalled(); + expect(onAfterShowSpy).not.toHaveBeenCalled(); + }); + + it('should call internal event handler subscribe and expect the "onAfterMenuShow" option to be called when addon notify is called', () => { + const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); + const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuClose'); + const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onAfterMenuShow'); + const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onCommand'); + const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onOptionSelected'); + + const instance = extension.register(); + instance.onAfterMenuShow.notify({ cell: 0, row: 0, grid: gridStub }, new Slick.EventData(), gridStub); + + expect(handlerSpy).toHaveBeenCalledTimes(5); + expect(handlerSpy).toHaveBeenCalledWith( + { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, + expect.anything() + ); + expect(onAfterShowSpy).toHaveBeenCalledWith(expect.anything(), { cell: 0, row: 0, grid: gridStub }); + expect(onb4ShowSpy).not.toHaveBeenCalled(); + expect(onb4CloseSpy).not.toHaveBeenCalled(); + expect(onCommandSpy).not.toHaveBeenCalled(); + expect(onOptionSpy).not.toHaveBeenCalled(); }); it('should call internal event handler subscribe and expect the "onCommand" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuClose'); const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onAfterMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onCommand'); const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onOptionSelected'); const instance = extension.register(); instance.onCommand.notify({ grid: gridStub, command: 'help' }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() @@ -281,19 +312,21 @@ describe('contextMenuExtension', () => { expect(onOptionSpy).not.toHaveBeenCalled(); expect(onb4CloseSpy).not.toHaveBeenCalled(); expect(onb4ShowSpy).not.toHaveBeenCalled(); + expect(onAfterShowSpy).not.toHaveBeenCalled(); }); it('should call internal event handler subscribe and expect the "onOptionSelected" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onb4CloseSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuClose'); const onb4ShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onBeforeMenuShow'); + const onAfterShowSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onAfterMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onCommand'); const onOptionSpy = jest.spyOn(SharedService.prototype.gridOptions.contextMenu, 'onOptionSelected'); const instance = extension.register(); instance.onOptionSelected.notify({ grid: gridStub, command: 'help' }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() @@ -302,6 +335,7 @@ describe('contextMenuExtension', () => { expect(onCommandSpy).not.toHaveBeenCalled(); expect(onb4CloseSpy).not.toHaveBeenCalled(); expect(onb4ShowSpy).not.toHaveBeenCalled(); + expect(onAfterShowSpy).not.toHaveBeenCalled(); }); it('should dispose of the addon', () => { diff --git a/src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts b/src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts index fb6b7229a..c747336b6 100644 --- a/src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts +++ b/src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts @@ -54,6 +54,7 @@ const mockAddon = jest.fn().mockImplementation(() => ({ updateAllTitles: jest.fn(), onColumnsChanged: new Slick.Event(), onCommand: new Slick.Event(), + onAfterMenuShow: new Slick.Event(), onBeforeMenuShow: new Slick.Event(), onMenuClose: new Slick.Event(), })); @@ -95,10 +96,11 @@ describe('gridMenuExtension', () => { hideForceFitButton: false, hideSyncResizeButton: true, onExtensionRegistered: jest.fn(), - onCommand: (e, args: { command: any, item: any, grid: any }) => { }, - onColumnsChanged: (e, args: { columns: Column[], grid: any }) => { }, - onBeforeMenuShow: (e, args: { menu: any, grid: any }) => { }, - onMenuClose: (e, args: { menu: any, grid: any }) => { }, + onCommand: () => { }, + onColumnsChanged: () => { }, + onAfterMenuShow: () => { }, + onBeforeMenuShow: () => { }, + onMenuClose: () => { }, }, pagination: { totalItems: 0 @@ -184,6 +186,7 @@ describe('gridMenuExtension', () => { it('should call internal event handler subscribe and expect the "onColumnsChanged" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onColumnSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onColumnsChanged'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onAfterMenuShow'); const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onBeforeMenuShow'); const onCloseSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onMenuClose'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onCommand'); @@ -192,12 +195,13 @@ describe('gridMenuExtension', () => { const instance = extension.register(); instance.onColumnsChanged.notify({ columns: columnsMock.slice(0, 1), grid: gridStub }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() ); expect(onColumnSpy).toHaveBeenCalledWith(expect.anything(), { columns: columnsMock.slice(0, 1), grid: gridStub }); + expect(onAfterSpy).not.toHaveBeenCalled(); expect(onBeforeSpy).not.toHaveBeenCalled(); expect(onCloseSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); @@ -208,6 +212,7 @@ describe('gridMenuExtension', () => { and it should override "visibleColumns" when array passed as arguments is bigger than previous visible columns`, () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onColumnSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onColumnsChanged'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onAfterMenuShow'); const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onBeforeMenuShow'); const onCloseSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onMenuClose'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onCommand'); @@ -216,12 +221,13 @@ describe('gridMenuExtension', () => { const instance = extension.register(); instance.onColumnsChanged.notify({ columns: columnsMock, grid: gridStub }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() ); expect(onColumnSpy).toHaveBeenCalledWith(expect.anything(), { columns: columnsMock, grid: gridStub }); + expect(onAfterSpy).not.toHaveBeenCalled(); expect(onBeforeSpy).not.toHaveBeenCalled(); expect(onCloseSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); @@ -231,6 +237,7 @@ describe('gridMenuExtension', () => { it('should call internal event handler subscribe and expect the "onBeforeMenuShow" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onColumnSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onColumnsChanged'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onAfterMenuShow'); const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onBeforeMenuShow'); const onCloseSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onMenuClose'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onCommand'); @@ -238,12 +245,36 @@ describe('gridMenuExtension', () => { const instance = extension.register(); instance.onBeforeMenuShow.notify({ grid: gridStub, menu: {} }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() ); expect(onBeforeSpy).toHaveBeenCalledWith(expect.anything(), { grid: gridStub, menu: {} }); + expect(onAfterSpy).not.toHaveBeenCalled(); + expect(onColumnSpy).not.toHaveBeenCalled(); + expect(onCloseSpy).not.toHaveBeenCalled(); + expect(onCommandSpy).not.toHaveBeenCalled(); + }); + + it('should call internal event handler subscribe and expect the "onAfterMenuShow" option to be called when addon notify is called', () => { + const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); + const onColumnSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onColumnsChanged'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onAfterMenuShow'); + const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onBeforeMenuShow'); + const onCloseSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onMenuClose'); + const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onCommand'); + + const instance = extension.register(); + instance.onAfterMenuShow.notify({ grid: gridStub, menu: {} }, new Slick.EventData(), gridStub); + + expect(handlerSpy).toHaveBeenCalledTimes(5); + expect(handlerSpy).toHaveBeenCalledWith( + { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, + expect.anything() + ); + expect(onAfterSpy).toHaveBeenCalledWith(expect.anything(), { grid: gridStub, menu: {} }); + expect(onBeforeSpy).not.toHaveBeenCalled(); expect(onColumnSpy).not.toHaveBeenCalled(); expect(onCloseSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); @@ -252,6 +283,7 @@ describe('gridMenuExtension', () => { it('should call internal event handler subscribe and expect the "onMenuClose" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onColumnSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onColumnsChanged'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onAfterMenuShow'); const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onBeforeMenuShow'); const onCloseSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onMenuClose'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onCommand'); @@ -259,13 +291,14 @@ describe('gridMenuExtension', () => { const instance = extension.register(); instance.onMenuClose.notify({ grid: gridStub, menu: {} }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() ); expect(onCloseSpy).toHaveBeenCalledWith(expect.anything(), { grid: gridStub, menu: {} }); expect(onColumnSpy).not.toHaveBeenCalled(); + expect(onAfterSpy).not.toHaveBeenCalled(); expect(onBeforeSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); }); @@ -273,6 +306,7 @@ describe('gridMenuExtension', () => { it('should call internal event handler subscribe and expect the "onCommand" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); const onColumnSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onColumnsChanged'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onAfterMenuShow'); const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onBeforeMenuShow'); const onCloseSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onMenuClose'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onCommand'); @@ -280,13 +314,14 @@ describe('gridMenuExtension', () => { const instance = extension.register(); instance.onCommand.notify({ grid: gridStub, command: 'help' }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(4); + expect(handlerSpy).toHaveBeenCalledTimes(5); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() ); expect(onCommandSpy).toHaveBeenCalledWith(expect.anything(), { grid: gridStub, command: 'help' }); expect(onColumnSpy).not.toHaveBeenCalled(); + expect(onAfterSpy).not.toHaveBeenCalled(); expect(onBeforeSpy).not.toHaveBeenCalled(); expect(onCloseSpy).not.toHaveBeenCalled(); }); diff --git a/src/app/modules/angular-slickgrid/extensions/__tests__/headerMenuExtension.spec.ts b/src/app/modules/angular-slickgrid/extensions/__tests__/headerMenuExtension.spec.ts index 4d896780e..413a2825b 100644 --- a/src/app/modules/angular-slickgrid/extensions/__tests__/headerMenuExtension.spec.ts +++ b/src/app/modules/angular-slickgrid/extensions/__tests__/headerMenuExtension.spec.ts @@ -42,6 +42,7 @@ const gridStub = { const mockAddon = jest.fn().mockImplementation(() => ({ init: jest.fn(), destroy: jest.fn(), + onAfterMenuShow: new Slick.Event(), onBeforeMenuShow: new Slick.Event(), onColumnsChanged: new Slick.Event(), onCommand: new Slick.Event(), @@ -74,8 +75,9 @@ describe('headerMenuExtension', () => { hideForceFitButton: false, hideSyncResizeButton: true, onExtensionRegistered: jest.fn(), - onCommand: (e, args: { command: any, item: any, grid: any }) => { }, - onBeforeMenuShow: (e, args: { menu: any, grid: any }) => { }, + onCommand: () => { }, + onBeforeMenuShow: () => { }, + onAfterMenuShow: () => { }, }, multiColumnSort: true, pagination: { @@ -165,6 +167,7 @@ describe('headerMenuExtension', () => { hideSortCommands: false, title: '', onCommand: expect.anything(), + onAfterMenuShow: expect.anything(), onBeforeMenuShow: expect.anything(), onExtensionRegistered: expect.anything(), }); @@ -174,36 +177,59 @@ describe('headerMenuExtension', () => { it('should call internal event handler subscribe and expect the "onBeforeMenuShow" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onAfterMenuShow'); const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onBeforeMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onCommand'); const instance = extension.register(); instance.onBeforeMenuShow.notify({ grid: gridStub, menu: {} }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(2); + expect(handlerSpy).toHaveBeenCalledTimes(3); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() ); expect(onBeforeSpy).toHaveBeenCalledWith(expect.anything(), { grid: gridStub, menu: {} }); + expect(onAfterSpy).not.toHaveBeenCalled(); + expect(onCommandSpy).not.toHaveBeenCalled(); + }); + + it('should call internal event handler subscribe and expect the "onAfterMenuShow" option to be called when addon notify is called', () => { + const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onAfterMenuShow'); + const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onBeforeMenuShow'); + const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onCommand'); + + const instance = extension.register(); + instance.onAfterMenuShow.notify({ grid: gridStub, menu: {} }, new Slick.EventData(), gridStub); + + expect(handlerSpy).toHaveBeenCalledTimes(3); + expect(handlerSpy).toHaveBeenCalledWith( + { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, + expect.anything() + ); + expect(onAfterSpy).toHaveBeenCalledWith(expect.anything(), { grid: gridStub, menu: {} }); + expect(onBeforeSpy).not.toHaveBeenCalled(); expect(onCommandSpy).not.toHaveBeenCalled(); }); it('should call internal event handler subscribe and expect the "onCommand" option to be called when addon notify is called', () => { const handlerSpy = jest.spyOn(extension.eventHandler, 'subscribe'); + const onAfterSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onAfterMenuShow'); const onBeforeSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onBeforeMenuShow'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onCommand'); const instance = extension.register(); instance.onCommand.notify({ grid: gridStub, command: 'help' }, new Slick.EventData(), gridStub); - expect(handlerSpy).toHaveBeenCalledTimes(2); + expect(handlerSpy).toHaveBeenCalledTimes(3); expect(handlerSpy).toHaveBeenCalledWith( { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), }, expect.anything() ); expect(onCommandSpy).toHaveBeenCalledWith(expect.anything(), { grid: gridStub, command: 'help' }); expect(onBeforeSpy).not.toHaveBeenCalled(); + expect(onAfterSpy).not.toHaveBeenCalled(); }); it('should dispose of the addon', () => { diff --git a/src/app/modules/angular-slickgrid/extensions/cellMenuExtension.ts b/src/app/modules/angular-slickgrid/extensions/cellMenuExtension.ts index 2bf887a55..25b52b3ab 100644 --- a/src/app/modules/angular-slickgrid/extensions/cellMenuExtension.ts +++ b/src/app/modules/angular-slickgrid/extensions/cellMenuExtension.ts @@ -9,7 +9,6 @@ import { ExtensionName, MenuCommandItem, MenuCommandItemCallbackArgs, - MenuOnBeforeMenuShowArgs, MenuOptionItemCallbackArgs, MenuOptionItem, Locale, @@ -88,26 +87,31 @@ export class CellMenuExtension implements Extension { if (this.sharedService.gridOptions.cellMenu.onExtensionRegistered) { this.sharedService.gridOptions.cellMenu.onExtensionRegistered(this._addon); } - this._eventHandler.subscribe(this._addon.onCommand, (event: Event, args: MenuCommandItemCallbackArgs) => { - if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onCommand === 'function') { + if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onCommand === 'function') { + this._eventHandler.subscribe(this._addon.onCommand, (event: Event, args: MenuCommandItemCallbackArgs) => { this.sharedService.gridOptions.cellMenu.onCommand(event, args); - } - }); - this._eventHandler.subscribe(this._addon.onOptionSelected, (event: Event, args: MenuOptionItemCallbackArgs) => { - if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onOptionSelected === 'function') { + }); + } + if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onOptionSelected === 'function') { + this._eventHandler.subscribe(this._addon.onOptionSelected, (event: Event, args: MenuOptionItemCallbackArgs) => { this.sharedService.gridOptions.cellMenu.onOptionSelected(event, args); - } - }); - this._eventHandler.subscribe(this._addon.onBeforeMenuShow, (event: Event, args: MenuOnBeforeMenuShowArgs) => { - if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onBeforeMenuShow === 'function') { + }); + } + if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onAfterMenuShow === 'function') { + this._eventHandler.subscribe(this._addon.onAfterMenuShow, (event: Event, args: { cell: number; row: number; grid: any; }) => { + this.sharedService.gridOptions.cellMenu.onAfterMenuShow(event, args); + }); + } + if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onBeforeMenuShow === 'function') { + this._eventHandler.subscribe(this._addon.onBeforeMenuShow, (event: Event, args: { cell: number; row: number; grid: any; }) => { this.sharedService.gridOptions.cellMenu.onBeforeMenuShow(event, args); - } - }); - this._eventHandler.subscribe(this._addon.onBeforeMenuClose, (event: Event, args: { cell: number; row: number; grid: any; menu: any; }) => { - if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onBeforeMenuClose === 'function') { + }); + } + if (this.sharedService.gridOptions.cellMenu && typeof this.sharedService.gridOptions.cellMenu.onBeforeMenuClose === 'function') { + this._eventHandler.subscribe(this._addon.onBeforeMenuClose, (event: Event, args: { cell: number; row: number; grid: any; menu: any; }) => { this.sharedService.gridOptions.cellMenu.onBeforeMenuClose(event, args); - } - }); + }); + } } return this._addon; } diff --git a/src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts b/src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts index afec0ecea..7eba47374 100644 --- a/src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts +++ b/src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts @@ -8,11 +8,9 @@ import { Extension, ExtensionName, FileType, - Locale, MenuCallbackArgs, MenuCommandItem, MenuCommandItemCallbackArgs, - MenuOnBeforeMenuShowArgs, MenuOptionItemCallbackArgs, SlickEventHandler, } from '../models/index'; @@ -101,26 +99,31 @@ export class ContextMenuExtension implements Extension { if (contextMenu.onExtensionRegistered) { contextMenu.onExtensionRegistered(this._addon); } - this._eventHandler.subscribe(this._addon.onCommand, (event: Event, args: MenuCommandItemCallbackArgs) => { - if (contextMenu && typeof contextMenu.onCommand === 'function') { + if (contextMenu && typeof contextMenu.onCommand === 'function') { + this._eventHandler.subscribe(this._addon.onCommand, (event: Event, args: MenuCommandItemCallbackArgs) => { contextMenu.onCommand(event, args); - } - }); - this._eventHandler.subscribe(this._addon.onOptionSelected, (event: Event, args: MenuOptionItemCallbackArgs) => { - if (contextMenu && typeof contextMenu.onOptionSelected === 'function') { + }); + } + if (contextMenu && typeof contextMenu.onOptionSelected === 'function') { + this._eventHandler.subscribe(this._addon.onOptionSelected, (event: Event, args: MenuOptionItemCallbackArgs) => { contextMenu.onOptionSelected(event, args); - } - }); - this._eventHandler.subscribe(this._addon.onBeforeMenuShow, (event: Event, args: MenuOnBeforeMenuShowArgs) => { - if (contextMenu && typeof contextMenu.onBeforeMenuShow === 'function') { + }); + } + if (contextMenu && typeof contextMenu.onBeforeMenuShow === 'function') { + this._eventHandler.subscribe(this._addon.onBeforeMenuShow, (event: Event, args: { cell: number; row: number; grid: any; }) => { contextMenu.onBeforeMenuShow(event, args); - } - }); - this._eventHandler.subscribe(this._addon.onBeforeMenuClose, (event: Event, args: { cell: number; row: number; grid: any; menu: any; }) => { - if (contextMenu && typeof contextMenu.onBeforeMenuClose === 'function') { + }); + } + if (contextMenu && typeof contextMenu.onBeforeMenuClose === 'function') { + this._eventHandler.subscribe(this._addon.onBeforeMenuClose, (event: Event, args: { cell: number; row: number; grid: any; menu: any; }) => { contextMenu.onBeforeMenuClose(event, args); - } - }); + }); + } + if (contextMenu && typeof contextMenu.onAfterMenuShow === 'function') { + this._eventHandler.subscribe(this._addon.onAfterMenuShow, (event: Event, args: { cell: number; row: number; grid: any; }) => { + contextMenu.onAfterMenuShow(event, args); + }); + } } return this._addon; } diff --git a/src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts b/src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts index bdfe59ea2..6b48c4f30 100644 --- a/src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts +++ b/src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts @@ -2,7 +2,7 @@ import { Injectable, Optional } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { Constants } from '../constants'; import { - CellArgs, + Column, DelimiterType, Extension, ExtensionName, @@ -12,7 +12,6 @@ import { GridMenuItem, Locale, MenuCommandItemCallbackArgs, - MenuOnBeforeMenuShowArgs, SlickEventHandler, } from '../models'; import { ExcelExportService } from '../services/excelExport.service'; @@ -98,12 +97,17 @@ export class GridMenuExtension implements Extension { if (this.sharedService.gridOptions.gridMenu.onExtensionRegistered) { this.sharedService.gridOptions.gridMenu.onExtensionRegistered(this._addon); } - this._eventHandler.subscribe(this._addon.onBeforeMenuShow, (e: any, args: CellArgs) => { - if (this.sharedService.gridOptions.gridMenu && typeof this.sharedService.gridOptions.gridMenu.onBeforeMenuShow === 'function') { + if (this.sharedService.gridOptions.gridMenu && typeof this.sharedService.gridOptions.gridMenu.onBeforeMenuShow === 'function') { + this._eventHandler.subscribe(this._addon.onBeforeMenuShow, (e: any, args: { grid: any; menu: any; columns: Column[] }) => { this.sharedService.gridOptions.gridMenu.onBeforeMenuShow(e, args); - } - }); - this._eventHandler.subscribe(this._addon.onColumnsChanged, (e: any, args: { columns: any, grid: any }) => { + }); + } + if (this.sharedService.gridOptions.gridMenu && typeof this.sharedService.gridOptions.gridMenu.onAfterMenuShow === 'function') { + this._eventHandler.subscribe(this._addon.onAfterMenuShow, (e: any, args: { grid: any; menu: any; columns: Column[] }) => { + this.sharedService.gridOptions.gridMenu.onAfterMenuShow(e, args); + }); + } + this._eventHandler.subscribe(this._addon.onColumnsChanged, (e: any, args: { grid; any; allColumns: Column[]; columns: Column[]; }) => { this._areVisibleColumnDifferent = true; if (this.sharedService.gridOptions.gridMenu && typeof this.sharedService.gridOptions.gridMenu.onColumnsChanged === 'function') { this.sharedService.gridOptions.gridMenu.onColumnsChanged(e, args); @@ -118,7 +122,7 @@ export class GridMenuExtension implements Extension { this.sharedService.gridOptions.gridMenu.onCommand(e, args); } }); - this._eventHandler.subscribe(this._addon.onMenuClose, (e: any, args: MenuOnBeforeMenuShowArgs) => { + this._eventHandler.subscribe(this._addon.onMenuClose, (e: any, args: { grid: any; menu: any; allColumns: Column[], visibleColumns: Column[] }) => { if (this.sharedService.gridOptions.gridMenu && typeof this.sharedService.gridOptions.gridMenu.onMenuClose === 'function') { this.sharedService.gridOptions.gridMenu.onMenuClose(e, args); } diff --git a/src/app/modules/angular-slickgrid/extensions/headerMenuExtension.ts b/src/app/modules/angular-slickgrid/extensions/headerMenuExtension.ts index c84cfd48a..0088d9539 100644 --- a/src/app/modules/angular-slickgrid/extensions/headerMenuExtension.ts +++ b/src/app/modules/angular-slickgrid/extensions/headerMenuExtension.ts @@ -13,7 +13,6 @@ import { Locale, MenuCommandItem, MenuCommandItemCallbackArgs, - MenuOnBeforeMenuShowArgs, SlickEventHandler, } from '../models/index'; import { FilterService } from '../services/filter.service'; @@ -93,11 +92,16 @@ export class HeaderMenuExtension implements Extension { this.sharedService.gridOptions.headerMenu.onCommand(e, args); } }); - this._eventHandler.subscribe(this._addon.onBeforeMenuShow, (e: any, args: MenuOnBeforeMenuShowArgs) => { - if (this.sharedService.gridOptions.headerMenu && typeof this.sharedService.gridOptions.headerMenu.onBeforeMenuShow === 'function') { + if (this.sharedService.gridOptions.headerMenu && typeof this.sharedService.gridOptions.headerMenu.onBeforeMenuShow === 'function') { + this._eventHandler.subscribe(this._addon.onBeforeMenuShow, (e: Event, args: { grid: any; column: Column; menu: any; }) => { this.sharedService.gridOptions.headerMenu.onBeforeMenuShow(e, args); - } - }); + }); + } + if (this.sharedService.gridOptions.headerMenu && typeof this.sharedService.gridOptions.headerMenu.onAfterMenuShow === 'function') { + this._eventHandler.subscribe(this._addon.onAfterMenuShow, (e: Event, args: { grid: any; column: Column; menu: any; }) => { + this.sharedService.gridOptions.headerMenu.onAfterMenuShow(e, args); + }); + } } return this._addon; } diff --git a/src/app/modules/angular-slickgrid/global-grid-options.ts b/src/app/modules/angular-slickgrid/global-grid-options.ts index d81debb23..d38f42f1e 100644 --- a/src/app/modules/angular-slickgrid/global-grid-options.ts +++ b/src/app/modules/angular-slickgrid/global-grid-options.ts @@ -4,7 +4,7 @@ import { Filters } from './filters/index'; /** * Options that can be passed to the Bootstrap-Datetimepicker directly */ -export const GlobalGridOptions: GridOption = { +export const GlobalGridOptions: Partial = { alwaysShowVerticalScroll: true, autoEdit: false, asyncEditorLoading: false, @@ -160,6 +160,8 @@ export const GlobalGridOptions: GridOption = { pageSize: 25, totalItems: 0 }, + // @ts-ignore + // technically speaking the Row Detail requires the process & viewComponent but we'll ignore it just to set certain options rowDetailView: { cssClass: 'detail-view-toggle', panelRows: 1, @@ -167,10 +169,6 @@ export const GlobalGridOptions: GridOption = { useRowClick: true, useSimpleViewportCalc: true, saveDetailViewOnScroll: false, - - // the following 2 property/method should always be override by the user - process: undefined, - viewComponent: null }, rowHeight: 35, topPanelHeight: 35 diff --git a/src/app/modules/angular-slickgrid/models/cellMenu.interface.ts b/src/app/modules/angular-slickgrid/models/cellMenu.interface.ts index 6e911bb61..f84a39a28 100644 --- a/src/app/modules/angular-slickgrid/models/cellMenu.interface.ts +++ b/src/app/modules/angular-slickgrid/models/cellMenu.interface.ts @@ -1,7 +1,6 @@ import { MenuCallbackArgs } from './menuCallbackArgs.interface'; import { MenuCommandItem } from './menuCommandItem.interface'; import { MenuCommandItemCallbackArgs } from './menuCommandItemCallbackArgs.interface'; -import { MenuOnBeforeMenuShowArgs } from './menuOnBeforeMenuShowArgs.interface'; import { MenuOptionItem } from './menuOptionItem.interface'; import { MenuOptionItemCallbackArgs } from './menuOptionItemCallbackArgs.interface'; @@ -66,14 +65,14 @@ export interface CellMenu { /** Fired after extension (control) is registered by SlickGrid */ onExtensionRegistered?: (plugin: any) => void; - /** SlickGrid Event fired before the menu is shown. */ - onBeforeMenuShow?: (e: Event, args: MenuOnBeforeMenuShowArgs) => void; + /** SlickGrid Event fired After the menu is shown. */ + onAfterMenuShow?: (e: Event, args: { cell: number; row: number; grid: any; }) => void; - /** SlickGrid Event fired when any of the columns checkbox selection changes. */ - onColumnsChanged?: (e: Event, args: any) => void; + /** SlickGrid Event fired Before the menu is shown. */ + onBeforeMenuShow?: (e: Event, args: { cell: number; row: number; grid: any; }) => void; /** SlickGrid Event fired when the menu is closing. */ - onBeforeMenuClose?: (e: Event, args: any) => void; + onBeforeMenuClose?: (e: Event, args: { cell: number; row: number; grid: any; menu: any; }) => void; /** SlickGrid Event fired on menu option clicked from the Command items list */ onCommand?: (e: Event, args: MenuCommandItemCallbackArgs) => void; diff --git a/src/app/modules/angular-slickgrid/models/contextMenu.interface.ts b/src/app/modules/angular-slickgrid/models/contextMenu.interface.ts index b02754cf4..d8973219b 100644 --- a/src/app/modules/angular-slickgrid/models/contextMenu.interface.ts +++ b/src/app/modules/angular-slickgrid/models/contextMenu.interface.ts @@ -1,7 +1,6 @@ import { MenuCallbackArgs } from './menuCallbackArgs.interface'; import { MenuCommandItem } from './menuCommandItem.interface'; import { MenuCommandItemCallbackArgs } from './menuCommandItemCallbackArgs.interface'; -import { MenuOnBeforeMenuShowArgs } from './menuOnBeforeMenuShowArgs.interface'; import { MenuOptionItem } from './menuOptionItem.interface'; import { MenuOptionItemCallbackArgs } from './menuOptionItemCallbackArgs.interface'; @@ -114,14 +113,14 @@ export interface ContextMenu { /** Fired after extension (control) is registered by SlickGrid */ onExtensionRegistered?: (plugin: any) => void; - /** SlickGrid Event fired before the menu is shown. */ - onBeforeMenuShow?: (e: Event, args: MenuOnBeforeMenuShowArgs) => void; + /** SlickGrid Event fired After the menu is shown. */ + onAfterMenuShow?: (e: Event, args: { cell: number; row: number; grid: any; }) => void; - /** SlickGrid Event fired when any of the columns checkbox selection changes. */ - onColumnsChanged?: (e: Event, args: any) => void; + /** SlickGrid Event fired Before the menu is shown. */ + onBeforeMenuShow?: (e: Event, args: { cell: number; row: number; grid: any; }) => void; /** SlickGrid Event fired when the menu is closing. */ - onBeforeMenuClose?: (e: Event, args: any) => void; + onBeforeMenuClose?: (e: Event, args: { cell: number; row: number; grid: any; menu: any; }) => void; /** SlickGrid Event fired on menu option clicked from the Command items list */ onCommand?: (e: Event, args: MenuCommandItemCallbackArgs) => void; diff --git a/src/app/modules/angular-slickgrid/models/gridMenu.interface.ts b/src/app/modules/angular-slickgrid/models/gridMenu.interface.ts index a7ffc4968..4f972b788 100644 --- a/src/app/modules/angular-slickgrid/models/gridMenu.interface.ts +++ b/src/app/modules/angular-slickgrid/models/gridMenu.interface.ts @@ -1,5 +1,7 @@ +import { Column } from './column.interface'; import { GridMenuItem } from './gridMenuItem.interface'; import { MenuCallbackArgs } from './menuCallbackArgs.interface'; +import { MenuCommandItemCallbackArgs } from './menuCommandItemCallbackArgs.interface'; export interface GridMenu { /** Array of Custom Items (title, command, disabled, ...) */ @@ -111,15 +113,18 @@ export interface GridMenu { /** Fired after extension (control) is registered by SlickGrid */ onExtensionRegistered?: (plugin: any) => void; - /** SlickGrid Event fired before the menu is shown. */ - onBeforeMenuShow?: (e: Event, args: any) => void; + /** SlickGrid Event fired After the menu is shown. */ + onAfterMenuShow?: (e: Event, args: { grid: any; menu: any; columns: Column[] }) => void; + + /** SlickGrid Event fired Before the menu is shown. */ + onBeforeMenuShow?: (e: Event, args: { grid: any; menu: any; columns: Column[] }) => void; /** SlickGrid Event fired when any of the columns checkbox selection changes. */ - onColumnsChanged?: (e: Event, args: any) => void; + onColumnsChanged?: (e: Event, args: { grid; any; allColumns: Column[]; columns: Column[]; }) => void; /** SlickGrid Event fired when the menu is closing. */ - onMenuClose?: (e: Event, args: any) => void; + onMenuClose?: (e: Event, args: { grid: any; menu: any; allColumns: Column[], visibleColumns: Column[] }) => void; /** SlickGrid Event fired on menu option clicked from the Command items list */ - onCommand?: (e: Event, args: any) => void; + onCommand?: (e: Event, args: MenuCommandItemCallbackArgs) => void; } diff --git a/src/app/modules/angular-slickgrid/models/headerMenu.interface.ts b/src/app/modules/angular-slickgrid/models/headerMenu.interface.ts index bdd651474..dd2ef0011 100644 --- a/src/app/modules/angular-slickgrid/models/headerMenu.interface.ts +++ b/src/app/modules/angular-slickgrid/models/headerMenu.interface.ts @@ -1,5 +1,5 @@ +import { Column } from './column.interface'; import { MenuCommandItemCallbackArgs } from './menuCommandItemCallbackArgs.interface'; -import { MenuOnBeforeMenuShowArgs } from './menuOnBeforeMenuShowArgs.interface'; export interface HeaderMenu { /** Auto-align drop menu to the left when not enough viewport space to show on the right */ @@ -72,8 +72,11 @@ export interface HeaderMenu { /** Fired after extension (plugin) is registered by SlickGrid */ onExtensionRegistered?: (plugin: any) => void; - /** Fired before the header menu shows up. */ - onBeforeMenuShow?: (e: Event, args: MenuOnBeforeMenuShowArgs) => void; + /** Fired After the header menu shows up. */ + onAfterMenuShow?: (e: Event, args: { grid: any; column: Column; menu: any; }) => void; + + /** Fired Before the header menu shows up. */ + onBeforeMenuShow?: (e: Event, args: { grid: any; column: Column; menu: any; }) => void; /** Fired when a command is clicked */ onCommand?: (e: Event, args: MenuCommandItemCallbackArgs) => void; diff --git a/src/app/modules/angular-slickgrid/models/index.ts b/src/app/modules/angular-slickgrid/models/index.ts index b04e6e350..907ef6f07 100644 --- a/src/app/modules/angular-slickgrid/models/index.ts +++ b/src/app/modules/angular-slickgrid/models/index.ts @@ -99,7 +99,6 @@ export * from './menuCallbackArgs.interface'; export * from './menuCommandItemCallbackArgs.interface'; export * from './menuCommandItem.interface'; export * from './menuItem.interface'; -export * from './menuOnBeforeMenuShowArgs.interface'; export * from './menuOptionItem.interface'; export * from './menuOptionItemCallbackArgs.interface'; export * from './metrics.interface'; diff --git a/src/app/modules/angular-slickgrid/models/menuOnBeforeMenuShowArgs.interface.ts b/src/app/modules/angular-slickgrid/models/menuOnBeforeMenuShowArgs.interface.ts deleted file mode 100644 index 5db9ef857..000000000 --- a/src/app/modules/angular-slickgrid/models/menuOnBeforeMenuShowArgs.interface.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Column } from './column.interface'; - -export interface MenuOption { - tooltip: string; -} -export interface MenuOnBeforeMenuShowArgs { - /** Cell or column index */ - cell?: number; - - /** Row index */ - row?: number; - - /** Reference to the grid. */ - grid: any; - - /** Cell Column definition */ - column: Column; - - /** Menu DOM element */ - menu: MenuOption; -} diff --git a/src/app/modules/angular-slickgrid/slickgrid-config.ts b/src/app/modules/angular-slickgrid/slickgrid-config.ts index 13147f420..b326f249c 100644 --- a/src/app/modules/angular-slickgrid/slickgrid-config.ts +++ b/src/app/modules/angular-slickgrid/slickgrid-config.ts @@ -1,7 +1,8 @@ +import { GridOption } from './models/gridOption.interface'; import { GlobalGridOptions } from './global-grid-options'; export class SlickgridConfig { - options: any; + options: Partial; constructor() { this.options = GlobalGridOptions;