activeadmin_addons 1.8.3 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/inputs/date_time_picker_input.rb +2 -3
- data/app/inputs/nested_select_input.rb +13 -3
- data/lib/activeadmin_addons/addons/tag_builder.rb +1 -1
- data/lib/activeadmin_addons/support/input_helpers/input_html_helpers.rb +1 -0
- data/lib/activeadmin_addons/support/input_helpers/input_methods.rb +7 -0
- data/lib/activeadmin_addons/support/input_helpers/input_options_handler.rb +5 -1
- data/lib/activeadmin_addons/support/input_helpers/select_helpers.rb +11 -3
- data/lib/activeadmin_addons/support/set_datepicker.rb +11 -1
- data/lib/activeadmin_addons/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31434452186d9b02e7d7272b27d06d1e4831b1c4c6de9c068e973cf5311da476
|
4
|
+
data.tar.gz: 0a43f7f1d45b50c01eeb4b4f7a56f5ff9bcb4329a24adb4f77fc1d1ca28fa0e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10db20adc03c85569ab16debe8edffd16115b348baf7779e79544fa42a265058cc60d3d24ac77dea5e85591297a6daeb2ede226141cb7dbb4e34d0776966462a
|
7
|
+
data.tar.gz: b911e25eeb0801b2bbe7857c012f4c93fa71a2bf77d574d552461e39cdedfcdd698673ed625a4034c749852f2d1b47e1387a7b7c0a4f754cdb3311c753beab6a
|
@@ -43,9 +43,8 @@ class DateTimePickerInput < ActiveAdminAddons::InputBase
|
|
43
43
|
|
44
44
|
def datetime_picker_options
|
45
45
|
@datetime_picker_options ||= begin
|
46
|
-
opts = options.fetch(:picker_options, {})
|
47
|
-
|
48
|
-
default_picker_options.merge(opts)
|
46
|
+
opts = default_picker_options.merge(options.fetch(:picker_options, {}))
|
47
|
+
Hash[opts.map { |k, v| [k.to_s.camelcase(:lower), v] }]
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
@@ -15,6 +15,7 @@ class NestedSelectInput < ActiveAdminAddons::InputBase
|
|
15
15
|
def hierarchy
|
16
16
|
data = get_levels_data
|
17
17
|
raise("Undefined levels on nested_select") if data.empty?
|
18
|
+
|
18
19
|
set_parent_attributes(data)
|
19
20
|
data.reverse
|
20
21
|
end
|
@@ -67,17 +68,26 @@ class NestedSelectInput < ActiveAdminAddons::InputBase
|
|
67
68
|
parent_attribute = level_data[:parent_attribute]
|
68
69
|
build_virtual_attr(parent_attribute)
|
69
70
|
instance = instance_from_attribute_name(level_data[:attribute])
|
70
|
-
if instance
|
71
|
+
if instance&.respond_to?(parent_attribute)
|
71
72
|
@object.send("#{parent_attribute}=", instance.send(parent_attribute))
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
76
|
def instance_from_attribute_name(attribute)
|
76
77
|
return unless attribute
|
78
|
+
|
77
79
|
attribute_value = @object.send(attribute)
|
78
80
|
return unless attribute_value
|
79
|
-
|
80
|
-
klass
|
81
|
+
|
82
|
+
klass = class_from_attribute(attribute)
|
83
|
+
klass.find_by(id: attribute_value)
|
84
|
+
end
|
85
|
+
|
86
|
+
def class_from_attribute(attribute)
|
87
|
+
association_name = attribute.to_s.chomp("_id")
|
88
|
+
association_name.camelize.constantize
|
89
|
+
rescue NameError
|
90
|
+
object_class.reflect_on_association(association_name).klass
|
81
91
|
end
|
82
92
|
|
83
93
|
def build_virtual_attr(attribute_name)
|
@@ -6,11 +6,13 @@ module ActiveAdminAddons
|
|
6
6
|
|
7
7
|
def valid_method
|
8
8
|
raise "invalid method given" if method.blank?
|
9
|
+
|
9
10
|
method
|
10
11
|
end
|
11
12
|
|
12
13
|
def valid_object
|
13
14
|
raise "blank object given" if @object.blank?
|
15
|
+
|
14
16
|
@object
|
15
17
|
end
|
16
18
|
|
@@ -42,6 +44,10 @@ module ActiveAdminAddons
|
|
42
44
|
@input_value ||= valid_object.send(valid_method)
|
43
45
|
end
|
44
46
|
|
47
|
+
def input_association_value
|
48
|
+
@input_association_value ||= valid_object.send(association_name)
|
49
|
+
end
|
50
|
+
|
45
51
|
def translated_method
|
46
52
|
valid_object.class.human_attribute_name(valid_method)
|
47
53
|
end
|
@@ -60,6 +66,7 @@ module ActiveAdminAddons
|
|
60
66
|
def build_virtual_attr
|
61
67
|
attribute_name = "virtual_#{valid_method}_attr"
|
62
68
|
fail "#{attribute_name} is already defined" if valid_object.respond_to?(attribute_name)
|
69
|
+
|
63
70
|
valid_object.singleton_class.send(:attr_accessor, attribute_name)
|
64
71
|
attribute_name
|
65
72
|
end
|
@@ -41,6 +41,7 @@ module ActiveAdminAddons
|
|
41
41
|
def load_class(class_attr)
|
42
42
|
@css_classes ||= []
|
43
43
|
return if class_attr.blank?
|
44
|
+
|
44
45
|
class_attr = class_attr.strip
|
45
46
|
@css_classes << class_attr
|
46
47
|
class_attr
|
@@ -49,6 +50,7 @@ module ActiveAdminAddons
|
|
49
50
|
def get_data_attr_value(attr_name)
|
50
51
|
item = data_attr_options[attr_name.to_sym]
|
51
52
|
return unless item
|
53
|
+
|
52
54
|
item[:value]
|
53
55
|
end
|
54
56
|
|
@@ -56,13 +58,14 @@ module ActiveAdminAddons
|
|
56
58
|
|
57
59
|
def formatted_option_value(item)
|
58
60
|
return item[:value].send(item[:formatter]) if item[:formatter]
|
61
|
+
|
59
62
|
item[:value]
|
60
63
|
end
|
61
64
|
|
62
65
|
def load_option_attr(attr_name, options)
|
63
66
|
value = calculate_attr_value(attr_name, options)
|
64
67
|
item = { value: value }
|
65
|
-
item[:formatter] = options[:formatter]
|
68
|
+
item[:formatter] = options[:formatter] if options[:formatter].present?
|
66
69
|
item
|
67
70
|
end
|
68
71
|
|
@@ -80,6 +83,7 @@ module ActiveAdminAddons
|
|
80
83
|
default_value = attr_options[:default]
|
81
84
|
return unless default_value
|
82
85
|
return default_value.call if default_value.is_a?(Proc)
|
86
|
+
|
83
87
|
default_value
|
84
88
|
end
|
85
89
|
|
@@ -42,6 +42,7 @@ module ActiveAdminAddons
|
|
42
42
|
|
43
43
|
def item_to_select_option(item)
|
44
44
|
return unless item
|
45
|
+
|
45
46
|
{
|
46
47
|
id: item.send((valid_options[:value] || :id)),
|
47
48
|
text: item.send((valid_options[:display_name] || :name))
|
@@ -66,19 +67,26 @@ module ActiveAdminAddons
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def selected_item
|
69
|
-
@selected_item ||=
|
70
|
+
@selected_item ||= begin
|
71
|
+
input_association_value
|
72
|
+
rescue NoMethodError
|
73
|
+
selected_collection.first
|
74
|
+
end
|
70
75
|
end
|
71
76
|
|
72
77
|
private
|
73
78
|
|
74
79
|
def active_record_relation?(value)
|
75
80
|
klass = value.class.name
|
76
|
-
|
77
|
-
|
81
|
+
[
|
82
|
+
"ActiveRecord::Relation",
|
83
|
+
"ActiveRecord::Associations::CollectionProxy"
|
84
|
+
].include?(klass)
|
78
85
|
end
|
79
86
|
|
80
87
|
def valid_options
|
81
88
|
raise "missing @options hash" unless !!@options
|
89
|
+
|
82
90
|
@options
|
83
91
|
end
|
84
92
|
|
@@ -5,9 +5,19 @@ module ::Formtastic
|
|
5
5
|
|
6
6
|
def default_input_type(method, options = {})
|
7
7
|
input_type = original_default_input_type(method, options)
|
8
|
-
|
8
|
+
|
9
|
+
if input_type == :date_select && active_admin_context?
|
10
|
+
input_type = :datepicker
|
11
|
+
end
|
12
|
+
|
9
13
|
input_type
|
10
14
|
end
|
15
|
+
|
16
|
+
def active_admin_context?
|
17
|
+
options[:builder] == ::ActiveAdmin::FormBuilder
|
18
|
+
rescue NameError
|
19
|
+
false
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_addons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Platanus
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-11-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: active_material
|