folder and project in list reqs
This commit is contained in:
parent
f3c64cca5a
commit
db077f9717
|
@ -17,10 +17,21 @@ var (
|
||||||
type ListReqs struct {
|
type ListReqs struct {
|
||||||
Due task.Date
|
Due task.Date
|
||||||
IncludeBefore bool
|
IncludeBefore bool
|
||||||
|
Folder string
|
||||||
|
Project string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr ListReqs) Valid() bool {
|
func (lr ListReqs) Valid() bool {
|
||||||
return !lr.Due.IsZero()
|
switch {
|
||||||
|
case lr.Folder != "":
|
||||||
|
return true
|
||||||
|
case lr.Project != "":
|
||||||
|
return true
|
||||||
|
case !lr.Due.IsZero():
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// List finds all tasks that satisfy the given requirements
|
// List finds all tasks that satisfy the given requirements
|
||||||
|
@ -45,14 +56,50 @@ func (l *List) Process() (*ListResult, error) {
|
||||||
return &ListResult{}, ErrInvalidReqs
|
return &ListResult{}, ErrInvalidReqs
|
||||||
}
|
}
|
||||||
|
|
||||||
potentialTasks, err := l.local.FindAllInFolder(task.FOLDER_PLANNED)
|
folders := []string{task.FOLDER_NEW, task.FOLDER_PLANNED, task.FOLDER_UNPLANNED}
|
||||||
if err != nil {
|
if l.reqs.Folder != "" {
|
||||||
return &ListResult{}, fmt.Errorf("%w: %v", ErrListProcess, err)
|
folders = []string{l.reqs.Folder}
|
||||||
|
}
|
||||||
|
|
||||||
|
var potentialTasks []*task.Task
|
||||||
|
for _, folder := range folders {
|
||||||
|
folderTasks, err := l.local.FindAllInFolder(folder)
|
||||||
|
if err != nil {
|
||||||
|
return &ListResult{}, fmt.Errorf("%w: %v", ErrListProcess, err)
|
||||||
|
}
|
||||||
|
for _, ft := range folderTasks {
|
||||||
|
potentialTasks = append(potentialTasks, ft)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if l.reqs.Due.IsZero() && l.reqs.Project == "" {
|
||||||
|
return &ListResult{
|
||||||
|
Tasks: potentialTasks,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if l.reqs.Project != "" {
|
||||||
|
var projectTasks []*task.Task
|
||||||
|
for _, pt := range potentialTasks {
|
||||||
|
if pt.Project == l.reqs.Project {
|
||||||
|
projectTasks = append(projectTasks, pt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
potentialTasks = projectTasks
|
||||||
|
}
|
||||||
|
|
||||||
|
if l.reqs.Due.IsZero() {
|
||||||
|
return &ListResult{
|
||||||
|
Tasks: potentialTasks,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dueTasks := []*task.Task{}
|
dueTasks := []*task.Task{}
|
||||||
for _, t := range potentialTasks {
|
for _, t := range potentialTasks {
|
||||||
switch {
|
switch {
|
||||||
|
case t.Due.IsZero():
|
||||||
|
// skip
|
||||||
case t.Due.Equal(l.reqs.Due):
|
case t.Due.Equal(l.reqs.Due):
|
||||||
dueTasks = append(dueTasks, t)
|
dueTasks = append(dueTasks, t)
|
||||||
case l.reqs.IncludeBefore && l.reqs.Due.After(t.Due):
|
case l.reqs.IncludeBefore && l.reqs.Due.After(t.Due):
|
||||||
|
|
|
@ -20,6 +20,7 @@ func TestListProcess(t *testing.T) {
|
||||||
Version: 1,
|
Version: 1,
|
||||||
Action: "action1",
|
Action: "action1",
|
||||||
Folder: task.FOLDER_NEW,
|
Folder: task.FOLDER_NEW,
|
||||||
|
Project: "project1",
|
||||||
}
|
}
|
||||||
task2 := &task.Task{
|
task2 := &task.Task{
|
||||||
Id: "id2",
|
Id: "id2",
|
||||||
|
@ -27,6 +28,7 @@ func TestListProcess(t *testing.T) {
|
||||||
Action: "action2",
|
Action: "action2",
|
||||||
Due: date1,
|
Due: date1,
|
||||||
Folder: task.FOLDER_PLANNED,
|
Folder: task.FOLDER_PLANNED,
|
||||||
|
Project: "project2",
|
||||||
}
|
}
|
||||||
task3 := &task.Task{
|
task3 := &task.Task{
|
||||||
Id: "id3",
|
Id: "id3",
|
||||||
|
@ -34,6 +36,7 @@ func TestListProcess(t *testing.T) {
|
||||||
Action: "action3",
|
Action: "action3",
|
||||||
Due: date2,
|
Due: date2,
|
||||||
Folder: task.FOLDER_PLANNED,
|
Folder: task.FOLDER_PLANNED,
|
||||||
|
Project: "project1",
|
||||||
}
|
}
|
||||||
task4 := &task.Task{
|
task4 := &task.Task{
|
||||||
Id: "id4",
|
Id: "id4",
|
||||||
|
@ -41,6 +44,7 @@ func TestListProcess(t *testing.T) {
|
||||||
Action: "action4",
|
Action: "action4",
|
||||||
Due: date3,
|
Due: date3,
|
||||||
Folder: task.FOLDER_PLANNED,
|
Folder: task.FOLDER_PLANNED,
|
||||||
|
Project: "project2",
|
||||||
}
|
}
|
||||||
allTasks := []*task.Task{task1, task2, task3, task4}
|
allTasks := []*task.Task{task1, task2, task3, task4}
|
||||||
|
|
||||||
|
@ -73,6 +77,20 @@ func TestListProcess(t *testing.T) {
|
||||||
},
|
},
|
||||||
exp: []*task.Task{task2, task3},
|
exp: []*task.Task{task2, task3},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "folder",
|
||||||
|
reqs: process.ListReqs{
|
||||||
|
Folder: task.FOLDER_PLANNED,
|
||||||
|
},
|
||||||
|
exp: []*task.Task{task2, task3, task4},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "project",
|
||||||
|
reqs: process.ListReqs{
|
||||||
|
Project: "project2",
|
||||||
|
},
|
||||||
|
exp: []*task.Task{task2, task4},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
list := process.NewList(local, tc.reqs)
|
list := process.NewList(local, tc.reqs)
|
||||||
|
|
Loading…
Reference in New Issue