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

@ -1,129 +0,0 @@
{{ 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 }}
<div class="pure-u-1-1" id="{{ $name }}">
<div class="padding">
<div class="overflow">
<table class="pure-table pure-table-bordered">
<thead>
<tr>
<th colspan="3">
{{ $name }}
</th>
</tr>
</thead>
<tbody>
{{ range .Groups }}
<tr>
<td>
Implements
</td>
<td colspan="2">
<code><a href="#{{.}}">{{ . }}</a></code><br />
</td>
</tr>
{{ end }}
{{ range $name, $comp := .CFields }}
<tr>
<td>Component Pointer</td>
<td>
<code>{{ $name }}</code>
</td>
<td>
<code><a href="#{{ $comp }}">{{ $comp }}</a></code>
</td>
</tr>
{{ end }}
{{ range $name, $iface := .IFields }}
<tr>
<td>Interface Slice</td>
<td>
<code>{{ $name }}</code>
</td>
<td>
<code><a href="#{{ $iface }}">[]{{ $iface }}</a></code>
</td>
</tr>
{{ end }}
{{ range $name, $sig := $comp.Methods }}
<tr>
<td>
Method
</td>
<td>
<code>{{ $name }}</code>
</td>
<td>
<code>{{ $sig }}</code>
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
</div>
</div>
{{ end }}
<div class="pure-u-1-1">
<h2 id="interfaces">Interfaces</h2>
</div>
{{ range $name, $group := .Analytics.Groups }}
<div class="pure-u-1-1" id="{{ $name }}">
<div class="padding">
<div class="overflow">
<table class="pure-table pure-table-bordered">
<thead>
<tr>
<th colspan="3">
{{ $name }}
</th>
</tr>
</thead>
<tbody>
{{ range $name, $sig := $group.Methods }}
<tr>
<td>
Method
</td>
<td>
<code>{{ $name }}</code>
</td>
<td>
<code>{{ $sig }}</code>
</td>
</tr>
{{ end }}
{{ range $group.Components }}
<tr>
<td>
Implemented By
</td>
<td colspan="2">
<code><a href="#{{.}}">{{ . }}</a></code>
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
</div>
{{ end }}
{{ 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:]