forked from FOSS/BangleApps
Allow sorting by modified as well as created date
parent
d03fb00f2d
commit
746ea6c129
|
@ -3,3 +3,4 @@ node_modules
|
|||
package-lock.json
|
||||
.DS_Store
|
||||
*.js.bak
|
||||
appdates.csv
|
||||
|
|
|
@ -5,12 +5,14 @@ node bin/sanitycheck.js || exit 1
|
|||
|
||||
echo "Sanity check passed."
|
||||
|
||||
echo "Finding most recent apps..."
|
||||
echo "Finding app dates..."
|
||||
|
||||
# Create list of:
|
||||
# appid,created_time,modified_time
|
||||
cd apps
|
||||
for appfolder in *; do
|
||||
echo "$(git log --follow --format=%ai $appfolder),$appfolder" | tail -n 1 ;
|
||||
done | grep -v _example_ | sort -r > ../recent.csv
|
||||
echo "$appfolder,$(git log --follow --format=%ai -- $appfolder | tail -n 1),$(git log --follow --format=%ai -- $appfolder | head -n 1)" ;
|
||||
done | grep -v _example_ | grep -v unknown.png > ../appdates.csv
|
||||
cd ..
|
||||
|
||||
echo "Ready to publish"
|
||||
|
|
|
@ -95,7 +95,8 @@
|
|||
<div class="sort-nav hidden">
|
||||
<span>Sort by:</span>
|
||||
<label class="chip active" sortid="">None</label>
|
||||
<label class="chip" sortid="new">New</label>
|
||||
<label class="chip" sortid="created">New</label>
|
||||
<label class="chip" sortid="modified">Updated</label>
|
||||
</div>
|
||||
<div class="filter-nav">
|
||||
<label class="chip active" filterid="">Default</label>
|
||||
|
|
13
js/index.js
13
js/index.js
|
@ -1,6 +1,6 @@
|
|||
var appJSON = []; // List of apps and info from apps.json
|
||||
var appsInstalled = []; // list of app JSON
|
||||
var appPublishDates = {}; // list of app publish dates from recent.csv
|
||||
var appSortInfo = {}; // list of data to sort by, from appdates.csv { created, modified }
|
||||
var files = []; // list of files on Bangle
|
||||
var DEFAULTSETTINGS = {
|
||||
pretokenise : true,
|
||||
|
@ -20,11 +20,14 @@ httpGet("apps.json").then(apps=>{
|
|||
refreshFilter();
|
||||
});
|
||||
|
||||
httpGet("recent.csv").then(csv=>{
|
||||
httpGet("appdates.csv").then(csv=>{
|
||||
document.querySelector(".sort-nav").classList.remove("hidden");
|
||||
csv.split("\n").forEach(line=>{
|
||||
var l = line.split(",");
|
||||
appPublishDates[l[1]] = Date.parse(l[0]);
|
||||
appSortInfo[l[0]] = {
|
||||
created : Date.parse(l[1]),
|
||||
modified : Date.parse(l[2])
|
||||
};
|
||||
});
|
||||
}).catch(err=>{
|
||||
console.log("No recent.csv - app sort disabled");
|
||||
|
@ -231,8 +234,8 @@ function refreshLibrary() {
|
|||
|
||||
if (activeSort) {
|
||||
visibleApps = visibleApps.slice(); // clone the array so sort doesn't mess with original
|
||||
if (activeSort=="new") {
|
||||
visibleApps = visibleApps.sort((a,b) => appPublishDates[b.id] - appPublishDates[a.id]);
|
||||
if (activeSort=="created" || activeSort=="modified") {
|
||||
visibleApps = visibleApps.sort((a,b) => appSortInfo[b.id][activeSort] - appSortInfo[a.id][activeSort]);
|
||||
} else throw new Error("Unknown sort type "+activeSort);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue