active_scaffold 3.1.20 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/jquery/active_scaffold.js +4 -1
- data/app/assets/javascripts/prototype/active_scaffold.js +4 -1
- data/app/assets/stylesheets/{active_scaffold.scss~ → active_scaffold.css.scss} +5 -2
- data/app/assets/stylesheets/{active_scaffold_colors.scss → active_scaffold_colors.css.scss} +4 -0
- data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -0
- data/app/assets/stylesheets/active_scaffold_images.css.scss +43 -0
- data/lib/active_scaffold/actions/core.rb +1 -0
- data/lib/active_scaffold/actions/nested.rb +0 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
- data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -0
- data/lib/active_scaffold/version.rb +2 -2
- data/test/mock_app/.gitignore +2 -0
- metadata +86 -164
- data/app/assets/javascripts/active_scaffold.js.erb~ +0 -16
- data/app/assets/javascripts/jquery/active_scaffold.js~ +0 -1053
- data/app/assets/javascripts/jquery/draggable_lists.js~ +0 -27
- data/app/assets/javascripts/prototype/active_scaffold.js~ +0 -1037
- data/app/assets/stylesheets/active_scaffold.css.erb +0 -11
- data/app/assets/stylesheets/active_scaffold.css.erb~ +0 -11
- data/app/assets/stylesheets/active_scaffold.css.scss.erb~ +0 -1120
- data/app/assets/stylesheets/active_scaffold.css.scss~ +0 -11
- data/app/assets/stylesheets/active_scaffold.css~ +0 -11
- data/app/assets/stylesheets/active_scaffold_colors.css +0 -244
- data/app/assets/stylesheets/active_scaffold_colors.css.scss~ +0 -481
- data/app/assets/stylesheets/active_scaffold_default.css.erb +0 -47
- data/app/assets/stylesheets/active_scaffold_default.css.erb~ +0 -57
- data/app/assets/stylesheets/active_scaffold_default.css.scss~ +0 -1092
- data/app/assets/stylesheets/active_scaffold_default.css~ +0 -923
- data/app/assets/stylesheets/active_scaffold_layout.css~ +0 -922
- data/app/assets/stylesheets/blue-theme.css~ +0 -1150
- data/config/locales/es.yml~ +0 -120
- data/frontends/default/views/_action_group.html.erb~ +0 -24
- data/frontends/default/views/_base_form.html.erb~ +0 -42
- data/frontends/default/views/_form.html.erb~ +0 -26
- data/frontends/default/views/_form_association.html.erb~ +0 -19
- data/frontends/default/views/_form_association_footer.html.erb~ +0 -48
- data/frontends/default/views/_horizontal_subform.html.erb~ +0 -32
- data/frontends/default/views/_horizontal_subform_header.html.erb~ +0 -11
- data/frontends/default/views/_horizontal_subform_record.html.erb~ +0 -38
- data/frontends/default/views/_list_actions.html.erb~ +0 -15
- data/frontends/default/views/_list_inline_adapter.html.erb~ +0 -10
- data/frontends/default/views/_list_messages.html.erb~ +0 -30
- data/frontends/default/views/_list_pagination.html.erb~ +0 -11
- data/frontends/default/views/_list_pagination_links.html.erb~ +0 -0
- data/frontends/default/views/_list_with_header.html.erb~ +0 -36
- data/frontends/default/views/_render_field.js.erb~ +0 -23
- data/frontends/default/views/_row.html.erb~ +0 -6
- data/frontends/default/views/_show.html.erb~ +0 -8
- data/frontends/default/views/_update_form.html.erb~ +0 -6
- data/frontends/default/views/_vertical_subform.html.erb~ +0 -12
- data/frontends/default/views/add_existing.js.erb~ +0 -18
- data/frontends/default/views/add_existing_form.html.erb~ +0 -5
- data/frontends/default/views/create.html.erb~ +0 -5
- data/frontends/default/views/edit_associated.js.erb~ +0 -13
- data/frontends/default/views/on_create.js.erb~ +0 -45
- data/frontends/default/views/on_update.js.erb~ +0 -31
- data/frontends/default/views/render_field.js.erb~ +0 -1
- data/frontends/default/views/search.html.erb~ +0 -5
- data/frontends/default/views/show.html.erb~ +0 -5
- data/frontends/default/views/update.html.erb~ +0 -8
- data/frontends/default/views/update_column.js.erb~ +0 -16
- data/lib/active_scaffold.rb~ +0 -373
- data/lib/active_scaffold/actions/core.rb~ +0 -203
- data/lib/active_scaffold/actions/create.rb~ +0 -148
- data/lib/active_scaffold/actions/list.rb~ +0 -196
- data/lib/active_scaffold/actions/nested.rb~ +0 -247
- data/lib/active_scaffold/actions/search.rb~ +0 -49
- data/lib/active_scaffold/actions/subform.rb~ +0 -27
- data/lib/active_scaffold/actions/update.rb~ +0 -150
- data/lib/active_scaffold/attribute_params.rb~ +0 -203
- data/lib/active_scaffold/bridges/date_picker/helper.rb~ +0 -180
- data/lib/active_scaffold/bridges/record_select/helpers.rb~ +0 -86
- data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
- data/lib/active_scaffold/config/base.rb~ +0 -72
- data/lib/active_scaffold/config/list.rb~ +0 -195
- data/lib/active_scaffold/config/nested.rb~ +0 -41
- data/lib/active_scaffold/config/search.rb~ +0 -74
- data/lib/active_scaffold/constraints.rb~ +0 -186
- data/lib/active_scaffold/data_structures/action_columns.rb~ +0 -140
- data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
- data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -147
- data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +0 -22
- data/lib/active_scaffold/extensions/action_view_rendering.rb~ +0 -120
- data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
- data/lib/active_scaffold/extensions/cache_association.rb~ +0 -12
- data/lib/active_scaffold/extensions/reverse_associations.rb~ +0 -64
- data/lib/active_scaffold/extensions/routing_mapper.rb~ +0 -48
- data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
- data/lib/active_scaffold/finder.rb~ +0 -370
- data/lib/active_scaffold/helpers/controller_helpers.rb~ +0 -92
- data/lib/active_scaffold/helpers/form_column_helpers.rb~ +0 -320
- data/lib/active_scaffold/helpers/id_helpers.rb~ +0 -123
- data/lib/active_scaffold/helpers/list_column_helpers.rb~ +0 -370
- data/lib/active_scaffold/helpers/search_column_helpers.rb~ +0 -263
- data/lib/active_scaffold/helpers/view_helpers.rb~ +0 -350
@@ -1,370 +0,0 @@
|
|
1
|
-
module ActiveScaffold
|
2
|
-
module Finder
|
3
|
-
def self.like_operator
|
4
|
-
@@like_operator ||= ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
# Takes a collection of search terms (the tokens) and creates SQL that
|
9
|
-
# searches all specified ActiveScaffold columns. A row will match if each
|
10
|
-
# token is found in at least one of the columns.
|
11
|
-
def create_conditions_for_columns(tokens, columns, text_search = :full)
|
12
|
-
# if there aren't any columns, then just return a nil condition
|
13
|
-
return unless columns.length > 0
|
14
|
-
like_pattern = like_pattern(text_search)
|
15
|
-
|
16
|
-
tokens = [tokens] if tokens.is_a? String
|
17
|
-
|
18
|
-
where_clauses = []
|
19
|
-
columns.each do |column|
|
20
|
-
where_clauses << ((column.column.nil? || column.column.text?) ? "#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?" : "#{column.search_sql} = ?")
|
21
|
-
end
|
22
|
-
phrase = "(#{where_clauses.join(' OR ')})"
|
23
|
-
|
24
|
-
sql = ([phrase] * tokens.length).join(' AND ')
|
25
|
-
tokens = tokens.collect do |value|
|
26
|
-
columns.collect {|column| (column.column.nil? || column.column.text?) ? like_pattern.sub('?', value) : column.column.type_cast(value)}
|
27
|
-
end.flatten
|
28
|
-
|
29
|
-
[sql, *tokens]
|
30
|
-
end
|
31
|
-
|
32
|
-
# Generates an SQL condition for the given ActiveScaffold column based on
|
33
|
-
# that column's database type (or form_ui ... for virtual columns?).
|
34
|
-
# TODO: this should reside on the column, not the controller
|
35
|
-
def condition_for_column(column, value, text_search = :full)
|
36
|
-
like_pattern = like_pattern(text_search)
|
37
|
-
if self.respond_to?("condition_for_#{column.name}_column")
|
38
|
-
return self.send("condition_for_#{column.name}_column", column, value, like_pattern)
|
39
|
-
end
|
40
|
-
return unless column and column.search_sql and not value.blank?
|
41
|
-
search_ui = column.search_ui || column.column.try(:type)
|
42
|
-
begin
|
43
|
-
if search_ui && self.respond_to?("condition_for_#{search_ui}_type")
|
44
|
-
self.send("condition_for_#{search_ui}_type", column, value, like_pattern)
|
45
|
-
else
|
46
|
-
unless column.search_sql.instance_of? Proc
|
47
|
-
case search_ui
|
48
|
-
when :boolean, :checkbox
|
49
|
-
["#{column.search_sql} = ?", column.column.type_cast(value)]
|
50
|
-
when :integer, :decimal, :float
|
51
|
-
condition_for_numeric(column, value)
|
52
|
-
when :string, :range
|
53
|
-
condition_for_range(column, value, like_pattern)
|
54
|
-
when :date, :time, :datetime, :timestamp
|
55
|
-
condition_for_datetime(column, value)
|
56
|
-
when :select, :multi_select, :country, :usa_state
|
57
|
-
["#{column.search_sql} in (?)", Array(value)]
|
58
|
-
else
|
59
|
-
if column.column.nil? || column.column.text?
|
60
|
-
["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
|
61
|
-
else
|
62
|
-
["#{column.search_sql} = ?", column.column.type_cast(value)]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
else
|
66
|
-
column.search_sql.call(value)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
rescue Exception => e
|
70
|
-
logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column :#{column.name}, search_ui = #{search_ui} in #{self.name}"
|
71
|
-
raise e
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def condition_for_numeric(column, value)
|
76
|
-
if !value.is_a?(Hash)
|
77
|
-
["#{column.search_sql} = ?", condition_value_for_numeric(column, value)]
|
78
|
-
elsif value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt])
|
79
|
-
nil
|
80
|
-
elsif value[:opt] == 'BETWEEN'
|
81
|
-
["#{column.search_sql} BETWEEN ? AND ?", condition_value_for_numeric(column, value[:from]), condition_value_for_numeric(column, value[:to])]
|
82
|
-
else
|
83
|
-
["#{column.search_sql} #{value[:opt]} ?", condition_value_for_numeric(column, value[:from])]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def condition_for_range(column, value, like_pattern = nil)
|
88
|
-
if !value.is_a?(Hash)
|
89
|
-
if column.column.nil? || column.column.text?
|
90
|
-
["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
|
91
|
-
else
|
92
|
-
["#{column.search_sql} = ?", column.column.type_cast(value)]
|
93
|
-
end
|
94
|
-
elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt])
|
95
|
-
condition_for_null_type(column, value[:opt], like_pattern)
|
96
|
-
elsif value[:from].blank?
|
97
|
-
nil
|
98
|
-
elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt])
|
99
|
-
["#{column.search_sql} LIKE ?", value[:opt].sub('?', value[:from])]
|
100
|
-
elsif value[:opt] == 'BETWEEN'
|
101
|
-
["#{column.search_sql} BETWEEN ? AND ?", value[:from], value[:to]]
|
102
|
-
elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt])
|
103
|
-
["#{column.search_sql} #{value[:opt]} ?", value[:from]]
|
104
|
-
else
|
105
|
-
nil
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def condition_value_for_datetime(value, conversion = :to_time)
|
110
|
-
if value.is_a? Hash
|
111
|
-
Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[part].to_i}) rescue nil
|
112
|
-
elsif value.respond_to?(:strftime)
|
113
|
-
value.send(conversion)
|
114
|
-
elsif conversion == :to_date
|
115
|
-
Date.strptime(value, I18n.t('date.formats.default')) rescue nil
|
116
|
-
else
|
117
|
-
parts = Date._parse(value)
|
118
|
-
time_parts = [[:hour, '%H'], [:min, '%M'], [:sec, '%S']].collect {|part, format_part| format_part if parts[part].present?}.compact
|
119
|
-
format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}"
|
120
|
-
time = DateTime.strptime(value, format)
|
121
|
-
time = Time.zone.local_to_utc(time) unless parts[:offset]
|
122
|
-
time.in_time_zone.send(conversion) rescue nil
|
123
|
-
end unless value.nil? || value.blank?
|
124
|
-
end
|
125
|
-
|
126
|
-
def condition_value_for_numeric(column, value)
|
127
|
-
return value if value.nil?
|
128
|
-
value = i18n_number_to_native_format(value) if [:i18n_number, :currency].include?(column.options[:format])
|
129
|
-
case (column.search_ui || column.column.type)
|
130
|
-
when :integer then value.to_i rescue value ? 1 : 0
|
131
|
-
when :float then value.to_f
|
132
|
-
when :decimal then ActiveRecord::ConnectionAdapters::Column.value_to_decimal(value)
|
133
|
-
else
|
134
|
-
value
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def i18n_number_to_native_format(value)
|
139
|
-
native = '.'
|
140
|
-
delimiter = I18n.t('number.format.delimiter')
|
141
|
-
separator = I18n.t('number.format.separator')
|
142
|
-
return value if value.blank? || !value.is_a?(String)
|
143
|
-
unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/
|
144
|
-
value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native)
|
145
|
-
else
|
146
|
-
value
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def condition_for_datetime(column, value, like_pattern = nil)
|
151
|
-
conversion = column.column.type == :date ? :to_date : :to_time
|
152
|
-
from_value = condition_value_for_datetime(value[:from], conversion)
|
153
|
-
to_value = condition_value_for_datetime(value[:to], conversion)
|
154
|
-
|
155
|
-
if from_value.nil? and to_value.nil?
|
156
|
-
nil
|
157
|
-
elsif !from_value
|
158
|
-
["#{column.search_sql} <= ?", to_value.to_s(:db)]
|
159
|
-
elsif !to_value
|
160
|
-
["#{column.search_sql} >= ?", from_value.to_s(:db)]
|
161
|
-
else
|
162
|
-
["#{column.search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)]
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def condition_for_record_select_type(column, value, like_pattern = nil)
|
167
|
-
if value.is_a?(Array)
|
168
|
-
["#{column.search_sql} IN (?)", value]
|
169
|
-
else
|
170
|
-
["#{column.search_sql} = ?", value]
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def condition_for_null_type(column, value, like_pattern = nil)
|
175
|
-
case value.to_sym
|
176
|
-
when :null
|
177
|
-
["#{column.search_sql} is null"]
|
178
|
-
when :not_null
|
179
|
-
["#{column.search_sql} is not null"]
|
180
|
-
else
|
181
|
-
nil
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def like_pattern(text_search)
|
186
|
-
case text_search
|
187
|
-
when :full then '%?%'
|
188
|
-
when :start then '?%'
|
189
|
-
when :end then '%?'
|
190
|
-
else '?'
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
NumericComparators = [
|
196
|
-
'=',
|
197
|
-
'>=',
|
198
|
-
'<=',
|
199
|
-
'>',
|
200
|
-
'<',
|
201
|
-
'!=',
|
202
|
-
'BETWEEN'
|
203
|
-
]
|
204
|
-
StringComparators = {
|
205
|
-
:contains => '%?%',
|
206
|
-
:begins_with => '?%',
|
207
|
-
:ends_with => '%?'
|
208
|
-
}
|
209
|
-
NullComparators = [
|
210
|
-
:null,
|
211
|
-
:not_null
|
212
|
-
]
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
def self.included(klass)
|
217
|
-
klass.extend ClassMethods
|
218
|
-
end
|
219
|
-
|
220
|
-
protected
|
221
|
-
|
222
|
-
attr_writer :active_scaffold_conditions
|
223
|
-
def active_scaffold_conditions
|
224
|
-
@active_scaffold_conditions ||= []
|
225
|
-
end
|
226
|
-
|
227
|
-
attr_writer :active_scaffold_includes
|
228
|
-
def active_scaffold_includes
|
229
|
-
@active_scaffold_includes ||= []
|
230
|
-
end
|
231
|
-
|
232
|
-
attr_writer :active_scaffold_habtm_joins
|
233
|
-
def active_scaffold_habtm_joins
|
234
|
-
@active_scaffold_habtm_joins ||= []
|
235
|
-
end
|
236
|
-
|
237
|
-
def all_conditions
|
238
|
-
merge_conditions(
|
239
|
-
active_scaffold_conditions, # from the search modules
|
240
|
-
conditions_for_collection, # from the dev
|
241
|
-
conditions_from_params, # from the parameters (e.g. /users/list?first_name=Fred)
|
242
|
-
conditions_from_constraints, # from any constraints (embedded scaffolds)
|
243
|
-
active_scaffold_session_storage[:conditions] # embedding conditions (weaker constraints)
|
244
|
-
)
|
245
|
-
end
|
246
|
-
|
247
|
-
# returns a single record (the given id) but only if it's allowed for the specified action.
|
248
|
-
# accomplishes this by checking model.#{action}_authorized?
|
249
|
-
# TODO: this should reside on the model, not the controller
|
250
|
-
def find_if_allowed(id, crud_type, klass = beginning_of_chain)
|
251
|
-
record = klass.find(id)
|
252
|
-
raise ActiveScaffold::RecordNotAllowed, "#{klass} with id = #{id}" unless record.authorized_for?(:crud_type => crud_type.to_sym)
|
253
|
-
return record
|
254
|
-
end
|
255
|
-
|
256
|
-
# returns a hash with options to find records
|
257
|
-
# valid options may include:
|
258
|
-
# * :sorting - a Sorting DataStructure (basically an array of hashes of field => direction, e.g. [{:field1 => 'asc'}, {:field2 => 'desc'}]). please note that multi-column sorting has some limitations: if any column in a multi-field sort uses method-based sorting, it will be ignored. method sorting only works for single-column sorting.
|
259
|
-
# * :per_page
|
260
|
-
# * :page
|
261
|
-
def finder_options(options = {})
|
262
|
-
options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select
|
263
|
-
|
264
|
-
search_conditions = all_conditions
|
265
|
-
full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes)
|
266
|
-
|
267
|
-
# create a general-use options array that's compatible with Rails finders
|
268
|
-
finder_options = { :order => options[:sorting].try(:clause),
|
269
|
-
:where => search_conditions,
|
270
|
-
:joins => joins_for_finder,
|
271
|
-
:includes => full_includes}
|
272
|
-
|
273
|
-
finder_options.merge! custom_finder_options
|
274
|
-
finder_options
|
275
|
-
end
|
276
|
-
|
277
|
-
# Returns a hash with options to count records, rejecting select and order options
|
278
|
-
# See finder_options for valid options
|
279
|
-
def count_options(find_options = {}, count_includes = nil)
|
280
|
-
count_includes ||= find_options[:includes] unless find_options[:where].nil?
|
281
|
-
options = find_options.reject{|k,v| [:select, :order].include? k}
|
282
|
-
options[:includes] = count_includes
|
283
|
-
options
|
284
|
-
end
|
285
|
-
|
286
|
-
# returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters
|
287
|
-
# See finder_options for valid options
|
288
|
-
# TODO: this should reside on the model, not the controller
|
289
|
-
def find_page(options = {})
|
290
|
-
options[:per_page] ||= 999999999
|
291
|
-
options[:page] ||= 1
|
292
|
-
|
293
|
-
find_options = finder_options(options)
|
294
|
-
klass = beginning_of_chain
|
295
|
-
|
296
|
-
# NOTE: we must use :include in the count query, because some conditions may reference other tables
|
297
|
-
if options[:pagination] && options[:pagination] != :infinite
|
298
|
-
count_query = append_to_query(klass, count_options(find_options, options[:count_includes]))
|
299
|
-
debugger
|
300
|
-
count = count_query.count unless options[:pagination] == :infinite
|
301
|
-
end
|
302
|
-
|
303
|
-
# Converts count to an integer if ActiveRecord returned an OrderedHash
|
304
|
-
# that happens when find_options contains a :group key
|
305
|
-
count = count.length if count.is_a? ActiveSupport::OrderedHash
|
306
|
-
|
307
|
-
# we build the paginator differently for method- and sql-based sorting
|
308
|
-
if options[:sorting] and options[:sorting].sorts_by_method?
|
309
|
-
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
|
310
|
-
sorted_collection = sort_collection_by_column(append_to_query(klass, find_options).all, *options[:sorting].first)
|
311
|
-
sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination]
|
312
|
-
sorted_collection
|
313
|
-
end
|
314
|
-
else
|
315
|
-
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
|
316
|
-
find_options.merge!(:offset => offset, :limit => per_page) if options[:pagination]
|
317
|
-
append_to_query(klass, find_options).all
|
318
|
-
end
|
319
|
-
end
|
320
|
-
pager.page(options[:page])
|
321
|
-
end
|
322
|
-
|
323
|
-
def append_to_query(query, options)
|
324
|
-
options.assert_valid_keys :where, :select, :group, :order, :limit, :offset, :joins, :includes, :lock, :readonly, :from
|
325
|
-
options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)|
|
326
|
-
# default ordering of model has a higher priority than current queries ordering
|
327
|
-
# fix this by removing existing ordering from arel
|
328
|
-
if k.to_sym == :order
|
329
|
-
query = query.where('1=1') unless query.is_a?(ActiveRecord::Relation)
|
330
|
-
query = query.except(:order)
|
331
|
-
end
|
332
|
-
query.send((k.to_sym), v)
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
def joins_for_finder
|
337
|
-
case joins_for_collection
|
338
|
-
when String
|
339
|
-
[ joins_for_collection ]
|
340
|
-
when Array
|
341
|
-
joins_for_collection
|
342
|
-
else
|
343
|
-
[]
|
344
|
-
end + active_scaffold_habtm_joins
|
345
|
-
end
|
346
|
-
|
347
|
-
def merge_conditions(*conditions)
|
348
|
-
segments = []
|
349
|
-
conditions.each do |condition|
|
350
|
-
unless condition.blank?
|
351
|
-
sql = active_scaffold_config.model.send(:sanitize_sql, condition)
|
352
|
-
segments << sql unless sql.blank?
|
353
|
-
end
|
354
|
-
end
|
355
|
-
"(#{segments.join(') AND (')})" unless segments.empty?
|
356
|
-
end
|
357
|
-
|
358
|
-
# TODO: this should reside on the column, not the controller
|
359
|
-
def sort_collection_by_column(collection, column, order)
|
360
|
-
sorter = column.sort[:method]
|
361
|
-
collection = collection.sort_by { |record|
|
362
|
-
value = (sorter.is_a? Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter)
|
363
|
-
value = '' if value.nil?
|
364
|
-
value
|
365
|
-
}
|
366
|
-
collection.reverse! if order.downcase == 'desc'
|
367
|
-
collection
|
368
|
-
end
|
369
|
-
end
|
370
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
module ActiveScaffold
|
2
|
-
module Helpers
|
3
|
-
module ControllerHelpers
|
4
|
-
def self.included(controller)
|
5
|
-
controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated}
|
6
|
-
end
|
7
|
-
|
8
|
-
include ActiveScaffold::Helpers::IdHelpers
|
9
|
-
|
10
|
-
def params_for(options = {})
|
11
|
-
# :adapter and :position are one-use rendering arguments. they should not propagate.
|
12
|
-
# :sort, :sort_direction, and :page are arguments that stored in the session. they need not propagate.
|
13
|
-
# and wow. no we don't want to propagate :record.
|
14
|
-
# :commit is a special rails variable for form buttons
|
15
|
-
blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe]
|
16
|
-
unless @params_for
|
17
|
-
@params_for = {}
|
18
|
-
params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value}
|
19
|
-
@params_for[:controller] = '/' + @params_for[:controller].to_s unless @params_for[:controller].to_s.first(1) == '/' # for namespaced controllers
|
20
|
-
@params_for.delete(:id) if @params_for[:id].nil?
|
21
|
-
end
|
22
|
-
@params_for.merge(options)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page)
|
26
|
-
def main_path_to_return
|
27
|
-
if params[:return_to]
|
28
|
-
params[:return_to]
|
29
|
-
else
|
30
|
-
parameters = {}
|
31
|
-
if params[:parent_controller]
|
32
|
-
parameters[:controller] = params[:parent_controller]
|
33
|
-
#parameters[:eid] = params[:parent_controller]
|
34
|
-
end
|
35
|
-
parameters.merge! nested.to_params if nested?
|
36
|
-
if params[:parent_sti]
|
37
|
-
parameters[:controller] = params[:parent_sti]
|
38
|
-
parameters[:eid] = nil
|
39
|
-
end
|
40
|
-
parameters[:parent_column] = nil
|
41
|
-
parameters[:parent_id] = nil
|
42
|
-
parameters[:action] = "index"
|
43
|
-
parameters[:id] = nil
|
44
|
-
parameters[:associated_id] = nil
|
45
|
-
parameters[:utf8] = nil
|
46
|
-
params_for(parameters)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def nested_singular_association?
|
51
|
-
nested? && (nested.belongs_to? || nested.has_one?)
|
52
|
-
end
|
53
|
-
|
54
|
-
def render_parent?
|
55
|
-
nested_singular_association? || params[:parent_sti]
|
56
|
-
end
|
57
|
-
|
58
|
-
def render_parent_options
|
59
|
-
if nested_singular_association?
|
60
|
-
{:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id}
|
61
|
-
elsif params[:parent_sti]
|
62
|
-
options = {:controller => params[:parent_sti], :action => render_parent_action(params[:parent_sti])}
|
63
|
-
if render_parent_action(params[:parent_sti]) == :index
|
64
|
-
options.merge(params.slice(:eid))
|
65
|
-
else
|
66
|
-
options.merge({:id => @record.id})
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def render_parent_action(controller_path = nil)
|
72
|
-
begin
|
73
|
-
@parent_action = :row
|
74
|
-
parent_controller = "#{controller_path.to_s.camelize}Controller".constantize
|
75
|
-
@parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true
|
76
|
-
@parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list == true
|
77
|
-
@parent_action = :index if action_name == 'destroy' && parent_controller.active_scaffold_config.actions.include?(:delete) && parent_controller.active_scaffold_config.delete.refresh_list == true
|
78
|
-
rescue ActiveScaffold::ControllerNotFound
|
79
|
-
end if @parent_action.nil?
|
80
|
-
@parent_action
|
81
|
-
end
|
82
|
-
|
83
|
-
def build_associated(column, record)
|
84
|
-
if column.singular_association?
|
85
|
-
record.send(:"build_#{column.name}")
|
86
|
-
else
|
87
|
-
record.send(column.name).build
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|