Unify instance_{rebuild,provision}.html
This commit unifies the templates for rebuild and provision as they are nearly identical.
This commit is contained in:
parent
760aae0dc1
commit
2459cc005f
4 changed files with 50 additions and 107 deletions
|
|
@ -1,47 +0,0 @@
|
||||||
<div class="pure-u-1-1">
|
|
||||||
<form class="pure-form pure-form-aligned" id="provision">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Main Parameters</legend>
|
|
||||||
|
|
||||||
<div class="pure-control-group">
|
|
||||||
<label for="slug">Slug</label>
|
|
||||||
<input name="slug" id="slug" placeholder="">
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
<fieldset>
|
|
||||||
<legend>System Parameters</legend>
|
|
||||||
|
|
||||||
<div class="pure-control-group">
|
|
||||||
<label for="php">PHP Version</label>
|
|
||||||
<select id="php">
|
|
||||||
<option value="" selected>Default ({{ .DefaultPHPVersion }})</option>
|
|
||||||
{{ range .PHPVersions }}
|
|
||||||
<option value="{{ . }}">{{ . }}</option>
|
|
||||||
{{ end }}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<label for="opcacheDevelopment" class="pure-checkbox">
|
|
||||||
<input type="checkbox" id="opcacheDevelopment" />
|
|
||||||
Opache Development Configuration
|
|
||||||
</label>
|
|
||||||
<div class="pure-control-group">
|
|
||||||
<label for="contentsecuritypolicy">Content Security Policy</label>
|
|
||||||
<input class="pure-input-1" name="contentsecuritypolicy" id="contentsecuritypolicy" list="content-security-policy" placeholder="">
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
<fieldset>
|
|
||||||
<legend>Profile</legend>
|
|
||||||
|
|
||||||
<div class="pure-control-group">
|
|
||||||
Not yet available
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<input type="submit" value="Provision" class="pure-button">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<datalist id="content-security-policy">
|
|
||||||
{{ range .ContentSecurityPolicies }}
|
|
||||||
<option value="{{ . }}">
|
|
||||||
{{ end }}
|
|
||||||
</datalist>
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
|
{{ $rebuild := .Rebuild }}
|
||||||
<div class="pure-u-1-1">
|
<div class="pure-u-1-1">
|
||||||
<form class="pure-form pure-form-aligned" id="rebuild">
|
<form class="pure-form pure-form-aligned" id="system">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Main Parameters</legend>
|
<legend>Main Parameters</legend>
|
||||||
|
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="slug">Slug</label>
|
<label for="slug">Slug</label>
|
||||||
<input name="slug" id="slug" placeholder="" readonly="readonly" value="{{ .Slug }}">
|
<input name="slug" id="slug" placeholder="" {{ if $rebuild }} readonly="readonly" value="{{ .Slug }}" {{ end }}>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|
@ -15,19 +16,19 @@
|
||||||
<label for="php">PHP Version</label>
|
<label for="php">PHP Version</label>
|
||||||
<select id="php">
|
<select id="php">
|
||||||
{{ $PHP := .System.PHP }}
|
{{ $PHP := .System.PHP }}
|
||||||
<option {{ if eq $PHP "" }}selected{{ end }}>Default ({{ .DefaultPHPVersion }})</option>
|
<option {{ if $rebuild }}{{ if eq $PHP "" }}selected{{ end }}{{ else }}selected{{ end }}>Default ({{ .DefaultPHPVersion }})</option>
|
||||||
{{ range .PHPVersions }}
|
{{ range .PHPVersions }}
|
||||||
<option {{ if eq $PHP . }}selected{{ end }} value="{{ . }}">{{ . }}</option>
|
<option {{ if $rebuild }}{{ if eq $PHP . }}selected{{ end }}{{ end }} value="{{ . }}">{{ . }}</option>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<label for="opcacheDevelopment" class="pure-checkbox">
|
<label for="opcacheDevelopment" class="pure-checkbox">
|
||||||
<input {{ if .System.OpCacheDevelopment }}checked{{end}} type="checkbox" id="opcacheDevelopment"/>
|
<input {{ if $rebuild }}{{ if .System.OpCacheDevelopment }}checked{{end}}{{end}} type="checkbox" id="opcacheDevelopment" />
|
||||||
Opache Development Configuration
|
Opache Development Configuration
|
||||||
</label>
|
</label>
|
||||||
<div class="pure-control-group" class="pure-input-1">
|
<div class="pure-control-group" class="pure-input-1">
|
||||||
<label for="contentsecuritypolicy">Content Security Policy</label>
|
<label for="contentsecuritypolicy">Content Security Policy</label>
|
||||||
<input name="contentsecuritypolicy" id="contentsecuritypolicy" list="content-security-policy" value="{{ .System.ContentSecurityPolicy }}">
|
<input name="contentsecuritypolicy" id="contentsecuritypolicy" list="content-security-policy" {{ if $rebuild }}value="{{ .System.ContentSecurityPolicy }}" {{ end }}>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|
@ -38,7 +39,7 @@
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<input type="submit" value="Rebuild" class="pure-button">
|
<input type="submit" value="{{ if $rebuild }}Rebuild{{ else }}Provision{{ end }}" class="pure-button">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -6,42 +6,16 @@ import (
|
||||||
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
|
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
|
||||||
|
|
||||||
_ "embed"
|
_ "embed"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed "html/instance_provision.html"
|
func (admin *Admin) instanceProvision(ctx context.Context) http.Handler {
|
||||||
var instanceProvisionHTML []byte
|
tpl := instanceSystemTemplate.Prepare(
|
||||||
var instanceProvisionTemplate = templating.Parse[instanceProvisionContext](
|
admin.Dependencies.Templating,
|
||||||
"instance_provision.html", instanceProvisionHTML, nil,
|
|
||||||
|
|
||||||
templating.Title("Provision New Instance"),
|
templating.Title("Provision New Instance"),
|
||||||
templating.Assets(assets.AssetsAdminProvision),
|
templating.Assets(assets.AssetsAdminProvision),
|
||||||
)
|
|
||||||
|
|
||||||
type instanceProvisionContext struct {
|
|
||||||
templating.RuntimeFlags
|
|
||||||
|
|
||||||
systemParams
|
|
||||||
}
|
|
||||||
|
|
||||||
type systemParams struct {
|
|
||||||
PHPVersions []string
|
|
||||||
ContentSecurityPolicies []string
|
|
||||||
DefaultPHPVersion string
|
|
||||||
}
|
|
||||||
|
|
||||||
func newSystemParams() (sp systemParams) {
|
|
||||||
sp.PHPVersions = models.KnownPHPVersions()
|
|
||||||
sp.ContentSecurityPolicies = models.ContentSecurityPolicyExamples()
|
|
||||||
sp.DefaultPHPVersion = models.DefaultPHPVersion
|
|
||||||
return sp
|
|
||||||
}
|
|
||||||
|
|
||||||
func (admin *Admin) instanceProvision(ctx context.Context) http.Handler {
|
|
||||||
tpl := instanceProvisionTemplate.Prepare(
|
|
||||||
admin.Dependencies.Templating,
|
|
||||||
|
|
||||||
templating.Crumbs(
|
templating.Crumbs(
|
||||||
menuAdmin,
|
menuAdmin,
|
||||||
|
|
@ -50,8 +24,8 @@ func (admin *Admin) instanceProvision(ctx context.Context) http.Handler {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return tpl.HTMLHandler(func(r *http.Request) (ipc instanceProvisionContext, err error) {
|
return tpl.HTMLHandler(func(r *http.Request) (ipc instanceSystemContext, err error) {
|
||||||
ipc.systemParams = newSystemParams()
|
ipc.prepare(false)
|
||||||
return ipc, nil
|
return ipc, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,27 +17,42 @@ import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed "html/instance_rebuild.html"
|
//go:embed "html/instance_system.html"
|
||||||
var instanceRebuildHTML []byte
|
var instanceSystemHTML []byte
|
||||||
var instanceRebuildTemplate = templating.Parse[instanceRebuildContext](
|
var instanceSystemTemplate = templating.Parse[instanceSystemContext](
|
||||||
"instance_rebuild.html", instanceRebuildHTML, nil,
|
"instance_system.html", instanceSystemHTML, nil,
|
||||||
|
|
||||||
templating.Title("Rebuild Instance"),
|
|
||||||
templating.Assets(assets.AssetsAdminRebuild),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type instanceRebuildContext struct {
|
// instanceSystemContext is the context for instance_system.html
|
||||||
|
type instanceSystemContext struct {
|
||||||
templating.RuntimeFlags
|
templating.RuntimeFlags
|
||||||
|
|
||||||
|
// parameters for completion
|
||||||
|
PHPVersions []string
|
||||||
|
ContentSecurityPolicies []string
|
||||||
|
DefaultPHPVersion string
|
||||||
|
|
||||||
|
// Are we in rebuild mode?
|
||||||
|
Rebuild bool
|
||||||
Slug string
|
Slug string
|
||||||
System models.System
|
System models.System
|
||||||
|
}
|
||||||
|
|
||||||
systemParams
|
// prepare prares the given instanceSystemContent
|
||||||
|
func (isc *instanceSystemContext) prepare(rebuild bool) {
|
||||||
|
isc.Rebuild = rebuild
|
||||||
|
isc.PHPVersions = models.KnownPHPVersions()
|
||||||
|
isc.ContentSecurityPolicies = models.ContentSecurityPolicyExamples()
|
||||||
|
isc.DefaultPHPVersion = models.DefaultPHPVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func (admin *Admin) instanceRebuild(ctx context.Context) http.Handler {
|
func (admin *Admin) instanceRebuild(ctx context.Context) http.Handler {
|
||||||
tpl := instanceRebuildTemplate.Prepare(
|
tpl := instanceSystemTemplate.Prepare(
|
||||||
admin.Dependencies.Templating,
|
admin.Dependencies.Templating,
|
||||||
|
|
||||||
|
templating.Title("Rebuild Instance"),
|
||||||
|
templating.Assets(assets.AssetsAdminRebuild),
|
||||||
|
|
||||||
templating.Crumbs(
|
templating.Crumbs(
|
||||||
menuAdmin,
|
menuAdmin,
|
||||||
menuInstances,
|
menuInstances,
|
||||||
|
|
@ -46,20 +61,20 @@ func (admin *Admin) instanceRebuild(ctx context.Context) http.Handler {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return tpl.HTMLHandlerWithFlags(func(r *http.Request) (ib instanceRebuildContext, funcs []templating.FlagFunc, err error) {
|
return tpl.HTMLHandlerWithFlags(func(r *http.Request) (isc instanceSystemContext, funcs []templating.FlagFunc, err error) {
|
||||||
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
||||||
|
|
||||||
var instance *wisski.WissKI
|
var instance *wisski.WissKI
|
||||||
instance, err = admin.Dependencies.Instances.WissKI(r.Context(), slug)
|
instance, err = admin.Dependencies.Instances.WissKI(r.Context(), slug)
|
||||||
if err == instances.ErrWissKINotFound {
|
if err == instances.ErrWissKINotFound {
|
||||||
return ib, nil, httpx.ErrNotFound
|
return isc, nil, httpx.ErrNotFound
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ib, nil, err
|
return isc, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ib.Slug = instance.Slug
|
isc.Slug = instance.Slug
|
||||||
ib.System = instance.System
|
isc.System = instance.System
|
||||||
|
|
||||||
// replace the menu item
|
// replace the menu item
|
||||||
funcs = []templating.FlagFunc{
|
funcs = []templating.FlagFunc{
|
||||||
|
|
@ -68,7 +83,7 @@ func (admin *Admin) instanceRebuild(ctx context.Context) http.Handler {
|
||||||
templating.Title(instance.Slug + " - Rebuild"),
|
templating.Title(instance.Slug + " - Rebuild"),
|
||||||
}
|
}
|
||||||
|
|
||||||
ib.systemParams = newSystemParams()
|
isc.prepare(true)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue