refactor: data structs for template + method
enclosing rooms.Room into roomTableData, with methods to be used in tempalte to get other template related derived data structures
This commit is contained in:
@@ -72,10 +72,7 @@ func streamingRoomStates(
|
||||
templFile := "templates/room.gohtml"
|
||||
tableTemplates := "templates/tableTemplates.gohtml"
|
||||
tmpl := template.Must(
|
||||
template.New("").Funcs(template.FuncMap{
|
||||
"bricksForPerson": bricksForPerson,
|
||||
"personsFromRoom": personsFromRoom,
|
||||
}).ParseFS(templateFs, tableTemplates, templFile))
|
||||
template.New("").ParseFS(templateFs, tableTemplates, templFile))
|
||||
|
||||
roomStream := roomsM.Subscribe(r.Context(), roomName)
|
||||
for room := range roomStream {
|
||||
@@ -84,7 +81,11 @@ func streamingRoomStates(
|
||||
|
||||
var buffer bytes.Buffer
|
||||
|
||||
err := tmpl.ExecuteTemplate(&buffer, "simpleRoomShow", room)
|
||||
roomTemplateData := roomTableData{
|
||||
Room: &room,
|
||||
currentPerson: session.PersonId,
|
||||
}
|
||||
err := tmpl.ExecuteTemplate(&buffer, "simpleRoomShow", &roomTemplateData)
|
||||
if err != nil {
|
||||
log.Printf("/rooms/subscribe/%s got error on template %s", roomName, err)
|
||||
}
|
||||
@@ -197,10 +198,7 @@ func roomPageRoute(
|
||||
baseFile := "templates/base.gohtml"
|
||||
tableTemplates := "templates/tableTemplates.gohtml"
|
||||
tmpl := template.Must(
|
||||
template.New("").Funcs(template.FuncMap{
|
||||
"bricksForPerson": bricksForPerson,
|
||||
"personsFromRoom": personsFromRoom,
|
||||
}).ParseFS(templateFs, tableTemplates, templFile, baseFile))
|
||||
template.New("").ParseFS(templateFs, tableTemplates, templFile, baseFile))
|
||||
|
||||
type GestureData struct {
|
||||
Name string
|
||||
@@ -215,10 +213,13 @@ func roomPageRoute(
|
||||
}
|
||||
|
||||
contentData := struct {
|
||||
Room rooms.Room
|
||||
Room *roomTableData
|
||||
Gestures []GestureData
|
||||
}{
|
||||
Room: room,
|
||||
Room: &roomTableData{
|
||||
Room: &room,
|
||||
currentPerson: session.PersonId,
|
||||
},
|
||||
Gestures: gesturesData,
|
||||
}
|
||||
data := pageData{
|
||||
|
||||
Reference in New Issue
Block a user