Bläddra i källkod

Sort candidate's candidacies in date order. Fix #7

This needs to be written as an SQL query as there's no way I can see in
DataMapper to order a result set by a column in a joined table (the
election date).
tags/last-sinatra-version
Adrian Short 13 år sedan
förälder
incheckning
97d77da9cc
2 ändrade filer med 44 tillägg och 13 borttagningar
  1. +31
    -0
      app.rb
  2. +13
    -13
      views/candidate.haml

+ 31
- 0
app.rb Visa fil

@@ -159,6 +159,37 @@ end

get '/candidates/:id/?' do
if @candidate = Candidate.get(params[:id])
@candidacies = repository(:default).adapter.select("
SELECT
e.d,
c.*,
p.name AS party_name,
p.colour AS party_colour,
b.name AS body_name,
b.slug AS body_slug,
b.districts_name AS districts_name,
d.name AS district_name,
d.slug AS district_slug
FROM candidacies c
INNER JOIN elections e
ON c.election_id = e.id
INNER JOIN parties p
ON c.party_id = p.id
INNER JOIN bodies b
ON e.body_id = b.id
INNER JOIN districts d
ON c.district_id = d.id
WHERE c.candidate_id = #{@candidate.id}
ORDER BY d
")
haml :candidate
else
404


+ 13
- 13
views/candidate.haml Visa fil

@@ -17,22 +17,22 @@
%th position
%th  
- @candidate.candidacies.each do |ccy|
- @candidacies.each do |ccy|
%tr
%td{ :style => "background-color: #{ccy.party.colour}" }  
%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
%a{ :href => "/bodies/#{ccy['body_slug']}/elections/#{ccy['d']}" }
= long_date(Date.parse(ccy['d']))
%td= ccy['party_name']
%td
%a{ :href => "/bodies/#{ccy.election.body.slug}" }
= ccy.election.body.name
%a{ :href => "/bodies/#{ccy['body_slug']}" }
= ccy['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
%td.right= commify(ccy.votes)
%td.right= to_ordinal(ccy.position)
%td= ccy.seats == 1 ? "Elected" : "Not elected"
%a{ :href => "/bodies/#{ccy['body_slug']}/elections/#{ccy['d']}/#{ccy['districts_name']}/#{ccy['district_slug']}" }
= ccy['district_name']
%td.right= commify(ccy['votes'])
%td.right= to_ordinal(ccy['position'])
%td= ccy['seats'] == 1 ? "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.

Laddar…
Avbryt
Spara