An open source, stand-alone, customisable public spending data web app.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

114 lignes
2.5 KiB

  1. require 'rubygems'
  2. require 'sinatra'
  3. require 'sinatra-helpers/haml/partials'
  4. require 'haml'
  5. require 'lib/models'
  6. get '/' do
  7. @directorates = Directorate.all
  8. # @results = repository(:default).adapter.query("
  9. # SELECT p.name,
  10. # sum(c.votes_2010) AS votes,
  11. # p.colour
  12. #
  13. # FROM parties p,
  14. # councilcandidates c
  15. #
  16. # WHERE p.id = c.party_id
  17. #
  18. # GROUP BY p.name, p.colour
  19. #
  20. # ORDER BY votes desc
  21. # ;")
  22. # select p.name, count(c.*) AS seats
  23. # FROM parties p, councilcandidates c
  24. # GROUP BY p.id
  25. haml :home
  26. end
  27. get '/directorates/:id' do
  28. @directorate = Directorate.get(params[:id])
  29. @total = @directorate.payments.sum(:amount)
  30. haml :directorate
  31. end
  32. get '/suppliers/:id.csv' do
  33. @supplier = Supplier.get(params[:id])
  34. headers "Content-Disposition" => "attachment;filename=supplier#{@supplier.id}.csv",
  35. "Content-Type" => "application/octet-stream"
  36. result = "Date,Trans No,Directorate,Service,Amount ex. VAT\n"
  37. for payment in @supplier.payments
  38. result += "#{payment.d.strftime("%d %b %Y")},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.service.name},#{sprintf("%0.2f", payment.amount)}\n"
  39. end
  40. result
  41. end
  42. get '/suppliers/:id' do
  43. @supplier = Supplier.get(params[:id])
  44. @total = @supplier.payments.sum(:amount)
  45. haml :supplier
  46. end
  47. get '/suppliers/?' do
  48. @suppliers = Supplier.all( :order => ['name'] )
  49. haml :suppliers
  50. end
  51. get '/services/:id.csv' do
  52. @service = Service.get(params[:id])
  53. headers "Content-Disposition" => "attachment;filename=service#{@service.id}.csv",
  54. "Content-Type" => "application/octet-stream"
  55. result = "Date,Trans No,Directorate,Supplier,Amount ex. VAT\n"
  56. for payment in @service.payments
  57. result += "#{payment.d.strftime("%d %b %Y")},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.supplier.name},#{sprintf("%0.2f", payment.amount)}\n"
  58. end
  59. result
  60. end
  61. get '/services/:id' do
  62. @service = Service.get(params[:id])
  63. @total = @service.payments.sum(:amount)
  64. haml :service
  65. end
  66. get '/services/?' do
  67. @services = Service.all( :order => ['name'] )
  68. haml :services
  69. end
  70. get '/wards/:slug/postcode/:postcode/?' do
  71. @ward = Ward.first(:slug => params[:slug])
  72. @postcode = params[:postcode]
  73. haml :wards
  74. end
  75. get '/wards/:slug/?' do
  76. @ward = Ward.first(:slug => params[:slug])
  77. haml :wards
  78. end
  79. get '/error' do
  80. haml :error
  81. end
  82. get '/about' do
  83. haml :about
  84. end
  85. not_found do
  86. haml :not_found
  87. end