Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #108 from msanchezal/sort
Browse files Browse the repository at this point in the history
US115894: part 2 sort when the values are undefined
  • Loading branch information
msanchezal authored Apr 13, 2020
2 parents c26dcf7 + c3741bb commit 1e50cc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@al/common",
"version": "1.2.15",
"version": "1.2.16",
"description": "A collection of lightweight utilities and common types shared across NEPAL libraries and applications based on them.",
"main": "./dist/umd/index.js",
"scripts": {
Expand Down
26 changes: 17 additions & 9 deletions src/cardstack/al-cardstack-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,30 @@ export abstract class AlCardstackView< EntityType=any,
*/
public applySortBy( descriptor:AlCardstackPropertyDescriptor, order:string = "DESC" ):boolean {
this.rawCards = this.rawCards.sort( ( a, b ) => {
let pa = a.properties;
let pb = b.properties;
if ( typeof( pa[descriptor.property] ) === 'string' && typeof( pb[descriptor.property] ) === 'string' ) {
let pa = a.properties[descriptor.property];
let pb = b.properties[descriptor.property];
if ( typeof( pa ) === 'string' || typeof( pb ) === 'string' ) {
pa = pa ? pa: '';
pb = pb ? pb : '';
if ( order === 'ASC' ) {
return pa[descriptor.property].localeCompare( pb[descriptor.property] );
return pa.localeCompare( pb );
} else {
return pb[descriptor.property].localeCompare( pa[descriptor.property] );
return pb.localeCompare( pa );
}
} else if ( typeof( pa[descriptor.property] ) === 'number' && typeof( pb[descriptor.property] ) === 'number' ) {
} else if ( typeof( pa ) === 'number' || typeof( pb ) === 'number' ) {
a = pa ? pa: 0;
pb = pb ? pb : 0;
if ( order === 'ASC' ) {
return pa[descriptor.property] - pb[descriptor.property];
return pa - pb;
} else {
return pb[descriptor.property] - pa[descriptor.property];
return pb - pa;
}
} else {
throw new Error("Inconsistent property normalization: properties are not string or number, or are mixed." );
if ( typeof( pa ) === 'undefined' && typeof( pb ) === 'undefined' ) {
return 0;
} else {
throw new Error("Inconsistent property normalization: properties are not string or number, or are mixed." );
}
}
} );
this.applyFiltersAndSearch();
Expand Down

0 comments on commit 1e50cc9

Please sign in to comment.