Compare commits
No commits in common. "38a37137d004c1c2512c7f917850fd2a29bb5a97" and "a93ae1269b49c6be427406285dacd729e7a80ff0" have entirely different histories.
38a37137d0
...
a93ae1269b
10 changed files with 40 additions and 88 deletions
52
vedia.rb
52
vedia.rb
|
|
@ -133,18 +133,17 @@ post '/login' do
|
|||
end
|
||||
session.clear
|
||||
session[:user_id] = user.id
|
||||
session[:timezone] = params[:timezone]
|
||||
if params[:r]
|
||||
redirect params[:r]
|
||||
else
|
||||
redirect '/'
|
||||
end
|
||||
redirect '/'
|
||||
else
|
||||
@error = _("Incorrect email or password.")
|
||||
erb :login
|
||||
end
|
||||
end
|
||||
|
||||
post '/timezone' do
|
||||
session[:timezone] = JSON.parse(request.body.read)['timezone']
|
||||
end
|
||||
|
||||
get '/reset' do
|
||||
erb :reset
|
||||
end
|
||||
|
|
@ -318,26 +317,19 @@ post '/votes/new' do
|
|||
end
|
||||
|
||||
get '/votes/:id' do
|
||||
require_login
|
||||
find_vote
|
||||
if not @vote
|
||||
erb :votes_show_unknown
|
||||
else
|
||||
if not current_user
|
||||
erb :votes_show_unauthenticated
|
||||
case @vote.state
|
||||
when 'draft'
|
||||
if @vote.users.exists?(current_user.id)
|
||||
erb :votes_edit
|
||||
else
|
||||
case @vote.state
|
||||
when 'draft'
|
||||
if @vote.users.exists?(current_user.id)
|
||||
erb :votes_edit
|
||||
else
|
||||
erb :votes_show_draft
|
||||
end
|
||||
when 'open'
|
||||
erb :votes_show_open
|
||||
when 'closed'
|
||||
erb :votes_show_closed
|
||||
end
|
||||
erb :votes_show_draft
|
||||
end
|
||||
when 'open'
|
||||
erb :votes_show_open
|
||||
when 'closed'
|
||||
erb :votes_show_closed
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -518,15 +510,15 @@ post '/votes/:id/ratings' do
|
|||
end
|
||||
if not @errors.empty?
|
||||
@params = params
|
||||
erb :votes_show_open
|
||||
else
|
||||
@vote.candidates.each do |candidate|
|
||||
rating = Rating.find_or_initialize_by(vote: @vote, user: current_user, candidate: candidate)
|
||||
rating.value = params[candidate.id.to_s]
|
||||
rating.save
|
||||
end
|
||||
@voted = true
|
||||
redirect '/votes/' + @vote.secure_id
|
||||
end
|
||||
erb :votes_show_open
|
||||
end
|
||||
|
||||
get '/votes/:id/organizers' do
|
||||
|
|
@ -602,11 +594,10 @@ helpers do
|
|||
end
|
||||
|
||||
def require_login
|
||||
redirect "/login?r=#{request.path}" unless current_user
|
||||
redirect '/login' unless current_user
|
||||
end
|
||||
|
||||
def require_admin
|
||||
require_login
|
||||
redirect '/' unless is_admin
|
||||
end
|
||||
|
||||
|
|
@ -643,7 +634,12 @@ helpers do
|
|||
end
|
||||
|
||||
def format_date(timestamp)
|
||||
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F')}"
|
||||
if session[:timezone]
|
||||
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F')}"
|
||||
else
|
||||
# Otherwise, format_date fails on first page after login. Not sure why...
|
||||
"#{timestamp.strftime('%F')}"
|
||||
end
|
||||
end
|
||||
|
||||
def format_date_and_time(timestamp)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<h2 class="mb-4"><%= _("Users") %></h2>
|
||||
|
||||
<ul class="mb-5">
|
||||
<% @users.sort_by { |user| user.email }.each do |user| %>
|
||||
<% @users.reverse.each do |user| %>
|
||||
<li>
|
||||
<a href="/admin/users/<%= user.id %>"><%= user.email %></a>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
<% unless @vote.ratings.blank? %>
|
||||
|
||||
<ul>
|
||||
<% @vote.ratings.collect { |rating| rating.user }.uniq.sort_by { |user| user.email }.each do |user| %>
|
||||
<% @vote.ratings.collect { |rating| rating.user }.uniq.each do |user| %>
|
||||
<li>
|
||||
<%= user.email %>
|
||||
<a href="/admin/votes/<%= @vote.id %>/ratings/<%= user.id %>/delete"><%= _("Delete") %></a>
|
||||
|
|
|
|||
|
|
@ -3,18 +3,22 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<% if @vote %>
|
||||
<title>Vedia · <%= @vote.title %></title>
|
||||
<meta property="og:title" content="<%= @vote.title %>"/>
|
||||
<% else %>
|
||||
<title>Vedia</title>
|
||||
<% end %>
|
||||
<title>Vedia</title>
|
||||
<script src="/chartkick.js"></script>
|
||||
<script src="/Chart.bundle.js"></script>
|
||||
<link rel="stylesheet" href="/bootstrap.css">
|
||||
<link rel="stylesheet" href="/bootstrap-icons.css">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
</head>
|
||||
<script>
|
||||
fetch('/timezone', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone })
|
||||
});
|
||||
</script>
|
||||
<body>
|
||||
<div class="container py-4">
|
||||
|
||||
|
|
@ -42,8 +46,6 @@
|
|||
<div class="d-flex flex-wrap justify-content-end pe-3 py-3 mb-4">
|
||||
<% if current_user %>
|
||||
<%= current_user.email %>
|
||||
<% else %>
|
||||
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<p class="alert alert-warning mb-4"><%= @error %></p>
|
||||
<% end %>
|
||||
|
||||
<form action="/login" name="login" method="post" class="mb-5">
|
||||
<form action="/login" method="post" class="mb-5">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label"><%= _("Email") %></label>
|
||||
<input type="text" name="email" class="form-control">
|
||||
|
|
@ -14,12 +14,6 @@
|
|||
<input type="password" name="password" class="form-control">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><%= _("Login") %></button>
|
||||
<input type="hidden" name="r" value="<%= @params[:r] %>">
|
||||
<input type="hidden" name="timezone" value="UTC">
|
||||
</form>
|
||||
<p><a href="/signup"><%= _("Create account") %></a></p>
|
||||
<p><a href="/reset"><%= _("Reset password") %></a></p>
|
||||
|
||||
<script>
|
||||
document.login.timezone.value = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -14,11 +14,6 @@
|
|||
<% when 'closed' %>
|
||||
<SPAN class="badge bg-dark"><%= _("Closed") %></span>
|
||||
<% end %>
|
||||
<% if vote.ratings.find { |rating| rating.user == current_user } %>
|
||||
<span class="badge bg-success"><%= _("Voted") %></span>
|
||||
<% elsif vote.state == 'open' %>
|
||||
<span class="badge bg-danger"><%= _("Not voted") %></span>
|
||||
<% end %>
|
||||
<% if vote.users.exists?(current_user.id) %>
|
||||
<span class="badge bg-warning text-bg-warning"><%= _("Organizer") %></span>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ end
|
|||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<% @vote.ratings.collect { |rating| rating.user }.uniq.sort_by { |user| user.email }.each do |user| %>
|
||||
<% @vote.ratings.collect { |rating| rating.user }.uniq.each do |user| %>
|
||||
<tr>
|
||||
<td><%= user.email %></td>
|
||||
<% @vote.candidates.each do |candidate| %>
|
||||
|
|
|
|||
|
|
@ -3,11 +3,6 @@
|
|||
<ul class="list-unstyled">
|
||||
<li>
|
||||
<span class="badge bg-primary"><%= _("Open") %></span>
|
||||
<% if @vote.ratings.find { |rating| rating.user == current_user } %>
|
||||
<span class="badge bg-success"><%= _("Voted") %></span>
|
||||
<% else %>
|
||||
<span class="badge bg-danger"><%= _("Not voted") %></span>
|
||||
<% end %>
|
||||
</li>
|
||||
<% if @vote.expire_on %>
|
||||
<li><%= _("Closes on %{date}") % { date: format_date_and_time(@vote.expire_on) } %></li>
|
||||
|
|
@ -31,10 +26,6 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @voted %>
|
||||
<p class="alert alert-success mb-4"><%= _("Gràcies per votar!") %></p>
|
||||
<% end %>
|
||||
|
||||
<form action="/votes/<%= @vote.secure_id %>/ratings" method="post" class="mb-5">
|
||||
|
||||
<% @vote.candidates.each do |candidate| %>
|
||||
|
|
@ -63,10 +54,10 @@
|
|||
<button type="submit" class="btn btn-primary"><%= _("Vote") %></button>
|
||||
</form>
|
||||
|
||||
<h2 class="mb-4"><%= _("Participants") + " (#{@vote.ratings.collect { |rating| rating.user }.uniq.count})" %></h2>
|
||||
<h2 class="mb-4"><%= _("Participants") %></h2>
|
||||
|
||||
<ul class="mb-5">
|
||||
<% @vote.ratings.collect { |rating| rating.user }.uniq.sort_by { |user| user.email }.each do |user| %>
|
||||
<% @vote.ratings.collect { |rating| rating.user }.uniq.each do |user| %>
|
||||
<li><%= user.email %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
<div class="mb-5">
|
||||
<h1><%= @vote.title %></h1>
|
||||
</div>
|
||||
|
||||
<p class="alert alert-warning mb-4"><%= _("You need to log in to see the details of this vote.") %></p>
|
||||
|
||||
<form action="/login" method="post" class="mb-5">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label"><%= _("Email") %></label>
|
||||
<input type="text" name="email" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label"><%= _("Password") %></label>
|
||||
<input type="password" name="password" class="form-control">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><%= _("Login") %></button>
|
||||
<input type="hidden" name="r" value="votes/<%= @vote.secure_id %>">
|
||||
<input type="hidden" name="timezone" value="UTC">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.login.timezone.value = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
</script>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
<div class="mb-5">
|
||||
<h1><%= _("Vote not found...") %></h1>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue