-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.templ
229 lines (208 loc) · 6.67 KB
/
base.templ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// -*- html -*-
package main
import "fmt"
// If configured in State, this will reload the page if the reported
// version of the server differs from what is in this code.
templ Reloader(st State) {
if st.RefreshIntervalMs > 0 {
@templ.JSONScript("buildTimestamp", st.BuildTimestamp)
@templ.JSONScript("refreshInterval", st.RefreshIntervalMs)
<script>
let buildTimestamp = JSON.parse(document.getElementById('buildTimestamp').textContent);
let refreshInterval = JSON.parse(document.getElementById('refreshInterval').textContent)
function checkVersion() {
fetch('/version?simple=1')
.then(response => response.text())
.then(timestamp => {
if (timestamp !== buildTimestamp) {
// Reload the page
console.log(`Timestamp changed: ${timestamp} <> ${buildTimestamp}`);
location.reload();
}
})
.catch(error => {
console.error('Error checking version:', error);
});
}
setInterval(checkVersion, refreshInterval);
</script>
}
}
templ Base(st State, toplevel int, title string) {
<!DOCTYPE html>
<html lang="en">
<head>
<title>{ title }</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<!-- popper.js, required for bootstrap tooltips -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<!-- core bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<!-- bootstrap icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css"/>
<!-- htmx -->
<script src="https://unpkg.com/[email protected]" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC" crossorigin="anonymous"></script>
<!-- this loading bar found from Reddit:
https://old.reddit.com/r/htmx/comments/1blwnc4/tip_of_the_day_unobtrusive_global_loading/
-->
<style>
.loading-bar {
opacity: 0;
width: 100%;
height: 4px;
background: linear-gradient(90deg, transparent,
#000, transparent,
#000, transparent
);
}
.htmx-request.loading-bar {
opacity: 1;
animation: fadeIn 1s linear forwards, slide 0.8s ease-in-out infinite;
}
@keyframes slide {
0% { transform: translateX(-100%); }
100% { transform: translateX( 100%); }
}
@keyframes fadeIn {
0% { opacity: 0; }
50% { opacity: 0; }
100% { opacity: 1; }
}
</style>
<!--
submit button -> image found in
https://www.tutorialrepublic.com/faq/how-to-add-icons-to-input-submit-button-in-bootstrap.php
-->
<style>
.icon-submit-btn {
display: inline-block;
position: relative;
}
.icon-submit-btn input[type="submit"]{
padding-left: 2em;
}
.icon-submit-btn .bi {
display: inline-block;
position: absolute;
left: 0.65em;
//top: 30%;
top: 15%;
}
.icon-submit-white {
color: white;
}
</style>
</head>
<body hx-boost="true" hx-indicator=".loading-bar">
@Reloader(st)
<div class="container-fluid" id="container">
<div class="row bg-success-subtle position-relative" id="top" style="padding-left:0;padding-right:0">
@Col(2) {
<h1><a href="/">Lixie</a></h1>
}
@Col(4) {
<ul class="nav nav-pills" style="padding-top:8px">
for _, info := range topLevelInfos {
<li class="nav-item">
<a
if info.ID == toplevel {
class="nav-link active"
} else {
class="nav-link"
}
href={ templ.URL(info.Path + "/") }
>{ info.Title }</a>
</li>
}
</ul>
}
@Col(6) {
if toplevel != TopLevelMain {
<h2 class="position-absolute bottom-0 end-0" style="padding-right:8px">{ title }</h2>
}
}
</div>
<div class="loading-bar"></div>
{ children... }
</div>
</body>
</html>
}
// Fresh row (with N columns of up to 12 width)
templ Row(id string) {
<div class="row" id={ id }>
{ children... }
</div>
}
func colForWidth(width int) string {
return fmt.Sprintf("col-%d", width)
}
// Variable-width column
templ Col(width int) {
<div class={ colForWidth(width) }>
{ children... }
</div>
}
// Convenience link components
templ ActionButton(title string, class string, href templ.SafeURL) {
<a
class={ class }
href={ href }
data-toggle="tooltip"
data-delay="500"
title={ title }
>
{ children... }
</a>
}
templ AddButton(title string, href templ.SafeURL) {
@ActionButton(title, "btn btn-sm btn-outline-primary", href) {
<i class="bi bi-file-earmark-plus"></i>
}
}
templ DeleteButton(title string, href templ.SafeURL) {
@ActionButton(title, "btn btn-sm btn-outline-danger", href) {
<i class="bi bi-trash3"></i>
}
}
templ EditButton(title string, href templ.SafeURL) {
@ActionButton(title, "btn btn-sm btn-outline-primary", href) {
<i class="bi bi-wrench-adjustable"></i>
}
}
templ SaveButton(title string, href templ.SafeURL) {
@ActionButton(title, "btn btn-sm btn-outline-primary", href) {
<i class="bi bi-floppy"></i>
}
}
// Convenience submit components
templ SubmitButton(title string, class string, name string) {
<div class="icon-submit-btn">
{ children... }
<input
class={ class }
data-toggle="tooltip"
data-delay="500"
name={ name }
title={ title }
type="submit"
value=" "
/>
</div>
}
templ AddSubmit(title string, name string) {
@SubmitButton(title, "btn btn-sm btn-primary", name) {
<i class="bi bi-file-earmark-plus icon-submit-white"></i>
}
}
templ DeleteSubmit(title string, name string) {
@SubmitButton(title, "btn btn-sm btn-danger", name) {
<i class="bi bi-trash3 icon-submit-white"></i>
}
}
templ SaveSubmit(title string, name string) {
@SubmitButton(title, "btn btn-sm btn-primary", name) {
<i class="bi bi-floppy icon-submit-white"></i>
}
}