An open source, stand-alone, customisable public spending data web app.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

111 lines
2.3 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. haml :directorate
  30. end
  31. get '/suppliers/:id.csv' do
  32. @supplier = Supplier.get(params[:id])
  33. headers "Content-Disposition" => "attachment;filename=supplier#{@supplier.id}.csv",
  34. "Content-Type" => "application/octet-stream"
  35. result = "Date,Trans No,Directorate,Service,Amount ex. VAT\n"
  36. for payment in @supplier.payments
  37. result += "#{payment.d.strftime("%d %b %Y")},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.service.name},#{sprintf("%0.2f", payment.amount)}\n"
  38. end
  39. result
  40. end
  41. get '/suppliers/:id' do
  42. @supplier = Supplier.get(params[:id])
  43. haml :supplier
  44. end
  45. get '/suppliers/?' do
  46. @suppliers = Supplier.all( :order => ['name'] )
  47. haml :suppliers
  48. end
  49. get '/services/:id.csv' do
  50. @service = Service.get(params[:id])
  51. headers "Content-Disposition" => "attachment;filename=service#{@service.id}.csv",
  52. "Content-Type" => "application/octet-stream"
  53. result = "Date,Trans No,Directorate,Supplier,Amount ex. VAT\n"
  54. for payment in @service.payments
  55. result += "#{payment.d.strftime("%d %b %Y")},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.supplier.name},#{sprintf("%0.2f", payment.amount)}\n"
  56. end
  57. result
  58. end
  59. get '/services/:id' do
  60. @service = Service.get(params[:id])
  61. haml :service
  62. end
  63. get '/services/?' do
  64. @services = Service.all( :order => ['name'] )
  65. haml :services
  66. end
  67. get '/wards/:slug/postcode/:postcode/?' do
  68. @ward = Ward.first(:slug => params[:slug])
  69. @postcode = params[:postcode]
  70. haml :wards
  71. end
  72. get '/wards/:slug/?' do
  73. @ward = Ward.first(:slug => params[:slug])
  74. haml :wards
  75. end
  76. get '/error' do
  77. haml :error
  78. end
  79. get '/about' do
  80. haml :about
  81. end
  82. not_found do
  83. haml :not_found
  84. end