From 7a53703aaa3242f3bae803dd00bb3a729f252e5a Mon Sep 17 00:00:00 2001
From: Tom Wiesing
Date: Fri, 21 Oct 2022 18:12:23 +0200
Subject: [PATCH] templates: Add ingredients page
---
.../dis/component/control/info/components.go | 49 +++++++++++++++++--
.../control/info/html/components.html | 13 +++++
.../info/html/{info_index.html => index.html} | 0
.../control/info/html/ingredients.html | 14 ++++++
.../{info_instance.html => instance.html} | 3 ++
internal/dis/component/control/info/index.go | 8 +--
internal/dis/component/control/info/info.go | 18 ++++---
.../dis/component/control/info/instance.go | 8 +--
.../dis/component/control/static/assets.go | 2 +-
.../component/control/static/assets_dist.go | 6 +++
.../dist/InstanceComponentsIndex.38d394c2.css | 0
.../dist/InstanceComponentsIndex.38d394c2.js | 0
.../entry/InstanceComponentsIndex/index.css | 0
.../entry/InstanceComponentsIndex/index.ts | 0
.../templates/_anal.html} | 16 +-----
internal/wisski/ingredient/info/info.go | 11 +----
internal/wisski/wisski.go | 4 +-
17 files changed, 109 insertions(+), 43 deletions(-)
create mode 100644 internal/dis/component/control/info/html/components.html
rename internal/dis/component/control/info/html/{info_index.html => index.html} (100%)
create mode 100644 internal/dis/component/control/info/html/ingredients.html
rename internal/dis/component/control/info/html/{info_instance.html => instance.html} (99%)
create mode 100644 internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.css
create mode 100644 internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.js
create mode 100644 internal/dis/component/control/static/src/entry/InstanceComponentsIndex/index.css
create mode 100644 internal/dis/component/control/static/src/entry/InstanceComponentsIndex/index.ts
rename internal/dis/component/control/{info/html/info_components.html => static/templates/_anal.html} (89%)
diff --git a/internal/dis/component/control/info/components.go b/internal/dis/component/control/info/components.go
index fa23963..1f1888a 100644
--- a/internal/dis/component/control/info/components.go
+++ b/internal/dis/component/control/info/components.go
@@ -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
+}
diff --git a/internal/dis/component/control/info/html/components.html b/internal/dis/component/control/info/html/components.html
new file mode 100644
index 0000000..bf916a7
--- /dev/null
+++ b/internal/dis/component/control/info/html/components.html
@@ -0,0 +1,13 @@
+{{ template "_base.html" . }}
+{{ define "title" }}Distillery Control Page - Components Page{{ end }}
+
+{{ define "header"}}
+
+ Control >
+ Components
+
+{{ end }}
+
+{{ define "content" }}
+{{ template "_anal.html" .Analytics }}
+{{ end }}
\ No newline at end of file
diff --git a/internal/dis/component/control/info/html/info_index.html b/internal/dis/component/control/info/html/index.html
similarity index 100%
rename from internal/dis/component/control/info/html/info_index.html
rename to internal/dis/component/control/info/html/index.html
diff --git a/internal/dis/component/control/info/html/ingredients.html b/internal/dis/component/control/info/html/ingredients.html
new file mode 100644
index 0000000..6281cb8
--- /dev/null
+++ b/internal/dis/component/control/info/html/ingredients.html
@@ -0,0 +1,14 @@
+{{ template "_base.html" . }}
+{{ define "title" }}Distillery Control Page - {{ .Instance.Slug }} - Ingredients{{ end }}
+
+{{ define "header"}}
+
+ Control >
+ Instance >
+ Ingredients
+
+{{ end }}
+
+{{ define "content" }}
+{{ template "_anal.html" .Analytics }}
+{{ end }}
\ No newline at end of file
diff --git a/internal/dis/component/control/info/html/info_instance.html b/internal/dis/component/control/info/html/instance.html
similarity index 99%
rename from internal/dis/component/control/info/html/info_instance.html
rename to internal/dis/component/control/info/html/instance.html
index 3675cd3..a97eef0 100644
--- a/internal/dis/component/control/info/html/info_instance.html
+++ b/internal/dis/component/control/info/html/instance.html
@@ -6,6 +6,9 @@
Control >
Instance
+
+ Ingredients
+
{{ end }}
{{ define "content" }}
diff --git a/internal/dis/component/control/info/index.go b/internal/dis/component/control/info/index.go
index 8754300..b8495f6 100644
--- a/internal/dis/component/control/info/index.go
+++ b/internal/dis/component/control/info/index.go
@@ -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 {
diff --git a/internal/dis/component/control/info/info.go b/internal/dis/component/control/info/info.go
index 19724b3..7065053 100644
--- a/internal/dis/component/control/info/info.go
+++ b/internal/dis/component/control/info/info.go
@@ -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,
})
diff --git a/internal/dis/component/control/info/instance.go b/internal/dis/component/control/info/instance.go
index c9c40dd..2fac1fa 100644
--- a/internal/dis/component/control/info/instance.go
+++ b/internal/dis/component/control/info/instance.go
@@ -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:]
diff --git a/internal/dis/component/control/static/assets.go b/internal/dis/component/control/static/assets.go
index b6d2b38..4d5b92a 100644
--- a/internal/dis/component/control/static/assets.go
+++ b/internal/dis/component/control/static/assets.go
@@ -21,7 +21,7 @@ type Assets struct {
Styles string // 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.
diff --git a/internal/dis/component/control/static/assets_dist.go b/internal/dis/component/control/static/assets_dist.go
index c59144e..e05bff8 100644
--- a/internal/dis/component/control/static/assets_dist.go
+++ b/internal/dis/component/control/static/assets_dist.go
@@ -25,3 +25,9 @@ var AssetsControlInstance = Assets{
Scripts: ``,
Styles: ` `,
}
+
+// AssetsInstanceComponentsIndex contains assets for the 'InstanceComponentsIndex' entrypoint.
+var AssetsInstanceComponentsIndex = Assets{
+ Scripts: ``,
+ Styles: ` `,
+}
diff --git a/internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.css b/internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.css
new file mode 100644
index 0000000..e69de29
diff --git a/internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.js b/internal/dis/component/control/static/dist/InstanceComponentsIndex.38d394c2.js
new file mode 100644
index 0000000..e69de29
diff --git a/internal/dis/component/control/static/src/entry/InstanceComponentsIndex/index.css b/internal/dis/component/control/static/src/entry/InstanceComponentsIndex/index.css
new file mode 100644
index 0000000..e69de29
diff --git a/internal/dis/component/control/static/src/entry/InstanceComponentsIndex/index.ts b/internal/dis/component/control/static/src/entry/InstanceComponentsIndex/index.ts
new file mode 100644
index 0000000..e69de29
diff --git a/internal/dis/component/control/info/html/info_components.html b/internal/dis/component/control/static/templates/_anal.html
similarity index 89%
rename from internal/dis/component/control/info/html/info_components.html
rename to internal/dis/component/control/static/templates/_anal.html
index 9566561..bd484fd 100644
--- a/internal/dis/component/control/info/html/info_components.html
+++ b/internal/dis/component/control/static/templates/_anal.html
@@ -1,19 +1,8 @@
-{{ template "_base.html" . }}
-{{ define "title" }}Distillery Control Page - Components Page{{ end }}
-
-{{ define "header"}}
-
- Control >
- Components
-
-{{ end }}
-
-{{ define "content" }}
Components
-{{ range $name, $comp := .Analytics.Components }}
+{{ range $name, $comp := .Components }}
@@ -83,7 +72,7 @@
Interfaces
-{{ range $name, $group := .Analytics.Groups }}
+{{ range $name, $group := .Groups }}
-{{ end }}
{{ end }}
\ No newline at end of file
diff --git a/internal/wisski/ingredient/info/info.go b/internal/wisski/ingredient/info/info.go
index 22d8687..6839aa6 100644
--- a/internal/wisski/ingredient/info/info.go
+++ b/internal/wisski/ingredient/info/info.go
@@ -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
diff --git a/internal/wisski/wisski.go b/internal/wisski/wisski.go
index 06608ec..48ecda4 100644
--- a/internal/wisski/wisski.go
+++ b/internal/wisski/wisski.go
@@ -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],