avo 2.15.3 → 2.16.1.pre.1.nativefields
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 +0 -2
- data/Gemfile.lock +78 -86
- data/app/components/avo/base_component.rb +7 -1
- data/app/components/avo/field_wrapper_component.html.erb +40 -0
- data/app/components/avo/field_wrapper_component.rb +102 -0
- data/app/components/avo/fields/badge_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +3 -3
- data/app/components/avo/fields/belongs_to_field/index_component.html.erb +2 -1
- data/app/components/avo/fields/belongs_to_field/show_component.html.erb +2 -2
- data/app/components/avo/fields/belongs_to_field/show_component.rb +8 -0
- data/app/components/avo/fields/boolean_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/boolean_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/boolean_group_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/code_field/edit_component.html.erb +2 -2
- data/app/components/avo/fields/code_field/show_component.html.erb +2 -2
- data/app/components/avo/fields/country_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/country_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/date_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/date_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/date_time_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/date_time_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/edit_component.rb +22 -4
- data/app/components/avo/fields/external_image_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/external_image_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/external_image_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/file_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/file_field/index_component.html.erb +2 -2
- data/app/components/avo/fields/file_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/files_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/files_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/gravatar_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/has_one_field/show_component.html.erb +14 -1
- data/app/components/avo/fields/has_one_field/show_component.rb +21 -0
- data/app/components/avo/fields/id_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/id_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/index_component.rb +9 -4
- data/app/components/avo/fields/key_value_field/edit_component.html.erb +2 -2
- data/app/components/avo/fields/key_value_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/markdown_field/edit_component.html.erb +2 -2
- data/app/components/avo/fields/markdown_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/number_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/number_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/password_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/progress_bar_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/select_field/edit_component.html.erb +1 -2
- data/app/components/avo/fields/select_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/show_component.rb +36 -1
- data/app/components/avo/fields/status_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/status_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/tags_field/edit_component.html.erb +1 -5
- data/app/components/avo/fields/tags_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/text_field/edit_component.html.erb +2 -2
- data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/text_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/textarea_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/textarea_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/trix_field/edit_component.html.erb +13 -13
- data/app/components/avo/fields/trix_field/edit_component.rb +19 -1
- data/app/components/avo/fields/trix_field/show_component.html.erb +1 -1
- data/app/components/avo/index/grid_item_component.html.erb +6 -6
- data/app/components/avo/index/grid_item_component.rb +15 -0
- data/app/components/avo/index/resource_controls_component.rb +3 -0
- data/app/components/avo/index/resource_grid_component.rb +1 -1
- data/app/components/avo/resource_component.rb +5 -1
- data/app/components/avo/sidebar/item_switcher_component.html.erb +3 -3
- data/app/components/avo/sidebar/link_component.html.erb +2 -2
- data/app/components/avo/sidebar/link_component.rb +3 -1
- data/app/components/avo/views/resource_edit_component.html.erb +47 -28
- data/app/components/avo/views/resource_edit_component.rb +26 -9
- data/app/components/avo/views/resource_show_component.rb +0 -8
- data/app/controllers/avo/actions_controller.rb +7 -5
- data/app/controllers/avo/application_controller.rb +22 -3
- data/app/controllers/avo/associations_controller.rb +2 -2
- data/app/controllers/avo/base_controller.rb +24 -11
- data/app/helpers/avo/application_helper.rb +31 -3
- data/app/helpers/avo/resources_helper.rb +4 -8
- data/app/helpers/avo/url_helpers.rb +8 -0
- data/app/javascript/js/controllers/action_controller.js +3 -1
- data/app/javascript/js/controllers/fields/date_field_controller.js +21 -1
- data/app/javascript/js/controllers/search_controller.js +122 -118
- data/app/views/avo/actions/show.html.erb +5 -1
- data/avo.gemspec +1 -1
- data/config/master.key +1 -0
- data/lib/avo/base_action.rb +25 -6
- data/lib/avo/base_resource.rb +6 -4
- data/lib/avo/base_resource_tool.rb +1 -1
- data/lib/avo/concerns/fetches_things.rb +2 -0
- data/lib/avo/configuration.rb +2 -0
- data/lib/avo/fields/base_field.rb +5 -1
- data/lib/avo/fields/belongs_to_field.rb +1 -1
- data/lib/avo/fields/has_and_belongs_to_many_field.rb +1 -1
- data/lib/avo/fields/has_base_field.rb +5 -1
- data/lib/avo/fields/has_many_field.rb +1 -1
- data/lib/avo/fields/select_field.rb +1 -0
- data/lib/avo/menu/base_item.rb +1 -0
- data/lib/avo/menu/builder.rb +4 -2
- data/lib/avo/menu/menu.rb +2 -0
- data/lib/avo/services/authorization_service.rb +24 -20
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/templates/field/components/edit_component.html.erb.tt +1 -1
- data/lib/generators/avo/templates/field/components/show_component.html.erb.tt +1 -1
- data/public/avo-assets/avo.base.css +26 -8
- data/public/avo-assets/avo.base.js +79 -79
- data/public/avo-assets/avo.base.js.map +3 -3
- metadata +8 -11
- data/app/components/avo/common_field_wrapper_component.html.erb +0 -26
- data/app/components/avo/common_field_wrapper_component.rb +0 -46
- data/app/components/avo/edit/field_wrapper_component.html.erb +0 -11
- data/app/components/avo/edit/field_wrapper_component.rb +0 -21
- data/app/components/avo/show/field_wrapper_component.html.erb +0 -9
- data/app/components/avo/show/field_wrapper_component.rb +0 -12
@@ -3,15 +3,21 @@
|
|
3
3
|
class Avo::Fields::EditComponent < ViewComponent::Base
|
4
4
|
include Avo::ResourcesHelper
|
5
5
|
|
6
|
+
attr_reader :compact
|
7
|
+
attr_reader :displayed_in_modal
|
6
8
|
attr_reader :field
|
9
|
+
attr_reader :form
|
10
|
+
attr_reader :index
|
11
|
+
attr_reader :resource
|
7
12
|
attr_reader :view
|
8
13
|
|
9
|
-
def initialize(field: nil, resource: nil, index: 0, form: nil, displayed_in_modal: false)
|
14
|
+
def initialize(field: nil, resource: nil, index: 0, form: nil, displayed_in_modal: false, compact: false, **kwargs)
|
15
|
+
@compact = compact
|
16
|
+
@displayed_in_modal = displayed_in_modal
|
10
17
|
@field = field
|
11
|
-
@resource = resource
|
12
|
-
@index = index
|
13
18
|
@form = form
|
14
|
-
@
|
19
|
+
@index = index
|
20
|
+
@resource = resource
|
15
21
|
@view = :edit
|
16
22
|
end
|
17
23
|
|
@@ -22,4 +28,16 @@ class Avo::Fields::EditComponent < ViewComponent::Base
|
|
22
28
|
def render?
|
23
29
|
!field.computed
|
24
30
|
end
|
31
|
+
|
32
|
+
def field_wrapper_args
|
33
|
+
{
|
34
|
+
compact: compact,
|
35
|
+
displayed_in_modal: displayed_in_modal,
|
36
|
+
field: field,
|
37
|
+
form: form,
|
38
|
+
index: index,
|
39
|
+
resource: resource,
|
40
|
+
view: view
|
41
|
+
}
|
42
|
+
end
|
25
43
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<%= @form.text_field @field.id,
|
3
3
|
class: classes("w-full"),
|
4
4
|
data: @field.get_html(:data, view: view, element: :input),
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<% if @field.value.present? %>
|
3
3
|
<div class="mb-2">
|
4
4
|
<%= render Avo::Fields::Common::SingleFileViewerComponent.new resource: @resource, field: @field %>
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<%= index_field_wrapper field: @field, resource: @resource, flush: flush? do %>
|
2
2
|
<% if @field.value.present? %>
|
3
3
|
<% if @field.value.attached? && @field.value.representable? && @field.is_image %>
|
4
|
-
<%= link_to_if @field.link_to_resource, image_tag(helpers.main_app.url_for(@field.value), class: 'h-10'),
|
4
|
+
<%= link_to_if @field.link_to_resource, image_tag(helpers.main_app.url_for(@field.value), class: 'h-10'), resource_view_path, class: 'block' %>
|
5
5
|
<% elsif @field.value.attached? && @field.is_audio %>
|
6
|
-
<%= link_to_if @field.link_to_resource, audio_tag(helpers.main_app.url_for(@field.value), controls: true, preload: false, class: 'max-h-full h-10'),
|
6
|
+
<%= link_to_if @field.link_to_resource, audio_tag(helpers.main_app.url_for(@field.value), controls: true, preload: false, class: 'max-h-full h-10'), resource_view_path, class: 'block h-8' %>
|
7
7
|
<% else %>
|
8
8
|
<%= @field.value.filename %>
|
9
9
|
<% end %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args, full_width: true do %>
|
2
2
|
<%= render Avo::Fields::Common::FilesListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
|
3
3
|
|
4
4
|
<% if @resource.authorization.authorize_action(:upload_attachments?, raise_exception: false) %>
|
@@ -1,3 +1,3 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args, full_width: true do %>
|
2
2
|
<%= render Avo::Fields::Common::FilesListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
|
3
3
|
<% end %>
|
@@ -6,10 +6,23 @@
|
|
6
6
|
<%= render Avo::PanelComponent.new(name: @field.name) do |c| %>
|
7
7
|
<% c.tools do %>
|
8
8
|
<% if !@field.is_readonly? && can_attach? %>
|
9
|
-
<%= a_link attach_path,
|
9
|
+
<%= a_link attach_path,
|
10
|
+
icon: 'heroicons/outline/link',
|
11
|
+
color: :primary,
|
12
|
+
'data-turbo-frame': 'attach_modal' do %>
|
10
13
|
<%= t('avo.attach_item', item: @field.name.downcase) %>
|
11
14
|
<% end %>
|
12
15
|
<% end %>
|
16
|
+
<% if !@field.is_readonly? && can_see_the_create_button? %>
|
17
|
+
<%= a_link create_path,
|
18
|
+
icon: 'heroicons/outline/plus',
|
19
|
+
'data-target': 'create',
|
20
|
+
'data-turbo-frame': '_top',
|
21
|
+
style: :primary,
|
22
|
+
color: :primary do %>
|
23
|
+
<%= t('avo.create_new_item', item: @field.name.downcase ) %>
|
24
|
+
<% end %>
|
25
|
+
<% end %>
|
13
26
|
<% end %>
|
14
27
|
|
15
28
|
<% c.body do %>
|
@@ -23,4 +23,25 @@ class Avo::Fields::HasOneField::ShowComponent < Avo::Fields::ShowComponent
|
|
23
23
|
def attach_path
|
24
24
|
helpers.avo.resources_associations_new_path(@resource.singular_model_key, @resource.model.id, @field.id)
|
25
25
|
end
|
26
|
+
|
27
|
+
def can_see_the_create_button?
|
28
|
+
create = "create_#{@field.id.to_s}?"
|
29
|
+
|
30
|
+
authorization_service = @resource.authorization
|
31
|
+
|
32
|
+
# By default return true if the create method is not defined for this field
|
33
|
+
return true unless authorization_service.has_method?(create, raise_exception: false)
|
34
|
+
|
35
|
+
authorization_service.authorize_action(create, raise_exception: false)
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_path
|
39
|
+
args = {
|
40
|
+
via_relation: @resource.singular_model_key,
|
41
|
+
via_relation_class: @resource.name,
|
42
|
+
via_resource_id: @resource.model.id
|
43
|
+
}
|
44
|
+
|
45
|
+
helpers.new_resource_path(resource: @field.target_resource, **args)
|
46
|
+
end
|
26
47
|
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<%= index_field_wrapper field: @field, resource: @resource, class: 'whitespace-no-wrap w-[1%]' do %>
|
2
|
-
<% link_to_if (@field.link_to_resource or Avo.configuration.id_links_to_resource), @field.value,
|
2
|
+
<% link_to_if (@field.link_to_resource or Avo.configuration.id_links_to_resource), @field.value, resource_view_path, title: t('avo.view_item', item: @resource.name).humanize %>
|
3
3
|
<% end %>
|
@@ -13,11 +13,16 @@ class Avo::Fields::IndexComponent < ViewComponent::Base
|
|
13
13
|
@view = :index
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def resource_view_path
|
17
|
+
args = {}
|
18
|
+
|
17
19
|
if @parent_model.present?
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
args = {
|
21
|
+
via_resource_class: @parent_model.class,
|
22
|
+
via_resource_id: @parent_model.id
|
23
|
+
}
|
21
24
|
end
|
25
|
+
|
26
|
+
helpers.resource_view_path(model: @resource.model, resource: @resource, **args)
|
22
27
|
end
|
23
28
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
<%=
|
2
|
-
<%= render Avo::Fields::Common::KeyValueComponent.new field: @field, form: @form, view:
|
1
|
+
<%= field_wrapper **field_wrapper_args, full_width: true do %>
|
2
|
+
<%= render Avo::Fields::Common::KeyValueComponent.new field: @field, form: @form, view: view %>
|
3
3
|
<% end %>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args, full_width: true do %>
|
2
2
|
<div data-controller="simple-mde">
|
3
3
|
<%= @form.text_area @field.id,
|
4
4
|
class: classes("w-full js-has-simple-mde-editor"),
|
5
5
|
data: {
|
6
|
-
view:
|
6
|
+
view: view,
|
7
7
|
'simple-mde-target': 'element',
|
8
8
|
'component-options': @field.options.to_json,
|
9
9
|
},
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args, full_width: true do %>
|
2
2
|
<div data-controller="simple-mde">
|
3
3
|
<%= text_area_tag @field.id, @field.value,
|
4
4
|
class: helpers.input_classes('w-full js-has-simple-mde-editor'),
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<%= @form.number_field @field.id,
|
3
3
|
class: classes("w-full"),
|
4
4
|
data: @field.get_html(:data, view: view, element: :input),
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<%= @form.password_field @field.id,
|
3
3
|
class: classes("w-full"),
|
4
4
|
data: @field.get_html(:data, view: view, element: :input),
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<% if @field.display_value %>
|
3
3
|
<div class="text-center text-sm font-semibold w-full leading-none mb-1">
|
4
4
|
<span class="js-progress-bar-value-<%= @field.id %>"><%= @field.value %></span><%= @field.value_suffix if @field.value_suffix.present? %>
|
@@ -1,3 +1,3 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<%= render Avo::Fields::Common::ProgressBarComponent.new value: @field.value, display_value: @field.display_value, value_suffix: @field.value_suffix, max: @field.max, view: view %>
|
3
3
|
<% end %>
|
@@ -1,6 +1,5 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<%= @form.select @field.id, @field.options_for_select, {
|
3
|
-
selected: @field.value,
|
4
3
|
include_blank: @field.include_blank
|
5
4
|
},
|
6
5
|
aria: {
|
@@ -3,12 +3,47 @@
|
|
3
3
|
class Avo::Fields::ShowComponent < ViewComponent::Base
|
4
4
|
include Avo::ResourcesHelper
|
5
5
|
|
6
|
+
attr_reader :field
|
7
|
+
attr_reader :index
|
8
|
+
attr_reader :resource
|
6
9
|
attr_reader :view
|
7
10
|
|
8
11
|
def initialize(field: nil, resource: nil, index: 0, form: nil)
|
9
12
|
@field = field
|
10
|
-
@resource = resource
|
11
13
|
@index = index
|
14
|
+
@resource = resource
|
12
15
|
@view = :show
|
13
16
|
end
|
17
|
+
|
18
|
+
def wrapper_data
|
19
|
+
{
|
20
|
+
**stimulus_attributes
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def stimulus_attributes
|
25
|
+
attributes = {}
|
26
|
+
|
27
|
+
if @resource.present?
|
28
|
+
@resource.get_stimulus_controllers.split(" ").each do |controller|
|
29
|
+
attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
wrapper_data_attributes = @field.get_html :data, view: view, element: :wrapper
|
34
|
+
if wrapper_data_attributes.present?
|
35
|
+
attributes.merge! wrapper_data_attributes
|
36
|
+
end
|
37
|
+
|
38
|
+
attributes
|
39
|
+
end
|
40
|
+
|
41
|
+
def field_wrapper_args
|
42
|
+
{
|
43
|
+
field: field,
|
44
|
+
index: index,
|
45
|
+
resource: resource,
|
46
|
+
view: view
|
47
|
+
}
|
48
|
+
end
|
14
49
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<%= @form.text_field @field.id,
|
3
3
|
class: classes("w-full"),
|
4
4
|
data: @field.get_html(:data, view: view, element: :input),
|
@@ -1,8 +1,4 @@
|
|
1
|
-
<%=
|
2
|
-
index: @index,
|
3
|
-
form: @form,
|
4
|
-
resource: @resource,
|
5
|
-
displayed_in_modal: @displayed_in_modal do %>
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
6
2
|
<div data-controller="tags-field">
|
7
3
|
<%# dummy field %>
|
8
4
|
<%= text_field_tag "#{@field.id}-dummy", '',
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<div class="flex gap-1 items-center flex-wrap">
|
3
3
|
<% @field.field_value.each do |item| %>
|
4
4
|
<%= render Avo::Fields::TagsField::TagComponent.new(label: label_from_item(item)) %>
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<%=
|
2
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
|
+
<%= form.text_field @field.id,
|
3
3
|
class: classes("w-full"),
|
4
4
|
data: @field.get_html(:data, view: view, element: :input),
|
5
5
|
disabled: @field.is_readonly?,
|
@@ -4,6 +4,6 @@
|
|
4
4
|
<% elsif @field.protocol.present? %>
|
5
5
|
<%= link_to @field.value, "#{@field.protocol}:#{@field.value}" %>
|
6
6
|
<% else %>
|
7
|
-
<%= link_to_if @field.link_to_resource, @field.value,
|
7
|
+
<%= link_to_if @field.link_to_resource, @field.value, resource_view_path %>
|
8
8
|
<% end %>
|
9
9
|
<% end %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= field_wrapper **field_wrapper_args do %>
|
2
2
|
<%= @form.text_area @field.id,
|
3
3
|
class: classes("w-full"),
|
4
4
|
data: @field.get_html(:data, view: view, element: :input),
|
@@ -1,16 +1,16 @@
|
|
1
1
|
<%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, full_width: true do %>
|
2
|
-
|
3
|
-
data
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
<%= content_tag :div, class: "relative block overflow-x-auto max-w-full",
|
3
|
+
data: {
|
4
|
+
controller: "trix-field",
|
5
|
+
trix_field_target: "controller",
|
6
|
+
resource_name: resource_name,
|
7
|
+
resource_id: resource_id,
|
8
|
+
attachments_disabled: @field.attachments_disabled,
|
9
|
+
attachment_key: @field.attachment_key,
|
10
|
+
hide_attachment_filename: @field.hide_attachment_filename,
|
11
|
+
hide_attachment_filesize: @field.hide_attachment_filesize,
|
12
|
+
hide_attachment_url: @field.hide_attachment_url,
|
13
|
+
} do %>
|
14
14
|
<%= content_tag 'trix-editor',
|
15
15
|
class: 'trix-content',
|
16
16
|
data: {
|
@@ -29,5 +29,5 @@
|
|
29
29
|
placeholder: @field.placeholder,
|
30
30
|
style: @field.get_html(:style, view: view, element: :input)
|
31
31
|
%>
|
32
|
-
|
32
|
+
<% end %>
|
33
33
|
<% end %>
|
@@ -1,7 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Avo::Fields::TrixField::EditComponent < Avo::Fields::EditComponent
|
4
|
+
attr_reader :resource
|
5
|
+
|
6
|
+
def initialize(**args)
|
7
|
+
@resource = args[:resource]
|
8
|
+
@resource_id = args[:resource_id]
|
9
|
+
@resource_name = args[:resource_name]
|
10
|
+
|
11
|
+
super(**args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_name
|
15
|
+
@resource_name || resource&.singular_route_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource_id
|
19
|
+
@resource_id || resource&.model&.id
|
20
|
+
end
|
21
|
+
|
4
22
|
def trix_id
|
5
|
-
"trix_#{
|
23
|
+
"trix_#{resource_name}_#{@field.id}"
|
6
24
|
end
|
7
25
|
end
|
@@ -7,23 +7,23 @@
|
|
7
7
|
<%== item_selector_input floating: true, size: :lg %>
|
8
8
|
<% end %>
|
9
9
|
<% if cover.blank? %>
|
10
|
-
<%= link_to
|
10
|
+
<%= link_to resource_view_path do %>
|
11
11
|
<%= render Avo::Index::GridCoverEmptyStateComponent.new %>
|
12
12
|
<% end %>
|
13
13
|
<% elsif cover.respond_to?(:to_image) && cover.to_image.present? %>
|
14
|
-
<%= link_to_if cover.link_to_resource, image_tag(cover.to_image, class: 'absolute h-full w-full object-cover'),
|
14
|
+
<%= link_to_if cover.link_to_resource, image_tag(cover.to_image, class: 'absolute h-full w-full object-cover'), resource_view_path, class: 'absolute h-full w-full object-cover', title: title.value %>
|
15
15
|
<% elsif cover.type == 'file' %>
|
16
16
|
<% if cover.value.attached? && cover.value.representable? %>
|
17
|
-
<%= link_to_if cover.link_to_resource, image_tag(helpers.main_app.url_for(cover.value.variant(resize_to_limit: [480, 480])), class: 'absolute h-full w-full object-cover'),
|
17
|
+
<%= link_to_if cover.link_to_resource, image_tag(helpers.main_app.url_for(cover.value.variant(resize_to_limit: [480, 480])), class: 'absolute h-full w-full object-cover'), resource_view_path, class: 'absolute h-full w-full object-cover', title: title.value %>
|
18
18
|
<% else %>
|
19
|
-
<%= link_to
|
19
|
+
<%= link_to resource_view_path do %>
|
20
20
|
<div class="absolute bg-gray-100 w-full h-full">
|
21
21
|
<%= helpers.svg 'avocado', class: 'relative transform -translate-x-1/2 -translate-y-1/2 h-20 text-gray-400 inset-auto top-1/2 left-1/2' %>
|
22
22
|
</div>
|
23
23
|
<% end %>
|
24
24
|
<% end %>
|
25
25
|
<% elsif cover.value.present? %>
|
26
|
-
<%= link_to_if cover.link_to_resource, image_tag(cover.value, class: 'absolute h-full w-full object-cover'),
|
26
|
+
<%= link_to_if cover.link_to_resource, image_tag(cover.value, class: 'absolute h-full w-full object-cover'), resource_view_path, class: 'absolute h-full w-full object-cover', title: title.value %>
|
27
27
|
<% else %>
|
28
28
|
<%= render Avo::Index::GridCoverEmptyStateComponent.new %>
|
29
29
|
<% end %>
|
@@ -31,7 +31,7 @@
|
|
31
31
|
<div class="grid grid-cols-1 place-content-between p-4 h-full">
|
32
32
|
<div class="mb-4 h-full flex flex-col space-between">
|
33
33
|
<div class="grid font-semibold leading-tight text-lg mb-2">
|
34
|
-
<%= link_to_if title.link_to_resource, title.value,
|
34
|
+
<%= link_to_if title.link_to_resource, title.value, resource_view_path if title.present? %>
|
35
35
|
</div>
|
36
36
|
<div class="text-sm break-words text-gray-500">
|
37
37
|
<%= body.value if body.present? %>
|
@@ -3,6 +3,8 @@
|
|
3
3
|
class Avo::Index::GridItemComponent < ViewComponent::Base
|
4
4
|
include Avo::ResourcesHelper
|
5
5
|
|
6
|
+
attr_reader :parent_resource
|
7
|
+
|
6
8
|
def initialize(resource: nil, reflection: nil, parent_model: nil, parent_resource: nil)
|
7
9
|
@resource = resource
|
8
10
|
@reflection = reflection
|
@@ -24,4 +26,17 @@ class Avo::Index::GridItemComponent < ViewComponent::Base
|
|
24
26
|
def body
|
25
27
|
@grid_fields.body_field
|
26
28
|
end
|
29
|
+
|
30
|
+
def resource_view_path
|
31
|
+
args = {}
|
32
|
+
|
33
|
+
if @parent_model.present?
|
34
|
+
args = {
|
35
|
+
via_resource_class: parent_resource.model_class,
|
36
|
+
via_resource_id: @parent_model.id
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
helpers.resource_view_path(model: @resource.model, resource: @resource, **args)
|
41
|
+
end
|
27
42
|
end
|
@@ -23,6 +23,8 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def can_view?
|
26
|
+
return false if Avo.configuration.resource_default_view == :edit
|
27
|
+
|
26
28
|
return authorize_association_for(:show) if @reflection.present?
|
27
29
|
|
28
30
|
# Even if there's a @reflection object present, for show we're going to fallback to the original policy.
|
@@ -65,6 +67,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def parent_resource
|
70
|
+
return @parent_resource if @parent_resource.present?
|
68
71
|
return nil if @parent_model.blank?
|
69
72
|
|
70
73
|
::Avo::App.get_resource_by_model_name @parent_model.class
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Avo::Index::ResourceGridComponent < ViewComponent::Base
|
4
|
-
def initialize(resources: nil, resource: nil, reflection: nil, parent_model: nil, parent_resource:
|
4
|
+
def initialize(resources: nil, resource: nil, reflection: nil, parent_model: nil, parent_resource: nil)
|
5
5
|
@resources = resources
|
6
6
|
@resource = resource
|
7
7
|
@reflection = reflection
|