avo 3.0.7 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of avo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/{public/avo-assets/avo.css → app/assets/builds/avo.base.css} +817 -640
- data/app/assets/builds/avo.base.js +131710 -0
- data/app/assets/builds/avo.base.js.map +7 -0
- data/app/components/avo/field_wrapper_component.rb +14 -3
- data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +12 -8
- data/app/components/avo/fields/hidden_field/edit_component.html.erb +2 -1
- data/app/components/avo/index/table_row_component.html.erb +1 -1
- data/app/controllers/avo/actions_controller.rb +2 -1
- data/app/helpers/avo/resources_helper.rb +2 -0
- data/app/views/avo/actions/show.html.erb +2 -2
- data/lib/avo/base_action.rb +1 -0
- data/lib/avo/base_resource.rb +1 -1
- data/lib/avo/concerns/has_action_stimulus_controllers.rb +15 -0
- data/lib/avo/concerns/{has_stimulus_controllers.rb → has_resource_stimulus_controllers.rb} +1 -1
- data/lib/avo/configuration.rb +21 -0
- data/lib/avo/fields/base_field.rb +1 -0
- data/lib/avo/fields/belongs_to_field.rb +5 -0
- data/lib/avo/fields/concerns/has_html_attributes.rb +27 -12
- data/lib/avo/version.rb +1 -1
- data/lib/avo.rb +2 -21
- data/lib/generators/avo/templates/action.tt +2 -2
- data/lib/generators/avo/templates/cards/chartkick_card.tt +1 -1
- data/lib/generators/avo/templates/cards/chartkick_card_sample.tt +1 -1
- data/lib/generators/avo/templates/cards/metric_card.tt +1 -1
- data/lib/generators/avo/templates/cards/metric_card_sample.tt +1 -1
- data/lib/generators/avo/templates/cards/partial_card.tt +1 -1
- data/lib/generators/avo/templates/cards/partial_card_sample.tt +1 -1
- data/lib/generators/avo/templates/initializer/avo.tt +14 -0
- data/public/avo-assets/avo.base.css +0 -232
- metadata +7 -7
- data/config/master.key +0 -1
- data/public/avo-assets/avo.js +0 -513
- data/public/avo-assets/avo.js.map +0 -7
@@ -36,6 +36,7 @@ class Avo::FieldWrapperComponent < ViewComponent::Base
|
|
36
36
|
@full_width = full_width
|
37
37
|
@label = label
|
38
38
|
@resource = resource
|
39
|
+
@action = field.action
|
39
40
|
@short = short
|
40
41
|
@stacked = stacked
|
41
42
|
@style = style
|
@@ -73,9 +74,11 @@ class Avo::FieldWrapperComponent < ViewComponent::Base
|
|
73
74
|
|
74
75
|
# Add the built-in stimulus integration data tags.
|
75
76
|
if @resource.present?
|
76
|
-
@resource
|
77
|
-
|
78
|
-
|
77
|
+
add_stimulus_attributes_for(@resource, attributes)
|
78
|
+
end
|
79
|
+
|
80
|
+
if @action.present?
|
81
|
+
add_stimulus_attributes_for(@action, attributes)
|
79
82
|
end
|
80
83
|
|
81
84
|
# Fetch the data attributes off the html option
|
@@ -109,4 +112,12 @@ class Avo::FieldWrapperComponent < ViewComponent::Base
|
|
109
112
|
def full_width?
|
110
113
|
@full_width
|
111
114
|
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def add_stimulus_attributes_for(entity, attributes)
|
119
|
+
entity.get_stimulus_controllers.split(" ").each do |controller|
|
120
|
+
attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
|
121
|
+
end
|
122
|
+
end
|
112
123
|
end
|
@@ -81,12 +81,14 @@
|
|
81
81
|
<%= @form.hidden_field @field.id_input_foreign_key %>
|
82
82
|
<% end %>
|
83
83
|
<% end %>
|
84
|
-
<%
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
<% if field.can_create? %>
|
85
|
+
<% create_href = create_path(Avo.resource_manager.get_resource_by_model_class(type.to_s)) %>
|
86
|
+
<% if !disabled && create_href.present? %>
|
87
|
+
<%= link_to t("avo.create_new_item", item: type.to_s.downcase),
|
88
|
+
create_href,
|
89
|
+
class: "text-sm"
|
90
|
+
%>
|
91
|
+
<% end %>
|
90
92
|
<% end %>
|
91
93
|
<% end %>
|
92
94
|
</div>
|
@@ -125,8 +127,10 @@
|
|
125
127
|
<%= @form.hidden_field @field.id_input_foreign_key %>
|
126
128
|
<% end %>
|
127
129
|
<% end %>
|
128
|
-
<% if
|
129
|
-
|
130
|
+
<% if field.can_create? %>
|
131
|
+
<% if !disabled && create_path.present? %>
|
132
|
+
<%= link_to t("avo.create_new_item", item: @field.name.downcase), create_path, class: "text-sm" %>
|
133
|
+
<% end %>
|
130
134
|
<% end %>
|
131
135
|
<% end %>
|
132
136
|
<% end %>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
<%= @form.hidden_field @field.id,
|
2
2
|
class: @field.get_html(:classes, view: view, element: :input),
|
3
3
|
data: @field.get_html(:data, view: view, element: :input),
|
4
|
-
style: @field.get_html(:style, view: view, element: :input)
|
4
|
+
style: @field.get_html(:style, view: view, element: :input),
|
5
|
+
value: @field.value
|
5
6
|
%>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%# hover:z-[21] removed from tr class to solve flickering actions component on row controls and z-20 changed to z-21%>
|
2
2
|
<tr
|
3
|
-
class="bg-white hover:bg-gray-50 hover:shadow-row
|
3
|
+
class="bg-white hover:bg-gray-50 hover:shadow-row z-21 border-b"
|
4
4
|
data-component-name="<%= self.class.to_s.underscore %>"
|
5
5
|
<%== item_selector_init @resource %>
|
6
6
|
data-resource-name="<%= @resource.class.to_s %>"
|
@@ -26,7 +26,8 @@ module Avo
|
|
26
26
|
fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query),
|
27
27
|
current_user: _current_user,
|
28
28
|
resource: resource,
|
29
|
-
query: decrypted_query ||
|
29
|
+
query: decrypted_query ||
|
30
|
+
(resource_ids.any? ? @resource.find_record(resource_ids, params: params) : [])
|
30
31
|
)
|
31
32
|
|
32
33
|
respond performed_action.response
|
@@ -46,6 +46,7 @@ module Avo
|
|
46
46
|
type: "checkbox",
|
47
47
|
name: t("avo.select_item"),
|
48
48
|
title: t("avo.select_item"),
|
49
|
+
autocomplete: :off,
|
49
50
|
class: "mx-3 rounded checked:bg-primary-400 focus:checked:!bg-primary-400 #{floating ? "absolute inset-auto left-0 mt-3 z-10 hidden group-hover:block checked:block" : ""} #{size.to_sym == :lg ? "w-5 h-5" : "w-4 h-4"}",
|
50
51
|
data: {
|
51
52
|
action: 'input->item-selector#toggle input->item-select-all#selectRow',
|
@@ -59,6 +60,7 @@ module Avo
|
|
59
60
|
type: "checkbox",
|
60
61
|
name: t("avo.select_all"),
|
61
62
|
title: t("avo.select_all"),
|
63
|
+
autocomplete: :off,
|
62
64
|
class: "mx-3 rounded w-4 h-4 checked:bg-primary-400 focus:checked:!bg-primary-400",
|
63
65
|
data: {
|
64
66
|
action: "input->item-select-all#toggle",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%= turbo_frame_tag "actions_show" do %>
|
2
2
|
<div
|
3
|
-
data-controller="action"
|
3
|
+
data-controller="<%= ["action", @action.get_stimulus_controllers].join(" ") %>"
|
4
4
|
data-no-confirmation="<%= @action.no_confirmation %>"
|
5
5
|
data-action-target="controllerDiv"
|
6
6
|
data-resource-name="<%= @resource.model_key %>"
|
@@ -28,7 +28,7 @@
|
|
28
28
|
<div class="mt-4 -mx-6">
|
29
29
|
<% @action.get_fields.each_with_index do |field, index| %>
|
30
30
|
<%= render field
|
31
|
-
.hydrate(resource: @resource, record: @resource.record, user: @resource.user, view: @view)
|
31
|
+
.hydrate(resource: @resource, record: @resource.record, user: @resource.user, view: @view, action: @action)
|
32
32
|
.component_for_view(@view)
|
33
33
|
.new(field: field, resource: @resource, index: index, form: form, compact: true)
|
34
34
|
%>
|
data/lib/avo/base_action.rb
CHANGED
data/lib/avo/base_resource.rb
CHANGED
@@ -6,7 +6,7 @@ module Avo
|
|
6
6
|
include Avo::Concerns::HasItems
|
7
7
|
include Avo::Concerns::CanReplaceItems
|
8
8
|
include Avo::Concerns::HasControls
|
9
|
-
include Avo::Concerns::
|
9
|
+
include Avo::Concerns::HasResourceStimulusControllers
|
10
10
|
include Avo::Concerns::ModelClassConstantized
|
11
11
|
include Avo::Concerns::HasDescription
|
12
12
|
include Avo::Concerns::HasHelpers
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Avo
|
2
|
+
module Concerns
|
3
|
+
module HasActionStimulusControllers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :stimulus_controllers, default: ""
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_stimulus_controllers
|
11
|
+
self.class.stimulus_controllers
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/avo/configuration.rb
CHANGED
@@ -6,6 +6,7 @@ module Avo
|
|
6
6
|
attr_writer :branding
|
7
7
|
attr_writer :root_path
|
8
8
|
attr_writer :cache_store
|
9
|
+
attr_writer :logger
|
9
10
|
attr_accessor :timezone
|
10
11
|
attr_accessor :per_page
|
11
12
|
attr_accessor :per_page_steps
|
@@ -97,6 +98,7 @@ module Avo
|
|
97
98
|
@resource_parent_controller = "Avo::ResourcesController"
|
98
99
|
@mount_avo_engines = true
|
99
100
|
@cache_store = computed_cache_store
|
101
|
+
@logger = default_logger
|
100
102
|
end
|
101
103
|
|
102
104
|
def current_user_method(&block)
|
@@ -193,6 +195,25 @@ module Avo
|
|
193
195
|
end
|
194
196
|
}
|
195
197
|
end
|
198
|
+
|
199
|
+
def logger
|
200
|
+
Avo::ExecutionContext.new(target: @logger).handle
|
201
|
+
end
|
202
|
+
|
203
|
+
def default_logger
|
204
|
+
-> {
|
205
|
+
file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log"))
|
206
|
+
|
207
|
+
file_logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
208
|
+
file_logger.formatter = proc do |severity, time, progname, msg|
|
209
|
+
"[Avo] #{time}: #{msg}\n".tap do |i|
|
210
|
+
puts i
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
file_logger
|
215
|
+
}
|
216
|
+
end
|
196
217
|
end
|
197
218
|
|
198
219
|
def self.configuration
|
@@ -83,6 +83,7 @@ module Avo
|
|
83
83
|
@polymorphic_help = args[:polymorphic_help]
|
84
84
|
@target = args[:target]
|
85
85
|
@use_resource = args[:use_resource] || nil
|
86
|
+
@can_create = args[:can_create].nil? ? true : args[:can_create]
|
86
87
|
end
|
87
88
|
|
88
89
|
def value
|
@@ -264,6 +265,10 @@ module Avo
|
|
264
265
|
super
|
265
266
|
end
|
266
267
|
|
268
|
+
def can_create?
|
269
|
+
@can_create
|
270
|
+
end
|
271
|
+
|
267
272
|
private
|
268
273
|
|
269
274
|
def get_model_class(model)
|
@@ -30,7 +30,10 @@ module Avo
|
|
30
30
|
default_attribute_value name
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
add_action_data_attributes(attributes, name, element)
|
34
|
+
add_resource_data_attributes(attributes, name, element, view)
|
35
|
+
|
36
|
+
attributes
|
34
37
|
end
|
35
38
|
|
36
39
|
private
|
@@ -50,18 +53,17 @@ module Avo
|
|
50
53
|
name == :data ? {} : ""
|
51
54
|
end
|
52
55
|
|
53
|
-
def
|
54
|
-
if
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
[:"#{controller}-target", "#{id.to_s.underscore}_#{type.to_s.underscore}_input".camelize(:lower)]
|
59
|
-
end
|
60
|
-
.to_h
|
56
|
+
def add_action_data_attributes(attributes, name, element)
|
57
|
+
if can_add_stimulus_attributes_for?(action, attributes, name, element)
|
58
|
+
attributes.merge!(stimulus_attributes_for(action))
|
59
|
+
end
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
def add_resource_data_attributes(attributes, name, element, view)
|
63
|
+
if can_add_stimulus_attributes_for?(resource, attributes, name, element) && view.in?([:edit, :new])
|
64
|
+
resource_stimulus_attributes = stimulus_attributes_for(resource)
|
65
|
+
|
66
|
+
attributes.merge!(resource_stimulus_attributes)
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
@@ -106,6 +108,19 @@ module Avo
|
|
106
108
|
|
107
109
|
result if result.present?
|
108
110
|
end
|
111
|
+
|
112
|
+
def can_add_stimulus_attributes_for?(entity, attributes, name, element)
|
113
|
+
!attributes.nil? && name == :data && element == :input && entity.present? && entity.respond_to?(:get_stimulus_controllers)
|
114
|
+
end
|
115
|
+
|
116
|
+
def stimulus_attributes_for(entity)
|
117
|
+
entity.get_stimulus_controllers
|
118
|
+
.split(" ")
|
119
|
+
.map do |controller|
|
120
|
+
[:"#{controller}-target", "#{id.to_s.underscore}_#{type.to_s.underscore}_input".camelize(:lower)]
|
121
|
+
end
|
122
|
+
.to_h
|
123
|
+
end
|
109
124
|
end
|
110
125
|
end
|
111
126
|
end
|
data/lib/avo/version.rb
CHANGED
data/lib/avo.rb
CHANGED
@@ -49,8 +49,8 @@ module Avo
|
|
49
49
|
delegate :license, :app, :error_manager, :tool_manager, :resource_manager, to: Avo::Current
|
50
50
|
|
51
51
|
def boot
|
52
|
-
|
53
|
-
|
52
|
+
@logger = Avo.configuration.logger
|
53
|
+
@field_manager = Avo::Fields::FieldManager.build
|
54
54
|
@cache_store = Avo.configuration.cache_store
|
55
55
|
plugin_manager.boot_plugins
|
56
56
|
Avo.run_load_hooks(:boot, self)
|
@@ -124,25 +124,6 @@ module Avo
|
|
124
124
|
mount Avo::Pro::Engine, at: "/avo-pro" if defined?(Avo::Pro::Engine)
|
125
125
|
}
|
126
126
|
end
|
127
|
-
|
128
|
-
private
|
129
|
-
|
130
|
-
def boot_logger
|
131
|
-
file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log"))
|
132
|
-
|
133
|
-
file_logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
134
|
-
file_logger.formatter = proc do |severity, time, progname, msg|
|
135
|
-
"[Avo] #{time}: #{msg}\n".tap do |i|
|
136
|
-
puts i
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
@logger = file_logger
|
141
|
-
end
|
142
|
-
|
143
|
-
def boot_fields
|
144
|
-
@field_manager = Avo::Fields::FieldManager.build
|
145
|
-
end
|
146
127
|
end
|
147
128
|
end
|
148
129
|
|
@@ -8,8 +8,8 @@ class Avo::Actions::<%= class_name.camelize %> < Avo::BaseAction
|
|
8
8
|
# # Add Action fields here
|
9
9
|
# end
|
10
10
|
|
11
|
-
def handle(
|
12
|
-
|
11
|
+
def handle(query:, fields:, current_user:, resource:, **args)
|
12
|
+
query.each do |record|
|
13
13
|
# Do something with your records.
|
14
14
|
end
|
15
15
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Avo::Cards::<%= class_name.camelize %> < Avo::
|
1
|
+
class Avo::Cards::<%= class_name.camelize %> < Avo::Cards::MetricCard
|
2
2
|
self.id = "<%= name.underscore %>"
|
3
3
|
self.label = "<%= name.underscore.humanize %>"
|
4
4
|
# self.description = "Some description"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Avo::Cards::<%= class_name.camelize %> < Avo::
|
1
|
+
class Avo::Cards::<%= class_name.camelize %> < Avo::Cards::PartialCard
|
2
2
|
self.id = "<%= name.underscore %>"
|
3
3
|
self.label = "<%= name.underscore.humanize %>"
|
4
4
|
self.partial = "avo/cards/<%= name.underscore %>"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Avo::Cards::<%= class_name.camelize %> < Avo::
|
1
|
+
class Avo::Cards::<%= class_name.camelize %> < Avo::Cards::PartialCard
|
2
2
|
self.id = "<%= name.underscore %>"
|
3
3
|
self.label = "<%= name.underscore.humanize %>"
|
4
4
|
self.partial = "avo/cards/<%= name.underscore %>"
|
@@ -64,6 +64,20 @@ Avo.configure do |config|
|
|
64
64
|
## provide a lambda to enable or disable cache_resource_filters per user/resource.
|
65
65
|
# config.cache_resource_filters = -> { current_user.cache_resource_filters? }
|
66
66
|
|
67
|
+
## == Logger ==
|
68
|
+
# config.logger = -> {
|
69
|
+
# file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log"))
|
70
|
+
#
|
71
|
+
# file_logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
72
|
+
# file_logger.formatter = proc do |severity, time, progname, msg|
|
73
|
+
# "[Avo] #{time}: #{msg}\n".tap do |i|
|
74
|
+
# puts i
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# file_logger
|
79
|
+
# }
|
80
|
+
|
67
81
|
## == Customization ==
|
68
82
|
# config.app_name = 'Avocadelicious'
|
69
83
|
# config.timezone = 'UTC'
|