vedia/views/votes_show_closed.erb

222 lines
9.8 KiB
Text

<div class="mb-5">
<h1><%= @vote.title %></h1>
<ul class="list-unstyled">
<li>
<span class="badge bg-dark text-bg-dark"><%= _("Closed") %></span>
<% if @vote.users.exists?(current_user.id) %>
<span class="badge bg-warning text-bg-warning"><%= _("Organizer") %></span>
<% end %>
</li>
<% if @vote.expire_on %>
<li><%= _("Closed on %{date}") % { date: format_date_and_time(@vote.expire_on) } %></li>
<% end %>
</ul>
</div>
<div class="mb-5">
<div class="lead">
<%= markdown(@vote.description) %>
</div>
</div>
<div class="mb-5"></div>
<h2 class="mb-4"><%= _("Results") %></h2>
<% if @vote.ratings.blank? %>
<%= _("No results are available because nobody voted on this vote.") %>
<% else %>
<% r = 0 %>
<% @results = @vote.candidates.sort { |a, b| a.mj <=> b.mj }.reverse %>
<% @results.each do |c| %>
<% r = r + 1 %>
<div class="card mb-4">
<div class="card-body">
<% if r == 1 %>
<p class="fs-5">
<i class="bi bi-trophy-fill"></i>
<%= _("Winning candidate") %>
</p>
<p><%= _("The winning candidate is the candidate with the highest median vote (↓), called <a href='https://en.wikipedia.org/wiki/Majority_judgment'><i>majority judgment</i></a>.") %></p>
<% end %>
<p class="fs-5">
<%= "##{r}" %>
<%= erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == c.mj.mj }.first } %>
</p>
<h3><%= c.name %></h3>
<table class="table table-borderless">
<tr>
<% (1..c.mj.n).each do |i| %>
<td class="p-0 text-center <% unless i == c.mj.majority %>opacity-0<% end %>">↓</td>
<% end %>
</tr>
<tr>
<% settings.values.reverse.each do |v| %>
<% (1..c.mj.count[v[:id]]).each do |r| %>
<td class="p-0 mj-cell mj-cell-<%= v[:id] %>">&nbsp;</td>
<% end %>
<% end %>
</tr>
</table>
<p class="d-inline-flex gap-3">
<a class="btn btn-outline-primary" data-bs-toggle="collapse" href="#description-<%= r %>" role="button" aria-expanded="false" aria-controls="description-<%= r %>">
<%= _("See description") %>
</a>
<% if r > 1 and c.mj.mj == @results.first.mj.mj %>
<a class="btn btn-primary" data-bs-toggle="collapse" href="#tiebreak-<%= r %>" role="button" aria-expanded="false" aria-controls="tiebreak-<%= r %>">
<%= _("Analyze tiebreak") %>
</a>
<% end %>
</p>
<div id="content-wrapper-<%= r %>">
<div class="collapse" data-bs-parent="#content-wrapper-<%= r %>" id="description-<%= r %>">
<%= markdown(c.description) %>
</div>
<% if r > 1 and c.mj.mj == @results.first.mj.mj %>
<div class="collapse" data-bs-parent="#content-wrapper-<%= r %>" id="tiebreak-<%= r %>">
<p>
<%= _("This candidate and the winning candidate have the same majority judgment.") %>
</p>
<p><%= _("To break the tie, we remove the vote that corresponds to the majority judgment one-by-one until one candidate has a better majority judgment than the other.") %></p>
<div class="row fw-bold">
<div class="col"><%= _("Votes for this candidate") %></div>
<div class="col text-end"><%= _("Votes for the winning candidate") %></div>
</div>
<table class="table table-borderless tiebreak">
<% n = 0 %>
<% previous = nil %>
<% max = @results.first.mj.n * 2 + 1 %>
<% c.mj.break_tie(@results.first.mj).each do |a, b| %>
<tr class="tiebreak-top">
<td colspan="<%= max %>"></td>
</tr>
<tr class="tiebreak-round">
<td colspan="<%= max %>">
<% if n == 0 %>
<% current = erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == a.mj }.first } %>
<%= _("Without removing any vote, both candidates have the same majority judgement of %{current}.") % { current: current } %>
<% end %>
<% if n == 1 %>
<% if a.mj == b.mj %>
<% current = erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == a.mj }.first } %>
<%= _("Removing a vote of rating %{previous}, both candidates still have the same majority judgement of %{current}.") % { previous: previous, current: current } %>
<% else %>
<% losing = erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == a.mj }.first } %>
<% winning = erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == b.mj }.first } %>
<%= _("Removing a vote of rating %{previous}, this candidate has a majority judgement of %{losing}, but the winning candidate has a majority judgement of %{winning}.") % { previous: previous, losing: losing, winning: winning } %>
<% end %>
<% end %>
<% if n > 1 %>
<% if a.mj == b.mj %>
<% current = erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == a.mj }.first } %>
<%= _("Removing another vote of rating %{previous}, both candidates still have the same majority judgement of %{current}.") % { previous: previous, current: current } %>
<% else %>
<% losing = erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == a.mj }.first } %>
<% winning = erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == b.mj }.first } %>
<%= _("Removing another vote of rating %{previous}, this candidate has a majority judgement of %{losing}, but the winning candidate has a majority judgement of %{winning}.") % { previous: previous, losing: losing, winning: winning } %>
<% end %>
<% end %>
<% previous = erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == a.mj }.first } %>
</td>
</tr>
<tr>
<% (1..a.n).each do |i| %>
<td class="p-0 text-center <% unless i == a.majority %>opacity-0<% end %>">↓</td>
<% end %>
<td colspan="<%= max - a.n - b.n %>"></td>
<% (1..b.n).each do |i| %>
<td class="p-0 text-center <% unless b.n - i + 1 == b.majority %>opacity-0<% end %>">↓</td>
<% end %>
</tr>
<tr>
<% i = 0 %>
<% settings.values.reverse.each do |v| %>
<% (1..a.count[v[:id]]).each do |r| %>
<% i = i + 1 %>
<td class="p-0 mj-cell mj-cell-<%= v[:id] %><% if i == a.majority and a.mj == b.mj %> mj-cell-majority<% end %>">&nbsp;</td>
<% end %>
<% end %>
<td class="p-0 text-center fw-bold" colspan="<%= max - a.n - b.n %>">
<% if a.mj < b.mj %><<% end %>
<% if a.mj > b.mj %>><% end %>
<% if a.mj == b.mj %>=<% end %>
</td>
<% i = 0 %>
<% settings.values.each do |v| %>
<% (1..b.count[v[:id]]).each do |r| %>
<% i = i + 1 %>
<td class="p-0 mj-cell mj-cell-<%= v[:id] %><% if b.n - i + 1 == b.majority and a.mj == b.mj %> mj-cell-majority<% end %>">&nbsp;</td>
<% end %>
<% end %>
</tr>
<% n = n + 1 %>
<% end %>
</table>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
<div class="mb-5"></div>
<h2 class="mb-4"><%= _("Ratings") + " (#{@vote.ratings.collect { |rating| rating.user }.uniq.count})" %></h2>
<table class="table table-striped w-auto mb-5">
<thead>
<tr>
<th><%= _("Participant") %></th>
<% @vote.candidates.each do |candidate| %>
<th><%= candidate.name %></th>
<% end %>
</tr>
</thead>
<% @vote.ratings.collect { |rating| rating.user }.uniq.sort_by { |user| user.email }.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 class="h5">
<%= erb :rating_badge, :locals => { :value => settings.values.select { |e| e[:id] == rating.value }.first } %>
</td>
<% end %>
<% end %>
</tr>
<% end %>
</table>
<% end %>
<% if @vote.users.exists?(current_user.id) and @vote.expire_on.nil? %>
<form action="/votes/<%= @vote.secure_id %>/reopen" method="post" class="mb-5">
<button type="submit" class="btn btn-outline-primary"><%= _("Reopen voting period") %></button>
</form>
<% end %>
<h2 class="mb-4"><%= _("Organizers") %></h2>
<ul>
<% @vote.organizers.each do |organizer| %>
<li><%= organizer.user.email %></li>
<% end %>
</ul>
<% if @vote.users.exists?(current_user.id) and @vote.expire_on.nil? %>
<h3 class="mb-3"><%= _("Add organizer") %></h3>
<form action="/votes/<%= @vote.secure_id %>/organizers" 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>
<button type="submit" class="btn btn-outline-primary"><%= _("Add organizer") %></button>
</form>
<% end %>