UI to attach
parent
47d6c37819
commit
d408229ba9
|
|
@ -166,6 +166,14 @@ const defaultWrapper = `
|
||||||
.comment:focus-within {
|
.comment:focus-within {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
}
|
}
|
||||||
|
.attachments > details > form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.attachments > details > form > input:first-of-type {
|
||||||
|
flex-grow: 2;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</header>
|
</header>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"local/notes-server/filetree"
|
"local/notes-server/filetree"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) notes(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) notes(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -49,13 +50,15 @@ func (s *Server) file(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fileHead(w, filetree.NewPathFromURL(r.URL.Path).BaseHREF)
|
s.fileHead(w, r.URL.Path)
|
||||||
fmt.Fprintln(w, file)
|
fmt.Fprintln(w, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileHead(w http.ResponseWriter, baseHREF string) {
|
func (s *Server) fileHead(w http.ResponseWriter, path string) {
|
||||||
|
baseHREF := filetree.NewPathFromURL(path).BaseHREF
|
||||||
htmlEdit(w, baseHREF)
|
htmlEdit(w, baseHREF)
|
||||||
htmlDelete(w, baseHREF)
|
htmlDelete(w, baseHREF)
|
||||||
|
s.htmlAttachments(w, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func htmlEdit(w http.ResponseWriter, baseHREF string) {
|
func htmlEdit(w http.ResponseWriter, baseHREF string) {
|
||||||
|
|
@ -76,6 +79,32 @@ func htmlDelete(w http.ResponseWriter, baseHREF string) {
|
||||||
</div><br>`, path.Join("/delete/", baseHREF))
|
</div><br>`, path.Join("/delete/", baseHREF))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) htmlAttachments(w http.ResponseWriter, urlPath string) {
|
||||||
|
dir := path.Dir(urlPath)
|
||||||
|
f := "." + path.Base(urlPath) + ".attachments"
|
||||||
|
_, files, _ := s.Notes.Dir(path.Join(dir, f))
|
||||||
|
//<!-- TODO READONELY -->
|
||||||
|
//style="min-width: 2em; text-align: center; padding: 0; margin-top: 0; margin-bottom: 0;"/>
|
||||||
|
form := fmt.Sprintf(`
|
||||||
|
<form enctype="multipart/form-data" action="/attach/%s" method="post">
|
||||||
|
<input type="file" name="file" required/>
|
||||||
|
<input type="submit" value="+"/>
|
||||||
|
</form>
|
||||||
|
`, strings.TrimPrefix(urlPath, "/"))
|
||||||
|
if config.ReadOnly {
|
||||||
|
form = ""
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, `<div style='display:inline-block' class="attachments">
|
||||||
|
<details>
|
||||||
|
<summary style="display: flex">
|
||||||
|
<span style="flex-grow: 2">Attachments</span>
|
||||||
|
</summary>
|
||||||
|
%s
|
||||||
|
%s
|
||||||
|
</details>
|
||||||
|
</div><br>`, form, files)
|
||||||
|
}
|
||||||
|
|
||||||
func htmlCreate(w http.ResponseWriter, baseHREF string) {
|
func htmlCreate(w http.ResponseWriter, baseHREF string) {
|
||||||
if config.ReadOnly {
|
if config.ReadOnly {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue