active_scaffold 3.5.5 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/{CHANGELOG → CHANGELOG.rdoc} +75 -0
  3. data/README.md +21 -10
  4. data/app/assets/javascripts/active_scaffold.js.erb +0 -1
  5. data/app/assets/javascripts/jquery/active_scaffold.js +98 -7
  6. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  7. data/app/assets/stylesheets/active_scaffold_layout.css +52 -29
  8. data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -2
  9. data/app/views/active_scaffold_overrides/_form.html.erb +1 -1
  10. data/app/views/active_scaffold_overrides/_form_association.html.erb +2 -1
  11. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +3 -2
  12. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +26 -10
  13. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +4 -4
  14. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +2 -1
  15. data/app/views/active_scaffold_overrides/_list.html.erb +2 -1
  16. data/app/views/active_scaffold_overrides/_list_header.html.erb +5 -7
  17. data/app/views/active_scaffold_overrides/_list_messages.html.erb +1 -0
  18. data/app/views/active_scaffold_overrides/_list_record.html.erb +4 -5
  19. data/app/views/active_scaffold_overrides/_list_with_header.html.erb +1 -1
  20. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -0
  21. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +4 -0
  22. data/app/views/active_scaffold_overrides/_render_field.js.erb +2 -1
  23. data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -1
  24. data/app/views/active_scaffold_overrides/_show_columns.html.erb +2 -2
  25. data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +4 -4
  26. data/app/views/active_scaffold_overrides/_update_calculations.js.erb +1 -1
  27. data/app/views/active_scaffold_overrides/_update_column.js.erb +2 -2
  28. data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +2 -2
  29. data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
  30. data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
  31. data/app/views/active_scaffold_overrides/on_action_update.js.erb +16 -6
  32. data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
  33. data/app/views/active_scaffold_overrides/row.js.erb +1 -1
  34. data/app/views/active_scaffold_overrides/update_column.js.erb +2 -2
  35. data/config/locales/de.yml +2 -1
  36. data/config/locales/en.yml +1 -0
  37. data/config/locales/es.yml +1 -0
  38. data/config/locales/fr.yml +2 -1
  39. data/config/locales/hu.yml +1 -0
  40. data/config/locales/ja.yml +1 -0
  41. data/config/locales/ru.yml +1 -0
  42. data/lib/active_scaffold.rb +19 -16
  43. data/lib/active_scaffold/actions/common_search.rb +11 -8
  44. data/lib/active_scaffold/actions/core.rb +91 -70
  45. data/lib/active_scaffold/actions/create.rb +28 -28
  46. data/lib/active_scaffold/actions/delete.rb +3 -3
  47. data/lib/active_scaffold/actions/field_search.rb +53 -43
  48. data/lib/active_scaffold/actions/list.rb +111 -27
  49. data/lib/active_scaffold/actions/nested.rb +65 -48
  50. data/lib/active_scaffold/actions/search.rb +1 -1
  51. data/lib/active_scaffold/actions/show.rb +4 -4
  52. data/lib/active_scaffold/actions/subform.rb +23 -22
  53. data/lib/active_scaffold/actions/update.rb +96 -77
  54. data/lib/active_scaffold/active_record_permissions.rb +2 -11
  55. data/lib/active_scaffold/attribute_params.rb +102 -94
  56. data/lib/active_scaffold/bridges.rb +8 -8
  57. data/lib/active_scaffold/bridges/active_storage.rb +6 -0
  58. data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +34 -0
  59. data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +54 -0
  60. data/lib/active_scaffold/bridges/active_storage/form_ui.rb +22 -0
  61. data/lib/active_scaffold/bridges/active_storage/list_ui.rb +36 -0
  62. data/lib/active_scaffold/bridges/bitfields.rb +2 -1
  63. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -15
  64. data/lib/active_scaffold/bridges/bitfields/list_ui.rb +19 -0
  65. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
  66. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +3 -12
  67. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
  68. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +2 -2
  69. data/lib/active_scaffold/bridges/chosen/helpers.rb +7 -6
  70. data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
  71. data/lib/active_scaffold/bridges/date_picker/helper.rb +49 -44
  72. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +1 -1
  73. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
  74. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
  75. data/lib/active_scaffold/bridges/file_column/form_ui.rb +3 -3
  76. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +10 -7
  77. data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
  78. data/lib/active_scaffold/bridges/paper_trail/actions.rb +3 -1
  79. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  80. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
  81. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
  82. data/lib/active_scaffold/bridges/record_select/helpers.rb +15 -17
  83. data/lib/active_scaffold/bridges/shared/date_bridge.rb +20 -19
  84. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -1
  85. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +21 -4
  86. data/lib/active_scaffold/config/base.rb +133 -41
  87. data/lib/active_scaffold/config/core.rb +146 -18
  88. data/lib/active_scaffold/config/delete.rb +14 -1
  89. data/lib/active_scaffold/config/field_search.rb +7 -1
  90. data/lib/active_scaffold/config/form.rb +10 -1
  91. data/lib/active_scaffold/config/list.rb +39 -13
  92. data/lib/active_scaffold/config/mark.rb +4 -2
  93. data/lib/active_scaffold/config/nested.rb +16 -17
  94. data/lib/active_scaffold/config/search.rb +9 -0
  95. data/lib/active_scaffold/config/show.rb +4 -0
  96. data/lib/active_scaffold/config/update.rb +4 -0
  97. data/lib/active_scaffold/configurable.rb +14 -7
  98. data/lib/active_scaffold/constraints.rb +22 -20
  99. data/lib/active_scaffold/core.rb +67 -28
  100. data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
  101. data/lib/active_scaffold/data_structures/action_link.rb +50 -20
  102. data/lib/active_scaffold/data_structures/action_links.rb +15 -13
  103. data/lib/active_scaffold/data_structures/association/abstract.rb +38 -15
  104. data/lib/active_scaffold/data_structures/association/active_mongoid.rb +2 -6
  105. data/lib/active_scaffold/data_structures/association/active_record.rb +6 -2
  106. data/lib/active_scaffold/data_structures/association/mongoid.rb +0 -3
  107. data/lib/active_scaffold/data_structures/column.rb +75 -66
  108. data/lib/active_scaffold/data_structures/columns.rb +3 -2
  109. data/lib/active_scaffold/data_structures/nested_info.rb +33 -19
  110. data/lib/active_scaffold/data_structures/set.rb +8 -0
  111. data/lib/active_scaffold/data_structures/sorting.rb +10 -2
  112. data/lib/active_scaffold/delayed_setup.rb +16 -5
  113. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -2
  114. data/lib/active_scaffold/extensions/action_view_rendering.rb +93 -32
  115. data/lib/active_scaffold/extensions/cow_proxy.rb +95 -0
  116. data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
  117. data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
  118. data/lib/active_scaffold/extensions/localize.rb +3 -1
  119. data/lib/active_scaffold/extensions/routing_mapper.rb +6 -45
  120. data/lib/active_scaffold/extensions/to_label.rb +3 -2
  121. data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
  122. data/lib/active_scaffold/finder.rb +110 -77
  123. data/lib/active_scaffold/helpers/action_link_helpers.rb +62 -36
  124. data/lib/active_scaffold/helpers/association_helpers.rb +18 -16
  125. data/lib/active_scaffold/helpers/controller_helpers.rb +34 -10
  126. data/lib/active_scaffold/helpers/form_column_helpers.rb +196 -124
  127. data/lib/active_scaffold/helpers/human_condition_helpers.rb +1 -1
  128. data/lib/active_scaffold/helpers/id_helpers.rb +6 -2
  129. data/lib/active_scaffold/helpers/list_column_helpers.rb +90 -57
  130. data/lib/active_scaffold/helpers/pagination_helpers.rb +2 -2
  131. data/lib/active_scaffold/helpers/search_column_helpers.rb +43 -41
  132. data/lib/active_scaffold/helpers/show_column_helpers.rb +3 -5
  133. data/lib/active_scaffold/helpers/view_helpers.rb +39 -36
  134. data/lib/active_scaffold/marked_model.rb +2 -2
  135. data/lib/active_scaffold/orm_checks.rb +3 -7
  136. data/lib/active_scaffold/paginator.rb +7 -7
  137. data/lib/active_scaffold/registry.rb +33 -0
  138. data/lib/active_scaffold/responds_to_parent.rb +8 -11
  139. data/lib/active_scaffold/tableless.rb +83 -67
  140. data/lib/active_scaffold/version.rb +2 -2
  141. data/lib/generators/active_scaffold/controller_generator.rb +2 -2
  142. data/lib/generators/active_scaffold/install_generator.rb +52 -4
  143. data/lib/generators/active_scaffold/resource_generator.rb +2 -2
  144. data/shoulda_macros/macros.rb +3 -1
  145. data/test/bridges/date_picker_test.rb +1 -2
  146. data/test/bridges/paperclip_test.rb +6 -6
  147. data/test/class_with_finder.rb +2 -2
  148. data/test/company.rb +4 -4
  149. data/test/config/create_test.rb +4 -2
  150. data/test/config/nested_test.rb +1 -1
  151. data/test/config/show_test.rb +1 -1
  152. data/test/config/update_test.rb +7 -6
  153. data/test/data_structures/action_columns_test.rb +2 -2
  154. data/test/data_structures/action_links_test.rb +1 -1
  155. data/test/data_structures/column_test.rb +3 -6
  156. data/test/data_structures/columns_test.rb +2 -2
  157. data/test/data_structures/sorting_test.rb +7 -0
  158. data/test/extensions/action_view_rendering_test.rb +20 -0
  159. data/test/extensions/active_record_test.rb +4 -4
  160. data/test/extensions/routing_mapper_test.rb +2 -2
  161. data/test/helpers/list_column_helpers_test.rb +3 -1
  162. data/test/misc/active_record_permissions_test.rb +3 -11
  163. data/test/misc/attribute_params_test.rb +12 -8
  164. data/test/misc/calculation_test.rb +1 -1
  165. data/test/misc/configurable_test.rb +10 -10
  166. data/test/misc/constraints_test.rb +3 -3
  167. data/test/misc/convert_numbers_format_test.rb +7 -3
  168. data/test/misc/lang_test.rb +1 -1
  169. data/test/misc/parse_datetime_test.rb +3 -4
  170. data/test/misc/tableless_test.rb +14 -0
  171. data/test/mock_app/Rakefile +1 -1
  172. data/test/mock_app/app/assets/config/manifest.js +0 -0
  173. data/test/mock_app/app/controllers/cars_controller.rb +1 -0
  174. data/test/mock_app/app/controllers/people_controller.rb +5 -1
  175. data/test/mock_app/app/controllers/roles_controller.rb +4 -0
  176. data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +2 -0
  177. data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +2 -0
  178. data/test/mock_app/app/views/people/_first_name_form_column.html.erb +2 -0
  179. data/test/mock_app/app/views/people/_form.html.erb +2 -0
  180. data/test/mock_app/app/views/people/list.html.erb +2 -0
  181. data/test/mock_app/config/application.rb +2 -1
  182. data/test/mock_app/config/boot.rb +1 -1
  183. data/test/mock_app/config/environment.rb +2 -2
  184. data/test/mock_app/config/routes.rb +4 -1
  185. data/test/mock_app/db/schema.rb +2 -0
  186. data/test/performance/list_cars_performance_test.rb +34 -0
  187. data/test/performance/list_people_performance_test.rb +31 -0
  188. data/test/performance_test_help.rb +3 -0
  189. data/test/test_helper.rb +12 -4
  190. metadata +71 -15
  191. data/app/assets/javascripts/prototype/rico_corner.js +0 -370
  192. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +0 -7
@@ -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, column) : 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, column) }
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, column)
25
+ variant = column.options[:thumb] || ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridgeHelpers.thumbnail_variant
26
+ content =
27
+ if variant && attachment.variable? && column.options[:thumb] != false
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
@@ -1,6 +1,7 @@
1
1
  class ActiveScaffold::Bridges::Bitfields < ActiveScaffold::DataStructures::Bridge
2
2
  def self.install
3
- require File.join(File.dirname(__FILE__), 'bitfields/bitfields_bridge')
3
+ Dir[File.join(__dir__, 'bitfields', '*.rb')].each { |file| require file }
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.each do |_, options|
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 _load_action_columns
19
- if 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
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
@@ -0,0 +1,19 @@
1
+ module ActiveScaffold
2
+ module Bridges
3
+ class Bitfields
4
+ module ListColumnHelpers
5
+ def format_column_value(record, column, value = nil)
6
+ if record.class.respond_to?(:bitfields) && record.class.bitfields&.include?(column.name)
7
+ value = record.bitfield_values(column.name).select { |_, v| v }.keys
8
+ safe_join active_scaffold_config.columns.select { |c| c.name.in? value }.map(&:label), ', '
9
+ else
10
+ super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ ActionView::Base.class_eval do
18
+ include ActiveScaffold::Bridges::Bitfields::ListColumnHelpers
19
+ 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 => (options[:show].nil? || options[:show]) ? nil : 'display: none'
39
+ :style => ('display: none' if options[:show] == false) # hide only if asked to hide
40
40
  )
41
41
  end
42
42
  end
@@ -66,7 +66,7 @@ module ActiveScaffold::Bridges
66
66
  # because the object may change (someone may log in or out). So we give ActiveRecord a proc that ties to the
67
67
  # current_ability_method on this ApplicationController.
68
68
  def assign_current_ability_to_models
69
- ::ActiveRecord::Base.current_ability_proc = proc { send(:current_ability) }
69
+ ::ActiveScaffold::Registry.current_ability_proc = proc { send(:current_ability) }
70
70
  end
71
71
  end
72
72
 
@@ -74,18 +74,9 @@ module ActiveScaffold::Bridges
74
74
  extend ActiveSupport::Concern
75
75
 
76
76
  module ClassMethods
77
- # The proc to call that retrieves the current_ability from the ApplicationController.
78
- def current_ability_proc
79
- Thread.current[:current_ability_proc]
80
- end
81
-
82
- def current_ability_proc=(value)
83
- Thread.current[:current_ability_proc] = value
84
- end
85
-
86
77
  # Class-level access to the current ability
87
78
  def current_ability
88
- ::ActiveRecord::Base.current_ability_proc.call if ::ActiveRecord::Base.current_ability_proc
79
+ ::ActiveScaffold::Registry.current_ability_proc&.call
89
80
  end
90
81
  end
91
82
 
@@ -120,7 +111,7 @@ module ActiveScaffold::Bridges
120
111
  crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self)
121
112
  action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self)
122
113
  else
123
- crud_type_result, action_result = false, false
114
+ crud_type_result = action_result = false
124
115
  end
125
116
  result = (crud_type_result && action_result) || super(options.merge(:reason => nil))
126
117
  # return array with nil reason if requested with options[:reason], we don't have reason but caller expects array
@@ -9,7 +9,7 @@ module ActiveScaffold
9
9
  update.multipart = true
10
10
  create.multipart = true
11
11
 
12
- model.uploaders.keys.each do |field|
12
+ model.uploaders.each_key do |field|
13
13
  configure_carrierwave_field(field.to_sym)
14
14
  end
15
15
  end
@@ -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).html_safe
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,17 +1,18 @@
1
+ require 'active_support/concern'
2
+
1
3
  class ActiveScaffold::Bridges::Chosen
2
4
  module Helpers
3
- def self.included(base)
4
- base.class_eval do
5
- include FormColumnHelpers
6
- include SearchColumnHelpers
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.try(:collection?)
15
+ if column.association&.collection?
15
16
  record = html_options.delete(:object)
16
17
  associated_options, select_options = active_scaffold_plural_association_options(column, record)
17
18
  options = {selected: associated_options.collect(&:id), include_blank: as_(:_select_), object: record}
@@ -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
- date_format, time_format = split_datetime_format(to_datepicker_format(rails_time_format))
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("AS DatePicker::Helper: rails date format #{rails_format} includes options which can't be converted to jquery datepicker format. Options %c, %U, %W, %w, %x %X, %z, %Z are not supported by datepicker and will be removed")
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, options)
131
- unless format == :default
132
- if column.form_ui == :date_picker
133
- js_format = to_datepicker_format(I18n.translate!("date.formats.#{format}"))
134
- options['data-dateFormat'] = js_format unless js_format.nil?
135
- else
136
- rails_time_format = I18n.translate!("time.formats.#{format}")
137
- date_format, time_format = datepicker_split_datetime_format(to_datepicker_format(rails_time_format))
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 = if current_search.is_a? Hash
151
- controller.class.condition_value_for_datetime(column, current_search[name], column.search_ui == :date_picker ? :to_date : :to_time)
152
- else
153
- current_search
154
- end
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] = (options[:show].nil? || options[:show]) ? nil : 'display: none'
159
- format = options.delete(:format) || (column.search_ui == :date_picker ? :default : :picker)
160
- datepicker_format_options(column, format, options)
161
- text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]", :object => nil))
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
- format = options.delete(:format) || (column.form_ui == :date_picker ? :default : :picker)
173
- datepicker_format_options(column, format, options)
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
@@ -10,7 +10,7 @@ module ActiveScaffold
10
10
  else
11
11
  attachment.name
12
12
  end
13
- link_to(content, dragonfly_url_for_attachment(attachment, record, column), :target => '_blank')
13
+ link_to(content, dragonfly_url_for_attachment(attachment, record, column), :target => '_blank', rel: 'noopener noreferrer')
14
14
  end
15
15
 
16
16
  def dragonfly_url_for_attachment(attachment, record, column)
@@ -33,7 +33,7 @@ class ActiveScaffold::Bridges::FileColumn
33
33
  # set null to false so active_scaffold wont set it to null
34
34
  # delete_file_column will take care of deleting a file or not.
35
35
  _columns_hash[field.to_s].instance_variable_set('@null', false)
36
- rescue
36
+ rescue StandardError
37
37
  false
38
38
  end
39
39
  end
@@ -9,7 +9,7 @@ module ActiveScaffold
9
9
 
10
10
  def generate_delete_helpers(klass)
11
11
  file_column_fields(klass).each do |field|
12
- klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.method_defined?(:"#{field}_with_delete=")
12
+ klass.send :class_eval, <<-CODE, __FILE__, __LINE__ + 1 unless klass.method_defined?(:"#{field}_with_delete=")
13
13
  attr_reader :delete_#{field}
14
14
 
15
15
  def delete_#{field}=(value)
@@ -19,7 +19,7 @@ module ActiveScaffold
19
19
  # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file!
20
20
  self.#{field} = nil unless self.#{field}_just_uploaded?
21
21
  end
22
- EOF
22
+ CODE
23
23
  end
24
24
  end
25
25
 
@@ -41,7 +41,7 @@ module ActiveScaffold
41
41
  versions = options[:magick][:versions]
42
42
  raise unless versions.stringify_keys[version]
43
43
  true
44
- rescue
44
+ rescue StandardError
45
45
  false
46
46
  end
47
47