From: Thomas Karpiniec Date: Tue, 22 Oct 2024 08:50:53 +0000 (+1100) Subject: Split HTML into header/footer templates X-Git-Tag: v1.0.0~9 X-Git-Url: https://code.octet-stream.net/broadcaster/commitdiff_plain/587f9c5bb84420d9f71fe75e29f54b8319c90064?hp=33a19d553807d171f6ba9f4dafe30f43bc4bab5e Split HTML into header/footer templates --- diff --git a/broadcaster-server/main.go b/broadcaster-server/main.go index 079f977..c44ff76 100644 --- a/broadcaster-server/main.go +++ b/broadcaster-server/main.go @@ -98,18 +98,37 @@ func main() { } } +type HeaderData struct { + SelectedMenu string +} + +func renderHeader(w http.ResponseWriter, selectedMenu string) { + tmpl := template.Must(template.ParseFS(content, "templates/header.html")) + data := HeaderData{ + SelectedMenu: selectedMenu, + } + tmpl.Execute(w, data) +} + +func renderFooter(w http.ResponseWriter) { + tmpl := template.Must(template.ParseFS(content, "templates/footer.html")) + tmpl.Execute(w, nil) +} + type HomeData struct { LoggedIn bool Username string } func homePage(w http.ResponseWriter, r *http.Request) { + renderHeader(w, "status") tmpl := template.Must(template.ParseFS(content, "templates/index.html")) data := HomeData{ LoggedIn: true, Username: "Bob", } tmpl.Execute(w, data) + renderFooter(w) } type LogInData struct { @@ -136,9 +155,10 @@ func logInPage(w http.ResponseWriter, r *http.Request) { data := LogInData{ Error: errText, } - + renderHeader(w, "") tmpl := template.Must(template.ParseFS(content, "templates/login.html")) tmpl.Execute(w, data) + renderFooter(w) } func playlistSection(w http.ResponseWriter, r *http.Request) { @@ -244,11 +264,13 @@ func changePasswordPage(w http.ResponseWriter, r *http.Request) { data.Message = "" data.ShowForm = true } + renderHeader(w, "change-password") tmpl := template.Must(template.ParseFS(content, "templates/change_password.html")) err = tmpl.Execute(w, data) if err != nil { log.Fatal(err) } + renderFooter(w) } type PlaylistsPageData struct { @@ -256,6 +278,7 @@ type PlaylistsPageData struct { } func playlistsPage(w http.ResponseWriter, _ *http.Request) { + renderHeader(w, "playlists") data := PlaylistsPageData{ Playlists: db.GetPlaylists(), } @@ -264,6 +287,7 @@ func playlistsPage(w http.ResponseWriter, _ *http.Request) { if err != nil { log.Fatal(err) } + renderFooter(w) } type RadiosPageData struct { @@ -271,6 +295,7 @@ type RadiosPageData struct { } func radiosPage(w http.ResponseWriter, _ *http.Request) { + renderHeader(w, "radios") data := RadiosPageData{ Radios: db.GetRadios(), } @@ -279,6 +304,7 @@ func radiosPage(w http.ResponseWriter, _ *http.Request) { if err != nil { log.Fatal(err) } + renderFooter(w) } type EditPlaylistPageData struct { @@ -306,8 +332,10 @@ func editPlaylistPage(w http.ResponseWriter, r *http.Request, id int) { data.Playlist = playlist data.Entries = db.GetEntriesForPlaylist(id) } + renderHeader(w, "radios") tmpl := template.Must(template.ParseFS(content, "templates/playlist.html")) tmpl.Execute(w, data) + renderFooter(w) } func submitPlaylist(w http.ResponseWriter, r *http.Request) { @@ -393,8 +421,10 @@ func editRadioPage(w http.ResponseWriter, r *http.Request, id int) { } data.Radio = radio } + renderHeader(w, "radios") tmpl := template.Must(template.ParseFS(content, "templates/radio.html")) tmpl.Execute(w, data) + renderFooter(w) } func submitRadio(w http.ResponseWriter, r *http.Request) { @@ -434,6 +464,7 @@ type FilesPageData struct { } func filesPage(w http.ResponseWriter, _ *http.Request) { + renderHeader(w, "files") data := FilesPageData{ Files: files.Files(), } @@ -443,6 +474,7 @@ func filesPage(w http.ResponseWriter, _ *http.Request) { if err != nil { log.Fatal(err) } + renderFooter(w) } func deleteFile(w http.ResponseWriter, r *http.Request) { @@ -473,8 +505,10 @@ func uploadFile(w http.ResponseWriter, r *http.Request) { func logOutPage(w http.ResponseWriter, r *http.Request) { clearSessionCookie(w) + renderHeader(w, "logout") tmpl := template.Must(template.ParseFS(content, "templates/logout.html")) tmpl.Execute(w, nil) + renderFooter(w) } func stopPage(w http.ResponseWriter, r *http.Request) { diff --git a/broadcaster-server/templates/change_password.html b/broadcaster-server/templates/change_password.html index 431e2a4..bab3a82 100644 --- a/broadcaster-server/templates/change_password.html +++ b/broadcaster-server/templates/change_password.html @@ -1,12 +1,4 @@ - - - - - - Broadcaster - - -
+

Change Password

{{if ne .Message ""}}

{{.Message}}

@@ -20,6 +12,3 @@ {{end}} -
- - diff --git a/broadcaster-server/templates/files.html b/broadcaster-server/templates/files.html index fa2614f..c86c6ce 100644 --- a/broadcaster-server/templates/files.html +++ b/broadcaster-server/templates/files.html @@ -1,12 +1,4 @@ - - - - - - Broadcaster - - -
+

Files! List

All files can be downloaded from the public file listing.

- - diff --git a/broadcaster-server/templates/footer.html b/broadcaster-server/templates/footer.html new file mode 100644 index 0000000..fd8d415 --- /dev/null +++ b/broadcaster-server/templates/footer.html @@ -0,0 +1,3 @@ + + + diff --git a/broadcaster-server/templates/header.html b/broadcaster-server/templates/header.html new file mode 100644 index 0000000..8e40467 --- /dev/null +++ b/broadcaster-server/templates/header.html @@ -0,0 +1,40 @@ + + + + + + Broadcaster + + + +
diff --git a/broadcaster-server/templates/index.html b/broadcaster-server/templates/index.html index 367d48c..b688947 100644 --- a/broadcaster-server/templates/index.html +++ b/broadcaster-server/templates/index.html @@ -1,40 +1,3 @@ - - - - - - Broadcaster - - - -
+

Welcome!

{{if .LoggedIn}}

Your username is: {{.Username}}.

@@ -76,6 +37,3 @@
Loading...
-
- - diff --git a/broadcaster-server/templates/login.html b/broadcaster-server/templates/login.html index 56772b9..2211b2f 100644 --- a/broadcaster-server/templates/login.html +++ b/broadcaster-server/templates/login.html @@ -1,12 +1,4 @@ - - - - - - Broadcaster Log In - - -
+

Log In

{{if ne .Error ""}} @@ -18,6 +10,3 @@
-
- - diff --git a/broadcaster-server/templates/logout.html b/broadcaster-server/templates/logout.html index b151265..8b7ee1c 100644 --- a/broadcaster-server/templates/logout.html +++ b/broadcaster-server/templates/logout.html @@ -1,14 +1,3 @@ - - - - - - Broadcaster Log Out - - -
+

Logged Out

Log In again

-
- - diff --git a/broadcaster-server/templates/playlist.html b/broadcaster-server/templates/playlist.html index e609712..d778250 100644 --- a/broadcaster-server/templates/playlist.html +++ b/broadcaster-server/templates/playlist.html @@ -1,9 +1,4 @@ - - - - - - Broadcaster + - - -
-

A specific playlist

+ +

A specific playlist

{{if .Playlist.Id}} Edit Playlist @@ -95,6 +88,3 @@ (Delete Item) -

- - diff --git a/broadcaster-server/templates/playlists.html b/broadcaster-server/templates/playlists.html index 8b83d3d..e1ba60f 100644 --- a/broadcaster-server/templates/playlists.html +++ b/broadcaster-server/templates/playlists.html @@ -1,12 +1,4 @@ - - - - - - Broadcaster - - -
+

Playlists!

    {{range .Playlists}} @@ -14,6 +6,3 @@ {{end}}

Add New Playlist

-
- - diff --git a/broadcaster-server/templates/radio.html b/broadcaster-server/templates/radio.html index 01e4f0c..c2ec9dd 100644 --- a/broadcaster-server/templates/radio.html +++ b/broadcaster-server/templates/radio.html @@ -1,12 +1,4 @@ - - - - - - Broadcaster - - -
+

A specific radio

{{if .Radio.Id}} @@ -38,6 +30,3 @@

{{end}} -

- - diff --git a/broadcaster-server/templates/radios.html b/broadcaster-server/templates/radios.html index d55ea4a..0c1288f 100644 --- a/broadcaster-server/templates/radios.html +++ b/broadcaster-server/templates/radios.html @@ -1,12 +1,4 @@ - - - - - - Broadcaster - - -
+

Radios

    {{range .Radios}} @@ -14,6 +6,3 @@ {{end}}

Register New Radio

-
- -