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: nilix
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) 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) { handlerFunc := func(w http.ResponseWriter, req *http.Request) {
// get table from request body // get table from request body
r, err := req.MultipartReader() r, err := req.MultipartReader()
@ -218,12 +218,6 @@ func apiUploadImg(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAda
dest.Write(fileData) dest.Write(fileData)
dest.Close() 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 // respond with URL so UI can update
AddContextValue(req, "location", "/uploads/"+tableKey.Name+"/"+uploadType+"/"+header.Filename) AddContextValue(req, "location", "/uploads/"+tableKey.Name+"/"+uploadType+"/"+header.Filename)
next.ServeHTTP(w, req) next.ServeHTTP(w, req)
@ -259,6 +253,16 @@ func apiListImages(next http.Handler, uploads string, uploadType string) http.Ha
return http.HandlerFunc(handlerFunc) 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 { func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploads string, uploadMaxMB int) http.Handler {
// create quartzgun router // create quartzgun router
rtr := &router.Router{Fallback: *template.Must(template.ParseFiles("static/error.html"))} 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)) rtr.Delete(`/api/table/(?P<Slug>\S+)`, Validate(apiDestroyTable(renderer.JSON("result"), udb, dbAdapter), udb, scopes))
// asset management // 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/ // GET /api/upload/<table>/map/
rtr.Get(`/api/upload/(?P<Slug>\S+)/map/`, Validate(apiListImages(renderer.JSON("files"), uploads, "map"), udb, scopes)) rtr.Get(`/api/upload/(?P<Slug>\S+)/map/`, Validate(apiListImages(renderer.JSON("files"), uploads, "map"), udb, scopes))
// DELETE /api/upload/<table>/map/<map> // 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> // DELETE /api/upload/<table>/token/<token>
return http.HandlerFunc(rtr.ServeHTTP) return http.HandlerFunc(rtr.ServeHTTP)

View file

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

View file

@ -86,4 +86,17 @@ button:hover {
height: auto; height: auto;
width: auto; width: auto;
border: solid 1px dimgray; 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;
} }