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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03dc6c3446d073d941e7b2ea748be0eb85c718e3196c77d479c4a320d27841be
4
- data.tar.gz: 18d2d8f837b29ea60f9453fff6569dd1ebc88a77f3c3f4843161a3a551b4b191
3
+ metadata.gz: 9f30e8baa3e8f62b2b0ad544daa0f6957725ac50f4a807402fb24a9f1bc60c19
4
+ data.tar.gz: e43a09a1a0b27bb48e975d6f87c8b84354c4a645c85a21d8fda458f408b4ca71
5
5
  SHA512:
6
- metadata.gz: a442d67dca15b0e57c8fdbc138d816e3ba69ed42993e456a9c73de3a9262092761c7a77239418e2cd18ce552e43274acd7e69a900bf3524853b9773b320990ba
7
- data.tar.gz: 409603c9f7fcb5a9dd05c40c0e9d75b47a600fc4e65cf622b5a00d75e261985c20adbd172fa806515441543b94976bf543c8eb9d0118a16b85460e1e8c22ec90
6
+ metadata.gz: a3db95de401a8fd67c1ff63d5b08df578e046fddebaeb06c150ad34a8199de34b54f7e38799115543d66982c6ff40c05c06391f4f7b8090424b3fa758678f2b6
7
+ data.tar.gz: 4a1726891e4be7ab40aa07aef8e4cda3f8657c542f51e05dc850bf589f9964f2fc74640192b0e9356788b95b5de91ca192d946693278339f18180681e3a9a1f8
data/Gemfile CHANGED
@@ -88,7 +88,7 @@ group :test do
88
88
  gem "capybara"
89
89
  gem "selenium-webdriver"
90
90
  # Easy installation and use of web drivers to run system tests with browsers
91
- gem "webdrivers", ">= 5.3.0"
91
+ gem "webdrivers"
92
92
  gem "fuubar"
93
93
  gem "simplecov", require: false
94
94
  gem "simplecov-cobertura"
@@ -127,7 +127,7 @@ gem "addressable"
127
127
  gem 'meta-tags'
128
128
 
129
129
  # Search
130
- gem "ransack", "~>4.0"
130
+ gem "ransack", "~> 3.1.0"
131
131
 
132
132
  gem 'friendly_id', '~> 5.4.0'
133
133
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.0.0.pre19)
4
+ avo (3.0.1.beta1)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -93,7 +93,7 @@ GEM
93
93
  activerecord (>= 6.0, < 7.1)
94
94
  acts_as_list (1.0.4)
95
95
  activerecord (>= 4.2)
96
- addressable (2.8.5)
96
+ addressable (2.8.1)
97
97
  public_suffix (>= 2.0.2, < 6.0)
98
98
  annotate (3.2.0)
99
99
  activerecord (>= 3.2, < 8.0)
@@ -138,7 +138,7 @@ GEM
138
138
  bump (0.10.0)
139
139
  bundler-integrity (1.0.9)
140
140
  byebug (11.1.3)
141
- capybara (3.39.2)
141
+ capybara (3.38.0)
142
142
  addressable
143
143
  matrix
144
144
  mini_mime (>= 0.1.3)
@@ -148,6 +148,7 @@ GEM
148
148
  regexp_parser (>= 1.5, < 3.0)
149
149
  xpath (~> 3.2)
150
150
  chartkick (4.2.1)
151
+ childprocess (4.1.0)
151
152
  concurrent-ruby (1.2.2)
152
153
  countries (5.1.2)
153
154
  sixarm_ruby_unaccent (~> 1.1)
@@ -210,7 +211,7 @@ GEM
210
211
  httparty (0.20.0)
211
212
  mime-types (~> 3.0)
212
213
  multi_xml (>= 0.5.2)
213
- i18n (1.14.1)
214
+ i18n (1.12.0)
214
215
  concurrent-ruby (~> 1.0)
215
216
  i18n-tasks (1.0.12)
216
217
  activesupport (>= 4.0.2)
@@ -263,8 +264,8 @@ GEM
263
264
  mime-types-data (~> 3.2015)
264
265
  mime-types-data (3.2022.0105)
265
266
  mini_magick (4.11.0)
266
- mini_mime (1.1.5)
267
- mini_portile2 (2.8.4)
267
+ mini_mime (1.1.2)
268
+ mini_portile2 (2.8.1)
268
269
  minitest (5.18.0)
269
270
  msgpack (1.5.6)
270
271
  multi_xml (0.6.0)
@@ -280,10 +281,10 @@ GEM
280
281
  net-protocol
281
282
  timeout
282
283
  nio4r (2.5.9)
283
- nokogiri (1.15.4)
284
- mini_portile2 (~> 2.8.2)
284
+ nokogiri (1.14.3)
285
+ mini_portile2 (~> 2.8.0)
285
286
  racc (~> 1.4)
286
- nokogiri (1.15.4-x86_64-linux)
287
+ nokogiri (1.14.3-x86_64-linux)
287
288
  racc (~> 1.4)
288
289
  orm_adapter (0.5.0)
289
290
  pagy (6.0.3)
@@ -294,11 +295,11 @@ GEM
294
295
  prefixed_ids (1.4.0)
295
296
  hashids (>= 1.0.0, < 2.0.0)
296
297
  rails (>= 6.0.0)
297
- public_suffix (5.0.3)
298
+ public_suffix (5.0.1)
298
299
  puma (6.0.2)
299
300
  nio4r (~> 2.0)
300
- racc (1.7.1)
301
- rack (2.2.8)
301
+ racc (1.6.2)
302
+ rack (2.2.6.4)
302
303
  rack-test (2.1.0)
303
304
  rack (>= 1.3)
304
305
  rails (6.1.7.3)
@@ -336,21 +337,21 @@ GEM
336
337
  thor (~> 1.0)
337
338
  rainbow (3.1.1)
338
339
  rake (13.0.6)
339
- ransack (4.0.0)
340
- activerecord (>= 6.1.5)
341
- activesupport (>= 6.1.5)
340
+ ransack (3.1.0)
341
+ activerecord (>= 6.0.4)
342
+ activesupport (>= 6.0.4)
342
343
  i18n
343
344
  rb-fsevent (0.11.1)
344
345
  rb-inotify (0.10.1)
345
346
  ffi (~> 1.0)
346
347
  redis (4.8.0)
347
- regexp_parser (2.8.1)
348
+ regexp_parser (2.6.1)
348
349
  responders (3.0.1)
349
350
  actionpack (>= 5.0)
350
351
  railties (>= 5.0)
351
352
  reverse_markdown (2.1.1)
352
353
  nokogiri
353
- rexml (3.2.6)
354
+ rexml (3.2.5)
354
355
  ripper-tags (0.9.1)
355
356
  rspec-core (3.11.0)
356
357
  rspec-support (~> 3.11.0)
@@ -392,7 +393,8 @@ GEM
392
393
  ruby-vips (2.1.4)
393
394
  ffi (~> 1.12)
394
395
  rubyzip (2.3.2)
395
- selenium-webdriver (4.10.0)
396
+ selenium-webdriver (4.5.0)
397
+ childprocess (>= 0.5, < 5.0)
396
398
  rexml (~> 3.2, >= 3.2.5)
397
399
  rubyzip (>= 1.2.2, < 3.0)
398
400
  websocket (~> 1.0)
@@ -462,10 +464,10 @@ GEM
462
464
  activemodel (>= 6.0.0)
463
465
  bindex (>= 0.4.0)
464
466
  railties (>= 6.0.0)
465
- webdrivers (5.3.1)
467
+ webdrivers (5.2.0)
466
468
  nokogiri (~> 1.6)
467
469
  rubyzip (>= 1.3.0)
468
- selenium-webdriver (~> 4.0, < 4.11)
470
+ selenium-webdriver (~> 4.0)
469
471
  webmock (3.18.1)
470
472
  addressable (>= 2.8.0)
471
473
  crack (>= 0.3.2)
@@ -479,7 +481,7 @@ GEM
479
481
  nokogiri (~> 1.8)
480
482
  yard (0.9.28)
481
483
  webrick (~> 1.7.0)
482
- zeitwerk (2.6.11)
484
+ zeitwerk (2.6.7)
483
485
 
484
486
  PLATFORMS
485
487
  ruby
@@ -535,7 +537,7 @@ DEPENDENCIES
535
537
  puma (~> 6.0.2)
536
538
  rails (~> 6.1.0)
537
539
  rails-controller-testing
538
- ransack (~> 4.0)
540
+ ransack (~> 3.1.0)
539
541
  redis (~> 4.0)
540
542
  ripper-tags
541
543
  rspec-rails (~> 4.0.0)
@@ -554,7 +556,7 @@ DEPENDENCIES
554
556
  test-prof
555
557
  tzinfo-data
556
558
  web-console (>= 3.3.0)
557
- webdrivers (>= 5.3.0)
559
+ webdrivers
558
560
  webmock
559
561
  zeitwerk
560
562
 
data/Rakefile CHANGED
@@ -19,8 +19,6 @@ load "rails/tasks/engine.rake"
19
19
 
20
20
  load "rails/tasks/statistics.rake"
21
21
 
22
- load "lib/tasks/avo_tasks.rake"
23
-
24
22
  require "bundler/gem_tasks"
25
23
 
26
24
  require "rake/testtask"
@@ -24,7 +24,6 @@
24
24
  @import './css/fields/code.css';
25
25
  @import './css/fields/progress.css';
26
26
  @import './css/fields/trix.css';
27
- @import './css/fields/tags.css';
28
27
 
29
28
  @import 'tailwindcss/components';
30
29
 
@@ -54,7 +54,7 @@ class Avo::ActionsComponent < ViewComponent::Base
54
54
  private
55
55
 
56
56
  def on_record_page?
57
- @view.in?(%w[show edit new])
57
+ @view.in?([:show, :edit, :new])
58
58
  end
59
59
 
60
60
  def on_index_page?
@@ -2,7 +2,7 @@
2
2
  class: classes,
3
3
  style: style,
4
4
  data: data do %>
5
- <div class="h-full <% if stacked? %> md:pt-4 md:w-full <% else %> md:pt-0 <% if short? %> md:h-10 <% else %> md:h-14 <% end %> <% end %> pt-4 flex self-start items-center flex-shrink-0 <%= @field.get_html(:classes, view: view, element: :label) %> w-48 <% if compact? %> md:w-48 xl:w-64 <% else %> md:w-64 <% end %> px-6 uppercase font-semibold text-gray-500 text-sm" data-slot="label">
5
+ <div class="h-full <% if stacked? %> md:pt-4 <% else %> md:pt-0 <% if short? %> md:h-10 <% else %> md:h-14 <% end %> <% end %> pt-4 flex self-start items-center flex-shrink-0 <%= @field.get_html(:classes, view: view, element: :label) %> w-48 <% if compact? %> md:w-48 xl:w-64 <% else %> md:w-64 <% end %> px-6 uppercase font-semibold text-gray-500 text-sm" data-slot="label">
6
6
  <% if form.present? %>
7
7
  <%= form.label field.id, label %>
8
8
  <% else %>
@@ -54,7 +54,13 @@ class Avo::FieldWrapperComponent < ViewComponent::Base
54
54
  @label || @field.name
55
55
  end
56
56
 
57
- delegate :show?, :edit?, to: :view, prefix: :on
57
+ def on_show?
58
+ view == :show
59
+ end
60
+
61
+ def on_edit?
62
+ view == :edit
63
+ end
58
64
 
59
65
  def help
60
66
  Avo::ExecutionContext.new(target: @help || @field.help, record: record, resource: resource, view: view).handle
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper **field_wrapper_args, dash_if_blank: false, flush: true do %>
1
+ <%= index_field_wrapper **field_wrapper_args, dash_if_blank: false, center_content: true, flush: true do %>
2
2
  <%= render Avo::Fields::Common::BooleanCheckComponent.new checked: @field.value %>
3
3
  <% end %>
@@ -1 +1,24 @@
1
- <span class="<%= classes %>" style="max-width: 120px;"><%= @value %></span>
1
+ <%
2
+ backgrounds = {
3
+ info: 'bg-blue-500',
4
+ success: 'bg-green-500',
5
+ danger: 'bg-red-500',
6
+ warning: 'bg-yellow-500',
7
+ }
8
+
9
+ label = @value
10
+ background = :info
11
+
12
+ @options.invert.each do |values, type|
13
+ if [values].flatten.map { |value| value }.include? @value
14
+ label = @value
15
+ background = type.to_sym
16
+ next
17
+ end
18
+ end
19
+
20
+ classes = 'whitespace-nowrap rounded-md uppercase px-2 py-1 text-xs font-bold block text-center truncate '
21
+
22
+ classes += "#{backgrounds[background]} text-white" if backgrounds[background].present?
23
+ %>
24
+ <span class="<%= classes %>" style="max-width: 120px;"><%= label %></span>
@@ -4,29 +4,5 @@ class Avo::Fields::Common::BadgeViewerComponent < ViewComponent::Base
4
4
  def initialize(value:, options:)
5
5
  @value = value
6
6
  @options = options
7
- @backgrounds = {
8
- info: "bg-blue-500",
9
- success: "bg-green-500",
10
- danger: "bg-red-500",
11
- warning: "bg-yellow-500",
12
- neutral: "bg-gray-500"
13
- }
14
- end
15
-
16
- def classes
17
- background = :info
18
-
19
- @options.invert.each do |values, type|
20
- if [values].flatten.map { |value| value }.include? @value
21
- background = type.to_sym
22
- next
23
- end
24
- end
25
-
26
- classes = "whitespace-nowrap rounded-md uppercase px-2 py-1 text-xs font-bold block text-center truncate "
27
-
28
- classes += "#{@backgrounds[background]} text-white" if @backgrounds[background].present?
29
-
30
- classes
31
7
  end
32
8
  end
@@ -1 +1,12 @@
1
- <%= helpers.svg "#{@icon}.svg", class: @classes %>
1
+ <%
2
+ classes = 'h-6 float-left mr-1'
3
+
4
+ if @checked
5
+ classes += ' text-green-600'
6
+ icon = 'heroicons/outline/check-circle'
7
+ else
8
+ classes += ' text-red-500'
9
+ icon = 'heroicons/outline/x-circle'
10
+ end
11
+ %>
12
+ <%= helpers.svg "#{icon}.svg", class: classes %>
@@ -2,7 +2,6 @@
2
2
 
3
3
  class Avo::Fields::Common::BooleanCheckComponent < ViewComponent::Base
4
4
  def initialize(checked: false)
5
- @icon = checked ? "heroicons/outline/check-circle" : "heroicons/outline/x-circle"
6
- @classes = "h-6 #{checked ? "text-green-600" : "text-red-500"}"
5
+ @checked = checked
7
6
  end
8
7
  end
@@ -9,4 +9,4 @@
9
9
  url = URI::HTTPS.build(host: "www.gravatar.com", path: "/avatar/#{@md5}", query: query)
10
10
  classes = @rounded ? 'rounded-full' : ''
11
11
  %>
12
- <%= link_to_if @link_to_record.present?, image_tag(url.to_s, class: classes, width: options[:size], height: options[:size]), @link, title: @title %>
12
+ <%= link_to_if @link_to_resource.present?, image_tag(url.to_s, class: classes, width: options[:size], height: options[:size]), @link, title: @title %>
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::Fields::Common::GravatarViewerComponent < ViewComponent::Base
4
- def initialize(md5: nil, link: nil, default: nil, size: nil, rounded: false, link_to_record: false, title: nil)
4
+ def initialize(md5: nil, link: nil, default: nil, size: nil, rounded: false, link_to_resource: false, title: nil)
5
5
  @md5 = md5
6
6
  @link = link
7
7
  @default = default
8
8
  @size = size
9
9
  @rounded = rounded
10
- @link_to_record = link_to_record
10
+ @link_to_resource = link_to_resource
11
11
  @title = title
12
12
  end
13
13
  end
@@ -1,9 +1,14 @@
1
1
  <div class="flex items-start py-1 leading-tight bg-gray-100 text-gray-500 text-xs">
2
2
  <div class="py-2 px-6 h-full w-full">
3
- <% if as_html %>
4
- <%= sanitize value %>
3
+ <% if empty %>
4
+ <% elsif value.present? %>
5
+ <% if as_html %>
6
+ <%= sanitize value %>
7
+ <% else %>
8
+ <div class="font-semibold uppercase"><%= value %></div>
9
+ <% end %>
5
10
  <% else %>
6
- <div class="font-semibold uppercase"><%= value %></div>
11
+
7
12
  <% end %>
8
13
  </div>
9
14
  </div>
@@ -3,9 +3,11 @@
3
3
  class Avo::Fields::Common::HeadingComponent < ViewComponent::Base
4
4
  attr_reader :value
5
5
  attr_reader :as_html
6
+ attr_reader :empty
6
7
 
7
- def initialize(value:, as_html:)
8
+ def initialize(value:, as_html:, empty:)
8
9
  @value = value
9
10
  @as_html = as_html
11
+ @empty = empty
10
12
  end
11
13
  end
@@ -3,7 +3,7 @@
3
3
  data-key-value-target="controller"
4
4
  data-options="<%= @field.options.to_json %>"
5
5
  data-input-classes="<%= input_classes %>"
6
- data-editable="<%= @view.form? %>"
6
+ data-editable="<%= @view.in?([:edit, :new]) %>"
7
7
  >
8
8
  <div class="w-full flex flex-col">
9
9
  <div class="flex w-full">
@@ -14,7 +14,7 @@
14
14
  <div class="w-1/2 py-3 px-3 uppercase font-semibold text-xs text-white">
15
15
  <%= @field.value_label %>
16
16
  </div>
17
- <% if @view.form? %>
17
+ <% if @view.in?([:edit, :new]) %>
18
18
  <div class="flex items-center justify-center p-2 px-3 border-l border-gray-600">
19
19
  <a href="javascript:void(0);"
20
20
  title="<%= @field.action_text %>"
@@ -5,9 +5,9 @@ class Avo::Fields::Common::KeyValueComponent < ViewComponent::Base
5
5
 
6
6
  attr_reader :view
7
7
 
8
- def initialize(field:, form: nil, view: "show")
8
+ def initialize(field:, form: nil, view: :show)
9
9
  @field = field
10
10
  @form = form
11
- @view = Avo::ViewInquirer.new(view)
11
+ @view = view
12
12
  end
13
13
  end
@@ -7,13 +7,19 @@ class Avo::Fields::Common::ProgressBarComponent < ViewComponent::Base
7
7
  attr_reader :max
8
8
  attr_reader :view
9
9
 
10
- def initialize(value:, display_value: false, value_suffix: nil, max: 100, view: "index")
10
+ def initialize(value:, display_value: false, value_suffix: nil, max: 100, view: :index)
11
11
  @value = value
12
12
  @display_value = display_value
13
13
  @value_suffix = value_suffix
14
14
  @max = max
15
- @view = Avo::ViewInquirer.new(view)
15
+ @view = view
16
16
  end
17
17
 
18
- delegate :show?, :index?, to: :view
18
+ def show?
19
+ view == :show
20
+ end
21
+
22
+ def index?
23
+ view == :index
24
+ end
19
25
  end
@@ -2,15 +2,12 @@
2
2
  classes = "inline-block"
3
3
  classes += " text-red-600" if @status == 'failed'
4
4
  classes += " text-green-600" if @status == 'success'
5
- classes += " text-gray-600" if @status == 'neutral'
6
5
  %>
7
6
  <div class="flex flex-shrink-0 <%= classes %> items-center">
8
7
  <% if @status == 'success' %>
9
8
  <%= helpers.svg 'heroicons/solid/check-circle', class: 'h-4' %>
10
9
  <% elsif @status == 'failed' %>
11
10
  <%= helpers.svg 'heroicons/solid/x-circle', class: 'h-4' %>
12
- <% elsif @status == 'neutral' %>
13
- <%= helpers.svg 'heroicons/solid/minus-circle', class: 'h-4' %>
14
11
  <% elsif @status == 'loading' %>
15
12
  <div class="spinner">
16
13
  <div class="double-bounce1 bg-gray-600"></div>
@@ -20,7 +20,7 @@ class Avo::Fields::EditComponent < ViewComponent::Base
20
20
  @multiple = multiple
21
21
  @resource = resource
22
22
  @stacked = stacked
23
- @view = Avo::ViewInquirer.new("edit")
23
+ @view = :edit
24
24
  end
25
25
 
26
26
  def classes(extra_classes = "")
@@ -1,6 +1,6 @@
1
1
  <%= index_field_wrapper **field_wrapper_args, flush: true do %>
2
2
  <% if @field.value.present? %>
3
- <%= link_to_if @field.link_to_record.present?,
3
+ <%= link_to_if @field.link_to_resource.present?,
4
4
  image_tag(@field.value,
5
5
  height: @field.height,
6
6
  style: "border-radius: #{@field.radius}px; max-height: #{@field.height}#{@field.height.to_s&.ends_with?('px') ? '' : 'px'};"),
@@ -1,9 +1,9 @@
1
1
  <%= index_field_wrapper **field_wrapper_args, flush: flush? do %>
2
2
  <% if @field.value.present? %>
3
3
  <% if @field.value.attached? && @field.value.representable? && @field.is_image %>
4
- <%= link_to_if @field.link_to_record, image_tag(helpers.main_app.url_for(@field.value), class: 'h-10'), resource_view_path, class: 'block' %>
4
+ <%= link_to_if @field.link_to_resource, image_tag(helpers.main_app.url_for(@field.value), class: 'h-10'), resource_view_path, class: 'block' %>
5
5
  <% elsif @field.value.attached? && @field.is_audio %>
6
- <%= link_to_if @field.link_to_record, audio_tag(helpers.main_app.url_for(@field.value), controls: true, preload: false, class: 'max-h-full h-10'), resource_view_path, class: 'block h-8' %>
6
+ <%= link_to_if @field.link_to_resource, audio_tag(helpers.main_app.url_for(@field.value), controls: true, preload: false, class: 'max-h-full h-10'), resource_view_path, class: 'block h-8' %>
7
7
  <% else %>
8
8
  <%= @field.value.filename %>
9
9
  <% end %>
@@ -4,7 +4,7 @@
4
4
  default: @field.default,
5
5
  size: @field.size,
6
6
  rounded: @field.rounded,
7
- link_to_record: @field.link_to_record,
7
+ link_to_resource: @field.link_to_resource,
8
8
  link: resource_view_path,
9
9
  title: t('avo.view_item', item: @resource.name).humanize
10
10
  )
@@ -1,3 +1,3 @@
1
1
  <div <% if @index == 0 %> class="overflow-hidden rounded-t" <% end %> data-field-id="<%= @field.id %>">
2
- <%= render Avo::Fields::Common::HeadingComponent.new value: @field.value, as_html: @field.as_html %>
2
+ <%= render Avo::Fields::Common::HeadingComponent.new value: @field.name, as_html: @field.as_html, empty: @field.empty %>
3
3
  </div>
@@ -1,3 +1,3 @@
1
1
  <div <% if @index == 0 %> class="overflow-hidden rounded-t" <% end %> data-field-id="<%= @field.id %>">
2
- <%= render Avo::Fields::Common::HeadingComponent.new value: @field.value, as_html: @field.as_html %>
2
+ <%= render Avo::Fields::Common::HeadingComponent.new value: @field.name, as_html: @field.as_html, empty: @field.empty %>
3
3
  </div>
@@ -1,3 +1,3 @@
1
1
  <%= index_field_wrapper **field_wrapper_args, class: 'whitespace-no-wrap w-[1%]' do %>
2
- <% link_to_if (@field.link_to_record or Avo.configuration.id_links_to_resource), @field.value, resource_view_path, title: t('avo.view_item', item: @resource.name).humanize %>
2
+ <% link_to_if (@field.link_to_resource or Avo.configuration.id_links_to_resource), @field.value, resource_view_path, title: t('avo.view_item', item: @resource.name).humanize %>
3
3
  <% end %>
@@ -13,7 +13,7 @@ class Avo::Fields::IndexComponent < Avo::BaseComponent
13
13
  @index = index
14
14
  @parent_record = parent_record
15
15
  @parent_resource = parent_resource
16
- @view = Avo::ViewInquirer.new("index")
16
+ @view = :index
17
17
  @reflection = reflection
18
18
  end
19
19
 
@@ -18,7 +18,7 @@ class Avo::Fields::ShowComponent < ViewComponent::Base
18
18
  @resource = resource
19
19
  @stacked = stacked
20
20
  @short = short
21
- @view = Avo::ViewInquirer.new("show")
21
+ @view = :show
22
22
  end
23
23
 
24
24
  def wrapper_data
@@ -4,6 +4,6 @@
4
4
  <% elsif @field.protocol.present? %>
5
5
  <%= link_to @field.value, "#{@field.protocol}:#{@field.value}" %>
6
6
  <% else %>
7
- <%= link_to_if @field.link_to_record, @field.value, resource_view_path %>
7
+ <%= link_to_if @field.link_to_resource, @field.value, resource_view_path %>
8
8
  <% end %>
9
9
  <% end %>
@@ -11,7 +11,7 @@ class Avo::Index::FieldWrapperComponent < ViewComponent::Base
11
11
  @classes = args[:class].present? ? args[:class] : ""
12
12
  @args = args
13
13
  @flush = flush
14
- @view = Avo::ViewInquirer.new("index")
14
+ @view = :index
15
15
  end
16
16
 
17
17
  def classes
@@ -23,7 +23,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
23
23
  end
24
24
 
25
25
  def can_view?
26
- return false if Avo.configuration.resource_default_view.edit?
26
+ return false if Avo.configuration.resource_default_view == :edit
27
27
 
28
28
  return authorize_association_for(:show) if @reflection.present?
29
29
 
@@ -17,12 +17,18 @@ class Avo::Index::ResourceTableComponent < ViewComponent::Base
17
17
 
18
18
  def encrypted_query
19
19
  # TODO: move this to the resource where we can apply the adapter pattern
20
- if Module.const_defined?("Ransack::Search") && query.instance_of?(Ransack::Search)
21
- @query = @query.result
20
+ serialized_query = if Module.const_defined?("Ransack::Search") && query.instance_of?(Ransack::Search)
21
+ query.context.object.to_sql
22
+ else
23
+ return :select_all_disabled if query.nil? || !query.respond_to?(:all) || !query.all.respond_to?(:to_sql)
24
+
25
+ query.all.to_sql
22
26
  end
23
27
 
28
+ return if serialized_query.nil?
29
+
24
30
  Avo::Services::EncryptionService.encrypt(
25
- message: Marshal.dump(@query),
31
+ message: serialized_query,
26
32
  purpose: :select_all
27
33
  )
28
34
  end
@@ -53,16 +53,11 @@ class Avo::ResourceComponent < Avo::BaseComponent
53
53
  end
54
54
 
55
55
  def destroy_path
56
- args = {record: @resource.record, resource: @resource}
57
-
58
- args[:referrer] = if params[:via_resource_class].present?
59
- back_path
60
- # If we're deleting a resource from a parent resource, we need to go back to the parent resource page after the deletion
61
- elsif @parent_resource.present?
62
- helpers.resource_path(record: @parent_record, resource: @parent_resource)
56
+ if params[:via_resource_class].present?
57
+ helpers.resource_path(record: @resource.record, resource: @resource, referrer: back_path)
58
+ else
59
+ helpers.resource_path(record: @resource.record, resource: @resource)
63
60
  end
64
-
65
- helpers.resource_path(**args)
66
61
  end
67
62
 
68
63
  # Ex: A Post has many Comments
@@ -1,12 +1,12 @@
1
1
  <div class="text-black border-gray-150 p-4 flex border-t">
2
- <div class="flex-1 flex space-x-4 w-full">
2
+ <div class="flex-1 flex space-x-4">
3
3
  <% if avatar.present? %>
4
- <div class="relative aspect-square w-10 h-10 overflow-hidden rounded shrink-0">
4
+ <div class="relative aspect-square w-10 h-10 overflow-hidden rounded">
5
5
  <%= image_tag avatar, class: "object-cover min-w-full min-h-full h-full" %>
6
6
  </div>
7
7
  <% end %>
8
- <div class="flex flex-col pr-3 min-w-0">
9
- <div class="font-medium text-ellipsis overflow-hidden">
8
+ <div class="flex flex-col">
9
+ <div class="font-medium">
10
10
  <%= name %>
11
11
  </div>
12
12
  <% if title.present? %>
@@ -25,7 +25,7 @@
25
25
  # On edit screens we want to load each tab because we wnst the DOM to have the fields present on form submission.
26
26
  # If you have a field which is in the second tab and it's required, the form submission will fail because the required field is not in view, and we don't want that.
27
27
  # We also want to load the current tab
28
- should_lazy_load = if @view.in?(%w[edit new update create])
28
+ should_lazy_load = if @view.to_s.in?(['edit', 'new', 'update', 'create'])
29
29
  false
30
30
  else
31
31
  !is_current_tab