UI to attach

master
Bel LaPointe 2021-02-25 16:43:32 -06:00
parent 47d6c37819
commit d408229ba9
2 changed files with 39 additions and 2 deletions

View File

@ -166,6 +166,14 @@ const defaultWrapper = `
.comment:focus-within {
display: inline-flex;
}
.attachments > details > form {
display: flex;
flex-direction: row;
width: 100%;
}
.attachments > details > form > input:first-of-type {
flex-grow: 2;
}
</style>
</header>
<body>

View File

@ -6,6 +6,7 @@ import (
"local/notes-server/filetree"
"net/http"
"path"
"strings"
)
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)
return
}
fileHead(w, filetree.NewPathFromURL(r.URL.Path).BaseHREF)
s.fileHead(w, r.URL.Path)
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)
htmlDelete(w, baseHREF)
s.htmlAttachments(w, path)
}
func htmlEdit(w http.ResponseWriter, baseHREF string) {
@ -76,6 +79,32 @@ func htmlDelete(w http.ResponseWriter, baseHREF string) {
</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) {
if config.ReadOnly {
return