mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-04 19:57:20 +02:00
File area updates WIP
This commit is contained in:
parent
c81b6789f4
commit
ac35d3506d
7 changed files with 135 additions and 48 deletions
30
core/conf_area_util.js
Normal file
30
core/conf_area_util.js
Normal 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);
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue