Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,34 @@ func main() {
closedPolls = uniquePolls(closedPolls)

c.HTML(200, "index.tmpl", gin.H{
"Polls": polls,
"Polls": polls,
"Username": claims.UserInfo.Username,
"FullName": claims.UserInfo.FullName,
})
}))

r.GET("/closed", csh.AuthWrapper(func(c *gin.Context) {
cl, _ := c.Get("cshauth")
claims := cl.(cshAuth.CSHClaims)

closedPolls, err := database.GetClosedVotedPolls(c, claims.UserInfo.Username)
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}
ownedPolls, err := database.GetClosedOwnedPolls(c, claims.UserInfo.Username)
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}
closedPolls = append(closedPolls, ownedPolls...)

sort.Slice(closedPolls, func(i, j int) bool {
return closedPolls[i].Id > closedPolls[j].Id
})
closedPolls = uniquePolls(closedPolls)

c.HTML(200, "closed.tmpl", gin.H{
"ClosedPolls": closedPolls,
"Username": claims.UserInfo.Username,
"FullName": claims.UserInfo.FullName,
Expand Down Expand Up @@ -430,6 +457,7 @@ func main() {
"IsOpen": poll.Open,
"IsHidden": poll.Hidden,
"CanModify": canModify,
"CanVote": canVote(claims.UserInfo, *poll, poll.AllowedUsers),
"Username": claims.UserInfo.Username,
"FullName": claims.UserInfo.FullName,
"Gatekeep": poll.Gatekeep,
Expand Down
48 changes: 48 additions & 0 deletions templates/closed.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSH Vote</title>
<!-- <link rel="stylesheet" href="https://themeswitcher.csh.rit.edu/api/get" /> -->
<link
rel="stylesheet"
href="https://assets.csh.rit.edu/csh-material-bootstrap/4.3.1/dist/csh-material-bootstrap.min.css"
media="screen"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
ul {
list-style: none;
}
</style>
</head>
<body>

{{ template "nav" . }}
<div class="container main p-5">
<h2>
<div class="d-inline">Closed Polls</div>
</h2>
<br />
<div>
<ul class="list-group">
{{ range $i, $poll := .ClosedPolls }}
<li>
<a
class="list-group-item list-group-item-action"
href="/results/{{ $poll.Id }}"
>
<span style="font-size: 1.1rem">
{{ $poll.ShortDescription }}
</span>

<span
><i>(created by {{ $poll.CreatedBy }})</i></span
>
</a>
</li>
{{ end }}
</ul>
</div>
</div>
</body>
</html>
14 changes: 2 additions & 12 deletions templates/create.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="/">Vote</a>
<div class="nav navbar-nav ml-auto">
<div class="navbar-user">
<img alt="User profile photo" src="https://profiles.csh.rit.edu/image/{{ .Username }}" />
<span class="text-light">{{ .FullName }}</span>
<a href="/auth/logout" style="color: #c3c3c3;"><i>(logout)</i></a>
</div>
</div>
</div>
</nav>
{{ template "nav" . }}

<div class="container main p-5">
<h2>Create Poll</h2>
<form action="/create" method="POST">
Expand Down
15 changes: 2 additions & 13 deletions templates/hidden.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,8 @@
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="/">Vote</a>
<div class="nav navbar-nav ml-auto">
<div class="navbar-user">
<img src="https://profiles.csh.rit.edu/image/{{ .Username }}" />
<span class="text-light">{{ .FullName }}</span>
<a href="/auth/logout" style="color: #c3c3c3"><i>(logout)</i></a>
</div>
</div>
</div>
</nav>

{{ template "nav" . }}

<div
style="text-align: center; font-size: 1.2rem"
class="main p-5 error-page align-center"
Expand Down
48 changes: 5 additions & 43 deletions templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,8 @@
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="/">Vote</a>
<div class="nav navbar-nav ml-auto">
<div class="navbar-user">
<img src="https://profiles.csh.rit.edu/image/{{ .Username }}" />
<span class="text-light">{{ .FullName }}</span>
<a href="/auth/logout" style="color: #c3c3c3;"><i>(logout)</i></a>
</div>
</div>
</div>
</nav>

{{ template "nav" . }}
<div class="container main p-5">
<h2>
<div class="d-inline">Active Polls</div>
Expand All @@ -47,43 +36,16 @@
class="list-group-item list-group-item-action"
href="/poll/{{ $poll.Id }}"
>
<span style="font-size: 1.1rem; white-space: normal; word-wrap: break-word;">{{
$poll.ShortDescription
}}</span>

<span
><i>(created by {{ $poll.CreatedBy }})</i></span
>
</a>
</li>
{{
end
}}
</ul>
</div>
<br />
<h3>Closed Polls</h3>
<br />
<div>
<ul class="list-group">
{{ range $i, $poll := .ClosedPolls }}
<li>
<a
class="list-group-item list-group-item-action"
href="/results/{{ $poll.Id }}"
>
<span style="font-size: 1.1rem">{{
$poll.ShortDescription
}}</span>
<span style="font-size: 1.1rem; white-space: normal; word-wrap: break-word;">
{{ $poll.ShortDescription }}
</span>

<span
><i>(created by {{ $poll.CreatedBy }})</i></span
>
</a>
</li>
{{
end
}}
{{ end }}
</ul>
</div>
</div>
Expand Down
18 changes: 18 additions & 0 deletions templates/nav.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{ define "nav" }}
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="/">Vote</a>
<a class="nav-item nav-link text-light " href="/">Open Polls</a>
<a class="nav-item nav-link text-light " href="/closed">Closed Polls</a>
<a class="nav-item nav-link text-light " href="/create">Create Poll</a>
<div class="nav navbar-nav ml-auto">
<div class="navbar-user">
<img src="https://profiles.csh.rit.edu/image/{{ .Username }}" />
<span class="text-light">{{ .FullName }}</span>
<a href="/auth/logout" style="color: #c3c3c3;"><i>(logout)</i></a>
</div>
</div>
</div>
</nav>

{{ end }}
13 changes: 1 addition & 12 deletions templates/poll.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="/">Vote</a>
<div class="nav navbar-nav ml-auto">
<div class="navbar-user">
<img src="https://profiles.csh.rit.edu/image/{{ .Username }}" />
<span class="text-light">{{ .FullName }}</span>
<a href="/auth/logout" style="color: #c3c3c3;"><i>(logout)</i></a>
</div>
</div>
</div>
</nav>
{{ template "nav" . }}

<div class="container main p-5">
<h2 style="white-space: normal; word-wrap: break-word;">{{ .ShortDescription }}</h2>
Expand Down
47 changes: 35 additions & 12 deletions templates/result.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,44 @@
media="screen"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<style>
.container div.d-none {
display: none!important;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="/">Vote</a>
<div class="nav navbar-nav ml-auto">
<div class="navbar-user">
<img src="https://profiles.csh.rit.edu/image/{{ .Username }}" />
<span class="text-light">{{ .FullName }}</span>
<a href="/auth/logout" style="color: #c3c3c3;"><i>(logout)</i></a>
</div>
</div>
</div>
</nav>
{{ template "nav" . }}

<div class="container main p-5">
{{ if eq .CanVote 9 }}
<div id="already-voted" class="alert alert-info alert-dismissible d-flex flex-row align-items-center" role="alert">
<h5 class="m-0">You have already voted in this poll.</h5>
<button class="close m-0" style="cursor: pointer;" onclick="document.getElementById('already-voted').classList.add('d-none');">
<span class="align-items-center">&times;</span>
</button>
</div>
{{ else if eq .CanVote 1 }}
<div id="db-error" class="alert alert-danger alert-dismissible d-flex flex-row align-items-center" role="alert">
<h5 class="m-0">There was an error checking your voting eligibility. Try refreshing the page or contacting the RTPs if the issue persists.</h5>
<button class="close m-0" style="cursor: pointer;" onclick="document.getElementById('db-error').classList.add('d-none');">
<span class="align-items-center">&times;</span>
</button>
</div>
{{ else if gt .CanVote 1 }}
<div id="cannot-vote" class="alert alert-warning alert-dismissible d-flex flex-row align-items-center" role="alert">
<h5 class="m-0">
You are not eligible to vote in this poll. This is likely because you are not an Active Member,
or because you did not meet the gatekeep requirements by the time the poll opened.
If you believe this is an error, please contact Evals or Opcomm.
</h5>
<button class="close m-0 ml-3" style="cursor: pointer;" onclick="document.getElementById('cannot-vote').classList.add('d-none');">
<span class="align-items-center">&times;</span>
</button>
</div>
{{ end }}

<h2 style="white-space: normal; word-wrap: break-word;">{{ .ShortDescription }}</h2>
{{ if .LongDescription }}
<h4>{{ .LongDescription | MakeLinks }}</h4>
Expand All @@ -38,6 +60,7 @@
<h4>Results will be available once the poll closes</h4>
</div>
{{ else }}

{{/* Displays information about required quorum and number of voters */}}
<div id="quorum-info">
<h5>Number of Eligible Voters: {{ len .EligibleVoters }}</h5>
Expand Down
13 changes: 1 addition & 12 deletions templates/unauthorized.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,7 @@
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="/">Vote</a>
<div class="nav navbar-nav ml-auto">
<div class="navbar-user">
<img src="https://profiles.csh.rit.edu/image/{{ .Username }}" />
<span class="text-light">{{ .FullName }}</span>
<a href="/auth/logout" style="color: #c3c3c3;"><i>(logout)</i></a>
</div>
</div>
</div>
</nav>
{{ template "nav" . }}

<div
style="text-align: center; font-size: 1.2rem"
Expand Down