avo 3.0.1.beta6 → 3.0.1.beta8
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 +2 -2
- data/Gemfile.lock +23 -25
- data/{public/avo-assets/avo.css → app/assets/builds/avo.base.css} +2094 -1468
- data/app/assets/builds/avo.base.js +124556 -0
- data/app/assets/builds/avo.base.js.map +7 -0
- data/app/assets/builds/avo.custom.js +6 -0
- data/app/assets/builds/avo.custom.js.map +7 -0
- data/app/assets/stylesheets/avo.base.css +1 -0
- data/app/assets/stylesheets/css/fields/tags.css +32 -0
- data/app/components/avo/actions_component.rb +1 -1
- data/app/components/avo/field_wrapper_component.rb +1 -7
- data/app/components/avo/fields/common/badge_viewer_component.html.erb +1 -0
- data/app/components/avo/fields/common/key_value_component.html.erb +2 -2
- data/app/components/avo/fields/common/key_value_component.rb +2 -2
- data/app/components/avo/fields/common/progress_bar_component.rb +3 -9
- data/app/components/avo/fields/edit_component.rb +1 -1
- data/app/components/avo/fields/index_component.rb +1 -1
- data/app/components/avo/fields/show_component.rb +1 -1
- data/app/components/avo/index/field_wrapper_component.rb +1 -1
- data/app/components/avo/index/resource_controls_component.rb +1 -1
- data/app/components/avo/index/resource_table_component.rb +6 -6
- data/app/components/avo/resource_component.rb +9 -4
- data/app/components/avo/sidebar_profile_component.html.erb +4 -4
- data/app/components/avo/tab_group_component.html.erb +1 -1
- data/app/components/avo/tab_switcher_component.rb +2 -2
- data/app/components/avo/views/resource_edit_component.rb +5 -5
- data/app/components/avo/views/resource_index_component.rb +1 -1
- data/app/components/avo/views/resource_show_component.rb +1 -1
- data/app/controllers/avo/actions_controller.rb +1 -1
- data/app/controllers/avo/application_controller.rb +5 -5
- data/app/controllers/avo/base_controller.rb +1 -1
- data/app/controllers/avo/search_controller.rb +17 -0
- data/app/controllers/concerns/avo/initializes_avo.rb +1 -0
- data/app/helpers/avo/url_helpers.rb +1 -1
- data/app/views/avo/actions/show.html.erb +1 -1
- data/config/routes.rb +4 -3
- data/db/factories.rb +1 -1
- data/lib/avo/base_action.rb +2 -2
- data/lib/avo/base_resource.rb +6 -5
- data/lib/avo/concerns/has_helpers.rb +18 -0
- data/lib/avo/concerns/has_items.rb +1 -1
- data/lib/avo/concerns/visible_in_different_views.rb +7 -1
- data/lib/avo/concerns/visible_items.rb +43 -0
- data/lib/avo/configuration.rb +8 -2
- data/lib/avo/current.rb +1 -0
- data/lib/avo/execution_context.rb +4 -1
- data/lib/avo/fields/badge_field.rb +1 -1
- data/lib/avo/fields/base_field.rb +9 -36
- data/lib/avo/fields/belongs_to_field.rb +1 -1
- data/lib/avo/fields/concerns/has_html_attributes.rb +2 -0
- data/lib/avo/fields/concerns/use_view_components.rb +45 -0
- data/lib/avo/fields/has_base_field.rb +2 -2
- data/lib/avo/resources/items/item_group.rb +2 -2
- data/lib/avo/resources/items/row.rb +3 -3
- data/lib/avo/resources/items/sidebar.rb +1 -1
- data/lib/avo/resources/items/tab.rb +2 -2
- data/lib/avo/resources/items/tab_group.rb +1 -1
- data/lib/avo/resources/resource_manager.rb +6 -1
- data/lib/avo/version.rb +1 -1
- data/lib/avo/view_inquirer.rb +36 -0
- data/lib/avo.rb +9 -0
- data/lib/generators/avo/eject_generator.rb +93 -16
- data/lib/generators/avo/resource_generator.rb +5 -5
- data/lib/generators/avo/templates/initializer/avo.tt +5 -0
- data/public/avo-assets/avo.base.css +50 -210
- metadata +12 -6
- data/config/master.key +0 -1
- data/public/avo-assets/avo.js +0 -513
- data/public/avo-assets/avo.js.map +0 -7
@@ -7,19 +7,13 @@ class Avo::Fields::Common::ProgressBarComponent < ViewComponent::Base
|
|
7
7
|
attr_reader :max
|
8
8
|
attr_reader :view
|
9
9
|
|
10
|
-
def initialize(value:, display_value: false, value_suffix: nil, max: 100, view:
|
10
|
+
def initialize(value:, display_value: false, value_suffix: nil, max: 100, view: "index")
|
11
11
|
@value = value
|
12
12
|
@display_value = display_value
|
13
13
|
@value_suffix = value_suffix
|
14
14
|
@max = max
|
15
|
-
@view = view
|
15
|
+
@view = Avo::ViewInquirer.new(view)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
view == :show
|
20
|
-
end
|
21
|
-
|
22
|
-
def index?
|
23
|
-
view == :index
|
24
|
-
end
|
18
|
+
delegate :show?, :index?, to: :view
|
25
19
|
end
|
@@ -23,7 +23,7 @@ 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
|
26
|
+
return false if Avo.configuration.resource_default_view.edit?
|
27
27
|
|
28
28
|
return authorize_association_for(:show) if @reflection.present?
|
29
29
|
|
@@ -17,14 +17,14 @@ class Avo::Index::ResourceTableComponent < ViewComponent::Base
|
|
17
17
|
|
18
18
|
def encrypted_query
|
19
19
|
# TODO: move this to the resource where we can apply the adapter pattern
|
20
|
-
|
21
|
-
query.
|
22
|
-
else
|
23
|
-
return :select_all_disabled if query.nil? || !query.respond_to?(:all) || !query.all.respond_to?(:to_sql)
|
24
|
-
|
25
|
-
query.all.to_sql
|
20
|
+
if Module.const_defined?("Ransack::Search") && query.instance_of?(Ransack::Search)
|
21
|
+
@query = query.result
|
26
22
|
end
|
27
23
|
|
24
|
+
return :select_all_disabled if query.nil? || !query.respond_to?(:all) || !query.all.respond_to?(:to_sql)
|
25
|
+
|
26
|
+
serialized_query = query.all.to_sql
|
27
|
+
|
28
28
|
return if serialized_query.nil?
|
29
29
|
|
30
30
|
Avo::Services::EncryptionService.encrypt(
|
@@ -53,11 +53,16 @@ class Avo::ResourceComponent < Avo::BaseComponent
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def destroy_path
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
args = {record: @resource.record, resource: @resource}
|
57
|
+
|
58
|
+
args[:referrer] = if params[:via_resource_class].present?
|
59
|
+
back_path
|
60
|
+
# If we're deleting a resource from a parent resource, we need to go back to the parent resource page after the deletion
|
61
|
+
elsif @parent_resource.present?
|
62
|
+
helpers.resource_path(record: @parent_record, resource: @parent_resource)
|
60
63
|
end
|
64
|
+
|
65
|
+
helpers.resource_path(**args)
|
61
66
|
end
|
62
67
|
|
63
68
|
# Ex: A Post has many Comments
|
@@ -1,12 +1,12 @@
|
|
1
1
|
<div class="text-black border-gray-150 p-4 flex border-t">
|
2
|
-
<div class="flex-1 flex space-x-4">
|
2
|
+
<div class="flex-1 flex space-x-4 w-full">
|
3
3
|
<% if avatar.present? %>
|
4
|
-
<div class="relative aspect-square w-10 h-10 overflow-hidden rounded">
|
4
|
+
<div class="relative aspect-square w-10 h-10 overflow-hidden rounded shrink-0">
|
5
5
|
<%= image_tag avatar, class: "object-cover min-w-full min-h-full h-full" %>
|
6
6
|
</div>
|
7
7
|
<% end %>
|
8
|
-
<div class="flex flex-col">
|
9
|
-
<div class="font-medium">
|
8
|
+
<div class="flex flex-col pr-3 min-w-0">
|
9
|
+
<div class="font-medium text-ellipsis overflow-hidden">
|
10
10
|
<%= name %>
|
11
11
|
</div>
|
12
12
|
<% if title.present? %>
|
@@ -25,7 +25,7 @@
|
|
25
25
|
# On edit screens we want to load each tab because we wnst the DOM to have the fields present on form submission.
|
26
26
|
# If you have a field which is in the second tab and it's required, the form submission will fail because the required field is not in view, and we don't want that.
|
27
27
|
# We also want to load the current tab
|
28
|
-
should_lazy_load = if @view.
|
28
|
+
should_lazy_load = if @view.in?(%w[edit new update create])
|
29
29
|
false
|
30
30
|
else
|
31
31
|
!is_current_tab
|
@@ -33,11 +33,11 @@ class Avo::TabSwitcherComponent < Avo::BaseComponent
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def is_edit?
|
36
|
-
@view.in?([
|
36
|
+
@view.in?(%w[edit update])
|
37
37
|
end
|
38
38
|
|
39
39
|
def is_new?
|
40
|
-
@view.in?([
|
40
|
+
@view.in?(%w[new create])
|
41
41
|
end
|
42
42
|
|
43
43
|
def is_initial_load?
|
@@ -3,11 +3,11 @@
|
|
3
3
|
class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
|
4
4
|
include Avo::ApplicationHelper
|
5
5
|
|
6
|
-
def initialize(resource: nil, record: nil, actions: [], view:
|
6
|
+
def initialize(resource: nil, record: nil, actions: [], view: "edit")
|
7
7
|
@resource = resource
|
8
8
|
@record = record
|
9
9
|
@actions = actions
|
10
|
-
@view = view
|
10
|
+
@view = Avo::ViewInquirer.new(view)
|
11
11
|
end
|
12
12
|
|
13
13
|
def title
|
@@ -18,7 +18,7 @@ class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
|
|
18
18
|
return resource_view_path if via_resource?
|
19
19
|
return resources_path if via_index?
|
20
20
|
|
21
|
-
if is_edit? && Avo.configuration.resource_default_view
|
21
|
+
if is_edit? && Avo.configuration.resource_default_view.show? # via resource show or edit page
|
22
22
|
return helpers.resource_path(record: @resource.record, resource: @resource)
|
23
23
|
end
|
24
24
|
|
@@ -34,7 +34,7 @@ class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def can_see_the_destroy_button?
|
37
|
-
return super if is_edit? && Avo.configuration.resource_default_view
|
37
|
+
return super if is_edit? && Avo.configuration.resource_default_view.edit?
|
38
38
|
|
39
39
|
false
|
40
40
|
end
|
@@ -52,7 +52,7 @@ class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def is_edit?
|
55
|
-
view.in?([
|
55
|
+
view.in?(%w[edit update])
|
56
56
|
end
|
57
57
|
|
58
58
|
def form_method
|
@@ -34,7 +34,7 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
34
34
|
@parent_record = parent_record
|
35
35
|
@parent_resource = parent_resource
|
36
36
|
@applied_filters = applied_filters
|
37
|
-
@view =
|
37
|
+
@view = Avo::ViewInquirer.new("index")
|
38
38
|
@query = query
|
39
39
|
@scopes = scopes
|
40
40
|
end
|
@@ -13,7 +13,7 @@ module Avo
|
|
13
13
|
|
14
14
|
def show
|
15
15
|
# Se the view to :new so the default value gets prefilled
|
16
|
-
@view =
|
16
|
+
@view = Avo::ViewInquirer.new("new")
|
17
17
|
|
18
18
|
@resource.hydrate(record: @record, view: @view, user: _current_user, params: params)
|
19
19
|
@record = ActionModel.new @action.get_attributes_for_action
|
@@ -115,7 +115,7 @@ module Avo
|
|
115
115
|
def set_resource
|
116
116
|
raise ActionController::RoutingError.new "No route matches" if resource.nil?
|
117
117
|
|
118
|
-
@resource = resource.new(view: action_name.
|
118
|
+
@resource = resource.new(view: action_name.to_s, user: _current_user, params: params)
|
119
119
|
|
120
120
|
set_authorization
|
121
121
|
end
|
@@ -149,12 +149,12 @@ module Avo
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def set_view
|
152
|
-
@view = action_name.
|
152
|
+
@view = Avo::ViewInquirer.new(action_name.to_s)
|
153
153
|
end
|
154
154
|
|
155
155
|
def set_record_to_fill
|
156
|
-
@record_to_fill = @resource.model_class.new if @view
|
157
|
-
@record_to_fill = @record if @view
|
156
|
+
@record_to_fill = @resource.model_class.new if @view.create?
|
157
|
+
@record_to_fill = @record if @view.update?
|
158
158
|
|
159
159
|
# If resource.record is nil, most likely the user is creating a new record.
|
160
160
|
# In that case, to access resource.record in visible and readonly blocks we hydrate the resource with a new record.
|
@@ -167,7 +167,7 @@ module Avo
|
|
167
167
|
return if is_attach_action?
|
168
168
|
|
169
169
|
@record = @resource.fill_record(@record_to_fill, cast_nullable(model_params), extra_params: extra_params)
|
170
|
-
assign_default_value_to_disabled_fields if @view
|
170
|
+
assign_default_value_to_disabled_fields if @view.create?
|
171
171
|
end
|
172
172
|
|
173
173
|
def is_attach_action?
|
@@ -529,7 +529,7 @@ module Avo
|
|
529
529
|
|
530
530
|
if @resource.class.send(action) == :index
|
531
531
|
resources_path(resource: @resource)
|
532
|
-
elsif @resource.class.send(action) == :edit || Avo.configuration.resource_default_view
|
532
|
+
elsif @resource.class.send(action) == :edit || Avo.configuration.resource_default_view.edit?
|
533
533
|
edit_resource_path(resource: @resource, record: @resource.record)
|
534
534
|
else
|
535
535
|
resource_path(record: @record, resource: @resource)
|
@@ -9,6 +9,8 @@ module Avo
|
|
9
9
|
|
10
10
|
def show
|
11
11
|
render json: search_resources([resource])
|
12
|
+
rescue => error
|
13
|
+
render_search_error(error)
|
12
14
|
end
|
13
15
|
|
14
16
|
private
|
@@ -164,5 +166,20 @@ module Avo
|
|
164
166
|
parent_resource = Avo.resource_manager.get_resource_by_model_class params[:via_reflection_class]
|
165
167
|
parent_resource.find_record params[:via_reflection_id], params: params
|
166
168
|
end
|
169
|
+
|
170
|
+
def render_search_error(error)
|
171
|
+
raise error unless Rails.env.development?
|
172
|
+
|
173
|
+
render json: {
|
174
|
+
error: {
|
175
|
+
header: "🚨 An error occurred while searching. 🚨",
|
176
|
+
help: "Please see the error and fix it before deploying.",
|
177
|
+
results: {
|
178
|
+
_label: error.message
|
179
|
+
},
|
180
|
+
count: 1
|
181
|
+
}
|
182
|
+
}, status: 500
|
183
|
+
end
|
167
184
|
end
|
168
185
|
end
|
@@ -21,7 +21,7 @@
|
|
21
21
|
<%= @action.get_message %>
|
22
22
|
</div>
|
23
23
|
<%= hidden_field_tag :action_id, @action.param_id %>
|
24
|
-
<%= form.hidden_field :avo_resource_ids, value: params[:resource_ids], 'data-action-target': 'resourceIds' %>
|
24
|
+
<%= form.hidden_field :avo_resource_ids, value: params[:id] || params[:resource_ids], 'data-action-target': 'resourceIds' %>
|
25
25
|
<%= form.hidden_field :avo_selected_query, 'data-action-target': 'selectedAllQuery' %>
|
26
26
|
<%= form.hidden_field :arguments, value: params[:arguments] %>
|
27
27
|
<% if @action.get_fields.present? %>
|
data/config/routes.rb
CHANGED
@@ -4,9 +4,10 @@ Avo::Engine.routes.draw do
|
|
4
4
|
get "resources", to: redirect(Avo.configuration.root_path)
|
5
5
|
get "dashboards", to: redirect(Avo.configuration.root_path)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# Mount Avo engines routes by default but leave it configurable in case the user wants to nest these under a scope.
|
8
|
+
if Avo.configuration.mount_avo_engines
|
9
|
+
instance_exec(&Avo.mount_engines)
|
10
|
+
end
|
10
11
|
|
11
12
|
post "/rails/active_storage/direct_uploads", to: "/active_storage/direct_uploads#create"
|
12
13
|
|
data/db/factories.rb
CHANGED
@@ -38,7 +38,7 @@ FactoryBot.define do
|
|
38
38
|
factory :project do
|
39
39
|
name { Faker::App.name }
|
40
40
|
status { ['closed', :rejected, :failed, 'loading', :running, :waiting].sample }
|
41
|
-
stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled"].sample }
|
41
|
+
stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled", "Drafting"].sample }
|
42
42
|
budget { Faker::Number.decimal(l_digits: 4) }
|
43
43
|
country { Faker::Address.country_code }
|
44
44
|
description { Faker::Markdown.sandwich(sentences: 5) }
|
data/lib/avo/base_action.rb
CHANGED
@@ -65,7 +65,7 @@ module Avo
|
|
65
65
|
self.class.record = record
|
66
66
|
self.class.resource = resource
|
67
67
|
self.class.user = user
|
68
|
-
self.class.view = view
|
68
|
+
self.class.view = Avo::ViewInquirer.new(view)
|
69
69
|
@arguments = arguments
|
70
70
|
|
71
71
|
self.class.message ||= I18n.t("avo.are_you_sure_you_want_to_run_this_option")
|
@@ -141,7 +141,7 @@ module Avo
|
|
141
141
|
def visible_in_view(parent_resource: nil)
|
142
142
|
if visible.blank?
|
143
143
|
# Hide on the :new view by default
|
144
|
-
return false if view
|
144
|
+
return false if view.new?
|
145
145
|
|
146
146
|
# Show on all other views
|
147
147
|
return true
|
data/lib/avo/base_resource.rb
CHANGED
@@ -9,6 +9,7 @@ module Avo
|
|
9
9
|
include Avo::Concerns::HasStimulusControllers
|
10
10
|
include Avo::Concerns::ModelClassConstantized
|
11
11
|
include Avo::Concerns::HasDescription
|
12
|
+
include Avo::Concerns::HasHelpers
|
12
13
|
|
13
14
|
# Avo::Current methods
|
14
15
|
delegate :context, to: Avo::Current
|
@@ -233,14 +234,14 @@ module Avo
|
|
233
234
|
delegate :model_key, to: :class
|
234
235
|
|
235
236
|
def initialize(record: nil, view: nil, user: nil, params: nil)
|
236
|
-
@view = view if view.present?
|
237
|
+
@view = Avo::ViewInquirer.new(view) if view.present?
|
237
238
|
@user = user if user.present?
|
238
239
|
@params = params if params.present?
|
239
240
|
|
240
241
|
if record.present?
|
241
242
|
@record = record
|
242
243
|
|
243
|
-
hydrate_model_with_default_values if @view
|
244
|
+
hydrate_model_with_default_values if @view&.new?
|
244
245
|
end
|
245
246
|
|
246
247
|
detect_fields
|
@@ -295,7 +296,7 @@ module Avo
|
|
295
296
|
# def get_action_arguments / def get_filter_arguments / def get_scope_arguments
|
296
297
|
define_method "get_#{entity}_arguments" do |entity_class|
|
297
298
|
klass = send("get_#{plural_entity}").find { |entity| entity[:class].to_s == entity_class.to_s }
|
298
|
-
|
299
|
+
|
299
300
|
raise "Couldn't find '#{entity_class}' in the 'def #{plural_entity}' method on your '#{self.class}' resource." if klass.nil?
|
300
301
|
|
301
302
|
klass[:arguments]
|
@@ -303,14 +304,14 @@ module Avo
|
|
303
304
|
end
|
304
305
|
|
305
306
|
def hydrate(record: nil, view: nil, user: nil, params: nil)
|
306
|
-
@view = view if view.present?
|
307
|
+
@view = Avo::ViewInquirer.new(view) if view.present?
|
307
308
|
@user = user if user.present?
|
308
309
|
@params = params if params.present?
|
309
310
|
|
310
311
|
if record.present?
|
311
312
|
@record = record
|
312
313
|
|
313
|
-
hydrate_model_with_default_values if @view
|
314
|
+
hydrate_model_with_default_values if @view&.new?
|
314
315
|
end
|
315
316
|
|
316
317
|
self
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Avo
|
2
|
+
module Concerns
|
3
|
+
module HasHelpers
|
4
|
+
def helpers
|
5
|
+
@helpers ||= Class.new do
|
6
|
+
def initialize
|
7
|
+
helper_names = ActionController::Base.all_helpers_from_path Rails.root.join("app", "helpers")
|
8
|
+
helpers = ActionController::Base.modules_for_helpers helper_names
|
9
|
+
|
10
|
+
helpers.each do |helper|
|
11
|
+
extend helper
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -273,7 +273,7 @@ module Avo
|
|
273
273
|
end
|
274
274
|
.select do |item|
|
275
275
|
# On location field we can have field coordinates and setters with different names like latitude and longitude
|
276
|
-
if !item.is_a?(Avo::Fields::LocationField) && !item.is_heading? && view.in?([
|
276
|
+
if !item.is_a?(Avo::Fields::LocationField) && !item.is_heading? && view.in?(%w[edit update new create])
|
277
277
|
if item.respond_to?(:id)
|
278
278
|
item.resource.record.respond_to?("#{item.id}=")
|
279
279
|
else
|
@@ -61,7 +61,7 @@ module Avo
|
|
61
61
|
def except_on(*where)
|
62
62
|
show_on_all
|
63
63
|
normalize_views(where).flatten.each do |view|
|
64
|
-
|
64
|
+
hide_on_view view
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -113,12 +113,18 @@ module Avo
|
|
113
113
|
|
114
114
|
def normalize_views(*views_and_groups)
|
115
115
|
forms = views_and_groups.flatten! & [:forms]
|
116
|
+
display = views_and_groups & [:display]
|
116
117
|
|
117
118
|
if forms.present?
|
118
119
|
views_and_groups -= forms
|
119
120
|
views_and_groups += [:new, :edit]
|
120
121
|
end
|
121
122
|
|
123
|
+
if display.present?
|
124
|
+
views_and_groups -= display
|
125
|
+
views_and_groups += [:index, :show]
|
126
|
+
end
|
127
|
+
|
122
128
|
views_and_groups.flatten.uniq
|
123
129
|
end
|
124
130
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# This concern helps us figure out what items are visible for each tab, panel or sidebar
|
2
|
+
module Avo
|
3
|
+
module Concerns
|
4
|
+
module VisibleItems
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
def items
|
7
|
+
items_holder&.items || []
|
8
|
+
end
|
9
|
+
|
10
|
+
def visible_items
|
11
|
+
items
|
12
|
+
.select do |item|
|
13
|
+
if item.respond_to? :hydrate
|
14
|
+
item.hydrate(view: view, resource: resource)
|
15
|
+
end
|
16
|
+
|
17
|
+
visible(item)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def visible(item)
|
22
|
+
return item.visible? if !item.is_field?
|
23
|
+
|
24
|
+
return false if item.respond_to?(:authorized?) && item.resource.present? && !item.authorized?
|
25
|
+
|
26
|
+
item.visible? && item.visible_in_view?(view: view)
|
27
|
+
end
|
28
|
+
|
29
|
+
def visible?
|
30
|
+
any_item_visible = visible_items.any?
|
31
|
+
return any_item_visible if !respond_to?(:visible_on?)
|
32
|
+
|
33
|
+
visible_on?(view) && any_item_visible
|
34
|
+
end
|
35
|
+
|
36
|
+
def hydrate(view: nil)
|
37
|
+
@view = view
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/avo/configuration.rb
CHANGED
@@ -36,13 +36,14 @@ module Avo
|
|
36
36
|
attr_accessor :main_menu
|
37
37
|
attr_accessor :profile_menu
|
38
38
|
attr_accessor :model_resource_mapping
|
39
|
-
|
39
|
+
attr_reader :resource_default_view
|
40
40
|
attr_accessor :authorization_client
|
41
41
|
attr_accessor :field_wrapper_layout
|
42
42
|
attr_accessor :sign_out_path_name
|
43
43
|
attr_accessor :resources
|
44
44
|
attr_accessor :prefix_path
|
45
45
|
attr_accessor :resource_parent_controller
|
46
|
+
attr_accessor :mount_avo_engines
|
46
47
|
|
47
48
|
def initialize
|
48
49
|
@root_path = "/avo"
|
@@ -88,11 +89,12 @@ module Avo
|
|
88
89
|
@main_menu = nil
|
89
90
|
@profile_menu = nil
|
90
91
|
@model_resource_mapping = {}
|
91
|
-
@resource_default_view =
|
92
|
+
@resource_default_view = Avo::ViewInquirer.new("show")
|
92
93
|
@authorization_client = :pundit
|
93
94
|
@field_wrapper_layout = :inline
|
94
95
|
@resources = nil
|
95
96
|
@resource_parent_controller = "Avo::ResourcesController"
|
97
|
+
@mount_avo_engines = true
|
96
98
|
end
|
97
99
|
|
98
100
|
def current_user_method(&block)
|
@@ -158,6 +160,10 @@ module Avo
|
|
158
160
|
"community"
|
159
161
|
end
|
160
162
|
end
|
163
|
+
|
164
|
+
def resource_default_view=(view)
|
165
|
+
@resource_default_view = Avo::ViewInquirer.new(view.to_s)
|
166
|
+
end
|
161
167
|
end
|
162
168
|
|
163
169
|
def self.configuration
|
data/lib/avo/current.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Avo
|
2
2
|
class ExecutionContext
|
3
|
-
|
3
|
+
include Avo::Concerns::HasHelpers
|
4
|
+
|
5
|
+
attr_accessor :target, :context, :params, :view_context, :current_user, :request, :include, :main_app, :avo, :locale
|
4
6
|
|
5
7
|
def initialize(**args)
|
6
8
|
# Extend the class with custom modules if required.
|
@@ -24,6 +26,7 @@ module Avo
|
|
24
26
|
@params ||= Avo::Current.params
|
25
27
|
@request ||= Avo::Current.request
|
26
28
|
@view_context ||= Avo::Current.view_context
|
29
|
+
@locale ||= Avo::Current.locale
|
27
30
|
@main_app ||= @view_context.main_app
|
28
31
|
@avo ||= @view_context.avo
|
29
32
|
end
|
@@ -8,7 +8,7 @@ module Avo
|
|
8
8
|
|
9
9
|
hide_on [:edit, :new]
|
10
10
|
|
11
|
-
default_options = {info: :info, success: :success, danger: :danger, warning: :warning}
|
11
|
+
default_options = {info: :info, success: :success, danger: :danger, warning: :warning, secondary: :secondary}
|
12
12
|
@options = args[:options].present? ? default_options.merge(args[:options]) : default_options
|
13
13
|
end
|
14
14
|
end
|