TODO: move completed tasks to different namespace else super slow load active tasks at scale
changeListOrder implementedmaster
parent
0f49595f0b
commit
9752acbd76
|
|
@ -20,6 +20,12 @@ func (rc readCloser) Close() error {
|
||||||
return nil
|
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 {
|
func Get(r *http.Request, k string) string {
|
||||||
s := r.FormValue(k)
|
s := r.FormValue(k)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"local/todo-server/server/ajax/form"
|
"local/todo-server/server/ajax/form"
|
||||||
"local/todo-server/server/ajax/list"
|
"local/todo-server/server/ajax/list"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type List struct{}
|
type List struct{}
|
||||||
|
|
@ -16,6 +17,9 @@ func (a *Ajax) loadLists(w http.ResponseWriter, r *http.Request) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
a.ListCnt = len(lists)
|
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{}{
|
return json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
"total": len(lists),
|
"total": len(lists),
|
||||||
"list": 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 {
|
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 {
|
func (a *Ajax) clearCompletedInList(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue