From 9cd672229729908aad07dceb3a6d8f801ecb393f Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Wed, 11 Jan 2012 22:36:36 +0000 Subject: [PATCH] New views aplenty --- views/bodies.haml | 6 +++ views/body.haml | 24 ++++++++++ views/candidate.haml | 39 ++++++++++++++++ views/candidates.haml | 23 ++++++++++ views/district.haml | 40 ++++++++++++++++ views/electionsummary.haml | 94 ++++++++++++++++++++++++++++++++++++++ views/register.haml | 10 ++++ views/resultsdistrict.haml | 74 ++++++++++++++++++++++++++++++ 8 files changed, 310 insertions(+) create mode 100644 views/bodies.haml create mode 100644 views/body.haml create mode 100644 views/candidate.haml create mode 100644 views/candidates.haml create mode 100644 views/district.haml create mode 100644 views/electionsummary.haml create mode 100644 views/register.haml create mode 100644 views/resultsdistrict.haml diff --git a/views/bodies.haml b/views/bodies.haml new file mode 100644 index 0000000..9f0db4d --- /dev/null +++ b/views/bodies.haml @@ -0,0 +1,6 @@ +%h1= @page_title = "Government Bodies" + +- @bodies.each do |body| + %p + %a{ :href => "/bodies/#{body.slug}" } + = body.name \ No newline at end of file diff --git a/views/body.haml b/views/body.haml new file mode 100644 index 0000000..449582f --- /dev/null +++ b/views/body.haml @@ -0,0 +1,24 @@ +.nav + %a{ :href => "/bodies" } + « Government bodies + +%h1= @page_title = @body.name + +%h2 Elections + +%table + - @body.elections.each do |election| + %tr + %td + %a{ :href => "/bodies/#{@body.slug}/elections/#{election.d}" }< + = long_date(election.d) + %td + = election.kind + +%h2 + = @body.districts_name.capitalize + +- @body.districts.each do |district| + %p + %a{ :href => "/bodies/#{@body.slug}/#{@body.districts_name}/#{district.slug}" } + = district.name \ No newline at end of file diff --git a/views/candidate.haml b/views/candidate.haml new file mode 100644 index 0000000..c1e135d --- /dev/null +++ b/views/candidate.haml @@ -0,0 +1,39 @@ +.nav + %a{ :href => "/candidates" } + « All candidates + +%h1= @page_title = @candidate.name + +%h2 Elections contested + +%table + %tr + %th + %th date + %th party + %th body + %th district + %th votes + %th position + %th + + - @candidate.candidacies.each do |ccy| + %tr + %td{ :style => "background-color: #{ccy.party.colour}" }   + %td + %a{ :href => "/bodies/#{ccy.election.body.slug}/elections/#{ccy.election.d}" } + = long_date(ccy.election.d) + %td= ccy.party.name + %td + %a{ :href => "/bodies/#{ccy.election.body.slug}" } + = ccy.election.body.name + %td + %a{ :href => "/bodies/#{ccy.election.body.slug}/elections/#{ccy.election.d}/#{ccy.district.body.districts_name}/#{ccy.district.slug}" } + = ccy.district.name + = ccy.district.body.district_name + %td.right= commify(ccy.votes) + %td.right= to_ordinal(ccy.position) + %td= ccy.elected? ? "Elected" : "Not elected" + +.warning + This might not be the complete electoral history for this candidate. They might have stood in elections outside Sutton and / or in Sutton elections for which we don't have data. \ No newline at end of file diff --git a/views/candidates.haml b/views/candidates.haml new file mode 100644 index 0000000..43a89ba --- /dev/null +++ b/views/candidates.haml @@ -0,0 +1,23 @@ +%h1= @page_title = "Candidates" + +- @first_letter = '' + +%table + - @candidates.each do |c| + - if c.surname[0] != @first_letter + - @first_letter = c.surname[0] + %tr.noborder + %td   + %td + %tr.noborder + %td.strong{ :style => "font-size: 300%;" }= @first_letter.upcase + %td + %tr + %td + %td + %tr + %td + %a{ :href => "/candidates/#{c.id}" } + = c.surname + %td= c.forenames + \ No newline at end of file diff --git a/views/district.haml b/views/district.haml new file mode 100644 index 0000000..de5e98c --- /dev/null +++ b/views/district.haml @@ -0,0 +1,40 @@ +- @page_title = "#{@district.name} #{@district.body.district_name}, #{@district.body.name}" + +.nav + %p + %a{ :href => "/bodies/#{@district.body.slug}" } + «  + = @district.body.name + +%h1= "#{@district.name} #{@district.body.district_name}" + +-# TODO % turnout plotted over time +-# TODO map of district shown within Sutton boundary + +%h2 Candidates elected + +- Election.all(:body => @district.body, :order => [:d.desc]).each do |election| + - ccys = Candidacy.all(:election_id => election.id, :district_id => @district.id, :elected => true, :order => [:votes.desc]) + + - unless ccys == [] + %h3 + %a{ :href => "/bodies/#{@district.body.slug}/elections/#{election.d}/#{election.body.districts_name}/#{@district.slug}"} + = long_date election.d + = election.kind + + %table + %tr + %th + %th + %th + %th + + - ccys.each do |ccy| + %tr + %td= ccy.position + %td{ :style => "background-color: #{ccy.party.colour}" }   + %td + %a{ :href => "/candidates/#{ccy.candidate.id}" } + = ccy.candidate.short_name + %td= ccy.party.name + \ No newline at end of file diff --git a/views/electionsummary.haml b/views/electionsummary.haml new file mode 100644 index 0000000..ec66b75 --- /dev/null +++ b/views/electionsummary.haml @@ -0,0 +1,94 @@ +- @page_title = "#{@election.body.name} #{@election.kind} #{long_date(@election.d)}" + +%h1 + = @election.body.name + = @election.kind + %br + = long_date(@election.d) + +%p= @election.reason + +- if @election.candidacies.count > 0 + + %p + = @election.candidacies.count + = "candidate".pluralize(@election.candidacies.count) + contested + = @total_seats + = "seat".pluralize(@total_seats) + in + = @total_districts + = @election.body.district_name.pluralize(@total_districts) + in Sutton. + + %h2 Seats, votes and candidates by party + + %table + %tr.header + %th + %th + %th.highlight seats won + %th votes + %th % seats + %th % votes + %th votes per seat + %th candidates + %th votes per candidate + -# + %th relative popularity + - @max_votes_per_candidate = @results_by_party.first.votez.to_f / @results_by_party.first.cands.to_f # We really need to scan the array for the max value + - @results_by_party.each do |row| + %tr + %td{ :style => "background-color: #{row.colour}" }   + %td.data_party= row.name + %td.data_seats.right.highlight= row.seatz + %td.data_votes.right= commify(row.votez) + %td.right= format_percent(row.seatz.to_f / @total_seats * 100) + %td.right= format_percent(row.votez.to_f / @total_votes * 100) + %td.data_votes_per_seat.right + - if row.seatz > 0 + = commify(row.votez / row.seatz) + - else + — + %td.data_candidates.right= row.cands + %td.right= commify(row.votez / row.cands) + -# + %td.right= format_percent( ( row.votez.to_f / row.cands.to_f ) / @max_votes_per_candidate * 100) + + + %tr.footer + %td + %td + %td.right.highlight= @total_seats + %td.right= commify(@total_votes) + %td + %td + %td + %td + %td + -# + %td + + %h2 + Results by + = @election.body.district_name + + %table + %tr.header + %th + %th seats + %th votes + - @results_by_district.each do |row| + %tr + %td + %a{ :href => "/bodies/#{@election.body.slug}/elections/#{@election.d}/#{@election.body.districts_name}/#{row.district_slug}"} + = row.name + %td.right= row.seats + %td.right= commify(row.votez) + %tr.footer + %td + %td.right= @total_seats + %td.right= commify(@total_votes) +- else + %p Full details and results will be available on this page. + \ No newline at end of file diff --git a/views/register.haml b/views/register.haml new file mode 100644 index 0000000..849b871 --- /dev/null +++ b/views/register.haml @@ -0,0 +1,10 @@ +%h2 Register to vote + +%p Register now so that you can vote in future elections. If you're not registered you can't vote. + +%p + You can get a registration form at the + %a{ :href => "http://www.aboutmyvote.co.uk/" } About My Vote + website or by phoning Sutton Council on + %span.phone 020 8770 4888. + \ No newline at end of file diff --git a/views/resultsdistrict.haml b/views/resultsdistrict.haml new file mode 100644 index 0000000..52e0ed5 --- /dev/null +++ b/views/resultsdistrict.haml @@ -0,0 +1,74 @@ +- @page_title = "#{@district.name} #{@district.body.district_name} results, #{@body.name} election #{short_date(@election.d)}" + +%p + %a{ :href => "/bodies/#{@district.body.slug}/elections/#{@election.d}" }< + = @body.name + election + = long_date(@election.d) + + +.nav + - if @districts_in_this_election.size > 1 + - @district_index = @districts_in_this_election.index(@district) + + - unless @district_index == 0 + - @previous_district = @districts_in_this_election[@district_index - 1] + %a{ :href => "/bodies/#{@election.body.slug}/elections/#{@election.d}/#{@election.body.districts_name}/#{@previous_district.slug}" }< + «  + = @previous_district.name +     + + - unless @district_index == @districts_in_this_election.size - 1 + - @next_district = @districts_in_this_election[@district_index + 1] + %a{ :href => "/bodies/#{@election.body.slug}/elections/#{@election.d}/#{@election.body.districts_name}/#{@next_district.slug}" }< + = @next_district.name + » + + %p + %a{ :href => "/bodies/#{@district.body.slug}/#{@district.body.district_name.pluralize(2)}/#{@district.slug}" } + All elections in + = @district.name + » + +%h1= @district.name + " " + @district.body.district_name + +- count = 0 + +%table + %tr.header + %th + %th + %th + %th.right votes + %th.right % votes + %th + + - for candidacy in @candidacies + - count += 1 + %tr.vcard + %td= count + %td{ :style => "background-color: #{candidacy.party.colour}" }   + %td + %span.candidate_name.fn + %a{ :href => "/candidates/#{candidacy.candidate.id}" } + = candidacy.candidate.short_name + %br + %span.candidate_party.org + = candidacy.party.name + + %td.right= commify(candidacy.votes) + + %td.right= format_percent(candidacy.votes.to_f / @total_votes * 100) + + %td + - if candidacy.seats == 1 + .elected ELECTED + + %tr.footer + %td + %td + %td + %td= commify(@total_votes) + %td + %td + %td