new task in app
This commit is contained in:
parent
09f0b10cb6
commit
85ef4ff36c
|
@ -1,6 +1,7 @@
|
|||
package component
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
|
@ -103,3 +104,36 @@ func (t *Tasks) MarkDone(id string) error {
|
|||
|
||||
return process.NewUpdate(t.local, id, update).Process()
|
||||
}
|
||||
|
||||
func (t *Tasks) Add(fields map[string]string) error {
|
||||
update := &task.LocalUpdate{
|
||||
Fields: []string{},
|
||||
}
|
||||
if len(fields["action"]) != 0 {
|
||||
update.Action = fields["action"]
|
||||
update.Fields = append(update.Fields, task.FIELD_ACTION)
|
||||
}
|
||||
if len(fields["project"]) != 0 {
|
||||
update.Project = fields["project"]
|
||||
update.Fields = append(update.Fields, task.FIELD_PROJECT)
|
||||
}
|
||||
due := task.NewDateFromString(fields["due"])
|
||||
if !due.IsZero() {
|
||||
update.Due = due
|
||||
update.Fields = append(update.Fields, task.FIELD_DUE)
|
||||
}
|
||||
recur := task.NewRecurrer(fields["recur"])
|
||||
if recur != nil {
|
||||
update.Recur = recur
|
||||
update.Fields = append(update.Fields, task.FIELD_RECUR)
|
||||
}
|
||||
if len(update.Fields) == 0 {
|
||||
return fmt.Errorf("no fields in new task")
|
||||
}
|
||||
|
||||
if err := process.NewNew(t.local, update).Process(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -99,6 +99,14 @@ func (r *Runner) processRequest() {
|
|||
}
|
||||
r.logger.Log(fmt.Sprintf("marked task %q done", v.ID))
|
||||
r.status = "marked done"
|
||||
case screen.SaveNewTaskRequest:
|
||||
r.status = "saving..."
|
||||
r.refresh <- true
|
||||
if err := r.tasks.Add(v.Fields); err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
}
|
||||
r.status = "saved"
|
||||
r.refresh <- true
|
||||
default:
|
||||
r.logger.Log("request unknown")
|
||||
}
|
||||
|
|
|
@ -1,50 +1,11 @@
|
|||
package screen
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
type SaveConfigRequest struct {
|
||||
Fields map[string]string
|
||||
}
|
||||
|
||||
var confLock sync.Mutex
|
||||
|
||||
type FormField struct {
|
||||
Label string
|
||||
Key string
|
||||
Value binding.String
|
||||
}
|
||||
|
||||
func NewFormField(key, label string) *FormField {
|
||||
val := binding.NewString()
|
||||
val.Set("...")
|
||||
|
||||
return &FormField{
|
||||
Label: label,
|
||||
Key: key,
|
||||
Value: val,
|
||||
}
|
||||
}
|
||||
|
||||
func (ff *FormField) SetValue(value string) {
|
||||
confLock.Lock()
|
||||
defer confLock.Unlock()
|
||||
|
||||
ff.Value.Set(value)
|
||||
}
|
||||
|
||||
func (ff *FormField) GetValue() string {
|
||||
val, _ := ff.Value.Get()
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
fields []*FormField
|
||||
commands chan interface{}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package screen
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
)
|
||||
|
||||
var formLock sync.Mutex
|
||||
|
||||
type FormField struct {
|
||||
Label string
|
||||
Key string
|
||||
Value binding.String
|
||||
}
|
||||
|
||||
func NewFormField(key, label string) *FormField {
|
||||
val := binding.NewString()
|
||||
val.Set("...")
|
||||
|
||||
return &FormField{
|
||||
Label: label,
|
||||
Key: key,
|
||||
Value: val,
|
||||
}
|
||||
}
|
||||
|
||||
func (ff *FormField) SetValue(value string) {
|
||||
formLock.Lock()
|
||||
defer formLock.Unlock()
|
||||
|
||||
ff.Value.Set(value)
|
||||
}
|
||||
|
||||
func (ff *FormField) GetValue() string {
|
||||
val, _ := ff.Value.Get()
|
||||
|
||||
return val
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
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
|
||||
root *fyne.Container
|
||||
}
|
||||
|
||||
func NewNewTask(commands chan interface{}, show chan string) *NewTask {
|
||||
fields := []*FormField{}
|
||||
for _, f := range [][2]string{
|
||||
{"action", "action"},
|
||||
{"project", "project"},
|
||||
{"due", "due string"},
|
||||
{"recur", "recur string"},
|
||||
} {
|
||||
fields = append(fields, NewFormField(f[0], f[1]))
|
||||
}
|
||||
|
||||
newTask := &NewTask{
|
||||
fields: fields,
|
||||
commands: commands,
|
||||
show: show,
|
||||
}
|
||||
newTask.Init()
|
||||
|
||||
return newTask
|
||||
}
|
||||
|
||||
func (nt *NewTask) Init() {
|
||||
taskForm := widget.NewForm()
|
||||
for _, f := range nt.fields {
|
||||
w := widget.NewEntry()
|
||||
w.Bind(f.Value)
|
||||
taskForm.Append(f.Label, w)
|
||||
}
|
||||
|
||||
taskForm.SubmitText = "save"
|
||||
taskForm.OnSubmit = nt.Save
|
||||
taskForm.Enable()
|
||||
nt.clearForm()
|
||||
|
||||
nt.root = container.NewBorder(
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
taskForm,
|
||||
)
|
||||
}
|
||||
|
||||
func (nt *NewTask) Save() {
|
||||
req := SaveNewTaskRequest{
|
||||
Fields: map[string]string{},
|
||||
}
|
||||
for _, f := range nt.fields {
|
||||
req.Fields[f.Key] = f.GetValue()
|
||||
}
|
||||
nt.commands <- req
|
||||
nt.show <- "tasks"
|
||||
|
||||
nt.clearForm()
|
||||
}
|
||||
|
||||
func (nt *NewTask) clearForm() {
|
||||
for _, f := range nt.fields {
|
||||
f.SetValue("")
|
||||
}
|
||||
}
|
||||
|
||||
func (nt *NewTask) Refresh(_ State) {}
|
||||
|
||||
func (nt *NewTask) Content() *fyne.Container {
|
||||
return nt.root
|
||||
}
|
||||
|
||||
func (nt *NewTask) Hide() {
|
||||
nt.root.Hide()
|
||||
}
|
||||
|
||||
func (nt *NewTask) Show() {
|
||||
nt.root.Show()
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package screen
|
||||
|
||||
type SaveConfigRequest struct {
|
||||
Fields map[string]string
|
||||
}
|
||||
|
||||
type SaveNewTaskRequest struct {
|
||||
Fields map[string]string
|
||||
}
|
||||
|
||||
type SyncTasksRequest struct{}
|
||||
|
||||
type MarkTaskDoneRequest struct {
|
||||
ID string
|
||||
}
|
|
@ -60,6 +60,7 @@ func NewScreenSet(requests chan interface{}) *ScreenSet {
|
|||
"tasks": NewTasks(requests, show),
|
||||
"logs": NewLog(),
|
||||
"config": NewConfig(requests, show),
|
||||
"new": NewNewTask(requests, show),
|
||||
}
|
||||
|
||||
cs := []fyne.CanvasObject{}
|
||||
|
|
|
@ -9,12 +9,6 @@ import (
|
|||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
type SyncTasksRequest struct{}
|
||||
|
||||
type MarkTaskDoneRequest struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
type Tasks struct {
|
||||
tasks []Task
|
||||
taskLabels binding.StringList
|
||||
|
@ -53,6 +47,9 @@ func (t *Tasks) Refresh(state State) {
|
|||
}
|
||||
|
||||
func (t *Tasks) Init() {
|
||||
newButton := widget.NewButton("new", func() {
|
||||
t.show <- "new"
|
||||
})
|
||||
doneButton := widget.NewButton("done", func() {
|
||||
t.markDone()
|
||||
})
|
||||
|
@ -68,7 +65,7 @@ func (t *Tasks) Init() {
|
|||
t.list.OnSelected = t.selectItem
|
||||
|
||||
t.root = container.NewBorder(
|
||||
nil,
|
||||
newButton,
|
||||
doneButton,
|
||||
nil,
|
||||
nil,
|
||||
|
|
Loading…
Reference in New Issue