An open source, stand-alone, customisable public spending data web app.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

app.rb 2.0 KiB

14 yıl önce
14 yıl önce
14 yıl önce
14 yıl önce
14 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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( :order => ['name'] )
  8. haml :home
  9. end
  10. get '/directorates/:id' do
  11. @directorate = Directorate.get(params[:id])
  12. @total = @directorate.payments.sum(:amount)
  13. haml :directorate
  14. end
  15. get '/suppliers/:id.csv' do
  16. @supplier = Supplier.get(params[:id])
  17. headers "Content-Disposition" => "attachment;filename=supplier#{@supplier.id}.csv",
  18. "Content-Type" => "application/octet-stream"
  19. result = "Date,Trans No,Directorate,Service,Amount ex. VAT\n"
  20. for payment in @supplier.payments
  21. result += "#{payment.d.strftime("%d %b %Y")},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.service.name},#{sprintf("%0.2f", payment.amount)}\n"
  22. end
  23. result
  24. end
  25. get '/suppliers/:id' do
  26. @supplier = Supplier.get(params[:id])
  27. @total = @supplier.payments.sum(:amount)
  28. haml :supplier
  29. end
  30. get '/suppliers/?' do
  31. @suppliers = Supplier.all( :order => ['name'] )
  32. haml :suppliers
  33. end
  34. get '/services/:id.csv' do
  35. @service = Service.get(params[:id])
  36. headers "Content-Disposition" => "attachment;filename=service#{@service.id}.csv",
  37. "Content-Type" => "application/octet-stream"
  38. result = "Date,Trans No,Directorate,Supplier,Amount ex. VAT\n"
  39. for payment in @service.payments
  40. result += "#{payment.d.strftime("%d %b %Y")},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.supplier.name},#{sprintf("%0.2f", payment.amount)}\n"
  41. end
  42. result
  43. end
  44. get '/services/:id' do
  45. @service = Service.get(params[:id])
  46. @total = @service.payments.sum(:amount)
  47. haml :service
  48. end
  49. get '/services/?' do
  50. @services = Service.all( :order => ['name'] )
  51. haml :services
  52. end
  53. get '/wards/:slug/postcode/:postcode/?' do
  54. @ward = Ward.first(:slug => params[:slug])
  55. @postcode = params[:postcode]
  56. haml :wards
  57. end
  58. get '/wards/:slug/?' do
  59. @ward = Ward.first(:slug => params[:slug])
  60. haml :wards
  61. end
  62. get '/error' do
  63. haml :error
  64. end
  65. get '/about' do
  66. haml :about
  67. end
  68. not_found do
  69. haml :not_found
  70. end