add an emu peeker to the honkform.

from petersanchez, adapted to new csp rules
This commit is contained in:
Ted Unangst 2023-01-26 16:27:11 -05:00
parent 2983156e4b
commit 455989f85b
4 changed files with 70 additions and 0 deletions

View File

@ -37,6 +37,14 @@
<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>

View File

@ -446,6 +446,24 @@ function playit(elem, word, wordlist, xid) {
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 @@ function playit(elem, word, wordlist, xid) {
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
})();

View File

@ -253,6 +253,11 @@ input[type=file] {
.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;

38
web.go
View File

@ -50,6 +50,8 @@ var honkSep = "h"
var develMode = false
var allemus []Emu
func getuserstyle(u *login.UserInfo) template.HTMLAttr {
if u == nil {
return ""
@ -149,6 +151,15 @@ func homepage(w http.ResponseWriter, r *http.Request) {
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) {
var emunames, memenames []string
emuext := make(map[string]string)
@ -2422,6 +2433,30 @@ func addcspheaders(next http.Handler) http.Handler {
})
}
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 @@ func serve() {
go tracker()
go bgmonitor()
loadLingo()
emuinit()
readviews = templates.Load(develMode,
viewDir+"/views/honkpage.html",
@ -2454,6 +2490,7 @@ func serve() {
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 @@ func serve() {
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)