Added sort order links to dirList pages

Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
Russ Magee 2020-04-28 18:57:47 -07:00
parent 86e454eccc
commit d5e9b26df2
3 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,6 @@
MAKEOPTS = $(MAKEOPTS)
GIT_COMMIT := $(shell git rev-list -1 HEAD)
VERSION := 0.2.8
VERSION := 0.2.9
BUILDOPTS :=$(BUILDOPTS) -ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT)"
.PHONY: install all clean

View File

@ -42,8 +42,8 @@ const (
)
var (
version string
gitCommit string
version string = "?"
gitCommit string = "00000"
server *http.Server
addrPort string // eg. ":9990"

View File

@ -125,19 +125,26 @@ func dirList(w http.ResponseWriter, r *http.Request, dir, upath, sortOrder strin
return
}
var sortFunc func(i, j int) bool
nameDelim := []string{"", ""}
newestDelim := []string{"", ""}
oldestDelim := []string{"", ""}
switch sortOrder {
case "name":
sortFunc = func(i, j int) bool { return items[i].Name() < items[j].Name() }
nameDelim = []string{"(", ")"}
case "oldest":
sortFunc = func(i, j int) bool {
return items[i].ModTime().Before(items[j].ModTime())
}
oldestDelim = []string{"(", ")"}
case "newest":
fallthrough
default:
sortFunc = func(i, j int) bool {
return items[i].ModTime().After(items[j].ModTime())
}
newestDelim = []string{"(", ")"}
}
sort.Slice(items, sortFunc)
@ -154,7 +161,7 @@ func dirList(w http.ResponseWriter, r *http.Request, dir, upath, sortOrder strin
if upath != "." {
_, _ = fmt.Fprintf(w,
"<a class=\"go-http-fs-item\" href=\"..\">-- up --</a>\n\n")
"<a class=\"go-http-fs-item\" href=\"..\">-- up --</a>&nbsp;&nbsp;Sort by:&nbsp;<a class=\"go-http-fs-item\" href=\"?sort=name\">"+nameDelim[0]+"name"+nameDelim[1]+"</a>&nbsp;|&nbsp;<a class=\"go-http-fs-item\" href=\"?sort=newest\">"+newestDelim[0]+"newest"+newestDelim[1]+"</a>&nbsp;|&nbsp;<a class=\"go-http-fs-item\" href=\"?sort=oldest\">"+oldestDelim[0]+"oldest"+oldestDelim[1]+"</a>\n\n")
}
if len(items) == 0 {
_, _ = fmt.Fprintf(w, usrDirListE())