lib/sinatra/handlers/reports.rb in sinatra-hexacta-0.0.2 vs lib/sinatra/handlers/reports.rb in sinatra-hexacta-0.1.0

- old
+ new

@@ -1,27 +1,54 @@ -#TOBEDONE +# encoding: utf-8 +module Sinatra + module ReportHandler + extend Hexacta + + def enable_reports + p "Enabling reports..." + before '/reports/*' do + error(403) if authenticated(User).permissions.empty? + end + + get '/reports' do + slim :reports + end + + get '/reports/:report_name' do |report_name| + date = Date.parse(params["date"]) unless params["date"].nil? + date ||= Date.today + headers "Content-Disposition" => "attachment;filename=#{report_name}.#{date}.xls", + "Content-Type" => "application/octet-stream" + slim "reports/#{report_name}".to_sym, locals: { :date => date }, :layout => false + end + end + + end + + register ReportHandler +end \ No newline at end of file