14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/growth/stats_controller.rb', line 14
def show
resource = params[:id].camelize
respond_to do |format|
format.html do
Growth::Transactions::GenerateRetentionReport.new.call(associations: params['association']) do |m|
m.success do |result|
render :show, locals: {resource: resource, report: result[:report]}
end
m.failure do |result|
render :show, locals: {resource: resource, report: result[:report]}
end
end
end
format.csv do
source_resources_count = params[:source_resources_count].to_i
target_resources_count = params[:target_resources_count].to_i
Growth::Transactions::GenerateRetentionReport.new.call(associations: params['association']) do |m|
m.success do |result|
stats = result[:report][:resources_stats].find do |stats|
stats[:total_source_resources] == source_resources_count
stats[:total_target_resources] == target_resources_count
end
resources = resource.constantize.find(stats[:total_source_resources_ids])
send_data to_csv(resources), filename: "#{resource.pluralize}-#{Date.today}.csv"
end
m.failure do |result|
raise 'failed to export csv'
end
end
end
end
end
|