editor technically works
parent
0e1ced34b2
commit
701ba9c48f
|
|
@ -222,17 +222,57 @@ func (server *Server) uiSearchHandler(w http.ResponseWriter, r *http.Request) er
|
|||
data[i].ID = idsTitles[i][0]
|
||||
data[i].Title = idsTitles[i][1]
|
||||
}
|
||||
log.Printf("ui search: %v", data)
|
||||
return t.Lookup("search").Execute(w, map[string]interface{}{"Results": data})
|
||||
}
|
||||
|
||||
func (server *Server) uiFilesHandler(w http.ResponseWriter, r *http.Request) error {
|
||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/ui/files")
|
||||
id := strings.Split(strings.TrimPrefix(r.URL.Path, "/"), "/")
|
||||
if len(id) == 0 || (len(id) == 1 && id[0] == "") {
|
||||
return server.rootHandler(w, r)
|
||||
}
|
||||
t, err := server.uiSubTemplates()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return t.Lookup("files").Execute(w, "TODO data")
|
||||
t, err = t.ParseFiles(path.Join(server.root, "ui", "files.ctmpl"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tree := server.tree()
|
||||
branches, err := tree.GetRootMeta()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
branchesJSON, err := json.Marshal(branches)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var parent Leaf
|
||||
if len(id) > 1 {
|
||||
parent, err = tree.Get(id[:len(id)-1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
leaf, err := tree.Get(id)
|
||||
if err != nil {
|
||||
if len(id) > 1 && parent.Title == "" {
|
||||
return err
|
||||
}
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"This": map[string]string{
|
||||
"Title": leaf.Title,
|
||||
"Content": leaf.Content,
|
||||
"ID": r.URL.Path,
|
||||
"PID": path.Dir(r.URL.Path),
|
||||
"PTitle": parent.Title,
|
||||
},
|
||||
"Tree": string(branchesJSON),
|
||||
}
|
||||
log.Printf("%v => %+v", id, data)
|
||||
return t.Lookup("files").Execute(w, data)
|
||||
}
|
||||
|
||||
func (server *Server) uiSubTemplates() (*template.Template, error) {
|
||||
|
|
@ -263,7 +303,7 @@ func (server *Server) uiSubTemplates() (*template.Template, error) {
|
|||
}
|
||||
|
||||
func (server *Server) rootHandler(w http.ResponseWriter, r *http.Request) error {
|
||||
http.Redirect(w, r, "/ui/files", 301)
|
||||
http.Redirect(w, r, "/ui/files/"+uuid.New().String()[:5], 301)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
todo:
|
||||
- do not rewrite .md title vs. link cause hrefs to ./gobs.md wont work
|
||||
- https://codepen.io/bisserof/pen/nrMveb
|
||||
- breadcrumb; https://concisecss.com/documentation/ui
|
||||
- alert box; https://concisecss.com/documentation/ui
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
function pushFile() {
|
||||
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
|
||||
const body = easyMDE.value() ? easyMDE.value() : ""
|
||||
const id = easyMDE.meta.id ? easyMDE.meta.id : ""
|
||||
const id = window.location.pathname.includes("/ui/files/") ? window.location.pathname.split("/ui/files/")[1] : ""
|
||||
headers = {}
|
||||
if (title)
|
||||
headers["Title"] = title
|
||||
|
|
@ -52,8 +52,6 @@
|
|||
alert(`failed to push file ${id}: ${status}: ${body}`)
|
||||
throw `failed to push file ${id}: ${status}: ${body}`
|
||||
}
|
||||
drawTree()
|
||||
//drawFile(id)
|
||||
document.getElementById("saveFeedback").innerHTML = "success!"
|
||||
if (saveFeedbackInterval) {
|
||||
clearTimeout(saveFeedbackInterval)
|
||||
|
|
|
|||
|
|
@ -76,4 +76,23 @@
|
|||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function http(method, remote, callback, body, headers) {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
||||
callback(xmlhttp.responseText, xmlhttp.status, (key) => xmlhttp.getResponseHeader(key))
|
||||
}
|
||||
};
|
||||
xmlhttp.open(method, remote, true);
|
||||
if (typeof body == "undefined") {
|
||||
body = null
|
||||
}
|
||||
if (headers) {
|
||||
for (var key in headers)
|
||||
xmlhttp.setRequestHeader(key, headers[key])
|
||||
}
|
||||
xmlhttp.send(body);
|
||||
}
|
||||
</script>
|
||||
{{ end }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue