v0.3.0: structural refactor — go:embed templates, server split, domain rename
- Migrate all 7 HTML templates + CSS from Go string constants to individual go:embed files in internal/web/templates/ (templates.go: 2150→35 lines) - Split server.go into auth.go, handlers.go, funcmap.go (server.go: 540→120 lines) - Rename controller subdomain from dashboard.* to felhom.* in Traefik labels - Update documentation (CLAUDE.md, README.md, CONTEXT.md) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/stacks"
|
||||
)
|
||||
|
||||
// templateFuncMap returns the FuncMap used by all HTML templates.
|
||||
func (s *Server) templateFuncMap() template.FuncMap {
|
||||
return template.FuncMap{
|
||||
"stateColor": func(state stacks.ContainerState) string {
|
||||
switch state {
|
||||
case stacks.StateRunning:
|
||||
return "green"
|
||||
case stacks.StateStarting:
|
||||
return "orange"
|
||||
case stacks.StateUnhealthy:
|
||||
return "yellow"
|
||||
case stacks.StateStopped, stacks.StateExited:
|
||||
return "red"
|
||||
case stacks.StateRestarting:
|
||||
return "yellow"
|
||||
default:
|
||||
return "gray"
|
||||
}
|
||||
},
|
||||
"stateLabel": func(state stacks.ContainerState) string {
|
||||
switch state {
|
||||
case stacks.StateRunning:
|
||||
return "Fut"
|
||||
case stacks.StateStarting:
|
||||
return "Indulás..."
|
||||
case stacks.StateUnhealthy:
|
||||
return "Nem egészséges"
|
||||
case stacks.StateStopped, stacks.StateExited:
|
||||
return "Leállítva"
|
||||
case stacks.StateRestarting:
|
||||
return "Újraindítás..."
|
||||
case stacks.StateNotDeployed:
|
||||
return "Nincs telepítve"
|
||||
case stacks.StatePaused:
|
||||
return "Szüneteltetve"
|
||||
default:
|
||||
return "Ismeretlen"
|
||||
}
|
||||
},
|
||||
"stateIcon": func(state stacks.ContainerState) string {
|
||||
switch state {
|
||||
case stacks.StateRunning:
|
||||
return "●"
|
||||
case stacks.StateStarting:
|
||||
return "◐"
|
||||
case stacks.StateUnhealthy:
|
||||
return "◑"
|
||||
case stacks.StateStopped, stacks.StateExited:
|
||||
return "○"
|
||||
case stacks.StateRestarting:
|
||||
return "◐"
|
||||
default:
|
||||
return "◌"
|
||||
}
|
||||
},
|
||||
"stateStr": func(state stacks.ContainerState) string {
|
||||
return string(state)
|
||||
},
|
||||
// isOperational returns true for any state where the stack has containers
|
||||
// and is not stopped/exited — used by templates for showing action buttons
|
||||
"isOperational": func(state stacks.ContainerState) bool {
|
||||
switch state {
|
||||
case stacks.StateRunning, stacks.StateStarting, stacks.StateUnhealthy, stacks.StateRestarting:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
},
|
||||
"logoURL": func(slug string) string {
|
||||
return s.cfg.AppLogoURL(slug)
|
||||
},
|
||||
"logoPNGURL": func(slug string) string {
|
||||
return s.cfg.AppLogoPNGURL(slug)
|
||||
},
|
||||
"appPageURL": func(slug string) string {
|
||||
return s.cfg.AppPageURL(slug)
|
||||
},
|
||||
"usageColor": func(percent float64) string {
|
||||
if percent >= 85 {
|
||||
return "red"
|
||||
}
|
||||
if percent >= 70 {
|
||||
return "yellow"
|
||||
}
|
||||
return "green"
|
||||
},
|
||||
"fmtMB": func(mb uint64) string {
|
||||
if mb >= 1024 {
|
||||
gb := float64(mb) / 1024.0
|
||||
if gb >= 10 {
|
||||
return fmt.Sprintf("%.0f GB", gb)
|
||||
}
|
||||
return fmt.Sprintf("%.1f GB", gb)
|
||||
}
|
||||
return fmt.Sprintf("%d MB", mb)
|
||||
},
|
||||
"fmtGB": func(gb float64) string {
|
||||
if gb >= 100 {
|
||||
return fmt.Sprintf("%.0f GB", gb)
|
||||
}
|
||||
if gb >= 10 {
|
||||
return fmt.Sprintf("%.1f GB", gb)
|
||||
}
|
||||
return fmt.Sprintf("%.2f GB", gb)
|
||||
},
|
||||
"subtract": func(a, b int) int {
|
||||
r := a - b
|
||||
if r < 0 {
|
||||
return 0
|
||||
}
|
||||
return r
|
||||
},
|
||||
"screenshotURL": func(slug string, index int) string {
|
||||
return s.cfg.AppScreenshotURL(slug, index)
|
||||
},
|
||||
"seq": func(n int) []int {
|
||||
result := make([]int, n)
|
||||
for i := range result {
|
||||
result[i] = i + 1
|
||||
}
|
||||
return result
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user