Add order to tasks and lists
parent
f2e3a71348
commit
48e8b91039
|
|
@ -2,6 +2,7 @@ package ajax
|
|||
|
||||
import (
|
||||
"local/todo-server/config"
|
||||
"local/todo-server/server/ajax/list"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
@ -15,5 +16,12 @@ func mockAjax() *Ajax {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
list := &list.List{
|
||||
Name: "list",
|
||||
UUID: "list",
|
||||
}
|
||||
if err := ajax.storageSetList(list); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ajax
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ type List struct {
|
|||
ShowCompl int `json:"showCompl"`
|
||||
ShowNotes int `json:"showNotes"`
|
||||
Hidden int `json:"hidden"`
|
||||
Max int `json:"max"`
|
||||
}
|
||||
|
||||
func New(r *http.Request) (*List, error) {
|
||||
|
|
@ -47,6 +48,11 @@ func (l *List) SetHideList(state bool) {
|
|||
set(state, &l.Hidden)
|
||||
}
|
||||
|
||||
func (l *List) NextIndex() int {
|
||||
l.Max += 1
|
||||
return l.Max
|
||||
}
|
||||
|
||||
func set(b bool, i *int) {
|
||||
*i = 1
|
||||
if !b {
|
||||
|
|
|
|||
|
|
@ -77,7 +77,10 @@ func (a *Ajax) storageListTasks(listID string, filters ...func(t *task.Task) boo
|
|||
}
|
||||
}
|
||||
sort.SliceStable(tasks, func(i, j int) bool {
|
||||
return tasks[i].Created.Before(tasks[j].Created)
|
||||
if tasks[i].Index == tasks[j].Index {
|
||||
return tasks[i].Created.Before(tasks[j].Created)
|
||||
}
|
||||
return tasks[i].Index < tasks[j].Index
|
||||
})
|
||||
return tasks, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func TestAjaxStorageListLists(t *testing.T) {
|
|||
|
||||
if results, err := ajax.storageListLists(); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(results) != 3 {
|
||||
} else if len(results) < 3 {
|
||||
t.Error(results)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,14 @@ func (a *Ajax) makeTask(r *http.Request) (string, *task.Task, error) {
|
|||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
list, err := a.storageGetList(listID)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
task.Index = list.NextIndex()
|
||||
if err := a.storageSetList(list); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
task.AppendTags(tags)
|
||||
return listID, task, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ type Task struct {
|
|||
Complete bool
|
||||
Note []string
|
||||
Due time.Time
|
||||
|
||||
Index int
|
||||
}
|
||||
|
||||
type StrList []string
|
||||
|
|
|
|||
Loading…
Reference in New Issue