commit 7b656ff502698ca5f32d25c1fc12df9117449a90
parent 8abb76e057899a871c58fcc1740485b406a44233
Author: Peter <peter@minskio.co.uk>
Date: Mon, 16 Nov 2026 09:51:44 +0000
Move notes import/export to separate page
Diffstat:
6 files changed, 56 insertions(+), 23 deletions(-)
diff --git a/internal/app/notes.go b/internal/app/notes.go
@@ -7,6 +7,7 @@ import (
"io"
"log"
"net/http"
+ "net/url"
"os"
"os/exec"
"sort"
@@ -382,6 +383,21 @@ func notesPreviewHandler(w http.ResponseWriter, r *http.Request) {
})
}
+// notesImportExportHandler displays the notes import and export page
+func notesImportExportHandler(w http.ResponseWriter, r *http.Request) {
+ q := r.URL.Query()
+
+ pageData := buildPageData("Import and Export Notes", struct {
+ Success string
+ Error string
+ }{
+ Success: q.Get("success"),
+ Error: q.Get("error"),
+ })
+
+ renderTemplate(w, "notes-import-export.html", pageData)
+}
+
// notesExportHandler exports notes as plain text file
func notesExportHandler(w http.ResponseWriter, r *http.Request) {
content, err := GetNotes(DB)
@@ -440,5 +456,5 @@ func notesImportHandler(w http.ResponseWriter, r *http.Request) {
return
}
- http.Redirect(w, r, "/notes", http.StatusSeeOther)
+ http.Redirect(w, r, "/notes/import-export?success="+url.QueryEscape("Notes imported successfully!"), http.StatusSeeOther)
}
diff --git a/internal/app/routes.go b/internal/app/routes.go
@@ -27,6 +27,7 @@ func RegisterRoutes() {
http.HandleFunc("/notes/export", notesExportHandler)
http.HandleFunc("/notes/filter", notesFilterHandler)
http.HandleFunc("/notes/import", notesImportHandler)
+ http.HandleFunc("/notes/import-export", notesImportExportHandler)
http.HandleFunc("/notes/preview", notesPreviewHandler)
http.HandleFunc("/notes/save", notesSaveHandler)
http.HandleFunc("/notes/stats", notesStatsHandler)
diff --git a/static/notes.js b/static/notes.js
@@ -243,10 +243,6 @@ function clearFilters() {
updatePreview(currentContent);
}
-function exportNotes() {
- window.location.href = '/notes/export';
-}
-
// Warn on unsaved changes
window.addEventListener('beforeunload', (e) => {
if (editor.value !== originalContent) {
diff --git a/templates/_header.html b/templates/_header.html
@@ -45,7 +45,10 @@
</ul>
</li>{{end}}
</ul></li>
-<li><a href="/notes"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill="000000" d="M7.5 7a.5.5 0 0 0 0 1h5a.5.5 0 0 0 0-1zM7 10.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m.5 2.5a.5.5 0 0 0 0 1h2a.5.5 0 0 0 0-1zm-1-11a.5.5 0 0 0-.5.5V3h-.5A1.5 1.5 0 0 0 4 4.5v12A1.5 1.5 0 0 0 5.5 18h6a.5.5 0 0 0 .354-.146l4-4A.5.5 0 0 0 16 13.5v-9A1.5 1.5 0 0 0 14.5 3H14v-.5a.5.5 0 0 0-1 0V3h-2.5v-.5a.5.5 0 0 0-1 0V3H7v-.5a.5.5 0 0 0-.5-.5m8 2a.5.5 0 0 1 .5.5V13h-2.5a1.5 1.5 0 0 0-1.5 1.5V17H5.5a.5.5 0 0 1-.5-.5v-12a.5.5 0 0 1 .5-.5zm-.207 10L12 16.293V14.5a.5.5 0 0 1 .5-.5z"/></svg><span>Notes</span></a></li>
+<li><a href="/notes"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill="000000" d="M7.5 7a.5.5 0 0 0 0 1h5a.5.5 0 0 0 0-1zM7 10.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m.5 2.5a.5.5 0 0 0 0 1h2a.5.5 0 0 0 0-1zm-1-11a.5.5 0 0 0-.5.5V3h-.5A1.5 1.5 0 0 0 4 4.5v12A1.5 1.5 0 0 0 5.5 18h6a.5.5 0 0 0 .354-.146l4-4A.5.5 0 0 0 16 13.5v-9A1.5 1.5 0 0 0 14.5 3H14v-.5a.5.5 0 0 0-1 0V3h-2.5v-.5a.5.5 0 0 0-1 0V3H7v-.5a.5.5 0 0 0-.5-.5m8 2a.5.5 0 0 1 .5.5V13h-2.5a1.5 1.5 0 0 0-1.5 1.5V17H5.5a.5.5 0 0 1-.5-.5v-12a.5.5 0 0 1 .5-.5zm-.207 10L12 16.293V14.5a.5.5 0 0 1 .5-.5z"/></svg><span>Notes</span></a>
+ <ul class="sub-menu">
+ <li><a href="/notes/import-export">Import/Export</a></li>
+ </ul></li>
<li><a href="/admin/settings"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill="#000000" d="M9 6.5a4.5 4.5 0 0 1 6.352-4.102a.5.5 0 0 1 .148.809L13.207 5.5L14.5 6.793L16.793 4.5a.5.5 0 0 1 .809.147a4.5 4.5 0 0 1-5.207 6.216L6.03 17.311a2.357 2.357 0 0 1-3.374-3.293L9.082 7.36A4.52 4.52 0 0 1 9 6.5ZM13.5 3a3.5 3.5 0 0 0-3.387 4.386a.5.5 0 0 1-.125.473l-6.612 6.854a1.357 1.357 0 0 0 1.942 1.896l6.574-6.66a.5.5 0 0 1 .512-.124a3.5 3.5 0 0 0 4.521-4.044l-2.072 2.073a.5.5 0 0 1-.707 0l-2-2a.5.5 0 0 1 0-.708l2.073-2.072a3.518 3.518 0 0 0-.72-.074Z"/></svg><span>Admin</span></a>
<ul class="sub-menu">
<li><a href="/admin/settings">Settings</a></li>
diff --git a/templates/notes-import-export.html b/templates/notes-import-export.html
@@ -0,0 +1,34 @@
+{{template "_header" .}}
+<h1>Import and Export Notes</h1>
+
+{{if .Data.Error}}
+<div class="admin-alert admin-alert--error">
+ <strong>Error:</strong> {{.Data.Error}}
+</div>
+{{end}}
+
+{{if .Data.Success}}
+<div class="admin-alert admin-alert--success">
+ <strong>Success:</strong> {{.Data.Success}}
+</div>
+{{end}}
+
+<div class="import-form">
+ <h4 style="margin-bottom: 10px">Export Notes</h4>
+ <form action="/notes/export" method="GET">
+ <button type="submit" class="btn btn-primary">Export</button>
+ </form>
+</div>
+
+<div class="import-form">
+ <h4 style="margin-bottom: 10px">Import Notes</h4>
+ <form action="/notes/import" method="POST" enctype="multipart/form-data">
+ <input type="file" name="file" accept=".txt" required>
+ <label class="checkbox-label">
+ <input type="checkbox" name="merge" value="true">
+ <span>Merge with existing notes (instead of replacing)</span>
+ </label>
+ <button type="submit" class="btn btn-primary" style="margin-top: 10px;">Import</button>
+ </form>
+</div>
+{{template "_footer"}}
diff --git a/templates/notes.html b/templates/notes.html
@@ -1,22 +1,5 @@
{{template "_header" .}}
-<details><summary>Import and Export</summary>
-
- <div class="import-form">
- <button class="btn btn-primary" onclick="exportNotes()">Export</button>
- <h4 style="margin-bottom: 10px">Import Notes</h4>
- <form action="/notes/import" method="POST" enctype="multipart/form-data">
- <input type="file" name="file" accept=".txt" required>
- <label class="checkbox-label">
- <input type="checkbox" name="merge" value="true">
- <span>Merge with existing notes (instead of replacing)</span>
- </label>
- <button type="submit" class="btn btn-primary" style="margin-top: 10px;">Import</button>
- </form>
- </div>
-
-</details>
-
<div class="toolbar">
<div class="toolbar-group">
<input type="text" class="search-box" id="search-input" placeholder="Filter notes...">