Allow sorting by modified as well as created date

pull/422/head
Gordon Williams 2020-05-13 11:25:08 +01:00
parent d03fb00f2d
commit 746ea6c129
4 changed files with 16 additions and 9 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ node_modules
package-lock.json package-lock.json
.DS_Store .DS_Store
*.js.bak *.js.bak
appdates.csv

View File

@ -5,12 +5,14 @@ node bin/sanitycheck.js || exit 1
echo "Sanity check passed." echo "Sanity check passed."
echo "Finding most recent apps..." echo "Finding app dates..."
# Create list of:
# appid,created_time,modified_time
cd apps cd apps
for appfolder in *; do for appfolder in *; do
echo "$(git log --follow --format=%ai $appfolder),$appfolder" | tail -n 1 ; echo "$appfolder,$(git log --follow --format=%ai -- $appfolder | tail -n 1),$(git log --follow --format=%ai -- $appfolder | head -n 1)" ;
done | grep -v _example_ | sort -r > ../recent.csv done | grep -v _example_ | grep -v unknown.png > ../appdates.csv
cd .. cd ..
echo "Ready to publish" echo "Ready to publish"

View File

@ -95,7 +95,8 @@
<div class="sort-nav hidden"> <div class="sort-nav hidden">
<span>Sort by:</span> <span>Sort by:</span>
<label class="chip active" sortid="">None</label> <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>
<div class="filter-nav"> <div class="filter-nav">
<label class="chip active" filterid="">Default</label> <label class="chip active" filterid="">Default</label>

View File

@ -1,6 +1,6 @@
var appJSON = []; // List of apps and info from apps.json var appJSON = []; // List of apps and info from apps.json
var appsInstalled = []; // list of app 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 files = []; // list of files on Bangle
var DEFAULTSETTINGS = { var DEFAULTSETTINGS = {
pretokenise : true, pretokenise : true,
@ -20,11 +20,14 @@ httpGet("apps.json").then(apps=>{
refreshFilter(); refreshFilter();
}); });
httpGet("recent.csv").then(csv=>{ httpGet("appdates.csv").then(csv=>{
document.querySelector(".sort-nav").classList.remove("hidden"); document.querySelector(".sort-nav").classList.remove("hidden");
csv.split("\n").forEach(line=>{ csv.split("\n").forEach(line=>{
var l = line.split(","); 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=>{ }).catch(err=>{
console.log("No recent.csv - app sort disabled"); console.log("No recent.csv - app sort disabled");
@ -231,8 +234,8 @@ function refreshLibrary() {
if (activeSort) { if (activeSort) {
visibleApps = visibleApps.slice(); // clone the array so sort doesn't mess with original visibleApps = visibleApps.slice(); // clone the array so sort doesn't mess with original
if (activeSort=="new") { if (activeSort=="created" || activeSort=="modified") {
visibleApps = visibleApps.sort((a,b) => appPublishDates[b.id] - appPublishDates[a.id]); visibleApps = visibleApps.sort((a,b) => appSortInfo[b.id][activeSort] - appSortInfo[a.id][activeSort]);
} else throw new Error("Unknown sort type "+activeSort); } else throw new Error("Unknown sort type "+activeSort);
} }