Преглед изворни кода

Add votes by party table

tags/last-sinatra-version
Adrian Short пре 12 година
родитељ
комит
8c2c4bbede
2 измењених фајлова са 56 додато и 2 уклоњено
  1. +21
    -0
      app.rb
  2. +35
    -2
      views/resultsdistrict.haml

+ 21
- 0
app.rb Прегледај датотеку

@@ -176,6 +176,27 @@ get '/bodies/:body/elections/:date/:districts_name/:district' do
@candidacies = Candidacy.all(:district => @district, :election => @election, :order => [:votes.desc])
@total_votes = Candidacy.sum(:votes, :district => @district, :election => @election)
@districts_in_this_election = @election.candidacies.districts
@results_by_party = repository(:default).adapter.select("
SELECT
p.name AS party_name,
p.colour AS party_colour,
COUNT(c.id) AS num_candidates,
SUM(c.votes) AS total_votes

FROM candidacies c
LEFT JOIN parties p
ON c.party_id = p.id
WHERE c.district_id = #{@district.id}
AND c.election_id = #{@election.id}
GROUP BY p.name
ORDER BY total_votes DESC
")
haml :resultsdistrict
end



+ 35
- 2
views/resultsdistrict.haml Прегледај датотеку

@@ -33,7 +33,39 @@

%h1= @district.name + " " + @district.body.district_name

- count = 0
%h2 Votes by party

%table
%tr.header
%th
%th
%th
%th candidates
%th.right votes
%th.right % votes
- count = 0
- @results_by_party.each do |row|
- count += 1
%tr
%td.right= count
%td{ :style => "background-color: #{row['party_colour'] }" }  
%td= row['party_name']
%td.right= row['num_candidates']
%td.right= commify(row['total_votes'])
%td.right= format_percent(row['total_votes'].to_f / @total_votes * 100)
%tr.footer
%td
%td
%td
%td
%td.right= commify(@total_votes)
%td


%h2 Votes by candidate
%table
%tr.header
@@ -44,6 +76,7 @@
%th.right % votes
%th

- count = 0
- for candidacy in @candidacies
- count += 1
%tr.vcard
@@ -69,7 +102,7 @@
%td
%td
%td
%td= commify(@total_votes)
%td.right= commify(@total_votes)
%td
%td
%td

Loading…
Откажи
Сачувај