-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-do.go
84 lines (68 loc) · 1.63 KB
/
post-do.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package tasq
import (
"time"
)
const (
QCompletedFilter = "filter.completed"
QNeedsActionFilter = "filter.needs_action"
QOverdueFilter = "filter.overdue"
QPositionSort = "sort.position"
QLatestFirstSort = "sort.latest_first"
QOldestFirstSort = "sort.oldest_first"
)
func raiseTasks(list []*QTask) []*QTask {
raisedTasks := make([]*QTask, 0)
positionalSort(list)
topLevelTasks := make(map[string]int)
for _, task := range list {
if task.Parent == "" {
topLevelTasks[task.Id] = len(raisedTasks)
raisedTasks = append(raisedTasks, task)
} else {
parentIdx := topLevelTasks[task.Parent]
raisedTasks[parentIdx].Children = append(raisedTasks[parentIdx].Children, task)
}
}
return raisedTasks
}
func statusFilter(list *QTasks, status string) {
matchingTasks := make([]*QTask, 0)
for _, task := range list.Items {
if task.Status == status {
matchingTasks = append(matchingTasks, task)
}
}
list.Items = matchingTasks
}
func positionalSort(list []*QTask) {
length := len(list)
for i := 1; i < length; i++ {
j := i
for j > 0 && list[j].Position < list[j-1].Position {
list[j], list[j-1] = list[j-1], list[j]
j -= 1
}
}
}
func chronologicalSort(list []*QTask) {
length := len(list)
for i := 1; i < length; i++ {
j := i
tj0, _ := time.Parse(time.RFC3339, list[j-1].Updated)
tj1, _ := time.Parse(time.RFC3339, list[j].Updated)
for j > 0 && tj1.After(tj0) {
list[j], list[j-1] = list[j-1], list[j]
j -= 1
}
}
}
func reverseChronologicalSort(list []*QTask) {
chronologicalSort(list)
i := 0
j := len(list) - 1
for i < j {
list[i], list[j] = list[j], list[i]
i++
j--
}
}