123 lines
3.0 KiB
Go
123 lines
3.0 KiB
Go
package server
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"strings"
|
|
|
|
"github.com/dal/kaos/internal/supervisor"
|
|
"github.com/dal/kaos/web"
|
|
)
|
|
|
|
// columnData holds data for rendering a single kanban column.
|
|
type columnData struct {
|
|
Name string
|
|
Label string
|
|
Icon string
|
|
Count int
|
|
Tasks []supervisor.Task
|
|
}
|
|
|
|
// dashboardData holds data for the full dashboard page.
|
|
type dashboardData struct {
|
|
Columns []columnData
|
|
}
|
|
|
|
// taskDetailData holds data for the task detail panel.
|
|
type taskDetailData struct {
|
|
Task supervisor.Task
|
|
Content string
|
|
HasReport bool
|
|
}
|
|
|
|
// statusIcons maps folder names to emoji icons.
|
|
var statusIcons = map[string]string{
|
|
"backlog": "📦",
|
|
"ready": "📋",
|
|
"active": "🔄",
|
|
"review": "👀",
|
|
"done": "✅",
|
|
}
|
|
|
|
// columnOrder defines the display order of columns.
|
|
var columnOrder = []string{"backlog", "ready", "active", "review", "done"}
|
|
|
|
// templateFuncs provides custom functions for templates.
|
|
var templateFuncs = template.FuncMap{
|
|
"joinDeps": func(deps []string) string {
|
|
return strings.Join(deps, ", ")
|
|
},
|
|
}
|
|
|
|
// templates holds the parsed template set.
|
|
var templates *template.Template
|
|
|
|
func init() {
|
|
templates = template.Must(
|
|
template.New("").Funcs(templateFuncs).ParseFS(
|
|
web.TemplatesFS,
|
|
"templates/layout.html",
|
|
"templates/dashboard.html",
|
|
"templates/docs-list.html",
|
|
"templates/docs-view.html",
|
|
"templates/partials/column.html",
|
|
"templates/partials/task-card.html",
|
|
"templates/partials/task-detail.html",
|
|
),
|
|
)
|
|
}
|
|
|
|
// renderDashboard generates the full dashboard HTML page.
|
|
func renderDashboard(columns map[string][]supervisor.Task) string {
|
|
data := dashboardData{}
|
|
for _, col := range columnOrder {
|
|
tasks := columns[col]
|
|
data.Columns = append(data.Columns, columnData{
|
|
Name: col,
|
|
Label: strings.ToUpper(col),
|
|
Icon: statusIcons[col],
|
|
Count: len(tasks),
|
|
Tasks: tasks,
|
|
})
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
if err := templates.ExecuteTemplate(&buf, "layout.html", data); err != nil {
|
|
return "Greška pri renderovanju: " + err.Error()
|
|
}
|
|
return buf.String()
|
|
}
|
|
|
|
// renderDocsList generates the docs listing HTML page.
|
|
func renderDocsList(data docsListData) string {
|
|
var buf bytes.Buffer
|
|
if err := templates.ExecuteTemplate(&buf, "docs-list", data); err != nil {
|
|
return "Greška pri renderovanju: " + err.Error()
|
|
}
|
|
return buf.String()
|
|
}
|
|
|
|
// renderDocsView generates the docs view HTML page.
|
|
func renderDocsView(data docsViewData) string {
|
|
var buf bytes.Buffer
|
|
if err := templates.ExecuteTemplate(&buf, "docs-view", data); err != nil {
|
|
return "Greška pri renderovanju: " + err.Error()
|
|
}
|
|
return buf.String()
|
|
}
|
|
|
|
// renderTaskDetail generates HTML fragment for task detail panel.
|
|
func renderTaskDetail(t supervisor.Task, content string, hasReport bool) string {
|
|
data := taskDetailData{
|
|
Task: t,
|
|
Content: content,
|
|
HasReport: hasReport,
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
if err := templates.ExecuteTemplate(&buf, "task-detail", data); err != nil {
|
|
return "Greška pri renderovanju: " + err.Error()
|
|
}
|
|
return buf.String()
|
|
}
|