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:
@@ -33,32 +33,29 @@ var brickColors = map[rooms.HandGesture]template.CSS{
|
||||
rooms.ChangeTopic: "--change-topic-color",
|
||||
}
|
||||
|
||||
// data to be passed to "roomPeople" template
|
||||
type roomTableData struct {
|
||||
Persons []personData
|
||||
Total int
|
||||
Tangens float64
|
||||
*rooms.Room
|
||||
currentPerson rooms.PersonId
|
||||
}
|
||||
|
||||
func personsFromRoom(room rooms.Room) roomTableData {
|
||||
// TODO start from the 'logged in person'
|
||||
total := len(room.Paricipants)
|
||||
persons := make([]personData, 0, total)
|
||||
tangens := math.Tan(math.Pi / float64(total)) // Math.tan(Math.PI/m);
|
||||
// tangens = math.Round(tangens*100) / 100
|
||||
func (room *roomTableData)Persons() []personData {
|
||||
persons := make([]personData, 0, room.Total())
|
||||
for i, pId := range room.Paricipants {
|
||||
personData := personDataFromRoom(room, pId)
|
||||
personData.Index = i
|
||||
// personData.Tan = math.Round(tangens*100)/100
|
||||
persons = append(persons, personData)
|
||||
}
|
||||
return roomTableData{
|
||||
Persons: persons,
|
||||
Total: total,
|
||||
Tangens: tangens,
|
||||
}
|
||||
return persons
|
||||
}
|
||||
func (r *roomTableData)Total() int {
|
||||
return len(r.Paricipants)
|
||||
}
|
||||
func (r *roomTableData)Tangens() float64 {
|
||||
return math.Tan(math.Pi / float64(r.Total())) // Math.tan(Math.PI/m);
|
||||
}
|
||||
|
||||
func personDataFromRoom(room rooms.Room, pId rooms.PersonId) personData {
|
||||
func personDataFromRoom(room *roomTableData, pId rooms.PersonId) personData {
|
||||
person, exists := room.AllKnownPeople[pId]
|
||||
if !exists || !slices.Contains(room.Paricipants, pId) {
|
||||
return personData{}
|
||||
@@ -85,7 +82,7 @@ func personDataFromRoom(room rooms.Room, pId rooms.PersonId) personData {
|
||||
}
|
||||
}
|
||||
|
||||
func bricksForPerson(pData personData) []brickState {
|
||||
func (pData personData)BricksForPerson() []brickState {
|
||||
var result = make([]brickState, 5)
|
||||
for gesture := rooms.ChangeTopic; gesture <= rooms.Meta; gesture++ {
|
||||
// for index := rooms.Meta; index >= rooms.ChangeTopic; index-- {
|
||||
@@ -168,7 +165,7 @@ func roomTemplatesPreview(
|
||||
Bricks []SingleBrickData
|
||||
ABrick brickState
|
||||
TestPerson personData
|
||||
ARoom rooms.Room
|
||||
ARoom *roomTableData
|
||||
}{
|
||||
DefaultColor: "--expand-color",
|
||||
ABrick: brickState{
|
||||
@@ -198,7 +195,10 @@ func roomTemplatesPreview(
|
||||
},
|
||||
},
|
||||
TestPerson: testPersonData,
|
||||
ARoom: aRoom,
|
||||
ARoom: &roomTableData{
|
||||
Room: &aRoom,
|
||||
currentPerson: aRoom.Paricipants[0],
|
||||
},
|
||||
}
|
||||
|
||||
pageData := pageData{
|
||||
@@ -207,10 +207,7 @@ func roomTemplatesPreview(
|
||||
}
|
||||
|
||||
baseFile := "templates/base.gohtml"
|
||||
tmpl := template.Must(template.New("").Funcs(template.FuncMap{
|
||||
"bricksForPerson": bricksForPerson,
|
||||
"personsFromRoom": personsFromRoom,
|
||||
}).ParseFS(templateFs, baseFile,
|
||||
tmpl := template.Must(template.New("").ParseFS(templateFs, baseFile,
|
||||
"templates/tableTemplates.gohtml",
|
||||
"templates/tableTemplatesPreview.gohtml",
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user