active_scaffold 3.4.17 → 3.4.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -1
- data/README.md +8 -4
- data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
- data/app/assets/stylesheets/active_scaffold.scss +1 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
- data/app/assets/stylesheets/blue-theme.css +1 -1
- data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
- data/lib/active_scaffold.rb +16 -16
- data/lib/active_scaffold/actions/common_search.rb +13 -11
- data/lib/active_scaffold/actions/core.rb +85 -78
- data/lib/active_scaffold/actions/create.rb +29 -28
- data/lib/active_scaffold/actions/delete.rb +17 -17
- data/lib/active_scaffold/actions/field_search.rb +18 -19
- data/lib/active_scaffold/actions/list.rb +30 -22
- data/lib/active_scaffold/actions/mark.rb +1 -1
- data/lib/active_scaffold/actions/nested.rb +78 -65
- data/lib/active_scaffold/actions/search.rb +13 -10
- data/lib/active_scaffold/actions/show.rb +10 -6
- data/lib/active_scaffold/actions/subform.rb +1 -2
- data/lib/active_scaffold/actions/update.rb +39 -31
- data/lib/active_scaffold/active_record_permissions.rb +14 -15
- data/lib/active_scaffold/attribute_params.rb +42 -43
- data/lib/active_scaffold/bridges.rb +22 -12
- data/lib/active_scaffold/bridges/ancestry.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
- data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
- data/lib/active_scaffold/bridges/cancan.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
- data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
- data/lib/active_scaffold/bridges/chosen.rb +1 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
- data/lib/active_scaffold/bridges/country_helper.rb +1 -1
- data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
- data/lib/active_scaffold/bridges/date_picker.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
- data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
- data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/file_column.rb +5 -5
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
- data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
- data/lib/active_scaffold/bridges/paperclip.rb +5 -5
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
- data/lib/active_scaffold/bridges/record_select.rb +1 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
- data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
- data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
- data/lib/active_scaffold/config/base.rb +9 -10
- data/lib/active_scaffold/config/core.rb +24 -29
- data/lib/active_scaffold/config/create.rb +0 -1
- data/lib/active_scaffold/config/field_search.rb +8 -10
- data/lib/active_scaffold/config/form.rb +5 -5
- data/lib/active_scaffold/config/list.rb +21 -20
- data/lib/active_scaffold/config/mark.rb +3 -3
- data/lib/active_scaffold/config/nested.rb +11 -10
- data/lib/active_scaffold/config/search.rb +2 -3
- data/lib/active_scaffold/config/show.rb +1 -1
- data/lib/active_scaffold/config/update.rb +1 -2
- data/lib/active_scaffold/configurable.rb +9 -11
- data/lib/active_scaffold/constraints.rb +9 -8
- data/lib/active_scaffold/core.rb +72 -84
- data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
- data/lib/active_scaffold/data_structures/action_link.rb +43 -43
- data/lib/active_scaffold/data_structures/action_links.rb +17 -15
- data/lib/active_scaffold/data_structures/actions.rb +5 -5
- data/lib/active_scaffold/data_structures/bridge.rb +6 -3
- data/lib/active_scaffold/data_structures/column.rb +110 -89
- data/lib/active_scaffold/data_structures/columns.rb +3 -3
- data/lib/active_scaffold/data_structures/error_message.rb +4 -6
- data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
- data/lib/active_scaffold/data_structures/set.rb +7 -8
- data/lib/active_scaffold/data_structures/sorting.rb +38 -33
- data/lib/active_scaffold/delayed_setup.rb +5 -6
- data/lib/active_scaffold/engine.rb +4 -4
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
- data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
- data/lib/active_scaffold/extensions/localize.rb +1 -1
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
- data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
- data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
- data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
- data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
- data/lib/active_scaffold/finder.rb +90 -93
- data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
- data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
- data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
- data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
- data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
- data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
- data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
- data/lib/active_scaffold/marked_model.rb +10 -10
- data/lib/active_scaffold/paginator.rb +30 -34
- data/lib/active_scaffold/responds_to_parent.rb +27 -28
- data/lib/active_scaffold/tableless.rb +20 -15
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
- data/shoulda_macros/macros.rb +27 -22
- data/test/bridges/bridge_test.rb +38 -29
- data/test/bridges/date_picker_test.rb +1 -1
- data/test/bridges/paper_trail_test.rb +17 -0
- data/test/bridges/paperclip_test.rb +3 -2
- data/test/bridges/tiny_mce_test.rb +5 -2
- data/test/company.rb +25 -30
- data/test/config/base_test.rb +1 -1
- data/test/config/core_test.rb +9 -9
- data/test/config/create_test.rb +14 -8
- data/test/config/delete_test.rb +4 -4
- data/test/config/field_search_test.rb +6 -6
- data/test/config/list_test.rb +16 -16
- data/test/config/nested_test.rb +4 -4
- data/test/config/search_test.rb +8 -8
- data/test/config/show_test.rb +6 -6
- data/test/config/subform_test.rb +1 -1
- data/test/config/update_test.rb +5 -5
- data/test/const_mocker.rb +4 -4
- data/test/data_structures/action_columns_test.rb +4 -5
- data/test/data_structures/action_link_test.rb +1 -0
- data/test/data_structures/action_links_test.rb +5 -5
- data/test/data_structures/column_test.rb +9 -9
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/error_message_test.rb +4 -5
- data/test/data_structures/set_test.rb +1 -2
- data/test/data_structures/sorting_test.rb +10 -10
- data/test/data_structures/validation_reflection_test.rb +8 -0
- data/test/extensions/routing_mapper_test.rb +2 -2
- data/test/helpers/list_column_helpers_test.rb +3 -2
- data/test/helpers/pagination_helpers_test.rb +5 -4
- data/test/helpers/search_column_helpers_test.rb +1 -1
- data/test/misc/active_record_permissions_test.rb +63 -50
- data/test/misc/attribute_params_test.rb +28 -26
- data/test/misc/calculation_test.rb +10 -3
- data/test/misc/configurable_test.rb +12 -13
- data/test/misc/constraints_test.rb +6 -6
- data/test/misc/convert_numbers_format_test.rb +7 -6
- data/test/misc/finder_test.rb +17 -12
- data/test/misc/lang_test.rb +3 -4
- data/test/misc/tableless_test.rb +2 -3
- data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
- data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
- data/test/mock_app/app/controllers/cars_controller.rb +1 -1
- data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
- data/test/mock_app/app/controllers/people_controller.rb +1 -1
- data/test/mock_app/app/models/file_model.rb +2 -2
- data/test/mock_app/app/models/person.rb +1 -1
- data/test/mock_app/config/application.rb +3 -3
- data/test/mock_app/config/boot.rb +1 -1
- data/test/mock_app/config/environment.rb +1 -0
- data/test/mock_app/config/environments/development.rb +0 -1
- data/test/mock_app/config/environments/production.rb +1 -1
- data/test/mock_app/db/schema.rb +14 -15
- data/test/model_stub.rb +13 -16
- data/test/run_all.rb +5 -7
- data/test/test_helper.rb +12 -9
- metadata +19 -3
@@ -28,7 +28,7 @@ module ActiveScaffold::Config
|
|
28
28
|
|
29
29
|
# show value of unauthorized columns instead of skip them
|
30
30
|
attr_accessor :show_unauthorized_columns
|
31
|
-
|
31
|
+
|
32
32
|
# the ActionLink for this action
|
33
33
|
attr_accessor :link
|
34
34
|
|
@@ -45,14 +45,14 @@ module ActiveScaffold::Config
|
|
45
45
|
def columns
|
46
46
|
unless @columns # lazy evaluation
|
47
47
|
self.columns = @core.columns._inheritable
|
48
|
-
|
49
|
-
|
48
|
+
columns.exclude :created_on, :created_at, :updated_on, :updated_at, :as_marked
|
49
|
+
columns.exclude *@core.columns.collect { |c| c.name if c.polymorphic_association? }.compact
|
50
50
|
end
|
51
51
|
@columns
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
public :columns=
|
55
|
-
|
55
|
+
|
56
56
|
# whether the form should be multipart
|
57
57
|
attr_writer :multipart
|
58
58
|
def multipart?
|
@@ -9,7 +9,7 @@ module ActiveScaffold::Config
|
|
9
9
|
@per_page = self.class.per_page
|
10
10
|
@page_links_inner_window = self.class.page_links_inner_window
|
11
11
|
@page_links_outer_window = self.class.page_links_outer_window
|
12
|
-
|
12
|
+
|
13
13
|
# originates here
|
14
14
|
@sorting = ActiveScaffold::DataStructures::Sorting.new(@core.columns)
|
15
15
|
@sorting.set_default_sorting(@core.model)
|
@@ -47,7 +47,7 @@ module ActiveScaffold::Config
|
|
47
47
|
# how many page links around first and last page to show
|
48
48
|
cattr_accessor :page_links_outer_window
|
49
49
|
@@page_links_outer_window = 0
|
50
|
-
|
50
|
+
|
51
51
|
# what string to use when a field is empty
|
52
52
|
cattr_accessor :empty_field_text
|
53
53
|
@@empty_field_text = '-'
|
@@ -89,7 +89,7 @@ module ActiveScaffold::Config
|
|
89
89
|
# Show search form in the list header instead of display the link
|
90
90
|
cattr_accessor :always_show_search
|
91
91
|
@@always_show_search = false
|
92
|
-
|
92
|
+
|
93
93
|
# Show create form in the list header instead of display the link
|
94
94
|
cattr_accessor :always_show_create
|
95
95
|
@@always_show_create = false
|
@@ -111,7 +111,7 @@ module ActiveScaffold::Config
|
|
111
111
|
self.columns = @core.columns._inheritable unless @columns # lazy evaluation
|
112
112
|
@columns
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
public :columns=
|
116
116
|
|
117
117
|
# include list header on refresh
|
@@ -125,7 +125,7 @@ module ActiveScaffold::Config
|
|
125
125
|
|
126
126
|
# how many page links around current page to show
|
127
127
|
attr_accessor :page_links_outer_window
|
128
|
-
|
128
|
+
|
129
129
|
# What kind of pagination to use:
|
130
130
|
# * true: The usual pagination
|
131
131
|
# * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway)
|
@@ -160,10 +160,11 @@ module ActiveScaffold::Config
|
|
160
160
|
val = [val] if val.is_a? Hash
|
161
161
|
sorting.set *val
|
162
162
|
end
|
163
|
+
|
163
164
|
def sorting
|
164
165
|
@sorting ||= ActiveScaffold::DataStructures::Sorting.new(@core.columns)
|
165
166
|
end
|
166
|
-
|
167
|
+
|
167
168
|
# overwrite the includes used for the count sql query
|
168
169
|
attr_accessor :count_includes
|
169
170
|
|
@@ -182,25 +183,25 @@ module ActiveScaffold::Config
|
|
182
183
|
def filtered_message
|
183
184
|
@filtered_message ? @filtered_message : :filtered
|
184
185
|
end
|
185
|
-
|
186
|
+
|
186
187
|
attr_writer :always_show_search
|
187
188
|
def always_show_search
|
188
189
|
@always_show_search && !search_partial.blank?
|
189
190
|
end
|
190
|
-
|
191
|
+
|
191
192
|
def search_partial
|
192
193
|
if @always_show_search == true
|
193
194
|
auto_search_partial
|
194
195
|
else
|
195
|
-
@always_show_search.to_s if @core.actions.include? @always_show_search
|
196
|
+
@always_show_search.to_s if @core.actions.include? @always_show_search
|
196
197
|
end
|
197
198
|
end
|
198
|
-
|
199
|
+
|
199
200
|
def auto_search_partial
|
200
|
-
return
|
201
|
-
return
|
201
|
+
return 'search' if @core.actions.include?(:search)
|
202
|
+
return 'field_search' if @core.actions.include?(:field_search)
|
202
203
|
end
|
203
|
-
|
204
|
+
|
204
205
|
# always show create
|
205
206
|
attr_writer :always_show_create
|
206
207
|
def always_show_create
|
@@ -212,11 +213,11 @@ module ActiveScaffold::Config
|
|
212
213
|
def hide_nested_column
|
213
214
|
@hide_nested_column.nil? ? true : @hide_nested_column
|
214
215
|
end
|
215
|
-
|
216
|
+
|
216
217
|
# wrap normal cells (not inplace editable columns or with link) with a tag
|
217
218
|
# it allows for more css styling
|
218
219
|
attr_accessor :wrap_tag
|
219
|
-
|
220
|
+
|
220
221
|
# Enable auto select columns on list, so only columns needed for list columns are selected
|
221
222
|
attr_accessor :auto_select_columns
|
222
223
|
|
@@ -229,7 +230,7 @@ module ActiveScaffold::Config
|
|
229
230
|
super(conf, storage, params, :list)
|
230
231
|
@sorting = nil
|
231
232
|
end
|
232
|
-
|
233
|
+
|
233
234
|
attr_writer :label
|
234
235
|
# This label has already been localized.
|
235
236
|
def label
|
@@ -237,12 +238,12 @@ module ActiveScaffold::Config
|
|
237
238
|
end
|
238
239
|
|
239
240
|
def per_page
|
240
|
-
self['per_page'] = @params['limit'].to_i if @params.
|
241
|
+
self['per_page'] = @params['limit'].to_i if @params.key? 'limit'
|
241
242
|
self['per_page'] || @conf.per_page
|
242
243
|
end
|
243
244
|
|
244
245
|
def page
|
245
|
-
self['page'] = @params['page'] || 1 if @params.
|
246
|
+
self['page'] = @params['page'] || 1 if @params.key?('page') || @conf.auto_pagination
|
246
247
|
self['page'] || 1
|
247
248
|
end
|
248
249
|
|
@@ -268,7 +269,7 @@ module ActiveScaffold::Config
|
|
268
269
|
def sorting
|
269
270
|
if @sorting.nil?
|
270
271
|
# we want to store as little as possible in the session, but we want to return a Sorting data structure. so we recreate it each page load based on session data.
|
271
|
-
self['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort']
|
272
|
+
self['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort'] && @params['sort_direction']
|
272
273
|
self['sort'] = nil if @params['sort_direction'] == 'reset'
|
273
274
|
|
274
275
|
if self['sort']
|
@@ -284,7 +285,7 @@ module ActiveScaffold::Config
|
|
284
285
|
end
|
285
286
|
@sorting
|
286
287
|
end
|
287
|
-
|
288
|
+
|
288
289
|
def count_includes
|
289
290
|
@conf.count_includes
|
290
291
|
end
|
@@ -9,16 +9,16 @@ module ActiveScaffold::Config
|
|
9
9
|
@@mark_all_mode = :search
|
10
10
|
|
11
11
|
attr_accessor :mark_all_mode
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(core_config)
|
14
14
|
@core = core_config
|
15
15
|
@mark_all_mode = self.class.mark_all_mode
|
16
16
|
@core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model < ActiveScaffold::MarkedModel
|
17
17
|
add_mark_column
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
protected
|
21
|
-
|
21
|
+
|
22
22
|
def add_mark_column
|
23
23
|
@core.columns.add :as_marked
|
24
24
|
@core.columns[:as_marked].label = 'M'
|
@@ -13,36 +13,37 @@ module ActiveScaffold::Config
|
|
13
13
|
# --------------------------
|
14
14
|
cattr_accessor :shallow_delete
|
15
15
|
@@shallow_delete = true
|
16
|
-
|
16
|
+
|
17
17
|
cattr_accessor :ignore_order_from_association
|
18
18
|
|
19
19
|
# instance-level configuration
|
20
20
|
# ----------------------------
|
21
21
|
attr_accessor :shallow_delete
|
22
|
-
|
22
|
+
|
23
23
|
attr_accessor :ignore_order_from_association
|
24
24
|
|
25
25
|
# Add a nested ActionLink
|
26
26
|
def add_link(attribute, options = {})
|
27
27
|
column = @core.columns[attribute.to_sym]
|
28
28
|
if column && column.association
|
29
|
-
label =
|
30
|
-
column.
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
label =
|
30
|
+
if column.polymorphic_association?
|
31
|
+
column.label
|
32
|
+
else
|
33
|
+
column.association.klass.model_name.human(:count => column.singular_association? ? 1 : 2, :default => column.association.klass.name.pluralize)
|
34
|
+
end
|
34
35
|
options.reverse_merge! :security_method => :nested_authorized?, :label => label
|
35
36
|
action_group = options.delete(:action_group) || self.action_group
|
36
37
|
action_link = @core.link_for_association(column, options)
|
37
38
|
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
|
38
39
|
action_link
|
39
40
|
elsif column.nil?
|
40
|
-
raise ArgumentError
|
41
|
+
raise ArgumentError, "unknown column #{attribute}"
|
41
42
|
elsif column.association.nil?
|
42
|
-
raise ArgumentError
|
43
|
+
raise ArgumentError, "column #{attribute} is not an association"
|
43
44
|
end
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
def add_scoped_link(named_scope, options = {})
|
47
48
|
action_link = @core.link_for_association_as_scope(named_scope.to_sym, options)
|
48
49
|
@core.action_links.add_to_group(action_link, action_group) unless action_link.nil?
|
@@ -9,7 +9,6 @@ module ActiveScaffold::Config
|
|
9
9
|
@split_terms = self.class.split_terms
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
12
|
# global level configuration
|
14
13
|
# --------------------------
|
15
14
|
# the ActionLink for this action
|
@@ -32,7 +31,7 @@ module ActiveScaffold::Config
|
|
32
31
|
end
|
33
32
|
|
34
33
|
cattr_accessor :split_terms
|
35
|
-
@@split_terms =
|
34
|
+
@@split_terms = ' '
|
36
35
|
|
37
36
|
# instance-level configuration
|
38
37
|
# ----------------------------
|
@@ -41,7 +40,7 @@ module ActiveScaffold::Config
|
|
41
40
|
def columns
|
42
41
|
# we want to delay initializing to the @core.columns set for as long as possible. Too soon and .search_sql will not be available to .searchable?
|
43
42
|
unless @columns
|
44
|
-
self.columns = @core.columns.collect{|c| c.name if @core.columns._inheritable.include?(c.name)
|
43
|
+
self.columns = @core.columns.collect { |c| c.name if @core.columns._inheritable.include?(c.name) && c.searchable? && c.association.nil? && c.text? }.compact
|
45
44
|
end
|
46
45
|
@columns
|
47
46
|
end
|
@@ -23,11 +23,10 @@ module ActiveScaffold::Config
|
|
23
23
|
attr_accessor :nested_links
|
24
24
|
cattr_accessor :nested_links
|
25
25
|
@@nested_links = false
|
26
|
-
|
26
|
+
|
27
27
|
attr_writer :hide_nested_column
|
28
28
|
def hide_nested_column
|
29
29
|
@hide_nested_column.nil? ? true : @hide_nested_column
|
30
30
|
end
|
31
|
-
|
32
31
|
end
|
33
32
|
end
|
@@ -7,22 +7,20 @@ module ActiveScaffold
|
|
7
7
|
module Configurable
|
8
8
|
def configure(&configuration_block)
|
9
9
|
return unless configuration_block
|
10
|
-
@configuration_binding = eval(
|
11
|
-
ret = instance_exec
|
10
|
+
@configuration_binding = configuration_block.binding.eval('self')
|
11
|
+
ret = instance_exec(self, &configuration_block)
|
12
12
|
@configuration_binding = nil
|
13
|
-
|
13
|
+
ret
|
14
14
|
end
|
15
15
|
|
16
16
|
# this method will surely need tweaking. for example, i'm not sure if it should call super before or after it tries to eval with the binding.
|
17
17
|
def method_missing(name, *args)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@configuration_binding.send(name, *args)
|
25
|
-
end
|
18
|
+
super
|
19
|
+
rescue NoMethodError, NameError
|
20
|
+
if @configuration_binding.nil?
|
21
|
+
raise
|
22
|
+
else
|
23
|
+
@configuration_binding.send(name, *args)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -17,7 +17,7 @@ module ActiveScaffold
|
|
17
17
|
# If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column.
|
18
18
|
def register_constraints_with_action_columns(constrained_fields = nil)
|
19
19
|
constrained_fields ||= []
|
20
|
-
constrained_fields |= active_scaffold_constraints.reject{|
|
20
|
+
constrained_fields |= active_scaffold_constraints.reject { |_, v| v.is_a? Hash }.keys.collect(&:to_sym)
|
21
21
|
exclude_actions = []
|
22
22
|
[:list, :update].each do |action_name|
|
23
23
|
if active_scaffold_config.actions.include? action_name
|
@@ -96,11 +96,12 @@ module ActiveScaffold
|
|
96
96
|
#
|
97
97
|
# please see the relevant tests for concrete examples.
|
98
98
|
|
99
|
-
field =
|
100
|
-
association.
|
101
|
-
|
102
|
-
|
103
|
-
|
99
|
+
field =
|
100
|
+
if [:has_one, :has_many, :has_and_belongs_to_many].include?(association.macro)
|
101
|
+
association.klass.primary_key
|
102
|
+
else
|
103
|
+
association.options[:foreign_key] || association.name.to_s.foreign_key
|
104
|
+
end
|
104
105
|
|
105
106
|
table = case association.macro
|
106
107
|
when :belongs_to then active_scaffold_config.model.table_name
|
@@ -141,7 +142,7 @@ module ActiveScaffold
|
|
141
142
|
|
142
143
|
active_scaffold_constraints.each do |k, v|
|
143
144
|
column = active_scaffold_config.columns[k]
|
144
|
-
if column
|
145
|
+
if column && column.association
|
145
146
|
if column.plural_association?
|
146
147
|
record.send("#{k}").send(:<<, column.association.klass.find(v))
|
147
148
|
elsif column.association.options[:polymorphic]
|
@@ -156,7 +157,7 @@ module ActiveScaffold
|
|
156
157
|
# note that we can't take the extra step to correct this unless we're permitted to
|
157
158
|
# run operations where activerecord auto-saves the object.
|
158
159
|
reverse = column.association.klass.reflect_on_association(column.association.reverse)
|
159
|
-
if reverse.macro == :has_one
|
160
|
+
if reverse.macro == :has_one && options[:allow_autosave]
|
160
161
|
record.send(k).send("#{column.association.reverse}=", record)
|
161
162
|
end
|
162
163
|
end
|
data/lib/active_scaffold/core.rb
CHANGED
@@ -11,7 +11,7 @@ module ActiveScaffold
|
|
11
11
|
def active_scaffold_config_for(klass)
|
12
12
|
self.class.active_scaffold_config_for(klass)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
module ClassMethods
|
16
16
|
def active_scaffold(model_id = nil, &block)
|
17
17
|
extend Prefixes
|
@@ -19,26 +19,26 @@ module ActiveScaffold
|
|
19
19
|
ActiveScaffold::Bridges.run_all
|
20
20
|
|
21
21
|
# converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address'
|
22
|
-
model_id =
|
22
|
+
model_id = to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore unless model_id
|
23
23
|
|
24
24
|
# run the configuration
|
25
25
|
@active_scaffold_config = ActiveScaffold::Config::Core.new(model_id)
|
26
26
|
@active_scaffold_config_block = block
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
links_for_associations
|
28
|
+
|
29
|
+
active_scaffold_superclasses_blocks.each { |superblock| active_scaffold_config.configure(&superblock) }
|
30
|
+
active_scaffold_config.sti_children = nil # reset sti_children if set in parent block
|
31
|
+
active_scaffold_config.configure(&block) if block_given?
|
32
|
+
active_scaffold_config._configure_sti unless active_scaffold_config.sti_children.nil?
|
33
|
+
active_scaffold_config._load_action_columns
|
34
34
|
|
35
35
|
# defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead
|
36
|
-
klass =
|
36
|
+
klass = active_scaffold_config.model
|
37
37
|
# Rails 4.0.4 has removed attribute_methods_generated,
|
38
38
|
# and made define_attribute_methods threadsave to call multiple times.
|
39
39
|
# Check for that here.
|
40
|
-
if (
|
41
|
-
|
40
|
+
if (Rails::VERSION::MAJOR == 4 && !klass.respond_to?(:attribute_methods_generated)) ||
|
41
|
+
!klass.attribute_methods_generated?
|
42
42
|
klass.define_attribute_methods
|
43
43
|
end
|
44
44
|
# include the rest of the code into the controller: the action core and the included actions
|
@@ -50,21 +50,19 @@ module ActiveScaffold
|
|
50
50
|
include ActiveScaffold::Actions::Core
|
51
51
|
end
|
52
52
|
active_scaffold_config.actions.each do |mod|
|
53
|
-
|
54
|
-
|
53
|
+
include "ActiveScaffold::Actions::#{mod.to_s.camelize}".constantize
|
54
|
+
mod_conf = active_scaffold_config.send(mod)
|
55
|
+
next unless mod_conf.respond_to?(:link) && (link = mod_conf.link)
|
55
56
|
|
56
57
|
# sneak the action links from the actions into the main set
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
elsif link.is_a? ActiveScaffold::DataStructures::ActionLink
|
62
|
-
active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group)
|
63
|
-
end
|
58
|
+
if link.is_a? Array
|
59
|
+
link.each { |current| active_scaffold_config.action_links.add_to_group(current, active_scaffold_config.send(mod).action_group) }
|
60
|
+
elsif link.is_a? ActiveScaffold::DataStructures::ActionLink
|
61
|
+
active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group)
|
64
62
|
end
|
65
63
|
end
|
66
64
|
end
|
67
|
-
|
65
|
+
_add_sti_create_links if active_scaffold_config.add_sti_create_links?
|
68
66
|
end
|
69
67
|
|
70
68
|
module Prefixes
|
@@ -76,64 +74,59 @@ module ActiveScaffold
|
|
76
74
|
# To be called after include action modules
|
77
75
|
def _add_sti_create_links
|
78
76
|
new_action_link = active_scaffold_config.action_links.collection['new']
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
77
|
+
return if new_action_link.nil? || active_scaffold_config.sti_children.empty?
|
78
|
+
active_scaffold_config.action_links.collection.delete('new')
|
79
|
+
active_scaffold_config.sti_children.each do |child|
|
80
|
+
new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone
|
81
|
+
new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.model_name.human)
|
82
|
+
new_sti_link.parameters = {:parent_sti => controller_path}
|
83
|
+
new_sti_link.controller = proc { active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path }
|
84
|
+
active_scaffold_config.action_links.collection.create.add(new_sti_link)
|
88
85
|
end
|
89
86
|
end
|
90
87
|
|
91
88
|
# Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it?
|
92
89
|
def links_for_associations
|
93
|
-
return unless active_scaffold_config.actions.include?
|
90
|
+
return unless active_scaffold_config.actions.include?(:list) && active_scaffold_config.actions.include?(:nested)
|
94
91
|
active_scaffold_config.columns.each do |column|
|
95
|
-
next unless column.link.nil?
|
96
|
-
#lazy load of action_link, cause it was really slowing down app in dev mode
|
97
|
-
#and might lead to trouble cause of cyclic constantization of controllers
|
98
|
-
#and might be unnecessary cause it is done before columns are configured
|
99
|
-
column.set_link(
|
92
|
+
next unless column.link.nil? && column.autolink?
|
93
|
+
# lazy load of action_link, cause it was really slowing down app in dev mode
|
94
|
+
# and might lead to trouble cause of cyclic constantization of controllers
|
95
|
+
# and might be unnecessary cause it is done before columns are configured
|
96
|
+
column.set_link(proc { |col| link_for_association(col) })
|
100
97
|
end
|
101
98
|
end
|
102
|
-
|
99
|
+
|
103
100
|
def active_scaffold_controller_for_column(column, options = {})
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
active_scaffold_controller_for(column.association.klass)
|
111
|
-
end
|
112
|
-
rescue ActiveScaffold::ControllerNotFound
|
113
|
-
nil
|
101
|
+
if column.polymorphic_association?
|
102
|
+
:polymorph
|
103
|
+
elsif options.include?(:controller)
|
104
|
+
"#{options[:controller].to_s.camelize}Controller".constantize
|
105
|
+
else
|
106
|
+
active_scaffold_controller_for(column.association.klass)
|
114
107
|
end
|
108
|
+
rescue ActiveScaffold::ControllerNotFound
|
109
|
+
nil
|
115
110
|
end
|
116
|
-
|
111
|
+
|
117
112
|
def link_for_association(column, options = {})
|
118
|
-
controller = active_scaffold_controller_for_column(column, options)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge(:html_options => {:class => column.name}))
|
133
|
-
end
|
113
|
+
return if (controller = active_scaffold_controller_for_column(column, options)).nil?
|
114
|
+
options.reverse_merge! :position => :after, :type => :member, :column => column,
|
115
|
+
:controller => (controller == :polymorph ? controller : "/#{controller.controller_path}")
|
116
|
+
options[:parameters] ||= {}
|
117
|
+
options[:parameters].reverse_merge! :association => column.association.name
|
118
|
+
if column.plural_association?
|
119
|
+
ActiveScaffold::DataStructures::ActionLink.new('index', options.merge(:refresh_on_close => true))
|
120
|
+
else
|
121
|
+
actions = controller.active_scaffold_config.actions unless controller == :polymorph
|
122
|
+
actions ||= [:create, :update, :show]
|
123
|
+
column.actions_for_association_links.delete :new unless actions.include? :create
|
124
|
+
column.actions_for_association_links.delete :edit unless actions.include? :update
|
125
|
+
column.actions_for_association_links.delete :show unless actions.include? :show
|
126
|
+
ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge(:html_options => {:class => column.name}))
|
134
127
|
end
|
135
128
|
end
|
136
|
-
|
129
|
+
|
137
130
|
def link_for_association_as_scope(scope, options = {})
|
138
131
|
options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path
|
139
132
|
options[:parameters] ||= {}
|
@@ -145,7 +138,7 @@ module ActiveScaffold
|
|
145
138
|
as_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'app', 'views')
|
146
139
|
index = view_paths.find_index { |p| p.to_s == as_path }
|
147
140
|
if index
|
148
|
-
self.view_paths = view_paths[0..index-1] + Array(path) + view_paths[index..-1]
|
141
|
+
self.view_paths = view_paths[0..index - 1] + Array(path) + view_paths[index..-1]
|
149
142
|
else
|
150
143
|
append_view_path path
|
151
144
|
end
|
@@ -153,19 +146,17 @@ module ActiveScaffold
|
|
153
146
|
|
154
147
|
def active_scaffold_config
|
155
148
|
if @active_scaffold_config.nil?
|
156
|
-
|
149
|
+
superclass.active_scaffold_config if superclass.respond_to? :active_scaffold_config
|
157
150
|
else
|
158
151
|
@active_scaffold_config
|
159
152
|
end
|
160
153
|
end
|
161
154
|
|
162
|
-
|
163
|
-
@active_scaffold_config_block
|
164
|
-
end
|
155
|
+
attr_reader :active_scaffold_config_block
|
165
156
|
|
166
157
|
def active_scaffold_superclasses_blocks
|
167
158
|
blocks = []
|
168
|
-
klass =
|
159
|
+
klass = superclass
|
169
160
|
while klass.respond_to? :active_scaffold_superclasses_blocks
|
170
161
|
blocks << klass.active_scaffold_config_block
|
171
162
|
klass = klass.superclass
|
@@ -174,23 +165,20 @@ module ActiveScaffold
|
|
174
165
|
end
|
175
166
|
|
176
167
|
def active_scaffold_config_for(klass)
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
controller.active_scaffold_config
|
185
|
-
end
|
168
|
+
controller = active_scaffold_controller_for(klass)
|
169
|
+
rescue ActiveScaffold::ControllerNotFound
|
170
|
+
config = ActiveScaffold::Config::Core.new(klass)
|
171
|
+
config._load_action_columns
|
172
|
+
config
|
173
|
+
else
|
174
|
+
controller.active_scaffold_config
|
186
175
|
end
|
187
176
|
|
188
177
|
def active_scaffold_controller_for(klass)
|
189
178
|
return self if uses_active_scaffold? && klass == active_scaffold_config.model
|
190
|
-
ActiveScaffold::Core.active_scaffold_controller_for(klass,
|
179
|
+
ActiveScaffold::Core.active_scaffold_controller_for(klass, to_s.deconstantize + '::')
|
191
180
|
end
|
192
181
|
|
193
|
-
|
194
182
|
def uses_active_scaffold?
|
195
183
|
!active_scaffold_config.nil?
|
196
184
|
end
|
@@ -220,7 +208,7 @@ module ActiveScaffold
|
|
220
208
|
return controller
|
221
209
|
end
|
222
210
|
end
|
223
|
-
raise ActiveScaffold::ControllerNotFound,
|
211
|
+
raise ActiveScaffold::ControllerNotFound, 'Could not find ' + error_message.join(' or '), caller
|
224
212
|
end
|
225
213
|
|
226
214
|
def self.column_type_cast(value, column)
|