An open source, stand-alone, customisable public spending data web app.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

101 Zeilen
2.6 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. @results = repository(:default).adapter.query("SELECT COUNT(*) FROM payments")
  9. @payments_count = @results[0]
  10. @results = repository(:default).adapter.query("SELECT COUNT(*) FROM suppliers")
  11. @suppliers_count = @results[0]
  12. @results = repository(:default).adapter.query("SELECT COUNT(*) FROM services")
  13. @services_count = @results[0]
  14. haml :home
  15. end
  16. get '/directorates/:slug' do
  17. @directorate = Directorate.first(:slug => params[:slug])
  18. haml :directorate
  19. end
  20. get '/suppliers/:slug.csv' do
  21. @supplier = Supplier.first(:slug => params[:slug])
  22. headers "Content-Disposition" => "attachment;filename=supplier-#{@supplier.slug}.csv",
  23. "Content-Type" => "application/octet-stream"
  24. result = "Date,Ref.,URL,Directorate,Service,Amount ex. VAT\n"
  25. for payment in @supplier.payments
  26. result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.url},\"#{payment.service.directorate.name}\",#{payment.service.name},#{sprintf("%0.2f", payment.amount)}\n"
  27. end
  28. result
  29. end
  30. get '/suppliers/:slug' do
  31. @supplier = Supplier.first(:slug => params[:slug])
  32. @total = @supplier.payments.sum(:amount)
  33. @count = @supplier.payments.size
  34. @avg = @supplier.payments.avg(:amount)
  35. @max = @supplier.payments.max(:amount)
  36. @min = @supplier.payments.min(:amount)
  37. haml :supplier
  38. end
  39. get '/suppliers/?' do
  40. @suppliers = Supplier.all( :order => ['name'] )
  41. haml :suppliers
  42. end
  43. get '/services/:slug.csv' do
  44. @service = Service.first(:slug => params[:slug])
  45. headers "Content-Disposition" => "attachment;filename=service-#{@service.slug}.csv",
  46. "Content-Type" => "application/octet-stream"
  47. result = "Date,Ref.,URL,Directorate,Supplier,Amount ex. VAT\n"
  48. for payment in @service.payments
  49. result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.url},\"#{payment.service.directorate.name}\",#{payment.supplier.name},#{sprintf("%0.2f", payment.amount)}\n"
  50. end
  51. result
  52. end
  53. get '/services/:slug' do
  54. @service = Service.first(:slug => params[:slug])
  55. @total = @service.payments.sum(:amount)
  56. @count = @service.payments.size
  57. @avg = @service.payments.avg(:amount)
  58. @max = @service.payments.max(:amount)
  59. @min = @service.payments.min(:amount)
  60. haml :service
  61. end
  62. get '/services/?' do
  63. @services = Service.all( :order => ['name'] )
  64. haml :services
  65. end
  66. get '/payments/:id' do
  67. @payment = Payment.get(params[:id])
  68. haml :payment
  69. end
  70. get '/error' do
  71. haml :error
  72. end
  73. get '/about' do
  74. haml :about
  75. end
  76. not_found do
  77. haml :not_found
  78. end