From 384afa0e00b50ff0a7ce2d19a8b4fe2d51887413 Mon Sep 17 00:00:00 2001 From: efim Date: Thu, 16 Nov 2023 06:22:09 +0000 Subject: [PATCH] feat: template for all room participants --- routes/room_page_templates_preview.go | 83 ++++++++++++++++++++++++-- routes/templates/tableTemplates.gohtml | 21 +++++-- 2 files changed, 95 insertions(+), 9 deletions(-) diff --git a/routes/room_page_templates_preview.go b/routes/room_page_templates_preview.go index 35f9355..c7ebec1 100644 --- a/routes/room_page_templates_preview.go +++ b/routes/room_page_templates_preview.go @@ -31,6 +31,42 @@ var brickColors = map[rooms.HandGesture]template.CSS{ rooms.ChangeTopic: "--change-topic-color", } +func personsFromRoom(room rooms.Room) []personData { + // TODO start from the 'logged in person' + result := make([]personData, 0, len(room.Paricipants)) + for _, pId := range room.Paricipants { + result = append(result, personDataFromRoom(room, pId)) + } + return result +} + +func personDataFromRoom(room rooms.Room, pId rooms.PersonId) personData { + person, exists := room.AllKnownPeople[pId] + if !exists || !slices.Contains(room.Paricipants, pId) { + return personData{} + } + + hand, handExists := room.ParticipantHands[pId] + var mark rooms.HandGesture + var markExists bool + for gesture := rooms.ChangeTopic; gesture <= rooms.Meta; gesture++ { + if room.Marks[gesture] == pId { + markExists = true + mark = gesture + } + } + isSpeaker := room.CurrentSpeaker == pId + + return personData{ + Name: person.Name, + IsSpeaker: isSpeaker, + IsRaised: handExists, + Raised: hand, + IsMark: markExists, + Mark: mark, + } +} + func bricksForPerson(pData personData) []brickState { var result = make([]brickState, 5) for gesture := rooms.ChangeTopic; gesture <= rooms.Meta; gesture++ { @@ -47,7 +83,7 @@ func bricksForPerson(pData personData) []brickState { templateType = "raisedBrick" } - result[gesture] = brickState{ + result[gesture] = brickState{ ColorClass: brickColors[gesture], TemplateType: templateType, } @@ -68,11 +104,45 @@ func roomTemplatesPreview( } testPersonData := personData{ - Name: "John Doe", + Name: "John Doe", IsRaised: true, - Raised: rooms.Expand, - IsMark: true, - Mark: rooms.ProbingQ, + Raised: rooms.Expand, + IsMark: true, + Mark: rooms.ProbingQ, + } + + var person1 = rooms.Person{ + Id: rooms.PersonId(100), + Name: "test person 1", + } + var person2 = rooms.Person{ + Id: rooms.PersonId(200), + Name: "test person 2", + } + var person3 = rooms.Person{ + Id: rooms.PersonId(300), + Name: "test person 3", + } + aRoom := rooms.Room{ + Name: "test", + CurrentSpeaker: person3.Id, + AllKnownPeople: map[rooms.PersonId]rooms.Person{ + person1.Id: person1, + person2.Id: person2, + person3.Id: person3, + }, + Paricipants: []rooms.PersonId{ + person1.Id, + person2.Id, + person3.Id, + }, + ParticipantHands: map[rooms.PersonId]rooms.HandGesture{ + person3.Id: rooms.ClarifyingQ, + person2.Id: rooms.Meta, + }, + Marks: map[rooms.HandGesture]rooms.PersonId{ + rooms.Expand: person1.Id, + }, } contentData := struct { @@ -80,6 +150,7 @@ func roomTemplatesPreview( Bricks []SingleBrickData ABrick brickState TestPerson personData + ARoom rooms.Room }{ DefaultColor: "--expand-color", ABrick: brickState{ @@ -109,6 +180,7 @@ func roomTemplatesPreview( }, }, TestPerson: testPersonData, + ARoom: aRoom, } pageData := pageData{ @@ -119,6 +191,7 @@ func roomTemplatesPreview( baseFile := "templates/base.gohtml" tmpl := template.Must(template.New("").Funcs(template.FuncMap{ "bricksForPerson": bricksForPerson, + "personsFromRoom": personsFromRoom, }).ParseFS(templateFs, baseFile, "templates/tableTemplates.gohtml")) err := tmpl.ExecuteTemplate(w, "full-page", pageData) diff --git a/routes/templates/tableTemplates.gohtml b/routes/templates/tableTemplates.gohtml index 03cc301..fc306d3 100644 --- a/routes/templates/tableTemplates.gohtml +++ b/routes/templates/tableTemplates.gohtml @@ -82,16 +82,29 @@
{{ block "personBlocks" .TestPerson }} -{{ range (bricksForPerson .) }} -{{ template "brick" . }} -{{ end }} -

{{ .Name }}

+
+ {{ range (bricksForPerson .) }} + {{ template "brick" . }} + {{ end }} +

{{ .Name }}

+
{{ end }}

And now i'll want to get all persons for a room

+
+ {{ block "roomPeople" .ARoom }} +
+ {{ range (personsFromRoom .) }} + {{ template "personBlocks" . }} + {{ end }} +
+ {{end}} +
{{end}}