avo 3.0.8 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of avo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/assets/builds/avo.base.css +699 -328
- data/app/assets/builds/avo.base.js +863 -7384
- data/app/assets/builds/avo.base.js.map +3 -3
- data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +106 -121
- data/app/components/avo/fields/belongs_to_field/edit_component.rb +18 -0
- data/lib/avo/version.rb +1 -1
- metadata +2 -2
@@ -1,137 +1,122 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
data-reload-belongs-to-field-polymorphic-value="<%= is_polymorphic? %>"
|
4
|
-
data-reload-belongs-to-field-searchable-value="<%= @field.is_searchable? %>"
|
5
|
-
data-reload-belongs-to-field-relation-name-value="<%= @field.id %>"
|
6
|
-
data-reload-belongs-to-field-target-name-value="<%= form.object_name %>[<%= @field.id_input_foreign_key %>]"
|
7
|
-
>
|
8
|
-
<% if is_polymorphic? %>
|
9
|
-
<%
|
10
|
-
# Set the model keys so we can pass them over
|
11
|
-
model_keys = @field.types.map do |type|
|
12
|
-
resource = Avo.resource_manager.get_resource_by_model_class(type.to_s)
|
13
|
-
[type.to_s, resource.model_key]
|
14
|
-
end.to_h
|
15
|
-
%>
|
16
|
-
<div class="divide-y"
|
1
|
+
<% if is_polymorphic? %>
|
2
|
+
<div class="divide-y"
|
17
3
|
data-controller="belongs-to-field"
|
18
4
|
data-searchable="<%= @field.is_searchable? %>"
|
19
5
|
data-association="<%= @field.id %>"
|
20
6
|
data-association-class="<%= @field&.target_resource&.model_class || nil %>"
|
21
7
|
>
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
8
|
+
<%= field_wrapper **field_wrapper_args, help: @field.polymorphic_help || '' do %>
|
9
|
+
<%= @form.select @field.type_input_foreign_key, @field.types.map { |type| [Avo.resource_manager.get_resource_by_model_class(type.to_s).name, type.to_s] },
|
10
|
+
{
|
11
|
+
value: @field.value,
|
12
|
+
include_blank: @field.placeholder,
|
13
|
+
},
|
14
|
+
{
|
15
|
+
class: classes("w-full"),
|
16
|
+
data: {
|
17
|
+
**@field.get_html(:data, view: view, element: :input),
|
18
|
+
action: "change->belongs-to-field#changeType #{field_html_action}",
|
19
|
+
'belongs-to-field-target': "select",
|
27
20
|
},
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}
|
37
|
-
%>
|
38
|
-
<%
|
39
|
-
# If the select field is disabled, no value will be sent. It's how HTML works.
|
40
|
-
# Thus the extra hidden field to actually send the related id to the server.
|
41
|
-
if disabled %>
|
42
|
-
<%= @form.hidden_field @field.type_input_foreign_key %>
|
43
|
-
<% end %>
|
21
|
+
disabled: disabled
|
22
|
+
}
|
23
|
+
%>
|
24
|
+
<%
|
25
|
+
# If the select field is disabled, no value will be sent. It's how HTML works.
|
26
|
+
# Thus the extra hidden field to actually send the related id to the server.
|
27
|
+
if disabled %>
|
28
|
+
<%= @form.hidden_field @field.type_input_foreign_key %>
|
44
29
|
<% end %>
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
30
|
+
<% end %>
|
31
|
+
<% @field.types.each do |type| %>
|
32
|
+
<div class="hidden"
|
33
|
+
data-belongs-to-field-target="type"
|
34
|
+
data-type="<%= type %>"
|
35
|
+
>
|
36
|
+
<%= field_wrapper **field_wrapper_args.merge!(data: reload_data), label: Avo.resource_manager.get_resource_by_model_class(type.to_s).name do %>
|
37
|
+
<% if @field.is_searchable? %>
|
38
|
+
<%= render Avo::Pro::SearchableAssociations::AutocompleteComponent.new form: @form,
|
39
|
+
disabled: disabled,
|
40
|
+
field: @field,
|
41
|
+
foreign_key: @field.id_input_foreign_key,
|
42
|
+
model_key: model_keys[type.to_s],
|
43
|
+
polymorphic_record: polymorphic_record,
|
44
|
+
resource: @resource,
|
45
|
+
style: @field.get_html(:style, view: view, element: :input),
|
46
|
+
type: type,
|
47
|
+
classes: classes("w-full"),
|
48
|
+
view: view
|
49
|
+
%>
|
50
|
+
<% else %>
|
51
|
+
<%= @form.select @field.id_input_foreign_key,
|
52
|
+
options_for_select(@field.values_for_type(type), @resource.present? && @resource.record.present? ? @resource.record[@field.id_input_foreign_key] : nil),
|
53
|
+
{
|
54
|
+
value: @resource.record[@field.id_input_foreign_key].to_s,
|
55
|
+
include_blank: @field.placeholder,
|
56
|
+
},
|
57
|
+
{
|
58
|
+
class: classes("w-full"),
|
59
|
+
data: @field.get_html(:data, view: view, element: :input),
|
60
|
+
disabled: disabled
|
61
|
+
}
|
62
|
+
%>
|
63
|
+
<%
|
64
|
+
# If the select field is disabled, no value will be sent. It's how HTML works.
|
65
|
+
# Thus the extra hidden field to actually send the related id to the server.
|
66
|
+
if disabled %>
|
67
|
+
<%= @form.hidden_field @field.id_input_foreign_key %>
|
83
68
|
<% end %>
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
69
|
+
<% end %>
|
70
|
+
<% if field.can_create? %>
|
71
|
+
<% create_href = create_path(Avo.resource_manager.get_resource_by_model_class(type.to_s)) %>
|
72
|
+
<% if !disabled && create_href.present? %>
|
73
|
+
<%= link_to t("avo.create_new_item", item: type.to_s.downcase),
|
74
|
+
create_href,
|
75
|
+
class: "text-sm"
|
76
|
+
%>
|
92
77
|
<% end %>
|
93
78
|
<% end %>
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
79
|
+
<% end %>
|
80
|
+
</div>
|
81
|
+
<% end %>
|
82
|
+
</div>
|
83
|
+
<% else %>
|
84
|
+
<%= field_wrapper **field_wrapper_args.merge!(data: reload_data) do %>
|
85
|
+
<% if @field.is_searchable? %>
|
86
|
+
<%= render Avo::Pro::SearchableAssociations::AutocompleteComponent.new form: @form,
|
87
|
+
field: @field,
|
88
|
+
model_key: @field.target_resource&.model_key,
|
89
|
+
foreign_key: @field.id_input_foreign_key,
|
90
|
+
resource: @resource,
|
91
|
+
disabled: disabled,
|
92
|
+
classes: classes("w-full"),
|
93
|
+
view: view,
|
94
|
+
style: @field.get_html(:style, view: view, element: :input)
|
95
|
+
%>
|
96
|
+
<% else %>
|
97
|
+
<%= @form.select @field.id_input_foreign_key, @field.options,
|
98
|
+
{
|
99
|
+
include_blank: @field.placeholder,
|
100
|
+
value: @field.value
|
101
|
+
},
|
102
|
+
{
|
103
|
+
class: classes("w-full"),
|
104
|
+
data: @field.get_html(:data, view: view, element: :input),
|
105
105
|
disabled: disabled,
|
106
|
-
classes: classes("w-full"),
|
107
|
-
view: view,
|
108
106
|
style: @field.get_html(:style, view: view, element: :input)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
{
|
117
|
-
class: classes("w-full"),
|
118
|
-
data: @field.get_html(:data, view: view, element: :input),
|
119
|
-
disabled: disabled,
|
120
|
-
style: @field.get_html(:style, view: view, element: :input)
|
121
|
-
}
|
122
|
-
%>
|
123
|
-
<%
|
124
|
-
# If the select field is disabled, no value will be sent. It's how HTML works.
|
125
|
-
# Thus the extra hidden field to actually send the related id to the server.
|
126
|
-
if disabled %>
|
127
|
-
<%= @form.hidden_field @field.id_input_foreign_key %>
|
128
|
-
<% end %>
|
107
|
+
}
|
108
|
+
%>
|
109
|
+
<%
|
110
|
+
# If the select field is disabled, no value will be sent. It's how HTML works.
|
111
|
+
# Thus the extra hidden field to actually send the related id to the server.
|
112
|
+
if disabled %>
|
113
|
+
<%= @form.hidden_field @field.id_input_foreign_key %>
|
129
114
|
<% end %>
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
115
|
+
<% end %>
|
116
|
+
<% if field.can_create? %>
|
117
|
+
<% if !disabled && create_path.present? %>
|
118
|
+
<%= link_to t("avo.create_new_item", item: @field.name.downcase), create_path, class: "text-sm" %>
|
134
119
|
<% end %>
|
135
120
|
<% end %>
|
136
121
|
<% end %>
|
137
|
-
|
122
|
+
<% end %>
|
@@ -73,4 +73,22 @@ class Avo::Fields::BelongsToField::EditComponent < Avo::Fields::EditComponent
|
|
73
73
|
def visit_through_association?
|
74
74
|
@field.target_resource.to_s == params[:via_resource_class].to_s
|
75
75
|
end
|
76
|
+
|
77
|
+
def model_keys
|
78
|
+
@field.types.map do |type|
|
79
|
+
resource = Avo.resource_manager.get_resource_by_model_class(type.to_s)
|
80
|
+
[type.to_s, resource.model_key]
|
81
|
+
end.to_h
|
82
|
+
end
|
83
|
+
|
84
|
+
def reload_data
|
85
|
+
{
|
86
|
+
controller: "reload-belongs-to-field",
|
87
|
+
action: 'turbo:before-stream-render@document->reload-belongs-to-field#beforeStreamRender',
|
88
|
+
reload_belongs_to_field_polymorphic_value: is_polymorphic?,
|
89
|
+
reload_belongs_to_field_searchable_value: @field.is_searchable?,
|
90
|
+
reload_belongs_to_field_relation_name_value: @field.id,
|
91
|
+
reload_belongs_to_field_target_name_value: "#{form.object_name}[#{@field.id_input_foreign_key}]"
|
92
|
+
}
|
93
|
+
end
|
76
94
|
end
|
data/lib/avo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-12-
|
12
|
+
date: 2023-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|