avo 2.17.1.pre.5.stackedlayout → 2.18.1.pre.1.eagerloaddirs

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +74 -72
  4. data/app/components/avo/base_component.rb +16 -0
  5. data/app/components/avo/fields/index_component.rb +4 -3
  6. data/app/components/avo/index/grid_item_component.rb +2 -2
  7. data/app/components/avo/index/resource_controls_component.rb +2 -2
  8. data/app/components/avo/index/table_row_component.html.erb +1 -1
  9. data/app/components/avo/item_switcher_component.html.erb +1 -1
  10. data/app/components/avo/resource_component.rb +1 -1
  11. data/app/components/avo/resource_sidebar_component.rb +1 -6
  12. data/app/components/avo/tab_group_component.rb +1 -1
  13. data/app/controllers/avo/application_controller.rb +6 -0
  14. data/app/controllers/avo/dashboards/cards_controller.rb +37 -0
  15. data/app/views/avo/{cards → dashboards/cards}/_chartkick_card.html.erb +0 -0
  16. data/app/views/avo/{cards → dashboards/cards}/_metric_card.html.erb +0 -0
  17. data/app/views/avo/{cards → dashboards/cards}/chartkick_missing.html.erb +0 -0
  18. data/app/views/avo/{cards → dashboards/cards}/show.html.erb +0 -0
  19. data/avo.gemspec +1 -1
  20. data/config/routes.rb +2 -2
  21. data/db/factories.rb +5 -0
  22. data/lib/avo/app.rb +11 -1
  23. data/lib/avo/base_action.rb +2 -2
  24. data/lib/avo/base_resource.rb +3 -6
  25. data/lib/avo/concerns/has_fields.rb +2 -0
  26. data/lib/avo/concerns/visible_items.rb +44 -0
  27. data/lib/avo/configuration/branding.rb +1 -1
  28. data/lib/avo/dynamic_router.rb +16 -15
  29. data/lib/avo/engine.rb +1 -9
  30. data/lib/avo/fields/base_field.rb +1 -1
  31. data/lib/avo/fields/has_base_field.rb +2 -0
  32. data/lib/avo/panel.rb +4 -1
  33. data/lib/avo/sidebar.rb +1 -31
  34. data/lib/avo/tab.rb +5 -22
  35. data/lib/avo/version.rb +1 -1
  36. data/lib/avo.rb +9 -0
  37. data/public/avo-assets/avo.base.css +10 -10
  38. data/{app/assets/svgs → public/avo-assets}/placeholder.svg +0 -0
  39. metadata +11 -10
  40. data/app/controllers/avo/cards_controller.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff184a72962903e95adcf3441d0e964f69d25664ea4c2b2e3581b520220339a2
4
- data.tar.gz: f2eebedd7b8ec0eb879116109e47b772cdf66d2ece017f532a1bf920cd6a4813
3
+ metadata.gz: dedb3bcead6abca3b563cf3c407486f240cd1f93af38c3d3c6edec9605266119
4
+ data.tar.gz: '09dcd70c7db58cdd1c13a5ced9a3b75bc5b7ed5afc8ecf4c24237ade4f67f417'
5
5
  SHA512:
6
- metadata.gz: 6548dc91057871f9529223985d8b42b26dc6253af4b4f5c98fba3c73ec04f9db4ed2eeaae759b40e8884323e5ed62703c4e430bec15a95c703998885ae78af71
7
- data.tar.gz: 8a47d790300bc6529cd143e6981630eb4f4077ef07b679c47132b0425e4b23e2310993466a0e761118e9cce1c633aa3af9ccf21dce30625089148f0f7976880b
6
+ metadata.gz: e918b0789be4e669df92c80870d16a94c2ae9a33dd8db7ef9498a1cf1d50a06d4d7074d7eb79a1da321bf0f8e7398e3061cb3f92d2fe62a1c2902b7aa79b2a3f
7
+ data.tar.gz: b6cc344b4ecc7b590219eed82708bf81ea21f006ce6a070c07e79aff53835af3ee2a12262a48f4261d223f2f96a85cd73c0eac21c2e8651a6cd002d5270b09e3
data/Gemfile CHANGED
@@ -102,14 +102,12 @@ group :test do
102
102
  gem "launchy", require: false
103
103
 
104
104
  gem "test-prof"
105
-
106
- gem "sprockets-rails"
107
105
  end
108
106
 
109
107
  gem "rubocop"
110
108
  gem "rubocop-shopify", require: false
111
109
 
112
- gem "zeitwerk", "~> 2.3"
110
+ gem "zeitwerk"
113
111
 
114
112
  gem "httparty"
115
113
 
@@ -160,6 +158,8 @@ gem "chartkick"
160
158
 
161
159
  # Avo file filed requires this gem
162
160
  gem "activestorage"
161
+ # Required by Avo
162
+ gem "sprockets-rails"
163
163
 
164
164
  # Avo file filed requires this gem
165
165
  # Use Active Storage variant
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.17.1.pre.5.stackedlayout)
4
+ avo (2.18.1.pre.1.eagerloaddirs)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
@@ -15,7 +15,7 @@ PATH
15
15
  pagy
16
16
  turbo-rails
17
17
  view_component
18
- zeitwerk
18
+ zeitwerk (>= 2.6.2)
19
19
 
20
20
  GEM
21
21
  remote: https://rubygems.org/
@@ -88,8 +88,8 @@ GEM
88
88
  activerecord (>= 6.0, < 7.1)
89
89
  acts_as_list (1.0.4)
90
90
  activerecord (>= 4.2)
91
- addressable (2.8.0)
92
- public_suffix (>= 2.0.2, < 5.0)
91
+ addressable (2.8.1)
92
+ public_suffix (>= 2.0.2, < 6.0)
93
93
  annotate (3.2.0)
94
94
  activerecord (>= 3.2, < 8.0)
95
95
  rake (>= 10.4, < 14.0)
@@ -100,22 +100,22 @@ GEM
100
100
  ast (2.4.2)
101
101
  awesome_print (1.9.2)
102
102
  aws-eventstream (1.2.0)
103
- aws-partitions (1.551.0)
104
- aws-sdk-core (3.125.5)
103
+ aws-partitions (1.621.0)
104
+ aws-sdk-core (3.134.0)
105
105
  aws-eventstream (~> 1, >= 1.0.2)
106
106
  aws-partitions (~> 1, >= 1.525.0)
107
107
  aws-sigv4 (~> 1.1)
108
- jmespath (~> 1.0)
109
- aws-sdk-kms (1.53.0)
110
- aws-sdk-core (~> 3, >= 3.125.0)
108
+ jmespath (~> 1, >= 1.6.1)
109
+ aws-sdk-kms (1.58.0)
110
+ aws-sdk-core (~> 3, >= 3.127.0)
111
111
  aws-sigv4 (~> 1.1)
112
- aws-sdk-s3 (1.111.3)
113
- aws-sdk-core (~> 3, >= 3.125.0)
112
+ aws-sdk-s3 (1.114.0)
113
+ aws-sdk-core (~> 3, >= 3.127.0)
114
114
  aws-sdk-kms (~> 1)
115
115
  aws-sigv4 (~> 1.4)
116
- aws-sigv4 (1.4.0)
116
+ aws-sigv4 (1.5.1)
117
117
  aws-eventstream (~> 1, >= 1.0.2)
118
- bcrypt (3.1.16)
118
+ bcrypt (3.1.18)
119
119
  better_html (2.0.1)
120
120
  actionview (>= 6.0)
121
121
  activesupport (>= 6.0)
@@ -131,7 +131,7 @@ GEM
131
131
  railties (>= 5.0)
132
132
  builder (3.2.4)
133
133
  bump (0.10.0)
134
- bundler-integrity (1.0.7)
134
+ bundler-integrity (1.0.9)
135
135
  byebug (11.1.3)
136
136
  capybara (3.36.0)
137
137
  addressable
@@ -150,7 +150,7 @@ GEM
150
150
  crack (0.4.5)
151
151
  rexml
152
152
  crass (1.0.6)
153
- cssbundling-rails (1.0.0)
153
+ cssbundling-rails (1.1.1)
154
154
  railties (>= 6.0.0)
155
155
  database_cleaner (2.0.1)
156
156
  database_cleaner-active_record (~> 2.0.0)
@@ -167,20 +167,20 @@ GEM
167
167
  diff-lcs (1.5.0)
168
168
  digest (3.1.0)
169
169
  docile (1.4.0)
170
- dotenv (2.7.6)
171
- dotenv-rails (2.7.6)
172
- dotenv (= 2.7.6)
170
+ dotenv (2.8.1)
171
+ dotenv-rails (2.8.1)
172
+ dotenv (= 2.8.1)
173
173
  railties (>= 3.2)
174
174
  dry-initializer (3.1.1)
175
175
  erb-formatter (0.3.0)
176
176
  erubi (1.11.0)
177
- factory_bot (6.2.0)
177
+ factory_bot (6.2.1)
178
178
  activesupport (>= 5.0.0)
179
179
  factory_bot_rails (6.2.0)
180
180
  factory_bot (~> 6.2.0)
181
181
  railties (>= 5.0.0)
182
- faker (2.19.0)
183
- i18n (>= 1.6, < 2)
182
+ faker (2.22.0)
183
+ i18n (>= 1.8.11, < 2)
184
184
  ffi (1.15.5)
185
185
  friendly_id (5.4.2)
186
186
  activerecord (>= 4.0.0)
@@ -190,16 +190,16 @@ GEM
190
190
  gem-release (2.2.2)
191
191
  globalid (1.0.0)
192
192
  activesupport (>= 5.0)
193
- groupdate (5.2.4)
194
- activesupport (>= 5)
193
+ groupdate (6.1.0)
194
+ activesupport (>= 5.2)
195
195
  hashdiff (1.0.1)
196
196
  highline (2.0.3)
197
197
  hightop (0.3.0)
198
198
  activesupport (>= 5.2)
199
- hotwire-livereload (1.1.0)
199
+ hotwire-livereload (1.2.2)
200
200
  listen (>= 3.0.0)
201
201
  rails (>= 6.0.0)
202
- htmlbeautifier (1.4.1)
202
+ htmlbeautifier (1.4.2)
203
203
  httparty (0.20.0)
204
204
  mime-types (~> 3.0)
205
205
  multi_xml (>= 0.5.2)
@@ -222,12 +222,12 @@ GEM
222
222
  inline_svg (1.8.0)
223
223
  activesupport (>= 3.0)
224
224
  nokogiri (>= 1.6)
225
- io-wait (0.2.1)
226
225
  iso (0.4.0)
227
226
  i18n
228
227
  jmespath (1.6.1)
229
- jsbundling-rails (1.0.0)
228
+ jsbundling-rails (1.0.3)
230
229
  railties (>= 6.0.0)
230
+ json (2.6.2)
231
231
  launchy (2.5.0)
232
232
  addressable (~> 2.7)
233
233
  listen (3.7.1)
@@ -243,7 +243,7 @@ GEM
243
243
  zeitwerk
244
244
  marcel (1.0.2)
245
245
  matrix (0.4.2)
246
- meta-tags (2.16.0)
246
+ meta-tags (2.17.0)
247
247
  actionpack (>= 3.2.0, < 7.1)
248
248
  method_source (1.0.0)
249
249
  mime-types (3.4.1)
@@ -253,10 +253,9 @@ GEM
253
253
  mini_mime (1.1.2)
254
254
  mini_portile2 (2.8.0)
255
255
  minitest (5.16.3)
256
- msgpack (1.6.0)
256
+ msgpack (1.5.6)
257
257
  multi_xml (0.6.0)
258
- net-protocol (0.1.2)
259
- io-wait
258
+ net-protocol (0.1.3)
260
259
  timeout
261
260
  net-smtp (0.3.1)
262
261
  digest
@@ -271,12 +270,12 @@ GEM
271
270
  orm_adapter (0.5.0)
272
271
  pagy (5.10.1)
273
272
  activesupport
274
- parallel (1.21.0)
275
- parser (3.1.0.0)
273
+ parallel (1.22.1)
274
+ parser (3.1.2.1)
276
275
  ast (~> 2.4.1)
277
- pg (1.3.1)
278
- public_suffix (4.0.6)
279
- puma (5.6.4)
276
+ pg (1.4.3)
277
+ public_suffix (5.0.0)
278
+ puma (5.6.5)
280
279
  nio4r (~> 2.0)
281
280
  pundit (2.2.0)
282
281
  activesupport (>= 3.0.0)
@@ -319,27 +318,27 @@ GEM
319
318
  thor (~> 1.0)
320
319
  rainbow (3.1.1)
321
320
  rake (13.0.6)
322
- ransack (2.5.0)
323
- activerecord (>= 5.2.4)
324
- activesupport (>= 5.2.4)
321
+ ransack (3.2.1)
322
+ activerecord (>= 6.1.5)
323
+ activesupport (>= 6.1.5)
325
324
  i18n
326
- rb-fsevent (0.11.0)
325
+ rb-fsevent (0.11.1)
327
326
  rb-inotify (0.10.1)
328
327
  ffi (~> 1.0)
329
- redis (4.6.0)
330
- regexp_parser (2.2.0)
328
+ redis (4.8.0)
329
+ regexp_parser (2.5.0)
331
330
  responders (3.0.1)
332
331
  actionpack (>= 5.0)
333
332
  railties (>= 5.0)
334
333
  rexml (3.2.5)
335
- rspec-core (3.10.2)
336
- rspec-support (~> 3.10.0)
337
- rspec-expectations (3.10.2)
334
+ rspec-core (3.11.0)
335
+ rspec-support (~> 3.11.0)
336
+ rspec-expectations (3.11.0)
338
337
  diff-lcs (>= 1.2.0, < 2.0)
339
- rspec-support (~> 3.10.0)
340
- rspec-mocks (3.10.3)
338
+ rspec-support (~> 3.11.0)
339
+ rspec-mocks (3.11.1)
341
340
  diff-lcs (>= 1.2.0, < 2.0)
342
- rspec-support (~> 3.10.0)
341
+ rspec-support (~> 3.11.0)
343
342
  rspec-rails (4.0.2)
344
343
  actionpack (>= 4.2)
345
344
  activesupport (>= 4.2)
@@ -348,33 +347,35 @@ GEM
348
347
  rspec-expectations (~> 3.10)
349
348
  rspec-mocks (~> 3.10)
350
349
  rspec-support (~> 3.10)
351
- rspec-support (3.10.3)
352
- rubocop (1.25.0)
350
+ rspec-support (3.11.0)
351
+ rubocop (1.35.0)
352
+ json (~> 2.3)
353
353
  parallel (~> 1.10)
354
- parser (>= 3.1.0.0)
354
+ parser (>= 3.1.2.1)
355
355
  rainbow (>= 2.2.2, < 4.0)
356
356
  regexp_parser (>= 1.8, < 3.0)
357
- rexml
358
- rubocop-ast (>= 1.15.1, < 2.0)
357
+ rexml (>= 3.2.5, < 4.0)
358
+ rubocop-ast (>= 1.20.1, < 2.0)
359
359
  ruby-progressbar (~> 1.7)
360
360
  unicode-display_width (>= 1.4.0, < 3.0)
361
- rubocop-ast (1.15.1)
362
- parser (>= 3.0.1.1)
363
- rubocop-performance (1.13.2)
361
+ rubocop-ast (1.21.0)
362
+ parser (>= 3.1.1.0)
363
+ rubocop-performance (1.14.3)
364
364
  rubocop (>= 1.7.0, < 2.0)
365
365
  rubocop-ast (>= 0.4.0)
366
- rubocop-shopify (2.5.0)
367
- rubocop (~> 1.25)
366
+ rubocop-shopify (2.9.0)
367
+ rubocop (~> 1.33)
368
368
  ruby-debug-ide (0.7.3)
369
369
  rake (>= 0.8.1)
370
370
  ruby-progressbar (1.11.0)
371
371
  ruby-vips (2.1.4)
372
372
  ffi (~> 1.12)
373
373
  rubyzip (2.3.2)
374
- selenium-webdriver (4.1.0)
374
+ selenium-webdriver (4.5.0)
375
375
  childprocess (>= 0.5, < 5.0)
376
376
  rexml (~> 3.2, >= 3.2.5)
377
- rubyzip (>= 1.2.2)
377
+ rubyzip (>= 1.2.2, < 3.0)
378
+ websocket (~> 1.0)
378
379
  simplecov (0.21.2)
379
380
  docile (~> 1.1)
380
381
  simplecov-html (~> 0.11)
@@ -383,7 +384,7 @@ GEM
383
384
  rexml
384
385
  simplecov (~> 0.19)
385
386
  simplecov-html (0.12.3)
386
- simplecov_json_formatter (0.1.3)
387
+ simplecov_json_formatter (0.1.4)
387
388
  sixarm_ruby_unaccent (1.2.0)
388
389
  smart_properties (1.17.0)
389
390
  spring (4.0.0)
@@ -396,21 +397,21 @@ GEM
396
397
  actionpack (>= 5.2)
397
398
  activesupport (>= 5.2)
398
399
  sprockets (>= 3.0.0)
399
- standard (1.7.0)
400
- rubocop (= 1.25.0)
401
- rubocop-performance (= 1.13.2)
400
+ standard (1.16.0)
401
+ rubocop (= 1.35.0)
402
+ rubocop-performance (= 1.14.3)
402
403
  terminal-table (3.0.2)
403
404
  unicode-display_width (>= 1.1.1, < 3)
404
- test-prof (1.0.7)
405
+ test-prof (1.0.10)
405
406
  thor (1.2.1)
406
- timeout (0.2.0)
407
+ timeout (0.3.0)
407
408
  turbo-rails (1.3.2)
408
409
  actionpack (>= 6.0.0)
409
410
  activejob (>= 6.0.0)
410
411
  railties (>= 6.0.0)
411
412
  tzinfo (2.0.5)
412
413
  concurrent-ruby (~> 1.0)
413
- unicode-display_width (2.1.0)
414
+ unicode-display_width (2.2.0)
414
415
  view_component (2.74.1)
415
416
  activesupport (>= 5.0.0, < 8.0)
416
417
  concurrent-ruby (~> 1.0)
@@ -422,20 +423,21 @@ GEM
422
423
  activemodel (>= 6.0.0)
423
424
  bindex (>= 0.4.0)
424
425
  railties (>= 6.0.0)
425
- webdrivers (5.0.0)
426
+ webdrivers (5.2.0)
426
427
  nokogiri (~> 1.6)
427
428
  rubyzip (>= 1.3.0)
428
429
  selenium-webdriver (~> 4.0)
429
- webmock (3.14.0)
430
+ webmock (3.18.1)
430
431
  addressable (>= 2.8.0)
431
432
  crack (>= 0.3.2)
432
433
  hashdiff (>= 0.4.0, < 2.0.0)
434
+ websocket (1.2.9)
433
435
  websocket-driver (0.7.5)
434
436
  websocket-extensions (>= 0.1.0)
435
437
  websocket-extensions (0.1.5)
436
438
  xpath (3.2.0)
437
439
  nokogiri (~> 1.8)
438
- zeitwerk (2.6.0)
440
+ zeitwerk (2.6.2)
439
441
 
440
442
  PLATFORMS
441
443
  ruby
@@ -508,7 +510,7 @@ DEPENDENCIES
508
510
  web-console (>= 3.3.0)
509
511
  webdrivers
510
512
  webmock
511
- zeitwerk (~> 2.3)
513
+ zeitwerk
512
514
 
513
515
  BUNDLED WITH
514
- 2.3.23
516
+ 2.3.24
@@ -43,4 +43,20 @@ class Avo::BaseComponent < ViewComponent::Base
43
43
  rescue
44
44
  nil
45
45
  end
46
+
47
+ def parent_or_child_resource
48
+ return @resource unless link_to_child_resource_is_enabled?
49
+
50
+ ::Avo::App.get_resource_by_model_name(@resource.model.class).dup
51
+ end
52
+
53
+ def link_to_child_resource_is_enabled?
54
+ return field_linked_to_child_resource? if @parent_resource
55
+
56
+ @resource.link_to_child_resource
57
+ end
58
+
59
+ def field_linked_to_child_resource?
60
+ field.present? && field.respond_to?(:link_to_child_resource) && field.link_to_child_resource
61
+ end
46
62
  end
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Avo::Fields::IndexComponent < ViewComponent::Base
3
+ class Avo::Fields::IndexComponent < Avo::BaseComponent
4
4
  include Avo::ResourcesHelper
5
5
 
6
6
  attr_reader :parent_resource
7
7
  attr_reader :view
8
8
 
9
- def initialize(field: nil, resource: nil, index: 0, parent_model: nil, parent_resource: nil)
9
+ def initialize(field: nil, resource: nil, reflection: nil, index: 0, parent_model: nil, parent_resource: nil)
10
10
  @field = field
11
11
  @resource = resource
12
12
  @index = index
13
13
  @parent_model = parent_model
14
14
  @parent_resource = parent_resource
15
15
  @view = :index
16
+ @reflection = reflection
16
17
  end
17
18
 
18
19
  def resource_view_path
@@ -25,7 +26,7 @@ class Avo::Fields::IndexComponent < ViewComponent::Base
25
26
  }
26
27
  end
27
28
 
28
- helpers.resource_view_path(model: @resource.model, resource: @resource, **args)
29
+ helpers.resource_view_path(model: @resource.model, resource: parent_or_child_resource, **args)
29
30
  end
30
31
 
31
32
  def field_wrapper_args
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Avo::Index::GridItemComponent < ViewComponent::Base
3
+ class Avo::Index::GridItemComponent < Avo::BaseComponent
4
4
  include Avo::ResourcesHelper
5
5
 
6
6
  attr_reader :parent_resource
@@ -37,6 +37,6 @@ class Avo::Index::GridItemComponent < ViewComponent::Base
37
37
  }
38
38
  end
39
39
 
40
- helpers.resource_view_path(model: @resource.model, resource: @resource, **args)
40
+ helpers.resource_view_path(model: @resource.model, resource: parent_or_child_resource, **args)
41
41
  end
42
42
  end
@@ -41,7 +41,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
41
41
  }
42
42
  end
43
43
 
44
- helpers.resource_path(model: @resource.model, resource: @resource, **args)
44
+ helpers.resource_path(model: @resource.model, resource: parent_or_child_resource , **args)
45
45
  end
46
46
 
47
47
  def edit_path
@@ -55,7 +55,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
55
55
  }
56
56
  end
57
57
 
58
- helpers.edit_resource_path(model: @resource.model, resource: @resource, **args)
58
+ helpers.edit_resource_path(model: @resource.model, resource: parent_or_child_resource, **args)
59
59
  end
60
60
 
61
61
  def singular_resource_name
@@ -17,7 +17,7 @@
17
17
  </td>
18
18
  <% end %>
19
19
  <% @resource.get_fields(reflection: @reflection, only_root: true).each_with_index do |field, index| %>
20
- <%= render field.component_for_view(:index).new(field: field, resource: @resource, index: index, parent_model: @parent_model, parent_resource: @parent_resource) %>
20
+ <%= render field.component_for_view(:index).new(field: field, resource: @resource, reflection: @reflection, index: index, parent_model: @parent_model, parent_resource: @parent_resource) %>
21
21
  <% end %>
22
22
  <% if Avo.configuration.resource_controls_on_the_right? %>
23
23
  <td class="text-right whitespace-nowrap px-2" data-control="resource-controls">
@@ -6,7 +6,7 @@
6
6
  <%= render Avo::PanelComponent.new(name: item.name, description: item.description, index: index) do |c| %>
7
7
  <% c.body do %>
8
8
  <div class="divide-y">
9
- <% item.items.each_with_index do |field, index| %>
9
+ <% item.visible_items.each_with_index do |field, index| %>
10
10
  <%= render field
11
11
  .hydrate(resource: @resource, model: @resource.model, user: resource.user, view: view)
12
12
  .component_for_view(view)
@@ -92,7 +92,7 @@ class Avo::ResourceComponent < Avo::BaseComponent
92
92
  end
93
93
 
94
94
  def sidebar_component(form: nil)
95
- Avo::ResourceSidebarComponent.new resource: @resource, fields: sidebar.items, params: params, view: view, form: form
95
+ Avo::ResourceSidebarComponent.new resource: @resource, fields: sidebar.visible_items, params: params, view: view, form: form
96
96
  end
97
97
 
98
98
  def has_reflection_and_is_read_only
@@ -5,6 +5,7 @@ class Avo::ResourceSidebarComponent < ViewComponent::Base
5
5
  attr_reader :params
6
6
  attr_reader :view
7
7
  attr_reader :form
8
+ attr_reader :fields
8
9
 
9
10
  def initialize(resource: nil, fields: nil, index: nil, params: nil, form: nil, view: nil)
10
11
  @resource = resource
@@ -14,12 +15,6 @@ class Avo::ResourceSidebarComponent < ViewComponent::Base
14
15
  @form = form
15
16
  end
16
17
 
17
- def fields
18
- @fields.filter do |field|
19
- field.visible_on? view
20
- end
21
- end
22
-
23
18
  def render?
24
19
  Avo::App.license.has_with_trial(:resource_sidebar)
25
20
  end
@@ -39,7 +39,7 @@ class Avo::TabGroupComponent < Avo::BaseComponent
39
39
 
40
40
  def visible_tabs
41
41
  tabs.select do |tab|
42
- !tab.empty?
42
+ tab.visible?
43
43
  end
44
44
  end
45
45
 
@@ -1,5 +1,11 @@
1
1
  module Avo
2
2
  class ApplicationController < ::ActionController::Base
3
+ if defined?(Pundit::Authorization)
4
+ Avo::ApplicationController.include Pundit::Authorization
5
+ elsif defined?(Pundit)
6
+ Avo::ApplicationController.include Pundit
7
+ end
8
+
3
9
  include Pagy::Backend
4
10
  include Avo::ApplicationHelper
5
11
  include Avo::UrlHelpers
@@ -0,0 +1,37 @@
1
+ require_dependency "avo/application_controller"
2
+
3
+ module Avo
4
+ module Dashboards
5
+ class CardsController < ApplicationController
6
+ before_action :set_dashboard
7
+ before_action :set_card
8
+ before_action :detect_chartkick
9
+
10
+ def show
11
+ render(:chartkick_missing) unless @chartkick_installed
12
+ end
13
+
14
+ private
15
+
16
+ def set_dashboard
17
+ @dashboard = Avo::App.get_dashboard_by_id params[:dashboard_id]
18
+
19
+ raise ActionController::RoutingError.new("Not Found") if @dashboard.nil? || @dashboard.is_hidden?
20
+ end
21
+
22
+ def set_card
23
+ @card = @dashboard.item_at_index(params[:index].to_i).tap do |card|
24
+ card.hydrate(dashboard: @dashboard, params: params)
25
+ end
26
+ end
27
+
28
+ def detect_chartkick
29
+ @chartkick_installed = if @card.class.ancestors.map(&:to_s).include?("Avo::Dashboards::ChartkickCard")
30
+ defined?(Chartkick)
31
+ else
32
+ true
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
data/avo.gemspec CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "activerecord", ">= 6.0"
36
36
  spec.add_dependency "actionview", ">= 6.0"
37
37
  spec.add_dependency "pagy"
38
- spec.add_dependency "zeitwerk"
38
+ spec.add_dependency "zeitwerk", ">= 2.6.2"
39
39
  spec.add_dependency "httparty"
40
40
  spec.add_dependency "active_link_to"
41
41
  spec.add_dependency "view_component"
data/config/routes.rb CHANGED
@@ -7,7 +7,7 @@ Avo::Engine.routes.draw do
7
7
  post "/rails/active_storage/direct_uploads", to: "/active_storage/direct_uploads#create"
8
8
 
9
9
  resources :dashboards do
10
- resources :cards
10
+ resources :cards, controller: "dashboards/cards"
11
11
  end
12
12
 
13
13
  scope "avo_api", as: "avo_api" do
@@ -33,7 +33,7 @@ Avo::Engine.routes.draw do
33
33
 
34
34
  # Generate resource routes as below:
35
35
  # resources :posts
36
- Avo::DynamicRouter.routes(self)
36
+ Avo::DynamicRouter.routes
37
37
 
38
38
  # Associations
39
39
  get "/:resource_name/:id/:related_name/new", to: "associations#new", as: "associations_new"
data/db/factories.rb CHANGED
@@ -60,6 +60,11 @@ FactoryBot.define do
60
60
  type { "Spouse" }
61
61
  end
62
62
 
63
+ factory :sibling do
64
+ name { "#{Faker::Name.first_name} #{Faker::Name.last_name}" }
65
+ type { "Sibling" }
66
+ end
67
+
63
68
  factory :fish do
64
69
  name { %w[Tilapia Salmon Trout Catfish Pangasius Carp].sample }
65
70
  end
data/lib/avo/app.rb CHANGED
@@ -17,6 +17,14 @@ module Avo
17
17
  class_attribute :error_messages
18
18
 
19
19
  class << self
20
+ def eager_load(entity)
21
+ paths = Avo::ENTITIES.fetch entity
22
+
23
+ return unless paths.present?
24
+
25
+ Rails.autoloaders.main.eager_load_dir(Rails.root.join(*paths).to_s)
26
+ end
27
+
20
28
  def boot
21
29
  init_fields
22
30
 
@@ -91,7 +99,7 @@ module Avo
91
99
  has_model = resource.model_class.present?
92
100
 
93
101
  unless has_model
94
- possible_model = resource.class.to_s.gsub 'Resource', ''
102
+ possible_model = resource.class.to_s.gsub "Resource", ""
95
103
 
96
104
  Avo::App.error_messages.push({
97
105
  url: "https://docs.avohq.io/2.0/resources.html#custom-model-class",
@@ -119,6 +127,8 @@ module Avo
119
127
  end
120
128
 
121
129
  def init_dashboards
130
+ eager_load :dashboards unless Rails.application.config.eager_load
131
+
122
132
  self.dashboards = Dashboards::BaseDashboard.descendants
123
133
  .select do |dashboard|
124
134
  dashboard != Dashboards::BaseDashboard
@@ -34,9 +34,9 @@ module Avo
34
34
  def form_data_attributes
35
35
  # We can't respond with a file download from Turbo se we disable it on the form
36
36
  if may_download_file
37
- {turbo: false, remote: false}
37
+ {turbo: false, remote: false, action_target: :form}
38
38
  else
39
- {"turbo-frame": "_top", "action-target": "form"}
39
+ {turbo_frame: :_top, action_target: :form}
40
40
  end
41
41
  end
42
42
 
@@ -49,6 +49,7 @@ module Avo
49
49
  class_attribute :record_selector, default: true
50
50
  class_attribute :keep_filters_panel_open, default: false
51
51
  class_attribute :extra_params
52
+ class_attribute :link_to_child_resource, default: false
52
53
 
53
54
  class << self
54
55
  delegate :t, to: ::I18n
@@ -422,9 +423,7 @@ module Avo
422
423
  end
423
424
 
424
425
  def label
425
- label_field.value || model_title
426
- rescue
427
- model_title
426
+ label_field&.value || model_title
428
427
  end
429
428
 
430
429
  def avatar_field
@@ -460,9 +459,7 @@ module Avo
460
459
  end
461
460
 
462
461
  def description
463
- description_field.value
464
- rescue
465
- nil
462
+ description_field&.value
466
463
  end
467
464
 
468
465
  def form_scope
@@ -270,6 +270,8 @@ module Avo
270
270
  end
271
271
  # each field has it's own visibility checker
272
272
  if item.respond_to? :visible?
273
+ item.hydrate(view: view) if item.view.nil?
274
+
273
275
  next unless item.visible?
274
276
  end
275
277
  # check if the user is authorized to view it
@@ -0,0 +1,44 @@
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
+ if items_holder.present?
8
+ items_holder.items
9
+ else
10
+ []
11
+ end
12
+ end
13
+
14
+ def visible_items
15
+ items
16
+ .map do |item|
17
+ visible(item) ? item : nil
18
+ end
19
+ .compact
20
+ end
21
+
22
+ def visible(item)
23
+ if item.is_field?
24
+ item.visible? && item.visible_on?(view)
25
+ else
26
+ item.visible?
27
+ end
28
+ end
29
+
30
+ def visible?
31
+ any_item_visible = visible_items.any?
32
+ return any_item_visible unless respond_to?(:visible_on?)
33
+
34
+ visible_on?(view) && any_item_visible
35
+ end
36
+
37
+ def hydrate(view: nil)
38
+ @view = view
39
+
40
+ self
41
+ end
42
+ end
43
+ end
44
+ end
@@ -16,7 +16,7 @@ class Avo::Configuration::Branding
16
16
  @default_chart_colors = ["#0B8AE2", "#34C683", "#2AB1EE", "#34C6A8"]
17
17
  @default_logo = "/avo-assets/logo.png"
18
18
  @default_logomark = "/avo-assets/logomark.png"
19
- @default_placeholder = "placeholder.svg"
19
+ @default_placeholder = "/avo-assets/placeholder.svg"
20
20
  end
21
21
 
22
22
  def css_colors
@@ -1,21 +1,22 @@
1
1
  module Avo
2
- module DynamicRouter
3
- def self.routes(router)
4
- Rails.application.eager_load! unless Rails.env.production?
2
+ class DynamicRouter
3
+ def self.routes
4
+ Avo::Engine.routes.draw do
5
+ scope "resources", as: "resources" do
6
+ Avo::App.eager_load(:resources) unless Rails.application.config.eager_load
5
7
 
6
- BaseResource.descendants
7
- .select do |resource|
8
- resource != :BaseResource
9
- end
10
- .select do |resource|
11
- resource.is_a? Class
12
- end
13
- # .select do |resource|
14
- # resource.model_class.present?
15
- # end
16
- .map do |resource|
17
- router.resources resource.new.route_key
8
+ BaseResource.descendants
9
+ .select do |resource|
10
+ resource != :BaseResource
11
+ end
12
+ .select do |resource|
13
+ resource.is_a? Class
14
+ end
15
+ .map do |resource|
16
+ resources resource.new.route_key
17
+ end
18
18
  end
19
+ end
19
20
  end
20
21
  end
21
22
  end
data/lib/avo/engine.rb CHANGED
@@ -27,15 +27,7 @@ module Avo
27
27
  end
28
28
 
29
29
  initializer "avo.autoload" do |app|
30
- [
31
- ["app", "avo", "fields"],
32
- ["app", "avo", "filters"],
33
- ["app", "avo", "actions"],
34
- ["app", "avo", "resources"],
35
- ["app", "avo", "dashboards"],
36
- ["app", "avo", "cards"],
37
- ["app", "avo", "resource_tools"]
38
- ].each do |path_params|
30
+ Avo::ENTITIES.values.each do |path_params|
39
31
  path = Rails.root.join(*path_params)
40
32
 
41
33
  if File.directory? path.to_s
@@ -83,7 +83,7 @@ module Avo
83
83
 
84
84
  @args = args
85
85
 
86
- @updatable = true
86
+ @updatable = !readonly
87
87
  @computable = true
88
88
  @computed = block.present?
89
89
  @computed_value = nil
@@ -7,6 +7,7 @@ module Avo
7
7
  attr_accessor :description
8
8
  attr_accessor :discreet_pagination
9
9
  attr_accessor :hide_search_input
10
+ attr_reader :link_to_child_resource
10
11
 
11
12
  def initialize(id, **args, &block)
12
13
  super(id, **args, &block)
@@ -19,6 +20,7 @@ module Avo
19
20
  @description = args[:description]
20
21
  @use_resource = args[:use_resource] || nil
21
22
  @discreet_pagination = args[:discreet_pagination] || false
23
+ @link_to_child_resource = args[:link_to_child_resource] || false
22
24
  end
23
25
 
24
26
  def searchable
data/lib/avo/panel.rb CHANGED
@@ -1,16 +1,19 @@
1
1
  class Avo::Panel
2
2
  include Avo::Concerns::IsResourceItem
3
+ include Avo::Concerns::VisibleItems
3
4
 
4
5
  class_attribute :item_type, default: :panel
5
6
 
6
7
  attr_reader :name
8
+ attr_reader :view
7
9
  attr_reader :description
8
10
  attr_accessor :items_holder
9
11
 
10
12
  delegate :items, :add_item, to: :items_holder
11
13
 
12
- def initialize(name: nil, description: nil)
14
+ def initialize(name: nil, description: nil, view: nil)
13
15
  @name = name
16
+ @view = view
14
17
  @description = description
15
18
  @items_holder = Avo::ItemsHolder.new
16
19
  end
data/lib/avo/sidebar.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  class Avo::Sidebar
2
2
  include Avo::Concerns::IsResourceItem
3
+ include Avo::Concerns::VisibleItems
3
4
  include Avo::Fields::FieldExtensions::VisibleInDifferentViews
4
5
 
5
6
  class_attribute :item_type, default: :sidebar
@@ -23,38 +24,7 @@ class Avo::Sidebar
23
24
  except_on args[:except_on] if args[:except_on].present?
24
25
  end
25
26
 
26
- def hydrate(view: nil)
27
- @view = view
28
-
29
- self
30
- end
31
-
32
27
  def empty?
33
28
  visible_items.blank?
34
29
  end
35
-
36
- def items
37
- if self.items_holder.present?
38
- self.items_holder.items
39
- else
40
- []
41
- end
42
- end
43
-
44
- def visible_items
45
- items.map do |item|
46
- # Remove the fields that shouldn't be visible in this view
47
- # eg: has_many fields on edit
48
- if not_visible_field(item)
49
- nil
50
- else
51
- item
52
- end
53
- end
54
- .compact
55
- end
56
-
57
- def not_visible_field(item)
58
- item.is_field? && !item.visible_on?(view)
59
- end
60
30
  end
data/lib/avo/tab.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  class Avo::Tab
2
2
  include Avo::Concerns::IsResourceItem
3
+ include Avo::Concerns::VisibleItems
3
4
  include Avo::Fields::FieldExtensions::VisibleInDifferentViews
4
5
 
5
6
  class_attribute :item_type, default: :tab
@@ -30,6 +31,10 @@ class Avo::Tab
30
31
  def hydrate(view: nil)
31
32
  @view = view
32
33
 
34
+ items_holder.items.grep(Avo::Panel).each do |panel|
35
+ panel.hydrate(view: view)
36
+ end
37
+
33
38
  self
34
39
  end
35
40
 
@@ -53,26 +58,4 @@ class Avo::Tab
53
58
  super(view)
54
59
  end
55
60
  end
56
-
57
- def items
58
- if self.items_holder.present?
59
- self.items_holder.items
60
- else
61
- []
62
- end
63
- end
64
-
65
- def visible_items
66
- items.map do |item|
67
- if item.is_field?
68
- visible = item.visible_on?(view)
69
- # Remove the fields that shouldn't be visible in this view
70
- # eg: has_many fields on edit
71
- item = nil unless visible
72
- end
73
-
74
- item
75
- end
76
- .compact
77
- end
78
61
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.17.1.pre.5.stackedlayout" unless const_defined?(:VERSION)
2
+ VERSION = "2.18.1.pre.1.eagerloaddirs" unless const_defined?(:VERSION)
3
3
  end
data/lib/avo.rb CHANGED
@@ -40,6 +40,15 @@ module Avo
40
40
  IN_DEVELOPMENT = ENV["AVO_IN_DEVELOPMENT"] == "1"
41
41
  PACKED = !IN_DEVELOPMENT
42
42
  COOKIES_KEY = "avo"
43
+ ENTITIES = {
44
+ cards: ["app", "avo", "cards"],
45
+ fields: ["app", "avo", "fields"],
46
+ filters: ["app", "avo", "filters"],
47
+ actions: ["app", "avo", "actions"],
48
+ resources: ["app", "avo", "resources"],
49
+ dashboards: ["app", "avo", "dashboards"],
50
+ resource_tools: ["app", "avo", "resource_tools"]
51
+ }
43
52
 
44
53
  class LicenseVerificationTemperedError < StandardError; end
45
54
 
@@ -7783,16 +7783,6 @@ trix-toolbar .trix-button-group:not(:first-child){
7783
7783
  line-height:1.5rem
7784
7784
  }
7785
7785
 
7786
- .text-3xl{
7787
- font-size:1.875rem;
7788
- line-height:2.25rem
7789
- }
7790
-
7791
- .text-5xl{
7792
- font-size:3rem;
7793
- line-height:1
7794
- }
7795
-
7796
7786
  .text-xl{
7797
7787
  font-size:1.25rem;
7798
7788
  line-height:1.75rem
@@ -7803,6 +7793,16 @@ trix-toolbar .trix-button-group:not(:first-child){
7803
7793
  line-height:1rem
7804
7794
  }
7805
7795
 
7796
+ .text-3xl{
7797
+ font-size:1.875rem;
7798
+ line-height:2.25rem
7799
+ }
7800
+
7801
+ .text-5xl{
7802
+ font-size:3rem;
7803
+ line-height:1
7804
+ }
7805
+
7806
7806
  .text-2xl{
7807
7807
  font-size:1.5rem;
7808
7808
  line-height:2rem
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: 2.17.1.pre.5.stackedlayout
4
+ version: 2.18.1.pre.1.eagerloaddirs
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-10-24 00:00:00.000000000 Z
12
+ date: 2022-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: 2.6.2
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 2.6.2
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: httparty
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -1309,7 +1309,6 @@ files:
1309
1309
  - app/assets/svgs/menu-back.svg
1310
1310
  - app/assets/svgs/menu.svg
1311
1311
  - app/assets/svgs/photograph.svg
1312
- - app/assets/svgs/placeholder.svg
1313
1312
  - app/assets/svgs/play.svg
1314
1313
  - app/assets/svgs/plus-circle.svg
1315
1314
  - app/assets/svgs/plus.svg
@@ -1596,7 +1595,7 @@ files:
1596
1595
  - app/controllers/avo/associations_controller.rb
1597
1596
  - app/controllers/avo/attachments_controller.rb
1598
1597
  - app/controllers/avo/base_controller.rb
1599
- - app/controllers/avo/cards_controller.rb
1598
+ - app/controllers/avo/dashboards/cards_controller.rb
1600
1599
  - app/controllers/avo/dashboards_controller.rb
1601
1600
  - app/controllers/avo/debug_controller.rb
1602
1601
  - app/controllers/avo/home_controller.rb
@@ -1659,10 +1658,10 @@ files:
1659
1658
  - app/views/avo/base/index.html.erb
1660
1659
  - app/views/avo/base/new.html.erb
1661
1660
  - app/views/avo/base/show.html.erb
1662
- - app/views/avo/cards/_chartkick_card.html.erb
1663
- - app/views/avo/cards/_metric_card.html.erb
1664
- - app/views/avo/cards/chartkick_missing.html.erb
1665
- - app/views/avo/cards/show.html.erb
1661
+ - app/views/avo/dashboards/cards/_chartkick_card.html.erb
1662
+ - app/views/avo/dashboards/cards/_metric_card.html.erb
1663
+ - app/views/avo/dashboards/cards/chartkick_missing.html.erb
1664
+ - app/views/avo/dashboards/cards/show.html.erb
1666
1665
  - app/views/avo/dashboards/show.html.erb
1667
1666
  - app/views/avo/debug/index.html.erb
1668
1667
  - app/views/avo/debug/report.html.erb
@@ -1728,6 +1727,7 @@ files:
1728
1727
  - lib/avo/concerns/has_stimulus_controllers.rb
1729
1728
  - lib/avo/concerns/is_resource_item.rb
1730
1729
  - lib/avo/concerns/model_class_constantized.rb
1730
+ - lib/avo/concerns/visible_items.rb
1731
1731
  - lib/avo/configuration.rb
1732
1732
  - lib/avo/configuration/branding.rb
1733
1733
  - lib/avo/configuration/resource_configuration.rb
@@ -1928,6 +1928,7 @@ files:
1928
1928
  - public/avo-assets/logo-on-white.png
1929
1929
  - public/avo-assets/logo.png
1930
1930
  - public/avo-assets/logomark.png
1931
+ - public/avo-assets/placeholder.svg
1931
1932
  homepage: https://avohq.io
1932
1933
  licenses:
1933
1934
  - Commercial
@@ -1,35 +0,0 @@
1
- require_dependency "avo/application_controller"
2
-
3
- module Avo
4
- class CardsController < ApplicationController
5
- before_action :set_dashboard
6
- before_action :set_card
7
- before_action :detect_chartkick
8
-
9
- def show
10
- render(:chartkick_missing) unless @chartkick_installed
11
- end
12
-
13
- private
14
-
15
- def set_dashboard
16
- @dashboard = Avo::App.get_dashboard_by_id params[:dashboard_id]
17
-
18
- raise ActionController::RoutingError.new("Not Found") if @dashboard.nil? || @dashboard.is_hidden?
19
- end
20
-
21
- def set_card
22
- @card = @dashboard.item_at_index(params[:index].to_i).tap do |card|
23
- card.hydrate(dashboard: @dashboard, params: params)
24
- end
25
- end
26
-
27
- def detect_chartkick
28
- @chartkick_installed = if @card.class.ancestors.map(&:to_s).include?("Avo::Dashboards::ChartkickCard")
29
- defined?(Chartkick)
30
- else
31
- true
32
- end
33
- end
34
- end
35
- end