Skip to content

Commit

Permalink
fix(build): fox all build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Mar 4, 2018
1 parent 78c32e5 commit 3d24212
Show file tree
Hide file tree
Showing 14 changed files with 4,644 additions and 103 deletions.
36 changes: 20 additions & 16 deletions aurelia-slickgrid/src/aurelia-slickgrid/aurelia-slickgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,13 @@ export class AureliaSlickgridCustomElement {

// 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 && gridOptions.backendServiceApi.service) {
gridOptions.backendServiceApi.service.init(gridOptions.backendServiceApi.options || {}, gridOptions.pagination, this.grid);
if (backendApi && backendApi.service && backendApi.service.init) {
backendApi.service.init(backendApi.options, gridOptions.pagination, this.grid);
}
}

Expand Down Expand Up @@ -306,20 +307,23 @@ export class AureliaSlickgridCustomElement {
const isExecuteCommandOnInit = (!serviceOptions) ? false : ((serviceOptions && serviceOptions.hasOwnProperty('executeProcessCommandOnInit')) ? serviceOptions['executeProcessCommandOnInit'] : true);

// update backend filters (if need be) before the query runs
if (gridOptions && gridOptions.presets) {
if (gridOptions.presets.filters) {
backendApi.service.updateFilters(gridOptions.presets.filters, true);
}
if (gridOptions.presets.sorters) {
backendApi.service.updateSorters(null, gridOptions.presets.sorters);
}
if (gridOptions.presets.pagination) {
backendApi.service.updatePagination(gridOptions.presets.pagination.pageNumber, gridOptions.presets.pagination.pageSize);
}
} else {
const columnFilters = this.filterService.getColumnFilters();
if (columnFilters) {
backendApi.service.updateFilters(columnFilters, false);
if (backendApi) {
const backendService = backendApi.service;
if (gridOptions && gridOptions.presets) {
if (backendService && backendService.updateFilters && gridOptions.presets.filters) {
backendService.updateFilters(gridOptions.presets.filters, true);
}
if (backendService && backendService.updateSorters && gridOptions.presets.sorters) {
backendService.updateSorters(undefined, gridOptions.presets.sorters);
}
if (backendService && backendService.updatePagination && gridOptions.presets.pagination) {
backendService.updatePagination(gridOptions.presets.pagination.pageNumber, gridOptions.presets.pagination.pageSize);
}
} else {
const columnFilters = this.filterService.getColumnFilters();
if (columnFilters && backendService && backendService.updateFilters) {
backendService.updateFilters(columnFilters, false);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class InputFilter implements Filter {
/**
* Set value(s) on the DOM element
*/
setValues(values) {
setValues(values: SearchTerm) {
if (values) {
this.$filterElm.val(values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class MultipleSelectFilter implements Filter {
/**
* Set value(s) on the DOM element
*/
setValues(values) {
setValues(values: SearchTerm[]) {
if (values) {
this.$filterElm.multipleSelect('setSelects', values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class SelectFilter implements Filter {
/**
* Set value(s) on the DOM element
*/
setValues(values) {
setValues(values: SearchTerm | SearchTerm[]) {
if (values) {
this.$filterElm.val(values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class SingleSelectFilter implements Filter {
/**
* Set value(s) on the DOM element
*/
setValues(values) {
setValues(values: SearchTerm | SearchTerm[]) {
if (values) {
values = Array.isArray(values) ? values : [values];
this.$filterElm.multipleSelect('setSelects', values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export interface Filter {
destroy: () => void;

/** Set value(s) on the DOM element */
setValues: (values: SearchTerm | SearchTerm[]) => void;
setValues: (values: SearchTerm | SearchTerm[] | undefined) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { CurrentFilter } from './currentFilter.interface';

export interface GridState {
/** Filters (and their state, columnId, searchTerm(s)) that are currently applied in the grid */
filters?: CurrentFilter[];
filters?: CurrentFilter[] | null;

/** Sorters (and their state, columnId, direction) that are currently applied in the grid */
sorters?: CurrentSorter[];
sorters?: CurrentSorter[] | null;

/** Pagination (and it's state, pageNumber, pageSize) that are currently applied in the grid */
pagination?: {
pageNumber: number;
pageSize: number;
};
} | null;
}
20 changes: 11 additions & 9 deletions aurelia-slickgrid/src/aurelia-slickgrid/services/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,13 @@ export class FilterService {
if (this._columnFilters) {
for (const colId of Object.keys(this._columnFilters)) {
const columnFilter = this._columnFilters[colId];
currentFilters.push({
columnId: colId,
searchTerm: (columnFilter && (columnFilter.searchTerm !== undefined || columnFilter.searchTerm !== null)) ? columnFilter.searchTerm : undefined,
searchTerms: (columnFilter && columnFilter.searchTerms) ? columnFilter.searchTerms : null
});
const filter = { columnId: colId || '' } as CurrentFilter;
if (columnFilter && columnFilter.searchTerms) {
filter.searchTerms = columnFilter.searchTerms;
} else {
filter.searchTerm = (columnFilter && (columnFilter.searchTerm !== undefined || columnFilter.searchTerm !== null)) ? columnFilter.searchTerm : undefined;
}
currentFilters.push(filter);
}
}
return currentFilters;
Expand All @@ -296,7 +298,7 @@ export class FilterService {
columnDef: args.columnDef || null,
operator: args.operator || undefined,
searchTerms: args.searchTerms || undefined,
searchTerm: ((e && e.target) ? (e.target as HTMLInputElement).value : null),
searchTerm: ((e && e.target) ? (e.target as HTMLInputElement).value : undefined),
};
}

Expand All @@ -316,8 +318,8 @@ export class FilterService {
const columnId = columnDef.id || '';

if (columnDef && columnId !== 'selector' && columnDef.filterable) {
let searchTerms: SearchTerm[];
let searchTerm: SearchTerm;
let searchTerms: SearchTerm[] | undefined;
let searchTerm: SearchTerm | undefined;

if (this._columnFilters[columnDef.id]) {
searchTerm = this._columnFilters[columnDef.id].searchTerm || undefined;
Expand Down Expand Up @@ -413,7 +415,7 @@ export class FilterService {
return columnDefinitions;
}

private updateColumnFilters(searchTerm: SearchTerm, searchTerms: any, columnDef: any) {
private updateColumnFilters(searchTerm: SearchTerm | undefined, searchTerms: SearchTerm[] | undefined, columnDef: any) {
if (searchTerm !== undefined && searchTerm !== null && searchTerm !== '') {
this._columnFilters[columnDef.id] = {
columnId: columnDef.id,
Expand Down
37 changes: 21 additions & 16 deletions aurelia-slickgrid/src/aurelia-slickgrid/services/graphql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import QueryBuilder from './graphqlQueryBuilder';
let timer: any;
const DEFAULT_FILTER_TYPING_DEBOUNCE = 750;
const DEFAULT_ITEMS_PER_PAGE = 25;
const DEFAULT_PAGE_SIZE = 20;

@inject(I18N)
export class GraphqlService implements BackendService {
Expand All @@ -42,7 +43,7 @@ export class GraphqlService implements BackendService {
private _grid: any;
onPaginationRefreshed = new EventAggregator();
options: GraphqlServiceOption;
pagination: Pagination | undefined;
pagination: Pagination;
defaultOrderBy: GraphqlSortingOption = { field: 'id', direction: SortDirection.ASC };
defaultPaginationOptions: GraphqlPaginationOption | GraphqlCursorPaginationOption = {
first: DEFAULT_ITEMS_PER_PAGE,
Expand Down Expand Up @@ -154,9 +155,11 @@ export class GraphqlService implements BackendService {
init(serviceOptions?: GraphqlServiceOption, pagination?: Pagination, grid?: any): void {
this._grid = grid;
this.options = serviceOptions || {};
this.pagination = pagination;
if (pagination) {
this.pagination = pagination;
}
if (grid && grid.getColumns && grid.getOptions) {
this._columnDefinitions = grid.getColumns() || serviceOptions.columnDefinitions;
this._columnDefinitions = grid.getColumns();
this._gridOptions = grid.getOptions();
}
}
Expand Down Expand Up @@ -280,7 +283,7 @@ export class GraphqlService implements BackendService {
* }
*/
onPaginationChanged(event: Event, args: PaginationChangedArgs) {
const pageSize = +args.pageSize || this.pagination.pageSize;
const pageSize = +args.pageSize || ((this.pagination) ? this.pagination.pageSize : DEFAULT_PAGE_SIZE);
this.updatePagination(args.newPage, pageSize);

// build the GraphQL query which we will use in the WebAPI callback
Expand Down Expand Up @@ -318,7 +321,7 @@ export class GraphqlService implements BackendService {
const columnFilter = columnFilters[columnId];

// if user defined some "presets", then we need to find the filters from the column definitions instead
let columnDef: Column;
let columnDef: Column | undefined;
if (isUpdatedByPreset && Array.isArray(this._columnDefinitions)) {
columnDef = this._columnDefinitions.find((column: Column) => {
return column.id === columnFilter.columnId;
Expand Down Expand Up @@ -365,7 +368,7 @@ export class GraphqlService implements BackendService {

// if we didn't find an Operator but we have a Filter Type, we should use default Operator
if (!operator && columnDef.filter) {
operator = mapOperatorByFilterType(columnDef.filter.type);
operator = mapOperatorByFilterType(columnDef.filter.type || '');
}

searchByArray.push({
Expand Down Expand Up @@ -436,15 +439,17 @@ export class GraphqlService implements BackendService {
} else {
if (sortColumns) {
for (const column of sortColumns) {
currentSorters.push({
columnId: (column.sortCol.queryField || column.sortCol.field || column.sortCol.id) + '',
direction: column.sortAsc ? SortDirection.ASC : SortDirection.DESC
});

graphqlSorters.push({
field: (column.sortCol.queryField || column.sortCol.field || column.sortCol.id) + '',
direction: column.sortAsc ? SortDirection.ASC : SortDirection.DESC
});
if (column && column.sortCol) {
currentSorters.push({
columnId: (column.sortCol.queryField || column.sortCol.field || column.sortCol.id) + '',
direction: column.sortAsc ? SortDirection.ASC : SortDirection.DESC
});

graphqlSorters.push({
field: (column.sortCol.queryField || column.sortCol.field || column.sortCol.id) + '',
direction: column.sortAsc ? SortDirection.ASC : SortDirection.DESC
});
}
}
}
}
Expand Down Expand Up @@ -505,7 +510,7 @@ export class GraphqlService implements BackendService {
const filtersArray: ColumnFilter[] = (typeof columnFilters === 'object') ? Object.keys(columnFilters).map(key => columnFilters[key]) : columnFilters;

return filtersArray.map((filter) => {
const tmpFilter: CurrentFilter = { columnId: filter.columnId };
const tmpFilter: CurrentFilter = { columnId: filter.columnId || '' };
if (filter.operator) {
tmpFilter.operator = filter.operator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export class GridOdataService implements BackendService {
const mergedOptions = { ...this.defaultOptions, ...options };
this.odataService.options = { ...mergedOptions, top: mergedOptions.top || (pagination ? pagination.pageSize : null) || this.defaultOptions.top };
this.options = this.odataService.options;
this.pagination = pagination;
if (pagination) {
this.pagination = pagination;
}

if (grid && grid.getColumns && grid.getOptions) {
this._columnDefinitions = grid.getColumns() || options.columnDefinitions;
Expand Down Expand Up @@ -172,7 +174,7 @@ export class GridOdataService implements BackendService {
const columnFilter = columnFilters[columnId];

// if user defined some "presets", then we need to find the filters from the column definitions instead
let columnDef: Column;
let columnDef: Column | undefined;
if (isUpdatedByPreset && Array.isArray(this._columnDefinitions)) {
columnDef = this._columnDefinitions.find((column: Column) => {
return column.id === columnFilter.columnId;
Expand Down Expand Up @@ -308,7 +310,7 @@ export class GridOdataService implements BackendService {
* @param columnFilters
*/
updateSorters(sortColumns?: SortChanged[], presetSorters?: CurrentSorter[]) {
let sortByArray = [];
let sortByArray: any[] = [];
const sorterArray: CurrentSorter[] = [];

if (!sortColumns && presetSorters) {
Expand All @@ -331,29 +333,32 @@ export class GridOdataService implements BackendService {
} else {
if (sortColumns) {
for (const column of sortColumns) {
let fieldName = (column.sortCol.queryField || column.sortCol.field || column.sortCol.id) + '';
if (this.odataService.options.caseType === CaseType.pascalCase) {
fieldName = String.titleCase(fieldName);
}
if (column.sortCol) {
let fieldName = (column.sortCol.queryField || column.sortCol.field || column.sortCol.id) + '';
if (this.odataService.options.caseType === CaseType.pascalCase) {
fieldName = String.titleCase(fieldName);
}

sorterArray.push({
columnId: fieldName,
direction: column.sortAsc ? 'asc' : 'desc'
});
sorterArray.push({
columnId: fieldName,
direction: column.sortAsc ? 'asc' : 'desc'
});
}
}
sortByArray = sorterArray;
}
}
}

// transform the sortby array into a CSV string for OData
sortByArray = sortByArray as CurrentSorter[];
const csvString = sortByArray.map((sorter) => `${sorter.columnId} ${sorter.direction.toLowerCase()}`).join(',');
this.odataService.updateOptions({
orderBy: (this.odataService.options.caseType === CaseType.pascalCase) ? String.titleCase(csvString) : csvString
});

// keep current Sorters and update the service options with the new sorting
this._currentSorters = sortByArray;
this._currentSorters = sortByArray as CurrentSorter[];

// build the OData query which we will use in the WebAPI callback
return this.odataService.buildQuery();
Expand All @@ -369,10 +374,10 @@ export class GridOdataService implements BackendService {
*/
private castFilterToColumnFilter(columnFilters: ColumnFilters | CurrentFilter[]): CurrentFilter[] {
// keep current filters & always save it as an array (columnFilters can be an object when it is dealt by SlickGrid Filter)
const filtersArray: ColumnFilter[] = (typeof columnFilters === 'object') ? Object.keys(columnFilters).map(key => columnFilters[key]) : columnFilters;
const filtersArray: ColumnFilter[] = ((typeof columnFilters === 'object') ? Object.keys(columnFilters).map(key => columnFilters[key]) : columnFilters) as CurrentFilter[];

return filtersArray.map((filter) => {
const tmpFilter: CurrentFilter = { columnId: filter.columnId };
const tmpFilter: CurrentFilter = { columnId: filter.columnId || '' };
if (filter.operator) {
tmpFilter.operator = filter.operator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export class GridStateService {
* Get the Filters (and their state, columnId, searchTerm(s)) that are currently applied in the grid
* @return current filters
*/
getCurrentFilters(): CurrentFilter[] {
getCurrentFilters(): CurrentFilter[] | null {
if (this._gridOptions && this._gridOptions.backendServiceApi) {
const backendService = this._gridOptions.backendServiceApi.service;
if (backendService) {
if (backendService && backendService.getCurrentFilters) {
return backendService.getCurrentFilters() as CurrentFilter[];
}
} else {
} else if (this.filterService && this.filterService.getCurrentLocalFilters) {
return this.filterService.getCurrentLocalFilters();
}
return null;
Expand All @@ -65,10 +65,10 @@ export class GridStateService {
* Get current Pagination (and it's state, pageNumber, pageSize) that are currently applied in the grid
* @return current pagination state
*/
getCurrentPagination(): CurrentPagination {
getCurrentPagination(): CurrentPagination | null {
if (this._gridOptions && this._gridOptions.backendServiceApi) {
const backendService = this._gridOptions.backendServiceApi.service;
if (backendService) {
if (backendService && backendService.getCurrentPagination) {
return backendService.getCurrentPagination();
}
} else {
Expand All @@ -81,13 +81,13 @@ export class GridStateService {
* Get the current Sorters (and their state, columnId, direction) that are currently applied in the grid
* @return current sorters
*/
getCurrentSorters(): CurrentSorter[] {
getCurrentSorters(): CurrentSorter[] | null {
if (this._gridOptions && this._gridOptions.backendServiceApi) {
const backendService = this._gridOptions.backendServiceApi.service;
if (backendService) {
if (backendService && backendService.getCurrentSorters) {
return backendService.getCurrentSorters() as CurrentSorter[];
}
} else {
} else if (this.sortService && this.sortService.getCurrentLocalSorters) {
return this.sortService.getCurrentLocalSorters();
}
return null;
Expand Down
Loading

0 comments on commit 3d24212

Please sign in to comment.