add an emu peeker to the honkform. from petersanchez, adapted to new csp rules
Ted Unangst tedu@tedunangst.com
Thu, 26 Jan 2023 16:27:11 -0500
4 files changed,
70 insertions(+),
0 deletions(-)
M
views/honkform.html
→
views/honkform.html
@@ -37,6 +37,14 @@ <input type="text" name="timestart" value="{{ .StartTime }}">
<p><label for=timeend>duration:</label><br> <input type="text" name="timeend" value="{{ .Duration }}"> </div> +<svg class="emuload" id="emuload" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-mood-neutral" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> +<path stroke="none" d="M0 0h24v24H0z" fill="none"></path> +<circle cx="12" cy="12" r="9"></circle> +<line x1="9" y1="10" x2="9.01" y2="10"></line> +<line x1="15" y1="10" x2="15.01" y2="10"></line> +</svg> +<div id="emupicker"> +</div> </details> <p> <textarea name="noise" id="honknoise">{{ .Noise }}</textarea>
M
views/honkpage.js
→
views/honkpage.js
@@ -446,6 +446,24 @@ makeaguess = module.makeaguess
module.addguesscontrols(elem, word, wordlist, xid) }) } +function addemu(data){ + const box = document.getElementById("honknoise"); + box.value += data; +} +function loademus() { + div = document.getElementById("emupicker") + request = new XMLHttpRequest(); + request.open('GET', '/emus') + request.onload = function(){ + div.innerHTML = request.responseText + } + if (div.style.display === "none") { + div.style.display = "block"; + } else { + div.style.display = "none"; + } + request.send() +} // init (function() {@@ -490,6 +508,7 @@ document.getElementById("honkingtime").onclick = function() {
return showhonkform() } document.getElementById("checkinbutton").onclick = fillcheckin + document.getElementById("emuload").onclick = loademus document.querySelector("#donker input").onchange = updatedonker document.querySelector("button[name=cancel]").onclick = cancelhonking })();
M
views/style.css
→
views/style.css
@@ -253,6 +253,11 @@
.honk details.actions summary { color: var(--fg-subtle); } + +#emupicker{height:300px;overflow-y:scroll;padding:3px;background:var(--bg-dark);border:solid 5px var(--fg-subtle);text-align:center;display:none;} +#emupicker img{margin:0;} +.emuload{background:var(--bg-page);padding:0.5em;} + .subtle .noise { color: var(--fg-subtle); font-size: 0.8em;
M
web.go
→
web.go
@@ -50,6 +50,8 @@ var honkSep = "h"
var develMode = false +var allemus []Emu + func getuserstyle(u *login.UserInfo) template.HTMLAttr { if u == nil { return ""@@ -147,6 +149,15 @@ templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
} honkpage(w, u, honks, templinfo) +} + +func showemus(w http.ResponseWriter, r *http.Request) { + templinfo := getInfo(r) + templinfo["Emus"] = allemus + err := readviews.Execute(w, "emus.html", templinfo) + if err != nil { + elog.Print(err) + } } func showfunzone(w http.ResponseWriter, r *http.Request) {@@ -2422,6 +2433,30 @@ next.ServeHTTP(w, r)
}) } +func emuinit() { + var emunames []string + dir, err := os.Open(dataDir + "/emus") + if err == nil { + emunames, _ = dir.Readdirnames(0) + dir.Close() + } + for _, e := range emunames { + if len(e) <= 4 { + continue + } + ext := e[len(e)-4:] + emu := Emu{ + ID: fmt.Sprintf("/emu/%s", e), + Name: e[:len(e)-4], + Type: "image/" + ext[1:], + } + allemus = append(allemus, emu) + } + sort.Slice(allemus, func(i, j int) bool { + return allemus[i].Name < allemus[j].Name + }) +} + func serve() { db := opendatabase() login.Init(login.InitArgs{Db: db, Logger: ilog, Insecure: develMode, SameSiteStrict: !develMode})@@ -2436,6 +2471,7 @@ go redeliverator()
go tracker() go bgmonitor() loadLingo() + emuinit() readviews = templates.Load(develMode, viewDir+"/views/honkpage.html",@@ -2454,6 +2490,7 @@ viewDir+"/views/xzone.html",
viewDir+"/views/msg.html", viewDir+"/views/header.html", viewDir+"/views/onts.html", + viewDir+"/views/emus.html", viewDir+"/views/honkpage.js", ) if !develMode {@@ -2555,6 +2592,7 @@ loggedin.HandleFunc("/c", showcombos)
loggedin.HandleFunc("/t", showconvoy) loggedin.HandleFunc("/q", showsearch) loggedin.HandleFunc("/hydra", webhydra) + loggedin.HandleFunc("/emus", showemus) loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker))) err = http.Serve(listener, mux)