✨ Display votes in non-anonymous voting results
This commit is contained in:
parent
58cb8645a4
commit
f2f8265499
6 changed files with 42 additions and 5 deletions
|
@ -1240,6 +1240,10 @@ input[type="range"]::-ms-fill-lower {
|
||||||
padding-bottom: 2rem;
|
padding-bottom: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pt-4 {
|
||||||
|
padding-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
.text-left {
|
.text-left {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ func getVotes(id string) ([]vote.Vote, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
|
i string
|
||||||
e string
|
e string
|
||||||
c vote.Choice
|
c vote.Choice
|
||||||
ts time.Time
|
ts time.Time
|
||||||
|
@ -94,7 +95,7 @@ func getVotes(id string) ([]vote.Vote, error) {
|
||||||
votes = []vote.Vote{}
|
votes = []vote.Vote{}
|
||||||
)
|
)
|
||||||
for result.Next() {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +107,7 @@ func getVotes(id string) ([]vote.Vote, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
v := vote.NewVoteWithTimestamp(e, c, ts)
|
v := vote.NewVoteWithTimestamp(i, e, c, ts)
|
||||||
votes = append(votes, v)
|
votes = append(votes, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,7 @@ func initStmtVoteSelect(db *sql.DB) {
|
||||||
var err error
|
var err error
|
||||||
if voteSelect, err = db.Prepare(`
|
if voteSelect, err = db.Prepare(`
|
||||||
SELECT
|
SELECT
|
||||||
|
id,
|
||||||
elector,
|
elector,
|
||||||
choice,
|
choice,
|
||||||
timestamp
|
timestamp
|
||||||
|
|
|
@ -118,4 +118,28 @@
|
||||||
Quorum: FAILED
|
Quorum: FAILED
|
||||||
</p>
|
</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ if not .Voting.Anonymous }}
|
||||||
|
<div class="relative overflow-x-auto py-4">
|
||||||
|
<table class="w-full text-sm text-left rtl:text-right text-gray-400 text-center mt-4">
|
||||||
|
<thead cols=3>
|
||||||
|
<h1 class="text-center text-4xl border-t border-gray-700 pt-4 text-gray-400">VOTES</h1>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{ range $vote := .Voting.Votes }}
|
||||||
|
<tr class="border-b border-t bg-gray-800 border-gray-700">
|
||||||
|
<td class="px-2 py-2">
|
||||||
|
{{ $vote.Choice }}
|
||||||
|
</td>
|
||||||
|
<td class="px-2 py-2 semibold">
|
||||||
|
{{ $vote.Elector }}
|
||||||
|
</td>
|
||||||
|
<td class="px-2 py-2">
|
||||||
|
{{ $vote.Id }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -128,6 +128,10 @@ func (v Voting) Electors() []string {
|
||||||
return electors
|
return electors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Voting) Anonymous() bool {
|
||||||
|
return v.annonymous
|
||||||
|
}
|
||||||
|
|
||||||
func (v Voting) IsOpen() bool {
|
func (v Voting) IsOpen() bool {
|
||||||
return v.deadline.After(time.Now().UTC())
|
return v.deadline.After(time.Now().UTC())
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,24 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Vote struct {
|
type Vote struct {
|
||||||
|
Id string
|
||||||
Elector string
|
Elector string
|
||||||
Choice Choice
|
Choice Choice
|
||||||
timestamp time.Time
|
timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVote(elector string, choice Choice) Vote {
|
func NewVote(id, elector string, choice Choice) Vote {
|
||||||
return Vote{
|
return Vote{
|
||||||
|
Id: id,
|
||||||
Elector: elector,
|
Elector: elector,
|
||||||
Choice: choice,
|
Choice: choice,
|
||||||
timestamp: time.Now().UTC(),
|
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{
|
return Vote{
|
||||||
|
Id: id,
|
||||||
Elector: elector,
|
Elector: elector,
|
||||||
Choice: choice,
|
Choice: choice,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
|
@ -28,5 +31,5 @@ func NewVoteWithTimestamp(elector string, choice Choice, timestamp time.Time) Vo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vote Vote) String() string {
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue