New dynamic list "Unscheduled" added. Close #18

This commit is contained in:
Anis Ahmad
2021-03-14 21:36:02 +06:00
parent 0087d6ea1f
commit 1cad2d0881
3 changed files with 20 additions and 3 deletions

View File

@@ -72,6 +72,7 @@ func (pane *ProjectPane) addDynamicLists() {
pane.list.AddItem("- Today", "", 0, func() { taskPane.LoadDynamicList("today") })
pane.list.AddItem("- Tomorrow", "", 0, func() { taskPane.LoadDynamicList("tomorrow") })
pane.list.AddItem("- Upcoming", "", 0, func() { taskPane.LoadDynamicList("upcoming") })
pane.list.AddItem("- Unscheduled", "", 0, func() { taskPane.LoadDynamicList("unscheduled") })
}
func (pane *ProjectPane) addProjectList() {

View File

@@ -158,13 +158,17 @@ func (pane *TaskPane) LoadDynamicList(logic string) {
week := today.Add(7 * 24 * time.Hour)
tasks, err = pane.taskRepo.GetAllByDateRange(today, week)
rangeDesc = fmt.Sprintf("next 7 days")
case "unscheduled":
tasks, err = pane.taskRepo.GetAllByDate(zeroTime)
rangeDesc = fmt.Sprintf("Unscheduled (task with no due date) ")
}
projectPane.activeProject = nil
taskPane.ClearList()
if err == storm.ErrNotFound {
statusBar.showForSeconds("[yellow]No Task was scheduled for "+rangeDesc, 5)
statusBar.showForSeconds("[yellow]No Task in list "+rangeDesc, 5)
pane.SetList(tasks)
} else if err != nil {
statusBar.showForSeconds("[red]Error: "+err.Error(), 5)

View File

@@ -33,8 +33,20 @@ func (t *taskRepository) GetAllByProject(project model.Project) ([]model.Task, e
func (t *taskRepository) GetAllByDate(date time.Time) ([]model.Task, error) {
var tasks []model.Task
err := t.DB.Find("DueDate", getRoundedDueDate(date), &tasks)
return tasks, err
if date.IsZero() {
var allTasks []model.Task
err := t.DB.AllByIndex("ProjectID", &allTasks)
for _, t := range allTasks {
if t.DueDate == 0 {
tasks = append(tasks, t)
}
}
return tasks, err
} else {
err := t.DB.Find("DueDate", getRoundedDueDate(date), &tasks)
return tasks, err
}
}
func (t *taskRepository) GetAllByDateRange(from, to time.Time) ([]model.Task, error) {