Added theme to configuration page

This commit is contained in:
Magnus Åhall 2024-06-25 09:18:15 +02:00
parent c77737a20e
commit 54ba7b160b
6 changed files with 29 additions and 0 deletions

View File

@ -38,3 +38,9 @@ func SmonConfigInit() (err error) {
return
}
func (cfg *Configuration) SetTheme(theme string) (err error) {
cfg.Settings["THEME"] = theme
_, err = service.Db.Conn.Exec(`UPDATE public.configuration SET value=$1 WHERE setting='THEME'`, theme)
return
}

12
main.go
View File

@ -148,6 +148,7 @@ func main() { // {{{
service.Register("/trigger/delete/{id}", false, false, actionTriggerDelete)
service.Register("/configuration", false, false, pageConfiguration)
service.Register("/configuration/theme", false, false, actionConfigurationTheme)
service.Register("/entry/{datapoint}", false, false, actionEntryDatapoint)
go nodataLoop()
@ -955,3 +956,14 @@ func pageConfiguration(w http.ResponseWriter, _ *http.Request, _ *session.T) { /
page.Render(w)
} // }}}
func actionConfigurationTheme(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{
theme := r.FormValue("theme")
err := smonConfig.SetTheme(theme)
if err != nil {
httpError(w, werr.Wrap(err).Log())
return
}
w.Header().Add("Location", "/configuration")
w.WriteHeader(302)
} // }}}

View File

@ -128,6 +128,7 @@ body {
h1,
h2 {
margin-bottom: 4px;
margin-top: 32px;
}
h1:first-child,
h2:first-child {

View File

@ -128,6 +128,7 @@ body {
h1,
h2 {
margin-bottom: 4px;
margin-top: 32px;
}
h1:first-child,
h2:first-child {

View File

@ -158,6 +158,7 @@ body {
h1,
h2 {
margin-bottom: 4px;
margin-top: 32px;
&:first-child {
margin-top: 0px;
}

View File

@ -93,4 +93,12 @@
{{ end }}
</div>
<h1>Theme</h1>
<form action="/configuration/theme" id="theme-set">
<select name="theme" onchange="console.log(this.form.submit())">
<option value="default_light" {{ if eq "default_light" .CONFIG.THEME }}selected{{ end }}>Default light</option>
<option value="gruvbox" {{ if eq "gruvbox" .CONFIG.THEME }}selected{{ end }}>Gruvbox</option>
</select>
</form>
{{ end }}