Skip to content
Merged
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
29 changes: 28 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
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
13 changes: 1 addition & 12 deletions templates/result.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@
<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 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
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