wip
parent
24acc02dc7
commit
09532849d4
|
|
@ -200,7 +200,6 @@ func (server *Server) putContentHandler(filePath string, w http.ResponseWriter,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) uiSearchHandler(w http.ResponseWriter, r *http.Request) error {
|
func (server *Server) uiSearchHandler(w http.ResponseWriter, r *http.Request) error {
|
||||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/ui/files")
|
|
||||||
t, err := server.uiSubTemplates()
|
t, err := server.uiSubTemplates()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -261,11 +260,11 @@ func (server *Server) uiFilesHandler(w http.ResponseWriter, r *http.Request) err
|
||||||
leaf.Title = "My New File"
|
leaf.Title = "My New File"
|
||||||
}
|
}
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"This": map[string]string{
|
"This": map[string]interface{}{
|
||||||
"Title": leaf.Title,
|
"Title": leaf.Title,
|
||||||
"Content": leaf.Content,
|
"Content": leaf.Content,
|
||||||
"ID": r.URL.Path,
|
"ID": id,
|
||||||
"PID": strings.TrimPrefix(path.Dir(r.URL.Path), "/"),
|
"PID": id.Pop(),
|
||||||
"PTitle": parent.Title,
|
"PTitle": parent.Title,
|
||||||
},
|
},
|
||||||
"Tree": string(branchesJSON),
|
"Tree": string(branchesJSON),
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
return `
|
return `
|
||||||
<div style="margin: 0; padding: 0; height: 0; width: 0;" id="${name}"></div>
|
<div style="margin: 0; padding: 0; height: 0; width: 0;" id="${name}"></div>
|
||||||
<a style="flex-grow: 1;" href="${href}#${parentname}"><button style="width: 100%; text-align: left; outline: none;">${title}</button></a>
|
<a style="flex-grow: 1;" href="${href}#${parentname}"><button style="width: 100%; text-align: left; outline: none;">${title}</button></a>
|
||||||
<a href="${href}/${crypto.randomUUID().split("-")[0]}#${parentname}"><button>+</button></a>
|
<a href="${href}/${generateUUID().split("-")[0]}#${parentname}"><button>+</button></a>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
function branchesHTML(id, branches) {
|
function branchesHTML(id, branches) {
|
||||||
|
|
@ -54,7 +54,7 @@
|
||||||
var out = ``
|
var out = ``
|
||||||
for(var i in branches) {
|
for(var i in branches) {
|
||||||
out += `<details open>`
|
out += `<details open>`
|
||||||
out += branchHTML((id ? id + "/" : "") + i, branches[i])
|
out += branchHTML(i, branches[i])
|
||||||
out += `</details>`
|
out += `</details>`
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
@ -65,6 +65,6 @@
|
||||||
n += 1
|
n += 1
|
||||||
return n > 0
|
return n > 0
|
||||||
}
|
}
|
||||||
drawTree(JSON.parse(`{{ .Tree }}`))
|
drawTree(JSON.parse({{ .Tree }}))
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
||||||
|
|
@ -94,5 +94,21 @@
|
||||||
}
|
}
|
||||||
xmlhttp.send(body);
|
xmlhttp.send(body);
|
||||||
}
|
}
|
||||||
|
function generateUUID() { // Public Domain/MIT // https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid
|
||||||
|
var d = new Date().getTime();//Timestamp
|
||||||
|
var d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now()*1000)) || 0;//Time in microseconds since page-load or 0 if unsupported
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||||
|
var r = Math.random() * 16;//random number between 0 and 16
|
||||||
|
if(d > 0){//Use timestamp until depleted
|
||||||
|
r = (d + r)%16 | 0;
|
||||||
|
d = Math.floor(d/16);
|
||||||
|
} else {//Use microseconds since page-load if supported
|
||||||
|
r = (d2 + r)%16 | 0;
|
||||||
|
d2 = Math.floor(d2/16);
|
||||||
|
}
|
||||||
|
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue