update due date in app

This commit is contained in:
Erik Winter 2022-10-31 15:59:58 +01:00
parent 85ef4ff36c
commit 2283d55551
9 changed files with 178 additions and 38 deletions

View File

@ -137,3 +137,18 @@ func (t *Tasks) Add(fields map[string]string) error {
return nil
}
func (t *Tasks) Update(id, newDue string) error {
due := task.NewDateFromString(newDue)
localTask, err := t.local.FindById(id)
if err != nil {
return err
}
update := &task.LocalUpdate{
ForVersion: localTask.Version,
Due: due,
Fields: []string{task.FIELD_DUE},
}
return process.NewUpdate(t.local, localTask.Id, update).Process()
}

View File

@ -107,6 +107,15 @@ func (r *Runner) processRequest() {
}
r.status = "saved"
r.refresh <- true
case screen.UpdateTaskRequest:
r.status = "saving..."
r.refresh <- true
if err := r.tasks.Update(v.ID, v.Due); err != nil {
r.logger.Log(err.Error())
}
r.logger.Log(fmt.Sprintf("updated due date task %q", v.ID))
r.status = "saved"
r.refresh <- true
default:
r.logger.Log("request unknown")
}

View File

@ -9,11 +9,11 @@ import (
type Config struct {
fields []*FormField
commands chan interface{}
show chan string
show chan ShowRequest
root *fyne.Container
}
func NewConfig(commands chan interface{}, show chan string) *Config {
func NewConfig(commands chan interface{}, show chan ShowRequest) *Config {
fields := []*FormField{}
for _, f := range [][2]string{
{"ConfigIMAPURL", "imap url"},
@ -50,7 +50,7 @@ func (cf *Config) Save() {
req.Fields[f.Key] = f.GetValue()
}
cf.commands <- req
cf.show <- "tasks"
cf.show <- ShowRequest{Screen: "tasks"}
}
func (cf *Config) Refresh(state State) {
@ -90,6 +90,6 @@ func (cf *Config) Hide() {
cf.root.Hide()
}
func (cf *Config) Show() {
func (cf *Config) Show(_ Task) {
cf.root.Show()
}

View File

@ -52,6 +52,6 @@ func (l *Log) Hide() {
l.root.Hide()
}
func (l *Log) Show() {
func (l *Log) Show(_ Task) {
l.root.Show()
}

View File

@ -1,23 +1,19 @@
package screen
import (
"sync"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
var newLock sync.Mutex
type NewTask struct {
fields []*FormField
commands chan interface{}
show chan string
show chan ShowRequest
root *fyne.Container
}
func NewNewTask(commands chan interface{}, show chan string) *NewTask {
func NewNewTask(commands chan interface{}, show chan ShowRequest) *NewTask {
fields := []*FormField{}
for _, f := range [][2]string{
{"action", "action"},
@ -48,6 +44,8 @@ func (nt *NewTask) Init() {
taskForm.SubmitText = "save"
taskForm.OnSubmit = nt.Save
taskForm.CancelText = "cancel"
taskForm.OnCancel = nt.Cancel
taskForm.Enable()
nt.clearForm()
@ -68,11 +66,15 @@ func (nt *NewTask) Save() {
req.Fields[f.Key] = f.GetValue()
}
nt.commands <- req
nt.show <- "tasks"
nt.show <- ShowRequest{Screen: "tasks"}
nt.clearForm()
}
func (nt *NewTask) Cancel() {
nt.show <- ShowRequest{Screen: "tasks"}
}
func (nt *NewTask) clearForm() {
for _, f := range nt.fields {
f.SetValue("")
@ -89,6 +91,6 @@ func (nt *NewTask) Hide() {
nt.root.Hide()
}
func (nt *NewTask) Show() {
func (nt *NewTask) Show(_ Task) {
nt.root.Show()
}

View File

@ -13,3 +13,8 @@ type SyncTasksRequest struct{}
type MarkTaskDoneRequest struct {
ID string
}
type UpdateTaskRequest struct {
ID string
Due string
}

View File

@ -14,6 +14,11 @@ type Task struct {
Action string
}
type ShowRequest struct {
Screen string
Task Task
}
type State struct {
Status string
CurrentScreen string
@ -26,12 +31,12 @@ type Screen interface {
Content() *fyne.Container
Refresh(state State)
Hide()
Show()
Show(Task)
}
type ScreenSet struct {
current string
show chan string
show chan ShowRequest
status binding.String
menu *fyne.Container
screens map[string]Screen
@ -40,16 +45,16 @@ type ScreenSet struct {
func NewScreenSet(requests chan interface{}) *ScreenSet {
status := binding.NewString()
show := make(chan string)
show := make(chan ShowRequest)
tasksButton := widget.NewButton("tasks", func() {
show <- "tasks"
show <- ShowRequest{Screen: "tasks"}
})
configButton := widget.NewButton("config", func() {
show <- "config"
show <- ShowRequest{Screen: "config"}
})
logsButton := widget.NewButton("logs", func() {
show <- "logs"
show <- ShowRequest{Screen: "logs"}
})
statusLabel := widget.NewLabel("> init...")
statusLabel.Bind(status)
@ -61,6 +66,7 @@ func NewScreenSet(requests chan interface{}) *ScreenSet {
"logs": NewLog(),
"config": NewConfig(requests, show),
"new": NewNewTask(requests, show),
"update": NewUpdateTask(requests, show),
}
cs := []fyne.CanvasObject{}
@ -68,7 +74,7 @@ func NewScreenSet(requests chan interface{}) *ScreenSet {
s.Hide()
cs = append(cs, s.Content())
}
screens["tasks"].Show()
screens["tasks"].Show(Task{})
root := container.NewBorder(menu, nil, nil, nil, cs...)
@ -83,10 +89,10 @@ func NewScreenSet(requests chan interface{}) *ScreenSet {
func (ss *ScreenSet) Run() {
for s := range ss.show {
if s != ss.current {
if s.Screen != ss.current {
ss.screens[ss.current].Hide()
ss.screens[s].Show()
ss.current = s
ss.screens[s.Screen].Show(s.Task)
ss.current = s.Screen
ss.root.Refresh()
}

View File

@ -12,19 +12,20 @@ import (
type Tasks struct {
tasks []Task
taskLabels binding.StringList
selectedTask string
selectedTask Task
list *widget.List
commands chan interface{}
show chan string
show chan ShowRequest
root *fyne.Container
}
func NewTasks(commands chan interface{}, show chan string) *Tasks {
func NewTasks(commands chan interface{}, show chan ShowRequest) *Tasks {
tasks := &Tasks{
tasks: []Task{},
taskLabels: binding.NewStringList(),
commands: commands,
show: show,
tasks: []Task{},
taskLabels: binding.NewStringList(),
commands: commands,
show: show,
selectedTask: Task{},
}
tasks.Init()
@ -41,14 +42,17 @@ func (t *Tasks) Refresh(state State) {
tls = append(tls, t.Action)
}
t.taskLabels.Set(tls)
if t.selectedTask == "" {
if t.selectedTask.ID == "" {
t.list.UnselectAll()
}
}
func (t *Tasks) Init() {
newButton := widget.NewButton("new", func() {
t.show <- "new"
t.show <- ShowRequest{Screen: "new"}
})
updateButton := widget.NewButton("update", func() {
t.updateTask()
})
doneButton := widget.NewButton("done", func() {
t.markDone()
@ -66,7 +70,7 @@ func (t *Tasks) Init() {
t.root = container.NewBorder(
newButton,
doneButton,
container.NewVBox(updateButton, doneButton),
nil,
nil,
t.list,
@ -81,7 +85,7 @@ func (t *Tasks) Hide() {
t.root.Hide()
}
func (t *Tasks) Show() {
func (t *Tasks) Show(_ Task) {
t.root.Show()
}
@ -91,15 +95,26 @@ func (t *Tasks) selectItem(lid widget.ListItemID) {
return
}
t.selectedTask = t.tasks[id].ID
t.selectedTask = t.tasks[id]
}
func (t *Tasks) markDone() {
if t.selectedTask == "" {
if t.selectedTask.ID == "" {
return
}
t.commands <- MarkTaskDoneRequest{
ID: t.selectedTask,
ID: t.selectedTask.ID,
}
t.selectedTask = Task{}
}
func (t *Tasks) updateTask() {
if t.selectedTask.ID == "" {
return
}
t.show <- ShowRequest{
Screen: "update",
Task: t.selectedTask,
}
t.selectedTask = ""
}

View File

@ -0,0 +1,88 @@
package screen
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
)
type UpdateTask struct {
field *FormField
action binding.String
taskID string
commands chan interface{}
show chan ShowRequest
root *fyne.Container
}
func NewUpdateTask(commands chan interface{}, show chan ShowRequest) *UpdateTask {
newUpdate := &UpdateTask{
field: NewFormField("new due", "due"),
action: binding.NewString(),
commands: commands,
show: show,
}
newUpdate.Init()
return newUpdate
}
func (ut *UpdateTask) Init() {
actionLabel := widget.NewLabel("")
actionLabel.Bind(ut.action)
updateForm := widget.NewForm()
dueEntry := widget.NewEntry()
dueEntry.Bind(ut.field.Value)
updateForm.Append(ut.field.Label, dueEntry)
updateForm.SubmitText = "save"
updateForm.OnSubmit = ut.Save
updateForm.CancelText = "cancel"
updateForm.OnCancel = ut.Cancel
updateForm.Enable()
ut.clearForm()
ut.root = container.NewBorder(
actionLabel,
nil,
nil,
nil,
updateForm,
)
}
func (ut *UpdateTask) Save() {
ut.commands <- UpdateTaskRequest{
ID: ut.taskID,
Due: ut.field.GetValue(),
}
ut.show <- ShowRequest{Screen: "tasks"}
}
func (ut *UpdateTask) Cancel() {
ut.clearForm()
ut.show <- ShowRequest{Screen: "tasks"}
}
func (ut *UpdateTask) clearForm() {
ut.field.SetValue("")
ut.action.Set("")
ut.taskID = ""
}
func (ut *UpdateTask) Refresh(_ State) {}
func (ut *UpdateTask) Content() *fyne.Container {
return ut.root
}
func (ut *UpdateTask) Hide() {
ut.root.Hide()
}
func (ut *UpdateTask) Show(task Task) {
ut.taskID = task.ID
ut.action.Set(task.Action)
ut.root.Show()
}