Move indexPageTemplate variable to index.go
This commit is contained in:
parent
7394cddc39
commit
615c228c2d
99
index.go
99
index.go
|
@ -8,6 +8,105 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var indexPageTemplate = `<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Add moments of your day</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css"
|
||||
integrity="sha256-zIG416V1ynj3Wgju/scU80KAEWOsO5rRLfVyRDuOv7Q=" crossorigin="anonymous"/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="section">
|
||||
<div class="container">
|
||||
<p>Logged in as: <a href="{{ .Me }}">{{ .Me }}</a> | <a href="/auth/logout">Logout</a></p>
|
||||
|
||||
<h1 class="title">Remember moments: <em class="js-counter is-primary">N</em> minutes since your last memo</h1>
|
||||
|
||||
<form action="/moment" class="form" method="post">
|
||||
<div class="field">
|
||||
<label class="label">What did you do in the last <em class="js-counter"></em> minutes:</label>
|
||||
<div class="control"><input type="text" name="memo" class="input" autofocus
|
||||
placeholder="add note / accomplishments"></div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<button class="button is-primary" type="submit">Save moment</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{ if .Moments }}
|
||||
<div class="section">
|
||||
<div class="container">
|
||||
<table class="table">
|
||||
{{ range .Moments }}
|
||||
<tr>
|
||||
<td>{{ (.Time.Format "15:04") }}</td>
|
||||
<td style="text-align:right">{{ if ne .Diff 0 }}{{ .Diff }}m{{ else }}start{{ end }}</td>
|
||||
<td> {{ .Memo }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var timeout = 20000;
|
||||
var timeoutID = setTimeout(adjustCounterText, timeout);
|
||||
var lastTime = {{ .LastMomentSeconds }};
|
||||
|
||||
adjustCounterText();
|
||||
|
||||
function adjustCounterText() {
|
||||
var counters = document.querySelectorAll(".js-counter");
|
||||
var date = new Date();
|
||||
var minutes = Math.floor((date.getTime() / 1000 - lastTime) / 60);
|
||||
|
||||
if (minutes >= 15) {
|
||||
notifyMe(minutes + " minutes passed since writing the last memory");
|
||||
}
|
||||
|
||||
counters.forEach(function (v) {
|
||||
v.innerHTML = minutes + "";
|
||||
})
|
||||
setTimeout(adjustCounterText, timeout);
|
||||
}
|
||||
|
||||
function notifyMe(text) {
|
||||
// Let's check if the browser supports notifications
|
||||
if (!("Notification" in window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's check whether notification permissions have already been granted
|
||||
else if (Notification.permission === "granted") {
|
||||
// If it's okay let's create a notification
|
||||
var notification = new Notification(text);
|
||||
}
|
||||
|
||||
// Otherwise, we need to ask the user for permission
|
||||
else if (Notification.permission !== "denied") {
|
||||
Notification.requestPermission(function (permission) {
|
||||
// If the user accepts, let's create a notification
|
||||
if (permission === "granted") {
|
||||
var notification = new Notification(text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// At last, if the user has denied notifications, and you
|
||||
// want to be respectful there is no need to bother them any more.
|
||||
}
|
||||
</script>
|
||||
{{ end }}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
|
||||
type indexHandler struct {
|
||||
DB *bbolt.DB
|
||||
}
|
||||
|
|
98
main.go
98
main.go
|
@ -15,104 +15,6 @@ import (
|
|||
const BucketKeyMoments = "moments"
|
||||
const DBFilename = "./moments.db"
|
||||
|
||||
var indexPageTemplate = `<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Add moments of your day</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css"
|
||||
integrity="sha256-zIG416V1ynj3Wgju/scU80KAEWOsO5rRLfVyRDuOv7Q=" crossorigin="anonymous"/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="section">
|
||||
<div class="container">
|
||||
<p>Logged in as: <a href="{{ .Me }}">{{ .Me }}</a> | <a href="/auth/logout">Logout</a></p>
|
||||
|
||||
<h1 class="title">Remember moments: <em class="js-counter is-primary">N</em> minutes since your last memo</h1>
|
||||
|
||||
<form action="/moment" class="form" method="post">
|
||||
<div class="field">
|
||||
<label class="label">What did you do in the last <em class="js-counter"></em> minutes:</label>
|
||||
<div class="control"><input type="text" name="memo" class="input" autofocus
|
||||
placeholder="add note / accomplishments"></div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<button class="button is-primary" type="submit">Save moment</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{ if .Moments }}
|
||||
<div class="section">
|
||||
<div class="container">
|
||||
<table class="table">
|
||||
{{ range .Moments }}
|
||||
<tr>
|
||||
<td>{{ (.Time.Format "15:04") }}</td>
|
||||
<td style="text-align:right">{{ if ne .Diff 0 }}{{ .Diff }}m{{ else }}start{{ end }}</td>
|
||||
<td> {{ .Memo }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var timeout = 20000;
|
||||
var timeoutID = setTimeout(adjustCounterText, timeout);
|
||||
var lastTime = {{ .LastMomentSeconds }};
|
||||
|
||||
adjustCounterText();
|
||||
|
||||
function adjustCounterText() {
|
||||
var counters = document.querySelectorAll(".js-counter");
|
||||
var date = new Date();
|
||||
var minutes = Math.floor((date.getTime() / 1000 - lastTime) / 60);
|
||||
|
||||
if (minutes >= 15) {
|
||||
notifyMe(minutes + " minutes passed since writing the last memory");
|
||||
}
|
||||
|
||||
counters.forEach(function (v) {
|
||||
v.innerHTML = minutes + "";
|
||||
})
|
||||
setTimeout(adjustCounterText, timeout);
|
||||
}
|
||||
|
||||
function notifyMe(text) {
|
||||
// Let's check if the browser supports notifications
|
||||
if (!("Notification" in window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's check whether notification permissions have already been granted
|
||||
else if (Notification.permission === "granted") {
|
||||
// If it's okay let's create a notification
|
||||
var notification = new Notification(text);
|
||||
}
|
||||
|
||||
// Otherwise, we need to ask the user for permission
|
||||
else if (Notification.permission !== "denied") {
|
||||
Notification.requestPermission(function (permission) {
|
||||
// If the user accepts, let's create a notification
|
||||
if (permission === "granted") {
|
||||
var notification = new Notification(text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// At last, if the user has denied notifications, and you
|
||||
// want to be respectful there is no need to bother them any more.
|
||||
}
|
||||
</script>
|
||||
{{ end }}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
// Moment is the main information this servers remembers
|
||||
type Moment struct {
|
||||
Key string
|
||||
|
|
Loading…
Reference in New Issue
Block a user