active_scaffold 3.5.2 → 3.6.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{CHANGELOG → CHANGELOG.rdoc} +66 -0
- data/README.md +17 -7
- data/app/assets/javascripts/active_scaffold.js.erb +0 -1
- data/app/assets/javascripts/jquery/active_scaffold.js +63 -6
- data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
- data/app/assets/stylesheets/active_scaffold_layout.css +52 -29
- data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +3 -2
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +6 -6
- 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/_list.html.erb +2 -1
- data/app/views/active_scaffold_overrides/_list_header.html.erb +5 -7
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_list_record.html.erb +4 -5
- data/app/views/active_scaffold_overrides/_list_with_header.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +4 -0
- data/app/views/active_scaffold_overrides/_render_field.js.erb +2 -1
- data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -1
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_update_calculations.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_column.js.erb +2 -2
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
- data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +16 -6
- data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
- data/app/views/active_scaffold_overrides/row.js.erb +1 -1
- data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
- data/config/locales/de.yml +2 -1
- data/config/locales/en.yml +1 -0
- data/config/locales/es.yml +1 -0
- data/config/locales/fr.yml +2 -1
- data/config/locales/hu.yml +1 -0
- data/config/locales/ja.yml +1 -0
- data/config/locales/ru.yml +1 -0
- data/lib/active_scaffold.rb +19 -16
- data/lib/active_scaffold/actions/common_search.rb +11 -8
- data/lib/active_scaffold/actions/core.rb +89 -71
- data/lib/active_scaffold/actions/create.rb +28 -28
- data/lib/active_scaffold/actions/delete.rb +3 -3
- data/lib/active_scaffold/actions/field_search.rb +53 -43
- data/lib/active_scaffold/actions/list.rb +111 -27
- data/lib/active_scaffold/actions/nested.rb +65 -48
- data/lib/active_scaffold/actions/search.rb +1 -1
- data/lib/active_scaffold/actions/show.rb +4 -4
- data/lib/active_scaffold/actions/subform.rb +12 -17
- data/lib/active_scaffold/actions/update.rb +96 -77
- data/lib/active_scaffold/active_record_permissions.rb +2 -11
- data/lib/active_scaffold/attribute_params.rb +104 -86
- data/lib/active_scaffold/bridges.rb +8 -8
- data/lib/active_scaffold/bridges/active_storage.rb +6 -0
- data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +33 -0
- data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +54 -0
- data/lib/active_scaffold/bridges/active_storage/form_ui.rb +22 -0
- data/lib/active_scaffold/bridges/active_storage/list_ui.rb +36 -0
- data/lib/active_scaffold/bridges/bitfields.rb +1 -0
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -15
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +9 -12
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +2 -2
- data/lib/active_scaffold/bridges/chosen/helpers.rb +11 -9
- data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
- data/lib/active_scaffold/bridges/date_picker/helper.rb +49 -44
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +10 -7
- data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
- data/lib/active_scaffold/bridges/record_select/helpers.rb +12 -16
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -19
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -1
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +21 -4
- data/lib/active_scaffold/config/base.rb +133 -41
- data/lib/active_scaffold/config/core.rb +146 -18
- data/lib/active_scaffold/config/delete.rb +14 -1
- data/lib/active_scaffold/config/field_search.rb +7 -1
- data/lib/active_scaffold/config/form.rb +10 -1
- data/lib/active_scaffold/config/list.rb +39 -13
- data/lib/active_scaffold/config/mark.rb +4 -2
- data/lib/active_scaffold/config/nested.rb +16 -17
- data/lib/active_scaffold/config/search.rb +9 -0
- data/lib/active_scaffold/config/show.rb +4 -0
- data/lib/active_scaffold/config/update.rb +4 -0
- data/lib/active_scaffold/configurable.rb +14 -7
- data/lib/active_scaffold/constraints.rb +22 -20
- data/lib/active_scaffold/core.rb +68 -29
- data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
- data/lib/active_scaffold/data_structures/action_link.rb +50 -20
- data/lib/active_scaffold/data_structures/action_links.rb +15 -13
- data/lib/active_scaffold/data_structures/association/abstract.rb +41 -15
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +2 -6
- data/lib/active_scaffold/data_structures/association/active_record.rb +6 -2
- data/lib/active_scaffold/data_structures/association/mongoid.rb +0 -3
- data/lib/active_scaffold/data_structures/column.rb +75 -66
- data/lib/active_scaffold/data_structures/columns.rb +3 -2
- data/lib/active_scaffold/data_structures/nested_info.rb +21 -19
- data/lib/active_scaffold/data_structures/set.rb +8 -0
- data/lib/active_scaffold/data_structures/sorting.rb +10 -2
- data/lib/active_scaffold/delayed_setup.rb +16 -5
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -2
- data/lib/active_scaffold/extensions/action_view_rendering.rb +34 -14
- data/lib/active_scaffold/extensions/cow_proxy.rb +91 -0
- data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
- data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
- data/lib/active_scaffold/extensions/localize.rb +3 -1
- data/lib/active_scaffold/extensions/routing_mapper.rb +6 -45
- data/lib/active_scaffold/extensions/to_label.rb +3 -2
- data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
- data/lib/active_scaffold/finder.rb +104 -73
- data/lib/active_scaffold/helpers/action_link_helpers.rb +62 -36
- data/lib/active_scaffold/helpers/association_helpers.rb +21 -19
- data/lib/active_scaffold/helpers/controller_helpers.rb +23 -10
- data/lib/active_scaffold/helpers/form_column_helpers.rb +157 -121
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/id_helpers.rb +6 -2
- data/lib/active_scaffold/helpers/list_column_helpers.rb +82 -53
- data/lib/active_scaffold/helpers/pagination_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/search_column_helpers.rb +29 -34
- data/lib/active_scaffold/helpers/show_column_helpers.rb +3 -5
- data/lib/active_scaffold/helpers/view_helpers.rb +38 -35
- data/lib/active_scaffold/marked_model.rb +2 -2
- data/lib/active_scaffold/orm_checks.rb +3 -7
- data/lib/active_scaffold/paginator.rb +7 -7
- data/lib/active_scaffold/registry.rb +33 -0
- data/lib/active_scaffold/responds_to_parent.rb +8 -11
- data/lib/active_scaffold/tableless.rb +67 -65
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/generators/active_scaffold/controller_generator.rb +2 -2
- data/lib/generators/active_scaffold/install_generator.rb +1 -1
- data/lib/generators/active_scaffold/resource_generator.rb +2 -2
- data/shoulda_macros/macros.rb +3 -1
- data/test/bridges/date_picker_test.rb +1 -2
- data/test/bridges/paperclip_test.rb +6 -6
- data/test/class_with_finder.rb +2 -2
- data/test/company.rb +4 -4
- data/test/config/create_test.rb +4 -2
- data/test/config/nested_test.rb +1 -1
- data/test/config/show_test.rb +1 -1
- data/test/config/update_test.rb +7 -6
- data/test/data_structures/action_columns_test.rb +2 -2
- data/test/data_structures/action_links_test.rb +1 -1
- data/test/data_structures/column_test.rb +3 -6
- data/test/data_structures/columns_test.rb +2 -2
- data/test/data_structures/sorting_test.rb +7 -0
- data/test/extensions/active_record_test.rb +4 -4
- data/test/extensions/routing_mapper_test.rb +2 -2
- data/test/helpers/list_column_helpers_test.rb +3 -1
- data/test/misc/active_record_permissions_test.rb +3 -11
- data/test/misc/attribute_params_test.rb +12 -8
- data/test/misc/calculation_test.rb +1 -1
- data/test/misc/configurable_test.rb +10 -10
- data/test/misc/constraints_test.rb +2 -2
- data/test/misc/convert_numbers_format_test.rb +7 -3
- data/test/misc/lang_test.rb +1 -1
- data/test/misc/parse_datetime_test.rb +3 -4
- data/test/misc/tableless_test.rb +6 -0
- data/test/mock_app/Rakefile +1 -1
- data/test/mock_app/app/assets/config/manifest.js +0 -0
- data/test/mock_app/app/controllers/cars_controller.rb +1 -0
- data/test/mock_app/app/controllers/people_controller.rb +3 -1
- data/test/mock_app/config/application.rb +2 -1
- data/test/mock_app/config/boot.rb +1 -1
- data/test/mock_app/config/environment.rb +2 -2
- data/test/mock_app/config/routes.rb +4 -1
- data/test/mock_app/db/schema.rb +2 -0
- data/test/performance/list_cars_performance_test.rb +34 -0
- data/test/performance/list_people_performance_test.rb +31 -0
- data/test/performance_test_help.rb +3 -0
- data/test/test_helper.rb +10 -2
- metadata +56 -15
- data/app/assets/javascripts/prototype/rico_corner.js +0 -370
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +0 -7
@@ -11,7 +11,7 @@ module ActiveScaffold
|
|
11
11
|
self.bridges = {}
|
12
12
|
|
13
13
|
def self.register(file)
|
14
|
-
match = file.match(
|
14
|
+
match = file.match(%r{(active_scaffold/bridges/(.*))\.rb\Z})
|
15
15
|
bridges[match[2].to_sym] = match[1] if match
|
16
16
|
end
|
17
17
|
|
@@ -34,18 +34,18 @@ module ActiveScaffold
|
|
34
34
|
|
35
35
|
def self.run_all
|
36
36
|
return false if bridges_run
|
37
|
-
bridges.
|
38
|
-
|
39
|
-
bridge.run if bridge
|
37
|
+
bridges.each_key do |bridge_name|
|
38
|
+
self[bridge_name]&.run
|
40
39
|
end
|
40
|
+
ActiveScaffold::Config::Core.freeze if ActiveScaffold.threadsafe
|
41
41
|
self.bridges_run = true
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.prepare_all
|
45
45
|
return false if bridges_prepared
|
46
|
-
bridges.
|
46
|
+
bridges.each_key do |bridge_name|
|
47
47
|
bridge = self[bridge_name]
|
48
|
-
bridge.prepare if bridge
|
48
|
+
bridge.prepare if bridge&.install?
|
49
49
|
end
|
50
50
|
self.bridges_prepared = true
|
51
51
|
end
|
@@ -53,14 +53,14 @@ module ActiveScaffold
|
|
53
53
|
def self.all_stylesheets
|
54
54
|
bridges.keys.collect do |bridge_name|
|
55
55
|
bridge = self[bridge_name]
|
56
|
-
bridge.stylesheets if bridge
|
56
|
+
bridge.stylesheets if bridge&.install?
|
57
57
|
end.compact.flatten
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.all_javascripts
|
61
61
|
bridges.keys.collect do |bridge_name|
|
62
62
|
bridge = self[bridge_name]
|
63
|
-
bridge.javascripts if bridge
|
63
|
+
bridge.javascripts if bridge&.install?
|
64
64
|
end.compact.flatten
|
65
65
|
end
|
66
66
|
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class ActiveScaffold::Bridges::ActiveStorage < ActiveScaffold::DataStructures::Bridge
|
2
|
+
def self.install
|
3
|
+
Dir[File.join(__dir__, 'active_storage', '*.rb')].each { |file| require file }
|
4
|
+
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridge
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
module Bridges
|
3
|
+
class ActiveStorage
|
4
|
+
module ActiveStorageBridge
|
5
|
+
def initialize(model_id)
|
6
|
+
super
|
7
|
+
return unless ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridgeHelpers.klass_has_active_storage_fields?(model)
|
8
|
+
|
9
|
+
model.send :extend, ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridgeHelpers
|
10
|
+
|
11
|
+
# include the "delete" helpers for use with active scaffold, unless they are already included
|
12
|
+
model.generate_delete_helpers
|
13
|
+
|
14
|
+
update.multipart = true
|
15
|
+
create.multipart = true
|
16
|
+
|
17
|
+
model.active_storage_has_one_fields.each { |field| configure_active_storage_field(field.to_sym, :has_one) }
|
18
|
+
model.active_storage_has_many_fields.each { |field| configure_active_storage_field(field.to_sym, :has_many) }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def configure_active_storage_field(field, field_type)
|
24
|
+
columns << field
|
25
|
+
columns.exclude "#{field}_attachment#{'s' if field_type == :has_many}".to_sym
|
26
|
+
columns.exclude "#{field}_blob#{'s' if field_type == :has_many}".to_sym
|
27
|
+
columns[field].form_ui ||= "active_storage_#{field_type}".to_sym
|
28
|
+
columns[field].params.add "delete_#{field}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
module Bridges
|
3
|
+
class ActiveStorage
|
4
|
+
module ActiveStorageBridgeHelpers
|
5
|
+
mattr_accessor :thumbnail_variant
|
6
|
+
self.thumbnail_variant = {resize_to_limit: [nil, 30]}
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# has_one :"#{name}_attachment", -> { where(name: name) }, class_name: "ActiveStorage::Attachment", as: :record, inverse_of: :record, dependent: false
|
10
|
+
def active_storage_has_one_fields(klass)
|
11
|
+
klass.reflect_on_all_associations(:has_one)&.select { |reflection| reflection.class_name == 'ActiveStorage::Attachment' } &.collect { |association| association.name[0..-12] } || []
|
12
|
+
end
|
13
|
+
|
14
|
+
# has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment", inverse_of: :record, dependent: false do
|
15
|
+
def active_storage_has_many_fields(klass)
|
16
|
+
klass.reflect_on_all_associations(:has_many)&.select { |reflection| reflection.class_name == 'ActiveStorage::Attachment' } &.collect { |association| association.name[0..-13] } || []
|
17
|
+
end
|
18
|
+
|
19
|
+
def klass_has_active_storage_fields?(klass)
|
20
|
+
active_storage_has_one_fields(klass).present? || active_storage_has_many_fields(klass).present?
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_delete_helpers(klass)
|
24
|
+
(active_storage_has_one_fields(klass) | active_storage_has_many_fields(klass)).each do |field|
|
25
|
+
klass.send :class_eval, <<-CODE, __FILE__, __LINE__ + 1 unless klass.method_defined?(:"#{field}_with_delete=")
|
26
|
+
attr_reader :delete_#{field}
|
27
|
+
|
28
|
+
def delete_#{field}=(value)
|
29
|
+
value = (value=="true") if String===value
|
30
|
+
return unless value
|
31
|
+
|
32
|
+
# passing nil to the file column causes the file to be deleted.
|
33
|
+
self.#{field}.purge
|
34
|
+
end
|
35
|
+
CODE
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def active_storage_has_one_fields
|
41
|
+
@active_storage_has_one_fields ||= ActiveStorageBridgeHelpers.active_storage_has_one_fields(self)
|
42
|
+
end
|
43
|
+
|
44
|
+
def active_storage_has_many_fields
|
45
|
+
@active_storage_has_many_fields ||= ActiveStorageBridgeHelpers.active_storage_has_many_fields(self)
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_delete_helpers
|
49
|
+
ActiveStorageBridgeHelpers.generate_delete_helpers(self)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
module Helpers
|
3
|
+
# Helpers that assist with the rendering of a Form Column
|
4
|
+
module FormColumnHelpers
|
5
|
+
def active_scaffold_input_active_storage_has_one(column, options)
|
6
|
+
record = options[:object]
|
7
|
+
active_storage = record.send(column.name.to_s)
|
8
|
+
content = active_scaffold_column_active_storage_has_one(record, column) if active_storage.attached?
|
9
|
+
active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls')
|
10
|
+
end
|
11
|
+
|
12
|
+
def active_scaffold_input_active_storage_has_many(column, options)
|
13
|
+
record = options[:object]
|
14
|
+
options[:multiple] = 'multiple'
|
15
|
+
options[:name] += '[]'
|
16
|
+
active_storage = record.send(column.name.to_s)
|
17
|
+
content = active_scaffold_column_active_storage_has_many(record, column) if active_storage.attached?
|
18
|
+
active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
module Helpers
|
3
|
+
module ListColumnHelpers
|
4
|
+
def active_scaffold_column_active_storage_has_one(record, column)
|
5
|
+
attachment = record.send(column.name.to_s)
|
6
|
+
attachment.attached? ? link_for_attachment(attachment) : nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def active_scaffold_column_active_storage_has_many(record, column)
|
10
|
+
active_storage_files = record.send(column.name.to_s)
|
11
|
+
return nil unless active_storage_files.attached?
|
12
|
+
|
13
|
+
attachments = active_storage_files.attachments
|
14
|
+
if attachments.size <= 3 # Lets display up to three links, otherwise just show the count.
|
15
|
+
links = attachments.map { |attachment| link_for_attachment(attachment) }
|
16
|
+
safe_join links, association_join_text(column)
|
17
|
+
else
|
18
|
+
pluralize attachments.size, column.name.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def link_for_attachment(attachment)
|
25
|
+
variant = column.options[:thumb] || ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridgeHelpers.thumbnail_variant
|
26
|
+
content =
|
27
|
+
if variant && attachment.variable?
|
28
|
+
image_tag(attachment.variant(variant))
|
29
|
+
else
|
30
|
+
attachment.filename
|
31
|
+
end
|
32
|
+
link_to(content, rails_blob_url(attachment, disposition: 'attachment'), target: '_blank', rel: 'noopener noreferrer')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -2,5 +2,6 @@ class ActiveScaffold::Bridges::Bitfields < ActiveScaffold::DataStructures::Bridg
|
|
2
2
|
def self.install
|
3
3
|
require File.join(File.dirname(__FILE__), 'bitfields/bitfields_bridge')
|
4
4
|
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::Bitfields::BitfieldsBridge
|
5
|
+
ActiveScaffold::Config::Core.after_config_callbacks << :_setup_bitfields
|
5
6
|
end
|
6
7
|
end
|
@@ -6,7 +6,7 @@ module ActiveScaffold
|
|
6
6
|
super
|
7
7
|
return unless model.respond_to?(:bitfields) && model.bitfields.present?
|
8
8
|
|
9
|
-
model.bitfields.
|
9
|
+
model.bitfields.each_value do |options|
|
10
10
|
columns << options.keys
|
11
11
|
options.each do |column, value|
|
12
12
|
columns[column].form_ui = :checkbox
|
@@ -15,23 +15,20 @@ module ActiveScaffold
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
18
|
+
def _setup_bitfields
|
19
|
+
return unless model.respond_to?(:bitfields) && model.bitfields.present?
|
20
|
+
model.bitfields.each do |column_name, options|
|
21
|
+
columns = options.keys.sort_by { |column| self.columns[column].weight }
|
22
|
+
%i[create update show subform].each do |action|
|
23
|
+
next unless actions.include? action
|
24
|
+
if send(action).columns.include? column_name
|
25
|
+
send(action).columns.exclude column_name
|
26
|
+
send(action).columns.add_subgroup(column_name) { |group| group.add(*columns) }
|
27
|
+
else
|
28
|
+
send(action).columns.exclude(*columns)
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
33
|
-
|
34
|
-
super
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
@@ -36,7 +36,7 @@ module ActiveScaffold
|
|
36
36
|
:class => 'text-input',
|
37
37
|
:id => "#{options[:id]}_#{name}",
|
38
38
|
:time => column_datetime?(column) ? true : false,
|
39
|
-
:style => (
|
39
|
+
:style => ('display: none' if options[:show] == false) # hide only if asked to hide
|
40
40
|
)
|
41
41
|
end
|
42
42
|
end
|
@@ -45,6 +45,12 @@ module ActiveScaffold::Bridges
|
|
45
45
|
def beginning_of_chain
|
46
46
|
super.accessible_by(current_ability)
|
47
47
|
end
|
48
|
+
|
49
|
+
# fix when ability allow access base on id
|
50
|
+
# can [:manage], Client, id: Client.of_employee(user).pluck(:id)
|
51
|
+
def new_model
|
52
|
+
super.tap { |record| record.id = nil }
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
@@ -60,7 +66,7 @@ module ActiveScaffold::Bridges
|
|
60
66
|
# because the object may change (someone may log in or out). So we give ActiveRecord a proc that ties to the
|
61
67
|
# current_ability_method on this ApplicationController.
|
62
68
|
def assign_current_ability_to_models
|
63
|
-
::
|
69
|
+
::ActiveScaffold::Registry.current_ability_proc = proc { send(:current_ability) }
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
@@ -68,18 +74,9 @@ module ActiveScaffold::Bridges
|
|
68
74
|
extend ActiveSupport::Concern
|
69
75
|
|
70
76
|
module ClassMethods
|
71
|
-
# The proc to call that retrieves the current_ability from the ApplicationController.
|
72
|
-
def current_ability_proc
|
73
|
-
Thread.current[:current_ability_proc]
|
74
|
-
end
|
75
|
-
|
76
|
-
def current_ability_proc=(value)
|
77
|
-
Thread.current[:current_ability_proc] = value
|
78
|
-
end
|
79
|
-
|
80
77
|
# Class-level access to the current ability
|
81
78
|
def current_ability
|
82
|
-
::
|
79
|
+
::ActiveScaffold::Registry.current_ability_proc&.call
|
83
80
|
end
|
84
81
|
end
|
85
82
|
|
@@ -114,7 +111,7 @@ module ActiveScaffold::Bridges
|
|
114
111
|
crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self)
|
115
112
|
action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self)
|
116
113
|
else
|
117
|
-
crud_type_result
|
114
|
+
crud_type_result = action_result = false
|
118
115
|
end
|
119
116
|
result = (crud_type_result && action_result) || super(options.merge(:reason => nil))
|
120
117
|
# return array with nil reason if requested with options[:reason], we don't have reason but caller expects array
|
@@ -7,11 +7,11 @@ module ActiveScaffold
|
|
7
7
|
thumbnail_style = ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridgeHelpers.thumbnail_style
|
8
8
|
content =
|
9
9
|
if carrierwave.versions.keys.include?(thumbnail_style)
|
10
|
-
image_tag(carrierwave.url(thumbnail_style), :border => 0)
|
10
|
+
image_tag(carrierwave.url(thumbnail_style), :border => 0)
|
11
11
|
else
|
12
12
|
record.send(record.send(:_mounter, column.name).send(:serialization_column))
|
13
13
|
end
|
14
|
-
link_to(content, carrierwave.url, :target => '_blank')
|
14
|
+
link_to(content, carrierwave.url, :target => '_blank', rel: 'noopener noreferrer')
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -1,21 +1,23 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
1
3
|
class ActiveScaffold::Bridges::Chosen
|
2
4
|
module Helpers
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
include FormColumnHelpers
|
8
|
+
include SearchColumnHelpers
|
8
9
|
end
|
9
10
|
|
10
11
|
module FormColumnHelpers
|
11
12
|
# requires RecordSelect plugin to be installed and configured.
|
12
13
|
def active_scaffold_input_chosen(column, html_options)
|
13
14
|
html_options[:class] << ' chosen'
|
14
|
-
if column.association
|
15
|
-
|
16
|
-
|
15
|
+
if column.association&.collection?
|
16
|
+
record = html_options.delete(:object)
|
17
|
+
associated_options, select_options = active_scaffold_plural_association_options(column, record)
|
18
|
+
options = {selected: associated_options.collect(&:id), include_blank: as_(:_select_), object: record}
|
17
19
|
|
18
|
-
html_options.update(:
|
20
|
+
html_options.update(multiple: true).update(column.options[:html_options] || {})
|
19
21
|
options.update(column.options)
|
20
22
|
active_scaffold_select_name_with_multiple html_options
|
21
23
|
|
@@ -42,19 +42,6 @@ class ActiveScaffold::Bridges::DatePicker
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
46
|
-
module CastExtension
|
47
|
-
def fallback_string_to_date(string)
|
48
|
-
Date.strptime(string, I18n.t('date.formats.default')) rescue super
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
if defined?(ActiveRecord::ConnectionAdapters::Type) # rails >= 4.2
|
53
|
-
ActiveRecord::ConnectionAdapters::Type::Date.send(:prepend, ActiveScaffold::Bridges::DatePicker::CastExtension)
|
54
|
-
else
|
55
|
-
class << ActiveRecord::ConnectionAdapters::Column
|
56
|
-
prepend ActiveScaffold::Bridges::DatePicker::CastExtension
|
57
|
-
end
|
58
45
|
end
|
59
46
|
|
60
47
|
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::DatePicker::DatePickerBridge
|
@@ -24,9 +24,7 @@ module ActiveScaffold::Bridges
|
|
24
24
|
def self.date_options_for_locales
|
25
25
|
I18n.available_locales.collect do |locale|
|
26
26
|
locale_date_options = date_options(locale)
|
27
|
-
if locale_date_options
|
28
|
-
"$.datepicker.regional['#{locale}'] = #{locale_date_options.to_json};"
|
29
|
-
end
|
27
|
+
"$.datepicker.regional['#{locale}'] = #{locale_date_options.to_json};" if locale_date_options
|
30
28
|
end.compact.join('')
|
31
29
|
end
|
32
30
|
|
@@ -52,16 +50,14 @@ module ActiveScaffold::Bridges
|
|
52
50
|
js_format = to_datepicker_format(I18n.translate!('date.formats.default', :locale => locale, :default => ''))
|
53
51
|
date_picker_options[:dateFormat] = js_format if js_format.present?
|
54
52
|
date_picker_options
|
55
|
-
rescue
|
53
|
+
rescue StandardError
|
56
54
|
raise if locale == I18n.locale
|
57
55
|
end
|
58
56
|
|
59
57
|
def self.datetime_options_for_locales
|
60
58
|
I18n.available_locales.collect do |locale|
|
61
59
|
locale_datetime_options = datetime_options(locale)
|
62
|
-
if locale_datetime_options
|
63
|
-
"$.timepicker.regional['#{locale}'] = #{locale_datetime_options.to_json};"
|
64
|
-
end
|
60
|
+
"$.timepicker.regional['#{locale}'] = #{locale_datetime_options.to_json};" if locale_datetime_options
|
65
61
|
end.compact.join('')
|
66
62
|
end
|
67
63
|
|
@@ -78,21 +74,20 @@ module ActiveScaffold::Bridges
|
|
78
74
|
datetime_picker_options.merge!(as_datetime_picker_options) if as_datetime_picker_options.is_a? Hash
|
79
75
|
Rails.logger.warn "ActiveScaffold: Missing datetime picker localization for your locale: #{locale}" if as_datetime_picker_options.blank?
|
80
76
|
|
81
|
-
|
82
|
-
datetime_picker_options[:dateFormat] = date_format unless date_format.nil?
|
83
|
-
unless time_format.nil?
|
84
|
-
datetime_picker_options[:timeFormat] = time_format
|
85
|
-
datetime_picker_options[:ampm] = true if rails_time_format.include?('%I')
|
86
|
-
end
|
77
|
+
datetime_picker_options.merge! format_to_datetime_picker(rails_time_format)
|
87
78
|
datetime_picker_options
|
88
|
-
rescue
|
79
|
+
rescue StandardError
|
89
80
|
raise if locale == I18n.locale
|
90
81
|
end
|
91
82
|
|
92
83
|
def self.to_datepicker_format(rails_format)
|
93
84
|
return nil if rails_format.nil?
|
94
85
|
if rails_format =~ /%[cUWwxXZz]/
|
95
|
-
Rails.logger.warn(
|
86
|
+
Rails.logger.warn(
|
87
|
+
"AS DatePicker::Helper: rails date format #{rails_format} includes options "\
|
88
|
+
"which can't be converted to jquery datepicker format. "\
|
89
|
+
'Options %c, %U, %W, %w, %x %X, %z, %Z are not supported by datepicker and will be removed'
|
90
|
+
)
|
96
91
|
nil
|
97
92
|
end
|
98
93
|
js_format = rails_format.dup
|
@@ -103,6 +98,17 @@ module ActiveScaffold::Bridges
|
|
103
98
|
js_format
|
104
99
|
end
|
105
100
|
|
101
|
+
def self.format_to_datetime_picker(rails_time_format)
|
102
|
+
date_format, time_format = split_datetime_format(to_datepicker_format(rails_time_format))
|
103
|
+
datetime_picker_options = {}
|
104
|
+
datetime_picker_options[:dateFormat] = date_format unless date_format.nil?
|
105
|
+
unless time_format.nil?
|
106
|
+
datetime_picker_options[:timeFormat] = time_format
|
107
|
+
datetime_picker_options[:ampm] = true if rails_time_format.include?('%I')
|
108
|
+
end
|
109
|
+
datetime_picker_options
|
110
|
+
end
|
111
|
+
|
106
112
|
def self.split_datetime_format(datetime_format)
|
107
113
|
date_format = datetime_format
|
108
114
|
time_format = nil
|
@@ -119,46 +125,44 @@ module ActiveScaffold::Bridges
|
|
119
125
|
end
|
120
126
|
|
121
127
|
module DatepickerColumnHelpers
|
122
|
-
def datepicker_split_datetime_format(datetime_format)
|
123
|
-
ActiveScaffold::Bridges::DatePicker::Helper.split_datetime_format(datetime_format)
|
124
|
-
end
|
125
|
-
|
126
128
|
def to_datepicker_format(rails_format)
|
127
129
|
ActiveScaffold::Bridges::DatePicker::Helper.to_datepicker_format(rails_format)
|
128
130
|
end
|
129
131
|
|
130
|
-
def datepicker_format_options(column, format
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
options['data-dateFormat'] = date_format unless date_format.nil?
|
139
|
-
unless time_format.nil?
|
140
|
-
options['data-timeFormat'] = time_format
|
141
|
-
options['data-ampm'] = true if rails_time_format.include?('%I')
|
142
|
-
end
|
143
|
-
end
|
132
|
+
def datepicker_format_options(column, format)
|
133
|
+
return {} if format == :default
|
134
|
+
if column.form_ui == :date_picker
|
135
|
+
js_format = to_datepicker_format(I18n.translate!("date.formats.#{format}"))
|
136
|
+
js_format.nil? ? {} : {dateFormat: js_format}
|
137
|
+
else
|
138
|
+
rails_time_format = I18n.translate!("time.formats.#{format}")
|
139
|
+
ActiveScaffold::Bridges::DatePicker::Helper.format_to_datetime_picker(rails_time_format)
|
144
140
|
end
|
145
141
|
end
|
142
|
+
|
143
|
+
def datepicker_format(options, ui)
|
144
|
+
options.delete(:format) || (ui == :date_picker ? :default : :picker)
|
145
|
+
end
|
146
146
|
end
|
147
147
|
|
148
148
|
module SearchColumnHelpers
|
149
149
|
def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name)
|
150
|
-
value =
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
value =
|
151
|
+
if current_search.is_a? Hash
|
152
|
+
controller.class.condition_value_for_datetime(column, current_search[name], column.search_ui == :date_picker ? :to_date : :to_time)
|
153
|
+
else
|
154
|
+
current_search
|
155
|
+
end
|
155
156
|
options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value)
|
156
157
|
options = active_scaffold_input_text_options(options.merge(column.options))
|
158
|
+
format = datepicker_format(options, column.search_ui)
|
157
159
|
options[:class] << " #{column.search_ui}"
|
158
|
-
options[:style] =
|
159
|
-
|
160
|
-
datepicker_format_options(column, format
|
161
|
-
|
160
|
+
options[:style] = 'display: none' if options[:show] == false # hide only if asked to hide
|
161
|
+
options[:data] ||= {}
|
162
|
+
options[:data].merge! datepicker_format_options(column, format)
|
163
|
+
value = l(value, :format => format) if value
|
164
|
+
options = options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]", :object => nil)
|
165
|
+
text_field_tag("#{options[:name]}[#{name}]", value, options)
|
162
166
|
end
|
163
167
|
end
|
164
168
|
|
@@ -168,9 +172,10 @@ module ActiveScaffold::Bridges
|
|
168
172
|
options = active_scaffold_input_text_options(options.merge(column.options))
|
169
173
|
options[:class] << " #{column.form_ui}"
|
170
174
|
|
175
|
+
format = datepicker_format(options, column.form_ui)
|
171
176
|
value = controller.class.condition_value_for_datetime(column, record.send(column.name), column.form_ui == :date_picker ? :to_date : :to_time)
|
172
|
-
|
173
|
-
datepicker_format_options(column, format
|
177
|
+
options[:data] ||= {}
|
178
|
+
options[:data].merge! datepicker_format_options(column, format)
|
174
179
|
options[:value] = (value ? l(value, :format => format) : nil)
|
175
180
|
text_field(:record, column.name, options)
|
176
181
|
end
|