Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit fdc1155

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
feat(sorters): consolidate & provide all date sorters
1 parent 1e983e2 commit fdc1155

20 files changed

+199
-207
lines changed

src/app/modules/angular-slickgrid/services/collection.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class CollectionService {
106106
const value1 = (enableTranslateLabel) ? this.translate.instant(dataRow1[propertyName] || ' ') : dataRow1[propertyName];
107107
const value2 = (enableTranslateLabel) ? this.translate.instant(dataRow2[propertyName] || ' ') : dataRow2[propertyName];
108108

109-
const sortResult = sortByFieldType(value1, value2, fieldType, sortDirection, columnDef);
109+
const sortResult = sortByFieldType(fieldType, value1, value2, sortDirection, columnDef);
110110
if (sortResult !== SortDirectionNumber.neutral) {
111111
return sortResult;
112112
}
@@ -123,7 +123,7 @@ export class CollectionService {
123123
sortedCollection = collection.sort((dataRow1: any, dataRow2: any) => {
124124
const value1 = (enableTranslateLabel) ? this.translate.instant(dataRow1[propertyName] || ' ') : dataRow1[propertyName];
125125
const value2 = (enableTranslateLabel) ? this.translate.instant(dataRow2[propertyName] || ' ') : dataRow2[propertyName];
126-
const sortResult = sortByFieldType(value1, value2, fieldType, sortDirection, columnDef);
126+
const sortResult = sortByFieldType(fieldType, value1, value2, sortDirection, columnDef);
127127
if (sortResult !== SortDirectionNumber.neutral) {
128128
return sortResult;
129129
}
@@ -136,7 +136,7 @@ export class CollectionService {
136136
sortedCollection = collection.sort((dataRow1: any, dataRow2: any) => {
137137
const value1 = (enableTranslateLabel) ? this.translate.instant(dataRow1 || ' ') : dataRow1;
138138
const value2 = (enableTranslateLabel) ? this.translate.instant(dataRow2 || ' ') : dataRow2;
139-
const sortResult = sortByFieldType(value1, value2, fieldType, sortDirection, columnDef);
139+
const sortResult = sortByFieldType(fieldType, value1, value2, sortDirection, columnDef);
140140
if (sortResult !== SortDirectionNumber.neutral) {
141141
return sortResult;
142142
}

src/app/modules/angular-slickgrid/services/sort.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export class SortService {
277277
return customSortResult;
278278
}
279279
} else {
280-
const sortResult = sortByFieldType(value1, value2, fieldType, sortDirection, columnSortObj.sortCol);
280+
const sortResult = sortByFieldType(fieldType, value1, value2, sortDirection, columnSortObj.sortCol);
281281
if (sortResult !== SortDirectionNumber.neutral) {
282282
return sortResult;
283283
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum';
2-
import { dateEuroShortSorter } from '../dateEuroShortSorter';
1+
import { sortByFieldType } from '../sorterUtilities';
2+
import { FieldType, SortDirectionNumber } from '../../models';
33

44
describe('the Date Euro Short Sorter', () => {
5-
it('should return an array of Euro dates sorted ascending when only valid dates are provided', () => {
5+
it('should return an array of dates sorted ascending when only valid dates are provided', () => {
66
const direction = SortDirectionNumber.asc;
77
const inputArray = ['8/8/98', '8/10/98', '8/8/98', '01/01/18', '14/12/98'];
8-
inputArray.sort((value1, value2) => dateEuroShortSorter(value1, value2, direction));
8+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction));
99
expect(inputArray).toEqual(['8/8/98', '8/8/98', '8/10/98', '14/12/98', '01/01/18']);
1010
});
1111

12-
it('should return an array of Euro dates sorted descending when only valid dates are provided', () => {
12+
it('should return an array of dates sorted descending when only valid dates are provided', () => {
1313
const direction = SortDirectionNumber.desc;
1414
const inputArray = ['8/8/98', '8/10/98', null, '8/8/98', '01/01/18', '14/12/98'];
15-
inputArray.sort((value1, value2) => dateEuroShortSorter(value1, value2, direction));
15+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction));
1616
expect(inputArray).toEqual(['01/01/18', '14/12/98', '8/10/98', '8/8/98', '8/8/98', null]);
1717
});
1818

1919
it(`should return an array with unsorted characters showing at the beginning
2020
then comes numbers sorted ascending when digits and chars are provided`, () => {
21-
const direction = SortDirectionNumber.asc;
22-
const inputArray = ['8/10/98', 'y', '8/8/98', '01/01/18', '14/12/98'];
23-
inputArray.sort((value1, value2) => dateEuroShortSorter(value1, value2, direction));
24-
expect(inputArray).toEqual(['y', '8/8/98', '8/10/98', '14/12/98', '01/01/18']);
25-
});
21+
const direction = SortDirectionNumber.asc;
22+
const inputArray = ['8/10/98', 'y', '8/8/98', '01/01/18', '14/12/98'];
23+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction));
24+
expect(inputArray).toEqual(['y', '8/8/98', '8/10/98', '14/12/98', '01/01/18']);
25+
});
2626

2727
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => {
2828
const direction = SortDirectionNumber.desc;
2929
const inputArray = ['8/10/98', null, '8/8/98', '01/01/18', '14/12/98'];
30-
inputArray.sort((value1, value2) => dateEuroShortSorter(value1, value2, direction));
30+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction));
3131
expect(inputArray).toEqual(['01/01/18', '14/12/98', '8/10/98', '8/8/98', null]);
3232
});
3333
});
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum';
2-
import { dateEuroSorter } from '../dateEuroSorter';
1+
import { sortByFieldType } from '../sorterUtilities';
2+
import { FieldType, SortDirectionNumber } from '../../models';
33

44
describe('the Date Euro Sorter', () => {
5-
it('should return an array of Euro dates sorted ascending when only valid dates are provided', () => {
5+
it('should return an array of dates sorted ascending when only valid dates are provided', () => {
66
const direction = SortDirectionNumber.asc;
77
const inputArray = ['08/08/1998', '08/10/1998', '08/08/1998', '01/01/2000', '14/12/1998'];
8-
inputArray.sort((value1, value2) => dateEuroSorter(value1, value2, direction));
8+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuro, value1, value2, direction));
99
expect(inputArray).toEqual(['08/08/1998', '08/08/1998', '08/10/1998', '14/12/1998', '01/01/2000']);
1010
});
1111

12-
it('should return an array of Euro dates sorted descending when only valid dates are provided', () => {
12+
it('should return an array of dates sorted descending when only valid dates are provided', () => {
1313
const direction = SortDirectionNumber.desc;
1414
const inputArray = ['08/08/1998', '08/10/1998', null, '08/08/1998', '01/01/2000', '14/12/1998'];
15-
inputArray.sort((value1, value2) => dateEuroSorter(value1, value2, direction));
15+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuro, value1, value2, direction));
1616
expect(inputArray).toEqual(['01/01/2000', '14/12/1998', '08/10/1998', '08/08/1998', '08/08/1998', null]);
1717
});
1818

1919
it(`should return an array with unsorted characters showing at the beginning
2020
then comes numbers sorted ascending when digits and chars are provided`, () => {
21-
const direction = SortDirectionNumber.asc;
22-
const inputArray = ['08/10/1998', 'y', '08/08/1998', '01/01/2000', '14/12/1998'];
23-
inputArray.sort((value1, value2) => dateEuroSorter(value1, value2, direction));
24-
expect(inputArray).toEqual(['y', '08/08/1998', '08/10/1998', '14/12/1998', '01/01/2000']);
25-
});
21+
const direction = SortDirectionNumber.asc;
22+
const inputArray = ['08/10/1998', 'y', '08/08/1998', '01/01/2000', '14/12/1998'];
23+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuro, value1, value2, direction));
24+
expect(inputArray).toEqual(['y', '08/08/1998', '08/10/1998', '14/12/1998', '01/01/2000']);
25+
});
2626

2727
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => {
2828
const direction = SortDirectionNumber.desc;
2929
const inputArray = ['08/10/1998', null, '08/08/1998', '01/01/2000', '14/12/1998'];
30-
inputArray.sort((value1, value2) => dateEuroSorter(value1, value2, direction));
30+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuro, value1, value2, direction));
3131
expect(inputArray).toEqual(['01/01/2000', '14/12/1998', '08/10/1998', '08/08/1998', null]);
3232
});
3333
});
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum';
2-
import { dateIsoSorter } from '../dateIsoSorter';
1+
import { sortByFieldType } from '../sorterUtilities';
2+
import { FieldType, SortDirectionNumber } from '../../models';
33

44
describe('the Date ISO (without time) Sorter', () => {
55
it('should return an array of US dates sorted ascending when only valid dates are provided', () => {
66
const direction = SortDirectionNumber.asc;
77
const inputArray = ['1998-08-08', '1998-10-08', '1998-08-08', '2001-01-01', '1998-12-14'];
8-
inputArray.sort((value1, value2) => dateIsoSorter(value1, value2, direction));
8+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateIso, value1, value2, direction));
99
expect(inputArray).toEqual(['1998-08-08', '1998-08-08', '1998-10-08', '1998-12-14', '2001-01-01']);
1010
});
1111

1212
it('should return an array of US dates sorted descending when only valid dates are provided', () => {
1313
const direction = SortDirectionNumber.desc;
1414
const inputArray = ['1998-08-08', '1998-10-08', null, '1998-08-08', '2001-01-01', '1998-12-14'];
15-
inputArray.sort((value1, value2) => dateIsoSorter(value1, value2, direction));
15+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateIso, value1, value2, direction));
1616
expect(inputArray).toEqual(['2001-01-01', '1998-12-14', '1998-10-08', '1998-08-08', '1998-08-08', null]);
1717
});
1818

1919
it(`should return an array with unsorted characters showing at the beginning
2020
then comes numbers sorted ascending when digits and chars are provided`, () => {
21-
const direction = SortDirectionNumber.asc;
22-
const inputArray = ['1998-10-08', 'y', '1998-08-08', '2001-01-01', '1998-12-14'];
23-
inputArray.sort((value1, value2) => dateIsoSorter(value1, value2, direction));
24-
expect(inputArray).toEqual(['y', '1998-08-08', '1998-10-08', '1998-12-14', '2001-01-01']);
25-
});
21+
const direction = SortDirectionNumber.asc;
22+
const inputArray = ['1998-10-08', 'y', '1998-08-08', '2001-01-01', '1998-12-14'];
23+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateIso, value1, value2, direction));
24+
expect(inputArray).toEqual(['y', '1998-08-08', '1998-10-08', '1998-12-14', '2001-01-01']);
25+
});
2626

2727
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => {
2828
const direction = SortDirectionNumber.desc;
2929
const inputArray = ['1998-10-08', null, '1998-08-08', '2001-01-01', '1998-12-14'];
30-
inputArray.sort((value1, value2) => dateIsoSorter(value1, value2, direction));
30+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateIso, value1, value2, direction));
3131
expect(inputArray).toEqual(['2001-01-01', '1998-12-14', '1998-10-08', '1998-08-08', null]);
3232
});
3333
});
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum';
2-
import { dateSorter } from '../dateSorter';
1+
import { sortByFieldType } from '../sorterUtilities';
2+
import { FieldType, SortDirectionNumber } from '../../models';
33

44
describe('the Date Sorter (ISO format with optional time included)', () => {
55
it('should return an array of ISO dates sorted ascending when only valid dates are provided', () => {
66
const direction = SortDirectionNumber.asc;
77
const inputArray = ['1998-08-08', '1998-08-09 01:01:10', null, '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11'];
8-
inputArray.sort((value1, value2) => dateSorter(value1, value2, direction));
8+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.date, value1, value2, direction));
99
expect(inputArray).toEqual([null, '1998-08-08', '1998-08-08', '1998-08-09 01:01:10', '1998-08-09 01:01:11', '2000-01-01 23:00:05']);
1010
});
1111

1212
it('should return an array of ISO dates sorted descending when only valid dates are provided', () => {
1313
const direction = SortDirectionNumber.desc;
1414
const inputArray = ['1998-08-08', '1998-08-09 01:01:10', null, '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11'];
15-
inputArray.sort((value1, value2) => dateSorter(value1, value2, direction));
15+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.date, value1, value2, direction));
1616
expect(inputArray).toEqual(['2000-01-01 23:00:05', '1998-08-09 01:01:11', '1998-08-09 01:01:10', '1998-08-08', '1998-08-08', null]);
1717
});
1818

1919
it(`should return an array with unsorted characters showing at the beginning
2020
then comes numbers sorted ascending when digits and chars are provided`, () => {
21-
const direction = SortDirectionNumber.asc;
22-
const inputArray = ['1998-08-09 01:01:10', 'y', '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11'];
23-
inputArray.sort((value1, value2) => dateSorter(value1, value2, direction));
24-
expect(inputArray).toEqual(['y', '1998-08-08', '1998-08-09 01:01:10', '1998-08-09 01:01:11', '2000-01-01 23:00:05']);
25-
});
21+
const direction = SortDirectionNumber.asc;
22+
const inputArray = ['1998-08-09 01:01:10', 'y', '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11'];
23+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.date, value1, value2, direction));
24+
expect(inputArray).toEqual(['y', '1998-08-08', '1998-08-09 01:01:10', '1998-08-09 01:01:11', '2000-01-01 23:00:05']);
25+
});
2626

2727
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => {
2828
const direction = SortDirectionNumber.desc;
2929
const inputArray = ['1998-08-09 01:01:10', null, '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11'];
30-
inputArray.sort((value1, value2) => dateSorter(value1, value2, direction));
30+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.date, value1, value2, direction));
3131
expect(inputArray).toEqual(['2000-01-01 23:00:05', '1998-08-09 01:01:11', '1998-08-09 01:01:10', '1998-08-08', null]);
3232
});
3333
});
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum';
2-
import { dateUsShortSorter } from '../dateUsShortSorter';
1+
import { sortByFieldType } from '../sorterUtilities';
2+
import { FieldType, SortDirectionNumber } from '../../models';
33

44
describe('the Date US Short Sorter', () => {
55
it('should return an array of US dates sorted ascending when only valid dates are provided', () => {
66
const direction = SortDirectionNumber.asc;
77
const inputArray = ['8/8/98', '10/8/98', '8/8/98', '01/01/18', '12/14/98'];
8-
inputArray.sort((value1, value2) => dateUsShortSorter(value1, value2, direction));
8+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction));
99
expect(inputArray).toEqual(['8/8/98', '8/8/98', '10/8/98', '12/14/98', '01/01/18']);
1010
});
1111

1212
it('should return an array of US dates sorted descending when only valid dates are provided', () => {
1313
const direction = SortDirectionNumber.desc;
1414
const inputArray = ['8/8/98', '10/8/98', null, '8/8/98', '01/01/18', '12/14/98'];
15-
inputArray.sort((value1, value2) => dateUsShortSorter(value1, value2, direction));
15+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction));
1616
expect(inputArray).toEqual(['01/01/18', '12/14/98', '10/8/98', '8/8/98', '8/8/98', null]);
1717
});
1818

1919
it(`should return an array with unsorted characters showing at the beginning
2020
then comes numbers sorted ascending when digits and chars are provided`, () => {
21-
const direction = SortDirectionNumber.asc;
22-
const inputArray = ['10/8/98', 'y', '8/8/98', '01/01/18', '12/14/98'];
23-
inputArray.sort((value1, value2) => dateUsShortSorter(value1, value2, direction));
24-
expect(inputArray).toEqual(['y', '8/8/98', '10/8/98', '12/14/98', '01/01/18']);
25-
});
21+
const direction = SortDirectionNumber.asc;
22+
const inputArray = ['10/8/98', 'y', '8/8/98', '01/01/18', '12/14/98'];
23+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction));
24+
expect(inputArray).toEqual(['y', '8/8/98', '10/8/98', '12/14/98', '01/01/18']);
25+
});
2626

2727
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => {
2828
const direction = SortDirectionNumber.desc;
2929
const inputArray = ['10/8/98', null, '8/8/98', '01/01/18', '12/14/98'];
30-
inputArray.sort((value1, value2) => dateUsShortSorter(value1, value2, direction));
30+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction));
3131
expect(inputArray).toEqual(['01/01/18', '12/14/98', '10/8/98', '8/8/98', null]);
3232
});
3333
});
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum';
2-
import { dateUsSorter } from '../dateUsSorter';
1+
import { sortByFieldType } from '../sorterUtilities';
2+
import { FieldType, SortDirectionNumber } from '../../models';
33

44
describe('the Date US Sorter', () => {
55
it('should return an array of US dates sorted ascending when only valid dates are provided', () => {
66
const direction = SortDirectionNumber.asc;
77
const inputArray = ['08/08/1998', '10/08/1998', '08/08/1998', '01/01/2000', '12/14/1998'];
8-
inputArray.sort((value1, value2) => dateUsSorter(value1, value2, direction));
8+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUs, value1, value2, direction));
99
expect(inputArray).toEqual(['08/08/1998', '08/08/1998', '10/08/1998', '12/14/1998', '01/01/2000']);
1010
});
1111

1212
it('should return an array of US dates sorted descending when only valid dates are provided', () => {
1313
const direction = SortDirectionNumber.desc;
1414
const inputArray = ['08/08/1998', '10/08/1998', null, '08/08/1998', '01/01/2000', '12/14/1998'];
15-
inputArray.sort((value1, value2) => dateUsSorter(value1, value2, direction));
15+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUs, value1, value2, direction));
1616
expect(inputArray).toEqual(['01/01/2000', '12/14/1998', '10/08/1998', '08/08/1998', '08/08/1998', null]);
1717
});
1818

1919
it(`should return an array with unsorted characters showing at the beginning
2020
then comes numbers sorted ascending when digits and chars are provided`, () => {
21-
const direction = SortDirectionNumber.asc;
22-
const inputArray = ['10/08/1998', 'y', '08/08/1998', '01/01/2000', '12/14/1998'];
23-
inputArray.sort((value1, value2) => dateUsSorter(value1, value2, direction));
24-
expect(inputArray).toEqual(['y', '08/08/1998', '10/08/1998', '12/14/1998', '01/01/2000']);
25-
});
21+
const direction = SortDirectionNumber.asc;
22+
const inputArray = ['10/08/1998', 'y', '08/08/1998', '01/01/2000', '12/14/1998'];
23+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUs, value1, value2, direction));
24+
expect(inputArray).toEqual(['y', '08/08/1998', '10/08/1998', '12/14/1998', '01/01/2000']);
25+
});
2626

2727
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => {
2828
const direction = SortDirectionNumber.desc;
2929
const inputArray = ['10/08/1998', null, '08/08/1998', '01/01/2000', '12/14/1998'];
30-
inputArray.sort((value1, value2) => dateUsSorter(value1, value2, direction));
30+
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUs, value1, value2, direction));
3131
expect(inputArray).toEqual(['01/01/2000', '12/14/1998', '10/08/1998', '08/08/1998', null]);
3232
});
3333
});

0 commit comments

Comments
 (0)