list sorting
This commit is contained in:
parent
3cd40f51d1
commit
35708710f2
|
@ -3,6 +3,7 @@ package command
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go-mod.ewintr.nl/planner/item"
|
"go-mod.ewintr.nl/planner/item"
|
||||||
|
@ -136,6 +137,25 @@ type ListResult struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr ListResult) Render() string {
|
func (lr ListResult) Render() string {
|
||||||
|
sort.Slice(lr.Tasks, func(i, j int) bool {
|
||||||
|
if lr.Tasks[i].Task.Project < lr.Tasks[j].Task.Project {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if lr.Tasks[i].Task.Project > lr.Tasks[j].Task.Project {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if lr.Tasks[i].Task.Recurrer == nil && lr.Tasks[j].Task.Recurrer != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if lr.Tasks[i].Task.Recurrer != nil && lr.Tasks[j].Task.Recurrer == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if lr.Tasks[i].Task.Date.After(lr.Tasks[j].Task.Date) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return lr.Tasks[i].LocalID < lr.Tasks[j].LocalID
|
||||||
|
})
|
||||||
|
|
||||||
var showRec, showDur bool
|
var showRec, showDur bool
|
||||||
for _, tl := range lr.Tasks {
|
for _, tl := range lr.Tasks {
|
||||||
if tl.Task.Recurrer != nil {
|
if tl.Task.Recurrer != nil {
|
||||||
|
|
|
@ -27,9 +27,7 @@ func TestListParse(t *testing.T) {
|
||||||
name: "empty",
|
name: "empty",
|
||||||
main: []string{},
|
main: []string{},
|
||||||
fields: map[string]string{},
|
fields: map[string]string{},
|
||||||
expArgs: command.ListArgs{
|
expArgs: command.ListArgs{},
|
||||||
To: today,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "today",
|
name: "today",
|
||||||
|
|
Loading…
Reference in New Issue