marking done
This commit is contained in:
parent
15811821f3
commit
822df27ac8
|
@ -2,6 +2,7 @@ package component
|
|||
|
||||
import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"ewintr.nl/gte/internal/process"
|
||||
"ewintr.nl/gte/internal/storage"
|
||||
|
@ -28,7 +29,7 @@ func NewTasks(conf *Configuration) (*Tasks, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (t *Tasks) Today() ([]string, error) {
|
||||
func (t *Tasks) Today() (map[string]string, error) {
|
||||
reqs := process.ListReqs{
|
||||
Due: task.Today(),
|
||||
IncludeBefore: true,
|
||||
|
@ -36,22 +37,50 @@ func (t *Tasks) Today() ([]string, error) {
|
|||
}
|
||||
res, err := process.NewList(t.local, reqs).Process()
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
return map[string]string{}, err
|
||||
}
|
||||
sort.Sort(task.ByDefault(res.Tasks))
|
||||
|
||||
tasks := []string{}
|
||||
tasks := map[string]string{}
|
||||
for _, t := range res.Tasks {
|
||||
tasks = append(tasks, t.Action)
|
||||
tasks[t.Id] = t.Action
|
||||
}
|
||||
|
||||
return tasks, nil
|
||||
}
|
||||
|
||||
func (t *Tasks) Sync() (int, error) {
|
||||
func (t *Tasks) Sync() (int, int, error) {
|
||||
countDisp, err := process.NewSend(t.local, t.disp).Process()
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
latestFetch, err := t.local.LatestSync()
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
if time.Now().Before(latestFetch.Add(15 * time.Minute)) {
|
||||
return countDisp, 0, nil
|
||||
}
|
||||
|
||||
res, err := process.NewFetch(t.remote, t.local).Process()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return countDisp, 0, err
|
||||
}
|
||||
return res.Count, nil
|
||||
return countDisp, res.Count, nil
|
||||
}
|
||||
|
||||
func (t *Tasks) MarkDone(id string) error {
|
||||
localTask, err := t.local.FindById(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
update := &task.LocalUpdate{
|
||||
ForVersion: localTask.Version,
|
||||
Fields: []string{task.FIELD_DONE},
|
||||
Done: true,
|
||||
}
|
||||
|
||||
return process.NewUpdate(t.local, id, update).Process()
|
||||
}
|
||||
|
|
|
@ -71,22 +71,34 @@ func (r *Runner) Run() {
|
|||
|
||||
func (r *Runner) processRequest() {
|
||||
for req := range r.requests {
|
||||
r.logger.Log(fmt.Sprintf("request %T: %s", req, req))
|
||||
|
||||
switch v := req.(type) {
|
||||
case screen.SaveConfigRequest:
|
||||
r.logger.Log("saving new config...")
|
||||
r.status = "saving..."
|
||||
r.refresh <- true
|
||||
for k, val := range v.Fields {
|
||||
r.conf.Set(k, val)
|
||||
}
|
||||
r.logger.Log("new config saved")
|
||||
r.status = "ready"
|
||||
r.refresh <- true
|
||||
case screen.SyncTasksRequest:
|
||||
r.logger.Log("syncing tasks...")
|
||||
r.status = "syncing..."
|
||||
r.refresh <- true
|
||||
count, err := r.tasks.Sync()
|
||||
countDisp, countFetch, err := r.tasks.Sync()
|
||||
if err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
}
|
||||
r.logger.Log(fmt.Sprintf("fetched: %d", count))
|
||||
r.status = "synced"
|
||||
r.logger.Log(fmt.Sprintf("dispatched: %d, fetched: %d", countDisp, countFetch))
|
||||
r.status = "ready"
|
||||
r.refresh <- true
|
||||
case screen.MarkTaskDoneRequest:
|
||||
r.logger.Log(fmt.Sprintf("marking task %s done...", v.ID))
|
||||
if err := r.tasks.MarkDone(v.ID); err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
}
|
||||
r.logger.Log("marked done")
|
||||
r.refresh <- true
|
||||
default:
|
||||
r.logger.Log("request unknown")
|
||||
|
@ -100,13 +112,20 @@ func (r *Runner) refresher() {
|
|||
if err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
}
|
||||
sTasks := []screen.Task{}
|
||||
for id, action := range tasks {
|
||||
sTasks = append(sTasks, screen.Task{
|
||||
ID: id,
|
||||
Action: action,
|
||||
})
|
||||
}
|
||||
|
||||
state := screen.State{
|
||||
Status: r.status,
|
||||
Tasks: tasks,
|
||||
Tasks: sTasks,
|
||||
Config: r.conf.Fields(),
|
||||
Logs: r.logger.Lines(),
|
||||
}
|
||||
|
||||
for _, s := range r.screens {
|
||||
s.Refresh(state)
|
||||
}
|
||||
|
|
|
@ -2,9 +2,14 @@ package screen
|
|||
|
||||
import "fyne.io/fyne/v2"
|
||||
|
||||
type Task struct {
|
||||
ID string
|
||||
Action string
|
||||
}
|
||||
|
||||
type State struct {
|
||||
Status string
|
||||
Tasks []string
|
||||
Tasks []Task
|
||||
Config map[string]string
|
||||
Logs []string
|
||||
}
|
||||
|
|
|
@ -9,23 +9,35 @@ import (
|
|||
|
||||
type SyncTasksRequest struct{}
|
||||
|
||||
type MarkTaskDoneRequest struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
type Tasks struct {
|
||||
status binding.String
|
||||
tasks binding.StringList
|
||||
tasks []Task
|
||||
taskLabels binding.StringList
|
||||
selectedTask string
|
||||
out chan interface{}
|
||||
}
|
||||
|
||||
func NewTasks(out chan interface{}) *Tasks {
|
||||
return &Tasks{
|
||||
status: binding.NewString(),
|
||||
tasks: binding.NewStringList(),
|
||||
tasks: []Task{},
|
||||
taskLabels: binding.NewStringList(),
|
||||
out: out,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tasks) Refresh(state State) {
|
||||
t.status.Set(state.Status)
|
||||
t.tasks.Set(state.Tasks)
|
||||
t.tasks = state.Tasks
|
||||
tls := []string{}
|
||||
for _, t := range t.tasks {
|
||||
tls = append(tls, t.Action)
|
||||
}
|
||||
t.taskLabels.Set(tls)
|
||||
}
|
||||
|
||||
func (t *Tasks) Content() fyne.CanvasObject {
|
||||
|
@ -33,8 +45,11 @@ func (t *Tasks) Content() fyne.CanvasObject {
|
|||
refreshButton := widget.NewButton("refresh", func() {
|
||||
t.out <- SyncTasksRequest{}
|
||||
})
|
||||
doneButton := widget.NewButton("done", func() {
|
||||
t.markDone()
|
||||
})
|
||||
list := widget.NewListWithData(
|
||||
t.tasks,
|
||||
t.taskLabels,
|
||||
func() fyne.CanvasObject {
|
||||
return widget.NewLabel("template")
|
||||
},
|
||||
|
@ -42,12 +57,31 @@ func (t *Tasks) Content() fyne.CanvasObject {
|
|||
o.(*widget.Label).Bind(i.(binding.String))
|
||||
},
|
||||
)
|
||||
list.OnSelected = t.selectItem
|
||||
|
||||
return container.NewBorder(
|
||||
container.NewHBox(refreshButton, statusLabel),
|
||||
nil,
|
||||
doneButton,
|
||||
nil,
|
||||
nil,
|
||||
list,
|
||||
)
|
||||
}
|
||||
|
||||
func (t *Tasks) selectItem(lid widget.ListItemID) {
|
||||
id := int(lid)
|
||||
if id < 0 || id >= len(t.tasks) {
|
||||
return
|
||||
}
|
||||
|
||||
t.selectedTask = t.tasks[id].ID
|
||||
}
|
||||
|
||||
func (t *Tasks) markDone() {
|
||||
if t.selectedTask == "" {
|
||||
return
|
||||
}
|
||||
t.out <- MarkTaskDoneRequest{
|
||||
ID: t.selectedTask,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ func NewFetch(remote *storage.RemoteRepository, local storage.LocalRepository) *
|
|||
|
||||
func (s *Fetch) Process() (*FetchResult, error) {
|
||||
start := time.Now()
|
||||
fmt.Printf("proc: %+v\n", s)
|
||||
|
||||
tasks := []*task.Task{}
|
||||
for _, folder := range task.KnownFolders {
|
||||
if folder == task.FOLDER_INBOX {
|
||||
|
|
Loading…
Reference in New Issue