Skip to content

Commit

Permalink
deprecate(service): delete GridExtraUtil & move function to GridService
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed May 26, 2018
1 parent d81b37b commit 4e31b18
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
9 changes: 2 additions & 7 deletions aurelia-slickgrid/src/aurelia-slickgrid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
GraphqlService,
GridEventService,
GridService,
GridExtraUtils,
GridStateService,
GridOdataService,
GroupingAndColspanService,
Expand All @@ -35,12 +34,8 @@ export * from './editors/index';
export * from './filter-conditions/index';
export * from './filters/index';

// export some of the Services
export {
GridExtraUtils,
GraphqlService,
GridOdataService
} from './services/index';
// export the Backend Services
export { GraphqlService, GridOdataService } from './services/index';

export function configure(aurelia: any, callback: any) {
aurelia.globalResources(PLATFORM.moduleName('./aurelia-slickgrid'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ControlAndPluginService,
ExportService,
FilterService,
GridExtraService,
GridService,
GridEventService,
GridStateService,
GroupingAndColspanService,
Expand All @@ -16,7 +16,7 @@ export interface AureliaGridInstance {
pluginService: ControlAndPluginService;
exportService: ExportService;
filterService: FilterService;
gridService: GridExtraService;
gridService: GridService;
gridEventService: GridEventService;
gridStateService: GridStateService;
groupingService: GroupingAndColspanService;
Expand Down
26 changes: 25 additions & 1 deletion aurelia-slickgrid/src/aurelia-slickgrid/services/grid.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, GridOption } from './../models/index';
import { CellArgs, Column, GridOption, OnEventArgs } from './../models/index';
import * as $ from 'jquery';

// using external non-typed js libraries
Expand All @@ -23,6 +23,30 @@ export class GridService {
this._dataView = dataView;
}

/**
* From a SlickGrid Event triggered get the Column Definition and Item Data Context
*
* For example the SlickGrid onClick will return cell arguments when subscribing to it.
* From these cellArgs, we want to get the Column Definition and Item Data
* @param cell event args
* @return object with columnDef and dataContext
*/
getColumnFromEventArguments(args: CellArgs): OnEventArgs {
if (!args || !args.grid || !args.grid.getColumns || !args.grid.getDataItem) {
throw new Error('To get the column definition and data, we need to have these arguments passed as objects (row, cell, grid)');
}

return {
row: args.row,
cell: args.cell,
columnDef: args.grid.getColumns()[args.cell],
dataContext: args.grid.getDataItem(args.row),
dataView: this._dataView,
grid: this._grid,
gridDefinition: this._gridOptions
};
}

getDataItemByRowNumber(rowNumber: number) {
if (!this._grid || typeof this._grid.getDataItem !== 'function') {
throw new Error('We could not find SlickGrid Grid object');
Expand Down
13 changes: 0 additions & 13 deletions aurelia-slickgrid/src/aurelia-slickgrid/services/gridExtraUtils.ts

This file was deleted.

3 changes: 1 addition & 2 deletions aurelia-slickgrid/src/aurelia-slickgrid/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export * from './export.service';
export * from './filter.service';
export * from './graphql.service';
export * from './gridEvent.service';
export * from './gridExtra.service';
export * from './gridExtraUtils';
export * from './grid.service';
export * from './gridState.service';
export * from './grid-odata.service';
export * from './groupingAndColspan.service';
Expand Down
2 changes: 1 addition & 1 deletion aurelia-slickgrid/src/examples/slickgrid/example10.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { autoinject, bindable } from 'aurelia-framework';
import { AureliaGridInstance, Column, FieldType, Formatter, Formatters, GridExtraUtils, GridOption } from '../../aurelia-slickgrid';
import { AureliaGridInstance, Column, FieldType, Formatter, Formatters, GridOption } from '../../aurelia-slickgrid';

@autoinject()
export class Example2 {
Expand Down
1 change: 0 additions & 1 deletion aurelia-slickgrid/src/examples/slickgrid/example11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
FieldType,
Formatter,
Formatters,
GridExtraUtils,
GridOption,
OnEventArgs
} from '../../aurelia-slickgrid';
Expand Down
9 changes: 1 addition & 8 deletions aurelia-slickgrid/src/examples/slickgrid/example3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Editors,
FieldType,
Formatters,
GridExtraUtils,
GridOption,
OnEventArgs,
OperatorType
Expand Down Expand Up @@ -197,12 +196,6 @@ export class Example3 {
},
editable: true,
enableCellNavigation: true,
enableCheckboxSelector: false,
rowSelectionOptions: {
// True (Single Selection), False (Multiple Selections)
// Default to True when no "rowSelectionOptions" provided
selectActiveRow: true
},
enableExcelCopyBuffer: true,
editCommandHandler: (item, column, editCommand) => {
this._commandQueue.push(editCommand);
Expand Down Expand Up @@ -261,7 +254,7 @@ export class Example3 {
// You could also subscribe to grid.onClick
// Note that if you had already setup "onCellClick" in the column definition, you cannot use grid.onClick
grid.onClick.subscribe((e, args) => {
const column = GridExtraUtils.getColumnDefinitionAndData(args);
const column = this.aureliaGrid.gridService.getColumnFromEventArguments(args);
console.log('onClick', args, column);
if (column.columnDef.id === 'edit') {
this.alertWarning = `open a modal window to edit: ${column.dataContext.title}`;
Expand Down

0 comments on commit 4e31b18

Please sign in to comment.