[WIP] Task editing
This commit is contained in:
@ -9,26 +9,36 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Annotation struct {
|
||||
Entry string `json:"entry,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
func (a Annotation) String() string {
|
||||
return fmt.Sprintf("%s %s", a.Entry, a.Description)
|
||||
}
|
||||
|
||||
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"`
|
||||
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"`
|
||||
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"`
|
||||
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"`
|
||||
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"`
|
||||
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"`
|
||||
Annotations []Annotation `json:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
func (t *Task) GetString(fieldWFormat string) string {
|
||||
@ -37,41 +47,136 @@ func (t *Task) GetString(fieldWFormat string) string {
|
||||
switch field {
|
||||
case "id":
|
||||
return strconv.FormatInt(t.Id, 10)
|
||||
|
||||
case "uuid":
|
||||
if format == "short" {
|
||||
return t.Uuid[:8]
|
||||
}
|
||||
return t.Uuid
|
||||
|
||||
case "description":
|
||||
return t.Description
|
||||
switch format {
|
||||
case "desc":
|
||||
return t.Description
|
||||
case "oneline":
|
||||
if len(t.Annotations) == 0 {
|
||||
return t.Description
|
||||
} else {
|
||||
var annotations []string
|
||||
for _, a := range t.Annotations {
|
||||
annotations = append(annotations, a.String())
|
||||
}
|
||||
return fmt.Sprintf("%s %s", t.Description, strings.Join(annotations, " "))
|
||||
}
|
||||
case "truncated":
|
||||
if len(t.Description) > 20 {
|
||||
return t.Description[:20] + "..."
|
||||
} else {
|
||||
return t.Description
|
||||
}
|
||||
case "count":
|
||||
return fmt.Sprintf("%s [%d]", t.Description, len(t.Annotations))
|
||||
case "truncated_count":
|
||||
if len(t.Description) > 20 {
|
||||
return fmt.Sprintf("%s... [%d]", t.Description[:20], len(t.Annotations))
|
||||
} else {
|
||||
return fmt.Sprintf("%s [%d]", t.Description, len(t.Annotations))
|
||||
}
|
||||
}
|
||||
|
||||
if len(t.Annotations) == 0 {
|
||||
return t.Description
|
||||
} else {
|
||||
var annotations []string
|
||||
for _, a := range t.Annotations {
|
||||
annotations = append(annotations, a.String())
|
||||
}
|
||||
// TODO support for multiline?
|
||||
return fmt.Sprintf("%s %s", t.Description, strings.Join(annotations, " "))
|
||||
}
|
||||
|
||||
case "project":
|
||||
switch format {
|
||||
case "parent":
|
||||
parent, _, _ := strings.Cut(t.Project, ".")
|
||||
return parent
|
||||
case "indented":
|
||||
return fmt.Sprintf(" %s", t.Project)
|
||||
}
|
||||
return t.Project
|
||||
|
||||
case "priority":
|
||||
return t.Priority
|
||||
|
||||
case "status":
|
||||
return t.Status
|
||||
|
||||
case "tags":
|
||||
return strings.Join(t.Tags, ", ")
|
||||
switch format {
|
||||
case "count":
|
||||
return strconv.Itoa(len(t.Tags))
|
||||
case "indicator":
|
||||
if len(t.Tags) > 0 {
|
||||
return "+"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return strings.Join(t.Tags, " ")
|
||||
|
||||
case "parent":
|
||||
if format == "short" {
|
||||
return t.Parent[:8]
|
||||
}
|
||||
return t.Parent
|
||||
|
||||
case "urgency":
|
||||
if format == "integer" {
|
||||
return strconv.Itoa(int(t.Urgency))
|
||||
}
|
||||
return fmt.Sprintf("%.2f", t.Urgency)
|
||||
|
||||
case "due":
|
||||
return formatDate(t.Due, format)
|
||||
|
||||
case "wait":
|
||||
return t.Wait
|
||||
return formatDate(t.Wait, format)
|
||||
|
||||
case "scheduled":
|
||||
return formatDate(t.Scheduled, format)
|
||||
|
||||
case "end":
|
||||
return t.End
|
||||
return formatDate(t.End, format)
|
||||
|
||||
case "entry":
|
||||
return formatDate(t.Entry, format)
|
||||
|
||||
case "modified":
|
||||
return t.Modified
|
||||
return formatDate(t.Modified, format)
|
||||
|
||||
case "start":
|
||||
return formatDate(t.Start, format)
|
||||
|
||||
case "until":
|
||||
return formatDate(t.Until, format)
|
||||
// TODO: implement these fields
|
||||
|
||||
case "depends":
|
||||
switch format {
|
||||
case "count":
|
||||
return strconv.Itoa(len(t.Depends))
|
||||
case "indicator":
|
||||
if len(t.Depends) > 0 {
|
||||
return "D"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
// TODO: get Ids from UUIDs
|
||||
return strings.Join(t.Depends, ", ")
|
||||
|
||||
case "recur":
|
||||
return t.Recur
|
||||
|
||||
default:
|
||||
slog.Error(fmt.Sprintf("Field not implemented: %s", field))
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user