From 202599aaeb157ce4d298b7e859289b984e76ab2c Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Thu, 12 Jan 2023 13:55:07 +0100 Subject: [PATCH] templating: Move actions into template --- internal/dis/component/auth/panel/panel.go | 6 ++-- internal/dis/component/auth/panel/password.go | 3 +- .../component/auth/panel/templates/user.html | 15 ++-------- internal/dis/component/auth/panel/totp.go | 15 ++++++---- internal/dis/component/auth/panel/user.go | 25 +++++++++++++++-- internal/dis/component/auth/session.go | 7 +++-- .../dis/component/control/admin/components.go | 18 +++++++----- .../dis/component/control/admin/grants.go | 10 ++++--- .../component/control/admin/html/index.html | 9 ------ .../control/admin/html/instance.html | 9 ------ .../component/control/admin/html/users.html | 10 +------ internal/dis/component/control/admin/index.go | 10 +++++-- .../dis/component/control/admin/instance.go | 12 ++++++-- internal/dis/component/control/admin/users.go | 23 +++++++++------ internal/dis/component/control/home/public.go | 8 ++++-- internal/dis/component/control/legal/legal.go | 6 ++-- internal/dis/component/control/news/news.go | 8 ++++-- .../control/static/custom/context.go | 28 +++++++++++++------ .../control/static/templates/_anal.html | 2 +- .../control/static/templates/_base.html | 10 +++++-- internal/dis/component/menu.go | 4 +++ internal/dis/component/resolver/resolver.go | 14 ++++++++-- internal/dis/component/resolver/resolver.html | 6 ++-- 23 files changed, 153 insertions(+), 105 deletions(-) diff --git a/internal/dis/component/auth/panel/panel.go b/internal/dis/component/auth/panel/panel.go index 803a26a..4d556e4 100644 --- a/internal/dis/component/auth/panel/panel.go +++ b/internal/dis/component/auth/panel/panel.go @@ -84,8 +84,8 @@ type userFormContext struct { User *models.User } -func (panel *UserPanel) UserFormContext(last component.MenuItem) func(ctx httpx.FormContext, r *http.Request) any { - crumbs := []component.MenuItem{ +func (panel *UserPanel) UserFormContext(last component.MenuItem, gaps custom.BaseContextGaps) func(ctx httpx.FormContext, r *http.Request) any { + gaps.Crumbs = []component.MenuItem{ {Title: "User", Path: "/user/"}, last, } @@ -93,7 +93,7 @@ func (panel *UserPanel) UserFormContext(last component.MenuItem) func(ctx httpx. user, err := panel.Dependencies.Auth.UserOf(r) uctx := userFormContext{FormContext: ctx} - panel.Dependencies.Custom.Update(&uctx, r, crumbs) + panel.Dependencies.Custom.Update(&uctx, r, gaps) if err == nil { uctx.User = &user.User } diff --git a/internal/dis/component/auth/panel/password.go b/internal/dis/component/auth/panel/password.go index 3991317..6903a51 100644 --- a/internal/dis/component/auth/panel/password.go +++ b/internal/dis/component/auth/panel/password.go @@ -9,6 +9,7 @@ import ( "github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static" + "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom" "github.com/FAU-CDI/wisski-distillery/pkg/httpx" "github.com/FAU-CDI/wisski-distillery/pkg/httpx/field" ) @@ -38,7 +39,7 @@ func (panel *UserPanel) routePassword(ctx context.Context) http.Handler { FieldTemplate: field.PureCSSFieldTemplate, RenderTemplate: passwordTemplate, - RenderTemplateContext: panel.UserFormContext(component.MenuItem{Title: "Change Password", Path: "/user/password/"}), + RenderTemplateContext: panel.UserFormContext(component.MenuItem{Title: "Change Password", Path: "/user/password/"}, custom.BaseContextGaps{}), 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/templates/user.html b/internal/dis/component/auth/panel/templates/user.html index 9bca784..b266052 100644 --- a/internal/dis/component/auth/panel/templates/user.html +++ b/internal/dis/component/auth/panel/templates/user.html @@ -18,14 +18,6 @@ {{ end }}

-
- Change Password - {{ if .User.IsTOTPEnabled }} - Disable Passcode (TOTP) - {{ else }} - Enable Passcode (TOTP) - {{ end }} -

@@ -34,14 +26,11 @@ {{ if (not .User.IsTOTPEnabled) }}

- TOTP is required to access these. + You are an administrator, but do not have TOTP enabled. + Please turn it on to access the admin page.

{{ end }} -
- Distillery Admin Page -
-
{{ end }} diff --git a/internal/dis/component/auth/panel/totp.go b/internal/dis/component/auth/panel/totp.go index 6c0cb81..717e24b 100644 --- a/internal/dis/component/auth/panel/totp.go +++ b/internal/dis/component/auth/panel/totp.go @@ -8,6 +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/control/static" + "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom" "github.com/FAU-CDI/wisski-distillery/pkg/httpx" "github.com/FAU-CDI/wisski-distillery/pkg/httpx/field" @@ -33,7 +34,7 @@ func (panel *UserPanel) routeTOTPEnable(ctx context.Context) http.Handler { }, RenderTemplate: totpEnableTemplate, - RenderTemplateContext: panel.UserFormContext(component.MenuItem{Title: "Enable TOTP", Path: "/user/totp/enable/"}), + RenderTemplateContext: panel.UserFormContext(component.MenuItem{Title: "Enable TOTP", Path: "/user/totp/enable/"}, custom.BaseContextGaps{}), Validate: func(r *http.Request, values map[string]string) (struct{}, error) { password := values["password"] @@ -78,9 +79,11 @@ type totpEnrollContext struct { func (panel *UserPanel) routeTOTPEnroll(ctx context.Context) http.Handler { totpEnrollTemplate := panel.Dependencies.Custom.Template(totpEnrollTemplate) - crumbs := []component.MenuItem{ - {Title: "User", Path: "/user/"}, - {Title: "Enable TOTP", Path: "/user/totp/enable/"}, + gaps := custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "User", Path: "/user/"}, + {Title: "Enable TOTP", Path: "/user/totp/enable/"}, + }, } return &httpx.Form[struct{}]{ Fields: []field.Field{ @@ -103,7 +106,7 @@ func (panel *UserPanel) routeTOTPEnroll(ctx context.Context) http.Handler { FormContext: context, }, } - panel.Dependencies.Custom.Update(&ctx.userFormContext, r, crumbs) + panel.Dependencies.Custom.Update(&ctx.userFormContext, r, gaps) if err == nil && user != nil { ctx.userFormContext.User = &user.User @@ -168,7 +171,7 @@ func (panel *UserPanel) routeTOTPDisable(ctx context.Context) http.Handler { return struct{}{}, err == nil && user != nil && !user.IsTOTPEnabled() }, RenderTemplate: totpDisableTemplate, - RenderTemplateContext: panel.UserFormContext(component.MenuItem{Title: "Disable TOTP", Path: "/user/totp/disable/"}), + RenderTemplateContext: panel.UserFormContext(component.MenuItem{Title: "Disable TOTP", Path: "/user/totp/disable/"}, custom.BaseContextGaps{}), Validate: func(r *http.Request, values map[string]string) (struct{}, error) { password, otp := values["password"], values["otp"] diff --git a/internal/dis/component/auth/panel/user.go b/internal/dis/component/auth/panel/user.go index 69515e7..45da2ae 100644 --- a/internal/dis/component/auth/panel/user.go +++ b/internal/dis/component/auth/panel/user.go @@ -36,13 +36,17 @@ type GrantWithURL struct { func (panel *UserPanel) routeUser(ctx context.Context) http.Handler { userTemplate := panel.Dependencies.Custom.Template(userTemplate) - crumbs := []component.MenuItem{ - {Title: "User", Path: "/user/"}, + gaps := custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "User", Path: "/user/"}, + }, + Actions: []component.MenuItem{ + {Title: "Change Password", Path: "/user/password"}, + }, } return &httpx.HTMLHandler[routeUserContext]{ Handler: func(r *http.Request) (ruc routeUserContext, err error) { - panel.Dependencies.Custom.Update(&ruc, r, crumbs) // find the user ruc.AuthUser, err = panel.Dependencies.Auth.UserOf(r) @@ -50,6 +54,21 @@ func (panel *UserPanel) routeUser(ctx context.Context) http.Handler { return ruc, err } + // build the gaps + gaps := gaps.Clone() + if ruc.AuthUser.IsTOTPEnabled() { + gaps.Actions = append(gaps.Actions, component.MenuItem{ + Title: "Disable Passcode (TOTP)", + Path: "/user/totp/disable/", + }) + } else { + gaps.Actions = append(gaps.Actions, component.MenuItem{ + Title: "Enable Passcode (TOTP)", + Path: "/user/totp/enable/", + }) + } + panel.Dependencies.Custom.Update(&ruc, r, gaps) + // find the grants grants, err := panel.Dependencies.Policy.User(r.Context(), ruc.AuthUser.User.User) if err != nil { diff --git a/internal/dis/component/auth/session.go b/internal/dis/component/auth/session.go index 434476e..0894a01 100644 --- a/internal/dis/component/auth/session.go +++ b/internal/dis/component/auth/session.go @@ -9,6 +9,7 @@ import ( "github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control" "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static" + "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom" "github.com/FAU-CDI/wisski-distillery/pkg/httpx" "github.com/FAU-CDI/wisski-distillery/pkg/httpx/field" "github.com/gorilla/sessions" @@ -144,8 +145,10 @@ func (auth *Auth) authLogin(ctx context.Context) http.Handler { if context.Err != nil { context.Err = errLoginFailed } - httpx.WriteHTML(auth.Dependencies.Custom.NewForm(context, r, []component.MenuItem{ - {Title: "Login", Path: template.URL(r.URL.RequestURI())}, + httpx.WriteHTML(auth.Dependencies.Custom.NewForm(context, r, custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Login", Path: template.URL(r.URL.RequestURI())}, + }, }), nil, loginTemplate, "", w, r) }, diff --git a/internal/dis/component/control/admin/components.go b/internal/dis/component/control/admin/components.go index 2e6b732..bd34a64 100644 --- a/internal/dis/component/control/admin/components.go +++ b/internal/dis/component/control/admin/components.go @@ -30,9 +30,11 @@ type componentContext struct { } func (admin *Admin) components(r *http.Request) (cp componentContext, err error) { - admin.Dependencies.Custom.Update(&cp, r, []component.MenuItem{ - {Title: "Admin", Path: "/admin/"}, - {Title: "Components", Path: "/admin/components/"}, + admin.Dependencies.Custom.Update(&cp, r, custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Admin", Path: "/admin/"}, + {Title: "Components", Path: "/admin/components/"}, + }, }) cp.Analytics = *admin.Analytics @@ -56,10 +58,12 @@ type ingredientsContext struct { func (admin *Admin) ingredients(r *http.Request) (cp ingredientsContext, err error) { slug := httprouter.ParamsFromContext(r.Context()).ByName("slug") - admin.Dependencies.Custom.Update(&cp, r, []component.MenuItem{ - {Title: "Admin", Path: "/admin/"}, - {Title: "Instance", Path: template.URL("/admin/instance/" + slug)}, - {Title: "Ingredients", Path: template.URL("/admin/instance/" + slug + "/ingredients/")}, + admin.Dependencies.Custom.Update(&cp, r, custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Admin", Path: "/admin/"}, + {Title: "Instance", Path: template.URL("/admin/instance/" + slug)}, + {Title: "Ingredients", Path: template.URL("/admin/instance/" + slug + "/ingredients/")}, + }, }) // find the instance itself! diff --git a/internal/dis/component/control/admin/grants.go b/internal/dis/component/control/admin/grants.go index 1df082a..0b5b339 100644 --- a/internal/dis/component/control/admin/grants.go +++ b/internal/dis/component/control/admin/grants.go @@ -40,10 +40,12 @@ type grantsContext struct { } func (gc *grantsContext) use(r *http.Request, slug string, admin *Admin) (err error) { - admin.Dependencies.Custom.Update(gc, r, []component.MenuItem{ - {Title: "Admin", Path: "/admin/"}, - {Title: "Instance", Path: template.URL("/admin/instance/" + slug)}, - {Title: "Grants", Path: template.URL("/admin/instance/" + slug + "/grants/")}, + admin.Dependencies.Custom.Update(gc, r, custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Admin", Path: "/admin/"}, + {Title: "Instance", Path: template.URL("/admin/instance/" + slug)}, + {Title: "Grants", Path: template.URL("/admin/instance/" + slug + "/grants/")}, + }, }) // find the instance itself diff --git a/internal/dis/component/control/admin/html/index.html b/internal/dis/component/control/admin/html/index.html index db1b8f1..2e2f74d 100644 --- a/internal/dis/component/control/admin/html/index.html +++ b/internal/dis/component/control/admin/html/index.html @@ -1,15 +1,6 @@ {{ template "_base.html" . }} {{ define "title" }}Admin{{ end }} -{{ define "header" }} -

-

- Users - Components -
-

-{{ end }} - {{ define "content" }}

Distillery Configuration

diff --git a/internal/dis/component/control/admin/html/instance.html b/internal/dis/component/control/admin/html/instance.html index 2017f0e..633d0fa 100644 --- a/internal/dis/component/control/admin/html/instance.html +++ b/internal/dis/component/control/admin/html/instance.html @@ -1,15 +1,6 @@ {{ template "_base.html" . }} {{ define "title" }}{{ .Instance.Slug }}{{ end }} -{{ define "header" }} -

-

-

-{{ end }} - {{ define "content" }}

Info & Status

diff --git a/internal/dis/component/control/admin/html/users.html b/internal/dis/component/control/admin/html/users.html index ae009df..6ecb9cb 100644 --- a/internal/dis/component/control/admin/html/users.html +++ b/internal/dis/component/control/admin/html/users.html @@ -1,13 +1,5 @@ {{ template "_base.html" . }} -{{ define "title" }}Admin Users{{ end }} - -{{ define "header" }} -

-

-

-{{ end }} +{{ define "title" }}Users{{ end }} {{ define "content" }} diff --git a/internal/dis/component/control/admin/index.go b/internal/dis/component/control/admin/index.go index 0f96525..f735eff 100644 --- a/internal/dis/component/control/admin/index.go +++ b/internal/dis/component/control/admin/index.go @@ -87,8 +87,14 @@ type indexContext struct { } func (admin *Admin) index(r *http.Request) (idx indexContext, err error) { - admin.Dependencies.Custom.Update(&idx, r, []component.MenuItem{ - {Title: "Admin", Path: "/admin/"}, + admin.Dependencies.Custom.Update(&idx, r, custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Admin", Path: "/admin/"}, + }, + Actions: []component.MenuItem{ + {Title: "Users", Path: "/admin/users/"}, + {Title: "Components", Path: "/admin/components/", Priority: component.SmallButton}, + }, }) idx.Distillery, idx.Instances, err = admin.Status(r.Context(), true) return diff --git a/internal/dis/component/control/admin/instance.go b/internal/dis/component/control/admin/instance.go index 5d688f6..1a71e03 100644 --- a/internal/dis/component/control/admin/instance.go +++ b/internal/dis/component/control/admin/instance.go @@ -32,9 +32,15 @@ type instanceContext struct { func (admin *Admin) instance(r *http.Request) (is instanceContext, err error) { slug := httprouter.ParamsFromContext(r.Context()).ByName("slug") - admin.Dependencies.Custom.Update(&is, r, []component.MenuItem{ - {Title: "Admin", Path: "/admin/"}, - {Title: "Instance", Path: template.URL("/admin/instance/" + slug)}, + admin.Dependencies.Custom.Update(&is, r, custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Admin", Path: "/admin/"}, + {Title: "Instance", Path: template.URL("/admin/instance/" + slug)}, + }, + Actions: []component.MenuItem{ + {Title: "Grants", Path: template.URL("/admin/grants/" + slug)}, + {Title: "Ingredients", Path: template.URL("/admin/ingredients/" + slug), Priority: component.SmallButton}, + }, }) // find the instance itself! diff --git a/internal/dis/component/control/admin/users.go b/internal/dis/component/control/admin/users.go index 266087e..f57ad8f 100644 --- a/internal/dis/component/control/admin/users.go +++ b/internal/dis/component/control/admin/users.go @@ -32,9 +32,11 @@ type userContext struct { } func (admin *Admin) users(r *http.Request) (uc userContext, err error) { - admin.Dependencies.Custom.Update(&uc, r, []component.MenuItem{ - {Title: "Admin", Path: "/admin/"}, - {Title: "Users", Path: "/admin/users/"}, + admin.Dependencies.Custom.Update(&uc, r, custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Admin", Path: "/admin/"}, + {Title: "Users", Path: "/admin/users/"}, + }, }) uc.Error = r.URL.Query().Get("error") @@ -62,10 +64,15 @@ type createUserResult struct { func (admin *Admin) createUser(ctx context.Context) http.Handler { userCreateTemplate := admin.Dependencies.Custom.Template(userCreateTemplate) - crumbs := []component.MenuItem{ - {Title: "Admin", Path: "/admin/"}, - {Title: "Users", Path: "/admin/users"}, - {Title: "Create", Path: "/admin/users/create"}, + gaps := custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Admin", Path: "/admin/"}, + {Title: "Users", Path: "/admin/users"}, + {Title: "Create", Path: "/admin/users/create"}, + }, + Actions: []component.MenuItem{ + {Title: "Create New", Path: "/admin/users/create/"}, + }, } return &httpx.Form[createUserResult]{ @@ -78,7 +85,7 @@ func (admin *Admin) createUser(ctx context.Context) http.Handler { RenderTemplate: userCreateTemplate, RenderTemplateContext: func(ctx httpx.FormContext, r *http.Request) any { - return admin.Dependencies.Custom.NewForm(ctx, r, crumbs) + return admin.Dependencies.Custom.NewForm(ctx, r, gaps) }, Validate: func(r *http.Request, values map[string]string) (cu createUserResult, err error) { diff --git a/internal/dis/component/control/home/public.go b/internal/dis/component/control/home/public.go index bfdf910..a274a5b 100644 --- a/internal/dis/component/control/home/public.go +++ b/internal/dis/component/control/home/public.go @@ -25,8 +25,10 @@ type publicContext struct { } func (home *Home) publicHandler(ctx context.Context) http.Handler { - crumbs := []component.MenuItem{ - {Title: "WissKI Distillery", Path: "/"}, + gaps := custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "WissKI Distillery", Path: "/"}, + }, } return httpx.HTMLHandler[publicContext]{ Handler: func(r *http.Request) (pc publicContext, err error) { @@ -35,7 +37,7 @@ func (home *Home) publicHandler(ctx context.Context) http.Handler { return pc, httpx.ErrNotFound } - home.Dependencies.Custom.Update(&pc, r, crumbs) + home.Dependencies.Custom.Update(&pc, r, gaps) pc.Instances = home.homeInstances.Get(nil) pc.SelfRedirect = home.Config.SelfRedirect.String() diff --git a/internal/dis/component/control/legal/legal.go b/internal/dis/component/control/legal/legal.go index 727641b..fde1f1b 100644 --- a/internal/dis/component/control/legal/legal.go +++ b/internal/dis/component/control/legal/legal.go @@ -59,8 +59,10 @@ type legalContext struct { } func (legal *Legal) context(r *http.Request) (lc legalContext, err error) { - legal.Dependencies.Custom.Update(&lc, r, []component.MenuItem{ - {Title: "Legal", Path: "/legal/"}, + legal.Dependencies.Custom.Update(&lc, r, custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "Legal", Path: "/legal/"}, + }, }) lc.LegalNotices = cli.LegalNotices diff --git a/internal/dis/component/control/news/news.go b/internal/dis/component/control/news/news.go index c270ce8..677d703 100644 --- a/internal/dis/component/control/news/news.go +++ b/internal/dis/component/control/news/news.go @@ -123,8 +123,10 @@ type newsContext struct { // HandleRoute returns the handler for the requested path func (news *News) HandleRoute(ctx context.Context, path string) (http.Handler, error) { - crumbs := []component.MenuItem{ - {Title: "News", Path: "/news/"}, + gaps := custom.BaseContextGaps{ + Crumbs: []component.MenuItem{ + {Title: "News", Path: "/news/"}, + }, } items, itemsErr := Items() @@ -134,7 +136,7 @@ func (news *News) HandleRoute(ctx context.Context, path string) (http.Handler, e return httpx.HTMLHandler[newsContext]{ Handler: func(r *http.Request) (nc newsContext, err error) { - news.Dependencies.Custom.Update(&nc, r, crumbs) + news.Dependencies.Custom.Update(&nc, r, gaps) nc.Items, err = items, itemsErr return diff --git a/internal/dis/component/control/static/custom/context.go b/internal/dis/component/control/static/custom/context.go index 612931e..01aa3cf 100644 --- a/internal/dis/component/control/static/custom/context.go +++ b/internal/dis/component/control/static/custom/context.go @@ -27,8 +27,8 @@ type BaseContext struct { GeneratedAt time.Time // time this page was generated at // Menu and breadcrumbs - Menu []component.MenuItem - Crumbs []component.MenuItem + Menu []component.MenuItem + BaseContextGaps CSRF template.HTML // CSRF Field } @@ -43,12 +43,24 @@ const ( requestNilError template.HTML = errorPrefix + "BaseContext.use() called with nil request" + errorSuffix ) +type BaseContextGaps struct { + Crumbs []component.MenuItem + Actions []component.MenuItem +} + +func (bcg BaseContextGaps) Clone() BaseContextGaps { + return BaseContextGaps{ + Crumbs: slices.Clone(bcg.Crumbs), + Actions: slices.Clone(bcg.Actions), + } +} + // Use updates this context to use the values from the given base. // // The given request *must not* be nil. // // For convenience the passed context is also returned. -func (tc *BaseContext) use(custom *Custom, r *http.Request, crumbs []component.MenuItem) *BaseContext { +func (tc *BaseContext) use(custom *Custom, r *http.Request, gaps BaseContextGaps) *BaseContext { // tc.custom = custom tc.inited = true tc.requestWasNil = r == nil @@ -65,7 +77,7 @@ func (tc *BaseContext) use(custom *Custom, r *http.Request, crumbs []component.M tc.Menu = custom.BuildMenu(r) // build the breadcrumbs - tc.Crumbs = slices.Clone(crumbs) + tc.BaseContextGaps = gaps.Clone() last := len(tc.Crumbs) - 1 for i := range tc.Crumbs { tc.Crumbs[i].Active = i == last @@ -86,9 +98,9 @@ func (bc BaseContext) DoInitCheck() template.HTML { } // NewForm is like New, but returns a new BaseFormContext -func (custom *Custom) NewForm(context httpx.FormContext, r *http.Request, crumbs []component.MenuItem) (ctx BaseFormContext) { +func (custom *Custom) NewForm(context httpx.FormContext, r *http.Request, bcg BaseContextGaps) (ctx BaseFormContext) { ctx.FormContext = context - ctx.use(custom, r, crumbs) + ctx.use(custom, r, bcg) return } @@ -96,11 +108,11 @@ func (custom *Custom) NewForm(context httpx.FormContext, r *http.Request, crumbs // // Assumes that context is a pointer to a struct type. // If this is not the case, might call panic(). -func (custom *Custom) Update(context any, r *http.Request, crumbs []component.MenuItem) *BaseContext { +func (custom *Custom) Update(context any, r *http.Request, bcg BaseContextGaps) *BaseContext { ctx := reflect.ValueOf(context). Elem().FieldByName(baseContextName).Addr(). Interface().(*BaseContext) - ctx.use(custom, r, crumbs) + ctx.use(custom, r, bcg) return ctx } diff --git a/internal/dis/component/control/static/templates/_anal.html b/internal/dis/component/control/static/templates/_anal.html index ec7160b..5d8af5a 100644 --- a/internal/dis/component/control/static/templates/_anal.html +++ b/internal/dis/component/control/static/templates/_anal.html @@ -1,5 +1,5 @@
-

Components

+

Structs

{{ range $name, $comp := .Components }} diff --git a/internal/dis/component/control/static/templates/_base.html b/internal/dis/component/control/static/templates/_base.html index 1996326..d284c8d 100644 --- a/internal/dis/component/control/static/templates/_base.html +++ b/internal/dis/component/control/static/templates/_base.html @@ -11,7 +11,7 @@ {{ .BaseContext.DoInitCheck }}