@@ -5,70 +5,58 @@ class ReportsController < ApplicationController
55 def index ; end
66
77 def features
8- forms = Reports ::FormDocumentsService . live_form_documents
8+ tag = params [ :tag ]
9+ forms = Reports ::FormDocumentsService . form_documents ( tag :)
910 data = Reports ::FeatureReportService . new ( forms ) . report
1011
11- render template : "reports/features" , locals : { data : }
12+ render template : "reports/features" , locals : { tag : , data : }
1213 end
1314
1415 def questions_with_answer_type
16+ tag = params [ :tag ]
1517 answer_type = params . require ( :answer_type )
16- forms = Reports ::FormDocumentsService . live_form_documents
18+ forms = Reports ::FormDocumentsService . form_documents ( tag : )
1719 questions = Reports ::FeatureReportService . new ( forms ) . questions_with_answer_type ( answer_type )
1820
19- render template : "reports/questions_with_answer_type" , locals : { answer_type :, questions : }
20- end
21-
22- def questions_with_add_another_answer
23- forms = Reports ::FormDocumentsService . live_form_documents
24- questions = Reports ::FeatureReportService . new ( forms ) . questions_with_add_another_answer
25-
2621 if params [ :format ] == "csv"
2722 send_data Reports ::QuestionsCsvReportService . new ( questions ) . csv ,
2823 type : "text/csv; charset=iso-8859-1" ,
29- disposition : "attachment; filename=#{ csv_filename ( 'live_questions_with_add_another_answer_report' ) } "
24+ disposition : "attachment; filename=#{ questions_csv_filename ( tag , answer_type ) } "
3025 else
31- render template : "reports/feature_report " , locals : { report : params [ :action ] , records : questions }
26+ render template : "reports/questions_with_answer_type " , locals : { tag : , answer_type : , questions : }
3227 end
3328 end
3429
30+ def questions_with_add_another_answer
31+ tag = params [ :tag ]
32+ forms = Reports ::FormDocumentsService . form_documents ( tag :)
33+ questions = Reports ::FeatureReportService . new ( forms ) . questions_with_add_another_answer
34+
35+ questions_feature_report ( tag , params [ :action ] , questions )
36+ end
37+
3538 def forms_with_routes
36- forms = Reports ::FormDocumentsService . live_form_documents
39+ tag = params [ :tag ]
40+ forms = Reports ::FormDocumentsService . form_documents ( tag :)
3741 forms = Reports ::FeatureReportService . new ( forms ) . forms_with_routes
3842
39- if params [ :format ] == "csv"
40- send_data Reports ::FormsCsvReportService . new ( forms ) . csv ,
41- type : "text/csv; charset=iso-8859-1" ,
42- disposition : "attachment; filename=#{ csv_filename ( 'live_forms_with_routes_report' ) } "
43- else
44- render template : "reports/feature_report" , locals : { report : params [ :action ] , records : forms }
45- end
43+ forms_feature_report ( tag , params [ :action ] , forms )
4644 end
4745
4846 def forms_with_payments
49- forms = Reports ::FormDocumentsService . live_form_documents
47+ tag = params [ :tag ]
48+ forms = Reports ::FormDocumentsService . form_documents ( tag :)
5049 forms = Reports ::FeatureReportService . new ( forms ) . forms_with_payments
5150
52- if params [ :format ] == "csv"
53- send_data Reports ::FormsCsvReportService . new ( forms ) . csv ,
54- type : "text/csv; charset=iso-8859-1" ,
55- disposition : "attachment; filename=#{ csv_filename ( 'live_forms_with_payments_report' ) } "
56- else
57- render template : "reports/feature_report" , locals : { report : params [ :action ] , records : forms }
58- end
51+ forms_feature_report ( tag , params [ :action ] , forms )
5952 end
6053
6154 def forms_with_csv_submission_enabled
62- forms = Reports ::FormDocumentsService . live_form_documents
55+ tag = params [ :tag ]
56+ forms = Reports ::FormDocumentsService . form_documents ( tag :)
6357 forms = Reports ::FeatureReportService . new ( forms ) . forms_with_csv_submission_enabled
6458
65- if params [ :format ] == "csv"
66- send_data Reports ::FormsCsvReportService . new ( forms ) . csv ,
67- type : "text/csv; charset=iso-8859-1" ,
68- disposition : "attachment; filename=#{ csv_filename ( 'live_forms_with_csv_submission_enabled_report' ) } "
69- else
70- render template : "reports/feature_report" , locals : { report : params [ :action ] , records : forms }
71- end
59+ forms_feature_report ( tag , params [ :action ] , forms )
7260 end
7361
7462 def users
@@ -120,27 +108,42 @@ def live_forms_csv
120108 end
121109
122110 def live_questions_csv
123- answer_type = params [ :answer_type ]
124111 forms = Reports ::FormDocumentsService . live_form_documents
125- questions = if answer_type
126- Reports ::FeatureReportService . new ( forms ) . questions_with_answer_type ( answer_type )
127- else
128- Reports ::FeatureReportService . new ( forms ) . questions
129- end
112+ questions = Reports ::FeatureReportService . new ( forms ) . questions
130113
131114 send_data Reports ::QuestionsCsvReportService . new ( questions ) . csv ,
132115 type : "text/csv; charset=iso-8859-1" ,
133- disposition : "attachment; filename=#{ questions_csv_filename ( answer_type ) } "
116+ disposition : "attachment; filename=#{ csv_filename ( 'live_questions_report' ) } "
134117 end
135118
136119private
137120
121+ def questions_feature_report ( tag , report , questions )
122+ if params [ :format ] == "csv"
123+ send_data Reports ::QuestionsCsvReportService . new ( questions ) . csv ,
124+ type : "text/csv; charset=iso-8859-1" ,
125+ disposition : "attachment; filename=#{ csv_filename ( "#{ tag } _#{ report } _report" ) } "
126+ else
127+ render template : "reports/feature_report" , locals : { tag :, report :, records : questions }
128+ end
129+ end
130+
131+ def forms_feature_report ( tag , report , forms )
132+ if params [ :format ] == "csv"
133+ send_data Reports ::FormsCsvReportService . new ( forms ) . csv ,
134+ type : "text/csv; charset=iso-8859-1" ,
135+ disposition : "attachment; filename=#{ csv_filename ( "#{ tag } _#{ report } _report" ) } "
136+ else
137+ render template : "reports/feature_report" , locals : { tag :, report :, records : forms }
138+ end
139+ end
140+
138141 def check_user_has_permission
139142 authorize Report , :can_view_reports?
140143 end
141144
142- def questions_csv_filename ( answer_type )
143- base_name = "live_questions_report "
145+ def questions_csv_filename ( tag , answer_type )
146+ base_name = "#{ tag } _questions_report "
144147 base_name += "_#{ answer_type } _answer_type" if answer_type . present?
145148 csv_filename ( base_name )
146149 end
0 commit comments