Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add registerExternalResources for Components/Services #196

Merged
merged 8 commits into from
Dec 14, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class Example2 {
excelExportOptions: {
sanitizeDataExport: true
},
registerExternalServices: [this.excelExportService, new TextExportService()],
registerExternalResources: [this.excelExportService, new TextExportService()],
showCustomFooter: true, // display some metrics in the bottom custom footer
customFooterOptions: {
// optionally display some text on the left footer container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class Example3 {
excelExportOptions: {
exportWithFormatter: true
},
registerExternalServices: [this.excelExportService],
registerExternalResources: [this.excelExportService],
enableFiltering: true,
rowSelectionOptions: {
// True (Single Selection), False (Multiple Selections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class Example4 {
exportWithFormatter: true,
sanitizeDataExport: true
},
registerExternalServices: [new ExcelExportService()],
registerExternalResources: [new ExcelExportService()],
rowSelectionOptions: {
// True (Single Selection), False (Multiple Selections)
selectActiveRow: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Example5 {
exportWithFormatter: true,
sanitizeDataExport: true
},
registerExternalServices: [new ExcelExportService()],
registerExternalResources: [new ExcelExportService()],
enableFiltering: true,
showCustomFooter: true, // display some metrics in the bottom custom footer
customFooterOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Example6 {
exportWithFormatter: true,
sanitizeDataExport: true
},
registerExternalServices: [new ExcelExportService()],
registerExternalResources: [new ExcelExportService()],
enableFiltering: true,
enableTreeData: true, // you must enable this flag for the filtering & sorting to work as expected
multiColumnSort: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class Example7 {
sanitizeDataExport: true
},
enableFiltering: true,
registerExternalServices: [new ExcelExportService()],
registerExternalResources: [new ExcelExportService()],
enableCellNavigation: true,
enableCheckboxSelector: true,
enableRowSelection: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Example08 {
exportWithFormatter: true,
sanitizeDataExport: true
},
registerExternalServices: [new ExcelExportService()],
registerExternalResources: [new ExcelExportService()],
enableCellNavigation: true,
enableColumnReorder: false,
enableSorting: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class Example11 {
excelExportOptions: {
exportWithFormatter: true
},
registerExternalServices: [new ExcelExportService()],
registerExternalResources: [new ExcelExportService()],
enableFiltering: true,
rowSelectionOptions: {
// True (Single Selection), False (Multiple Selections)
Expand Down
16 changes: 9 additions & 7 deletions examples/webpack-demo-vanilla-bundle/src/examples/example12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
formatNumber,
} from '@slickgrid-universal/common';
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { Slicker, SlickCompositeEditorComponent, SlickerGridInstance, SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle';
import { Slicker, SlickerGridInstance, SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle';
import { SlickCompositeEditorComponent } from '@slickgrid-universal/composite-editor-component';

import { ExampleGridOptions } from './example-grid-options';
import '../salesforce-styles.scss';
Expand Down Expand Up @@ -94,6 +95,7 @@ export class Example12 {
}

constructor() {
this.compositeEditorInstance = new SlickCompositeEditorComponent();
this._bindingEventService = new BindingEventService();
}

Expand Down Expand Up @@ -126,7 +128,7 @@ export class Example12 {
initializeGrid() {
this.columnDefinitions = [
{
id: 'title', name: 'Title', field: 'title', sortable: true, type: FieldType.string, minWidth: 100,
id: 'title', name: 'Title', field: 'title', sortable: true, type: FieldType.string, minWidth: 75,
filterable: true, columnGroup: 'Common Factor',
filter: { model: Filters.compoundInputText },
formatter: Formatters.multiple, params: { formatters: [Formatters.uppercase, Formatters.bold] },
Expand All @@ -145,7 +147,7 @@ export class Example12 {
},
},
{
id: 'duration', name: 'Duration', field: 'duration', sortable: true, filterable: true,
id: 'duration', name: 'Duration', field: 'duration', sortable: true, filterable: true, minWidth: 75,
type: FieldType.number, columnGroup: 'Common Factor',
formatter: (_row, _cell, value) => {
if (value === null || value === undefined) {
Expand All @@ -156,7 +158,7 @@ export class Example12 {
editor: { model: Editors.float, massUpdate: true, decimal: 2, valueStep: 1, minValue: 0, maxValue: 10000, alwaysSaveOnEnterKey: true, required: true },
},
{
id: 'cost', name: 'Cost', field: 'cost', width: 90, minWidth: 100,
id: 'cost', name: 'Cost', field: 'cost', width: 90, minWidth: 70,
sortable: true, filterable: true, type: FieldType.number, columnGroup: 'Analysis',
filter: { model: Filters.compoundInputNumber },
formatter: Formatters.dollar,
Expand Down Expand Up @@ -196,7 +198,7 @@ export class Example12 {
editor: { model: Editors.date, massUpdate: true, params: { hideClearButton: false } },
},
{
id: 'completed', name: 'Completed', field: 'completed', width: 80, minWidth: 20, maxWidth: 100,
id: 'completed', name: 'Completed', field: 'completed', width: 80, minWidth: 75, maxWidth: 100,
sortable: true, filterable: true, columnGroup: 'Period',
formatter: Formatters.multiple,
params: { formatters: [Formatters.checkmarkMaterial, Formatters.center] },
Expand Down Expand Up @@ -363,7 +365,7 @@ export class Example12 {
excelExportOptions: {
exportWithFormatter: false
},
registerExternalServices: [new ExcelExportService()],
registerExternalResources: [new ExcelExportService(), this.compositeEditorInstance],
enableFiltering: true,
rowSelectionOptions: {
// True (Single Selection), False (Multiple Selections)
Expand Down Expand Up @@ -885,7 +887,7 @@ export class Example12 {
}

setTimeout(() => {
this.compositeEditorInstance = this.sgb.slickCompositeEditor?.openDetails({
this.compositeEditorInstance?.openDetails({
headerTitle: modalTitle,
modalType,
// showCloseButtonOutside: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class Example50 {
exportOptions: {
exportWithFormatter: true,
},
registerExternalServices: [new TextExportService()],
registerExternalResources: [new TextExportService()],
enableCellNavigation: true,
enableCheckboxSelector: true,
enableFiltering: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ describe('contextMenuExtension', () => {
it('should call "exportToExcel" and expect an error thrown when ExcelExportService is not registered prior to calling the method', () => {
const copyGridOptionsMock = { ...gridOptionsMock, enableExcelExport: true, enableTextExport: false, contextMenu: { hideCopyCellValueCommand: true, hideExportCsvCommand: true, hideExportExcelCommand: false } } as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([]);
extension.register();

const menuItemCommand = ((copyGridOptionsMock.contextMenu as ContextMenu).commandItems as MenuCommandItem[]).find((item: MenuCommandItem) => item.command === 'export-excel') as MenuCommandItem;
Expand All @@ -811,7 +811,7 @@ describe('contextMenuExtension', () => {
it('should call "exportToFile" with CSV and expect an error thrown when TextExportService is not registered prior to calling the method', () => {
const copyGridOptionsMock = { ...gridOptionsMock, enableExcelExport: false, enableTextExport: true, contextMenu: { hideCopyCellValueCommand: true, hideExportCsvCommand: false, hideExportExcelCommand: true } } as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([]);
extension.register();

const menuItemCommand = ((copyGridOptionsMock.contextMenu as ContextMenu).commandItems as MenuCommandItem[]).find((item: MenuCommandItem) => item.command === 'export-csv') as MenuCommandItem;
Expand All @@ -834,7 +834,7 @@ describe('contextMenuExtension', () => {
const excelExportSpy = jest.spyOn(excelExportServiceStub, 'exportToExcel');
const copyGridOptionsMock = { ...gridOptionsMock, enableExcelExport: true, enableTextExport: false, contextMenu: { hideCopyCellValueCommand: true, hideExportCsvCommand: true, hideExportExcelCommand: false } } as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([excelExportServiceStub]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([excelExportServiceStub]);
extension.register();

const menuItemCommand = ((copyGridOptionsMock.contextMenu as ContextMenu).commandItems as MenuCommandItem[]).find((item: MenuCommandItem) => item.command === 'export-excel') as MenuCommandItem;
Expand All @@ -850,7 +850,7 @@ describe('contextMenuExtension', () => {
const exportSpy = jest.spyOn(exportServiceStub, 'exportToFile');
const copyGridOptionsMock = { ...gridOptionsMock, enableExcelExport: false, enableTextExport: true, contextMenu: { hideCopyCellValueCommand: true, hideExportCsvCommand: false, hideExportExcelCommand: true } } as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([exportServiceStub]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([exportServiceStub]);
extension.register();

const menuItemCommand = ((copyGridOptionsMock.contextMenu as ContextMenu).commandItems as MenuCommandItem[]).find((item: MenuCommandItem) => item.command === 'export-csv') as MenuCommandItem;
Expand All @@ -868,7 +868,7 @@ describe('contextMenuExtension', () => {
const exportSpy = jest.spyOn(exportServiceStub, 'exportToFile');
const copyGridOptionsMock = { ...gridOptionsMock, enableExcelExport: false, enableTextExport: true, contextMenu: { hideCopyCellValueCommand: true, hideExportCsvCommand: false, hideExportExcelCommand: true } } as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([exportServiceStub]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([exportServiceStub]);
extension.register();

const menuItemCommand = ((copyGridOptionsMock.contextMenu as ContextMenu).commandItems as MenuCommandItem[]).find((item: MenuCommandItem) => item.command === 'export-text-delimited') as MenuCommandItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ describe('gridMenuExtension', () => {
{ notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), },
expect.anything()
);
expect(onCommandSpy).toHaveBeenCalledWith(expect.anything(), { item: { command: 'help' }, column: {}, grid: gridStub, command: 'help' });
expect(onCommandSpy).toHaveBeenCalledWith(expect.anything(), { item: { command: 'help' }, column: {} as Column, grid: gridStub, command: 'help' });
expect(onAfterSpy).not.toHaveBeenCalled();
expect(onColumnSpy).not.toHaveBeenCalled();
expect(onBeforeSpy).not.toHaveBeenCalled();
Expand Down Expand Up @@ -633,7 +633,7 @@ describe('gridMenuExtension', () => {

it('should call "exportToExcel" and expect an error thrown when ExcelExportService is not registered prior to calling the method', (done) => {
try {
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([]);
const instance = extension.register() as SlickGridMenu;
instance.onCommand!.notify({ item: { command: 'export-excel' }, column: {} as Column, grid: gridStub, command: 'export-excel' }, new Slick.EventData(), gridStub);
} catch (e) {
Expand All @@ -644,7 +644,7 @@ describe('gridMenuExtension', () => {

it('should call "exportToFile" with CSV and expect an error thrown when TextExportService is not registered prior to calling the method', (done) => {
try {
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([]);
const instance = extension.register() as SlickGridMenu;
instance.onCommand!.notify({ item: { command: 'export-csv' }, column: {} as Column, grid: gridStub, command: 'export-csv' }, new Slick.EventData(), gridStub);
} catch (e) {
Expand All @@ -666,7 +666,7 @@ describe('gridMenuExtension', () => {
it('should call "exportToExcel" set when the command triggered is "export-excel"', () => {
const excelExportSpy = jest.spyOn(excelExportServiceStub, 'exportToExcel');
const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu as GridMenu, 'onCommand');
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([excelExportServiceStub]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([excelExportServiceStub]);

const instance = extension.register() as SlickGridMenu;
instance.onCommand!.notify({ item: { command: 'export-excel' }, column: {} as Column, grid: gridStub, command: 'export-excel' }, new Slick.EventData(), gridStub);
Expand All @@ -681,7 +681,7 @@ describe('gridMenuExtension', () => {
it('should call "exportToFile" with CSV set when the command triggered is "export-csv"', () => {
const exportSpy = jest.spyOn(exportServiceStub, 'exportToFile');
const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu as GridMenu, 'onCommand');
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([exportServiceStub]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([exportServiceStub]);

const instance = extension.register() as SlickGridMenu;
instance.onCommand!.notify({ item: { command: 'export-csv' }, column: {} as Column, grid: gridStub, command: 'export-csv' }, new Slick.EventData(), gridStub);
Expand All @@ -698,7 +698,7 @@ describe('gridMenuExtension', () => {
it('should call "exportToFile" with Text Delimited set when the command triggered is "export-text-delimited"', () => {
const exportSpy = jest.spyOn(exportServiceStub, 'exportToFile');
const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu as GridMenu, 'onCommand');
jest.spyOn(SharedService.prototype, 'externalRegisteredServices', 'get').mockReturnValue([exportServiceStub]);
jest.spyOn(SharedService.prototype, 'externalRegisteredResources', 'get').mockReturnValue([exportServiceStub]);

const instance = extension.register() as SlickGridMenu;
instance.onCommand!.notify({ item: { command: 'export-text-delimited' }, column: {} as Column, grid: gridStub, command: 'export-text-delimited' }, new Slick.EventData(), gridStub);
Expand Down
12 changes: 6 additions & 6 deletions packages/common/src/extensions/contextMenuExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class ContextMenuExtension implements Extension {
command: commandName,
positionOrder: 51,
action: () => {
const registedServices = this.sharedService?.externalRegisteredServices || [];
const registedServices = this.sharedService?.externalRegisteredResources || [];
const excelService: TextExportService = registedServices.find((service: any) => service.className === 'TextExportService');
if (excelService?.exportToFile) {
excelService.exportToFile({
Expand All @@ -243,7 +243,7 @@ export class ContextMenuExtension implements Extension {
useUtf8WithBom: true,
});
} else {
throw new Error(`[Slickgrid-Universal] You must register the TextExportService to properly use Export to File in the Context Menu. Example:: this.gridOptions = { enableTextExport: true, registerExternalServices: [new TextExportService()] };`);
throw new Error(`[Slickgrid-Universal] You must register the TextExportService to properly use Export to File in the Context Menu. Example:: this.gridOptions = { enableTextExport: true, registerExternalResources: [new TextExportService()] };`);
}
},
}
Expand All @@ -263,15 +263,15 @@ export class ContextMenuExtension implements Extension {
command: commandName,
positionOrder: 52,
action: () => {
const registedServices = this.sharedService?.externalRegisteredServices || [];
const registedServices = this.sharedService?.externalRegisteredResources || [];
const excelService: ExcelExportService = registedServices.find((service: any) => service.className === 'ExcelExportService');
if (excelService?.exportToExcel) {
excelService.exportToExcel({
filename: 'export',
format: FileType.xlsx,
});
} else {
throw new Error(`[Slickgrid-Universal] You must register the ExcelExportService to properly use Export to Excel in the Context Menu. Example:: this.gridOptions = { enableExcelExport: true, registerExternalServices: [new ExcelExportService()] };`);
throw new Error(`[Slickgrid-Universal] You must register the ExcelExportService to properly use Export to Excel in the Context Menu. Example:: this.gridOptions = { enableExcelExport: true, registerExternalResources: [new ExcelExportService()] };`);
}
},
}
Expand All @@ -291,7 +291,7 @@ export class ContextMenuExtension implements Extension {
command: commandName,
positionOrder: 53,
action: () => {
const registedServices = this.sharedService?.externalRegisteredServices || [];
const registedServices = this.sharedService?.externalRegisteredResources || [];
const excelService: TextExportService = registedServices.find((service: any) => service.className === 'TextExportService');
if (excelService?.exportToFile) {
excelService.exportToFile({
Expand All @@ -301,7 +301,7 @@ export class ContextMenuExtension implements Extension {
useUtf8WithBom: true,
});
} else {
throw new Error(`[Slickgrid-Universal] You must register the TextExportService to properly use Export to File in the Context Menu. Example:: this.gridOptions = { enableTextExport: true, registerExternalServices: [new TextExportService()] };`);
throw new Error(`[Slickgrid-Universal] You must register the TextExportService to properly use Export to File in the Context Menu. Example:: this.gridOptions = { enableTextExport: true, registerExternalResources: [new TextExportService()] };`);
}
},
}
Expand Down
Loading