put admin controls in its own accordion with position: fixed

This commit is contained in:
Iris Lightshard 2023-05-14 22:57:18 -06:00
parent 7ad9d76f78
commit 8836d10d88
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
3 changed files with 29 additions and 12 deletions

View file

@ -150,7 +150,7 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
return http.HandlerFunc(handlerFunc)
}
func apiUploadImg(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploads, uploadType string, uploadMax int) http.Handler {
func apiUploadImg(next http.Handler, dbAdapter mongodb.DbAdapter, uploads, uploadType string, uploadMax int) http.Handler {
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
// get table from request body
r, err := req.MultipartReader()
@ -218,12 +218,6 @@ func apiUploadImg(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAda
dest.Write(fileData)
dest.Close()
err = dbAdapter.SetMapImageUrl(tableKey, "/uploads/"+tableKey.Name+"/"+uploadType+"/"+header.Filename)
if err != nil {
w.WriteHeader(500)
next.ServeHTTP(w, req)
return
}
// respond with URL so UI can update
AddContextValue(req, "location", "/uploads/"+tableKey.Name+"/"+uploadType+"/"+header.Filename)
next.ServeHTTP(w, req)
@ -259,6 +253,16 @@ func apiListImages(next http.Handler, uploads string, uploadType string) http.Ha
return http.HandlerFunc(handlerFunc)
}
func apiDeleteImage(next http.Handler, uploads string, uploadType string) http.Handler {
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
// put the path together
// if the file exists, delete it and return the deleted path
// otherwise, return an error
}
return http.HandlerFunc(handlerFunc)
}
func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploads string, uploadMaxMB int) http.Handler {
// create quartzgun router
rtr := &router.Router{Fallback: *template.Must(template.ParseFiles("static/error.html"))}
@ -274,11 +278,12 @@ func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploa
rtr.Delete(`/api/table/(?P<Slug>\S+)`, Validate(apiDestroyTable(renderer.JSON("result"), udb, dbAdapter), udb, scopes))
// asset management
rtr.Post(`/api/upload/(?P<Slug>\S+)/map/`, Validate(apiUploadImg(renderer.JSON("location"), udb, dbAdapter, uploads, "map", uploadMaxMB), udb, scopes))
rtr.Post(`/api/upload/(?P<Slug>\S+)/map/`, Validate(apiUploadImg(renderer.JSON("location"), dbAdapter, uploads, "map", uploadMaxMB), udb, scopes))
// GET /api/upload/<table>/map/
rtr.Get(`/api/upload/(?P<Slug>\S+)/map/`, Validate(apiListImages(renderer.JSON("files"), uploads, "map"), udb, scopes))
// DELETE /api/upload/<table>/map/<map>
rtr.Post(`/api/upload/(?P<Slug>\S+)/token/`, Validate(apiUploadImg(renderer.JSON("location"), udb, dbAdapter, uploads, "token", uploadMaxMB), udb, scopes))
rtr.Post(`/api/upload/(?P<Slug>\S+)/token/`, Validate(apiUploadImg(renderer.JSON("location"), dbAdapter, uploads, "token", uploadMaxMB), udb, scopes))
rtr.Get(`/api/upload/(?P<Slug>\S+)/token/`, Validate(apiListImages(renderer.JSON("files"), uploads, "token"), udb, scopes))
// DELETE /api/upload/<table>/token/<token>
return http.HandlerFunc(rtr.ServeHTTP)

View file

@ -60,8 +60,7 @@
<div id="aux"></div>
<div id="map"></div>
</main>
<div id="adminWrapper" style="display:none;">
<div id="adminCtrl">
<details id="adminWrapper" style="display:none;"><summary>admin</summary>
<button onclick="setTableCreateFormVisible(true)">New Table</button>
<form onsubmit="return false" id="createTableForm" style="display:none;">
<input id="newTableName"/>
@ -71,7 +70,7 @@
</form>
</div>
<div id="adminZone"></div>
</div>
</details>
</body>
<script src="./util.js" type="text/javascript"></script>
<script src="./socket.js" type="text/javascript"></script>

View file

@ -87,3 +87,16 @@ button:hover {
width: auto;
border: solid 1px dimgray;
}
#adminWrapper {
position: fixed;
top: 2em;
right: 0;
padding: 1em;
border: solid 1px #fff;
background: rgba(0,0,0,0.8);
color: #fff;
box-sizing: border-box;
max-height: calc(100vh - 4em);
overflow-y: auto;
}