Added sort order links to dirList pages
Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
parent
86e454eccc
commit
d5e9b26df2
2
Makefile
2
Makefile
|
@ -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
|
||||
|
|
|
@ -42,8 +42,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
version string
|
||||
gitCommit string
|
||||
version string = "?"
|
||||
gitCommit string = "00000"
|
||||
|
||||
server *http.Server
|
||||
addrPort string // eg. ":9990"
|
||||
|
|
|
@ -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> Sort by: <a class=\"go-http-fs-item\" href=\"?sort=name\">"+nameDelim[0]+"name"+nameDelim[1]+"</a> | <a class=\"go-http-fs-item\" href=\"?sort=newest\">"+newestDelim[0]+"newest"+newestDelim[1]+"</a> | <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())
|
||||
|
|
Loading…
Reference in New Issue