Move instance > purge to a separate page
This commit is contained in:
parent
a2ad685b61
commit
1379b4d11a
5 changed files with 79 additions and 20 deletions
|
|
@ -73,6 +73,7 @@ var (
|
|||
menuInstance = component.DummyMenuItem()
|
||||
menuRebuild = component.DummyMenuItem()
|
||||
menuGrants = component.DummyMenuItem()
|
||||
menuPurge = component.DummyMenuItem()
|
||||
)
|
||||
|
||||
func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http.Handler, err error) {
|
||||
|
|
@ -133,6 +134,11 @@ func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http
|
|||
router.Handler(http.MethodPost, route+"grants/", iUsers) // NOTE(twiesing): This path is intentionally different!
|
||||
}
|
||||
|
||||
{
|
||||
purge := admin.instancePurge(ctx)
|
||||
router.Handler(http.MethodGet, route+"instance/:slug/purge", purge)
|
||||
}
|
||||
|
||||
// add a router for the login page
|
||||
router.Handler(http.MethodPost, route+"login", admin.loginHandler(ctx))
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
<a class="pure-button pure-button-small" href="#stats">Statistics</a>
|
||||
<a class="pure-button pure-button-small" href="#ssh">SSH Keys</a>
|
||||
<a class="pure-button pure-button-small" href="#snapshots">Snapshots</a>
|
||||
<a class="pure-button pure-button-small" href="#danger">Dangerous Actions</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -548,22 +547,4 @@
|
|||
{{ end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="pure-u-1-1">
|
||||
<h2 id="danger">Dangerous Actions</h2>
|
||||
</div>
|
||||
|
||||
<div class="pure-u-1 pure-u-xl-2-5">
|
||||
<p>
|
||||
Purging this instance completely removes it from the distillery.
|
||||
Backups containing the instance will remain, but it will not be possible to restore it directly.
|
||||
You must enter the slug <code>{{ .Instance.Slug }}</code> to confirm purging.
|
||||
</p>
|
||||
<form class="pure-form">
|
||||
<fieldset>
|
||||
<input type="text" id="purge-confirm-slug" placeholder="{{ .Instance.Slug }}" />
|
||||
<button class="remote-action pure-button pure-button-danger" data-action="purge" data-param="{{ .Instance.Slug }}" data-confirm-param="#purge-confirm-slug" data-buffer="1000" data-force-reload="/admin/">Purge Instance</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
13
internal/dis/component/server/admin/html/instance_purge.html
Normal file
13
internal/dis/component/server/admin/html/instance_purge.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<div class="pure-u-1-1">
|
||||
<p>
|
||||
Purging this instance completely removes it from the distillery.
|
||||
Backups containing the instance will remain, but it will not be possible to restore it directly.
|
||||
You must enter the slug <code>{{ .Instance.Slug }}</code> to confirm purging.
|
||||
</p>
|
||||
<form class="pure-form">
|
||||
<fieldset>
|
||||
<input type="text" id="purge-confirm-slug" placeholder="{{ .Instance.Slug }}" />
|
||||
<button class="remote-action pure-button pure-button-danger" data-action="purge" data-param="{{ .Instance.Slug }}" data-confirm-param="#purge-confirm-slug" data-buffer="1000" data-force-reload="/admin/">Purge Instance</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
|
@ -79,6 +79,7 @@ func (admin *Admin) instanceTabs(slug string, active string) templating.FlagFunc
|
|||
{Title: "Overview", Path: template.URL("/admin/instance/" + slug), Active: active == "overview"},
|
||||
{Title: "Rebuild", Path: template.URL("/admin/instance/" + slug + "/rebuild"), Active: active == "rebuild"},
|
||||
{Title: "Users & Grants", Path: template.URL("/admin/instance/" + slug + "/users"), Active: active == "users"},
|
||||
{Title: "Purge", Path: template.URL("/admin/instance/" + slug + "/purge"), Active: active == "purge"},
|
||||
|
||||
// TODO: These still need to be migrated to their own tabs
|
||||
// Then we also need to redo the main page
|
||||
|
|
@ -90,7 +91,6 @@ func (admin *Admin) instanceTabs(slug string, active string) templating.FlagFunc
|
|||
{Title: "Stats", Path: template.URL("/instance/" + slug + "/stats"), Active: active == "stats"},
|
||||
{Title: "SSH", Path: template.URL("/instance/" + slug + "/ssh"), Active: active == "ssh"},
|
||||
{Title: "Snapshots", Path: template.URL("/instance/" + slug + "/snapshots"), Active: active == "snapshots"},
|
||||
{Title: "Danger Zone", Path: template.URL("/instance/" + slug + "/danger"), Active: active == "danger"},
|
||||
*/
|
||||
}
|
||||
return flags
|
||||
|
|
|
|||
59
internal/dis/component/server/admin/instance_purge.go
Normal file
59
internal/dis/component/server/admin/instance_purge.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"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/wisski"
|
||||
"github.com/tkw1536/pkglib/httpx"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
//go:embed "html/instance_purge.html"
|
||||
var instancePurgeHTML []byte
|
||||
var instancePurgeTemplate = templating.Parse[instancePurgeContext](
|
||||
"instance_purge.html", instancePurgeHTML, nil,
|
||||
|
||||
templating.Assets(assets.AssetsAdmin),
|
||||
)
|
||||
|
||||
type instancePurgeContext struct {
|
||||
templating.RuntimeFlags
|
||||
|
||||
Instance *wisski.WissKI
|
||||
}
|
||||
|
||||
func (admin *Admin) instancePurge(ctx context.Context) http.Handler {
|
||||
tpl := instancePurgeTemplate.Prepare(
|
||||
admin.dependencies.Templating,
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuInstances,
|
||||
menuInstance,
|
||||
menuPurge,
|
||||
),
|
||||
)
|
||||
|
||||
return tpl.HTMLHandlerWithFlags(func(r *http.Request) (ctx instancePurgeContext, funcs []templating.FlagFunc, err error) {
|
||||
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
||||
|
||||
// setup the context with just the instance
|
||||
ctx.Instance, err = admin.dependencies.Instances.WissKI(r.Context(), slug)
|
||||
if err != nil {
|
||||
return ctx, nil, httpx.ErrNotFound
|
||||
}
|
||||
|
||||
return ctx, []templating.FlagFunc{
|
||||
templating.ReplaceCrumb(menuInstance, component.MenuItem{Title: "Instance", Path: template.URL("/admin/instance/" + ctx.Instance.Slug)}),
|
||||
templating.ReplaceCrumb(menuPurge, component.MenuItem{Title: "Purge", Path: template.URL("/admin/instance/" + ctx.Instance.Slug + "/purge")}),
|
||||
templating.Title(ctx.Instance.Slug + " - Purge"),
|
||||
admin.instanceTabs(slug, "purge"),
|
||||
}, nil
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue