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