An open source, stand-alone, customisable public spending data web app.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

87 linhas
2.1 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( :order => ['name'] )
  8. haml :home
  9. end
  10. get '/directorates/:slug' do
  11. @directorate = Directorate.first(:slug => params[:slug])
  12. @total = @directorate.payments.sum(:amount)
  13. haml :directorate
  14. end
  15. get '/suppliers/:slug.csv' do
  16. @supplier = Supplier.first(:slug => params[:slug])
  17. headers "Content-Disposition" => "attachment;filename=supplier-#{@supplier.slug}.csv",
  18. "Content-Type" => "application/octet-stream"
  19. result = "Date,Ref.,URL,Trans No,Directorate,Service,Amount ex. VAT\n"
  20. for payment in @supplier.payments
  21. result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.url},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.service.name},#{sprintf("%0.2f", payment.amount)}\n"
  22. end
  23. result
  24. end
  25. get '/suppliers/:slug' do
  26. @supplier = Supplier.first(:slug => params[:slug])
  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/:slug.csv' do
  35. @service = Service.first(:slug => params[:slug])
  36. headers "Content-Disposition" => "attachment;filename=service-#{@service.slug}.csv",
  37. "Content-Type" => "application/octet-stream"
  38. result = "Date,Ref.,URL,Trans No,Directorate,Supplier,Amount ex. VAT\n"
  39. for payment in @service.payments
  40. result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.url},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.supplier.name},#{sprintf("%0.2f", payment.amount)}\n"
  41. end
  42. result
  43. end
  44. get '/services/:slug' do
  45. @service = Service.first(:slug => params[:slug])
  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 '/payments/:id' do
  54. @payment = Payment.get(params[:id])
  55. haml :payment
  56. end
  57. get '/error' do
  58. haml :error
  59. end
  60. get '/about' do
  61. haml :about
  62. end
  63. not_found do
  64. haml :not_found
  65. end