templates: Add ingredients page
This commit is contained in:
parent
d64e6f8ec3
commit
7a53703aaa
17 changed files with 109 additions and 43 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
13
internal/dis/component/control/info/html/components.html
Normal file
13
internal/dis/component/control/info/html/components.html
Normal 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> >
|
||||
<a class="pure-button pure-button-primary" href="/dis/components">Components</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
{{ define "content" }}
|
||||
{{ template "_anal.html" .Analytics }}
|
||||
{{ end }}
|
||||
14
internal/dis/component/control/info/html/ingredients.html
Normal file
14
internal/dis/component/control/info/html/ingredients.html
Normal 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> >
|
||||
<a class="pure-button" href="/dis/instance/{{ .Instance.Slug }}">Instance</a> >
|
||||
<a class="pure-button pure-button-primary" href="/dis/ingredients/{{ .Instance.Slug }}">Ingredients</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
{{ define "content" }}
|
||||
{{ template "_anal.html" .Analytics }}
|
||||
{{ end }}
|
||||
|
|
@ -6,6 +6,9 @@
|
|||
<a class="pure-button" href="/dis/index">Control</a> >
|
||||
<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" }}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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:]
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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">`,
|
||||
}
|
||||
|
|
|
|||
0
internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.css
vendored
Normal file
0
internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.css
vendored
Normal file
0
internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.js
vendored
Normal file
0
internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.js
vendored
Normal 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> >
|
||||
<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 }}
|
||||
|
|
@ -4,11 +4,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel/drush"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/locker"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php/extras"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
|
|
@ -18,11 +15,7 @@ type Info struct {
|
|||
PHP *php.PHP
|
||||
Fetchers []ingredient.Fetcher
|
||||
|
||||
Barrel *barrel.Barrel
|
||||
Locker *locker.Locker
|
||||
Drush *drush.Drush
|
||||
Prefixes *extras.Prefixes
|
||||
Pathbuilder *extras.Pathbuilder
|
||||
Analytics *lazy.PoolAnalytics
|
||||
}
|
||||
|
||||
// TODO: Use the information struct globally
|
||||
|
|
|
|||
|
|
@ -96,7 +96,9 @@ func (wisski *WissKI) allIngredients() []initFunc {
|
|||
auto[*extras.Pathbuilder],
|
||||
|
||||
// info
|
||||
auto[*info.Info],
|
||||
manual(func(info *info.Info) {
|
||||
info.Analytics = &wisski.pool.Analytics
|
||||
}),
|
||||
auto[*barrel.LastRebuildFetcher],
|
||||
auto[*barrel.RunningFetcher],
|
||||
auto[*drush.LastUpdateFetcher],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue