[WIP] Editing
This commit is contained in:
@ -19,25 +19,26 @@ func (a Annotation) String() string {
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
Id int64 `json:"id,omitempty"`
|
||||
Uuid string `json:"uuid,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Project string `json:"project,omitempty"`
|
||||
Priority string `json:"priority,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Depends []string `json:"depends,omitempty"`
|
||||
Id int64 `json:"id,omitempty"`
|
||||
Uuid string `json:"uuid,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Project string `json:"project"`
|
||||
Priority string `json:"priority"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Tags []string `json:"tags"`
|
||||
Depends []string `json:"depends,omitempty"`
|
||||
DependsIds string
|
||||
Urgency float32 `json:"urgency,omitempty"`
|
||||
Parent string `json:"parent,omitempty"`
|
||||
Due string `json:"due,omitempty"`
|
||||
Wait string `json:"wait,omitempty"`
|
||||
Scheduled string `json:"scheduled,omitempty"`
|
||||
Until string `json:"until,omitempty"`
|
||||
Due string `json:"due"`
|
||||
Wait string `json:"wait"`
|
||||
Scheduled string `json:"scheduled"`
|
||||
Until string `json:"until"`
|
||||
Start string `json:"start,omitempty"`
|
||||
End string `json:"end,omitempty"`
|
||||
Entry string `json:"entry,omitempty"`
|
||||
Modified string `json:"modified,omitempty"`
|
||||
Recur string `json:"recur,omitempty"`
|
||||
Recur string `json:"recur"`
|
||||
Annotations []Annotation `json:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
@ -171,8 +172,7 @@ func (t *Task) GetString(fieldWFormat string) string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
// TODO: get Ids from UUIDs
|
||||
return strings.Join(t.Depends, ", ")
|
||||
return t.DependsIds
|
||||
|
||||
case "recur":
|
||||
return t.Recur
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
// TODO: error handling
|
||||
// TODO: split combinedOutput and handle stderr differently
|
||||
// TODO: reorder functions
|
||||
package taskwarrior
|
||||
|
||||
import (
|
||||
@ -90,6 +93,8 @@ type TaskWarrior interface {
|
||||
AddTask(task *Task) error
|
||||
ImportTask(task *Task)
|
||||
SetTaskDone(task *Task)
|
||||
|
||||
Undo()
|
||||
}
|
||||
|
||||
type TaskSquire struct {
|
||||
@ -138,6 +143,7 @@ func (ts *TaskSquire) GetTasks(report *Report, filter ...string) Tasks {
|
||||
for _, context := range ts.contexts {
|
||||
if context.Active && context.Name != "none" {
|
||||
args = append(args, context.ReadFilter)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -160,13 +166,39 @@ func (ts *TaskSquire) GetTasks(report *Report, filter ...string) Tasks {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, task := range tasks {
|
||||
if task.Depends != nil && len(task.Depends) > 0 {
|
||||
ids := make([]string, len(task.Depends))
|
||||
for i, dependUuid := range task.Depends {
|
||||
ids[i] = ts.getIds([]string{fmt.Sprintf("uuid:%s", dependUuid)})
|
||||
}
|
||||
|
||||
task.DependsIds = strings.Join(ids, " ")
|
||||
}
|
||||
}
|
||||
|
||||
return tasks
|
||||
}
|
||||
|
||||
func (ts *TaskSquire) getIds(filter []string) string {
|
||||
cmd := exec.Command(twBinary, append(append(ts.defaultArgs, filter...), "_ids")...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
slog.Error("Failed getting field:", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
func (ts *TaskSquire) GetContext(context string) *Context {
|
||||
ts.mutex.Lock()
|
||||
defer ts.mutex.Unlock()
|
||||
|
||||
if context == "" {
|
||||
context = "none"
|
||||
}
|
||||
|
||||
if context, ok := ts.contexts[context]; ok {
|
||||
return context
|
||||
} else {
|
||||
@ -276,6 +308,10 @@ func (ts *TaskSquire) SetContext(context *Context) error {
|
||||
ts.mutex.Lock()
|
||||
defer ts.mutex.Unlock()
|
||||
|
||||
if context.Name == "none" && ts.contexts["none"].Active {
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd := exec.Command(twBinary, []string{"context", context.Name}...)
|
||||
if err := cmd.Run(); err != nil {
|
||||
slog.Error("Failed setting context:", err)
|
||||
@ -355,6 +391,17 @@ func (ts *TaskSquire) SetTaskDone(task *Task) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *TaskSquire) Undo() {
|
||||
ts.mutex.Lock()
|
||||
defer ts.mutex.Unlock()
|
||||
|
||||
cmd := exec.Command(twBinary, append(ts.defaultArgs, []string{"undo"}...)...)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
slog.Error("Failed undoing task:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *TaskSquire) extractConfig() *TWConfig {
|
||||
cmd := exec.Command(twBinary, append(ts.defaultArgs, []string{"_show"}...)...)
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
||||
Reference in New Issue
Block a user