Style forms; [WIP] Draw table

This commit is contained in:
Martin Pander
2024-05-21 16:52:18 +02:00
parent d960f1f113
commit fce35f0fc7
9 changed files with 517 additions and 45 deletions

View File

@ -16,6 +16,10 @@ func NewConfig(config []string) *TWConfig {
}
}
func (tc *TWConfig) GetConfig() map[string]string {
return tc.config
}
func (tc *TWConfig) Get(key string) string {
if _, ok := tc.config[key]; !ok {
slog.Debug(fmt.Sprintf("Key not found in config: %s", key))

View File

@ -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")
}

View File

@ -16,6 +16,22 @@ const (
)
var (
reportBlacklist = map[string]struct{}{
"burndown.daily": {},
"burndown.monthly": {},
"burndown.weekly": {},
"calendar": {},
"colors": {},
"export": {},
"ghistory.annual": {},
"ghistory.monthly": {},
"history.annual": {},
"history.monthly": {},
"information": {},
"summary": {},
"timesheet": {},
}
tagBlacklist = map[string]struct{}{
"ACTIVE": {},
"ANNOTATED": {},
@ -330,6 +346,9 @@ func (ts *TaskSquire) extractReports() Reports {
reports := make(Reports)
for _, report := range availableReports {
if _, ok := reportBlacklist[report]; ok {
continue
}
reports[report] = &Report{
Name: report,
Description: ts.config.Get(fmt.Sprintf("report.%s.description", report)),