Add state for votes

This commit is contained in:
ricola 2025-04-06 17:04:31 -06:00
parent abc26f733f
commit aefc722c9d
5 changed files with 177 additions and 49 deletions

44
views/votes_results.erb Normal file
View file

@ -0,0 +1,44 @@
<h1><%= @vote.title %></h1>
<p><%= @vote.description %></p>
<form action="/votes/<%= @vote.secure_id %>/reopen" method="post">
<button type="submit">Reopen voting period</button>
</form>
<h2>Organizers</h2>
<ul>
<% @vote.organizers.each do |organizer| %>
<li><%= organizer.user.email %></li>
<% end %>
</ul>
<h2>All ratings</h2>
<table>
<tr>
<th>Participant</th>
<% @vote.candidates.each do |candidate| %>
<th><%= candidate.name %></th>
<% end %>
</tr>
<% @vote.ratings.collect { |rating| rating.user }.uniq.each do |user| %>
<tr>
<td><%= user.email %></td>
<% @vote.candidates.each do |candidate| %>
<% if rating = @vote.ratings.find { |rating| rating.user == user and rating.candidate == candidate } %>
<td><%= rating.value %></td>
<% end %>
<% end %>
</tr>
<% end %>
</table>
<h2>Results</h2>
<ol>
<% @vote.candidates.sort { |a, b| a.mj <=> b.mj }.reverse.each do |candidate| %>
<li><%= candidate.name %>: <%= candidate.mj.mj %></li>
<% end %>
</ol>