Top Level Namespace
Defined Under Namespace
Modules: AcFilters, PrawnReport, PrawnReportActiveRecord, PrawnReportController
Classes: AcFilter, AcFilterDef, AcFilterDefsController, AcFilterOption, ActiveRecordYAMLSerializer, AddExcluirToReportTemplate, AddFieldsToFilter, AddFilledCriteriaToOptions, AddFilterDefs, AddFiltersToReports, AddGroupToFilterDef, AddOrderToFilterDef, AddSelectSql, AddSerializationParamsToReport, AddSqlQueryToAcFilterDef, AddSystemCriteriaToAcFilter, ChangeFilledCriteriaUnfilledCriteria, ChangeIncludesAndJoinsToHash, ChangeSelectSql, CreateAcFilterIncludes, CreateAcFilterJoins, CreatePrawnReportCatalogs, CustomGenerateReportController, GenerateReportController, ReportTemplate, ReportTemplatesController
Instance Method Summary
collapse
-
#fill_params(f, fillings) ⇒ Object
-
#fill_with_checkbox(conditions, filled, parsed_filter, filter) ⇒ Object
-
#fill_with_options(conditions, filled, parsed_filter, filter) ⇒ Object
-
#fill_with_others(conditions, filled, parsed_filter, filter) ⇒ Object
-
#fill_with_period(conditions, filled, parsed_filter, filter) ⇒ Object
-
#fill_with_timezone_period(conditions, filled, parsed_filter, filter) ⇒ Object
-
#get_ac_filters_applied(params, ac_filter_def) ⇒ Object
-
#get_param_by_label(params, label) ⇒ Object
-
#is_filled?(parsed_params, filter) ⇒ Boolean
-
#parse_ac_filters(params) ⇒ Object
-
#parse_condition(conditions, parsed_filter, filter) ⇒ Object
-
#parse_conditions(parsed_filter, system_params) ⇒ Object
Instance Method Details
#fill_params(f, fillings) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/ac_filters_utils.rb', line 49
def fill_params(f, fillings)
if ['period', 'timezone_period'].include?(f.data_type)
[fillings['from_date'], fillings['to_date']]
elsif f.data_type == 'text'
'%' + fillings['filter_value'] + '%'
elsif f.data_type == 'options'
fillings['filter_value']
else
fillings['filter_value']
end
end
|
#fill_with_checkbox(conditions, filled, parsed_filter, filter) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/ac_filters_utils.rb', line 98
def fill_with_checkbox(conditions, filled, parsed_filter, filter)
if filled && filter.has_filled_criteria?
conditions[0] << filter.filled_criteria
elsif filter.has_unfilled_criteria?
conditions[0] << filter.unfilled_criteria
end
end
|
#fill_with_options(conditions, filled, parsed_filter, filter) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/ac_filters_utils.rb', line 106
def fill_with_options(conditions, filled, parsed_filter, filter)
if !filled && filter.has_unfilled_criteria?
conditions[0] << c.unfilled_criteria
elsif filled
fo = AcFilterOption.find_by_ac_filter_id_and_value(filter.id, parsed_filter[filter.id]['filter_value'])
if fo && fo.filled_criteria.to_s != ''
conditions[0] << fo.filled_criteria
conditions << fill_params(filter, parsed_filter[filter.id])
elsif filter.has_filled_criteria?
conditions[0] << filter.filled_criteria
conditions << fill_params(filter, parsed_filter[filter.id])
end
end
end
|
#fill_with_others(conditions, filled, parsed_filter, filter) ⇒ Object
153
154
155
156
157
158
159
160
161
|
# File 'lib/ac_filters_utils.rb', line 153
def fill_with_others(conditions, filled, parsed_filter, filter)
if filled && filter.has_filled_criteria?
fp = fill_params(filter, parsed_filter[filter.id])
conditions[0] << filter.filled_criteria
conditions << fp
elsif filter.has_unfilled_criteria?
conditions[0] << filter.unfilled_criteria
end
end
|
#fill_with_period(conditions, filled, parsed_filter, filter) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/ac_filters_utils.rb', line 121
def fill_with_period(conditions, filled, parsed_filter, filter)
if !filled && filter.has_unfilled_criteria?
conditions[0] << c.unfilled_criteria
elsif filled
fp = fill_params(filter, parsed_filter[filter.id])
if fp[0].to_s != ''
conditions[0] << filter.filled_criteria_from
conditions << fp[0]
end
if fp[1].to_s != ''
conditions[0] << filter.filled_criteria_to
conditions << fp[1]
end
end
end
|
#fill_with_timezone_period(conditions, filled, parsed_filter, filter) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/ac_filters_utils.rb', line 137
def fill_with_timezone_period(conditions, filled, parsed_filter, filter)
if !filled && filter.has_unfilled_criteria?
conditions[0] << c.unfilled_criteria
elsif filled
fp = fill_params(filter, parsed_filter[filter.id])
if fp[0].to_s != ''
conditions[0] << filter.filled_criteria_from
conditions << Time.zone.parse(fp[0])
end
if fp[1].to_s != ''
conditions[0] << filter.filled_criteria_to
conditions << Time.zone.parse(fp[1])+1.day
end
end
end
|
#get_ac_filters_applied(params, ac_filter_def) ⇒ Object
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
|
# File 'lib/ac_filters_utils.rb', line 19
def get_ac_filters_applied(params, ac_filter_def)
parsed_filter = parse_ac_filters(params)
r = []
ac_filter_def.ac_filters.each do |f|
if f.query_user? && (parsed_filter[f.id]['is_filled'] == 'true')
pf = parsed_filter[f.id]
val = ''
if ['text', 'options'].include? f.data_type
val = pf['filter_value']
elsif ['period', 'timezone_period'].include?(f.data_type)
if (!pf['from_date'].empty?) && (!pf['to_date'].empty?)
val = "#{Date.parse(pf['from_date']).strftime('%d/%m/%Y')} até #{Date.parse(pf['to_date']).strftime('%d/%m/%Y')}"
elsif !pf['from_date'].empty?
val = "Desde #{Date.parse(pf['from_date']).strftime('%d/%m/%Y')}"
elsif
val = "Até #{Date.parse(pf['to_date']).strftime('%d/%m/%Y')}"
end
elsif f.data_type == 'autocomplete'
val = Kernel.const_get(f.target_model).find(pf['filter_value']).send(f.target_field)
end
r << [f.label, val]
end
end
r
end
|
#get_param_by_label(params, label) ⇒ Object
163
164
165
166
|
# File 'lib/ac_filters_utils.rb', line 163
def get_param_by_label(params, label)
filter = AcFilter.find(:first, :conditions => ['ac_filter_def_id = ? and label = ?',params['filter_def_id'], label])
'ac_filter_'+filter.id.to_s
end
|
#is_filled?(parsed_params, filter) ⇒ Boolean
45
46
47
|
# File 'lib/ac_filters_utils.rb', line 45
def is_filled?(parsed_params, filter)
!parsed_params[filter.id].nil?
end
|
#parse_ac_filters(params) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/ac_filters_utils.rb', line 3
def parse_ac_filters(params)
parsed_filters = {}
parsed_filters['filter_def_id'] = params['filter_def_id'].to_i
params.each_pair do |k,v|
md = /^ac_filter_(\d+)_(.+)/.match(k)
if md
filter_id = md[1]
filter_result_name = md[2].underscore
filter_value = v
parsed_filters[filter_id.to_i] = {} unless parsed_filters[filter_id.to_i]
parsed_filters[filter_id.to_i][filter_result_name] = filter_value
end
end
parsed_filters
end
|
#parse_condition(conditions, parsed_filter, filter) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/ac_filters_utils.rb', line 82
def parse_condition(conditions, parsed_filter, filter)
filled = parsed_filter[filter.id]['is_filled'] == 'true'
if filter.data_type == 'checkbox'
fill_with_checkbox(conditions, filled, parsed_filter, filter)
elsif filter.data_type == 'options'
fill_with_options(conditions, filled, parsed_filter, filter)
elsif filter.data_type == 'period'
fill_with_period(conditions, filled, parsed_filter, filter)
elsif filter.data_type == 'timezone_period'
fill_with_timezone_period(conditions, filled, parsed_filter, filter)
else
fill_with_others(conditions, filled, parsed_filter, filter)
end
end
|
#parse_conditions(parsed_filter, system_params) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/ac_filters_utils.rb', line 61
def parse_conditions(parsed_filter, system_params)
system_params.symbolize_keys!
filter_def = AcFilterDef.find(parsed_filter['filter_def_id'])
conditions = []
conditions[0] = ['1=1']
filter_def.ac_filters.each do |f|
if f.query_user?
parse_condition(conditions, parsed_filter, f)
elsif f.system_criteria.to_s != ''
conditions[0] << f.filled_criteria
conditions << system_params[f.system_criteria.to_sym]
else
conditions[0] << f.filled_criteria
end
end
conditions[0] = conditions[0].join(' and ')
conditions
end
|