Add basic previous days page
This commit is contained in:
parent
1bd41cad43
commit
958b69dc08
6 changed files with 62 additions and 8 deletions
|
@ -13,7 +13,7 @@ As a result of this, it is also neither secure nor idiot-proof.
|
|||
* You can easily export everything in a zip file for backups
|
||||
|
||||
* Everything is plain(text) and simple. No databases, encryption, OAuth, or anything fancy. Even the password is plainte- *wait is this a feature?*
|
||||
* Telegram notifications support
|
||||
* Optional Telegram notifications for failed login attempts are present
|
||||
|
||||
## Data format:
|
||||
```
|
||||
|
|
5
TODO.md
5
TODO.md
|
@ -1,10 +1,11 @@
|
|||
# TODO
|
||||
List of things to add to this project
|
||||
|
||||
* Make scram configurable
|
||||
* Use reflection in config loading
|
||||
* Check export function for improvements
|
||||
* Add missing frontend pages
|
||||
* More slog.Debug?
|
||||
* Improve viewing of data (textarea over raw API requests)
|
||||
* More slog.Debug and a debug flag?
|
||||
* Think about timezones
|
||||
* Consider more secure auth methods
|
||||
* *Go* dependency-less? <-- this is a terrible idea
|
32
pages/days.html
Normal file
32
pages/days.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="/public/main.css">
|
||||
<script src="/public/date.js"></script>
|
||||
<script src="/public/requests.js"></script>
|
||||
|
||||
<title>Hibiscus.txt</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>🌺 Hibiscus.txt</h1>
|
||||
<p id="status">Today is <span id="today-date">a place</span></p>
|
||||
</header>
|
||||
<main>
|
||||
<h2>Previous days</h2>
|
||||
<ul id="days"></ul>
|
||||
</main>
|
||||
<footer>
|
||||
<p><a href="/">home </a> | <a href="/days">previous days</a> | <a href="/api/readme">readme.txt</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
<script defer>
|
||||
updateDate()
|
||||
beginDateUpdater()
|
||||
|
||||
loadPrevious()
|
||||
</script>
|
||||
</html>
|
|
@ -16,13 +16,12 @@
|
|||
</header>
|
||||
<main>
|
||||
<h2 style="margin-bottom:0;"><label for="day">Your day so far:</label></h2>
|
||||
<textarea id="day" name="Day entry" cols="40" rows="10" style="max-width: 640px; width: 100%"></textarea>
|
||||
<textarea id="day" name="Day entry" cols="40" rows="15" style="max-width: 640px; width: 100%"></textarea>
|
||||
<div class="grid"><button onclick="saveToday()">Save</button></div>
|
||||
|
||||
<h2><label for="log">Log</label></h2>
|
||||
<input type="text" id="log" name="log" style="max-width: 640px; width: 100%"/>
|
||||
<div class="grid"><button onclick="saveLog()">Send</button></div>
|
||||
</main>
|
||||
<footer>
|
||||
<p><a href="/">home </a> | <a href="/days">previous days</a> | <a href="/api/readme">readme.txt</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
<script defer>
|
||||
|
|
|
@ -62,4 +62,23 @@ function loadToday() {
|
|||
dayField.value = data
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadPrevious() {
|
||||
let daysField = document.getElementById("days")
|
||||
daysField.innerHTML = ""
|
||||
getData("/api/day", "").then((data) => {
|
||||
if (data === 401) {
|
||||
alert("Unauthorized")
|
||||
} else if (data === 500) {
|
||||
alert("Internal server error")
|
||||
} else {
|
||||
data = JSON.parse(data).reverse() // Reverse: latest days first
|
||||
for (let i in data) {
|
||||
let li = document.createElement("li");
|
||||
li.innerHTML = `<a href="/api/day/${data[i]}">${data[i]}</a>`
|
||||
daysField.appendChild(li);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
3
serve.go
3
serve.go
|
@ -22,6 +22,9 @@ func Serve() {
|
|||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "./pages/index.html")
|
||||
})
|
||||
r.Get("/days", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "./pages/days.html")
|
||||
})
|
||||
|
||||
// API =============
|
||||
apiRouter := chi.NewRouter()
|
||||
|
|
Loading…
Reference in a new issue