Skip to content

Commit

Permalink
fix(journal): expose sorting functions in transaction sort (#1610)
Browse files Browse the repository at this point in the history
This commit fixes a bug where transactions were not properly sorted in the Posting Journal when sorted by `trans_id`.  It removes the branching structure and replaces it with a simple regular expression.
  • Loading branch information
troyev authored and jniles committed May 8, 2017
1 parent 7cf8682 commit 71206e2
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions client/src/js/services/grid/GridSorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,11 @@ function GridSortingService(util) {
*/
function transactionIds(a, b, rowA, rowB, direction) {
var first, second;
var nullValuesResult = this.gridApi.core.sortHandleNulls(a, b);
// determine integer (reference) value by extracting it from the transaction ID
// match returns an array of mathces - take the first element
first = Number(/[a-z,A-Z]*([0-9]*)/g.exec(a)[1]);
second = Number(/[a-z,A-Z]*([0-9]*)/g.exec(b)[1]);

// if there is no row information we must assume this is a group and we only
// have the transaction ID to inform the sort
var isGroupRowHeader = angular.isUndefined(rowA);

// allow UI Grid to sort null values appropriately
if (nullValuesResult !== null) {
return nullValuesResult;
}

// determine values for comparison
if (isGroupRowHeader) {
var testInteger = /\d+$/;

// determine integer (reference) value by extracting it from the transaction ID
// match returns an array of mathces - take the first element
first = Number(a.match(testInteger).shift());
second = Number(b.match(testInteger).shift());
} else {

// reference value is passed in the row - simply use this
// FIXME(@jniles) we rarely pass the numeric reference value...
first = Number(rowA.entity.reference);
second = Number(rowB.entity.reference);
}

// This (standard method) causes transaction groups to be sorted incorrectly - why has not been demonstrated
// Standard integer compare sort: return first - second;
if (first > second) {
return 1;
}
Expand All @@ -83,10 +59,11 @@ function GridSortingService(util) {
// global sorting configuration
gridOptions.enableSorting = true;

this.transactionIds = transactionIds;
this.sortByReference = sortByReference;
// register for the grid API
util.after(gridOptions, 'onRegisterApi', function onRegisterApi(api) {
this.gridApi = api;
this.transactionIds = transactionIds.bind(this);
}.bind(this));
}

Expand Down

0 comments on commit 71206e2

Please sign in to comment.