Move snapshots to separate page
This commit is contained in:
parent
a43ada586d
commit
ff92df3a87
5 changed files with 109 additions and 36 deletions
|
|
@ -74,6 +74,7 @@ var (
|
||||||
menuRebuild = component.DummyMenuItem()
|
menuRebuild = component.DummyMenuItem()
|
||||||
menuGrants = component.DummyMenuItem()
|
menuGrants = component.DummyMenuItem()
|
||||||
menuPurge = component.DummyMenuItem()
|
menuPurge = component.DummyMenuItem()
|
||||||
|
menuSnapshots = component.DummyMenuItem()
|
||||||
)
|
)
|
||||||
|
|
||||||
func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http.Handler, err error) {
|
func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http.Handler, err error) {
|
||||||
|
|
@ -139,6 +140,11 @@ func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http
|
||||||
router.Handler(http.MethodGet, route+"instance/:slug/purge", purge)
|
router.Handler(http.MethodGet, route+"instance/:slug/purge", purge)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
snapshots := admin.instanceSnapshots(ctx)
|
||||||
|
router.Handler(http.MethodGet, route+"instance/:slug/snapshots", snapshots)
|
||||||
|
}
|
||||||
|
|
||||||
// add a router for the login page
|
// add a router for the login page
|
||||||
router.Handler(http.MethodPost, route+"login", admin.loginHandler(ctx))
|
router.Handler(http.MethodPost, route+"login", admin.loginHandler(ctx))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
<a class="pure-button pure-button-small" href="#wisski">WissKI Data</a>
|
<a class="pure-button pure-button-small" href="#wisski">WissKI Data</a>
|
||||||
<a class="pure-button pure-button-small" href="#stats">Statistics</a>
|
<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="#ssh">SSH Keys</a>
|
||||||
<a class="pure-button pure-button-small" href="#snapshots">Snapshots</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -514,37 +513,3 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pure-u-1-1">
|
|
||||||
<h2 id="snapshots">Snapshots</h2>
|
|
||||||
<p>
|
|
||||||
<button class="remote-action pure-button pure-button-action" data-action="snapshot" data-param="{{ .Instance.Slug }}" data-buffer="1000" data-force-reload>Take a snapshot</button>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="pure-u-1">
|
|
||||||
<table class="pure-table pure-table-bordered padding">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Path</th>
|
|
||||||
<th>Created</th>
|
|
||||||
<th>Packed</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{{ range .Info.Snapshots }}
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<code class="path">{{ .Path }}</code>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<code class="date">{{ .Created.Format "2006-01-02T15:04:05Z07:00" }}</code>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ .Packed }}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{ end}}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
<div class="pure-u-1-1">
|
||||||
|
<p>
|
||||||
|
Taking a snapshot makes a backup of the entire instance, including triplestore and graph database.
|
||||||
|
Currently snapshot can only be accessed on the server filesystem.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<button class="remote-action pure-button pure-button-action" data-action="snapshot" data-param="{{ .Instance.Slug }}" data-buffer="1000" data-force-reload>Take a snapshot</button>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pure-u-1">
|
||||||
|
<table class="pure-table pure-table-bordered padding">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Path</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Packed</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{ range .Snapshots }}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<code class="path">{{ .Path }}</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<code class="date">{{ .Created.Format "2006-01-02T15:04:05Z07:00" }}</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ .Packed }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{ end}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</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: "Overview", Path: template.URL("/admin/instance/" + slug), Active: active == "overview"},
|
||||||
{Title: "Rebuild", Path: template.URL("/admin/instance/" + slug + "/rebuild"), Active: active == "rebuild"},
|
{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: "Users & Grants", Path: template.URL("/admin/instance/" + slug + "/users"), Active: active == "users"},
|
||||||
|
{Title: "Snapshots", Path: template.URL("/admin/instance/" + slug + "/snapshots"), Active: active == "snapshots"},
|
||||||
{Title: "Purge", Path: template.URL("/admin/instance/" + slug + "/purge"), Active: active == "purge"},
|
{Title: "Purge", Path: template.URL("/admin/instance/" + slug + "/purge"), Active: active == "purge"},
|
||||||
|
|
||||||
// TODO: These still need to be migrated to their own tabs
|
// TODO: These still need to be migrated to their own tabs
|
||||||
|
|
@ -90,7 +91,6 @@ func (admin *Admin) instanceTabs(slug string, active string) templating.FlagFunc
|
||||||
{Title: "Users & Grants", Path: template.URL("/instance/" + slug + "/users"), Active: active == "users"},
|
{Title: "Users & Grants", Path: template.URL("/instance/" + slug + "/users"), Active: active == "users"},
|
||||||
{Title: "Stats", Path: template.URL("/instance/" + slug + "/stats"), Active: active == "stats"},
|
{Title: "Stats", Path: template.URL("/instance/" + slug + "/stats"), Active: active == "stats"},
|
||||||
{Title: "SSH", Path: template.URL("/instance/" + slug + "/ssh"), Active: active == "ssh"},
|
{Title: "SSH", Path: template.URL("/instance/" + slug + "/ssh"), Active: active == "ssh"},
|
||||||
{Title: "Snapshots", Path: template.URL("/instance/" + slug + "/snapshots"), Active: active == "snapshots"},
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
return flags
|
return flags
|
||||||
|
|
|
||||||
66
internal/dis/component/server/admin/instance_snapshots.go
Normal file
66
internal/dis/component/server/admin/instance_snapshots.go
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
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/models"
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||||
|
"github.com/tkw1536/pkglib/httpx"
|
||||||
|
|
||||||
|
"github.com/julienschmidt/httprouter"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed "html/instance_snapshots.html"
|
||||||
|
var instanceSnapshotsHTML []byte
|
||||||
|
var instanceSnapshotsTemplate = templating.Parse[instanceSnapshotsContext](
|
||||||
|
"instance_snapshots.html", instanceSnapshotsHTML, nil,
|
||||||
|
|
||||||
|
templating.Assets(assets.AssetsAdmin),
|
||||||
|
)
|
||||||
|
|
||||||
|
type instanceSnapshotsContext struct {
|
||||||
|
templating.RuntimeFlags
|
||||||
|
|
||||||
|
Instance *wisski.WissKI
|
||||||
|
Snapshots []models.Export
|
||||||
|
}
|
||||||
|
|
||||||
|
func (admin *Admin) instanceSnapshots(ctx context.Context) http.Handler {
|
||||||
|
tpl := instanceSnapshotsTemplate.Prepare(
|
||||||
|
admin.dependencies.Templating,
|
||||||
|
templating.Crumbs(
|
||||||
|
menuAdmin,
|
||||||
|
menuInstances,
|
||||||
|
menuInstance,
|
||||||
|
menuSnapshots,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
return tpl.HTMLHandlerWithFlags(func(r *http.Request) (ctx instanceSnapshotsContext, 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
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Snapshots, err = ctx.Instance.Snapshots(r.Context())
|
||||||
|
if err != nil {
|
||||||
|
return ctx, nil, httpx.ErrInternalServerError
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx, []templating.FlagFunc{
|
||||||
|
templating.ReplaceCrumb(menuInstance, component.MenuItem{Title: "Instance", Path: template.URL("/admin/instance/" + ctx.Instance.Slug)}),
|
||||||
|
templating.ReplaceCrumb(menuSnapshots, component.MenuItem{Title: "Snapshots", Path: template.URL("/admin/instance/" + ctx.Instance.Slug + "/snapshots")}),
|
||||||
|
templating.Title(ctx.Instance.Slug + " - Snapshots"),
|
||||||
|
admin.instanceTabs(slug, "snapshots"),
|
||||||
|
}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue