62 lines
1.0 KiB
Go
62 lines
1.0 KiB
Go
|
package webcmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func (this *App) Serve_Tasks(w http.ResponseWriter) {
|
||
|
w.Header().Set("Content-Type", "text/html;charset=UTF-8")
|
||
|
|
||
|
w.WriteHeader(200)
|
||
|
this.ServePartial_Header(w, "/tasks")
|
||
|
|
||
|
fmt.Fprint(w, `
|
||
|
<table>
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th>Task</th>
|
||
|
<th>Started</th>
|
||
|
<th>State</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
|
`)
|
||
|
|
||
|
this.tasksMtx.RLock()
|
||
|
defer this.tasksMtx.RUnlock()
|
||
|
for ref, t := range this.tasks {
|
||
|
fmt.Fprintf(w,
|
||
|
`<tr>
|
||
|
<td><a href="/task/%s">%s</td>
|
||
|
<td>%s</td>
|
||
|
<td>
|
||
|
`,
|
||
|
hesc(ref), hesc(ref),
|
||
|
hesc(time.Unix(t.started, 0).Format(time.RFC822Z)),
|
||
|
)
|
||
|
|
||
|
if t.Finished() {
|
||
|
fmt.Fprint(w, `<span class="task-state-finished">Finished</span>`)
|
||
|
} else {
|
||
|
fmt.Fprint(w, `<span class="task-state-running">Running</span>`)
|
||
|
}
|
||
|
|
||
|
fmt.Fprint(w, `
|
||
|
</td>
|
||
|
</tr>
|
||
|
`)
|
||
|
}
|
||
|
|
||
|
fmt.Fprint(w, `
|
||
|
</tbody>
|
||
|
</table>
|
||
|
|
||
|
<form method="POST" action="/x-clear-completed-tasks">
|
||
|
<input type="submit" value="Clear completed tasks »">
|
||
|
</form>
|
||
|
`)
|
||
|
this.ServePartial_Footer(w)
|
||
|
}
|