switch namespaces from tags to relations with auto-creation

This commit is contained in:
2026-03-28 04:15:36 +01:00
parent 9b250c20f9
commit f907657c6f
6 changed files with 128 additions and 66 deletions

View File

@@ -46,7 +46,7 @@ var (
"low": {" ", "low", cDim},
"": {" ", "n/a", cDim},
}
relIcons = map[string]string{"blocks": "\uf068", "subtask": "\uf0da", "related": "\uf0c1", "assignee": "\uf007"}
relIcons = map[string]string{"blocks": "\uf068", "subtask": "\uf0da", "related": "\uf0c1", "assignee": "\uf007", "in_namespace": "\uf07b"}
prioRanks = map[string]int{"high": 3, "medium": 2, "low": 1}
statusRanks = map[string]int{"open": 2, "": 1, "done": 0}
)
@@ -72,16 +72,6 @@ func render(rm RenderMap, key string, short bool) string {
return v.c.Sprint(v.l)
}
func getDisplayTags(n *models.Node) []string {
var tags []string
for _, t := range n.Tags {
if !strings.HasPrefix(t, "_") {
tags = append(tags, t)
}
}
return tags
}
func PrintNodes(w io.Writer, nodes []*models.Node, jsonOut bool) error {
if jsonOut {
return json.NewEncoder(w).Encode(nodes)
@@ -91,6 +81,11 @@ func PrintNodes(w io.Writer, nodes []*models.Node, jsonOut bool) error {
return nil
}
d, err := db.GetDB()
if err != nil {
return err
}
fmt.Fprintln(w)
sort.Slice(nodes, func(i, j int) bool {
si, sj := nodes[i].GetProperty("status"), nodes[j].GetProperty("status")
@@ -101,15 +96,19 @@ func PrintNodes(w io.Writer, nodes []*models.Node, jsonOut bool) error {
})
for _, n := range nodes {
tags := getDisplayTags(n)
ns_rels, err := d.GetRelNames(n, models.RelInNamespace)
if err != nil {
return err
}
fmt.Fprintf(w, " %s %s %s %s %s %s",
cDim.Sprint(n.ID),
render(prioRM, n.GetProperty("prio"), true),
render(statusRM, n.GetProperty("status"), true),
render(typeRM, n.GetProperty("type"), true),
cTitle.Sprint(truncate(n.Title, 80)),
cDim.Sprint("["+n.GetProperty("namespace")+"]"),
cDim.Sprint("["+strings.Join(ns_rels, ",")+"]"),
)
tags := n.GetDisplayTags()
if len(tags) > 0 {
fmt.Fprintf(w, " %s", cPrimary.Sprint("#"+strings.Join(tags, " #")))
}
@@ -128,13 +127,33 @@ func PrintNode(w io.Writer, n *models.Node, jsonOut bool) error {
fmt.Fprintln(w, cDim.Sprint(" ───────────────────────────────"))
fmt.Fprintf(w, " Status: %s\n", render(statusRM, n.GetProperty("status"), false))
fmt.Fprintf(w, " Priority: %s\n", render(prioRM, n.GetProperty("prio"), false))
fmt.Fprintf(w, " Namespace: %s\n", cWarn.Sprint(n.GetProperty("namespace")))
if n.DueDate != "" {
fmt.Fprintf(w, " Due: %s %s\n", iconCalendar, n.DueDate)
}
fmt.Fprintf(w, " Created: %s\n", cDim.Sprint(n.CreatedAt))
fmt.Fprintf(w, " Updated: %s\n", cDim.Sprint(n.UpdatedAt))
if tags := n.GetDisplayTags(); len(tags) > 0 {
fmt.Fprintf(w, "\n tags: %s\n", cPrimary.Sprint(strings.Join(tags, " • ")))
}
if db, err := db.GetDB(); err != nil {
fmt.Fprintf(w, "failed to attach to db: %v", err)
} else {
for relType := range n.Relations {
names, err := db.GetRelNames(n, models.RelType(relType))
if err != nil {
fmt.Fprintf(w, "err: %v", err)
}
if len(names) > 0 {
fmt.Fprintf(w, "\n %s\n", string(relType))
}
for _, name := range names {
fmt.Fprintf(w, " %s %s\n", relIcons[relType], name)
}
}
}
if n.Content != "" {
fmt.Fprintln(w, "\n"+cPrimary.Sprint(" Content:"))
for i, line := range strings.Split(n.Content, "\n") {
@@ -146,28 +165,6 @@ func PrintNode(w io.Writer, n *models.Node, jsonOut bool) error {
}
}
if tags := getDisplayTags(n); len(tags) > 0 {
fmt.Fprintf(w, "\n tags: %s\n", cPrimary.Sprint(strings.Join(tags, " • ")))
}
if db, err := db.GetDB(); err == nil {
if len(n.Relations) > 0 {
for relType, ids := range n.Relations {
if relIcon, ok := relIcons[string(relType)]; ok {
fmt.Fprintf(w, "\n %s\n", string(relType))
for _, id := range ids {
node, err := db.NodeByID(id)
if err == nil {
fmt.Fprintf(w, " %s %s\n", relIcon, node.Title)
}
}
}
}
}
} else {
fmt.Fprintf(w, "failed to attach to db: %v", err)
}
fmt.Fprintln(w)
return nil
}