Skip to content

Commit

Permalink
refactor(code): remove deprecated "onBackendEventApi"
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed May 26, 2018
1 parent 4e31b18 commit 05568ad
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 26 deletions.
19 changes: 8 additions & 11 deletions aurelia-slickgrid/src/aurelia-slickgrid/aurelia-slickgrid.ts
Expand Up @@ -187,7 +187,7 @@ export class AureliaSlickgridCustomElement {

// attach the Backend Service API callback functions only after the grid is initialized
// because the preProcess() and onInit() might get triggered
if (this.gridOptions && (this.gridOptions.backendServiceApi || this.gridOptions.onBackendEventApi)) {
if (this.gridOptions && this.gridOptions.backendServiceApi) {
this.attachBackendCallbackFunctions(this.gridOptions);
}

Expand Down Expand Up @@ -285,8 +285,8 @@ export class AureliaSlickgridCustomElement {
* For now, this is GraphQL Service only feautre and it will basically refresh the Dataset & Pagination without having the user to create his own PostProcess every time
*/
createBackendApiInternalPostProcessCallback(gridOptions: GridOption) {
if (gridOptions && (gridOptions.backendServiceApi || gridOptions.onBackendEventApi)) {
const backendApi = gridOptions.backendServiceApi || gridOptions.onBackendEventApi;
if (gridOptions && gridOptions.backendServiceApi) {
const backendApi = gridOptions.backendServiceApi;

// internalPostProcess only works with a GraphQL Service, so make sure it is that type
if (backendApi && backendApi.service && backendApi.service instanceof GraphqlService) {
Expand Down Expand Up @@ -316,7 +316,7 @@ export class AureliaSlickgridCustomElement {

// attach external sorting (backend) when available or default onSort (dataView)
if (gridOptions.enableSorting) {
(gridOptions.backendServiceApi || gridOptions.onBackendEventApi) ? this.sortService.attachBackendOnSort(grid, dataView) : this.sortService.attachLocalOnSort(grid, dataView);
gridOptions.backendServiceApi ? this.sortService.attachBackendOnSort(grid, dataView) : this.sortService.attachLocalOnSort(grid, dataView);
}

// attach external filter (backend) when available or default onFilter (dataView)
Expand All @@ -327,15 +327,12 @@ export class AureliaSlickgridCustomElement {
if (gridOptions.presets && gridOptions.presets.filters) {
this.filterService.populateColumnFilterSearchTerms(grid);
}
(gridOptions.backendServiceApi || gridOptions.onBackendEventApi) ? this.filterService.attachBackendOnFilter(grid) : this.filterService.attachLocalOnFilter(grid, this.dataview);
gridOptions.backendServiceApi ? this.filterService.attachBackendOnFilter(grid) : this.filterService.attachLocalOnFilter(grid, this.dataview);
}

// if user set an onInit Backend, we'll run it right away (and if so, we also need to run preProcess, internalPostProcess & postProcess)
if (gridOptions.backendServiceApi || gridOptions.onBackendEventApi) {
const backendApi = gridOptions.backendServiceApi || gridOptions.onBackendEventApi;
if (gridOptions.onBackendEventApi) {
console.warn(`"onBackendEventApi" has been DEPRECATED, please consider using "backendServiceApi" in the short term since "onBackendEventApi" will be removed in future versions. You can take look at the Aurelia-Slickgrid Wikis for OData/GraphQL Services implementation`);
}
if (gridOptions.backendServiceApi) {
const backendApi = gridOptions.backendServiceApi;

if (backendApi && backendApi.service && backendApi.service.init) {
backendApi.service.init(backendApi.options, gridOptions.pagination, this.grid);
Expand Down Expand Up @@ -406,7 +403,7 @@ export class AureliaSlickgridCustomElement {
}

attachBackendCallbackFunctions(gridOptions: GridOption) {
const backendApi = gridOptions.backendServiceApi || gridOptions.onBackendEventApi;
const backendApi = gridOptions.backendServiceApi;
const serviceOptions: BackendServiceOption = (backendApi && backendApi.service && backendApi.service.options) ? backendApi.service.options : {};
const isExecuteCommandOnInit = (!serviceOptions) ? false : ((serviceOptions && serviceOptions.hasOwnProperty('executeProcessCommandOnInit')) ? serviceOptions['executeProcessCommandOnInit'] : true);

Expand Down
Expand Up @@ -23,7 +23,4 @@ export interface BackendServiceOption {
* users (first: 20, offset: 10, userId: 123) { ... }
*/
extraQueryArguments?: QueryArgument[];

/** Backend Service API callback definitions */
onBackendEventApi?: BackendEventChanged;
}
Expand Up @@ -58,7 +58,7 @@ export interface GridOption {
maxToolTipLength: number;
};

/** Backend Service API definition (GraphQL/OData Services), also goes with onBackendEventApi */
/** Backend Service API definition (GraphQL/OData Services) */
backendServiceApi?: BackendServiceApi;

/** CSS class name used to simulate cell flashing */
Expand Down Expand Up @@ -247,9 +247,6 @@ export interface GridOption {
/** Defaults to true, which will display numbers indicating column sort precedence are displayed in the columns when multiple columns selected */
numberedMultiColumnSort?: boolean;

/** DEPRECATED, Please use "backendServiceApi" instead */
onBackendEventApi?: BackendEventChanged;

/** Pagination options, these are used ONLY with a Backend Service API (GraphQL/OData Services) */
pagination?: Pagination;

Expand Down
Expand Up @@ -411,7 +411,7 @@ export class ControlAndPluginService {
* @param grid
*/
private addGridMenuCustomCommands(grid: any) {
const backendApi = this._gridOptions.backendServiceApi || this._gridOptions.onBackendEventApi || null;
const backendApi = this._gridOptions.backendServiceApi || null;

if (this._gridOptions && this._gridOptions.enableFiltering) {
// show grid menu: clear all filters
Expand Down Expand Up @@ -557,7 +557,7 @@ export class ControlAndPluginService {
/** Call a refresh dataset with a BackendServiceApi */
refreshBackendDataset() {
let query;
const backendApi = this._gridOptions.backendServiceApi || this._gridOptions.onBackendEventApi;
const backendApi = this._gridOptions.backendServiceApi;
if (!backendApi || !backendApi.service || !backendApi.process) {
throw new Error(`BackendServiceApi requires at least a "process" function and a "service" defined`);
}
Expand Down
Expand Up @@ -76,7 +76,7 @@ export class FilterService {
}
const gridOptions: GridOption = args.grid.getOptions() || {};

const backendApi = gridOptions.backendServiceApi || gridOptions.onBackendEventApi;
const backendApi = gridOptions.backendServiceApi;
if (!backendApi || !backendApi.process || !backendApi.service) {
throw new Error(`BackendServiceApi requires at least a "process" function and a "service" defined`);
}
Expand Down
Expand Up @@ -252,7 +252,7 @@ export class GraphqlService implements BackendService {
*/
onFilterChanged(event: Event, args: FilterChangedArgs): Promise<string> {
const gridOptions: GridOption = this._gridOptions || args.grid.getOptions();
const backendApi = gridOptions.backendServiceApi || gridOptions.onBackendEventApi;
const backendApi = gridOptions.backendServiceApi;

if (backendApi === undefined) {
throw new Error('Something went wrong in the GraphqlService, "backendServiceApi" is not initialized');
Expand Down
Expand Up @@ -128,7 +128,7 @@ export class GridOdataService implements BackendService {
*/
onFilterChanged(event: Event, args: FilterChangedArgs): Promise<string> {
const serviceOptions: GridOption = args.grid.getOptions();
const backendApi = serviceOptions.backendServiceApi || serviceOptions.onBackendEventApi;
const backendApi = serviceOptions.backendServiceApi;

if (backendApi === undefined) {
throw new Error('Something went wrong in the GridOdataService, "backendServiceApi" is not initialized');
Expand Down
Expand Up @@ -59,7 +59,7 @@ export class SortService {
throw new Error('Something went wrong when trying to attach the "onBackendSortChanged(event, args)" function, it seems that "args" is not populated correctly');
}
const gridOptions: GridOption = args.grid.getOptions() || {};
const backendApi = gridOptions.backendServiceApi || gridOptions.onBackendEventApi;
const backendApi = gridOptions.backendServiceApi;

if (!backendApi || !backendApi.process || !backendApi.service) {
throw new Error(`BackendServiceApi requires at least a "process" function and a "service" defined`);
Expand Down
4 changes: 2 additions & 2 deletions aurelia-slickgrid/src/aurelia-slickgrid/slick-pagination.ts
Expand Up @@ -105,7 +105,7 @@ export class SlickPaginationCustomElement {
}

refreshPagination(isPageNumberReset: boolean = false) {
const backendApi = this._gridPaginationOptions.backendServiceApi || this._gridPaginationOptions.onBackendEventApi;
const backendApi = this._gridPaginationOptions.backendServiceApi;
if (!backendApi || !backendApi.service || !backendApi.process) {
throw new Error(`BackendServiceApi requires at least a "process" function and a "service" defined`);
}
Expand Down Expand Up @@ -143,7 +143,7 @@ export class SlickPaginationCustomElement {
async onPageChanged(event: Event | undefined, pageNumber: number) {
this.recalculateFromToIndexes();

const backendApi = this._gridPaginationOptions.backendServiceApi || this._gridPaginationOptions.onBackendEventApi;
const backendApi = this._gridPaginationOptions.backendServiceApi;
if (!backendApi || !backendApi.service || !backendApi.process) {
throw new Error(`BackendServiceApi requires at least a "process" function and a "service" defined`);
}
Expand Down

0 comments on commit 05568ad

Please sign in to comment.