Add better sorting

master
Gordon Williams 2019-11-07 08:43:56 +00:00
parent 567d124a6a
commit fcab506202
3 changed files with 14 additions and 3 deletions

View File

@ -50,7 +50,7 @@ the *default* of `To RAM`
{"name":"+7chname","url":"my-great-app.json"}, {"name":"+7chname","url":"my-great-app.json"},
{"name":"-7chname","url":"my-great-app.js"}, {"name":"-7chname","url":"my-great-app.js"},
{"name":"*7chname","url":"my-great-app.js","evaluate":true} {"name":"*7chname","url":"my-great-app.js","evaluate":true}
] ],
}, },
``` ```
@ -74,7 +74,9 @@ the *default* of `To RAM`
"evaluate":true // if supplied, data isn't quoted into a String before upload "evaluate":true // if supplied, data isn't quoted into a String before upload
// (eg it's evaluated as JS) // (eg it's evaluated as JS)
}, },
"sortorder" : 0, // optional - choose where in the list this goes.
// this should only really be used to put system
// stuff at the top
] ]
} }
``` ```

View File

@ -2,7 +2,12 @@ var appJSON = []; // List of apps and info from apps.json
var appsInstalled = []; // list of app IDs var appsInstalled = []; // list of app IDs
httpGet("apps.json").then(apps=>{ httpGet("apps.json").then(apps=>{
appJSON = JSON.parse(apps); try {
appJSON = JSON.parse(apps);
} catch(e) {
console.log(e);
showToast("App List Corrupted","error");
}
appJSON.sort(appSorter); appJSON.sort(appSorter);
refreshLibrary(); refreshLibrary();
}); });

View File

@ -33,5 +33,9 @@ function toJS(txt) {
function appSorter(a,b) { function appSorter(a,b) {
if (a.unknown || b.unknown) if (a.unknown || b.unknown)
return (a.unknown)? 1 : -1; return (a.unknown)? 1 : -1;
var sa = 0|a.sortorder;
var sb = 0|b.sortorder;
if (sa<sb) return -1;
if (sa>sb) return 1;
return (a.name==b.name) ? 0 : ((a.name<b.name) ? -1 : 1); return (a.name==b.name) ? 0 : ((a.name<b.name) ? -1 : 1);
} }