From f2f8265499a9192be13ce0a99955ab6972a793c3 Mon Sep 17 00:00:00 2001
From: Brian Wiborg
Date: Mon, 13 May 2024 12:46:13 +0200
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Display=20votes=20in=20non-anonymou?=
=?UTF-8?q?s=20voting=20results?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
static/css/tailwind.css | 4 ++++
store/handler.go | 5 +++--
store/prepared.go | 1 +
tmpl/voting.html | 24 ++++++++++++++++++++++++
voting/main.go | 4 ++++
voting/vote/vote.go | 9 ++++++---
6 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/static/css/tailwind.css b/static/css/tailwind.css
index 9a75909..464c063 100644
--- a/static/css/tailwind.css
+++ b/static/css/tailwind.css
@@ -1240,6 +1240,10 @@ input[type="range"]::-ms-fill-lower {
padding-bottom: 2rem;
}
+.pt-4 {
+ padding-top: 1rem;
+}
+
.text-left {
text-align: left;
}
diff --git a/store/handler.go b/store/handler.go
index 5649b3c..61cb3c2 100644
--- a/store/handler.go
+++ b/store/handler.go
@@ -86,6 +86,7 @@ func getVotes(id string) ([]vote.Vote, error) {
return nil, err
}
var (
+ i string
e string
c vote.Choice
ts time.Time
@@ -94,7 +95,7 @@ func getVotes(id string) ([]vote.Vote, error) {
votes = []vote.Vote{}
)
for result.Next() {
- if err = result.Scan(&e, &dbChoice, &dbTimestamp); err != nil {
+ if err = result.Scan(&i, &e, &dbChoice, &dbTimestamp); err != nil {
return nil, err
}
@@ -106,7 +107,7 @@ func getVotes(id string) ([]vote.Vote, error) {
return nil, err
}
- v := vote.NewVoteWithTimestamp(e, c, ts)
+ v := vote.NewVoteWithTimestamp(i, e, c, ts)
votes = append(votes, v)
}
diff --git a/store/prepared.go b/store/prepared.go
index 5286dbb..b7a00e8 100644
--- a/store/prepared.go
+++ b/store/prepared.go
@@ -125,6 +125,7 @@ func initStmtVoteSelect(db *sql.DB) {
var err error
if voteSelect, err = db.Prepare(`
SELECT
+ id,
elector,
choice,
timestamp
diff --git a/tmpl/voting.html b/tmpl/voting.html
index 24936bd..4d83897 100644
--- a/tmpl/voting.html
+++ b/tmpl/voting.html
@@ -118,4 +118,28 @@
Quorum: FAILED
{{ end }}
+ {{ if not .Voting.Anonymous }}
+
+
+
+ VOTES
+
+
+ {{ range $vote := .Voting.Votes }}
+
+
+ {{ $vote.Choice }}
+ |
+
+ {{ $vote.Elector }}
+ |
+
+ {{ $vote.Id }}
+ |
+
+
+
+
+ {{ end }}
+ {{ end }}
{{ end }}
diff --git a/voting/main.go b/voting/main.go
index 705f26d..e45fa89 100644
--- a/voting/main.go
+++ b/voting/main.go
@@ -128,6 +128,10 @@ func (v Voting) Electors() []string {
return electors
}
+func (v Voting) Anonymous() bool {
+ return v.annonymous
+}
+
func (v Voting) IsOpen() bool {
return v.deadline.After(time.Now().UTC())
}
diff --git a/voting/vote/vote.go b/voting/vote/vote.go
index 7a8dad5..2ca4d74 100644
--- a/voting/vote/vote.go
+++ b/voting/vote/vote.go
@@ -6,21 +6,24 @@ import (
)
type Vote struct {
+ Id string
Elector string
Choice Choice
timestamp time.Time
}
-func NewVote(elector string, choice Choice) Vote {
+func NewVote(id, elector string, choice Choice) Vote {
return Vote{
+ Id: id,
Elector: elector,
Choice: choice,
timestamp: time.Now().UTC(),
}
}
-func NewVoteWithTimestamp(elector string, choice Choice, timestamp time.Time) Vote {
+func NewVoteWithTimestamp(id, elector string, choice Choice, timestamp time.Time) Vote {
return Vote{
+ Id: id,
Elector: elector,
Choice: choice,
timestamp: timestamp,
@@ -28,5 +31,5 @@ func NewVoteWithTimestamp(elector string, choice Choice, timestamp time.Time) Vo
}
func (vote Vote) String() string {
- return fmt.Sprintf("%s %s %s", vote.timestamp.Format(time.DateTime), vote.Choice, vote.Elector)
+ return fmt.Sprintf("%s %s %s %s", vote.Id, vote.timestamp.Format(time.DateTime), vote.Choice, vote.Elector)
}