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
@@ -9,25 +9,25 @@ module ActiveScaffold::DataStructures
|
|
9
9
|
|
10
10
|
def set_values(*args)
|
11
11
|
@set = []
|
12
|
-
|
12
|
+
add *args
|
13
13
|
end
|
14
14
|
|
15
15
|
# the way to add items to the set.
|
16
16
|
def add(*args)
|
17
17
|
args.flatten! # allow [] as a param
|
18
|
-
args.each
|
18
|
+
args.each do |arg|
|
19
19
|
arg = arg.to_sym if arg.is_a? String
|
20
20
|
@set << arg unless @set.include? arg # avoid duplicates
|
21
|
-
|
21
|
+
end
|
22
22
|
end
|
23
23
|
alias_method :<<, :add
|
24
24
|
|
25
25
|
# the way to remove items from the set.
|
26
26
|
def exclude(*args)
|
27
27
|
args.flatten! # allow [] as a param
|
28
|
-
args.collect!
|
28
|
+
args.collect!(&:to_sym) # symbolize the args
|
29
29
|
# check respond_to? :to_sym, ActionColumns doesn't respond to to_sym
|
30
|
-
@set.reject! { |c| c.respond_to?
|
30
|
+
@set.reject! { |c| c.respond_to?(:to_sym) && args.include?(c.to_sym) } # reject all items specified
|
31
31
|
end
|
32
32
|
alias_method :remove, :exclude
|
33
33
|
|
@@ -45,17 +45,16 @@ module ActiveScaffold::DataStructures
|
|
45
45
|
alias_method :[], :find_by_name
|
46
46
|
|
47
47
|
def each
|
48
|
-
@set.each {|i| yield i }
|
48
|
+
@set.each { |i| yield i }
|
49
49
|
end
|
50
50
|
|
51
51
|
# returns the number of items in the set
|
52
52
|
def length
|
53
53
|
@set.length
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def empty?
|
57
57
|
@set.empty?
|
58
58
|
end
|
59
|
-
|
60
59
|
end
|
61
60
|
end
|
@@ -4,43 +4,37 @@ module ActiveScaffold::DataStructures
|
|
4
4
|
include Enumerable
|
5
5
|
|
6
6
|
attr_accessor :constraint_columns
|
7
|
-
attr_accessor :sorting_by_primary_key
|
7
|
+
attr_accessor :sorting_by_primary_key # enabled by default for postgres
|
8
8
|
|
9
9
|
def initialize(columns)
|
10
10
|
@columns = columns
|
11
11
|
@clauses = []
|
12
12
|
@constraint_columns = []
|
13
13
|
end
|
14
|
-
|
15
|
-
def set_default_sorting(model)
|
16
|
-
model_scope = model.send(:build_default_scope)
|
17
|
-
order_clause = model_scope.order_values.join(",") if model_scope
|
18
14
|
|
15
|
+
def set_default_sorting(model)
|
19
16
|
# fallback to setting primary key ordering
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
17
|
+
setup_primary_key_order_clause(model)
|
18
|
+
model_scope = model.send(:build_default_scope)
|
19
|
+
order_clause = model_scope.order_values.join(',') if model_scope
|
20
|
+
return unless order_clause
|
25
21
|
# If an ORDER BY clause is found set default sorting according to it
|
26
|
-
|
27
|
-
|
28
|
-
@default_sorting = true
|
29
|
-
end
|
22
|
+
set_sorting_from_order_clause(order_clause, model.table_name)
|
23
|
+
@default_sorting = true
|
30
24
|
end
|
31
25
|
|
32
26
|
def set_nested_sorting(table_name, order_clause)
|
33
27
|
clear
|
34
28
|
set_sorting_from_order_clause(order_clause, table_name)
|
35
29
|
end
|
36
|
-
|
30
|
+
|
37
31
|
# add a clause to the sorting, assuming the column is sortable
|
38
32
|
def add(column_name, direction = nil)
|
39
33
|
direction ||= 'ASC'
|
40
34
|
direction = direction.to_s.upcase
|
41
35
|
column = get_column(column_name)
|
42
36
|
raise ArgumentError, "Could not find column #{column_name}" if column.nil?
|
43
|
-
raise ArgumentError,
|
37
|
+
raise ArgumentError, 'Sorting direction unknown' unless [:ASC, :DESC].include? direction.to_sym
|
44
38
|
@clauses << [column, direction.untaint] if column.sortable?
|
45
39
|
raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting?
|
46
40
|
end
|
@@ -59,7 +53,7 @@ module ActiveScaffold::DataStructures
|
|
59
53
|
clear
|
60
54
|
if args.first.is_a?(Enumerable)
|
61
55
|
args.each do |h|
|
62
|
-
h.is_a?(Hash) ? h.each { |c,d| add(c,d) } : add(*h)
|
56
|
+
h.is_a?(Hash) ? h.each { |c, d| add(c, d) } : add(*h)
|
63
57
|
end
|
64
58
|
else
|
65
59
|
add(*args)
|
@@ -83,8 +77,8 @@ module ActiveScaffold::DataStructures
|
|
83
77
|
clause[1]
|
84
78
|
end
|
85
79
|
|
86
|
-
SORTING_STAGES = Hash[%w(reset ASC DESC reset).each_cons(2).
|
87
|
-
DEFAULT_SORTING_STAGES = Hash[%w(ASC DESC ASC).each_cons(2).
|
80
|
+
SORTING_STAGES = Hash[%w(reset ASC DESC reset).each_cons(2).to_a].freeze
|
81
|
+
DEFAULT_SORTING_STAGES = Hash[%w(ASC DESC ASC).each_cons(2).to_a].freeze
|
88
82
|
def next_sorting_of(column, sorted_by_default)
|
89
83
|
stages = sorted_by_default ? DEFAULT_SORTING_STAGES : SORTING_STAGES
|
90
84
|
stages[direction_of(column)] || 'ASC'
|
@@ -92,11 +86,11 @@ module ActiveScaffold::DataStructures
|
|
92
86
|
|
93
87
|
# checks whether any column is configured to sort by method (using a proc)
|
94
88
|
def sorts_by_method?
|
95
|
-
@clauses.any? { |sorting| sorting[0].sort.is_a?
|
89
|
+
@clauses.any? { |sorting| sorting[0].sort.is_a?(Hash) && sorting[0].sort.key?(:method) }
|
96
90
|
end
|
97
91
|
|
98
92
|
def sorts_by_sql?
|
99
|
-
@clauses.any? { |sorting| sorting[0].sort.is_a?
|
93
|
+
@clauses.any? { |sorting| sorting[0].sort.is_a?(Hash) && sorting[0].sort.key?(:sql) }
|
100
94
|
end
|
101
95
|
|
102
96
|
# iterate over the clauses
|
@@ -118,12 +112,12 @@ module ActiveScaffold::DataStructures
|
|
118
112
|
each do |sort_column, sort_direction|
|
119
113
|
next if constraint_columns.include? sort_column.name
|
120
114
|
sql = sort_column.sort[:sql]
|
121
|
-
next if sql.nil?
|
115
|
+
next if sql.nil? || sql.empty?
|
122
116
|
|
123
|
-
order << Array(sql).map {|column| "#{column} #{sort_direction}"}.join(', ')
|
117
|
+
order << Array(sql).map { |column| "#{column} #{sort_direction}" }.join(', ')
|
124
118
|
end
|
125
119
|
|
126
|
-
order << @
|
120
|
+
order << @primary_key_order_clause if @sorting_by_primary_key
|
127
121
|
order unless order.empty?
|
128
122
|
end
|
129
123
|
|
@@ -132,7 +126,7 @@ module ActiveScaffold::DataStructures
|
|
132
126
|
# retrieves the sorting clause for the given column
|
133
127
|
def get_clause(column)
|
134
128
|
column = get_column(column)
|
135
|
-
@clauses.find{ |clause| clause[0] == column}
|
129
|
+
@clauses.find { |clause| clause[0] == column }
|
136
130
|
end
|
137
131
|
|
138
132
|
# possibly converts the given argument into a column object from @columns (if it's not already)
|
@@ -141,13 +135,13 @@ module ActiveScaffold::DataStructures
|
|
141
135
|
return name_or_column if name_or_column.is_a? ActiveScaffold::DataStructures::Column
|
142
136
|
# it's a name
|
143
137
|
name_or_column = name_or_column.to_s.split('.').last if name_or_column.to_s.include? '.'
|
144
|
-
|
138
|
+
@columns[name_or_column]
|
145
139
|
end
|
146
140
|
|
147
141
|
def mixed_sorting?
|
148
|
-
sorts_by_method?
|
142
|
+
sorts_by_method? && sorts_by_sql?
|
149
143
|
end
|
150
|
-
|
144
|
+
|
151
145
|
def default_sorting?
|
152
146
|
@default_sorting
|
153
147
|
end
|
@@ -161,20 +155,20 @@ module ActiveScaffold::DataStructures
|
|
161
155
|
end
|
162
156
|
end
|
163
157
|
end
|
164
|
-
|
158
|
+
|
165
159
|
def extract_order_parts(criterion_parts)
|
166
160
|
column_name_part, direction_part = criterion_parts.strip.split(' ')
|
167
161
|
column_name_parts = column_name_part.split('.')
|
168
162
|
order = {:direction => extract_direction(direction_part),
|
169
|
-
|
163
|
+
:column_name => remove_quotes(column_name_parts.last)}
|
170
164
|
order[:table_name] = remove_quotes(column_name_parts[-2]) if column_name_parts.length >= 2
|
171
165
|
order
|
172
166
|
end
|
173
|
-
|
167
|
+
|
174
168
|
def different_table?(model_table_name, order_table_name)
|
175
169
|
!order_table_name.nil? && model_table_name != order_table_name
|
176
170
|
end
|
177
|
-
|
171
|
+
|
178
172
|
def remove_quotes(sql_name)
|
179
173
|
if sql_name.starts_with?('"') || sql_name.starts_with?('`')
|
180
174
|
sql_name[1, (sql_name.length - 2)]
|
@@ -182,7 +176,7 @@ module ActiveScaffold::DataStructures
|
|
182
176
|
sql_name
|
183
177
|
end
|
184
178
|
end
|
185
|
-
|
179
|
+
|
186
180
|
def extract_direction(direction_part)
|
187
181
|
if direction_part.to_s.upcase == 'DESC'
|
188
182
|
'DESC'
|
@@ -190,5 +184,16 @@ module ActiveScaffold::DataStructures
|
|
190
184
|
'ASC'
|
191
185
|
end
|
192
186
|
end
|
187
|
+
|
188
|
+
def postgres?(model)
|
189
|
+
model.connection.try(:adapter_name) == 'PostgreSQL'
|
190
|
+
end
|
191
|
+
|
192
|
+
def setup_primary_key_order_clause(model)
|
193
|
+
return unless model.column_names.include?(model.primary_key)
|
194
|
+
set([model.primary_key, 'ASC'])
|
195
|
+
@primary_key_order_clause = clause
|
196
|
+
@sorting_by_primary_key = postgres?(model) # mandatory for postgres, so enabled by default
|
197
|
+
end
|
193
198
|
end
|
194
199
|
end
|
@@ -8,17 +8,16 @@ module ActiveScaffold
|
|
8
8
|
self.class.config_active_scaffold_delayed
|
9
9
|
super
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
module ClassMethods
|
13
13
|
def active_scaffold(model_id = nil, &block)
|
14
|
-
@active_scaffold_delayed = proc{ super(model_id, &block) }
|
14
|
+
@active_scaffold_delayed = proc { super(model_id, &block) }
|
15
15
|
end
|
16
16
|
|
17
17
|
def config_active_scaffold_delayed
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
return unless @active_scaffold_delayed
|
19
|
+
block, @active_scaffold_delayed = @active_scaffold_delayed, nil
|
20
|
+
block.call
|
22
21
|
end
|
23
22
|
|
24
23
|
def active_scaffold_config
|
@@ -1,22 +1,23 @@
|
|
1
1
|
module ActiveScaffold
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
initializer
|
3
|
+
initializer 'active_scaffold.action_controller' do
|
4
4
|
ActiveSupport.on_load :action_controller do
|
5
5
|
include ActiveScaffold::Core
|
6
6
|
include ActiveScaffold::DelayedSetup if ActiveScaffold.delayed_setup
|
7
7
|
include ActiveScaffold::RespondsToParent
|
8
8
|
include ActiveScaffold::Helpers::ControllerHelpers
|
9
9
|
include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Controller
|
10
|
+
ActiveScaffold::Bridges.prepare_all
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
initializer
|
14
|
+
initializer 'active_scaffold.action_view' do
|
14
15
|
ActiveSupport.on_load :action_view do
|
15
16
|
include ActiveScaffold::Helpers::ViewHelpers
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
initializer
|
20
|
+
initializer 'active_scaffold.active_record' do
|
20
21
|
ActiveSupport.on_load :active_record do
|
21
22
|
include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Model
|
22
23
|
ActiveRecord::Associations::Association.send :include, ActiveScaffold::Tableless::Association
|
@@ -24,6 +25,5 @@ module ActiveScaffold
|
|
24
25
|
ActiveRecord::Associations::SingularAssociation.send :include, ActiveScaffold::Tableless::SingularAssociation
|
25
26
|
end
|
26
27
|
end
|
27
|
-
|
28
28
|
end
|
29
29
|
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
module ActionController #:nodoc:
|
3
3
|
class Base
|
4
4
|
def render_with_active_scaffold(*args, &block)
|
5
|
-
if self.class.uses_active_scaffold?
|
5
|
+
if self.class.uses_active_scaffold? && params[:adapter] && @rendering_adapter.nil? && request.xhr?
|
6
6
|
@rendering_adapter = true # recursion control
|
7
7
|
# if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template
|
8
|
-
opts = args.blank? ?
|
8
|
+
opts = args.blank? ? {} : args.first
|
9
9
|
render :partial => params[:adapter][1..-1],
|
10
|
-
|
10
|
+
:locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe},
|
11
11
|
:use_full_path => true, :layout => false, :content_type => :html
|
12
12
|
@rendering_adapter = nil # recursion control
|
13
13
|
else
|
@@ -17,4 +17,3 @@ module ActionController #:nodoc:
|
|
17
17
|
alias_method_chain :render, :active_scaffold
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActionView
|
2
2
|
class LookupContext
|
3
3
|
attr_accessor :last_template
|
4
|
-
|
4
|
+
|
5
5
|
def find_template_with_last_template(name, prefixes = [], partial = false, keys = [], options = {})
|
6
6
|
self.last_template = find_template_without_last_template(name, prefixes, partial, keys, options)
|
7
7
|
end
|
@@ -35,7 +35,7 @@ module ActionView::Helpers #:nodoc:
|
|
35
35
|
# Defining options[:label] lets you completely customize the list title for the embedded scaffold.
|
36
36
|
#
|
37
37
|
def render_with_active_scaffold(*args, &block)
|
38
|
-
if args.first.is_a?
|
38
|
+
if args.first.is_a?(Hash) && args.first[:active_scaffold]
|
39
39
|
require 'digest/md5'
|
40
40
|
options = args.first
|
41
41
|
|
@@ -45,7 +45,7 @@ module ActionView::Helpers #:nodoc:
|
|
45
45
|
eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s)
|
46
46
|
eid_info = session["as:#{eid}"] ||= {}
|
47
47
|
if constraints
|
48
|
-
eid_info['constraints'] = constraints
|
48
|
+
eid_info['constraints'] = constraints
|
49
49
|
else
|
50
50
|
eid_info.delete 'constraints'
|
51
51
|
end
|
@@ -99,7 +99,7 @@ module ActionView::Helpers #:nodoc:
|
|
99
99
|
else
|
100
100
|
options[:prefixes] = ['active_scaffold_overrides']
|
101
101
|
last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root)
|
102
|
-
lookup_context.view_paths = view_paths.drop(view_paths.find_index {|path| path.to_s == last_view_path} + 1)
|
102
|
+
lookup_context.view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
|
103
103
|
end
|
104
104
|
result = render_without_active_scaffold options
|
105
105
|
lookup_context.view_paths = @_view_paths if @_view_paths
|
@@ -121,10 +121,9 @@ module ActionView::Helpers #:nodoc:
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
alias_method_chain :render, :active_scaffold
|
124
|
-
|
124
|
+
|
125
125
|
def view_stack
|
126
126
|
@_view_stack ||= []
|
127
127
|
end
|
128
|
-
|
129
128
|
end
|
130
129
|
end
|
@@ -14,7 +14,7 @@ module ActiveScaffold
|
|
14
14
|
relation = clone
|
15
15
|
|
16
16
|
args.flatten!
|
17
|
-
relation.joins_values += [''] # HACK for using outer_joins in update_all/delete_all
|
17
|
+
relation.joins_values += [''] # HACK: for using outer_joins in update_all/delete_all
|
18
18
|
relation.outer_joins_values += args
|
19
19
|
|
20
20
|
relation
|
@@ -30,12 +30,12 @@ module ActiveScaffold
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def outer_joins(*args)
|
33
|
-
check_if_method_has_arguments!(
|
33
|
+
check_if_method_has_arguments!('outer_joins', args)
|
34
34
|
spawn.outer_joins!(*args.compact.flatten)
|
35
35
|
end
|
36
36
|
|
37
37
|
def outer_joins!(*args)
|
38
|
-
self.joins_values += [''] # HACK for using outer_joins in update_all/delete_all
|
38
|
+
self.joins_values += [''] # HACK: for using outer_joins in update_all/delete_all
|
39
39
|
self.outer_joins_values += args
|
40
40
|
self
|
41
41
|
end
|
@@ -43,25 +43,25 @@ module ActiveScaffold
|
|
43
43
|
|
44
44
|
if Rails.version < '4.1'
|
45
45
|
def build_arel
|
46
|
-
|
47
|
-
|
46
|
+
if outer_joins_values.empty?
|
47
|
+
super
|
48
|
+
else
|
49
|
+
relation = except(:outer_joins)
|
48
50
|
join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, outer_joins_values, [])
|
49
51
|
join_dependency.join_associations.each do |association|
|
50
52
|
relation = association.join_relation(relation)
|
51
53
|
end
|
52
54
|
relation.build_arel
|
53
|
-
else
|
54
|
-
super
|
55
55
|
end
|
56
56
|
end
|
57
57
|
else
|
58
58
|
def build_arel
|
59
|
-
|
60
|
-
|
59
|
+
if outer_joins_values.empty?
|
60
|
+
super
|
61
|
+
else
|
62
|
+
relation = except(:outer_joins)
|
61
63
|
relation.joins! ActiveRecord::Associations::JoinDependency.new(@klass, outer_joins_values, [])
|
62
64
|
relation.build_arel
|
63
|
-
else
|
64
|
-
super
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -4,7 +4,7 @@ class Object
|
|
4
4
|
text = I18n.translate("#{key}", {:scope => [:active_scaffold, *options.delete(:scope)], :default => key.is_a?(String) ? key : key.to_s.titleize}.merge(options)).html_safe
|
5
5
|
# text = nil if text.include?('translation missing:')
|
6
6
|
end
|
7
|
-
text ||= key
|
7
|
+
text ||= key
|
8
8
|
text
|
9
9
|
end
|
10
10
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveScaffold
|
2
2
|
module DateSelectExtension
|
3
3
|
def datetime_selector_with_name(options, html_options)
|
4
|
-
options.merge!(:prefix => options[:name].gsub(/\[[^\[]*\]$/,'')) if options[:name]
|
4
|
+
options.merge!(:prefix => options[:name].gsub(/\[[^\[]*\]$/, '')) if options[:name]
|
5
5
|
datetime_selector_without_name(options, html_options)
|
6
6
|
end
|
7
7
|
def self.included(base)
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'active_scaffold/paginator'
|
2
2
|
|
3
3
|
class Paginator
|
4
|
-
|
5
4
|
# Total number of pages
|
6
5
|
def number_of_pages_with_infinite
|
7
6
|
number_of_pages_without_infinite if @count
|
8
7
|
end
|
9
8
|
alias_method_chain :number_of_pages, :infinite
|
10
|
-
|
9
|
+
|
11
10
|
# Is this an "infinite" paginator
|
12
11
|
def infinite?
|
13
12
|
@count.nil?
|
@@ -16,7 +15,7 @@ class Paginator
|
|
16
15
|
def count
|
17
16
|
@count || first.items.size
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
class Page
|
21
20
|
# Checks to see if there's a page after this one
|
22
21
|
def next_with_infinite?
|
@@ -33,6 +32,4 @@ class Paginator
|
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
38
|
-
|