Skip to content

Commit

Permalink
feat(metrics): deprecated Statistic and renamed to Metrics (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Sep 25, 2019
1 parent dd04d4e commit 147c894
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 40 deletions.
4 changes: 3 additions & 1 deletion src/aurelia-slickgrid/aurelia-slickgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,15 @@ export class AureliaSlickgridCustomElement {

// send the response process to the postProcess callback
if (backendApi.postProcess) {
processResult.statistics = {
processResult.metrics = {
startTime,
endTime,
executionTime: endTime.valueOf() - startTime.valueOf(),
totalItemCount: this.gridOptions && this.gridOptions.pagination && this.gridOptions.pagination.totalItems
};
backendApi.postProcess(processResult);
// @deprecated, use metrics instead
processResult.statistics = processResult.metrics;
}
} catch (e) {
if (backendApi && backendApi.onError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ describe('gridMenuExtension', () => {
const query = `query { users (first:20,offset:0) { totalCount, nodes { id,name,gender,company } } }`;
const processResult = {
data: { users: { nodes: [] }, pageInfo: { hasNextPage: true }, totalCount: 0 },
statistics: { startTime: now, endTime: now, executionTime: 0, totalItemCount: 0 }
metrics: { startTime: now, endTime: now, executionTime: 0, totalItemCount: 0 }
};
const preSpy = jest.spyOn(gridOptionsMock.backendServiceApi, 'preProcess');
const postSpy = jest.spyOn(gridOptionsMock.backendServiceApi, 'postProcess');
Expand Down
4 changes: 3 additions & 1 deletion src/aurelia-slickgrid/extensions/gridMenuExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ export class GridMenuExtension implements Extension {
// send the response process to the postProcess callback
if (backendApi && backendApi.postProcess) {
if (processResult instanceof Object) {
processResult.statistics = {
processResult.metrics = {
startTime,
endTime,
executionTime: endTime.valueOf() - startTime.valueOf(),
totalItemCount: this.sharedService.gridOptions && this.sharedService.gridOptions.pagination && this.sharedService.gridOptions.pagination.totalItems
};
// @deprecated, use metrics instead
processResult.statistics = processResult.metrics;
}
backendApi.postProcess(processResult);
}
Expand Down
4 changes: 4 additions & 0 deletions src/aurelia-slickgrid/models/graphqlResult.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Metrics } from './metrics.interface';
import { Statistic } from './statistic.interface';

export interface GraphqlResult {
Expand All @@ -11,5 +12,8 @@ export interface GraphqlResult {
}
};

metrics?: Metrics;

/** @deprecated please use "metrics" instead */
statistics?: Statistic;
}
1 change: 1 addition & 0 deletions src/aurelia-slickgrid/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export * from './jQueryUiSliderOption.interface';
export * from './jQueryUiSliderResponse.interface';
export * from './keyCode.enum';
export * from './locale.interface';
export * from './metrics.interface';
export * from './multiColumnSort.interface';
export * from './multipleSelectOption.interface';
export * from './odataOption.interface';
Expand Down
16 changes: 16 additions & 0 deletions src/aurelia-slickgrid/models/metrics.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface Metrics {
/** process start time */
startTime: Date;

/** process end time */
endTime?: Date;

/** time it took to execute in millisecond */
executionTime?: number;

/** number of items displayed */
itemCount?: number;

/** Total count of items in dataset or in database (if used with a BackendServiceApi) */
totalItemCount: number;
}
12 changes: 10 additions & 2 deletions src/aurelia-slickgrid/services/__tests__/backend-utilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@ describe('backend-utilities', () => {
expect(spy).toHaveBeenCalled();
});

it('should execute the "postProcess" when it is defined and add some statistics to the object', () => {
it('should execute the "postProcess" when it is defined and add some metrics to the object', () => {
const now = new Date();
const mockResult = { data: { users: [{ firstName: 'John', lastName: 'Doe' }] } };
const expectaction = {
data: { users: [{ firstName: 'John', lastName: 'Doe' }], },
metrics: {
startTime: now,
endTime: expect.any(Date),
executionTime: expect.any(Number),
itemCount: 1,
totalItemCount: 1
},
// @deprecated, should be removed when Statistic is removed from the lib
statistics: {
startTime: now,
endTime: expect.any(Date),
executionTime: expect.any(Number),
itemCount: 1,
totalItemCount: 1
}
},
};
gridOptionMock.backendServiceApi.postProcess = jest.fn();
gridOptionMock.pagination = { totalItems: 1, pageSizes: [10, 25], pageSize: 10 };
Expand Down
4 changes: 3 additions & 1 deletion src/aurelia-slickgrid/services/backend-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export function executeBackendProcessesCallback(startTime: Date, processResult:
// send the response process to the postProcess callback
if (backendApi.postProcess !== undefined) {
if (processResult instanceof Object) {
processResult.statistics = {
processResult.metrics = {
startTime,
endTime,
executionTime: endTime.valueOf() - startTime.valueOf(),
itemCount: gridOptions && gridOptions.pagination && gridOptions.pagination.totalItems,
totalItemCount: gridOptions && gridOptions.pagination && gridOptions.pagination.totalItems
};
// @deprecated
processResult.statistics = processResult.metrics;
}
backendApi.postProcess(processResult);
}
Expand Down
2 changes: 1 addition & 1 deletion src/aurelia-slickgrid/slick-pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class SlickPaginationCustomElement {
// send the response process to the postProcess callback
if (backendApi.postProcess) {
if (processResult instanceof Object) {
processResult.statistics = {
processResult.metrics = {
startTime,
endTime,
executionTime: endTime.valueOf() - startTime.valueOf(),
Expand Down
8 changes: 4 additions & 4 deletions src/examples/slickgrid/example23.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ <h2>${title}</h2>
<div class="subtitle" innerhtml.bind="subTitle"></div>

<br />
<span if.bind="statistics">
<b>Statistics:</b> ${statistics.endTime | dateFormat: 'DD MMM, h:mm:ss a'} | ${statistics.itemCount} of
${statistics.totalItemCount}
<span if.bind="metrics">
<b>Metrics:</b> ${metrics.endTime | dateFormat: 'DD MMM, h:mm:ss a'} | ${metrics.itemCount} of
${metrics.totalItemCount}
items
</span>
<button class="btn btn-default btn-sm" data-test="language" click.delegate="switchLanguage()">
Expand All @@ -22,6 +22,6 @@ <h2>${title}</h2>
<aurelia-slickgrid grid-id="grid23" column-definitions.bind="columnDefinitions" grid-options.bind="gridOptions"
dataset.bind="dataset" asg-on-aurelia-grid-created.delegate="aureliaGridReady($event.detail)"
asg-on-grid-state-changed.delegate="gridStateChanged($event.detail)"
sg-on-row-count-changed.delegate="refreshStatistics($event.detail.eventData, $event.detail.args)">
sg-on-row-count-changed.delegate="refreshMetrics($event.detail.eventData, $event.detail.args)">
</aurelia-slickgrid>
</template>
8 changes: 4 additions & 4 deletions src/examples/slickgrid/example23.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
JQueryUiSliderOption,
MultipleSelectOption,
OperatorType,
Statistic,
Metrics,
} from '../../aurelia-slickgrid';
import * as moment from 'moment-mini';

Expand Down Expand Up @@ -57,7 +57,7 @@ export class Example23 {
gridOptions: GridOption;
dataset: any[];
selectedLanguage: string;
statistics: Statistic;
metrics: Metrics;

constructor(private i18n: I18N) {
// define the grid options & columns and then create the grid itself
Expand Down Expand Up @@ -219,10 +219,10 @@ export class Example23 {
console.log('Client sample, current Grid State:: ', this.aureliaGrid.gridStateService.getCurrentGridState());
}

refreshStatistics(e, args) {
refreshMetrics(e, args) {
if (args && args.current > 0) {
setTimeout(() => {
this.statistics = {
this.metrics = {
startTime: new Date(),
itemCount: args && args.current,
totalItemCount: this.dataset.length
Expand Down
17 changes: 10 additions & 7 deletions src/examples/slickgrid/example4.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
<h2>${title}</h2>
<div class="subtitle" innerhtml.bind="subTitle"></div>

<br/>
<span if.bind="statistics">
<b>Statistics:</b> ${statistics.endTime | dateFormat: 'DD MMM, h:mm:ss a'} | ${statistics.itemCount} of ${statistics.totalItemCount}
<br />
<span if.bind="metrics">
<b>Metrics:</b> ${metrics.endTime | dateFormat: 'DD MMM, h:mm:ss a'} | ${metrics.itemCount} of
${metrics.totalItemCount}
items
</span>

<button class="btn btn-default btn-sm" click.delegate="aureliaGrid.filterService.clearFilters()">Clear Filters</button>
<button class="btn btn-default btn-sm" click.delegate="aureliaGrid.filterService.clearFilters()">Clear
Filters</button>
<button class="btn btn-default btn-sm" click.delegate="aureliaGrid.sortService.clearSorting()">Clear Sorting</button>

<aurelia-slickgrid grid-id="grid1" column-definitions.bind="columnDefinitions" grid-options.bind="gridOptions" dataset.bind="dataset"
asg-on-aurelia-grid-created.delegate="aureliaGridReady($event.detail)" asg-on-grid-state-changed.delegate="gridStateChanged($event.detail)"
sg-on-row-count-changed.delegate="refreshStatistics($event.detail.eventData, $event.detail.args)">
<aurelia-slickgrid grid-id="grid1" column-definitions.bind="columnDefinitions" grid-options.bind="gridOptions"
dataset.bind="dataset" asg-on-aurelia-grid-created.delegate="aureliaGridReady($event.detail)"
asg-on-grid-state-changed.delegate="gridStateChanged($event.detail)"
sg-on-row-count-changed.delegate="refreshMetrics($event.detail.eventData, $event.detail.args)">
</aurelia-slickgrid>
</template>
8 changes: 4 additions & 4 deletions src/examples/slickgrid/example4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
GridOption,
MultipleSelectOption,
OperatorType,
Statistic,
Metrics,
} from '../../aurelia-slickgrid';

function randomBetween(min, max) {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class Example4 {
columnDefinitions: Column[];
gridOptions: GridOption;
dataset: any[];
statistics: Statistic;
metrics: Metrics;

constructor(private http: HttpClient, private httpFetch: FetchClient) {
this.defineGrid();
Expand Down Expand Up @@ -267,10 +267,10 @@ export class Example4 {
console.log('Client sample, current Grid State:: ', this.aureliaGrid.gridStateService.getCurrentGridState());
}

refreshStatistics(e, args) {
refreshMetrics(e, args) {
if (args && args.current > 0) {
setTimeout(() => {
this.statistics = {
this.metrics = {
startTime: new Date(),
itemCount: args && args.current,
totalItemCount: this.dataset.length
Expand Down
6 changes: 3 additions & 3 deletions src/examples/slickgrid/example5.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ <h2>${title}</h2>
<i class="fa fa-refresh fa-spin fa-lg fa-fw"></i>
</span>
</div>
<span if.bind="statistics">
<b>Statistics:</b> ${statistics.endTime | dateFormat: 'DD MMM, h:mm:ss a'} | ${statistics.executionTime}ms |
${statistics.totalItemCount}
<span if.bind="metrics">
<b>Metrics:</b> ${metrics.endTime | dateFormat: 'DD MMM, h:mm:ss a'} | ${metrics.executionTime}ms |
${metrics.totalItemCount}
items
</span>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/examples/slickgrid/example5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
GridOdataService,
GridOption,
GridStateChange,
Metrics,
OperatorType,
Statistic,
} from '../../aurelia-slickgrid';

const defaultPageSize = 20;
Expand Down Expand Up @@ -38,7 +38,7 @@ export class Example5 {
columnDefinitions: Column[];
gridOptions: GridOption;
dataset = [];
statistics: Statistic;
metrics: Metrics;

odataVersion = 2;
odataQuery = '';
Expand Down Expand Up @@ -110,7 +110,7 @@ export class Example5 {
preProcess: () => this.displaySpinner(true),
process: (query) => this.getCustomerApiCall(query),
postProcess: (response) => {
this.statistics = response.statistics;
this.metrics = response.metrics;
this.displaySpinner(false);
this.getCustomerCallback(response);
}
Expand All @@ -130,8 +130,8 @@ export class Example5 {
// however we need to force Aurelia to do a dirty check, doing a clone object will do just that
this.gridOptions.pagination.totalItems = data['totalRecordCount'];
this.gridOptions = { ...{}, ...this.gridOptions };
if (this.statistics) {
this.statistics.totalItemCount = data['totalRecordCount'];
if (this.metrics) {
this.metrics.totalItemCount = data['totalRecordCount'];
}

// once pagination totalItems is filled, we can update the dataset
Expand Down
6 changes: 3 additions & 3 deletions src/examples/slickgrid/example6.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ <h2>${title}</h2>
</button>
<span><label>Locale</label>: ${selectedLanguage + '.json'}</span>
<br />
<span if.bind="statistics">
<b>Statistics:</b> ${statistics.endTime | dateFormat: 'DD MMM, h:mm:ss a'} | ${statistics.executionTime}ms |
${statistics.totalItemCount}
<span if.bind="metrics">
<b>Metrics:</b> ${metrics.endTime | dateFormat: 'DD MMM, h:mm:ss a'} | ${metrics.executionTime}ms |
${metrics.totalItemCount}
items
</span>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/examples/slickgrid/example6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
MultipleSelectOption,
OperatorType,
SortDirection,
Statistic,
Metrics,
} from '../../aurelia-slickgrid';

const defaultPageSize = 20;
Expand Down Expand Up @@ -46,7 +46,7 @@ export class Example6 {
columnDefinitions: Column[];
gridOptions: GridOption;
dataset = [];
statistics: Statistic;
metrics: Metrics;

isWithCursor = false;
graphqlQuery = '';
Expand Down Expand Up @@ -162,7 +162,7 @@ export class Example6 {
preProcess: () => this.displaySpinner(true),
process: (query) => this.getCustomerApiCall(query),
postProcess: (result: GraphqlResult) => {
this.statistics = result.statistics;
this.metrics = result.metrics;
this.displaySpinner(false);
}
}
Expand Down

0 comments on commit 147c894

Please sign in to comment.