templates: Add ingredients page

This commit is contained in:
Tom Wiesing 2022-10-21 18:12:23 +02:00
parent d64e6f8ec3
commit 7a53703aaa
No known key found for this signature in database
17 changed files with 109 additions and 43 deletions

View file

@ -2,30 +2,71 @@ package info
import (
"net/http"
"strings"
"time"
_ "embed"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
)
//go:embed "html/info_components.html"
//go:embed "html/components.html"
var componentsTemplateString string
var componentsTemplate = static.AssetsComponentsIndex.MustParseShared(
"info_components.html",
"components.html",
componentsTemplateString,
)
type componentsPageContext struct {
type componentContext struct {
Time time.Time
Analytics lazy.PoolAnalytics
}
func (info *Info) componentsPageAPI(r *http.Request) (cp componentsPageContext, err error) {
func (info *Info) components(r *http.Request) (cp componentContext, err error) {
cp.Analytics = *info.Analytics
cp.Time = time.Now().UTC()
return
}
//go:embed "html/ingredients.html"
var ingredientsTemplateString string
var ingredientsTemplate = static.AssetsInstanceComponentsIndex.MustParseShared(
"ingredients.html",
ingredientsTemplateString,
)
type ingredientsContext struct {
Time time.Time
Instance models.Instance
Analytics *lazy.PoolAnalytics
}
func (info *Info) ingredients(r *http.Request) (cp ingredientsContext, err error) {
cp.Time = time.Now().UTC()
// find the slug as the last component of path!
slug := strings.TrimSuffix(r.URL.Path, "/")
slug = slug[strings.LastIndex(slug, "/")+1:]
// find the instance itself!
instance, err := info.Instances.WissKI(slug)
if err == instances.ErrWissKINotFound {
return cp, httpx.ErrNotFound
}
if err != nil {
return cp, err
}
cp.Instance = instance.Instance
// and get the components
cp.Analytics = instance.Info().Analytics
return
}

View file

@ -0,0 +1,13 @@
{{ template "_base.html" . }}
{{ define "title" }}Distillery Control Page - Components Page{{ end }}
{{ define "header"}}
<p>
<a class="pure-button" href="/dis/index">Control</a> &gt;
<a class="pure-button pure-button-primary" href="/dis/components">Components</a>
</p>
{{ end }}
{{ define "content" }}
{{ template "_anal.html" .Analytics }}
{{ end }}

View file

@ -0,0 +1,14 @@
{{ template "_base.html" . }}
{{ define "title" }}Distillery Control Page - {{ .Instance.Slug }} - Ingredients{{ end }}
{{ define "header"}}
<p>
<a class="pure-button" href="/dis/index">Control</a> &gt;
<a class="pure-button" href="/dis/instance/{{ .Instance.Slug }}">Instance</a> &gt;
<a class="pure-button pure-button-primary" href="/dis/ingredients/{{ .Instance.Slug }}">Ingredients</a>
</p>
{{ end }}
{{ define "content" }}
{{ template "_anal.html" .Analytics }}
{{ end }}

View file

@ -6,6 +6,9 @@
<a class="pure-button" href="/dis/index">Control</a> &gt;
<a class="pure-button pure-button-primary" href="/dis/instance/{{ .Info.Slug }}">Instance</a>
</p>
<p>
<a class="pure-button" href="/dis/ingredients/{{ .Info.Slug }}">Ingredients</a>
</p>
{{ end }}
{{ define "content" }}

View file

@ -13,14 +13,14 @@ import (
"golang.org/x/sync/errgroup"
)
//go:embed "html/info_index.html"
//go:embed "html/index.html"
var indexTemplateStr string
var indexTemplate = static.AssetsControlIndex.MustParseShared(
"info_index.html",
"index.html",
indexTemplateStr,
)
type indexPageContext struct {
type indexContext struct {
Time time.Time
Config *config.Config
@ -34,7 +34,7 @@ type indexPageContext struct {
Backups []models.Export
}
func (nfo *Info) indexPageAPI(r *http.Request) (idx indexPageContext, err error) {
func (nfo *Info) index(r *http.Request) (idx indexContext, err error) {
var group errgroup.Group
group.Go(func() error {

View file

@ -39,20 +39,26 @@ func (info *Info) Handler(route string, context context.Context, io stream.IOStr
})
// add a handler for the index page
mux.Handle(route+"index", httpx.HTMLHandler[indexPageContext]{
Handler: info.indexPageAPI,
mux.Handle(route+"index", httpx.HTMLHandler[indexContext]{
Handler: info.index,
Template: indexTemplate,
})
// add a handler for the component page
mux.Handle(route+"components", httpx.HTMLHandler[componentsPageContext]{
Handler: info.componentsPageAPI,
mux.Handle(route+"components", httpx.HTMLHandler[componentContext]{
Handler: info.components,
Template: componentsTemplate,
})
// add a handler for the component page
mux.Handle(route+"ingredients/", httpx.HTMLHandler[ingredientsContext]{
Handler: info.ingredients,
Template: ingredientsTemplate,
})
// add a handler for the instance page
mux.Handle(route+"instance/", httpx.HTMLHandler[instancePageContext]{
Handler: info.instancePageAPI,
mux.Handle(route+"instance/", httpx.HTMLHandler[instanceContext]{
Handler: info.instance,
Template: instanceTemplate,
})

View file

@ -13,21 +13,21 @@ import (
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
)
//go:embed "html/info_instance.html"
//go:embed "html/instance.html"
var instanceTemplateString string
var instanceTemplate = static.AssetsControlInstance.MustParseShared(
"info_instance.html",
"instance.html",
instanceTemplateString,
)
type instancePageContext struct {
type instanceContext struct {
Time time.Time
Instance models.Instance
Info info.WissKIInfo
}
func (info *Info) instancePageAPI(r *http.Request) (is instancePageContext, err error) {
func (info *Info) instance(r *http.Request) (is instanceContext, err error) {
// find the slug as the last component of path!
slug := strings.TrimSuffix(r.URL.Path, "/")
slug = slug[strings.LastIndex(slug, "/")+1:]

View file

@ -21,7 +21,7 @@ type Assets struct {
Styles string // <link> tags inserted by the asset
}
//go:generate node build.mjs HomeHome ComponentsIndex ControlIndex ControlInstance
//go:generate node build.mjs HomeHome ComponentsIndex ControlIndex ControlInstance InstanceComponentsIndex
// MustParse parses a new template from the given source
// and calls [RegisterAssoc] on it.

View file

@ -25,3 +25,9 @@ var AssetsControlInstance = Assets{
Scripts: `<script nomodule="" defer src="/static/ControlIndex.613b02c2.js"></script><script type="module" src="/static/ControlIndex.cfbf936d.js"></script><script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/ControlInstance.66b95713.js"></script><script src="/static/ControlInstance.9cc7166d.js" nomodule="" defer></script>`,
Styles: `<link rel="stylesheet" href="/static/HomeHome.a75f04fa.css"><link rel="stylesheet" href="/static/ControlIndex.6d59e220.css"><link rel="stylesheet" href="/static/ControlIndex.6d2ae968.css"><link rel="stylesheet" href="/static/ControlInstance.38d394c2.css">`,
}
// AssetsInstanceComponentsIndex contains assets for the 'InstanceComponentsIndex' entrypoint.
var AssetsInstanceComponentsIndex = Assets{
Scripts: `<script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/InstanceComponentsIndex.38d394c2.js"></script><script src="/static/InstanceComponentsIndex.38d394c2.js" nomodule="" defer></script>`,
Styles: `<link rel="stylesheet" href="/static/HomeHome.a75f04fa.css"><link rel="stylesheet" href="/static/InstanceComponentsIndex.38d394c2.css">`,
}

View file

@ -1,19 +1,8 @@
{{ template "_base.html" . }}
{{ define "title" }}Distillery Control Page - Components Page{{ end }}
{{ define "header"}}
<p>
<a class="pure-button" href="/dis/index">Control</a> &gt;
<a class="pure-button pure-button-primary" href="/dis/components">Components</a>
</p>
{{ end }}
{{ define "content" }}
<div class="pure-u-1-1">
<h2 id="components">Components</h2>
</div>
{{ range $name, $comp := .Analytics.Components }}
{{ range $name, $comp := .Components }}
<div class="pure-u-1-1" id="{{ $name }}">
<div class="padding">
<div class="overflow">
@ -83,7 +72,7 @@
<h2 id="interfaces">Interfaces</h2>
</div>
{{ range $name, $group := .Analytics.Groups }}
{{ range $name, $group := .Groups }}
<div class="pure-u-1-1" id="{{ $name }}">
<div class="padding">
@ -125,5 +114,4 @@
</div>
</div>
</div>
{{ end }}
{{ end }}