custom: Add new footer template and context
This commit is contained in:
parent
009d649ea6
commit
bda763725e
18 changed files with 197 additions and 33 deletions
|
|
@ -3,9 +3,11 @@ package home
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
||||
)
|
||||
|
|
@ -14,11 +16,13 @@ type Home struct {
|
|||
component.Base
|
||||
Dependencies struct {
|
||||
Instances *instances.Instances
|
||||
Custom *custom.Custom
|
||||
}
|
||||
|
||||
redirect lazy.Lazy[*Redirect]
|
||||
instanceNames lazy.Lazy[map[string]struct{}]
|
||||
homeBytes lazy.Lazy[[]byte]
|
||||
homeTemplate lazy.Lazy[*template.Template]
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ package home
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"html/template"
|
||||
"time"
|
||||
|
||||
_ "embed"
|
||||
|
||||
"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/internal/status"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
|
@ -30,7 +32,8 @@ var homeHTMLStr string
|
|||
var homeTemplate = static.AssetsHome.MustParseShared("home.html", homeHTMLStr)
|
||||
|
||||
func (home *Home) homeRender(ctx context.Context) ([]byte, error) {
|
||||
var context HomeContext
|
||||
var context homeContext
|
||||
home.Dependencies.Custom.Update(&context)
|
||||
|
||||
// setup a couple of static things
|
||||
context.Time = time.Now().UTC()
|
||||
|
|
@ -57,11 +60,15 @@ func (home *Home) homeRender(ctx context.Context) ([]byte, error) {
|
|||
|
||||
// render the template
|
||||
var buffer bytes.Buffer
|
||||
homeTemplate.Execute(&buffer, context)
|
||||
home.homeTemplate.Get(func() *template.Template {
|
||||
return home.Dependencies.Custom.Template(homeTemplate)
|
||||
}).Execute(&buffer, context)
|
||||
return buffer.Bytes(), nil
|
||||
}
|
||||
|
||||
type HomeContext struct {
|
||||
type homeContext struct {
|
||||
custom.BaseContext
|
||||
|
||||
Instances []status.WissKI
|
||||
|
||||
Time time.Time
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue