From 0ec28551af9e7c54ac354c71f9c38340b493d011 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Fri, 2 May 2014 14:42:14 +0100 Subject: [PATCH] Gracefully handle elections for which we don't yet have results --- views/resultsdistrict.haml | 43 +++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/views/resultsdistrict.haml b/views/resultsdistrict.haml index f2f5c0b..62ecc9b 100644 --- a/views/resultsdistrict.haml +++ b/views/resultsdistrict.haml @@ -33,6 +33,12 @@ %h1= @district.name + " " + @district.body.district_name +- @election_held = Candidacy.sum(:votes, :election => @election, :district => @district) + +- unless @election_held + .warning + We don't have the results for this election yet. + %h2 Votes by party %table @@ -53,16 +59,26 @@ %td.right= count %td{ :style => "background-color: #{row['party_colour'] }" }   %td= row['party_name'] - %td.right.highlight= row['num_seats'] + - if @election_held + %td.right.highlight= row['num_seats'] + - else + %td.right.highlight — %td.right= row['num_candidates'] - %td.right= commify(row['total_votes']) - %td.right= format_percent(row['total_votes'].to_f / @total_votes * 100) + - if @election_held + %td.right= commify(row['total_votes']) + %td.right= format_percent(row['total_votes'].to_f / @total_votes * 100) + - else + %td.right — + %td.right — %tr.footer %td   %td   %td   - %td.right.highlight= @total_seats + - if @election_held + %td.right.highlight= @total_seats + - else + %td.right.highlight   %td.right= @total_candidates %td.right= commify(@total_votes) %td   @@ -91,15 +107,18 @@ = candidacy.candidate.short_name %td.org = party_name(candidacy.labcoop, candidacy.party.name) - - %td.right= commify(candidacy.votes) - - %td.right= format_percent(candidacy.votes.to_f / @total_votes * 100) - - - if candidacy.seats == 1 - %td.elected="Elected" + - if @election_held + %td.right= commify(candidacy.votes) + %td.right= format_percent(candidacy.votes.to_f / @total_votes * 100) + + - if candidacy.seats == 1 + %td.elected="Elected" + - else + %td   - else - %td   + %td.right — + %td.right — + %td %tr.footer %td