avo 3.0.1.beta7 → 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,6 +7,7 @@ module Avo
|
|
7
7
|
prepend Avo::Concerns::IsResourceItem
|
8
8
|
include Avo::Concerns::IsVisible
|
9
9
|
include Avo::Concerns::VisibleInDifferentViews
|
10
|
+
include Avo::Concerns::HasHelpers
|
10
11
|
include Avo::Fields::Concerns::HasFieldName
|
11
12
|
include Avo::Fields::Concerns::HasDefault
|
12
13
|
include Avo::Fields::Concerns::HasHTMLAttributes
|
@@ -14,6 +15,7 @@ module Avo
|
|
14
15
|
include Avo::Fields::Concerns::IsReadonly
|
15
16
|
include Avo::Fields::Concerns::IsDisabled
|
16
17
|
include Avo::Fields::Concerns::IsRequired
|
18
|
+
include Avo::Fields::Concerns::UseViewComponents
|
17
19
|
|
18
20
|
include ActionView::Helpers::UrlHelper
|
19
21
|
|
@@ -73,11 +75,12 @@ module Avo
|
|
73
75
|
@visible = args[:visible]
|
74
76
|
@as_avatar = args[:as_avatar] || false
|
75
77
|
@html = args[:html] || nil
|
76
|
-
@view = args[:view] || nil
|
78
|
+
@view = Avo::ViewInquirer.new(args[:view]) || nil
|
77
79
|
@value = args[:value] || nil
|
78
80
|
@stacked = args[:stacked] || nil
|
79
81
|
@for_presentation_only = args[:for_presentation_only] || false
|
80
82
|
@resource = args[:resource]
|
83
|
+
@components = args[:components] || {}
|
81
84
|
|
82
85
|
@args = args
|
83
86
|
|
@@ -192,7 +195,8 @@ module Avo
|
|
192
195
|
key: key,
|
193
196
|
value: value,
|
194
197
|
resource: resource,
|
195
|
-
field: self
|
198
|
+
field: self,
|
199
|
+
include: self.class.included_modules
|
196
200
|
).handle
|
197
201
|
end
|
198
202
|
|
@@ -220,35 +224,8 @@ module Avo
|
|
220
224
|
id.to_sym
|
221
225
|
end
|
222
226
|
|
223
|
-
def view_component_name
|
224
|
-
"#{type.camelize}Field"
|
225
|
-
end
|
226
|
-
|
227
|
-
# For custom components the namespace will be different than Avo::Fields so we should take that into account.
|
228
|
-
def view_component_namespace
|
229
|
-
"#{self.class.to_s.deconstantize}::#{view_component_name}"
|
230
|
-
end
|
231
|
-
|
232
|
-
# Try and build the component class or fallback to a blank one
|
233
|
-
def component_for_view(view = :index)
|
234
|
-
# Use the edit variant for all "update" views
|
235
|
-
view = :edit if view.in? [:new, :create, :update]
|
236
|
-
|
237
|
-
component_class = "#{view_component_namespace}::#{view.to_s.camelize}Component"
|
238
|
-
component_class.constantize
|
239
|
-
rescue
|
240
|
-
unless Rails.env.test?
|
241
|
-
Avo.logger.info "Failed to find component for the `#{self.class}` field on the `#{view}` view."
|
242
|
-
end
|
243
|
-
# When returning nil, a race condition happens and throws an error in some environments.
|
244
|
-
# See https://github.com/avo-hq/avo/pull/365
|
245
|
-
::Avo::BlankFieldComponent
|
246
|
-
end
|
247
|
-
|
248
227
|
def record_errors
|
249
|
-
|
250
|
-
|
251
|
-
record.errors
|
228
|
+
record.nil? ? {} : record.errors
|
252
229
|
end
|
253
230
|
|
254
231
|
def type
|
@@ -289,11 +266,7 @@ module Avo
|
|
289
266
|
private
|
290
267
|
|
291
268
|
def model_or_class(model)
|
292
|
-
|
293
|
-
"class"
|
294
|
-
else
|
295
|
-
"model"
|
296
|
-
end
|
269
|
+
model.instance_of?(String) ? "class" : "model"
|
297
270
|
end
|
298
271
|
|
299
272
|
def is_model?(model)
|
@@ -305,7 +278,7 @@ module Avo
|
|
305
278
|
end
|
306
279
|
|
307
280
|
def on_create?
|
308
|
-
@view.in?([
|
281
|
+
@view.in?(%w[new create])
|
309
282
|
end
|
310
283
|
|
311
284
|
def in_action?
|
@@ -13,6 +13,8 @@ module Avo
|
|
13
13
|
# get_html :classes, view: :show, element: :wrapper
|
14
14
|
# get_html :styles, view: :index, element: :wrapper
|
15
15
|
def get_html(name = nil, element:, view:)
|
16
|
+
view = view.to_sym if view.present?
|
17
|
+
|
16
18
|
if [view, element].any?(&:nil?)
|
17
19
|
default_attribute_value name
|
18
20
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Avo
|
2
|
+
module Fields
|
3
|
+
module Concerns
|
4
|
+
module UseViewComponents
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
attr_reader :components
|
9
|
+
end
|
10
|
+
|
11
|
+
def view_component_name
|
12
|
+
"#{type.camelize}Field"
|
13
|
+
end
|
14
|
+
|
15
|
+
# For custom components the namespace will be different than Avo::Fields so we should take that into account.
|
16
|
+
def view_component_namespace
|
17
|
+
"#{self.class.to_s.deconstantize}::#{view_component_name}"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Try and build the component class or fallback to a blank one
|
21
|
+
def component_for_view(view = :index)
|
22
|
+
# Use the edit variant for all "update" views
|
23
|
+
view = :edit if view.in? [:new, :create, :update]
|
24
|
+
|
25
|
+
custom_components = Avo::ExecutionContext.new(
|
26
|
+
target: components,
|
27
|
+
resource: @resource,
|
28
|
+
record: @record,
|
29
|
+
view: view
|
30
|
+
).handle
|
31
|
+
|
32
|
+
component_class = custom_components.dig("#{view}_component".to_sym) || "#{view_component_namespace}::#{view.to_s.camelize}Component"
|
33
|
+
component_class.to_s.constantize
|
34
|
+
rescue
|
35
|
+
unless Rails.env.test?
|
36
|
+
Avo.logger.info "Failed to find component for the `#{self.class}` field on the `#{view}` view."
|
37
|
+
end
|
38
|
+
# When returning nil, a race condition happens and throws an error in some environments.
|
39
|
+
# See https://github.com/avo-hq/avo/pull/365
|
40
|
+
::Avo::BlankFieldComponent
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -79,8 +79,8 @@ module Avo
|
|
79
79
|
|
80
80
|
# Adds the view override component
|
81
81
|
# has_one, has_many, has_and_belongs_to_many fields don't have edit views
|
82
|
-
def component_for_view(view =
|
83
|
-
view =
|
82
|
+
def component_for_view(view = Avo::ViewInquirer.new("index"))
|
83
|
+
view = Avo::ViewInquirer.new("show") if view.in? %w[new create update edit]
|
84
84
|
|
85
85
|
super view
|
86
86
|
end
|
@@ -3,7 +3,7 @@ class Avo::Resources::Items::ItemGroup
|
|
3
3
|
|
4
4
|
include Avo::Concerns::HasItems
|
5
5
|
include Avo::Concerns::HasItemType
|
6
|
-
include Avo::Concerns::
|
6
|
+
include Avo::Concerns::VisibleItems
|
7
7
|
include Avo::Concerns::VisibleInDifferentViews
|
8
8
|
|
9
9
|
attr_reader :name
|
@@ -13,7 +13,7 @@ class Avo::Resources::Items::ItemGroup
|
|
13
13
|
|
14
14
|
def initialize(name: nil, description: nil, view: nil, **args)
|
15
15
|
@name = name
|
16
|
-
@view = view
|
16
|
+
@view = Avo::ViewInquirer.new view
|
17
17
|
@description = description
|
18
18
|
@items_holder = Avo::Resources::Items::Holder.new
|
19
19
|
@args = args
|
@@ -2,7 +2,7 @@ class Avo::Resources::Items::Row
|
|
2
2
|
include Avo::Concerns::IsResourceItem
|
3
3
|
include Avo::Concerns::HasItems
|
4
4
|
include Avo::Concerns::HasItemType
|
5
|
-
include Avo::Concerns::
|
5
|
+
include Avo::Concerns::VisibleItems
|
6
6
|
|
7
7
|
class_attribute :item_type, default: :row
|
8
8
|
|
@@ -12,12 +12,12 @@ class Avo::Resources::Items::Row
|
|
12
12
|
delegate :items, :add_item, to: :items_holder
|
13
13
|
|
14
14
|
def initialize(view: nil)
|
15
|
-
@view = view
|
15
|
+
@view = Avo::ViewInquirer.new view
|
16
16
|
@items_holder = Avo::Resources::Items::Holder.new
|
17
17
|
end
|
18
18
|
|
19
19
|
def hydrate(view: nil, resource: nil, **args)
|
20
|
-
@view = view
|
20
|
+
@view = Avo::ViewInquirer.new view
|
21
21
|
@resource = resource
|
22
22
|
|
23
23
|
self
|
@@ -13,7 +13,7 @@ class Avo::Resources::Items::Sidebar
|
|
13
13
|
def initialize(name: nil, view: nil, **args)
|
14
14
|
@name = name
|
15
15
|
@items_holder = Avo::Resources::Items::Holder.new
|
16
|
-
@view = view
|
16
|
+
@view = Avo::ViewInquirer.new view
|
17
17
|
@args = args
|
18
18
|
|
19
19
|
post_initialize if respond_to?(:post_initialize)
|
@@ -3,7 +3,7 @@ class Avo::Resources::Items::Tab
|
|
3
3
|
|
4
4
|
include Avo::Concerns::HasItems
|
5
5
|
include Avo::Concerns::HasItemType
|
6
|
-
include Avo::Concerns::
|
6
|
+
include Avo::Concerns::VisibleItems
|
7
7
|
include Avo::Concerns::VisibleInDifferentViews
|
8
8
|
|
9
9
|
delegate :items, :add_item, to: :items_holder
|
@@ -14,7 +14,7 @@ class Avo::Resources::Items::Tab
|
|
14
14
|
@name = name
|
15
15
|
@description = description
|
16
16
|
@items_holder = Avo::Resources::Items::Holder.new
|
17
|
-
@view = view
|
17
|
+
@view = Avo::ViewInquirer.new view
|
18
18
|
@args = args
|
19
19
|
|
20
20
|
post_initialize if respond_to?(:post_initialize)
|
@@ -152,7 +152,12 @@ module Avo
|
|
152
152
|
def get_available_resources(user = nil)
|
153
153
|
valid_resources
|
154
154
|
.select do |resource|
|
155
|
-
|
155
|
+
resource.authorization.class.authorize(
|
156
|
+
user,
|
157
|
+
resource.model_class,
|
158
|
+
Avo.configuration.authorization_methods.stringify_keys["index"],
|
159
|
+
raise_exception: false
|
160
|
+
)
|
156
161
|
end
|
157
162
|
.sort_by { |r| r.name }
|
158
163
|
end
|
data/lib/avo/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Allows to check the the view type by using `view.index?` or `view.edit?` etc...
|
2
|
+
# It also allows to check if the view is a form or a display view by using `view.form?` or `view.display?`
|
3
|
+
module Avo
|
4
|
+
class ViewInquirer < ActiveSupport::StringInquirer
|
5
|
+
DISPLAY_VIEWS = %w[index show]
|
6
|
+
FORM_VIEWS = %w[new edit]
|
7
|
+
|
8
|
+
def initialize(view)
|
9
|
+
super(view.to_s)
|
10
|
+
|
11
|
+
@display = in? DISPLAY_VIEWS
|
12
|
+
@form = in? FORM_VIEWS
|
13
|
+
end
|
14
|
+
|
15
|
+
def display?
|
16
|
+
@display
|
17
|
+
end
|
18
|
+
|
19
|
+
def form?
|
20
|
+
@form
|
21
|
+
end
|
22
|
+
|
23
|
+
# To avoid breaking changes we allow the comparison with symbols
|
24
|
+
def ==(other)
|
25
|
+
if other.is_a? Symbol
|
26
|
+
to_sym == other
|
27
|
+
else
|
28
|
+
super(other)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def in?(another_object)
|
33
|
+
super another_object.map(&:to_s)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/avo.rb
CHANGED
@@ -116,6 +116,15 @@ module Avo
|
|
116
116
|
true
|
117
117
|
end
|
118
118
|
|
119
|
+
# Mount all Avo engines
|
120
|
+
def mount_engines
|
121
|
+
-> {
|
122
|
+
mount Avo::DynamicFilters::Engine, at: "/avo-dynamic_filters" if defined?(Avo::DynamicFilters::Engine)
|
123
|
+
mount Avo::Dashboards::Engine, at: "/dashboards" if defined?(Avo::Dashboards::Engine)
|
124
|
+
mount Avo::Pro::Engine, at: "/avo-pro" if defined?(Avo::Pro::Engine)
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
119
128
|
private
|
120
129
|
|
121
130
|
def boot_logger
|
@@ -18,6 +18,16 @@ module Generators
|
|
18
18
|
type: :string,
|
19
19
|
required: false
|
20
20
|
|
21
|
+
class_option "field-components",
|
22
|
+
desc: "The field components to eject. Example: 'trix', 'text'",
|
23
|
+
type: :string,
|
24
|
+
required: false
|
25
|
+
|
26
|
+
class_option :view,
|
27
|
+
desc: "The view of the component to eject when using --field-component option. Example: 'index', 'show'",
|
28
|
+
type: :string,
|
29
|
+
required: false
|
30
|
+
|
21
31
|
source_root ::Avo::Engine.root
|
22
32
|
|
23
33
|
namespace "avo:eject"
|
@@ -38,12 +48,17 @@ module Generators
|
|
38
48
|
eject_partial
|
39
49
|
elsif options[:component].present?
|
40
50
|
eject_component
|
51
|
+
elsif options["field-components"].present?
|
52
|
+
eject_field_components
|
41
53
|
else
|
42
54
|
say "Please specify a partial or a component to eject.\n" \
|
43
55
|
"Examples: rails g avo:eject --partial :logo\n" \
|
44
56
|
" rails g avo:eject --partial app/views/layouts/avo/application.html.erb\n" \
|
45
57
|
" rails g avo:eject --component Avo::Index::TableRowComponent\n" \
|
46
58
|
" rails g avo:eject --component avo/index/table_row_component\n" \
|
59
|
+
" rails g avo:eject --field-components trix\n" \
|
60
|
+
" rails g avo:eject --field-components trix --scope users\n" \
|
61
|
+
" rails g avo:eject --field-components text --scope users --view edit\n" \
|
47
62
|
" rails g avo:eject --component Avo::Views::ResourceIndexComponent --scope users\n" \
|
48
63
|
" rails g avo:eject --component avo/views/resource_index_component --scope users", :yellow
|
49
64
|
end
|
@@ -60,8 +75,14 @@ module Generators
|
|
60
75
|
path.present? && File.file?(::Avo::Engine.root.join(path))
|
61
76
|
end
|
62
77
|
|
63
|
-
def
|
64
|
-
|
78
|
+
def dir_exists?(path)
|
79
|
+
path.present? && Dir.exist?(::Avo::Engine.root.join(path))
|
80
|
+
end
|
81
|
+
|
82
|
+
def eject(path, dest_path = nil, is_directory: false)
|
83
|
+
method = is_directory ? :directory : :copy_file
|
84
|
+
|
85
|
+
send method, ::Avo::Engine.root.join(path), ::Rails.root.join(dest_path || path)
|
65
86
|
end
|
66
87
|
|
67
88
|
def eject_partial
|
@@ -83,27 +104,33 @@ module Generators
|
|
83
104
|
end
|
84
105
|
end
|
85
106
|
|
86
|
-
def eject_component
|
107
|
+
def eject_component(component_to_eject = options[:component], confirmation: true)
|
87
108
|
# Underscore the component name
|
88
109
|
# Example: Avo::Views::ResourceIndexComponent => avo/views/resource_index_component
|
89
|
-
component =
|
110
|
+
component = component_to_eject.underscore
|
90
111
|
|
91
112
|
# Get the component path for both, the rb and erb files
|
92
113
|
rb, erb = ["app/components/#{component}.rb", "app/components/#{component}.html.erb"]
|
93
114
|
|
94
115
|
# Return if one of the components doesn't exist
|
95
116
|
if !path_exists?(rb) || !path_exists?(erb)
|
96
|
-
return say("Failed to find the `#{
|
117
|
+
return say("Failed to find the `#{component_to_eject}` component.", :yellow)
|
97
118
|
end
|
98
119
|
|
99
120
|
# Add the scope to the component if it's possible
|
100
121
|
if add_scope? component
|
101
|
-
component = component.
|
122
|
+
component = if component.starts_with?("avo/views/")
|
123
|
+
component.gsub("avo/views/", "avo/views/#{options[:scope].underscore}/")
|
124
|
+
elsif component.starts_with?("avo/fields/")
|
125
|
+
component.gsub("avo/fields/", "avo/fields/#{options[:scope].underscore}/")
|
126
|
+
end
|
102
127
|
added_scope = true
|
103
128
|
end
|
104
129
|
|
105
130
|
# Confirm the ejection
|
106
|
-
|
131
|
+
if confirmation
|
132
|
+
return if !confirm_ejection_on(component.camelize)
|
133
|
+
end
|
107
134
|
|
108
135
|
# Get the destination path for both, the rb and erb files
|
109
136
|
dest_rb = "#{::Avo.configuration.view_component_path}/#{component}.rb"
|
@@ -117,27 +144,77 @@ module Generators
|
|
117
144
|
# Example: Avo::Views::ResourceIndexComponent => Avo::Views::Admins::ResourceIndexComponent
|
118
145
|
if added_scope
|
119
146
|
[dest_rb, dest_erb].each do |path|
|
120
|
-
|
147
|
+
if component.starts_with?("avo/views/")
|
148
|
+
modified_content = File.read(path).gsub("Avo::Views::", "Avo::Views::#{options[:scope].camelize}::")
|
149
|
+
elsif component.starts_with?("avo/fields/")
|
150
|
+
modified_content = File.read(path).gsub("#{options["field-components"].camelize}Field", "#{options[:scope].camelize}::#{options["field-components"].camelize}Field")
|
151
|
+
end
|
121
152
|
|
122
153
|
File.open(path, "w") do |file|
|
123
154
|
file.puts modified_content
|
124
155
|
end
|
125
156
|
end
|
126
157
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
158
|
+
if component.starts_with?("avo/views/")
|
159
|
+
say "You can now use this component on any resource by configuring the 'self.components' option.\n" \
|
160
|
+
" self.components = {\n" \
|
161
|
+
" #{component.split("/").last}: #{component.camelize}\n" \
|
162
|
+
" }", :green
|
163
|
+
elsif component.starts_with?("avo/fields/")
|
164
|
+
say "You can now use this component on any field by configuring the 'components' option.\n" \
|
165
|
+
" field :name, as: :#{options["field-components"]}, components: {\n" \
|
166
|
+
" #{component.split("/").last}: #{component.camelize}\n" \
|
167
|
+
" }", :green
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def eject_field_components
|
173
|
+
# Check if the field exists
|
174
|
+
field_path = "lib/avo/fields/#{options["field-components"]}_field.rb"
|
175
|
+
return say("Failed to find the `#{options["field-components"]}` field.", :yellow) if !path_exists?(field_path)
|
176
|
+
|
177
|
+
# Eject single component if view is specified
|
178
|
+
if options[:view].present?
|
179
|
+
return eject_component "Avo::Fields::#{options["field-components"].camelize}Field::#{options[:view].camelize}Component"
|
180
|
+
end
|
181
|
+
|
182
|
+
# Check if the field components directory exist
|
183
|
+
components_path = "app/components/avo/fields/#{options["field-components"]}_field"
|
184
|
+
return say("Failed to find the `#{options["field-components"]}` field components.", :yellow) if !dir_exists?(components_path)
|
185
|
+
|
186
|
+
# Build the destination path for the components directory add the scope
|
187
|
+
destination_components_path = "#{::Avo.configuration.view_component_path}/#{components_path.gsub("app/components/", "")}"
|
188
|
+
|
189
|
+
if options[:scope].present?
|
190
|
+
destination_components_path = destination_components_path.gsub("avo/fields/", "avo/fields/#{options[:scope].underscore}/")
|
191
|
+
end
|
192
|
+
|
193
|
+
# Confirm the ejection
|
194
|
+
confirm_ejection_on destination_components_path, is_directory: true
|
195
|
+
|
196
|
+
# Eject the components directory
|
197
|
+
eject components_path, destination_components_path, is_directory: true
|
198
|
+
|
199
|
+
# Rename the component classes if scope was added
|
200
|
+
if options[:scope].present?
|
201
|
+
Dir.glob("#{destination_components_path}/*").each do |file|
|
202
|
+
modified_content = File.read(file).gsub("#{options["field-components"].camelize}Field", "#{options[:scope].camelize}::#{options["field-components"].camelize}Field")
|
203
|
+
|
204
|
+
File.open(file, "w") do |open_file|
|
205
|
+
open_file.puts modified_content
|
206
|
+
end
|
207
|
+
end
|
131
208
|
end
|
132
209
|
end
|
133
210
|
|
134
|
-
def confirm_ejection_on(path)
|
135
|
-
say("By ejecting the '#{path}' \033[1myou'll take on the responsibility for maintain it.", :yellow)
|
136
|
-
yes?("Are you sure you want to eject the '#{path}'? [y/N]", :yellow)
|
211
|
+
def confirm_ejection_on(path, is_directory: false)
|
212
|
+
say("By ejecting the '#{path}'#{" directory" if is_directory} \033[1myou'll take on the responsibility for maintain it.", :yellow)
|
213
|
+
yes?("Are you sure you want to eject the '#{path}'#{" directory" if is_directory}? [y/N]", :yellow)
|
137
214
|
end
|
138
215
|
|
139
216
|
def add_scope?(component)
|
140
|
-
component.starts_with?("avo/views/") && options[:scope].present?
|
217
|
+
(component.starts_with?("avo/views/") || component.starts_with?("avo/fields/")) && options[:scope].present?
|
141
218
|
end
|
142
219
|
end
|
143
220
|
end
|
@@ -21,7 +21,7 @@ module Generators
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def resource_class
|
24
|
-
|
24
|
+
class_name.remove(":").to_s
|
25
25
|
end
|
26
26
|
|
27
27
|
def controller_class
|
@@ -29,7 +29,7 @@ module Generators
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def resource_name
|
32
|
-
|
32
|
+
model_resource_name.to_s
|
33
33
|
end
|
34
34
|
|
35
35
|
def controller_name
|
@@ -139,12 +139,12 @@ module Generators
|
|
139
139
|
|
140
140
|
fields.each do |field_name, field_options|
|
141
141
|
# if field_options are not available (likely a missing resource for an association), skip the field
|
142
|
-
fields_string += "\n
|
142
|
+
fields_string += "\n # Could not generate a field for #{field_name}" and next unless field_options
|
143
143
|
|
144
144
|
options = ""
|
145
145
|
field_options[:options].each { |k, v| options += ", #{k}: #{v}" } if field_options[:options].present?
|
146
146
|
|
147
|
-
fields_string += "\n
|
147
|
+
fields_string += "\n #{field_string field_name, field_options[:field], options}"
|
148
148
|
end
|
149
149
|
|
150
150
|
fields_string
|
@@ -166,7 +166,7 @@ module Generators
|
|
166
166
|
|
167
167
|
def fields_from_model_rich_texts
|
168
168
|
rich_texts.each do |name, _|
|
169
|
-
fields[
|
169
|
+
fields[name.delete_prefix("rich_text_")] = {field: "trix"}
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
@@ -1,10 +1,15 @@
|
|
1
1
|
# For more information regarding these settings check out our docs https://docs.avohq.io
|
2
|
+
# The values disaplayed here are the default ones. Uncomment and change them to fit your needs.
|
2
3
|
Avo.configure do |config|
|
3
4
|
## == Routing ==
|
4
5
|
config.root_path = '/<%= options[:path] %>'
|
5
6
|
# used only when you have custom `map` configuration in your config.ru
|
6
7
|
# config.prefix_path = "/internal"
|
7
8
|
|
9
|
+
# Sometimes you migth want to mount Avo's engines yourself.
|
10
|
+
# https://docs.avohq.io/3.0/routing.html
|
11
|
+
# config.mount_avo_engines = true
|
12
|
+
|
8
13
|
# Where should the user be redirected when visting the `/<%= options[:path] %>` url
|
9
14
|
# config.home_path = nil
|
10
15
|
|