From 1cc2306cbf30173ff333334e3d30048611211113 Mon Sep 17 00:00:00 2001
From: Noah Petherbridge
Date: Tue, 20 Dec 2022 19:15:45 -0800
Subject: [PATCH] Wrap Up Polls Support
* Add the PollVotes table and associated logic.
* Multiple choice polls supported.
* Expiring and non-expiring polls.
* Icons and badges on the forum pages to show posts with polls
* Bugfix: non-explicit users getting SQL errors on Newest Posts page.
---
pkg/config/config.go | 15 +++++
pkg/controller/forum/new_post.go | 22 ++++++-
pkg/controller/poll/vote.go | 91 ++++++++++++++++++++++++++++
pkg/models/forum_recent.go | 2 +-
pkg/models/models.go | 1 +
pkg/models/poll.go | 85 ++++++++++++++++++++++++++
pkg/models/poll_votes.go | 56 ++++++++++++++++-
pkg/router/router.go | 2 +
pkg/utility/time.go | 5 ++
web/templates/forum/board_index.html | 7 +++
web/templates/forum/new_post.html | 18 ++++--
web/templates/forum/newest.html | 4 ++
web/templates/forum/thread.html | 70 +++++++++++++++++----
13 files changed, 356 insertions(+), 22 deletions(-)
create mode 100644 pkg/controller/poll/vote.go
diff --git a/pkg/config/config.go b/pkg/config/config.go
index e45fd62..cf32fbb 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -96,11 +96,26 @@ const (
// rapidly it does not increment the view counter more.
ThreadViewDebounceRedisKey = "debounce-view/user=%d/thr=%d"
ThreadViewDebounceCooldown = 1 * time.Hour
+)
+// Poll settings
+var (
// Max number of responses to accept for a poll (how many form
// values the app will read in). NOTE: also enforced in frontend
// UX in new_post.html, update there if you change this.
PollMaxAnswers = 100
+
+ // Poll color CSS classes (Bulma). Plugged in to templates like:
+ //
- {{if not .EditCommentID}}
+ {{if and (not .EditCommentID) (not .Thread)}}
+
+
+
+
+
-
+
- Poll expires:
+ Poll expires:
@@ -355,7 +365,7 @@
delimiters: ['[[', ']]'],
data() {
return {
- pollVisible: true,
+ pollVisible: pollOptions.length > 0,
answers: [
{value: ""},
{value: ""},
diff --git a/web/templates/forum/newest.html b/web/templates/forum/newest.html
index a88021b..fec9ffd 100644
--- a/web/templates/forum/newest.html
+++ b/web/templates/forum/newest.html
@@ -81,6 +81,10 @@
{{end}}
+ {{if .Thread.PollID}}
+
+ {{end}}
+
{{if .Thread.Explicit}}
{{end}}
diff --git a/web/templates/forum/thread.html b/web/templates/forum/thread.html
index 897382f..04e9e7d 100644
--- a/web/templates/forum/thread.html
+++ b/web/templates/forum/thread.html
@@ -153,27 +153,71 @@
{{if and (eq $i 0) $Root.Thread.PollID}}
Poll
+
+ {{$Poll := $Root.Thread.Poll}}
+ {{$PollResult := $Poll.Result $Root.CurrentUser}}
+
{{end}}