File area updates WIP

This commit is contained in:
Bryan Ashby 2016-10-01 13:25:32 -06:00
parent c81b6789f4
commit ac35d3506d
7 changed files with 135 additions and 48 deletions

30
core/conf_area_util.js Normal file
View file

@ -0,0 +1,30 @@
/* jslint node: true */
'use strict';
// deps
const _ = require('lodash');
exports.sortAreasOrConfs = sortAreasOrConfs;
//
// Method for sorting message, file, etc. areas and confs
// If the sort key is present and is a number, sort in numerical order;
// Otherwise, use a locale comparison on the sort key or name as a fallback
//
function sortAreasOrConfs(areasOrConfs, type) {
let entryA;
let entryB;
areasOrConfs.sort((a, b) => {
entryA = a[type];
entryB = b[type];
if(_.isNumber(entryA.sort) && _.isNumber(entryB.sort)) {
return entryA.sort - entryB.sort;
} else {
const keyA = entryA.sort ? entryA.sort.toString() : entryA.name;
const keyB = entryB.sort ? entryB.sort.toString() : entryB.name;
return keyA.localeCompare(keyB);
}
});
}