Close votes automatically after 7 days

Closes #1
This commit is contained in:
ricola 2025-06-08 15:57:26 -06:00
parent cac94c2379
commit e474a9a8ea
14 changed files with 283 additions and 97 deletions

View file

@ -8,6 +8,15 @@
<script src="/Chart.bundle.js"></script>
<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>
<% if current_user %>
<p><%= _("Logged in as %{email}.") % { email: current_user.email } %> <a href="/logout"><%= _("Logout") %></a></p>

View file

@ -1,3 +1,3 @@
<%= _("Visit the following link to reset your password:") %>
<%= _("Visit this link to reset your password:") %>
<%= "#{settings.base_url}reset/#{@reset}" %>

View file

@ -0,0 +1,7 @@
<%= _("Results:") %>
<% i = 0 %><% vote.candidates.sort { |a, b| a.mj <=> b.mj }.reverse.each do |candidate| %><% i = i + 1 %>
<%= "#{i}. #{candidate.name}" %>
<% end %>
<%= _("Visit this link to see the full results:") %>
<%= "#{settings.base_url}votes/#{vote.secure_id}" %>

View file

@ -56,7 +56,7 @@
<h3><%= _("Actions for organizers") %></h2>
<form action="/votes/<%= @vote.secure_id %>/open" method="post">
<form action="/votes/<%= @vote.secure_id %>/open" method="get">
<% if @vote.candidates.length < 2 %>
<button type="submit" disabled><%= _("Open vote to participants") %></button>
<p><%= _("Add at least 2 candidates before opening the vote to participants.") %></p>

28
views/votes_open.erb Normal file
View file

@ -0,0 +1,28 @@
<h1><%= _("Open vote") %></h1>
<p><%= _("Closing date: #{format_date(@expire_on)}") %></p>
<p><%= _("The vote will automatically close on that date and the results will
be sent to all users by email.") %></p>
<p><%= _("You won't be able to modify or delete this vote anymore after
opening it.") %></p>
<form action="/votes/<%= @vote.secure_id %>/open" method="post">
<button type="submit"><%= _("Open vote to participants") %></button>
</form>
<form action="/votes/<%= @vote.secure_id %>" method="get">
<button type="submit"><%= _("Cancel") %></button>
</form>
<h2><%= @vote.title %></h2>
<p><%= @vote.description %></p>
<h2><%= _("Candidates") %></h2>
<% @vote.candidates.each do |candidate| %>
<h3><%= candidate.name %></h3>
<p><%= candidate.description %></p>
<% end %>

View file

@ -1,7 +1,13 @@
<h1><%= @vote.title %></h1>
<% if @vote.expire_on %>
<p><%= _("Closing date: #{format_date(@vote.expire_on)}") %></p>
<% end %>
<p><%= @vote.description %></p>
<% if @vote.ratings.length > 0 %>
<h2><%= _("All ratings") %></h2>
<table>
@ -62,6 +68,14 @@ end
%>
<%= bar_chart data, colors: colors, stacked: true, legend: 'bottom' %>
<% else %>
<h2><%= _("Results") %></h2>
<%= _("No results are available because nobody voted on this vote.") %>
<% end %>
<h2><%= _("Organizers") %></h2>
<ul>
@ -70,7 +84,7 @@ end
<% end %>
</ul>
<% if @vote.users.exists?(current_user.id) %>
<% if @vote.users.exists?(current_user.id) and @vote.expire_on.nil? %>
<h3><%= _("Actions for organizers") %></h3>

View file

@ -1,5 +1,9 @@
<h1><%= @vote.title %></h1>
<% if @vote.expire_on %>
<p><%= _("Closing date: #{format_date(@vote.expire_on)}") %></p>
<% end %>
<p><%= @vote.description %></p>
<h2><%= _("Your ratings") %></h2>
@ -39,7 +43,7 @@
<% end %>
</ul>
<% if @vote.users.exists?(current_user.id) %>
<% if @vote.users.exists?(current_user.id) and @vote.expire_on.nil? %>
<h3><%= _("Actions for organizers") %></h3>