1require 'csv' |
|
3class Admin::StatisticsController < Admin::AdminController |
|
4 after_action :set_content_disposition, if: :csv_request?, except: [:index] |
|
6 def index |
|
7 respond_to do |format| |
|
8 format.html
|
|
9 end |
|
10 end |
|
12 def moderation |
|
13 @rows = Statistics.moderation(by: period, parliament: parliament) |
|
15 respond_to do |format| |
|
16 format.csv
|
|
17 end |
|
18 end |
|
20 private
|
|
22 def parliament |
|
23 if params.key?(:parliament) |
|
24 Parliament.find(params[:parliament]) |
|
25 end |
|
26 end |
|
28 def period |
|
29 params[:period] |
|
30 end |
|
32 def csv_filename |
|
33 if params.key?(:parliament) |
|
34 "#{action_name}-#{parliament.period}-by-#{period}.csv" |
|
35 else |
|
36 "#{action_name}-by-#{period}.csv" |
|
37 end |
|
38 end |
|
40 def set_content_disposition |
|
41 response.headers['Content-Disposition'] = "attachment; filename=#{csv_filename}" |
|
42 end |
|
43end |