avo 4.4.2 → 4.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/components/avo/debug/status_component.html.erb +27 -23
- data/app/components/avo/debug/status_component.rb +4 -0
- data/app/components/avo/resource_component.rb +1 -1
- data/app/controllers/avo/actions_controller.rb +41 -4
- data/app/controllers/avo/base_application_controller.rb +1 -0
- data/app/controllers/avo/base_controller.rb +1 -1
- data/app/helpers/avo/application_helper.rb +21 -0
- data/app/views/avo/actions/show.html.erb +1 -1
- data/app/views/avo/base/_multiple_select_filter.html.erb +3 -2
- data/app/views/avo/base/_select_filter.html.erb +1 -1
- data/lib/avo/base_action.rb +31 -3
- data/lib/avo/concerns/association_query_scope.rb +21 -9
- data/lib/avo/concerns/renders_controls.rb +3 -1
- data/lib/avo/configuration.rb +7 -0
- data/lib/avo/fields/array_field.rb +5 -0
- data/lib/avo/fields/concerns/has_storage_key.rb +38 -0
- data/lib/avo/fields/date_field.rb +1 -1
- data/lib/avo/fields/date_time_field.rb +1 -1
- data/lib/avo/fields/file_field.rb +8 -0
- data/lib/avo/fields/files_field.rb +4 -1
- data/lib/avo/fields/time_field.rb +1 -1
- data/lib/avo/skills/avo-actions/SKILL.md +4 -3
- data/lib/avo/skills/avo-admin-config/SKILL.md +4 -1
- data/lib/avo/skills/avo-custom-ui/SKILL.md +3 -1
- data/lib/avo/skills/avo-fields/SKILL.md +2 -0
- data/lib/avo/skills/avo-filters/SKILL.md +1 -0
- data/lib/avo/skills/avo-index-views/SKILL.md +2 -2
- data/lib/avo/skills/avo-update/SKILL.md +2 -2
- data/lib/avo/skills/docs-index.json +2 -2
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/templates/initializer/avo.tt +4 -0
- metadata +2 -4
- data/config/initializers/pagy.rb +0 -6
- data/lib/generators/avo/templates/locales/pagy/nn.yml +0 -15
- data/lib/generators/avo/templates/locales/pagy/ro.yml +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a89f96a8c205ef4f0693b8b593bf09988d27968ea8013f8dcefa2b7846f87c9e
|
|
4
|
+
data.tar.gz: 67f740fcdd78212f5f717b4ba4ac16ae911fa9b9cec29900b19f4680133a614e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df12fa371c2240d2599b82e0fd02664ba638cb85d1aac47d7c6f9b62ca639be06177f0371bde90519416e4ff17d6e203b694fec43ae151a5061f5c90742c81ed
|
|
7
|
+
data.tar.gz: f2fa0792dc3c89d06bd1f082b71a91e91ee50effc4c66ef248f5634f8dfaeba6e6afe6bb43b78e08bd4550ebac263261ae86f579722ce094e72057e7c7638e03
|
data/Gemfile.lock
CHANGED
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
<%= render ui.panel(title: "Avo Status", description: "Use this page to debug your Avo instance.") do |panel| %>
|
|
2
2
|
<% panel.with_body do %>
|
|
3
3
|
<div class="status-page">
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
<% if license_card? %>
|
|
5
|
+
<%= license_card %>
|
|
6
|
+
<% else %>
|
|
7
|
+
<%= render ui.card(title: "License", padded: true) do |card| %>
|
|
8
|
+
<% card.with_body do %>
|
|
9
|
+
<div class="status-page__license">
|
|
10
|
+
<%= render ui.badge(label: "Community", color: :success, icon: "tabler/outline/rosette-discount-check") %>
|
|
11
|
+
<dl class="status-page__details">
|
|
12
|
+
<% information_items.each do |key, value| %>
|
|
13
|
+
<div class="status-page__detail">
|
|
14
|
+
<dt class="status-page__detail-label"><%= key.humanize %></dt>
|
|
15
|
+
<dd class="status-page__detail-value"><%= value.presence || tag.span("Not set", class: "status-page__detail-empty") %></dd>
|
|
16
|
+
</div>
|
|
17
|
+
<% end %>
|
|
18
|
+
</dl>
|
|
19
|
+
</div>
|
|
20
|
+
<% end %>
|
|
21
|
+
<% card.with_footer do %>
|
|
22
|
+
<div class="status-page__upgrade">
|
|
23
|
+
<p class="status-page__upgrade-text">
|
|
24
|
+
Need more? Pick your license, then open its <strong>Upgrade</strong> section.
|
|
25
|
+
</p>
|
|
26
|
+
<%= a_link "https://avohq.io/licenses", style: :primary, color: :blue, size: :sm, target: "_blank", icon: "tabler/outline/external-link" do %>
|
|
27
|
+
View licenses
|
|
14
28
|
<% end %>
|
|
15
|
-
</
|
|
16
|
-
|
|
17
|
-
<% end %>
|
|
18
|
-
<% card.with_footer do %>
|
|
19
|
-
<div class="status-page__upgrade">
|
|
20
|
-
<p class="status-page__upgrade-text">
|
|
21
|
-
Need more? Pick your license, then open its <strong>Upgrade</strong> section.
|
|
22
|
-
</p>
|
|
23
|
-
<%= a_link "https://avohq.io/licenses", style: :primary, color: :blue, size: :sm, target: "_blank", icon: "tabler/outline/external-link" do %>
|
|
24
|
-
View licenses
|
|
25
|
-
<% end %>
|
|
26
|
-
</div>
|
|
29
|
+
</div>
|
|
30
|
+
<% end %>
|
|
27
31
|
<% end %>
|
|
28
32
|
<% end %>
|
|
29
33
|
|
|
30
|
-
<%= render Avo::Debug::PluginsComponent.new %>
|
|
34
|
+
<%= render Avo::Debug::PluginsComponent.new(row_extra: @plugin_row_extra) %>
|
|
31
35
|
|
|
32
36
|
<% if Avo::IN_DEVELOPMENT %>
|
|
33
37
|
<%= render ui.card(title: "Telemetry", description: "The payload sent to HQ. Shown only when AVO_IN_DEVELOPMENT=1.", class: "status-page__wide") do |card| %>
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
class Avo::Debug::StatusComponent < Avo::BaseComponent
|
|
4
4
|
include Avo::ApplicationHelper
|
|
5
5
|
|
|
6
|
+
# A host page that knows more about the license fills these, so it reuses this layout instead of drawing its own.
|
|
7
|
+
renders_one :license_card
|
|
8
|
+
prop :plugin_row_extra
|
|
9
|
+
|
|
6
10
|
def information_items
|
|
7
11
|
@information_items ||= {
|
|
8
12
|
license_key: Avo.configuration.license_key,
|
|
@@ -161,7 +161,7 @@ class Avo::ResourceComponent < Avo::BaseComponent
|
|
|
161
161
|
|
|
162
162
|
def row_actions
|
|
163
163
|
@resource.get_actions
|
|
164
|
-
.map { |action_bag| action_bag[:class].new(record: @resource.record, resource: @resource, view: @view, **action_bag.except(:class)) }
|
|
164
|
+
.map { |action_bag| action_bag[:class].new(record: @resource.record, resource: @resource, view: @view, parent_record: @parent_record, parent_resource: @parent_resource, **action_bag.except(:class)) }
|
|
165
165
|
.select { |action| action.is_a?(Avo::Divider) || action.visible_in_view(parent_resource: @parent_resource) }
|
|
166
166
|
end
|
|
167
167
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
module Avo
|
|
2
2
|
class ActionsController < Avo::ApplicationController
|
|
3
|
+
include Avo::Concerns::AssociationQueryScope
|
|
4
|
+
|
|
3
5
|
before_action :set_resource_name, :set_resource
|
|
4
|
-
before_action :set_query, :set_record, :set_action, :verify_authorization, only: [:show, :handle]
|
|
6
|
+
before_action :set_query, :set_record, :set_parent, :set_action, :verify_authorization, only: [:show, :handle]
|
|
5
7
|
before_action :set_fields, only: :handle
|
|
6
8
|
|
|
7
9
|
# Sets @record based on context:
|
|
@@ -93,7 +95,7 @@ module Avo
|
|
|
93
95
|
|
|
94
96
|
def action_params
|
|
95
97
|
@action_params ||= params.permit(
|
|
96
|
-
:id, :authenticity_token, :resource_name, :action_id, :button, :arguments, :view_type, :resource_view, :via_related_name, fields: {}
|
|
98
|
+
:id, :authenticity_token, :resource_name, :action_id, :button, :arguments, :view_type, :resource_view, :via_related_name, :via_resource_class, :via_record_id, fields: {}
|
|
97
99
|
)
|
|
98
100
|
end
|
|
99
101
|
|
|
@@ -108,13 +110,42 @@ module Avo
|
|
|
108
110
|
view: origin_view,
|
|
109
111
|
arguments: BaseAction.decode_arguments(params[:arguments] || params.dig(:fields, :arguments)) || {},
|
|
110
112
|
query: @query,
|
|
111
|
-
index_query: decrypted_index_query
|
|
113
|
+
index_query: decrypted_index_query,
|
|
114
|
+
parent_record: @parent_record,
|
|
115
|
+
parent_resource: @parent_resource
|
|
112
116
|
)
|
|
113
117
|
|
|
114
118
|
# Fetch action's fields
|
|
115
119
|
@action.fields
|
|
116
120
|
end
|
|
117
121
|
|
|
122
|
+
# The panel's parent arrives as request params, so it is looked up the way the panel loaded it, and the run
|
|
123
|
+
# asks what the panel's Actions button asked: that the user may view the association and act on it.
|
|
124
|
+
def set_parent
|
|
125
|
+
return if params[:via_resource_class].blank? || params[:via_record_id].blank? || params[:via_related_name].blank?
|
|
126
|
+
|
|
127
|
+
field = set_parent_from_via_params(association: params[:via_related_name], resource_class: @resource.class)
|
|
128
|
+
|
|
129
|
+
raise Avo::NotAuthorizedError.new unless act_on_association_authorized?(field)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Mirrors the `act_on_{association}?` check that shows the Actions button in the panel.
|
|
133
|
+
def act_on_association_authorized?(field)
|
|
134
|
+
return true unless Avo.configuration.authorization_enabled?
|
|
135
|
+
|
|
136
|
+
association_name = BaseResource.valid_association_name(@parent_record, field.association_name)
|
|
137
|
+
return true if association_name.blank?
|
|
138
|
+
|
|
139
|
+
service = @parent_resource.authorization(user: _current_user)
|
|
140
|
+
method_name = :"act_on_#{association_name}?"
|
|
141
|
+
|
|
142
|
+
if service.has_method?(method_name, raise_exception: false)
|
|
143
|
+
service.authorize_action(method_name, record: @parent_record, raise_exception: false)
|
|
144
|
+
else
|
|
145
|
+
!Avo.configuration.explicit_authorization
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
118
149
|
# The view the action was started from: index, show, or edit. The action
|
|
119
150
|
# link and the modal form both carry it as `resource_view`, but that is a
|
|
120
151
|
# request param, so it is trusted only as far as the route backs it up: a
|
|
@@ -172,7 +203,13 @@ module Avo
|
|
|
172
203
|
turbo_stream.avo_flash_alerts
|
|
173
204
|
]
|
|
174
205
|
when :navigate_to_action
|
|
175
|
-
|
|
206
|
+
# The next action runs from the same panel, so it gets the same parent.
|
|
207
|
+
src, _ = @response[:action].link_arguments(
|
|
208
|
+
resource: @action.resource,
|
|
209
|
+
**@action.parent_query,
|
|
210
|
+
via_related_name: params[:via_related_name],
|
|
211
|
+
**@response[:navigate_to_action_args]
|
|
212
|
+
)
|
|
176
213
|
|
|
177
214
|
turbo_stream.turbo_frame_set_src(Avo::MODAL_FRAME_ID, src)
|
|
178
215
|
when :redirect
|
|
@@ -110,6 +110,7 @@ module Avo
|
|
|
110
110
|
def set_related_resource
|
|
111
111
|
# Find the field from the parent resource
|
|
112
112
|
association_field = find_association_field(resource: @resource, association: params[:related_name])
|
|
113
|
+
raise ActiveRecord::RecordNotFound if association_field.nil?
|
|
113
114
|
|
|
114
115
|
# Find the resource from the related field
|
|
115
116
|
related_resource = association_field.hydrate(record: @record).resource_class(params)
|
|
@@ -403,7 +403,7 @@ module Avo
|
|
|
403
403
|
@actions = @resource
|
|
404
404
|
.get_actions
|
|
405
405
|
.map do |action_bag|
|
|
406
|
-
action_bag[:class].new(record:, resource: @resource, view: @view, **action_bag.except(:class))
|
|
406
|
+
action_bag[:class].new(record:, resource: @resource, view: @view, parent_record: @parent_record, parent_resource: @parent_resource, **action_bag.except(:class))
|
|
407
407
|
end
|
|
408
408
|
.select do |action|
|
|
409
409
|
action.is_a?(DividerComponent) || action.visible_in_view(parent_resource: @parent_resource)
|
|
@@ -264,6 +264,27 @@ module Avo
|
|
|
264
264
|
Avo::Filters::BaseFilter.encode_filters(filter_params)
|
|
265
265
|
end
|
|
266
266
|
|
|
267
|
+
# Filter `options` map each id to its label. A Hash in place of a label is a group: its key labels an <optgroup>
|
|
268
|
+
# and the Hash holds that group's own id => label options.
|
|
269
|
+
def filter_options_for_select(options, selected)
|
|
270
|
+
return options_for_select(options.invert, selected) if options.values.none?(Hash)
|
|
271
|
+
|
|
272
|
+
safe_join(
|
|
273
|
+
options.map do |key, value|
|
|
274
|
+
if value.is_a?(Hash)
|
|
275
|
+
content_tag :optgroup, options_for_select(value.invert, selected), label: key
|
|
276
|
+
else
|
|
277
|
+
options_for_select([[value, key]], selected)
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# The rows a select box needs to list the filter's `options`, counting each group's label as a row.
|
|
284
|
+
def filter_options_rows(options)
|
|
285
|
+
options.values.sum { |value| value.is_a?(Hash) ? value.size + 1 : 1 }
|
|
286
|
+
end
|
|
287
|
+
|
|
267
288
|
def number_to_social(number, start_at: 10_000)
|
|
268
289
|
return number_with_delimiter(number) if number < start_at
|
|
269
290
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
class="hidden text-content"
|
|
12
12
|
>
|
|
13
13
|
<%= form_with scope: 'fields',
|
|
14
|
-
url: @action.link_arguments(resource: @resource, resource_view: params[:resource_view]).first,
|
|
14
|
+
url: @action.link_arguments(resource: @resource, resource_view: params[:resource_view], via_related_name: params[:via_related_name]).first,
|
|
15
15
|
local: true,
|
|
16
16
|
html: {
|
|
17
17
|
novalidate: true,
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
data-controller="multiple-select-filter"
|
|
4
4
|
data-filter-name="<%= filter.name %>"
|
|
5
5
|
data-multiple-select-filter-keep-filters-panel-open-value="<%= @resource.keep_filters_panel_open %>">
|
|
6
|
-
|
|
6
|
+
<% options = filter.options %>
|
|
7
|
+
<%= select_tag filter.id, filter_options_for_select(options, filter.selected_value(@applied_filters)),
|
|
7
8
|
class: input_classes("filters-multi-select w-full"),
|
|
8
9
|
multiple: true,
|
|
9
|
-
size:
|
|
10
|
+
size: filter_options_rows(options).clamp(2, 4),
|
|
10
11
|
id: "avo_filters_#{filter.id.parameterize.underscore}",
|
|
11
12
|
"data-filter-class": filter.class.to_s,
|
|
12
13
|
"data-multiple-select-filter-target": "selector" %>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
data-controller="select-filter"
|
|
4
4
|
data-filter-name="<%= filter.name %>"
|
|
5
5
|
data-select-filter-keep-filters-panel-open-value="<%= @resource.keep_filters_panel_open %>">
|
|
6
|
-
<%= select_tag filter.id,
|
|
6
|
+
<%= select_tag filter.id, filter_options_for_select(filter.options, filter.applied_or_default_value(@applied_filters)),
|
|
7
7
|
class: input_classes("w-full mb-0"),
|
|
8
8
|
include_blank: filter.class.empty_message || "—",
|
|
9
9
|
id: "avo_filters_#{filter.id.parameterize.underscore}",
|
data/lib/avo/base_action.rb
CHANGED
|
@@ -36,6 +36,10 @@ module Avo
|
|
|
36
36
|
attr_accessor :record
|
|
37
37
|
attr_accessor :resource
|
|
38
38
|
attr_accessor :user
|
|
39
|
+
# The record and resource of the association panel the action was started from, like the
|
|
40
|
+
# team whose members panel lists the selected users. Both are nil anywhere else.
|
|
41
|
+
attr_accessor :parent_record
|
|
42
|
+
attr_accessor :parent_resource
|
|
39
43
|
attr_reader :arguments
|
|
40
44
|
attr_reader :icon
|
|
41
45
|
attr_reader :appended_turbo_streams
|
|
@@ -53,7 +57,6 @@ module Avo
|
|
|
53
57
|
delegate :avo, to: :view_context
|
|
54
58
|
delegate :main_app, to: :view_context
|
|
55
59
|
delegate :to_param, to: :class
|
|
56
|
-
delegate :link_arguments, to: :class
|
|
57
60
|
delegate :translation_key, to: :class
|
|
58
61
|
|
|
59
62
|
class << self
|
|
@@ -129,6 +132,8 @@ module Avo
|
|
|
129
132
|
target: name,
|
|
130
133
|
resource: @resource,
|
|
131
134
|
record: @record,
|
|
135
|
+
parent_record: @parent_record,
|
|
136
|
+
parent_resource: @parent_resource,
|
|
132
137
|
view: @view,
|
|
133
138
|
arguments: @arguments,
|
|
134
139
|
query: @query,
|
|
@@ -139,9 +144,11 @@ module Avo
|
|
|
139
144
|
self.class.to_s.demodulize.underscore.humanize(keep_id_suffix: true)
|
|
140
145
|
end
|
|
141
146
|
|
|
142
|
-
def initialize(record: nil, resource: nil, user: nil, view: nil, arguments: {}, icon: "tabler/outline/player-play", query: nil, index_query: nil)
|
|
147
|
+
def initialize(record: nil, resource: nil, user: nil, view: nil, arguments: {}, icon: "tabler/outline/player-play", query: nil, index_query: nil, parent_record: nil, parent_resource: nil)
|
|
143
148
|
@record = record
|
|
144
149
|
@resource = resource
|
|
150
|
+
@parent_record = parent_record
|
|
151
|
+
@parent_resource = parent_resource
|
|
145
152
|
@user = user
|
|
146
153
|
@view = Avo::ViewInquirer.new(view)
|
|
147
154
|
@icon = icon
|
|
@@ -159,6 +166,18 @@ module Avo
|
|
|
159
166
|
@response[:messages] = []
|
|
160
167
|
end
|
|
161
168
|
|
|
169
|
+
# The action's link carries the panel's parent, so the actions controller can find it again.
|
|
170
|
+
def link_arguments(resource:, arguments: {}, **args)
|
|
171
|
+
self.class.link_arguments(resource:, arguments:, **parent_query, **args)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# The `via_*` params that name the parent, or an empty hash when there is none.
|
|
175
|
+
def parent_query
|
|
176
|
+
return {} if @parent_record.blank? || @parent_resource.blank?
|
|
177
|
+
|
|
178
|
+
{via_resource_class: @parent_resource.class.to_s, via_record_id: @parent_record.to_param}
|
|
179
|
+
end
|
|
180
|
+
|
|
162
181
|
# Blank method
|
|
163
182
|
def fields
|
|
164
183
|
end
|
|
@@ -237,7 +256,8 @@ module Avo
|
|
|
237
256
|
Avo::ExecutionContext.new(
|
|
238
257
|
target: visible,
|
|
239
258
|
params: params,
|
|
240
|
-
|
|
259
|
+
parent_record: @parent_record,
|
|
260
|
+
parent_resource: parent_resource || @parent_resource,
|
|
241
261
|
resource: @resource,
|
|
242
262
|
view: @view,
|
|
243
263
|
arguments: arguments
|
|
@@ -349,6 +369,8 @@ module Avo
|
|
|
349
369
|
target: authorize,
|
|
350
370
|
action: self,
|
|
351
371
|
resource: @resource,
|
|
372
|
+
parent_record: @parent_record,
|
|
373
|
+
parent_resource: @parent_resource,
|
|
352
374
|
view: @view,
|
|
353
375
|
arguments: arguments
|
|
354
376
|
).handle
|
|
@@ -372,6 +394,8 @@ module Avo
|
|
|
372
394
|
target: confirmation,
|
|
373
395
|
action: self,
|
|
374
396
|
resource: @resource,
|
|
397
|
+
parent_record: @parent_record,
|
|
398
|
+
parent_resource: @parent_resource,
|
|
375
399
|
view: @view,
|
|
376
400
|
arguments:
|
|
377
401
|
).handle
|
|
@@ -393,6 +417,8 @@ module Avo
|
|
|
393
417
|
action: self,
|
|
394
418
|
resource: @resource,
|
|
395
419
|
record: @record,
|
|
420
|
+
parent_record: @parent_record,
|
|
421
|
+
parent_resource: @parent_resource,
|
|
396
422
|
view: @view,
|
|
397
423
|
arguments:,
|
|
398
424
|
query: @query,
|
|
@@ -412,6 +438,8 @@ module Avo
|
|
|
412
438
|
target: self.class.public_send(option),
|
|
413
439
|
resource: @resource,
|
|
414
440
|
record: @record,
|
|
441
|
+
parent_record: @parent_record,
|
|
442
|
+
parent_resource: @parent_resource,
|
|
415
443
|
view: @view,
|
|
416
444
|
arguments: @arguments,
|
|
417
445
|
query: @query,
|
|
@@ -29,15 +29,7 @@ module Avo
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def build_association_scope_from_params(resource:, authorization:)
|
|
32
|
-
|
|
33
|
-
@parent_record = parent_resource_class.find_record(params[:via_record_id], params: params)
|
|
34
|
-
@parent_resource = parent_resource_class.new(
|
|
35
|
-
record: @parent_record,
|
|
36
|
-
view: Avo::ViewInquirer.new("show")
|
|
37
|
-
)
|
|
38
|
-
@parent_resource.detect_fields
|
|
39
|
-
field = find_association_field(resource: @parent_resource, association: params[:association_name] || params[:related_name])
|
|
40
|
-
authorize_via_association field, resource.class
|
|
32
|
+
field = set_parent_from_via_params(association: params[:association_name] || params[:related_name], resource_class: resource.class)
|
|
41
33
|
|
|
42
34
|
association_query_scope(
|
|
43
35
|
parent_resource: @parent_resource,
|
|
@@ -48,6 +40,26 @@ module Avo
|
|
|
48
40
|
resource: resource
|
|
49
41
|
)
|
|
50
42
|
end
|
|
43
|
+
|
|
44
|
+
# Returns the parent's association field once it is known to list `resource_class` and the user may view it.
|
|
45
|
+
def set_parent_from_via_params(association:, resource_class:)
|
|
46
|
+
parent_resource_class = Avo.resource_manager.get_resource(params[:via_resource_class])
|
|
47
|
+
raise ActiveRecord::RecordNotFound if parent_resource_class.nil?
|
|
48
|
+
|
|
49
|
+
@parent_record = parent_resource_class.find_record(params[:via_record_id], params: params)
|
|
50
|
+
@parent_resource = parent_resource_class.new(
|
|
51
|
+
record: @parent_record,
|
|
52
|
+
view: Avo::ViewInquirer.new("show")
|
|
53
|
+
)
|
|
54
|
+
@parent_resource.detect_fields
|
|
55
|
+
field = find_association_field(resource: @parent_resource, association: association)
|
|
56
|
+
# Only the panel fields (has_one, has_many, has_and_belongs_to_many, array) list records through the parent.
|
|
57
|
+
raise ActiveRecord::RecordNotFound unless field.is_a?(Avo::Fields::FrameBaseField)
|
|
58
|
+
|
|
59
|
+
authorize_via_association field, resource_class
|
|
60
|
+
|
|
61
|
+
field
|
|
62
|
+
end
|
|
51
63
|
end
|
|
52
64
|
end
|
|
53
65
|
end
|
|
@@ -41,11 +41,13 @@ module Avo::Concerns::RendersControls
|
|
|
41
41
|
|
|
42
42
|
def render_action(action)
|
|
43
43
|
return if !can_see_the_actions_button?
|
|
44
|
+
# Inside an association panel the action's blocks see the panel's parent, and its link carries it.
|
|
45
|
+
action.action.hydrate(parent_record: @parent_record, parent_resource: @parent_resource) if @parent_record.present?
|
|
44
46
|
return if !action.action.visible_in_view(parent_resource: @parent_resource)
|
|
45
47
|
|
|
46
48
|
tooltip = avo_tooltip_attributes(action.title)
|
|
47
49
|
|
|
48
|
-
a_link Avo::Services::URIService.parse(action.path).append_query(via_related_name_query).to_s,
|
|
50
|
+
a_link Avo::Services::URIService.parse(action.path).append_query(via_related_name_query.merge(action.action.parent_query)).to_s,
|
|
49
51
|
color: action.color,
|
|
50
52
|
style: action.style,
|
|
51
53
|
icon: action.icon,
|
data/lib/avo/configuration.rb
CHANGED
|
@@ -37,6 +37,10 @@ module Avo
|
|
|
37
37
|
# Field labels fall back to the model's attribute translations (activerecord.attributes / attributes).
|
|
38
38
|
attr_accessor :model_attribute_translations
|
|
39
39
|
attr_accessor :currency
|
|
40
|
+
# Default Luxon display formats for date, date_time, and time fields. A field's own `format:` wins.
|
|
41
|
+
attr_accessor :date_format
|
|
42
|
+
attr_accessor :date_time_format
|
|
43
|
+
attr_accessor :time_format
|
|
40
44
|
attr_accessor :default_view_type
|
|
41
45
|
attr_accessor :license_key
|
|
42
46
|
attr_accessor :authorization_methods
|
|
@@ -180,6 +184,9 @@ module Avo
|
|
|
180
184
|
@locale_selector = true
|
|
181
185
|
@model_attribute_translations = true
|
|
182
186
|
@currency = "USD"
|
|
187
|
+
@date_format = "yyyy-LL-dd"
|
|
188
|
+
@date_time_format = "yyyy-LL-dd TT"
|
|
189
|
+
@time_format = "TT"
|
|
183
190
|
@default_view_type = :table
|
|
184
191
|
@map_view = {}
|
|
185
192
|
@license_key = nil
|
|
@@ -12,6 +12,11 @@ module Avo
|
|
|
12
12
|
def resource_class(params)
|
|
13
13
|
use_resource || Avo.resource_manager.get_resource_by_name(@id.to_s)
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
# There's no Active Record association to reflect on, so the panel lists the resource named after the field.
|
|
17
|
+
def target_resource
|
|
18
|
+
resource_class(nil)
|
|
19
|
+
end
|
|
15
20
|
end
|
|
16
21
|
end
|
|
17
22
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Avo
|
|
2
|
+
module Fields
|
|
3
|
+
module Concerns
|
|
4
|
+
# The `key` option of the `file` and `files` fields: the blob key Active Storage stores an uploaded file under,
|
|
5
|
+
# instead of a random token. A string, or a block that sees the `record`, `resource`, `field` and `file`.
|
|
6
|
+
module HasStorageKey
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
attr_reader :key
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
# Direct uploads and Media Library files arrive as signed ids of blobs that are already stored, so they keep
|
|
16
|
+
# their key. Only a file uploaded through the form becomes the attachable hash that carries one.
|
|
17
|
+
def with_storage_key(file, record:)
|
|
18
|
+
return file if @key.nil? || !file.is_a?(ActionDispatch::Http::UploadedFile)
|
|
19
|
+
|
|
20
|
+
storage_key = Avo::ExecutionContext.new(target: @key, record:, resource: @resource, field: self, file:).handle.to_s
|
|
21
|
+
return file if storage_key.blank?
|
|
22
|
+
|
|
23
|
+
# Keys are unique and a replaced file's blob is purged after the new one is saved, so a re-upload of the same
|
|
24
|
+
# key would fail the save with the database's error. save_record stops on this field error instead.
|
|
25
|
+
taken = ActiveStorage::Blob.exists?(key: storage_key) || !storage_keys.add?(storage_key)
|
|
26
|
+
record.errors.add(id, :taken) if taken
|
|
27
|
+
|
|
28
|
+
{io: file.open, filename: file.original_filename, content_type: file.content_type, key: storage_key}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Keys given out during this fill, so two files of one upload can't share a key either
|
|
32
|
+
def storage_keys
|
|
33
|
+
@storage_keys ||= Set.new
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -12,7 +12,7 @@ module Avo
|
|
|
12
12
|
|
|
13
13
|
add_string_prop args, :first_day_of_week, 1
|
|
14
14
|
add_string_prop args, :picker_format, "Y-m-d"
|
|
15
|
-
add_string_prop args, :format,
|
|
15
|
+
add_string_prop args, :format, Avo.configuration.date_format
|
|
16
16
|
add_boolean_prop args, :disable_mobile
|
|
17
17
|
add_object_prop args, :picker_options
|
|
18
18
|
end
|
|
@@ -11,7 +11,7 @@ module Avo
|
|
|
11
11
|
|
|
12
12
|
add_boolean_prop args, :time_24hr
|
|
13
13
|
add_string_prop args, :picker_format, "Y-m-d H:i:S"
|
|
14
|
-
add_string_prop args, :format,
|
|
14
|
+
add_string_prop args, :format, Avo.configuration.date_time_format
|
|
15
15
|
add_string_prop args, :timezone
|
|
16
16
|
add_boolean_prop args, :relative, true
|
|
17
17
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module Avo
|
|
2
2
|
module Fields
|
|
3
3
|
class FileField < BaseField
|
|
4
|
+
include Avo::Fields::Concerns::HasStorageKey
|
|
5
|
+
|
|
4
6
|
attr_accessor :link_to_record
|
|
5
7
|
attr_accessor :is_avatar
|
|
6
8
|
attr_accessor :direct_upload
|
|
@@ -17,6 +19,7 @@ module Avo
|
|
|
17
19
|
@accept = args[:accept].present? ? args[:accept] : nil
|
|
18
20
|
@display_filename = args[:display_filename].nil? || args[:display_filename]
|
|
19
21
|
@lightbox = args[:lightbox].nil? || args[:lightbox]
|
|
22
|
+
@key = args[:key]
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
# Images open in an in-page lightbox on the Show view unless the field opts
|
|
@@ -38,6 +41,11 @@ module Avo
|
|
|
38
41
|
rails_blob_url value
|
|
39
42
|
end
|
|
40
43
|
|
|
44
|
+
# The storage key goes on last, so `update_using` still gets the uploaded file.
|
|
45
|
+
def apply_update_using(record, key, value, resource)
|
|
46
|
+
with_storage_key(super, record:)
|
|
47
|
+
end
|
|
48
|
+
|
|
41
49
|
def value
|
|
42
50
|
final_value = super
|
|
43
51
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module Avo
|
|
2
2
|
module Fields
|
|
3
3
|
class FilesField < BaseField
|
|
4
|
+
include Avo::Fields::Concerns::HasStorageKey
|
|
5
|
+
|
|
4
6
|
attr_accessor :direct_upload
|
|
5
7
|
attr_accessor :accept
|
|
6
8
|
attr_reader :display_filename
|
|
@@ -17,6 +19,7 @@ module Avo
|
|
|
17
19
|
@lightbox = args[:lightbox].nil? || args[:lightbox]
|
|
18
20
|
@view_type = args[:view_type] || :grid
|
|
19
21
|
@hide_view_type_switcher = args[:hide_view_type_switcher]
|
|
22
|
+
@key = args[:key]
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
# Images open in an in-page lightbox on the Show view unless the field opts
|
|
@@ -47,7 +50,7 @@ module Avo
|
|
|
47
50
|
|
|
48
51
|
# `attach` without its immediate save on a persisted record, so the files are saved with the record and a form
|
|
49
52
|
# that fails saves none. One assignment avoids an index_active_storage_attachments_uniqueness violation.
|
|
50
|
-
record.public_send(:"#{key}=", record.public_send(key).blobs + value.compact_blank)
|
|
53
|
+
record.public_send(:"#{key}=", record.public_send(key).blobs + value.compact_blank.map { |file| with_storage_key(file, record:) })
|
|
51
54
|
|
|
52
55
|
record
|
|
53
56
|
end
|
|
@@ -171,7 +171,7 @@ def handle(query:, fields:, **args)
|
|
|
171
171
|
end
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
**Picking an associated record.** A `belongs_to` field
|
|
174
|
+
**Picking an associated record.** A `belongs_to` field renders in the action modal wherever the action starts: **Show**, one or several rows on **Index**, or a standalone action with no record. On a single record it opens with that record's association preselected. Before `avo` 4.2.9 it rendered only with exactly one record, so older apps guard it with `visible: -> { resource.record.present? }` (drop the guard on 4.2.9+). For a value that isn't an association, use a plain input:
|
|
175
175
|
|
|
176
176
|
```ruby
|
|
177
177
|
# Short list — a select with the options loaded when the form renders.
|
|
@@ -261,7 +261,7 @@ When an index spans multiple pages, checking "Select all" offers to select **eve
|
|
|
261
261
|
|
|
262
262
|
- **`query` is an array** (a relation only on Select all across pages). Even a single-record action gets `[record]`; relation methods like `update_all`, `where` or `find_each` aren't available on it, so iterate, or use `Model.where(id: query.map(&:id))`. Use `query.first` for the one-record case; don't call record methods on `query` directly. `records` is an alias.
|
|
263
263
|
- **Records deleted after selection are omitted.** Another user may delete a checked record before the action request arrives. Avo drops that missing record and still passes every surviving selection to `handle`; action authors do not need to rescue `ActiveRecord::RecordNotFound` for this race. `query` can therefore come back **empty** when every selected record is gone — guard with `return error "No record selected" if query.blank?` if that matters.
|
|
264
|
-
- **"My action doesn't show up", or is refused, is usually the policy.** With Pundit, `act_on?` in the resource's policy gates the Actions dropdown and every run: Avo asks it of the record in the URL and of each selected record (of the model class when there are none, and for a "Select all" run), and one refusal refuses the whole run. An action started from an association panel shows under the parent's `act_on_<assoc>?`,
|
|
264
|
+
- **"My action doesn't show up", or is refused, is usually the policy.** With Pundit, `act_on?` in the resource's policy gates the Actions dropdown and every run: Avo asks it of the record in the URL and of each selected record (of the model class when there are none, and for a "Select all" run), and one refusal refuses the whole run. An action started from an association panel shows under the parent's `act_on_<assoc>?`, and from `avo` 4.4.4 its run asks the parent's `view_<assoc>?` and `act_on_<assoc>?` again; it still runs only on children whose own `act_on?` allows it. `authorize` on the action gates it further. Check the policy first. See the **`avo-authorization`** skill.
|
|
265
265
|
- **`view` is the view the action was started from.** In `authorize`, `visible`, the modal text blocks, `fields`, and `handle`, `view` (and `resource.view`) is `index`, `show`, or `edit` — the page the user opened the action from — both while the modal renders and while the action runs. It is never `new`; the modal is not a view. It arrives with the request and is checked against the route (`show` and `edit` need a record in the URL), so use it to adapt behavior (`reload_records if view.index?`), never as the only gate on who may run the action: gate people on `current_user`, and single-versus-bulk on `query.size` or `record`.
|
|
266
266
|
- **Every field in `fields` renders in the modal.** `hide_on`/`show_on` marks are for resource views and are ignored here. A field with a form component (text, select, hidden...) renders as an input; a display-only field (badge, key/value) renders read-only, as on Show. The one mark that counts: a badge declared with `show_on: :forms` renders as a select. The modal focuses its first input; a field with `autofocus: true` takes the focus instead (avo-fields lists the fields that support it). Use it to show context next to the inputs.
|
|
267
267
|
- **The modal is a NEW request.** Params from the Index/Show page that opened it are **not** available in `fields`/`handle`. To prefill from the triggering page, parse `request.referer`:
|
|
@@ -270,7 +270,8 @@ When an index spans multiple pages, checking "Select all" offers to select **eve
|
|
|
270
270
|
URI.parse(request.referer).query.to_s.include?("hey=ya") ? :yes : :no
|
|
271
271
|
}
|
|
272
272
|
```
|
|
273
|
-
-
|
|
273
|
+
- **A `belongs_to` field arrives in `handle` under its foreign key.** `field :user, as: :belongs_to` is `fields[:user_id]`; a polymorphic one arrives as `fields[:reviewable_type]` and `fields[:reviewable_id]` (4.2.7+). Both are the submitted strings, and an action does not check the type against the field's `types`, so validate it before constantizing. On `avo` older than 4.2.9 the field doesn't render in a bulk or standalone action: use `as: :select` or `as: :tags, mode: :select, fetch_values_from: "..."` and assign the ID yourself.
|
|
274
|
+
- **Actions also run from association panels (4.3.3+).** A `has_many` or `has_and_belongs_to_many` panel offers the actions declared on the *associated* resource, on the rows checked in the panel. `record` is `nil` while the dropdown renders (as on Index), so `name` and `arguments` blocks must handle that. From `avo` 4.4.4 the action reads the panel's parent as `parent_record` and `parent_resource` in `fields`, `handle` and every block, and keeps it through `navigate_to_action`; use it instead of passing the parent id in `arguments`. Both are `nil` outside a panel, so guard in an action that also runs on Index. Before 4.4.4 only `visible` got it, as `parent_resource.record`.
|
|
274
275
|
- **`reload_records` is Index-only.** It doesn't work on association tables — use `reload` there.
|
|
275
276
|
- **Notification bodies truncate at ~320 characters.** Keep `succeed`/`error` messages short; put long output in a `download` or a redirect.
|
|
276
277
|
- **File downloads need `self.turbo = false`.** Otherwise Turbo intercepts the response and the download won't fire.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: avo-admin-config
|
|
3
|
-
description: Configure Avo's app-wide admin settings in config/initializers/avo.rb via Avo.configure — app name, timezone/currency, per-page and index behavior, layout width, home redirect, open-in-editor links, and the other global knobs that don't belong to a single feature. Use when the user wants to change how many records per page, rename the admin / change the app name, set the timezone or currency for the admin, default the index to grid view, make the admin full-width, keep clicking a row from opening the record, skip the show view / go straight to edit, open Avo files in Cursor or VS Code from the UI, keep the sidebar always open, redirect the admin home to a dashboard, add a class to the body tag, make rows denser, widen the sidebar or turn off sidebar resizing, remove or retune the floating "Back to top" button, persist filters/pagination across requests, choose which map tiles the admin renders, or opt out of usage metadata.
|
|
3
|
+
description: Configure Avo's app-wide admin settings in config/initializers/avo.rb via Avo.configure — app name, timezone/currency, date and time display formats, per-page and index behavior, layout width, home redirect, open-in-editor links, and the other global knobs that don't belong to a single feature. Use when the user wants to change how many records per page, rename the admin / change the app name, set the timezone or currency for the admin, show every date as dd.mm.yyyy, default the index to grid view, make the admin full-width, keep clicking a row from opening the record, skip the show view / go straight to edit, open Avo files in Cursor or VS Code from the UI, keep the sidebar always open, redirect the admin home to a dashboard, add a class to the body tag, make rows denser, widen the sidebar or turn off sidebar resizing, remove or retune the floating "Back to top" button, persist filters/pagination across requests, choose which map tiles the admin renders, or opt out of usage metadata.
|
|
4
4
|
allowed-tools: Read, Edit, Write, Glob, Grep, Bash, WebFetch
|
|
5
5
|
metadata:
|
|
6
6
|
requires-gem: none — Community
|
|
@@ -59,6 +59,9 @@ config.app_name = -> { I18n.t "app_name" } # block form for dynamic/i18n na
|
|
|
59
59
|
config.timezone = "UTC" # for date/datetime fields
|
|
60
60
|
config.use_browser_timezone = false # render everyone in the app's configured zone instead; default true renders each visitor's own zone (cookie-detected, one soft reload + alert). Defaults to false in the test environment — the soft reload races browser specs
|
|
61
61
|
config.currency = "USD" # stored for your own code; no built-in field reads it (the Money field takes `currencies:`)
|
|
62
|
+
config.date_format = "dd.LL.yyyy" # Luxon display format for every `date` field on Index/Show (default "yyyy-LL-dd"); a field's own `format:` wins
|
|
63
|
+
config.date_time_format = "dd.LL.yyyy HH:mm" # same for `date_time` fields (default "yyyy-LL-dd TT")
|
|
64
|
+
config.time_format = "HH:mm" # same for `time` fields (default "TT"); `time` never reads date_time_format. Forms keep each field's flatpickr `picker_format`
|
|
62
65
|
config.locale = "en-US" # force Avo's UI locale (default: I18n.default_locale)
|
|
63
66
|
config.locale_selector = [:en, :ro] # profile-menu language picker, stored per user (default: true; false hides it)
|
|
64
67
|
config.model_attribute_translations = false # field labels stop falling back to the model's activerecord.attributes / attributes keys (default: true)
|
|
@@ -482,7 +482,7 @@ end
|
|
|
482
482
|
`Avo.plugin_manager` API:
|
|
483
483
|
|
|
484
484
|
- `register(name, priority: 10)` — add to the plugin list (lower priority runs earlier).
|
|
485
|
-
- `register_view_type(name, component:, icon:, active_icon:)` — a new index view type. **Pass `component:` as a string** (`"MyPlugin::ViewTypes::TimelineViewTypeComponent"`) to dodge boot load-order issues; the component inherits `Avo::ViewTypes::BaseViewTypeComponent` and must render `paginator_component
|
|
485
|
+
- `register_view_type(name, component:, icon:, active_icon:)` — a new index view type. **Pass `component:` as a string** (`"MyPlugin::ViewTypes::TimelineViewTypeComponent"`) to dodge boot load-order issues; the component inherits `Avo::ViewTypes::BaseViewTypeComponent` and must render `paginator_component` and keep its list inside `<turbo-frame id="<%= list_frame_id %>">`. Name the list's frame with `list_frame_id` (not the `turbo_frame` prop, which is the surrounding frame passed on to the paginator) and the selection data attributes (`data-resource-name`, `data-selected-resources-name`) with `resource_name_for(@resource)`, never `@resource.model_key` (4.3.4+): inside an association panel both use the association field's id, so two panels on one page don't collide. It only gets `collection`, `records` and `pagination` slots where its template calls `render_index_slot`, passing the default markup as the block for replacements. Enabling it on a resource is **avo-index-views** (`self.view_types` / `self.default_view_type`).
|
|
486
486
|
- `register_field(method_name, klass)` — ship a field *type* from a gem (the plugin-author side of **avo-custom-fields**).
|
|
487
487
|
- `register_menu_item(name, &block)` — a custom menu DSL method for `config.main_menu`. Delegates to `avo-menu`; **no-op when avo-menu isn't installed**, so register unconditionally.
|
|
488
488
|
- `register_configuration(name, klass)` — add a `config.<name>` namespace to `Avo::Configuration` backed by an instance of `klass`, so host apps configure the plugin from the same `config/initializers/avo.rb` they already use. **The one call that must not go in `avo_boot`** — see below.
|
|
@@ -520,6 +520,7 @@ Assets from library code go through `Avo.asset_manager` (not the app pipeline);
|
|
|
520
520
|
- **Custom tool vs. resource tool vs. new field.** Standalone page → custom tool. Widget on a record's Show/Edit → resource tool. A new *input type* used across resources → **avo-custom-fields** (not this).
|
|
521
521
|
- **Ejected files are frozen copies — you own them forever.** They stop receiving upstream updates; Avo bug/security fixes won't reach your copy. Prefer [view slots](#view-slots), CSS-variable / Tailwind-layer overrides and `--scope` (so you don't replace a component everywhere) before ejecting whole components.
|
|
522
522
|
- **A slot replacement that skips its default skips the nested hooks too.** Replacing `:header` without `default_content.call` also drops the title and controls and their hooks. Replacing `:collection` the same way drops `records` and `pagination`.
|
|
523
|
+
- **Live search refreshes `collection`, `records` and `pagination` slots, not `toolbar` ones.** Put a summary that must follow the search and page in a collection or records slot. On an empty index core renders the shared empty state with `collection` and `records` hooks only, no `pagination`. Map view's collection hooks wrap only its optional embedded table.
|
|
523
524
|
- **Index slots of a resource also fire on its has-many panels** on a parent's page. Return `nil` when `parent_record` is present if the content only belongs on the main index.
|
|
524
525
|
- **`controls` hooks run twice when `buttons_on_form_footers` is on**, once in the header and once in the footer, so a fixed HTML id can be duplicated.
|
|
525
526
|
- **The toolbar doesn't refresh on live search.** Put a summary that follows the search in a `collection`, `records` or `pagination` hook.
|
|
@@ -536,6 +537,7 @@ Assets from library code go through `Avo.asset_manager` (not the app pipeline);
|
|
|
536
537
|
- **`avo-overrides.css` is served as-is — NOT compiled by Tailwind.** `@apply` and utility classes won't be generated there; it's for raw CSS and CSS-variable overrides. Put Tailwind-using CSS under `app/assets/stylesheets/avo/`.
|
|
537
538
|
- **Tailwind integration silently stays off** unless `tailwindcss-ruby` is present, and — if you pull Tailwind via `tailwindcss-rails` — that gem is **>= 4.0** (on 3.x the integration is disabled even though `tailwindcss-ruby` is there). Symptom: your utility classes don't exist in the admin.
|
|
538
539
|
- **New JS/CSS not loading?** You skipped the asset-pipeline entrypoint. Run `avo:js:install` (or wire `avo.custom.js` manually) — `self.stimulus_controllers` alone loads nothing.
|
|
540
|
+
- **`avo_boot` must not load app classes.** It runs while the app initializes, and naming a controller, component or model there loads Action Controller, Action View or Active Record early (Rails 8.2 flags it). Extend Avo's `lib/` classes (resources, fields, managers) in the hook; extend controllers, components and helpers from `Rails.autoloaders.main.on_load("Avo::BaseController") { |klass, _| klass.prepend ... }`; extend models from `ActiveSupport.on_load(:active_record)`. It also re-runs on each code reload in development.
|
|
539
541
|
- **Plugin registration must be inside `ActiveSupport.on_load(:avo_boot)`** — with one exception: `register_configuration` runs **too late** there and must go in an engine initializer ordered `before: :load_config_initializers`. `register_view_type`'s `component:` should be a **string**, and `register_menu_item` is a no-op without `avo-menu`.
|
|
540
542
|
|
|
541
543
|
## Report
|
|
@@ -152,6 +152,7 @@ Every field accepts these common options (full list + types at the field-options
|
|
|
152
152
|
- **`autofocus:`** — puts the cursor in the field when the New/Edit form or an action modal opens: `autofocus: true`, or `autofocus: -> { view.new? }` for New only. In an action modal it replaces the default first-input focus; if several fields set it, the first one on the page wins. Honored by `text`, `textarea`, `number`, `password`, `select`, `status`, `boolean`, `code`, `easy_mde`, `area`, `external_image`, `file`, `files`, `progress_bar`, `country`, non-searchable `belongs_to` (a polymorphic one focuses its type select) and fields generated with `avo:field`; every other field ignores it. Only set it on one of those: in an action modal, a field that ignores it leaves nothing focused. A readonly/disabled field or one in a tab that isn't open can't take focus. It is also ignored in nested association forms, in reactive (`react_on`) re-renders, and in the action card of an Avo AI chat, which keep focus where the surrounding form or chat composer put it.
|
|
153
153
|
- **`sortable:`** — makes the Index column sortable. `true` for real columns; a `-> { query.order(...) }` lambda (receives `query` and `direction`) for computed fields.
|
|
154
154
|
- **Number `format:`** — formats `:number` fields on Index and Show with `:delimited`, `:percentage`, or `:human`; forms keep the raw number. A formatted number is end-aligned in tables, while a bare number stays start-aligned for identifier/year-shaped values. Rails i18n controls delimiters and separators. For money use the `:money` field, and for anything else `format_display_using:`.
|
|
155
|
+
- **Date and time `format:`** - Luxon tokens for `:date`, `:date_time` and `:time` on Index and Show: `field :starts_at, as: :date_time, format: "dd LLL yyyy HH:mm"`. To change every field at once, set `config.date_format`, `config.date_time_format` or `config.time_format` in the initializer (see the avo-admin-config skill); a field's own `format:` wins. New and Edit use `picker_format` with flatpickr tokens, which the config options don't touch.
|
|
155
156
|
- **`format_using:`** — reshape the displayed value. **Runs on form views too**, so branch on the view when the form should stay editable: `format_using: -> { view.form? ? value : value.upcase }`. View-scoped variants exist (`format_display_using`, `format_index_using`, `format_show_using`, `format_form_using`, …) — the most specific one wins, they don't chain. Rails view helpers are callable directly inside the block — `-> { number_to_currency(value) }`, no `view_context` receiver.
|
|
156
157
|
- **`update_using:`** — parse the raw form `value` before it's saved.
|
|
157
158
|
- **`nullable:`** / **`null_values:`** — store empty input as `NULL` (optionally define which values count as null).
|
|
@@ -159,6 +160,7 @@ Every field accepts these common options (full list + types at the field-options
|
|
|
159
160
|
- **`always_show:`** — editor fields only (`trix`, `rhino`, `lexxy`, `markdown`, `easy_mde`, `tip_tap`, `code`). `true` renders the full value on Show instead of the collapsed preview. Defaults to `false`.
|
|
160
161
|
- **`link_to_record:`** — make the Index cell a link to the record. Only on `:id`, `:text`, `:number`, `:date`, `:date_time`, `:time`, `:gravatar`, `:file`, `:external_image`, and `belongs_to`.
|
|
161
162
|
- **`lightbox:`** — `:file` and `:files` only. On Show, images open in an in-page lightbox (prev/next, arrow keys, Escape, a link to the original) by default; `lightbox: false` renders the plain image. Non-image files are unaffected.
|
|
163
|
+
- **`key:`** - `:file` and `:files` only. The Active Storage blob key a file uploaded through the form is stored under, instead of a random token: a string, or a block with `record`, `resource`, `field` and the uploaded `file`, run once per file. A blank result keeps the random key. Keys are unique: a taken key, a re-upload of the same name included, shows "has already been taken" on the field and saves nothing, so add a random segment (`"posts/#{SecureRandom.base36(8)}/#{file.original_filename}"`). `record.to_param` is nil on New. Direct uploads and Media Library picks keep their key.
|
|
162
164
|
- **`for_attribute:`** — back the field with a different attribute than its id (lets you show one column two ways).
|
|
163
165
|
- **`width:`** / **`stacked:`** — column width (`25/33/50/66/75/100`; any value <100 auto-stacks) and label-above-value layout. `stacked:` on the field wins everywhere, so `stacked: false` opts out of the auto-stacking and of sidebars/preview stacking too.
|
|
164
166
|
- **`html:`** — attach `style`/`classes`/`data` to the field's wrapper/label/input per view (e.g. allow wrapping on Index: `html: {index: {wrapper: {classes: "whitespace-normal"}}}`). See the html page.
|
|
@@ -159,6 +159,7 @@ The same filter class can be registered on many resources. To vary behavior per
|
|
|
159
159
|
|
|
160
160
|
- **Default state:** define `default` returning the same shape `apply` expects (`:published`, `{is_featured: true}`, `["a", "b"]`).
|
|
161
161
|
- **Dynamic options:** `options` is plain Ruby — query the DB or an API.
|
|
162
|
+
- **Grouped options:** on select and multiple select filters, a Hash in place of a label is a group — `{"Europe" => {fr: "France", de: "Germany"}}` lists France and Germany under an `<optgroup>` labeled "Europe". `apply` still receives the option ids (`"fr"`). This is not the select field's `grouped_options` format, which lists the label first; flip each pair to reuse a field's list.
|
|
162
163
|
- **Conditional visibility:** `self.visible = -> { current_user.admin? }`.
|
|
163
164
|
- **Filters that depend on each other:** read `applied_filters` in `options`, or override `react` to change a filter's own value when another changes.
|
|
164
165
|
- **Link to a pre-filtered view:** `Avo::Filters::BaseFilter.encode_filters({"Avo::Filters::Name" => "Apple"})` → pass as `encoded_filters:`.
|
|
@@ -233,7 +233,7 @@ Make it the default with `self.default_view_type = :map`.
|
|
|
233
233
|
|
|
234
234
|
Not a view type — a table affordance. Checking the header "Select all" checkbox and confirming "select all matching" lets an action run on **every record the current query matches**, across all pages, not just the visible page. Avo serializes (and encrypts) the whole query — filters, sorting, scopes — and reconstructs it inside the action.
|
|
235
235
|
|
|
236
|
-
It works out of the box on the table view; nothing to enable on the resource. The action itself is where the selection is consumed — cross-link the **avo-actions** skill for writing/handling the action. If serialization fails, Avo silently disables select-all rather than crashing (see the `normalizes` gotcha below).
|
|
236
|
+
It works out of the box on the table view and, from `avo` 4.3.10, on the grid view (a bar above the cards with the page checkbox, "Select all matching" and Undo); nothing to enable on the resource. A resource that sets `self.record_selector` to hide checkboxes renders no bar. The action itself is where the selection is consumed — cross-link the **avo-actions** skill for writing/handling the action. If serialization fails, Avo silently disables select-all rather than crashing (see the `normalizes` gotcha below).
|
|
237
237
|
|
|
238
238
|
**Coming back to the index (4.3.1+):** going Back (browser Back or the record page's **Go back** link) re-checks the rows that were selected and restores scroll. The selection is kept per browser tab and per URL (filters, sort, page), is forgotten after running an action or on reload, and a "Select all matching" choice is not kept. With `config.persistence = { driver: :session }` (4.3.11+) the selection is kept per page rather than per URL and comes back however you reach the index; turn it off with `selection: false`. System specs that expect nothing selected after **Go back** will now find rows checked.
|
|
239
239
|
|
|
@@ -254,7 +254,7 @@ class Avo::Resources::Project < Avo::BaseResource
|
|
|
254
254
|
end
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
-
`cards` means the resource's dashboard cards, not grid items. Blocks run once per region, not per row: use `row_options` to change rows.
|
|
257
|
+
`cards` means the resource's dashboard cards, not grid items. Collection, records and pagination slots refresh with live search; toolbar, cards and header ones don't. Blocks run once per region, not per row: use `row_options` to change rows.
|
|
258
258
|
|
|
259
259
|
The **avo-custom-ui** skill's **View slots** section has the full reference, Show/Edit/New, block context and gotchas.
|
|
260
260
|
|
|
@@ -66,7 +66,7 @@ grep -n "avo" Gemfile
|
|
|
66
66
|
bin/rails avo:update # or: bundle exec rails avo:update
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
The task resolves Avo core plus every registered Avo plugin to its real gem name and runs `bundle update --conservative <those gems>` — `--conservative` so it doesn't drag unrelated shared dependencies along. Read its output: it echoes the exact `bundle update` command it ran.
|
|
69
|
+
The task resolves Avo core plus every registered Avo plugin to its real gem name and runs `bundle update --conservative <those gems>` — `--conservative` so it doesn't drag unrelated shared dependencies along. Read its output: it echoes the exact `bundle update` command it ran. From `avo` 4.3.10, `AVO_UPDATE_PUSH=1 bin/rails avo:update` also commits `Gemfile.lock` (message `Update Avo gems`) and pushes to the branch's upstream, for scheduled jobs and agents. It refuses to start outside a Git repo, with uncommitted changes to tracked files, or on a branch with no upstream; run it on a branch you're happy to push to, not the deploy branch.
|
|
70
70
|
|
|
71
71
|
If the task isn't available (older Avo, or the app won't boot), fall back to naming the gems yourself:
|
|
72
72
|
|
|
@@ -147,7 +147,7 @@ Check the project's own instructions for how — in this order: `AGENTS.md`, `CL
|
|
|
147
147
|
| Command | Does |
|
|
148
148
|
| --- | --- |
|
|
149
149
|
| `grep -E "^ {4}avo(-[a-z_]+)? \(" Gemfile.lock` | Current version of every Avo gem — run **before** updating |
|
|
150
|
-
| `bin/rails avo:update` | `bundle update --conservative` across Avo core + every registered plugin |
|
|
150
|
+
| `bin/rails avo:update` | `bundle update --conservative` across Avo core + every registered plugin (`AVO_UPDATE_PUSH=1` also commits and pushes the lockfile) |
|
|
151
151
|
| `git diff Gemfile.lock \| grep -E "^[-+] {4}avo"` | The actual before → after jump per gem |
|
|
152
152
|
| `bundle update --conservative avo …` | Manual fallback when the rake task isn't available |
|
|
153
153
|
| `bundle outdated \| grep avo` | What's available above the current Gemfile constraints |
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"repo": "avo-hq/docs.avohq.io",
|
|
3
3
|
"docs_path": "docs/4.0",
|
|
4
|
-
"commit": "
|
|
5
|
-
"date": "2026-11-
|
|
4
|
+
"commit": "52cd4fe38a73692266edd911dc22c432eea8af73",
|
|
5
|
+
"date": "2026-11-10",
|
|
6
6
|
"note": "The docs commit these skills were last indexed from. Run ruby lib/avo/skills/bin/docs_drift.rb to see what changed since, and --update after a refresh."
|
|
7
7
|
}
|
data/lib/avo/version.rb
CHANGED
|
@@ -176,6 +176,10 @@ Avo.configure do |config|
|
|
|
176
176
|
# config.timezone = 'UTC'
|
|
177
177
|
# config.use_browser_timezone = true # set false to render dates/times in the app's configured zone for everyone; off automatically in the test environment
|
|
178
178
|
# config.currency = 'USD'
|
|
179
|
+
# Default display formats (Luxon tokens) for date, date_time, and time fields. A field's own `format:` wins.
|
|
180
|
+
# config.date_format = 'yyyy-LL-dd'
|
|
181
|
+
# config.date_time_format = 'yyyy-LL-dd TT'
|
|
182
|
+
# config.time_format = 'TT'
|
|
179
183
|
# config.hide_layout_when_printing = false
|
|
180
184
|
# config.container_width = :lg # :full, :lg, :md, or :sm. Hash for per-view: { index: :full, single: :md }
|
|
181
185
|
# config.use_stacked_fields = false
|
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: 4.4.
|
|
4
|
+
version: 4.4.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adrian Marin
|
|
@@ -967,7 +967,6 @@ files:
|
|
|
967
967
|
- config/i18n-tasks.yml
|
|
968
968
|
- config/importmap.rb
|
|
969
969
|
- config/initializers/avo_icons.rb
|
|
970
|
-
- config/initializers/pagy.rb
|
|
971
970
|
- config/routes.rb
|
|
972
971
|
- config/routes/dynamic_routes.rb
|
|
973
972
|
- config/spring.rb
|
|
@@ -1045,6 +1044,7 @@ files:
|
|
|
1045
1044
|
- lib/avo/fields/concerns/has_field_name.rb
|
|
1046
1045
|
- lib/avo/fields/concerns/has_html_attributes.rb
|
|
1047
1046
|
- lib/avo/fields/concerns/has_resizable_editor.rb
|
|
1047
|
+
- lib/avo/fields/concerns/has_storage_key.rb
|
|
1048
1048
|
- lib/avo/fields/concerns/is_disabled.rb
|
|
1049
1049
|
- lib/avo/fields/concerns/is_readonly.rb
|
|
1050
1050
|
- lib/avo/fields/concerns/is_required.rb
|
|
@@ -1247,8 +1247,6 @@ files:
|
|
|
1247
1247
|
- lib/generators/avo/templates/locales/avo.ua.yml
|
|
1248
1248
|
- lib/generators/avo/templates/locales/avo.zh-TW.yml
|
|
1249
1249
|
- lib/generators/avo/templates/locales/avo.zh.yml
|
|
1250
|
-
- lib/generators/avo/templates/locales/pagy/nn.yml
|
|
1251
|
-
- lib/generators/avo/templates/locales/pagy/ro.yml
|
|
1252
1250
|
- lib/generators/avo/templates/resource/controller.tt
|
|
1253
1251
|
- lib/generators/avo/templates/resource/resource.tt
|
|
1254
1252
|
- lib/generators/avo/templates/resource_tools/partial.tt
|
data/config/initializers/pagy.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
nn:
|
|
2
|
-
pagy:
|
|
3
|
-
item_name:
|
|
4
|
-
one: "resultat"
|
|
5
|
-
other: "resultat"
|
|
6
|
-
nav:
|
|
7
|
-
prev: "‹ Førre"
|
|
8
|
-
next: "Neste ›"
|
|
9
|
-
gap: "…"
|
|
10
|
-
info:
|
|
11
|
-
no_items: "Ingen %{item_name} funne"
|
|
12
|
-
single_page: "Viser <b>%{count}</b> %{item_name}"
|
|
13
|
-
multiple_pages: "Viser %{item_name} <b>%{from}-%{to}</b> av totalt <b>%{count}</b>"
|
|
14
|
-
combo_nav_js: "<label>Side %{page_input} av %{pages}</label>"
|
|
15
|
-
items_selector_js: "<label>Vis %{items_input} %{item_name} per side</label>"
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
|
|
2
|
-
|
|
3
|
-
ro:
|
|
4
|
-
pagy:
|
|
5
|
-
item_name:
|
|
6
|
-
one: "un record"
|
|
7
|
-
other: "recorduri"
|
|
8
|
-
nav:
|
|
9
|
-
prev: "‹ Înapoi"
|
|
10
|
-
next: "Înainte ›"
|
|
11
|
-
gap: "…"
|
|
12
|
-
info:
|
|
13
|
-
no_items: "Nici %{item_name} găsit"
|
|
14
|
-
single_page: "<b>%{count}</b> %{item_name}"
|
|
15
|
-
multiple_pages: "<b>%{from}-%{to}</b> din totalul de <b>%{count}</b>"
|
|
16
|
-
combo_nav_js: "<label>Pagina %{page_input} din %{pages}</label>"
|
|
17
|
-
items_selector_js: "<label>Show %{items_input} %{item_name} per page</label>"
|