TODO: move completed tasks to different namespace else super slow load active tasks at scale

changeListOrder implemented
master
bel 2019-12-05 17:48:49 -07:00
parent 0f49595f0b
commit 9752acbd76
2 changed files with 29 additions and 1 deletions

View File

@ -20,6 +20,12 @@ func (rc readCloser) Close() error {
return nil
}
func GetAll(r *http.Request, k string) []string {
r.ParseForm()
v, _ := r.Form[k]
return v
}
func Get(r *http.Request, k string) string {
s := r.FormValue(k)
if s == "" {

View File

@ -6,6 +6,7 @@ import (
"local/todo-server/server/ajax/form"
"local/todo-server/server/ajax/list"
"net/http"
"sort"
)
type List struct{}
@ -16,6 +17,9 @@ func (a *Ajax) loadLists(w http.ResponseWriter, r *http.Request) error {
return err
}
a.ListCnt = len(lists)
sort.Slice(lists, func(i, j int) bool {
return lists[i].Index < lists[j].Index
})
return json.NewEncoder(w).Encode(map[string]interface{}{
"total": len(lists),
"list": lists,
@ -73,7 +77,25 @@ func (a *Ajax) publishList(w http.ResponseWriter, r *http.Request) error {
}
func (a *Ajax) changeListOrder(w http.ResponseWriter, r *http.Request) error {
return errors.New("TODO not impl")
order := form.GetAll(r, "order[]")
lists, err := a.storageListLists()
if err != nil {
return err
}
for i := range order {
listUUID := order[i]
for j := range lists {
if lists[j].UUID == listUUID {
lists[j].Index = i
if err := a.storageSetList(lists[j]); err != nil {
return err
}
}
}
}
return json.NewEncoder(w).Encode(map[string]interface{}{
"total": len(order),
})
}
func (a *Ajax) clearCompletedInList(w http.ResponseWriter, r *http.Request) error {