active_scaffold 3.4.43 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +39 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +27 -19
- data/app/assets/javascripts/active_scaffold.js.erb +1 -1
- data/app/assets/javascripts/jquery/active_scaffold.js +95 -43
- data/app/assets/javascripts/jquery/tiny_mce_bridge.js +30 -6
- data/app/assets/javascripts/prototype/tiny_mce_bridge.js +11 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +2 -2
- data/app/assets/stylesheets/active_scaffold_layout.css +36 -28
- data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -3
- data/app/views/active_scaffold_overrides/_field_search.html.erb +8 -7
- data/app/views/active_scaffold_overrides/_form_association.html.erb +9 -9
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +52 -50
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_human_conditions.html.erb +3 -1
- data/app/views/active_scaffold_overrides/_list_calculations.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_list_column_headings.html.erb +2 -0
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +5 -3
- data/app/views/active_scaffold_overrides/_list_record.html.erb +3 -1
- data/app/views/active_scaffold_overrides/_list_with_header.html.erb +9 -9
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +18 -10
- data/app/views/active_scaffold_overrides/_render_field.js.erb +3 -3
- data/app/views/active_scaffold_overrides/_search.html.erb +7 -6
- data/app/views/active_scaffold_overrides/_show_actions.html.erb +14 -0
- data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_actions.html.erb +6 -2
- data/app/views/active_scaffold_overrides/_update_column.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/destroy.js.erb +2 -3
- data/app/views/active_scaffold_overrides/edit_associated.js.erb +4 -3
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +5 -3
- data/app/views/active_scaffold_overrides/on_create.js.erb +4 -4
- data/app/views/active_scaffold_overrides/on_update.js.erb +6 -6
- data/app/views/active_scaffold_overrides/show.html.erb +6 -0
- data/app/views/active_scaffold_overrides/update.html.erb +1 -1
- data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
- data/config/brakeman.ignore +26 -0
- data/config/brakeman.yml +3 -0
- data/config/i18n-tasks.yml +121 -0
- data/config/locales/de.yml +81 -70
- data/config/locales/en.yml +83 -74
- data/config/locales/es.yml +82 -73
- data/config/locales/fr.yml +86 -75
- data/config/locales/hu.yml +81 -70
- data/config/locales/ja.yml +71 -60
- data/config/locales/ru.yml +85 -74
- data/lib/active_scaffold.rb +3 -0
- data/lib/active_scaffold/actions/common_search.rb +11 -7
- data/lib/active_scaffold/actions/core.rb +119 -47
- data/lib/active_scaffold/actions/create.rb +1 -1
- data/lib/active_scaffold/actions/delete.rb +11 -8
- data/lib/active_scaffold/actions/field_search.rb +104 -6
- data/lib/active_scaffold/actions/list.rb +25 -21
- data/lib/active_scaffold/actions/mark.rb +12 -4
- data/lib/active_scaffold/actions/nested.rb +26 -26
- data/lib/active_scaffold/actions/search.rb +2 -2
- data/lib/active_scaffold/actions/show.rb +4 -5
- data/lib/active_scaffold/actions/subform.rb +9 -7
- data/lib/active_scaffold/actions/update.rb +20 -13
- data/lib/active_scaffold/active_record_permissions.rb +24 -5
- data/lib/active_scaffold/attribute_params.rb +68 -49
- data/lib/active_scaffold/bridges.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +15 -19
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +10 -14
- data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -7
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +19 -22
- data/lib/active_scaffold/bridges/cancan.rb +4 -3
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +11 -21
- data/lib/active_scaffold/bridges/carrierwave.rb +2 -1
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +2 -6
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +6 -39
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/chosen.rb +4 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +3 -2
- data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +2 -2
- data/lib/active_scaffold/bridges/date_picker.rb +3 -0
- data/lib/active_scaffold/bridges/date_picker/ext.rb +43 -38
- data/lib/active_scaffold/bridges/date_picker/helper.rb +24 -23
- data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +3 -25
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +2 -2
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +6 -8
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +0 -2
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +2 -1
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/actions.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -2
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/paperclip.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +3 -28
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +3 -7
- data/lib/active_scaffold/bridges/record_select.rb +2 -0
- data/lib/active_scaffold/bridges/record_select/helpers.rb +14 -18
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +4 -8
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -20
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +7 -22
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +14 -14
- data/lib/active_scaffold/config/base.rb +9 -6
- data/lib/active_scaffold/config/core.rb +30 -21
- data/lib/active_scaffold/config/create.rb +2 -1
- data/lib/active_scaffold/config/delete.rb +2 -2
- data/lib/active_scaffold/config/field_search.rb +9 -3
- data/lib/active_scaffold/config/form.rb +4 -4
- data/lib/active_scaffold/config/list.rb +27 -23
- data/lib/active_scaffold/config/nested.rb +4 -4
- data/lib/active_scaffold/config/search.rb +6 -6
- data/lib/active_scaffold/config/show.rb +11 -1
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +4 -2
- data/lib/active_scaffold/constraints.rb +39 -36
- data/lib/active_scaffold/core.rb +36 -15
- data/lib/active_scaffold/data_structures/action_columns.rb +14 -9
- data/lib/active_scaffold/data_structures/action_link.rb +4 -5
- data/lib/active_scaffold/data_structures/action_links.rb +5 -4
- data/lib/active_scaffold/data_structures/actions.rb +2 -2
- data/lib/active_scaffold/data_structures/association.rb +8 -0
- data/lib/active_scaffold/data_structures/association/abstract.rb +147 -0
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +42 -0
- data/lib/active_scaffold/data_structures/association/active_record.rb +94 -0
- data/lib/active_scaffold/data_structures/association/mongoid.rb +45 -0
- data/lib/active_scaffold/data_structures/bridge.rb +3 -6
- data/lib/active_scaffold/data_structures/column.rb +100 -82
- data/lib/active_scaffold/data_structures/columns.rb +21 -3
- data/lib/active_scaffold/data_structures/nested_info.rb +22 -37
- data/lib/active_scaffold/data_structures/set.rb +4 -4
- data/lib/active_scaffold/data_structures/sorting.rb +29 -15
- data/lib/active_scaffold/engine.rb +3 -1
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +10 -5
- data/lib/active_scaffold/extensions/action_view_rendering.rb +65 -59
- data/lib/active_scaffold/extensions/left_outer_joins.rb +48 -53
- data/lib/active_scaffold/extensions/localize.rb +3 -4
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +7 -11
- data/lib/active_scaffold/extensions/paginator_extensions.rb +20 -18
- data/lib/active_scaffold/extensions/routing_mapper.rb +104 -40
- data/lib/active_scaffold/extensions/to_label.rb +1 -1
- data/lib/active_scaffold/extensions/unsaved_associated.rb +4 -13
- data/lib/active_scaffold/extensions/unsaved_record.rb +12 -1
- data/lib/active_scaffold/finder.rb +200 -134
- data/lib/active_scaffold/helpers/action_link_helpers.rb +398 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +12 -30
- data/lib/active_scaffold/helpers/controller_helpers.rb +74 -24
- data/lib/active_scaffold/helpers/form_column_helpers.rb +205 -112
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +21 -11
- data/lib/active_scaffold/helpers/id_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/list_column_helpers.rb +117 -39
- data/lib/active_scaffold/helpers/pagination_helpers.rb +11 -14
- data/lib/active_scaffold/helpers/search_column_helpers.rb +69 -32
- data/lib/active_scaffold/helpers/show_column_helpers.rb +9 -3
- data/lib/active_scaffold/helpers/view_helpers.rb +41 -426
- data/lib/active_scaffold/orm_checks.rb +109 -0
- data/lib/active_scaffold/paginator.rb +1 -1
- data/lib/active_scaffold/responds_to_parent.rb +12 -10
- data/lib/active_scaffold/tableless.rb +81 -43
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/generators/active_scaffold/controller_generator.rb +49 -0
- data/lib/generators/active_scaffold/install_generator.rb +45 -0
- data/lib/generators/active_scaffold/resource_generator.rb +56 -0
- data/lib/generators/{active_scaffold_controller/templates → templates}/controller.rb +0 -0
- data/lib/generators/{active_scaffold_controller/templates → templates}/helper.rb +0 -0
- data/shoulda_macros/macros.rb +3 -3
- data/test/active_scaffold_config_mock.rb +33 -0
- data/test/bridges/bridge_test.rb +9 -9
- data/test/bridges/date_picker_test.rb +3 -1
- data/test/bridges/paper_trail_test.rb +2 -3
- data/test/bridges/paperclip_test.rb +21 -10
- data/test/bridges/tiny_mce_test.rb +20 -21
- data/test/class_with_finder.rb +42 -0
- data/test/company.rb +6 -4
- data/test/config/core_test.rb +1 -1
- data/test/config/create_test.rb +1 -1
- data/test/config/list_test.rb +3 -3
- data/test/config/update_test.rb +3 -3
- data/test/data_structures/action_columns_test.rb +3 -3
- data/test/data_structures/association_column_test.rb +5 -5
- data/test/data_structures/column_test.rb +14 -14
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/set_test.rb +2 -2
- data/test/data_structures/sorting_test.rb +6 -4
- data/test/extensions/active_record_test.rb +1 -1
- data/test/extensions/routing_mapper_test.rb +64 -13
- data/test/helpers/form_column_helpers_test.rb +6 -6
- data/test/helpers/list_column_helpers_test.rb +9 -5
- data/test/helpers/pagination_helpers_test.rb +1 -0
- data/test/misc/active_record_permissions_test.rb +18 -1
- data/test/misc/attribute_params_test.rb +26 -17
- data/test/misc/calculation_test.rb +8 -31
- data/test/misc/configurable_test.rb +3 -2
- data/test/misc/constraints_test.rb +33 -22
- data/test/misc/convert_numbers_format_test.rb +28 -10
- data/test/misc/finder_test.rb +6 -29
- data/test/misc/parse_datetime_test.rb +160 -0
- data/test/misc/render_test.rb +1 -1
- data/test/misc/tableless_test.rb +24 -0
- data/test/mock_app/app/models/building.rb +2 -1
- data/test/mock_app/config.ru +1 -1
- data/test/mock_app/config/environments/test.rb +1 -1
- data/test/mock_app/config/routes.rb +11 -3
- data/test/model_stub.rb +11 -6
- data/test/run_all.rb +1 -1
- data/test/test_helper.rb +19 -4
- metadata +42 -23
- data/lib/active_scaffold/data_structures/error_message.rb +0 -22
- data/lib/active_scaffold/extensions/reverse_associations.rb +0 -119
- data/lib/generators/active_scaffold/USAGE +0 -29
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +0 -21
- data/lib/generators/active_scaffold_controller/USAGE +0 -19
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +0 -29
- data/test/data_structures/error_message_test.rb +0 -25
@@ -1,73 +1,68 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
1
|
+
if Rails.version < '5.0.0'
|
2
|
+
module ActiveScaffold
|
3
|
+
module OuterJoins
|
4
|
+
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
const_get(:MULTI_VALUE_METHODS) << :outer_joins
|
6
|
+
def left_outer_joins_values
|
7
|
+
@values[:left_outer_joins] || []
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
relation = clone
|
15
|
-
|
16
|
-
args.flatten!
|
17
|
-
relation.joins_values += [''] # HACK: for using outer_joins in update_all/delete_all
|
18
|
-
relation.outer_joins_values += args
|
19
|
-
|
20
|
-
relation
|
21
|
-
end
|
22
|
-
else
|
23
|
-
def outer_joins_values
|
24
|
-
@values[:outer_joins] || []
|
10
|
+
def left_outer_joins_values=(values)
|
11
|
+
raise ImmutableRelation if @loaded
|
12
|
+
@values[:left_outer_joins] = values
|
25
13
|
end
|
26
14
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
15
|
+
def left_outer_joins(*args)
|
16
|
+
check_if_method_has_arguments!('left_outer_joins', args)
|
17
|
+
spawn.left_outer_joins!(*args.compact.flatten)
|
30
18
|
end
|
19
|
+
alias left_joins left_outer_joins
|
31
20
|
|
32
21
|
def outer_joins(*args)
|
33
|
-
|
34
|
-
|
22
|
+
ActiveSupport::Deprecation.warn 'use left_outer_joins or left_joins which is added to Rails 5.0.0'
|
23
|
+
left_outer_joins(*args)
|
35
24
|
end
|
36
25
|
|
37
|
-
def
|
38
|
-
self.joins_values += [''] # HACK: for using
|
39
|
-
self.
|
26
|
+
def left_outer_joins!(*args)
|
27
|
+
self.joins_values += [''] # HACK: for using left_outer_joins in update_all/delete_all
|
28
|
+
self.left_outer_joins_values += args
|
40
29
|
self
|
41
30
|
end
|
42
|
-
|
31
|
+
alias left_joins! left_outer_joins!
|
32
|
+
|
33
|
+
def outer_joins!(*args)
|
34
|
+
ActiveSupport::Deprecation.warn 'use left_outer_joins! or left_joins! which is added to Rails 5.0.0'
|
35
|
+
left_outer_joins!(*args)
|
36
|
+
end
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
38
|
+
if Rails.version < '4.1'
|
39
|
+
def build_arel
|
40
|
+
if left_outer_joins_values.empty?
|
41
|
+
super
|
42
|
+
else
|
43
|
+
relation = except(:left_outer_joins)
|
44
|
+
join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, left_outer_joins_values, [])
|
45
|
+
join_dependency.join_associations.each do |association|
|
46
|
+
relation = association.join_relation(relation)
|
47
|
+
end
|
48
|
+
relation.build_arel
|
53
49
|
end
|
54
|
-
relation.build_arel
|
55
50
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
51
|
+
else
|
52
|
+
def build_arel
|
53
|
+
if left_outer_joins_values.empty?
|
54
|
+
super
|
55
|
+
else
|
56
|
+
relation = except(:left_outer_joins)
|
57
|
+
relation.joins! ActiveRecord::Associations::JoinDependency.new(@klass, left_outer_joins_values, [])
|
58
|
+
relation.build_arel
|
59
|
+
end
|
65
60
|
end
|
66
61
|
end
|
67
62
|
end
|
68
63
|
end
|
69
|
-
|
70
|
-
ActiveRecord::
|
71
|
-
|
72
|
-
|
64
|
+
ActiveRecord::Relation.send :include, ActiveScaffold::OuterJoins
|
65
|
+
module ActiveRecord::Querying
|
66
|
+
delegate :left_outer_joins, :left_joins, :outer_joins, :to => :all
|
67
|
+
end
|
73
68
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
class Object
|
2
2
|
def as_(key, options = {})
|
3
|
-
|
4
|
-
text = I18n.translate(
|
3
|
+
if key.present?
|
4
|
+
text = I18n.translate(key.to_s, {: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
|
8
|
-
text
|
7
|
+
text || key
|
9
8
|
end
|
10
9
|
end
|
@@ -1,17 +1,13 @@
|
|
1
1
|
module ActiveScaffold
|
2
2
|
module DateSelectExtension
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
base.class_eval do
|
9
|
-
alias_method_chain :datetime_selector, :name
|
10
|
-
private :datetime_selector_without_name, :datetime_selector_with_name, :datetime_selector
|
11
|
-
end
|
3
|
+
private
|
4
|
+
|
5
|
+
def datetime_selector(options, html_options)
|
6
|
+
options[:prefix] = options[:name].gsub(/\[[^\[]*\]$/, '') if options[:name]
|
7
|
+
super(options, html_options)
|
12
8
|
end
|
13
9
|
end
|
14
10
|
end
|
15
|
-
|
16
|
-
|
11
|
+
ActionView::Helpers::Tags::DateSelect.class_eval do
|
12
|
+
prepend ActiveScaffold::DateSelectExtension
|
17
13
|
end
|
@@ -1,35 +1,37 @@
|
|
1
1
|
require 'active_scaffold/paginator'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module ActiveScaffold
|
4
|
+
module Paginator
|
5
|
+
# Total number of pages
|
6
|
+
def number_of_pages
|
7
|
+
super if @count
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
# Is this an "infinite" paginator
|
11
|
+
def infinite?
|
12
|
+
@count.nil?
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
def count
|
16
|
+
@count || first.items.size
|
17
|
+
end
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
+
module Page
|
20
21
|
# Checks to see if there's a page after this one
|
21
|
-
def
|
22
|
-
|
23
|
-
next_without_infinite?
|
22
|
+
def next?
|
23
|
+
@pager.infinite? || super
|
24
24
|
end
|
25
|
-
alias_method_chain :next?, :infinite
|
26
25
|
|
27
26
|
def empty?
|
28
27
|
if @pager.infinite?
|
29
28
|
items.to_a.empty?
|
30
29
|
else
|
31
|
-
@pager.count
|
30
|
+
@pager.count.zero?
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
35
|
+
|
36
|
+
Paginator.class_eval { prepend ActiveScaffold::Paginator }
|
37
|
+
Paginator::Page.class_eval { prepend ActiveScaffold::Page }
|
@@ -1,73 +1,137 @@
|
|
1
|
-
module
|
1
|
+
module ActiveScaffold
|
2
2
|
module Routing
|
3
3
|
ACTIVE_SCAFFOLD_CORE_ROUTING = {
|
4
4
|
:collection => {:show_search => :get, :render_field => :post, :mark => :post},
|
5
|
-
:member => {:update_column => :post, :render_field => [
|
6
|
-
}
|
5
|
+
:member => {:update_column => :post, :render_field => %i[get post], :mark => :post}
|
6
|
+
}.freeze
|
7
7
|
ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = {
|
8
8
|
:collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post},
|
9
9
|
:member => {:edit_associated => :get, :destroy_existing => :delete}
|
10
|
-
}
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
class Association
|
13
|
+
def default_actions(actions_hash)
|
14
|
+
(actions_hash[:collection].keys + actions_hash[:member].keys).uniq
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_actions(actions_hash, options)
|
18
|
+
default_actions = default_actions(actions_hash)
|
19
|
+
if only = options[:only]
|
20
|
+
Array(only).map(&:to_sym)
|
21
|
+
elsif except = options[:except]
|
22
|
+
default_actions - Array(except).map(&:to_sym)
|
23
|
+
else
|
24
|
+
default_actions
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(mapper, options = {})
|
29
|
+
actions = get_actions(ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING, options)
|
30
|
+
|
31
|
+
mapper.collection do
|
32
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each do |name, type|
|
33
|
+
mapper.match(name, via: type) if actions.include? name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
mapper.member do
|
38
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each do |name, type|
|
39
|
+
mapper.match(name, via: type) if actions.include? name
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Basic < Association
|
46
|
+
def initialize(defaults = {})
|
47
|
+
@defaults = defaults
|
48
|
+
end
|
49
|
+
|
50
|
+
def call(mapper, options = {})
|
51
|
+
options = @defaults.merge(options)
|
52
|
+
actions = get_actions(ACTIVE_SCAFFOLD_CORE_ROUTING, options)
|
53
|
+
|
54
|
+
mapper.collection do
|
55
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each do |name, type|
|
56
|
+
mapper.match(name, via: type) if actions.include? name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
mapper.member do
|
61
|
+
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each do |name, type|
|
62
|
+
mapper.match(name, via: type) if actions.include? name
|
63
|
+
end
|
64
|
+
mapper.get 'list', action: :index if mapper.send(:parent_resource).actions.include? :index
|
65
|
+
end
|
66
|
+
|
67
|
+
super if options[:association]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module ActionDispatch
|
74
|
+
module Routing
|
75
|
+
ACTIVE_SCAFFOLD_CORE_ROUTING = ActiveScaffold::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING
|
76
|
+
ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = ActiveScaffold::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING
|
11
77
|
|
12
78
|
class Mapper
|
13
79
|
module Resources
|
14
|
-
|
15
|
-
|
16
|
-
|
80
|
+
def parent_options
|
81
|
+
opts = parent_resource.instance_variable_get(:@options)
|
82
|
+
if Rails.version >= '5.0.0'
|
83
|
+
opts.merge(
|
84
|
+
only: parent_resource.instance_variable_get(:@only),
|
85
|
+
except: parent_resource.instance_variable_get(:@except)
|
86
|
+
)
|
17
87
|
end
|
88
|
+
opts
|
18
89
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
90
|
+
|
91
|
+
def define_active_scaffold_concern
|
92
|
+
ActiveSupport::Deprecation.warn 'Add concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true) to your routes file.'
|
93
|
+
concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)
|
23
94
|
end
|
24
95
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each do |name, type|
|
35
|
-
match(name, :via => type) if parent_resource.actions.include? name
|
36
|
-
end
|
37
|
-
get 'list', :action => :index if resource.actions.include? :index
|
38
|
-
end
|
96
|
+
def define_active_scaffold_association_concern
|
97
|
+
ActiveSupport::Deprecation.warn 'Add concern :active_scaffold_association, ActiveScaffold::Routing::Association.new to your routes file.'
|
98
|
+
concern :active_scaffold_association, ActiveScaffold::Routing::Association.new
|
99
|
+
end
|
100
|
+
|
101
|
+
def as_routes(opts = {association: true})
|
102
|
+
define_active_scaffold_concern unless @concerns[:active_scaffold]
|
103
|
+
if opts[:association] && !@concerns[:active_scaffold_association]
|
104
|
+
define_active_scaffold_association_concern
|
39
105
|
end
|
40
|
-
|
106
|
+
ActiveSupport::Deprecation.warn 'Use concerns: :active_scaffold in resources instead of as_routes, or concerns :active_scaffold in resources block if want to disable association routes or restrict routes with only or except options.'
|
107
|
+
concerns :active_scaffold, parent_options.merge(association: opts[:association])
|
41
108
|
end
|
42
109
|
|
43
110
|
def as_association_routes
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
match(name, :via => type) if parent_resource.actions.include? name
|
48
|
-
end
|
49
|
-
end
|
50
|
-
member do
|
51
|
-
ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each do |name, type|
|
52
|
-
match(name, :via => type) if parent_resource.actions.include? name
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
111
|
+
define_active_scaffold_association_concern unless @concerns[:active_scaffold_association]
|
112
|
+
ActiveSupport::Deprecation.warn 'Use concerns: :active_scaffold_association in resources instead of as_association_routes, or concerns :active_scaffold_association in resources block if want to restrict routes with only or except options.'
|
113
|
+
concerns :active_scaffold_association, parent_options
|
56
114
|
end
|
57
115
|
|
58
116
|
def as_nested_resources(*resources)
|
59
117
|
options = resources.extract_options!
|
118
|
+
nested_options = options.merge(parent_scaffold: parent_scaffold)
|
60
119
|
resources.each do |resource|
|
61
|
-
resources(resource,
|
120
|
+
resources(resource, nested_options.merge(association: resource)) { yield if block_given? }
|
62
121
|
end
|
63
122
|
end
|
64
123
|
|
65
124
|
def as_scoped_routes(*scopes)
|
66
125
|
options = scopes.extract_options!
|
126
|
+
scoped_options = options.merge(parent_scaffold: parent_scaffold, association: parent_resource.plural)
|
67
127
|
scopes.each do |scope|
|
68
|
-
resources(scope,
|
128
|
+
resources(scope, scoped_options.merge(named_scope: scope)) { yield if block_given? }
|
69
129
|
end
|
70
130
|
end
|
131
|
+
|
132
|
+
def parent_scaffold
|
133
|
+
merge_module_scope(@scope[:module], parent_resource.plural)
|
134
|
+
end
|
71
135
|
end
|
72
136
|
end
|
73
137
|
end
|
@@ -13,20 +13,11 @@ class ActiveRecord::Base
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def save_associated!
|
16
|
-
save_associated || raise(ActiveRecord::RecordNotSaved)
|
16
|
+
save_associated || raise(ActiveRecord::RecordNotSaved, "Fail saving associations for #{inspect}")
|
17
17
|
end
|
18
18
|
|
19
19
|
def no_errors_in_associated?
|
20
|
-
with_unsaved_associated { |a| a.errors.count
|
21
|
-
end
|
22
|
-
|
23
|
-
def keeping_errors
|
24
|
-
old_errors = errors.dup if errors.present?
|
25
|
-
yield.tap do
|
26
|
-
(old_errors || []).each do |attr|
|
27
|
-
old_errors[attr].each { |msg| errors.add(attr, msg) unless errors.added?(attr, msg) }
|
28
|
-
end
|
29
|
-
end
|
20
|
+
with_unsaved_associated { |a| a.errors.count.zero? && a.no_errors_in_associated? }
|
30
21
|
end
|
31
22
|
|
32
23
|
protected
|
@@ -42,9 +33,9 @@ class ActiveRecord::Base
|
|
42
33
|
#
|
43
34
|
# Otherwise the default behaviour of traversing all associations will be preserved.
|
44
35
|
def associations_for_update
|
45
|
-
if
|
36
|
+
if respond_to?(:scaffold_update_nofollow)
|
46
37
|
self.class.reflect_on_all_associations.reject { |association| scaffold_update_nofollow.include?(association.name) }
|
47
|
-
elsif
|
38
|
+
elsif respond_to?(:scaffold_update_follow)
|
48
39
|
self.class.reflect_on_all_associations.select { |association| scaffold_update_follow.include?(association.name) }
|
49
40
|
else
|
50
41
|
self.class.reflect_on_all_associations
|
@@ -2,7 +2,7 @@
|
|
2
2
|
module ActiveScaffold::UnsavedRecord
|
3
3
|
# acts like a dirty? flag, manually thrown during update_record_from_params.
|
4
4
|
def unsaved=(val)
|
5
|
-
@unsaved =
|
5
|
+
@unsaved = val ? true : false
|
6
6
|
end
|
7
7
|
|
8
8
|
# whether the unsaved? flag has been thrown
|
@@ -14,5 +14,16 @@ module ActiveScaffold::UnsavedRecord
|
|
14
14
|
def save(*)
|
15
15
|
super.tap { self.unsaved = false }
|
16
16
|
end
|
17
|
+
|
18
|
+
def keeping_errors
|
19
|
+
old_errors = errors.dup if errors.present?
|
20
|
+
result = yield
|
21
|
+
if old_errors
|
22
|
+
old_errors.each do |attr|
|
23
|
+
old_errors[attr].each { |msg| errors.add(attr, msg) unless errors.added?(attr, msg) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
result && old_errors.blank?
|
27
|
+
end
|
17
28
|
end
|
18
29
|
ActiveRecord::Base.class_eval { include ActiveScaffold::UnsavedRecord }
|