diff --git a/internal/dis/component/auth/auth.go b/internal/dis/component/auth/auth.go
index d87bac5..9e4eabb 100644
--- a/internal/dis/component/auth/auth.go
+++ b/internal/dis/component/auth/auth.go
@@ -5,7 +5,7 @@ import (
"net/http"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
- "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templates"
+ "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/sql"
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
"github.com/gorilla/sessions"
@@ -17,7 +17,7 @@ type Auth struct {
Dependencies struct {
SQL *sql.SQL
UserDeleteHooks []component.UserDeleteHook
- Templating *templates.Templating
+ Templating *templating.Templating
}
store lazy.Lazy[sessions.Store]
diff --git a/internal/dis/component/auth/login.html b/internal/dis/component/auth/login.html
index 81a87ea..9ef48a4 100644
--- a/internal/dis/component/auth/login.html
+++ b/internal/dis/component/auth/login.html
@@ -1,5 +1,4 @@
-{{ template "_form.html" . }}
-{{ define "form/title" }}Login Required{{ end }}
+{{ template "form.html" . }}
{{ define "form/button" }}Login{{ end }}
{{ define "form/inside" }}
diff --git a/internal/dis/component/auth/panel/panel.go b/internal/dis/component/auth/panel/panel.go
index 5eddfb3..2bda260 100644
--- a/internal/dis/component/auth/panel/panel.go
+++ b/internal/dis/component/auth/panel/panel.go
@@ -9,7 +9,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth/next"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth/policy"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
- "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templates"
+ "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/ssh2/sshkeys"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
@@ -20,7 +20,7 @@ type UserPanel struct {
component.Base
Dependencies struct {
Auth *auth.Auth
- Templating *templates.Templating
+ Templating *templating.Templating
Policy *policy.Policy
Instances *instances.Instances
Next *next.Next
@@ -106,30 +106,25 @@ func (panel *UserPanel) HandleRoute(ctx context.Context, route string) (http.Han
}
type userFormContext struct {
- templates.BaseContext
+ templating.RuntimeFlags
httpx.FormContext
User *models.User
}
-func (panel *UserPanel) UserFormContext2(tpl *templates.Template[userFormContext], last component.MenuItem, gaps ...templates.BaseContextGaps) func(ctx httpx.FormContext, r *http.Request) any {
- var g templates.BaseContextGaps
- if len(gaps) > 1 {
- panic("UserFormContext2: gaps must be of length 0 or 1")
- }
- if len(gaps) == 1 {
- g = gaps[0]
- }
- g.Crumbs = []component.MenuItem{
- {Title: "User", Path: "/user/"},
- last,
- }
+func (panel *UserPanel) UserFormContext(tpl *templating.Template[userFormContext], last component.MenuItem, funcs ...templating.FlagFunc) func(ctx httpx.FormContext, r *http.Request) any {
+ funcs = append(funcs, func(flags templating.Flags, r *http.Request) templating.Flags {
+ flags.Crumbs = append(flags.Crumbs, component.MenuItem{})
+ copy(flags.Crumbs[1:], flags.Crumbs)
+ flags.Crumbs[0] = component.MenuItem{Title: "User", Path: "/user/"}
+ return flags
+ })
- return templates.MappedHandler(tpl, func(ctx httpx.FormContext, r *http.Request) (userFormContext, templates.BaseContextGaps) {
+ return func(ctx httpx.FormContext, r *http.Request) any {
uctx := userFormContext{FormContext: ctx}
if user, err := panel.Dependencies.Auth.UserOf(r); err == nil {
uctx.User = &user.User
}
- return uctx, g
- })
+ return tpl.Context(r, uctx, funcs...)
+ }
}
diff --git a/internal/dis/component/auth/panel/password.go b/internal/dis/component/auth/panel/password.go
index adf3e79..6723d25 100644
--- a/internal/dis/component/auth/panel/password.go
+++ b/internal/dis/component/auth/panel/password.go
@@ -9,14 +9,19 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
- templating "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templates"
+ "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
"github.com/FAU-CDI/wisski-distillery/pkg/httpx/field"
)
//go:embed "templates/password.html"
var passwordHTML []byte
-var passwordTemplate = templating.Parse[userFormContext]("password.html", passwordHTML, assets.AssetsUser)
+var passwordTemplate = templating.Parse[userFormContext](
+ "password.html", passwordHTML, httpx.FormTemplate,
+
+ templating.Title("Change Password"),
+ templating.Assets(assets.AssetsUser),
+)
var (
errPasswordsNotIdentical = errors.New("passwords are not identical")
@@ -40,7 +45,7 @@ func (panel *UserPanel) routePassword(ctx context.Context) http.Handler {
FieldTemplate: field.PureCSSFieldTemplate,
RenderTemplate: tpl.Template(),
- RenderTemplateContext: panel.UserFormContext2(tpl, component.MenuItem{Title: "Change Password", Path: "/user/password/"}),
+ RenderTemplateContext: panel.UserFormContext(tpl, component.MenuItem{Title: "Change Password", Path: "/user/password/"}),
Validate: func(r *http.Request, values map[string]string) (struct{}, error) {
old, passcode, new, new2 := values["old"], values["otp"], values["new"], values["new2"]
diff --git a/internal/dis/component/auth/panel/ssh.go b/internal/dis/component/auth/panel/ssh.go
index e88c606..55bbd33 100644
--- a/internal/dis/component/auth/panel/ssh.go
+++ b/internal/dis/component/auth/panel/ssh.go
@@ -8,7 +8,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
- "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templates"
+ "github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
"github.com/FAU-CDI/wisski-distillery/pkg/httpx/field"
@@ -22,10 +22,15 @@ import (
//go:embed "templates/ssh.html"
var sshHTML []byte
-var sshTemplate = templates.Parse[SSHTemplateContext]("ssh.html", sshHTML, assets.AssetsUser)
+var sshTemplate = templating.Parse[SSHTemplateContext](
+ "ssh.html", sshHTML, nil,
+
+ templating.Title("SSH Keys"),
+ templating.Assets(assets.AssetsUser),
+)
type SSHTemplateContext struct {
- templates.BaseContext
+ templating.RuntimeFlags
Keys []models.Keys
@@ -37,15 +42,16 @@ type SSHTemplateContext struct {
}
func (panel *UserPanel) sshRoute(ctx context.Context) http.Handler {
- tpl := sshTemplate.Prepare(panel.Dependencies.Templating, templates.BaseContextGaps{
- Crumbs: []component.MenuItem{
- {Title: "User", Path: "/user/"},
- {Title: "SSH Keys", Path: "/user/ssh/"},
- },
- Actions: []component.MenuItem{
- {Title: "Add New Key", Path: "/user/ssh/add/"},
- },
- })
+ tpl := sshTemplate.Prepare(
+ panel.Dependencies.Templating,
+ templating.Crumbs(
+ component.MenuItem{Title: "User", Path: "/user/"},
+ component.MenuItem{Title: "SSH Keys", Path: "/user/ssh/"},
+ ),
+ templating.Actions(
+ component.MenuItem{Title: "Add New Key", Path: "/user/ssh/add/"},
+ ),
+ )
return tpl.HTMLHandler(func(r *http.Request) (sc SSHTemplateContext, err error) {
user, err := panel.Dependencies.Auth.UserOf(r)
@@ -114,7 +120,11 @@ func (panel *UserPanel) sshDeleteRoute(ctx context.Context) http.Handler {
//go:embed "templates/ssh_add.html"
var sshAddHTML []byte
-var sshAddTemplate = templates.ParseForm("ssh_add.html", sshAddHTML, assets.AssetsUser)
+var sshAddTemplate = templating.ParseForm(
+ "ssh_add.html", sshAddHTML, httpx.FormTemplate,
+ templating.Title("Add SSH Key"),
+ templating.Assets(assets.AssetsUser),
+)
type addKeyResult struct {
User *auth.AuthUser
@@ -123,13 +133,14 @@ type addKeyResult struct {
}
func (panel *UserPanel) sshAddRoute(ctx context.Context) http.Handler {
- tpl := sshAddTemplate.Prepare(panel.Dependencies.Templating, templates.BaseContextGaps{
- Crumbs: []component.MenuItem{
- {Title: "User", Path: "/user/"},
- {Title: "SSH Keys", Path: "/user/ssh/"},
- {Title: "Add New Key", Path: "/user/ssh/add/"},
- },
- })
+ tpl := sshAddTemplate.Prepare(
+ panel.Dependencies.Templating,
+ templating.Crumbs(
+ component.MenuItem{Title: "User", Path: "/user/"},
+ component.MenuItem{Title: "SSH Keys", Path: "/user/ssh/"},
+ component.MenuItem{Title: "Add New Key", Path: "/user/ssh/add/"},
+ ),
+ )
return &httpx.Form[addKeyResult]{
Fields: []field.Field{
@@ -139,7 +150,7 @@ func (panel *UserPanel) sshAddRoute(ctx context.Context) http.Handler {
FieldTemplate: field.PureCSSFieldTemplate,
RenderTemplate: tpl.Template(),
- RenderTemplateContext: templates.FormTemplateContext(tpl),
+ RenderTemplateContext: templating.FormTemplateContext(tpl),
Validate: func(r *http.Request, values map[string]string) (ak addKeyResult, err error) {
ak.User, err = panel.Dependencies.Auth.UserOf(r)
diff --git a/internal/dis/component/auth/panel/templates/password.html b/internal/dis/component/auth/panel/templates/password.html
index e85182d..e7c5cff 100644
--- a/internal/dis/component/auth/panel/templates/password.html
+++ b/internal/dis/component/auth/panel/templates/password.html
@@ -1,3 +1,2 @@
-{{ template "_form.html" . }}
-{{ define "form/title" }}Change Password{{ end }}
+{{ template "form.html" . }}
{{ define "form/button" }}Update{{ end }}
diff --git a/internal/dis/component/auth/panel/templates/ssh.html b/internal/dis/component/auth/panel/templates/ssh.html
index 9f20edd..219ee29 100644
--- a/internal/dis/component/auth/panel/templates/ssh.html
+++ b/internal/dis/component/auth/panel/templates/ssh.html
@@ -1,8 +1,3 @@
-{{ template "_base.html" . }}
-{{ define "title" }}SSH Keys{{ end }}
-
-{{ define "content" }}
-
This page allows you to add, view and remove ssh keys to and from your distillery account.
@@ -101,4 +96,3 @@ Host {{ .Domain }}.proxy
-{{ end }}
\ No newline at end of file
diff --git a/internal/dis/component/auth/panel/templates/ssh_add.html b/internal/dis/component/auth/panel/templates/ssh_add.html
index 15ae52e..bb47420 100644
--- a/internal/dis/component/auth/panel/templates/ssh_add.html
+++ b/internal/dis/component/auth/panel/templates/ssh_add.html
@@ -1,7 +1,4 @@
-{{ template "_form.html" . }}
-{{ define "form/title" }}Add SSH Key{{ end }}
{{ define "form/button" }}Add{{ end }}
-
{{ define "form/inside" }}