avo 3.0.0.pre19 → 3.0.1.beta1

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.

Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +25 -23
  4. data/Rakefile +0 -2
  5. data/app/assets/stylesheets/avo.base.css +0 -1
  6. data/app/components/avo/actions_component.rb +1 -1
  7. data/app/components/avo/field_wrapper_component.html.erb +1 -1
  8. data/app/components/avo/field_wrapper_component.rb +7 -1
  9. data/app/components/avo/fields/boolean_field/index_component.html.erb +1 -1
  10. data/app/components/avo/fields/common/badge_viewer_component.html.erb +24 -1
  11. data/app/components/avo/fields/common/badge_viewer_component.rb +0 -24
  12. data/app/components/avo/fields/common/boolean_check_component.html.erb +12 -1
  13. data/app/components/avo/fields/common/boolean_check_component.rb +1 -2
  14. data/app/components/avo/fields/common/gravatar_viewer_component.html.erb +1 -1
  15. data/app/components/avo/fields/common/gravatar_viewer_component.rb +2 -2
  16. data/app/components/avo/fields/common/heading_component.html.erb +8 -3
  17. data/app/components/avo/fields/common/heading_component.rb +3 -1
  18. data/app/components/avo/fields/common/key_value_component.html.erb +2 -2
  19. data/app/components/avo/fields/common/key_value_component.rb +2 -2
  20. data/app/components/avo/fields/common/progress_bar_component.rb +9 -3
  21. data/app/components/avo/fields/common/status_viewer_component.html.erb +0 -3
  22. data/app/components/avo/fields/edit_component.rb +1 -1
  23. data/app/components/avo/fields/external_image_field/index_component.html.erb +1 -1
  24. data/app/components/avo/fields/file_field/index_component.html.erb +2 -2
  25. data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
  26. data/app/components/avo/fields/heading_field/edit_component.html.erb +1 -1
  27. data/app/components/avo/fields/heading_field/show_component.html.erb +1 -1
  28. data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
  29. data/app/components/avo/fields/index_component.rb +1 -1
  30. data/app/components/avo/fields/show_component.rb +1 -1
  31. data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
  32. data/app/components/avo/index/field_wrapper_component.rb +1 -1
  33. data/app/components/avo/index/resource_controls_component.rb +1 -1
  34. data/app/components/avo/index/resource_table_component.rb +9 -3
  35. data/app/components/avo/resource_component.rb +4 -9
  36. data/app/components/avo/sidebar_profile_component.html.erb +4 -4
  37. data/app/components/avo/tab_group_component.html.erb +1 -1
  38. data/app/components/avo/tab_switcher_component.rb +2 -2
  39. data/app/components/avo/views/resource_edit_component.html.erb +20 -9
  40. data/app/components/avo/views/resource_edit_component.rb +5 -5
  41. data/app/components/avo/views/resource_index_component.rb +1 -1
  42. data/app/components/avo/views/resource_show_component.html.erb +1 -1
  43. data/app/components/avo/views/resource_show_component.rb +1 -1
  44. data/app/controllers/avo/actions_controller.rb +20 -9
  45. data/app/controllers/avo/application_controller.rb +5 -5
  46. data/app/controllers/avo/base_controller.rb +1 -39
  47. data/app/controllers/avo/search_controller.rb +2 -19
  48. data/app/controllers/concerns/avo/initializes_avo.rb +0 -1
  49. data/app/helpers/avo/resources_helper.rb +1 -1
  50. data/app/helpers/avo/url_helpers.rb +1 -1
  51. data/app/views/avo/base/edit.html.erb +1 -1
  52. data/app/views/avo/base/index.html.erb +1 -1
  53. data/app/views/avo/base/new.html.erb +1 -1
  54. data/app/views/avo/base/show.html.erb +1 -1
  55. data/app/views/layouts/avo/application.html.erb +2 -10
  56. data/bin/dev +0 -2
  57. data/config/master.key +1 -0
  58. data/config/routes.rb +3 -4
  59. data/db/factories.rb +1 -1
  60. data/lib/avo/base_action.rb +26 -21
  61. data/lib/avo/base_resource.rb +7 -13
  62. data/lib/avo/concerns/filters_session_handler.rb +3 -3
  63. data/lib/avo/concerns/has_items.rb +5 -1
  64. data/lib/avo/concerns/visible_in_different_views.rb +1 -7
  65. data/lib/avo/configuration.rb +4 -28
  66. data/lib/avo/current.rb +6 -1
  67. data/lib/avo/dsl/field_parser.rb +1 -1
  68. data/lib/avo/execution_context.rb +1 -4
  69. data/lib/avo/fields/badge_field.rb +1 -1
  70. data/lib/avo/fields/base_field.rb +44 -21
  71. data/lib/avo/fields/belongs_to_field.rb +1 -1
  72. data/lib/avo/fields/concerns/has_html_attributes.rb +0 -2
  73. data/lib/avo/fields/external_image_field.rb +2 -2
  74. data/lib/avo/fields/file_field.rb +2 -2
  75. data/lib/avo/fields/gravatar_field.rb +2 -2
  76. data/lib/avo/fields/has_base_field.rb +2 -2
  77. data/lib/avo/fields/heading_field.rb +13 -5
  78. data/lib/avo/fields/id_field.rb +2 -2
  79. data/lib/avo/fields/status_field.rb +1 -3
  80. data/lib/avo/fields/text_field.rb +2 -2
  81. data/lib/avo/filters/base_filter.rb +1 -1
  82. data/lib/avo/html/builder.rb +1 -1
  83. data/lib/avo/licensing/h_q.rb +1 -1
  84. data/lib/avo/licensing/license_manager.rb +1 -1
  85. data/lib/avo/resources/items/holder.rb +6 -0
  86. data/lib/avo/resources/items/item_group.rb +2 -2
  87. data/lib/avo/resources/items/row.rb +3 -3
  88. data/lib/avo/resources/items/sidebar.rb +1 -1
  89. data/lib/avo/resources/items/tab.rb +2 -2
  90. data/lib/avo/resources/items/tab_group.rb +1 -1
  91. data/lib/avo/resources/resource_manager.rb +1 -6
  92. data/lib/avo/version.rb +1 -1
  93. data/lib/avo.rb +0 -9
  94. data/lib/generators/avo/controller_generator.rb +0 -3
  95. data/lib/generators/avo/eject_generator.rb +15 -180
  96. data/lib/generators/avo/field_generator.rb +2 -49
  97. data/lib/generators/avo/js/install_generator.rb +2 -2
  98. data/lib/generators/avo/resource_generator.rb +7 -10
  99. data/lib/generators/avo/tailwindcss/install_generator.rb +12 -58
  100. data/lib/generators/avo/templates/initializer/avo.tt +1 -6
  101. data/lib/generators/avo/templates/resource/controller.tt +1 -1
  102. data/lib/generators/avo/templates/tailwindcss/avo.tailwind.css +3 -5
  103. data/lib/tasks/avo_tasks.rake +5 -33
  104. data/public/avo-assets/avo.base.css +4146 -75
  105. data/{app/assets/builds/avo.base.css → public/avo-assets/avo.css} +3808 -547
  106. data/public/avo-assets/avo.js +513 -0
  107. data/public/avo-assets/avo.js.map +7 -0
  108. metadata +6 -14
  109. data/app/assets/builds/avo.base.js +0 -124556
  110. data/app/assets/builds/avo.base.js.map +0 -7
  111. data/app/assets/builds/avo.custom.js +0 -6
  112. data/app/assets/builds/avo.custom.js.map +0 -7
  113. data/app/assets/stylesheets/css/fields/tags.css +0 -32
  114. data/lib/avo/concerns/has_helpers.rb +0 -18
  115. data/lib/avo/concerns/visible_items.rb +0 -43
  116. data/lib/avo/fields/concerns/use_view_components.rb +0 -45
  117. data/lib/avo/view_inquirer.rb +0 -36
  118. data/lib/generators/avo/concerns/parent_controller.rb +0 -20
  119. data/lib/generators/avo/templates/tailwindcss/tailwind.config.js +0 -11
@@ -30,6 +30,10 @@ module Avo
30
30
  deprecated_dsl_api __method__, "fields"
31
31
  end
32
32
 
33
+ def heading(body, **args)
34
+ deprecated_dsl_api __method__, "fields"
35
+ end
36
+
33
37
  def sidebar(**args, &block)
34
38
  deprecated_dsl_api __method__, "fields"
35
39
  end
@@ -269,7 +273,7 @@ module Avo
269
273
  end
270
274
  .select do |item|
271
275
  # On location field we can have field coordinates and setters with different names like latitude and longitude
272
- if !item.is_a?(Avo::Fields::LocationField) && !item.is_heading? && view.in?(%w[edit update new create])
276
+ if !item.is_a?(Avo::Fields::LocationField) && !item.is_heading? && view.in?([:edit, :update, :new, :create])
273
277
  if item.respond_to?(:id)
274
278
  item.resource.record.respond_to?("#{item.id}=")
275
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
- hide_on_view view
64
+ show_on_view view
65
65
  end
66
66
  end
67
67
 
@@ -113,18 +113,12 @@ 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]
117
116
 
118
117
  if forms.present?
119
118
  views_and_groups -= forms
120
119
  views_and_groups += [:new, :edit]
121
120
  end
122
121
 
123
- if display.present?
124
- views_and_groups -= display
125
- views_and_groups += [:index, :show]
126
- end
127
-
128
122
  views_and_groups.flatten.uniq
129
123
  end
130
124
  end
@@ -12,6 +12,7 @@ module Avo
12
12
  attr_accessor :locale
13
13
  attr_accessor :currency
14
14
  attr_accessor :default_view_type
15
+ attr_accessor :license
15
16
  attr_accessor :license_key
16
17
  attr_accessor :authorization_methods
17
18
  attr_accessor :authenticate
@@ -36,14 +37,12 @@ module Avo
36
37
  attr_accessor :main_menu
37
38
  attr_accessor :profile_menu
38
39
  attr_accessor :model_resource_mapping
39
- attr_reader :resource_default_view
40
+ attr_accessor :resource_default_view
40
41
  attr_accessor :authorization_client
41
42
  attr_accessor :field_wrapper_layout
42
43
  attr_accessor :sign_out_path_name
43
44
  attr_accessor :resources
44
45
  attr_accessor :prefix_path
45
- attr_accessor :resource_parent_controller
46
- attr_accessor :mount_avo_engines
47
46
 
48
47
  def initialize
49
48
  @root_path = "/avo"
@@ -55,6 +54,7 @@ module Avo
55
54
  @locale = nil
56
55
  @currency = "USD"
57
56
  @default_view_type = :table
57
+ @license = "community"
58
58
  @license_key = nil
59
59
  @current_user = proc {}
60
60
  @authenticate = proc {}
@@ -89,12 +89,10 @@ module Avo
89
89
  @main_menu = nil
90
90
  @profile_menu = nil
91
91
  @model_resource_mapping = {}
92
- @resource_default_view = Avo::ViewInquirer.new("show")
92
+ @resource_default_view = :show
93
93
  @authorization_client = :pundit
94
94
  @field_wrapper_layout = :inline
95
95
  @resources = nil
96
- @resource_parent_controller = "Avo::ResourcesController"
97
- @mount_avo_engines = true
98
96
  end
99
97
 
100
98
  def current_user_method(&block)
@@ -142,28 +140,6 @@ module Avo
142
140
  def app_name
143
141
  Avo::ExecutionContext.new(target: @app_name).handle
144
142
  end
145
-
146
- def license=(value)
147
- if Rails.env.development?
148
- puts "[Avo DEPRECATION WARNING]: The `config.license` configuration option is no longer supported and will be removed in future versions. Please discontinue its use and solely utilize the `license_key` instead."
149
- end
150
- end
151
-
152
- def license
153
- gems = Gem::Specification.map {|gem| gem.name}
154
-
155
- @license ||= if gems.include?("avo-advanced")
156
- "advanced"
157
- elsif gems.include?("avo-pro")
158
- "pro"
159
- elsif gems.include?("avo")
160
- "community"
161
- end
162
- end
163
-
164
- def resource_default_view=(view)
165
- @resource_default_view = Avo::ViewInquirer.new(view.to_s)
166
- end
167
143
  end
168
144
 
169
145
  def self.configuration
data/lib/avo/current.rb CHANGED
@@ -24,11 +24,16 @@ class Avo::Current < ActiveSupport::CurrentAttributes
24
24
  attribute :resource_manager
25
25
  attribute :tool_manager
26
26
  attribute :plugin_manager
27
- attribute :locale
28
27
 
29
28
  delegate :params, to: :request
30
29
 
31
30
  def request
32
31
  view_context.request || ActionDispatch::Request.empty
33
32
  end
33
+
34
+ def current_user
35
+ Rails.logger.warn "DEPRECATION WARNING: Avo::Current.current_user become deprecated and will become obsolete on futhure versions. Please use Avo::Current.user instead."
36
+
37
+ user
38
+ end
34
39
  end
@@ -47,7 +47,7 @@ module Avo
47
47
  else
48
48
  # The symbol can be transformed to a class and found.
49
49
  class_name = as.to_s.camelize
50
- field_class = "Avo::Fields::#{class_name}Field"
50
+ field_class = "#{class_name}Field"
51
51
 
52
52
  # Discover & load custom field classes
53
53
  if Object.const_defined? field_class
@@ -1,8 +1,6 @@
1
1
  module Avo
2
2
  class ExecutionContext
3
- include Avo::Concerns::HasHelpers
4
-
5
- attr_accessor :target, :context, :params, :view_context, :current_user, :request, :include, :main_app, :avo, :locale
3
+ attr_accessor :target, :context, :params, :view_context, :current_user, :request, :include, :main_app, :avo
6
4
 
7
5
  def initialize(**args)
8
6
  # Extend the class with custom modules if required.
@@ -26,7 +24,6 @@ module Avo
26
24
  @params ||= Avo::Current.params
27
25
  @request ||= Avo::Current.request
28
26
  @view_context ||= Avo::Current.view_context
29
- @locale ||= Avo::Current.locale
30
27
  @main_app ||= @view_context.main_app
31
28
  @avo ||= @view_context.avo
32
29
  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, neutral: :neutral}
11
+ default_options = {info: :info, success: :success, danger: :danger, warning: :warning}
12
12
  @options = args[:options].present? ? default_options.merge(args[:options]) : default_options
13
13
  end
14
14
  end
@@ -7,7 +7,6 @@ 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
11
10
  include Avo::Fields::Concerns::HasFieldName
12
11
  include Avo::Fields::Concerns::HasDefault
13
12
  include Avo::Fields::Concerns::HasHTMLAttributes
@@ -15,7 +14,6 @@ module Avo
15
14
  include Avo::Fields::Concerns::IsReadonly
16
15
  include Avo::Fields::Concerns::IsDisabled
17
16
  include Avo::Fields::Concerns::IsRequired
18
- include Avo::Fields::Concerns::UseViewComponents
19
17
 
20
18
  include ActionView::Helpers::UrlHelper
21
19
 
@@ -75,12 +73,11 @@ module Avo
75
73
  @visible = args[:visible]
76
74
  @as_avatar = args[:as_avatar] || false
77
75
  @html = args[:html] || nil
78
- @view = Avo::ViewInquirer.new(args[:view]) || nil
76
+ @view = args[:view] || nil
79
77
  @value = args[:value] || nil
80
78
  @stacked = args[:stacked] || nil
81
79
  @for_presentation_only = args[:for_presentation_only] || false
82
80
  @resource = args[:resource]
83
- @components = args[:components] || {}
84
81
 
85
82
  @args = args
86
83
 
@@ -158,7 +155,14 @@ module Avo
158
155
 
159
156
  # Run computable callback block if present
160
157
  if computable && block.present?
161
- final_value = execute_block
158
+ final_value = Avo::ExecutionContext.new(
159
+ target: block,
160
+ record: record,
161
+ resource: @resource,
162
+ view: @view,
163
+ field: self,
164
+ include: self.class.included_modules
165
+ ).handle
162
166
  end
163
167
 
164
168
  # Run the value through resolver if present
@@ -177,17 +181,6 @@ module Avo
177
181
  final_value
178
182
  end
179
183
 
180
- def execute_block
181
- Avo::ExecutionContext.new(
182
- target: block,
183
- record: record,
184
- resource: resource,
185
- view: view,
186
- field: self,
187
- include: self.class.included_modules
188
- ).handle
189
- end
190
-
191
184
  # Fills the record with the received value on create and update actions.
192
185
  def fill_field(record, key, value, params)
193
186
  return record unless record.methods.include? key.to_sym
@@ -199,8 +192,7 @@ module Avo
199
192
  key: key,
200
193
  value: value,
201
194
  resource: resource,
202
- field: self,
203
- include: self.class.included_modules
195
+ field: self
204
196
  ).handle
205
197
  end
206
198
 
@@ -228,8 +220,35 @@ module Avo
228
220
  id.to_sym
229
221
  end
230
222
 
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
+
231
248
  def record_errors
232
- record.nil? ? {} : record.errors
249
+ return {} if record.nil?
250
+
251
+ record.errors
233
252
  end
234
253
 
235
254
  def type
@@ -270,7 +289,11 @@ module Avo
270
289
  private
271
290
 
272
291
  def model_or_class(model)
273
- model.instance_of?(String) ? "class" : "model"
292
+ if model.instance_of?(String)
293
+ "class"
294
+ else
295
+ "model"
296
+ end
274
297
  end
275
298
 
276
299
  def is_model?(model)
@@ -282,7 +305,7 @@ module Avo
282
305
  end
283
306
 
284
307
  def on_create?
285
- @view.in?(%w[new create])
308
+ @view.in?([:new, :create])
286
309
  end
287
310
 
288
311
  def in_action?
@@ -259,7 +259,7 @@ module Avo
259
259
  end
260
260
 
261
261
  def name
262
- return polymorphic_as.to_s.humanize if polymorphic_as.present? && view.index?
262
+ return polymorphic_as.to_s.humanize if polymorphic_as.present? && view == :index
263
263
 
264
264
  super
265
265
  end
@@ -13,8 +13,6 @@ 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
-
18
16
  if [view, element].any?(&:nil?)
19
17
  default_attribute_value name
20
18
  end
@@ -4,12 +4,12 @@ module Avo
4
4
  attr_reader :width
5
5
  attr_reader :height
6
6
  attr_reader :radius
7
- attr_reader :link_to_record
7
+ attr_reader :link_to_resource
8
8
 
9
9
  def initialize(id, **args, &block)
10
10
  super(id, **args, &block)
11
11
 
12
- @link_to_record = args[:link_to_record].present? ? args[:link_to_record] : false
12
+ @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
13
13
 
14
14
  @width = args[:width].present? ? args[:width] : 40
15
15
  @height = args[:height].present? ? args[:height] : 40
@@ -1,7 +1,7 @@
1
1
  module Avo
2
2
  module Fields
3
3
  class FileField < BaseField
4
- attr_accessor :link_to_record
4
+ attr_accessor :link_to_resource
5
5
  attr_accessor :is_avatar
6
6
  attr_accessor :is_image
7
7
  attr_accessor :is_audio
@@ -12,7 +12,7 @@ module Avo
12
12
  def initialize(id, **args, &block)
13
13
  super(id, **args, &block)
14
14
 
15
- @link_to_record = args[:link_to_record].present? ? args[:link_to_record] : false
15
+ @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
16
16
  @is_avatar = args[:is_avatar].present? ? args[:is_avatar] : false
17
17
  @is_image = args[:is_image].present? ? args[:is_image] : @is_avatar
18
18
  @is_audio = args[:is_audio].present? ? args[:is_audio] : false
@@ -4,7 +4,7 @@ require "erb"
4
4
  module Avo
5
5
  module Fields
6
6
  class GravatarField < BaseField
7
- attr_reader :link_to_record
7
+ attr_reader :link_to_resource
8
8
  attr_reader :rounded
9
9
  attr_reader :size
10
10
  attr_reader :default
@@ -16,7 +16,7 @@ module Avo
16
16
 
17
17
  hide_on [:edit, :new]
18
18
 
19
- @link_to_record = args[:link_to_record].present? ? args[:link_to_record] : false
19
+ @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
20
20
  @rounded = args[:rounded].nil? ? true : args[:rounded]
21
21
  @size = args[:size].present? ? args[:size].to_i : 32
22
22
  @default = args[:default].present? ? ERB::Util.url_encode(args[:default]).to_s : ""
@@ -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 = Avo::ViewInquirer.new("index"))
83
- view = Avo::ViewInquirer.new("show") if view.in? %w[new create update edit]
82
+ def component_for_view(view = :index)
83
+ view = :show if view.in? [:new, :create, :update, :edit]
84
84
 
85
85
  super view
86
86
  end
@@ -4,27 +4,35 @@ module Avo
4
4
  module Fields
5
5
  class HeadingField < BaseField
6
6
  attr_reader :as_html
7
+ attr_reader :empty
8
+
9
+ def initialize(content, **args, &block)
10
+ # Mark the field as empty if there's no content passed
11
+ @empty = content.blank?
12
+ # Add dummy content
13
+ content ||= SecureRandom.hex
7
14
 
8
- def initialize(id, **args, &block)
9
15
  args[:updatable] = false
10
- @label = args[:label] || id.to_s.humanize
11
16
 
12
- super(id, **args, &block)
17
+ super(content, **args, &block)
13
18
 
14
19
  # this field is not used to update anything
15
20
  @for_presentation_only = true
16
21
 
17
22
  hide_on :index
18
23
 
19
- @as_html = args[:as_html].presence || false
24
+ @as_html = args[:as_html].present? ? args[:as_html] : false
20
25
  end
21
26
 
22
27
  def id
23
28
  "heading_#{name.to_s.parameterize.underscore}"
24
29
  end
25
30
 
31
+ # Override the value method if the field is empty
26
32
  def value
27
- block.present? ? execute_block : @label
33
+ return nil if empty
34
+
35
+ super
28
36
  end
29
37
  end
30
38
  end
@@ -1,7 +1,7 @@
1
1
  module Avo
2
2
  module Fields
3
3
  class IdField < BaseField
4
- attr_reader :link_to_record
4
+ attr_reader :link_to_resource
5
5
 
6
6
  def initialize(id, **args, &block)
7
7
  args[:readonly] = true
@@ -12,7 +12,7 @@ module Avo
12
12
 
13
13
  add_boolean_prop args, :sortable, true
14
14
 
15
- @link_to_record = args[:link_to_record].present? ? args[:link_to_record] : false
15
+ @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
16
16
  end
17
17
  end
18
18
  end
@@ -6,15 +6,13 @@ module Avo
6
6
 
7
7
  @loading_when = args[:loading_when].present? ? [args[:loading_when]].flatten.map(&:to_sym) : [:waiting, :running]
8
8
  @failed_when = args[:failed_when].present? ? [args[:failed_when]].flatten.map(&:to_sym) : [:failed]
9
- @success_when = args[:success_when].present? ? [args[:success_when]].flatten.map(&:to_sym) : []
10
9
  end
11
10
 
12
11
  def status
13
- status = "neutral"
12
+ status = "success"
14
13
  if value.present?
15
14
  status = "failed" if @failed_when.include? value.to_sym
16
15
  status = "loading" if @loading_when.include? value.to_sym
17
- status = "success" if @success_when.include? value.to_sym
18
16
  end
19
17
 
20
18
  status
@@ -1,14 +1,14 @@
1
1
  module Avo
2
2
  module Fields
3
3
  class TextField < BaseField
4
- attr_reader :link_to_record
4
+ attr_reader :link_to_resource
5
5
  attr_reader :as_html
6
6
  attr_reader :protocol
7
7
 
8
8
  def initialize(id, **args, &block)
9
9
  super(id, **args, &block)
10
10
 
11
- add_boolean_prop args, :link_to_record
11
+ add_boolean_prop args, :link_to_resource
12
12
  add_boolean_prop args, :as_html
13
13
  add_string_prop args, :protocol
14
14
  end
@@ -15,7 +15,7 @@ module Avo
15
15
  delegate :params, to: Avo::Current
16
16
  delegate :request, to: Avo::Current
17
17
  delegate :view_context, to: Avo::Current
18
- def current_user
18
+ def curent_user
19
19
  Avo::Current.user
20
20
  end
21
21
 
@@ -22,7 +22,7 @@ class Avo::HTML::Builder
22
22
  delegate :app, to: Avo::Current
23
23
  delegate :root_path, to: :app
24
24
  delegate :params, to: Avo::Current
25
- def current_user
25
+ def curent_user
26
26
  Avo::Current.user
27
27
  end
28
28
 
@@ -5,7 +5,7 @@ module Avo
5
5
  attr_accessor :cache_store
6
6
 
7
7
  # ENDPOINT = "https://v3.avohq.io/api/v1/licenses/check".freeze unless const_defined?(:ENDPOINT)
8
- ENDPOINT = "https://avohq.io/api/v1/licenses/check".freeze unless const_defined?(:ENDPOINT)
8
+ # ENDPOINT = "https://avohq.io/api/v1/licenses/check".freeze unless const_defined?(:ENDPOINT)
9
9
  REQUEST_TIMEOUT = 5 unless const_defined?(:REQUEST_TIMEOUT) # seconds
10
10
  CACHE_TIME = 3600 unless const_defined?(:CACHE_TIME) # seconds
11
11
 
@@ -9,7 +9,7 @@ module Avo
9
9
  case @hq_response["id"]
10
10
  when "community"
11
11
  CommunityLicense.new @hq_response
12
- when "pro", "advanced"
12
+ when "pro"
13
13
  ProLicense.new @hq_response
14
14
  else
15
15
  NilLicense.new @hq_response
@@ -56,6 +56,12 @@ class Avo::Resources::Items::Holder
56
56
  add_item panel
57
57
  end
58
58
 
59
+ def heading(body = nil, **args, &block)
60
+ field = Avo::Fields::HeadingField.new(body, **args)
61
+
62
+ add_item field
63
+ end
64
+
59
65
  def sidebar(**args, &block)
60
66
  add_item Avo::Resources::Items::Sidebar::Builder.parse_block(**args, &block)
61
67
  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::VisibleItems
6
+ include Avo::Concerns::IsVisible
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 = Avo::ViewInquirer.new view
16
+ @view = 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::VisibleItems
5
+ include Avo::Concerns::IsVisible
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 = Avo::ViewInquirer.new view
15
+ @view = 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 = Avo::ViewInquirer.new view
20
+ @view = 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 = Avo::ViewInquirer.new view
16
+ @view = 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::VisibleItems
6
+ include Avo::Concerns::IsVisible
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 = Avo::ViewInquirer.new view
17
+ @view = view
18
18
  @args = args
19
19
 
20
20
  post_initialize if respond_to?(:post_initialize)
@@ -12,7 +12,7 @@ class Avo::Resources::Items::TabGroup
12
12
  def initialize(index: 0, view: nil, style: nil, **args)
13
13
  @index = index
14
14
  @items_holder = Avo::Resources::Items::Holder.new
15
- @view = Avo::ViewInquirer.new view
15
+ @view = view
16
16
  @style = style
17
17
  @args = args
18
18
 
@@ -152,12 +152,7 @@ module Avo
152
152
  def get_available_resources(user = nil)
153
153
  valid_resources
154
154
  .select do |resource|
155
- resource.authorization.class.authorize(
156
- user,
157
- resource.model_class,
158
- Avo.configuration.authorization_methods.stringify_keys["index"],
159
- raise_exception: false
160
- )
155
+ Services::AuthorizationService.authorize user, resource.model_class, Avo.configuration.authorization_methods.stringify_keys["index"], raise_exception: false
161
156
  end
162
157
  .sort_by { |r| r.name }
163
158
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.0.0.pre19" unless const_defined?(:VERSION)
2
+ VERSION = "3.0.1.beta1" unless const_defined?(:VERSION)
3
3
  end
data/lib/avo.rb CHANGED
@@ -116,15 +116,6 @@ 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
-
128
119
  private
129
120
 
130
121
  def boot_logger