Class: CustomReport::ReportsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- CustomReport::ReportsController
show all
- Defined in:
- app/controllers/custom_report/reports_controller.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
195
196
197
|
# File 'app/controllers/custom_report/reports_controller.rb', line 195
def method_missing(name, *args, &block)
main_app.send(name, *args, &block)
end
|
Instance Method Details
#create ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/custom_report/reports_controller.rb', line 65
def create
@report = CustomReport::Report.new(
:name => params[:report][:name],
:category => params[:report][:category],
:description => params[:report][:description],
:scope => params[:report][:scope],
:columns_yaml => params[:report][:columns_yaml]
)
@report.save
redirect_to report_path(@report)
end
|
#custom_report ⇒ Object
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/custom_report/reports_controller.rb', line 122
def custom_report
if params[:id]
CustomReport::Report.includes(:report_check_items).find params[:id]
elsif params[:report]
CustomReport::Report.new(params[:report])
else
CustomReport::Report.new(:name => "Custom Report", :columns => [["Column 1", "some_method"], ["Column 2", "some_other_method"]])
end
end
|
#custom_reports ⇒ Object
115
116
117
118
119
120
|
# File 'app/controllers/custom_report/reports_controller.rb', line 115
def custom_reports
scope = CustomReport::Report.order("category,name")
scope = scope.where(:administrator_id => params[:show_for]) if params[:show_for].present?
scope = scope.where("custom_report_reports.deleted_at IS NULL") unless params[:show_archived].present?
scope.group_by(&:category)
end
|
#destroy ⇒ Object
152
153
154
155
|
# File 'app/controllers/custom_report/reports_controller.rb', line 152
def destroy
custom_report.update_column(:deleted_at, Time.current)
redirect_to reports_path
end
|
#edit ⇒ Object
77
78
79
80
|
# File 'app/controllers/custom_report/reports_controller.rb', line 77
def edit
set_return_path
@report = CustomReport::Report.find(params[:id])
end
|
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/controllers/custom_report/reports_controller.rb', line 96
def format_column(entity, column, column_index)
format = column[:format] || "text"
raw = entity[column_index].to_s
case format
when "text"
raw
when "strong"
"<strong>#{raw}</strong>"
when "impersonate"
view_context.link_to "Impersonate", impersonate_path(:email => raw)
when "eval"
raw.html_safe
else
"unknown formatter: #{format}"
end
end
|
#get_the_report ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/custom_report/reports_controller.rb', line 35
def get_the_report
begin
@filters = []
@filters.each do |filter|
if filter.first == "options"
filter.each do |key|
next if key == "options"
params[key.to_sym] = true
end
end
end
@filters.reject! {|f| f.first == "options" }
@filter_args = params[:filters] || {}
@results = @report.generate(params, @filter_args)
@iterator = @report.iterator
@columns = @report.columns_hash
@check_items = @report.report_check_items.group_by(&:item_id)
@report.update_column(:last_opened, Time.current)
rescue Exception => e
render :text => "<strong>Error:</strong> <p>#{e.class}: #{e.message}</p><p style='font-family: monospace;'>#{e.backtrace.join("<br>")}</p>"
end
end
|
#index ⇒ Object
17
18
19
|
# File 'app/controllers/custom_report/reports_controller.rb', line 17
def index
@custom_reports = custom_reports
end
|
#new ⇒ Object
61
62
63
|
# File 'app/controllers/custom_report/reports_controller.rb', line 61
def new
@report = CustomReport::Report.new
end
|
#remove_all_check_items ⇒ Object
146
147
148
149
150
|
# File 'app/controllers/custom_report/reports_controller.rb', line 146
def remove_all_check_items
CustomReport::ReportCheckItem.where(:report_id => params[:id]).delete_all
render :js => "$('.check_item').attr('checked',false);"
end
|
#show ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/custom_report/reports_controller.rb', line 21
def show
@report = custom_report
respond_to do |format|
format.html {
get_the_report
}
format.csv {
params[:dont_paginate] = 1
get_the_report
render_csv @results, :filename => "#{custom_report.name.parameterize}-#{Time.now.strftime("%Y%m%d%H%M%S")}", :columns => @columns
}
end
end
|
#toggle_check_item ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'app/controllers/custom_report/reports_controller.rb', line 132
def toggle_check_item
@item = CustomReport::ReportCheckItem.where(:report_id => params[:id], :item_id => params[:item_id]).first
unless @item
@item = CustomReport::ReportCheckItem.new
@item.report_id = params[:id]
@item.item_id = params[:item_id]
@item.save!
else
@item.destroy
end
render :nothing => true
end
|
#unarchive ⇒ Object
91
92
93
94
|
# File 'app/controllers/custom_report/reports_controller.rb', line 91
def unarchive
custom_report.update_column(:deleted_at, nil)
redirect_to custom_reports_path(:show_archived => 1)
end
|
#update ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'app/controllers/custom_report/reports_controller.rb', line 82
def update
set_return_path
if custom_report.update_attributes({"has_checklist" => "false"}.merge(params[:report]).merge(:administrator_type => CustomReport.admin_class))
redirect_to @return_path
else
render "edit"
end
end
|