update due date in app
This commit is contained in:
parent
85ef4ff36c
commit
2283d55551
|
@ -137,3 +137,18 @@ func (t *Tasks) Add(fields map[string]string) error {
|
||||||
|
|
||||||
return nil
|
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()
|
||||||
|
}
|
||||||
|
|
|
@ -107,6 +107,15 @@ func (r *Runner) processRequest() {
|
||||||
}
|
}
|
||||||
r.status = "saved"
|
r.status = "saved"
|
||||||
r.refresh <- true
|
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:
|
default:
|
||||||
r.logger.Log("request unknown")
|
r.logger.Log("request unknown")
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,11 @@ import (
|
||||||
type Config struct {
|
type Config struct {
|
||||||
fields []*FormField
|
fields []*FormField
|
||||||
commands chan interface{}
|
commands chan interface{}
|
||||||
show chan string
|
show chan ShowRequest
|
||||||
root *fyne.Container
|
root *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(commands chan interface{}, show chan string) *Config {
|
func NewConfig(commands chan interface{}, show chan ShowRequest) *Config {
|
||||||
fields := []*FormField{}
|
fields := []*FormField{}
|
||||||
for _, f := range [][2]string{
|
for _, f := range [][2]string{
|
||||||
{"ConfigIMAPURL", "imap url"},
|
{"ConfigIMAPURL", "imap url"},
|
||||||
|
@ -50,7 +50,7 @@ func (cf *Config) Save() {
|
||||||
req.Fields[f.Key] = f.GetValue()
|
req.Fields[f.Key] = f.GetValue()
|
||||||
}
|
}
|
||||||
cf.commands <- req
|
cf.commands <- req
|
||||||
cf.show <- "tasks"
|
cf.show <- ShowRequest{Screen: "tasks"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cf *Config) Refresh(state State) {
|
func (cf *Config) Refresh(state State) {
|
||||||
|
@ -90,6 +90,6 @@ func (cf *Config) Hide() {
|
||||||
cf.root.Hide()
|
cf.root.Hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cf *Config) Show() {
|
func (cf *Config) Show(_ Task) {
|
||||||
cf.root.Show()
|
cf.root.Show()
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,6 @@ func (l *Log) Hide() {
|
||||||
l.root.Hide()
|
l.root.Hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Log) Show() {
|
func (l *Log) Show(_ Task) {
|
||||||
l.root.Show()
|
l.root.Show()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,19 @@
|
||||||
package screen
|
package screen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
var newLock sync.Mutex
|
|
||||||
|
|
||||||
type NewTask struct {
|
type NewTask struct {
|
||||||
fields []*FormField
|
fields []*FormField
|
||||||
commands chan interface{}
|
commands chan interface{}
|
||||||
show chan string
|
show chan ShowRequest
|
||||||
root *fyne.Container
|
root *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNewTask(commands chan interface{}, show chan string) *NewTask {
|
func NewNewTask(commands chan interface{}, show chan ShowRequest) *NewTask {
|
||||||
fields := []*FormField{}
|
fields := []*FormField{}
|
||||||
for _, f := range [][2]string{
|
for _, f := range [][2]string{
|
||||||
{"action", "action"},
|
{"action", "action"},
|
||||||
|
@ -48,6 +44,8 @@ func (nt *NewTask) Init() {
|
||||||
|
|
||||||
taskForm.SubmitText = "save"
|
taskForm.SubmitText = "save"
|
||||||
taskForm.OnSubmit = nt.Save
|
taskForm.OnSubmit = nt.Save
|
||||||
|
taskForm.CancelText = "cancel"
|
||||||
|
taskForm.OnCancel = nt.Cancel
|
||||||
taskForm.Enable()
|
taskForm.Enable()
|
||||||
nt.clearForm()
|
nt.clearForm()
|
||||||
|
|
||||||
|
@ -68,11 +66,15 @@ func (nt *NewTask) Save() {
|
||||||
req.Fields[f.Key] = f.GetValue()
|
req.Fields[f.Key] = f.GetValue()
|
||||||
}
|
}
|
||||||
nt.commands <- req
|
nt.commands <- req
|
||||||
nt.show <- "tasks"
|
nt.show <- ShowRequest{Screen: "tasks"}
|
||||||
|
|
||||||
nt.clearForm()
|
nt.clearForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nt *NewTask) Cancel() {
|
||||||
|
nt.show <- ShowRequest{Screen: "tasks"}
|
||||||
|
}
|
||||||
|
|
||||||
func (nt *NewTask) clearForm() {
|
func (nt *NewTask) clearForm() {
|
||||||
for _, f := range nt.fields {
|
for _, f := range nt.fields {
|
||||||
f.SetValue("")
|
f.SetValue("")
|
||||||
|
@ -89,6 +91,6 @@ func (nt *NewTask) Hide() {
|
||||||
nt.root.Hide()
|
nt.root.Hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nt *NewTask) Show() {
|
func (nt *NewTask) Show(_ Task) {
|
||||||
nt.root.Show()
|
nt.root.Show()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,3 +13,8 @@ type SyncTasksRequest struct{}
|
||||||
type MarkTaskDoneRequest struct {
|
type MarkTaskDoneRequest struct {
|
||||||
ID string
|
ID string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateTaskRequest struct {
|
||||||
|
ID string
|
||||||
|
Due string
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,11 @@ type Task struct {
|
||||||
Action string
|
Action string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ShowRequest struct {
|
||||||
|
Screen string
|
||||||
|
Task Task
|
||||||
|
}
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
Status string
|
Status string
|
||||||
CurrentScreen string
|
CurrentScreen string
|
||||||
|
@ -26,12 +31,12 @@ type Screen interface {
|
||||||
Content() *fyne.Container
|
Content() *fyne.Container
|
||||||
Refresh(state State)
|
Refresh(state State)
|
||||||
Hide()
|
Hide()
|
||||||
Show()
|
Show(Task)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScreenSet struct {
|
type ScreenSet struct {
|
||||||
current string
|
current string
|
||||||
show chan string
|
show chan ShowRequest
|
||||||
status binding.String
|
status binding.String
|
||||||
menu *fyne.Container
|
menu *fyne.Container
|
||||||
screens map[string]Screen
|
screens map[string]Screen
|
||||||
|
@ -40,16 +45,16 @@ type ScreenSet struct {
|
||||||
|
|
||||||
func NewScreenSet(requests chan interface{}) *ScreenSet {
|
func NewScreenSet(requests chan interface{}) *ScreenSet {
|
||||||
status := binding.NewString()
|
status := binding.NewString()
|
||||||
show := make(chan string)
|
show := make(chan ShowRequest)
|
||||||
|
|
||||||
tasksButton := widget.NewButton("tasks", func() {
|
tasksButton := widget.NewButton("tasks", func() {
|
||||||
show <- "tasks"
|
show <- ShowRequest{Screen: "tasks"}
|
||||||
})
|
})
|
||||||
configButton := widget.NewButton("config", func() {
|
configButton := widget.NewButton("config", func() {
|
||||||
show <- "config"
|
show <- ShowRequest{Screen: "config"}
|
||||||
})
|
})
|
||||||
logsButton := widget.NewButton("logs", func() {
|
logsButton := widget.NewButton("logs", func() {
|
||||||
show <- "logs"
|
show <- ShowRequest{Screen: "logs"}
|
||||||
})
|
})
|
||||||
statusLabel := widget.NewLabel("> init...")
|
statusLabel := widget.NewLabel("> init...")
|
||||||
statusLabel.Bind(status)
|
statusLabel.Bind(status)
|
||||||
|
@ -61,6 +66,7 @@ func NewScreenSet(requests chan interface{}) *ScreenSet {
|
||||||
"logs": NewLog(),
|
"logs": NewLog(),
|
||||||
"config": NewConfig(requests, show),
|
"config": NewConfig(requests, show),
|
||||||
"new": NewNewTask(requests, show),
|
"new": NewNewTask(requests, show),
|
||||||
|
"update": NewUpdateTask(requests, show),
|
||||||
}
|
}
|
||||||
|
|
||||||
cs := []fyne.CanvasObject{}
|
cs := []fyne.CanvasObject{}
|
||||||
|
@ -68,7 +74,7 @@ func NewScreenSet(requests chan interface{}) *ScreenSet {
|
||||||
s.Hide()
|
s.Hide()
|
||||||
cs = append(cs, s.Content())
|
cs = append(cs, s.Content())
|
||||||
}
|
}
|
||||||
screens["tasks"].Show()
|
screens["tasks"].Show(Task{})
|
||||||
|
|
||||||
root := container.NewBorder(menu, nil, nil, nil, cs...)
|
root := container.NewBorder(menu, nil, nil, nil, cs...)
|
||||||
|
|
||||||
|
@ -83,10 +89,10 @@ func NewScreenSet(requests chan interface{}) *ScreenSet {
|
||||||
|
|
||||||
func (ss *ScreenSet) Run() {
|
func (ss *ScreenSet) Run() {
|
||||||
for s := range ss.show {
|
for s := range ss.show {
|
||||||
if s != ss.current {
|
if s.Screen != ss.current {
|
||||||
ss.screens[ss.current].Hide()
|
ss.screens[ss.current].Hide()
|
||||||
ss.screens[s].Show()
|
ss.screens[s.Screen].Show(s.Task)
|
||||||
ss.current = s
|
ss.current = s.Screen
|
||||||
|
|
||||||
ss.root.Refresh()
|
ss.root.Refresh()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,20 @@ import (
|
||||||
type Tasks struct {
|
type Tasks struct {
|
||||||
tasks []Task
|
tasks []Task
|
||||||
taskLabels binding.StringList
|
taskLabels binding.StringList
|
||||||
selectedTask string
|
selectedTask Task
|
||||||
list *widget.List
|
list *widget.List
|
||||||
commands chan interface{}
|
commands chan interface{}
|
||||||
show chan string
|
show chan ShowRequest
|
||||||
root *fyne.Container
|
root *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTasks(commands chan interface{}, show chan string) *Tasks {
|
func NewTasks(commands chan interface{}, show chan ShowRequest) *Tasks {
|
||||||
tasks := &Tasks{
|
tasks := &Tasks{
|
||||||
tasks: []Task{},
|
tasks: []Task{},
|
||||||
taskLabels: binding.NewStringList(),
|
taskLabels: binding.NewStringList(),
|
||||||
commands: commands,
|
commands: commands,
|
||||||
show: show,
|
show: show,
|
||||||
|
selectedTask: Task{},
|
||||||
}
|
}
|
||||||
tasks.Init()
|
tasks.Init()
|
||||||
|
|
||||||
|
@ -41,14 +42,17 @@ func (t *Tasks) Refresh(state State) {
|
||||||
tls = append(tls, t.Action)
|
tls = append(tls, t.Action)
|
||||||
}
|
}
|
||||||
t.taskLabels.Set(tls)
|
t.taskLabels.Set(tls)
|
||||||
if t.selectedTask == "" {
|
if t.selectedTask.ID == "" {
|
||||||
t.list.UnselectAll()
|
t.list.UnselectAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tasks) Init() {
|
func (t *Tasks) Init() {
|
||||||
newButton := widget.NewButton("new", func() {
|
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() {
|
doneButton := widget.NewButton("done", func() {
|
||||||
t.markDone()
|
t.markDone()
|
||||||
|
@ -66,7 +70,7 @@ func (t *Tasks) Init() {
|
||||||
|
|
||||||
t.root = container.NewBorder(
|
t.root = container.NewBorder(
|
||||||
newButton,
|
newButton,
|
||||||
doneButton,
|
container.NewVBox(updateButton, doneButton),
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
t.list,
|
t.list,
|
||||||
|
@ -81,7 +85,7 @@ func (t *Tasks) Hide() {
|
||||||
t.root.Hide()
|
t.root.Hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tasks) Show() {
|
func (t *Tasks) Show(_ Task) {
|
||||||
t.root.Show()
|
t.root.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,15 +95,26 @@ func (t *Tasks) selectItem(lid widget.ListItemID) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t.selectedTask = t.tasks[id].ID
|
t.selectedTask = t.tasks[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tasks) markDone() {
|
func (t *Tasks) markDone() {
|
||||||
if t.selectedTask == "" {
|
if t.selectedTask.ID == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.commands <- MarkTaskDoneRequest{
|
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 = ""
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue