]> code.octet-stream.net Git - broadcaster/blobdiff - broadcaster-server/main.go
Add a menu system
[broadcaster] / broadcaster-server / main.go
index 079f977e33546c0652ad1472ec7d7e33a3cf342c..5a3cbb9dd8f07d60c3f276300ac9dbd8cf0c38bd 100644 (file)
@@ -2,7 +2,7 @@ package main
 
 import (
        "bufio"
 
 import (
        "bufio"
-       "embed"
+       "embed"
        "flag"
        "fmt"
        "golang.org/x/net/websocket"
        "flag"
        "fmt"
        "golang.org/x/net/websocket"
@@ -20,8 +20,9 @@ import (
 const version = "v1.0.0"
 const formatString = "2006-01-02T15:04"
 
 const version = "v1.0.0"
 const formatString = "2006-01-02T15:04"
 
-//go:embed templates/*
-var content embed.FS
+// //go:embed templates/*
+//var content embed.FS
+var content = os.DirFS("../broadcaster-server/")
 
 var config ServerConfig = NewServerConfig()
 
 
 var config ServerConfig = NewServerConfig()
 
@@ -98,18 +99,45 @@ func main() {
        }
 }
 
        }
 }
 
+type HeaderData struct {
+       SelectedMenu string
+       Username string
+}
+
+func renderHeader(w http.ResponseWriter, selectedMenu string) {
+       tmpl := template.Must(template.ParseFS(content, "templates/header.html"))
+       data := HeaderData{
+               SelectedMenu: selectedMenu,
+               Username: "username",
+       }
+       err := tmpl.Execute(w, data)
+       if err != nil {
+               log.Fatal(err)
+       }
+}
+
+func renderFooter(w http.ResponseWriter) {
+       tmpl := template.Must(template.ParseFS(content, "templates/footer.html"))
+       err := tmpl.Execute(w, nil)
+       if err != nil {
+               log.Fatal(err)
+       }
+}
+
 type HomeData struct {
        LoggedIn bool
        Username string
 }
 
 func homePage(w http.ResponseWriter, r *http.Request) {
 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)
        tmpl := template.Must(template.ParseFS(content, "templates/index.html"))
        data := HomeData{
                LoggedIn: true,
                Username: "Bob",
        }
        tmpl.Execute(w, data)
+       renderFooter(w)
 }
 
 type LogInData struct {
 }
 
 type LogInData struct {
@@ -136,9 +164,10 @@ func logInPage(w http.ResponseWriter, r *http.Request) {
        data := LogInData{
                Error: errText,
        }
        data := LogInData{
                Error: errText,
        }
-
+       renderHeader(w, "")
        tmpl := template.Must(template.ParseFS(content, "templates/login.html"))
        tmpl.Execute(w, data)
        tmpl := template.Must(template.ParseFS(content, "templates/login.html"))
        tmpl.Execute(w, data)
+       renderFooter(w)
 }
 
 func playlistSection(w http.ResponseWriter, r *http.Request) {
 }
 
 func playlistSection(w http.ResponseWriter, r *http.Request) {
@@ -244,11 +273,13 @@ func changePasswordPage(w http.ResponseWriter, r *http.Request) {
                data.Message = ""
                data.ShowForm = true
        }
                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)
        }
        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 {
 }
 
 type PlaylistsPageData struct {
@@ -256,6 +287,7 @@ type PlaylistsPageData struct {
 }
 
 func playlistsPage(w http.ResponseWriter, _ *http.Request) {
 }
 
 func playlistsPage(w http.ResponseWriter, _ *http.Request) {
+       renderHeader(w, "playlists")
        data := PlaylistsPageData{
                Playlists: db.GetPlaylists(),
        }
        data := PlaylistsPageData{
                Playlists: db.GetPlaylists(),
        }
@@ -264,6 +296,7 @@ func playlistsPage(w http.ResponseWriter, _ *http.Request) {
        if err != nil {
                log.Fatal(err)
        }
        if err != nil {
                log.Fatal(err)
        }
+       renderFooter(w)
 }
 
 type RadiosPageData struct {
 }
 
 type RadiosPageData struct {
@@ -271,6 +304,7 @@ type RadiosPageData struct {
 }
 
 func radiosPage(w http.ResponseWriter, _ *http.Request) {
 }
 
 func radiosPage(w http.ResponseWriter, _ *http.Request) {
+       renderHeader(w, "radios")
        data := RadiosPageData{
                Radios: db.GetRadios(),
        }
        data := RadiosPageData{
                Radios: db.GetRadios(),
        }
@@ -279,6 +313,7 @@ func radiosPage(w http.ResponseWriter, _ *http.Request) {
        if err != nil {
                log.Fatal(err)
        }
        if err != nil {
                log.Fatal(err)
        }
+       renderFooter(w)
 }
 
 type EditPlaylistPageData struct {
 }
 
 type EditPlaylistPageData struct {
@@ -306,8 +341,10 @@ func editPlaylistPage(w http.ResponseWriter, r *http.Request, id int) {
                data.Playlist = playlist
                data.Entries = db.GetEntriesForPlaylist(id)
        }
                data.Playlist = playlist
                data.Entries = db.GetEntriesForPlaylist(id)
        }
+       renderHeader(w, "radios")
        tmpl := template.Must(template.ParseFS(content, "templates/playlist.html"))
        tmpl.Execute(w, data)
        tmpl := template.Must(template.ParseFS(content, "templates/playlist.html"))
        tmpl.Execute(w, data)
+       renderFooter(w)
 }
 
 func submitPlaylist(w http.ResponseWriter, r *http.Request) {
 }
 
 func submitPlaylist(w http.ResponseWriter, r *http.Request) {
@@ -393,8 +430,10 @@ func editRadioPage(w http.ResponseWriter, r *http.Request, id int) {
                }
                data.Radio = radio
        }
                }
                data.Radio = radio
        }
+       renderHeader(w, "radios")
        tmpl := template.Must(template.ParseFS(content, "templates/radio.html"))
        tmpl.Execute(w, data)
        tmpl := template.Must(template.ParseFS(content, "templates/radio.html"))
        tmpl.Execute(w, data)
+       renderFooter(w)
 }
 
 func submitRadio(w http.ResponseWriter, r *http.Request) {
 }
 
 func submitRadio(w http.ResponseWriter, r *http.Request) {
@@ -434,6 +473,7 @@ type FilesPageData struct {
 }
 
 func filesPage(w http.ResponseWriter, _ *http.Request) {
 }
 
 func filesPage(w http.ResponseWriter, _ *http.Request) {
+       renderHeader(w, "files")
        data := FilesPageData{
                Files: files.Files(),
        }
        data := FilesPageData{
                Files: files.Files(),
        }
@@ -443,6 +483,7 @@ func filesPage(w http.ResponseWriter, _ *http.Request) {
        if err != nil {
                log.Fatal(err)
        }
        if err != nil {
                log.Fatal(err)
        }
+       renderFooter(w)
 }
 
 func deleteFile(w http.ResponseWriter, r *http.Request) {
 }
 
 func deleteFile(w http.ResponseWriter, r *http.Request) {
@@ -473,8 +514,10 @@ func uploadFile(w http.ResponseWriter, r *http.Request) {
 
 func logOutPage(w http.ResponseWriter, r *http.Request) {
        clearSessionCookie(w)
 
 func logOutPage(w http.ResponseWriter, r *http.Request) {
        clearSessionCookie(w)
+       renderHeader(w, "")
        tmpl := template.Must(template.ParseFS(content, "templates/logout.html"))
        tmpl.Execute(w, nil)
        tmpl := template.Must(template.ParseFS(content, "templates/logout.html"))
        tmpl.Execute(w, nil)
+       renderFooter(w)
 }
 
 func stopPage(w http.ResponseWriter, r *http.Request) {
 }
 
 func stopPage(w http.ResponseWriter, r *http.Request) {