Skip to content
This repository has been archived by the owner on Aug 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #6 from SlateFoundation/develop
Browse files Browse the repository at this point in the history
Release: slate-core-data v1.1.1
  • Loading branch information
themightychris authored Jan 5, 2018
2 parents a3472e9 + 487051c commit 023057f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/sorter/Code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Ext.define('Slate.sorter.Code', {
extend: 'Ext.util.Sorter',


config: {
numberRe: /^\d+$/,
numberDelim: '.',

sorterFn: function(a, b) {
var codeA = a.get('Code').toLowerCase(),
codeB = b.get('Code').toLowerCase(),
numberRe = this._numberRe, // eslint-disable-line no-underscore-dangle
numberDelim = this._numberDelim, // eslint-disable-line no-underscore-dangle
dotIndexA, dotIndexB,
numberA, numberB;

if (codeA == codeB) {
return 0;
}

dotIndexA = codeA.lastIndexOf(numberDelim);
dotIndexB = codeB.lastIndexOf(numberDelim);

if (
dotIndexA == -1
|| dotIndexB == -1
|| codeA.substr(0, dotIndexA) != codeB.substr(0, dotIndexB)
|| (numberA = codeA.substr(dotIndexA + 1)) == ''
|| (numberB = codeB.substr(dotIndexB + 1)) == ''
|| !numberRe.test(numberA)
|| !numberRe.test(numberB)
) {
return codeA < codeB ? -1 : 1;
}

return numberA - numberB;
}
},

});
6 changes: 6 additions & 0 deletions src/store/courses/Sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ Ext.define('Slate.store.courses.Sections', {
direction: 'ASC'
}
]
},

getByCode: function(code) {
var index = code ? this.findExact('Code', code) : -1;

return index == -1 ? null : this.getAt(index);
}
});

0 comments on commit 023057f

Please sign in to comment.