draw new file button stubbed

master
Bel LaPointe 2022-02-08 17:01:07 -07:00
parent 867da930a4
commit 7b51fd077d
1 changed files with 26 additions and 18 deletions

View File

@ -35,11 +35,7 @@
<script> <script>
function init() { function init() {
drawTree() drawTree()
function drawTreeLoop() { setInterval(drawTree, 10000)
drawTree()
setInterval(drawTreeLoop, 10000)
}
drawTreeLoop()
var queryF = getParameterByName("f") var queryF = getParameterByName("f")
console.log("init query f:", queryF) console.log("init query f:", queryF)
if (queryF && queryF.length != "") { if (queryF && queryF.length != "") {
@ -62,26 +58,38 @@
if (status != 200) { if (status != 200) {
throw Exception(`ERR loading file: ${status}: ${body}`) throw Exception(`ERR loading file: ${status}: ${body}`)
} }
const pid = headers("pid") const pid = headers("pid") ? headers("pid") : ""
document.getElementById("titlePath").innerHTML = `${pid ? "... / " : ""}<a href="#?f=${pid ? pid : ""}"><input type="button" value="${pid ? pid : ""}" onclick="drawFile('${pid}');"></a> / ` const title = headers("title") ? headers("title") : ""
if (!pid) { setMDE(id, pid, title, body)
document.getElementById("titlePath").innerHTML = "/"
}
document.getElementById("title").innerHTML = headers("title")
easyMDE.value(body)
}) })
} }
function drawNewFile(pid) {
setMDE("", pid, "", "")
}
function setMDE(id, pid, title, body) {
console.log(`set MDE: id=${id}, pid=${pid}, title=${title}, body=${body}`)
document.getElementById("titlePath").innerHTML = `${pid ? "... / " : ""}<a href="#?f=${pid}"><input type="button" value="${pid}" onclick="drawFile('${pid}');"></a> / `
if (pid == "") {
document.getElementById("titlePath").innerHTML = "/"
}
document.getElementById("title").innerHTML = title
easyMDE.value(body)
easyMDE.meta = {
id: id,
pid: pid,
}
}
function drawTree() { function drawTree() {
function htmlifyBranch(id, branch) { function htmlifyBranch(pid, id, branch) {
var children = "" var children = ""
for (var child in branch.Children) for (var child in branch.Children)
children += "\n" + htmlifyBranch(child, branch.Children[child]) children += "\n" + htmlifyBranch(id, child, branch.Children[child])
return ` return `
<details open> <details open>
<summary> <summary>
<div> <div>
<a href="#?f=${id}"><input type="button" value="${branch.Title}" onclick="drawFile('${id}');"/></a> <a href="#?f=${id}"><input type="button" value="${branch.Title}" onclick="drawFile('${id}');"/></a>
<input type="button" value="+" onclick="alert('todo'); return false;"/> <input type="button" value="+" onclick="drawNewFile('${id}');"/>
</div> </div>
</summary> </summary>
${children} ${children}
@ -92,9 +100,9 @@
const tree = JSON.parse(body) const tree = JSON.parse(body)
var innerHTML = "" var innerHTML = ""
for(var id in tree) { for(var id in tree) {
innerHTML += htmlifyBranch(id, tree[id]) innerHTML += htmlifyBranch("", id, tree[id])
} }
innerHTML = htmlifyBranch("", { innerHTML = htmlifyBranch("", "", {
Title: "Files", Title: "Files",
Children: {}, Children: {},
}).replace("</summary>", "</summary>"+innerHTML) }).replace("</summary>", "</summary>"+innerHTML)
@ -119,7 +127,7 @@
<body style="width: 90%; max-width: 1024px; margin: auto;" onload="init(); return false;"> <body style="width: 90%; max-width: 1024px; margin: auto;" onload="init(); return false;">
<div style="width: 100%; display: flex; flex-direction: column;"> <div style="width: 100%; display: flex; flex-direction: column;">
<div style="margin: 1em; display: flex; flex-direction: row;"> <div style="margin: 1em; display: flex; flex-direction: row;">
<input type="text" style="flex-grow: 1;" placeholder="not impl"/> <input type="text" style="flex-grow: 1;" placeholder="todo"/>
<input type="submit" value="search"/> <input type="submit" value="search"/>
</div> </div>
<div style="width: 100%; display: flex; flex-direction: row; flex-grow: 1;"> <div style="width: 100%; display: flex; flex-direction: row; flex-grow: 1;">