Style forms; [WIP] Draw table
This commit is contained in:
@ -1,5 +1,13 @@
|
||||
package taskwarrior
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
Id int64 `json:"id"`
|
||||
Uuid string `json:"uuid"`
|
||||
@ -8,13 +16,69 @@ type Task struct {
|
||||
Priority string `json:"priority"`
|
||||
Status string `json:"status"`
|
||||
Tags []string `json:"tags"`
|
||||
Depends []string `json:"depends"`
|
||||
Urgency float32 `json:"urgency"`
|
||||
Due string `json:"due"`
|
||||
Wait string `json:"wait"`
|
||||
Scheduled string `json:"scheduled"`
|
||||
Until string `json:"until"`
|
||||
Recur string `json:"recur"`
|
||||
Start string `json:"start"`
|
||||
End string `json:"end"`
|
||||
Entry string `json:"entry"`
|
||||
Modified string `json:"modified"`
|
||||
Parent string `json:"parent"`
|
||||
}
|
||||
|
||||
func (t *Task) Get(field string) string {
|
||||
switch field {
|
||||
case "id":
|
||||
return strconv.FormatInt(t.Id, 10)
|
||||
case "uuid":
|
||||
return t.Uuid
|
||||
case "description":
|
||||
return t.Description
|
||||
case "project":
|
||||
return t.Project
|
||||
case "priority":
|
||||
return t.Priority
|
||||
case "status":
|
||||
return t.Status
|
||||
case "tags":
|
||||
return strings.Join(t.Tags, ", ")
|
||||
case "urgency":
|
||||
return fmt.Sprintf("%.2f", t.Urgency)
|
||||
case "due":
|
||||
return t.Due
|
||||
case "wait":
|
||||
return t.Wait
|
||||
case "scheduled":
|
||||
return t.Scheduled
|
||||
case "end":
|
||||
return t.End
|
||||
case "entry":
|
||||
return t.Entry
|
||||
case "modified":
|
||||
return t.Modified
|
||||
// TODO: implement these fields
|
||||
case "start.age":
|
||||
return formatTime(t.Start)
|
||||
case "depends":
|
||||
return strings.Join(t.Depends, ", ")
|
||||
case "entry.age":
|
||||
return formatTime(t.Entry)
|
||||
case "scheduled.countdown":
|
||||
return formatTime(t.Scheduled)
|
||||
case "until.remaining":
|
||||
return formatTime(t.Until)
|
||||
case "due.relative":
|
||||
return formatTime(t.Due)
|
||||
case "recur":
|
||||
return t.Recur
|
||||
default:
|
||||
slog.Error(fmt.Sprintf("Field not implemented: %s", field))
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
type Tasks []*Task
|
||||
@ -39,3 +103,16 @@ type Report struct {
|
||||
}
|
||||
|
||||
type Reports map[string]*Report
|
||||
|
||||
func formatTime(timeStr string) string {
|
||||
if timeStr == "" {
|
||||
return ""
|
||||
}
|
||||
format := "20060102T150405Z"
|
||||
t, err := time.Parse(format, timeStr)
|
||||
if err != nil {
|
||||
slog.Error("Failed to parse time:", err)
|
||||
return timeStr
|
||||
}
|
||||
return t.Format("2006-01-02 15:04")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user