]> code.octet-stream.net Git - broadcaster/commitdiff
Split HTML into header/footer templates
authorThomas Karpiniec <tom.karpiniec@outlook.com>
Tue, 22 Oct 2024 08:50:53 +0000 (19:50 +1100)
committerThomas Karpiniec <tom.karpiniec@outlook.com>
Tue, 22 Oct 2024 08:50:53 +0000 (19:50 +1100)
12 files changed:
broadcaster-server/main.go
broadcaster-server/templates/change_password.html
broadcaster-server/templates/files.html
broadcaster-server/templates/footer.html [new file with mode: 0644]
broadcaster-server/templates/header.html [new file with mode: 0644]
broadcaster-server/templates/index.html
broadcaster-server/templates/login.html
broadcaster-server/templates/logout.html
broadcaster-server/templates/playlist.html
broadcaster-server/templates/playlists.html
broadcaster-server/templates/radio.html
broadcaster-server/templates/radios.html

index 079f977e33546c0652ad1472ec7d7e33a3cf342c..c44ff7612629805fbf09b0b280df4d83d413483c 100644 (file)
@@ -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) {
index 431e2a4b6ab2be74f69e9e7348d61e244f89f791..bab3a82227974805cd1f23900c8a3ef015f6c396 100644 (file)
@@ -1,12 +1,4 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster</title>
-  </head>
-  <body>
-    <main>
+
       <h1>Change Password</h1>
       {{if ne .Message ""}}
       <p><b>{{.Message}}</b></p>
@@ -20,6 +12,3 @@
         <input type="submit" value="Change Password">
       </form>
       {{end}}
-    </main>
-  </body>
-</html>
index fa2614fbb021ea909c643a3ec3fe845435bebc69..c86c6ceb7cead75331175ba552e6067a0abb81f1 100644 (file)
@@ -1,12 +1,4 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster</title>
-  </head>
-  <body>
-    <main>
+
       <h1>Files! List</h1>
       <p>All files can be downloaded from the <a href="/file-downloads/">public file listing</a>.</p>
       <ul>
@@ -21,6 +13,3 @@
         <input type="submit" value="Upload">
       </form>
       </p>
-    </main>
-  </body>
-</html>
diff --git a/broadcaster-server/templates/footer.html b/broadcaster-server/templates/footer.html
new file mode 100644 (file)
index 0000000..fd8d415
--- /dev/null
@@ -0,0 +1,3 @@
+    </main>
+  </body>
+</html>
diff --git a/broadcaster-server/templates/header.html b/broadcaster-server/templates/header.html
new file mode 100644 (file)
index 0000000..8e40467
--- /dev/null
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Broadcaster</title>
+    <style type="text/css">
+      table.radio-status, td.outer {
+        border: 1px solid;
+      }
+      table.inner {
+        border-collapse: collapse;
+      }
+      td.clear {
+        width: 5em;
+        height: 5em;
+        text-align: center;
+      }
+      .time-table {
+        font-size: 90%;
+      }
+      .playlist-field {
+        text-align: right;
+        padding-right: 1em;
+        width: 5em;
+      }
+      .playlist-table {
+        font-size: 90%;
+        width: 30em;
+      }
+      .stop {
+        text-align: center;
+      }
+      .head {
+        text-align: center;
+      }
+    </style>
+  </head>
+  <body>
+    <main>
index 367d48c0caae4f2827983aecd5987e3a146fc2db..b688947499a864f36cbecca80beba0839bba4d75 100644 (file)
@@ -1,40 +1,3 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster</title>
-    <style type="text/css">
-      table.radio-status, td.outer {
-        border: 1px solid;
-      }
-      table.inner {
-        border-collapse: collapse;
-      }
-      td.clear {
-        width: 5em;
-        height: 5em;
-        text-align: center;
-      }
-      .time-table {
-        font-size: 90%;
-      }
-      .playlist-field {
-        text-align: right;
-        padding-right: 1em;
-        width: 5em;
-      }
-      .playlist-table {
-        font-size: 90%;
-        width: 30em;
-      }
-      .stop {
-        text-align: center;
-      }
-      .head {
-        text-align: center;
-      }
-    </style>
     <script type="text/javascript">
       function connectWebsocket() {
         console.log("Attempting to create websocket connection for radio status sync")
@@ -59,9 +22,7 @@
       // initial connection on page load
       connectWebsocket();
     </script>
-  </head>
-  <body>
-    <main>
+
       <h1>Welcome!</h1>
       {{if .LoggedIn}}
       <p>Your username is: {{.Username}}.</p>
@@ -76,6 +37,3 @@
       <div id="connected-radios">
         <i>Loading...</i>
       </div>
-    </main>
-  </body>
-</html>
index 56772b94870007c2efa8f1011d8b025efa0c0dc4..2211b2fd6a38d938e0e0d3b9155a590e6874f4f9 100644 (file)
@@ -1,12 +1,4 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster Log In</title>
-  </head>
-  <body>
-    <main>
+
       <h1>Log In</h1>
       <form action="/login" method="post">
         {{if ne .Error ""}}
@@ -18,6 +10,3 @@
         <input type="password" id="password" name="password"><br>
         <input type="submit" value="Log In">
       </form>
-    </main>
-  </body>
-</html>
index b1512653d66014bcf992abd260472cbdaac676d0..8b7ee1c39c186b6c22299a13dcd41964584f779d 100644 (file)
@@ -1,14 +1,3 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster Log Out</title>
-  </head>
-  <body>
-    <main>
+
         <h1>Logged Out</h1>
         <p><a href="/login">Log In again</a></p>
-    </main>
-  </body>
-</html>
index e6097120fadf8963c1e0980ecef15a274489925d..d778250ac609e5ba1e1b8147c34ca79ad4c5520f 100644 (file)
@@ -1,9 +1,4 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster</title>
+
     <script type="text/javascript">
     function deleteItem(sender) {
       sender.parentNode.remove();
       parent.insertBefore(p, marker);
     }
     </script>
-  </head>
-  <body>
-    <main>
-      <h1>A specific playlist</h1>
+
+    <h1>A specific playlist</h1>
       <h2>
       {{if .Playlist.Id}}
       Edit Playlist
@@ -95,6 +88,3 @@
         </select>
         <a href="#" onclick="deleteItem(this)">(Delete Item)</a>
       </template>
-    </main>
-  </body>
-</html>
index 8b83d3d4c6ee629996ffec011db008e5a17587a8..e1ba60f1085c1a1b9322fd38b3967d78b345d73d 100644 (file)
@@ -1,12 +1,4 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster</title>
-  </head>
-  <body>
-    <main>
+
       <h1>Playlists!</h1>
       <ul>
       {{range .Playlists}}
@@ -14,6 +6,3 @@
       {{end}}
       </ul>
       <p><a href="/playlists/new">Add New Playlist</a></p>
-    </main>
-  </body>
-</html>
index 01e4f0ca5c5f96eb9332fe8c1eb5df171a22dcac..c2ec9dd844292ff6e60561015903d44809f31846 100644 (file)
@@ -1,12 +1,4 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster</title>
-  </head>
-  <body>
-    <main>
+
       <h1>A specific radio</h1>
       <h2>
       {{if .Radio.Id}}
@@ -38,6 +30,3 @@
         </p>
       </form>
       {{end}}
-    </main>
-  </body>
-</html>
index d55ea4aa9ed7bd96782eff77e36918183ab53506..0c1288fe99c26f00802c1d2130bddee3b388777f 100644 (file)
@@ -1,12 +1,4 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Broadcaster</title>
-  </head>
-  <body>
-    <main>
+
       <h1>Radios</h1>
       <ul>
       {{range .Radios}}
@@ -14,6 +6,3 @@
       {{end}}
       </ul>
       <p><a href="/radios/new">Register New Radio</a></p>
-    </main>
-  </body>
-</html>