tasks: always display list in sorted order (oldest first)
This commit is contained in:
parent
0768e10403
commit
ef252d5cab
32
tpl_Tasks.go
32
tpl_Tasks.go
@ -3,9 +3,29 @@ package webcmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TaskListItem struct {
|
||||||
|
ref string
|
||||||
|
start int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskList []TaskListItem
|
||||||
|
|
||||||
|
func (tl TaskList) Len() int {
|
||||||
|
return len(tl)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tl TaskList) Swap(i, j int) {
|
||||||
|
tl[i], tl[j] = tl[j], tl[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tl TaskList) Less(i, j int) bool {
|
||||||
|
return tl[i].start < tl[j].start
|
||||||
|
}
|
||||||
|
|
||||||
func (this *App) Serve_Tasks(w http.ResponseWriter) {
|
func (this *App) Serve_Tasks(w http.ResponseWriter) {
|
||||||
w.Header().Set("Content-Type", "text/html;charset=UTF-8")
|
w.Header().Set("Content-Type", "text/html;charset=UTF-8")
|
||||||
|
|
||||||
@ -26,7 +46,19 @@ func (this *App) Serve_Tasks(w http.ResponseWriter) {
|
|||||||
|
|
||||||
this.tasksMtx.RLock()
|
this.tasksMtx.RLock()
|
||||||
defer this.tasksMtx.RUnlock()
|
defer this.tasksMtx.RUnlock()
|
||||||
|
|
||||||
|
tl := make(TaskList, 0, len(this.tasks))
|
||||||
for ref, t := range this.tasks {
|
for ref, t := range this.tasks {
|
||||||
|
tl = append(tl, TaskListItem{ref, t.started})
|
||||||
|
}
|
||||||
|
sort.Sort(tl)
|
||||||
|
|
||||||
|
for _, tlRef := range tl {
|
||||||
|
ref := tlRef.ref
|
||||||
|
t := this.tasks[ref]
|
||||||
|
|
||||||
|
startTime := time.Unix(t.started, 0)
|
||||||
|
|
||||||
fmt.Fprintf(w,
|
fmt.Fprintf(w,
|
||||||
`<tr>
|
`<tr>
|
||||||
<td><a href="/task/%s">%s</td>
|
<td><a href="/task/%s">%s</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user