avo 3.0.0.pre8 → 3.0.0.pre9

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/assets/stylesheets/avo.base.css +0 -1
  4. data/app/assets/svgs/map-empty-state.svg +35 -0
  5. data/app/assets/svgs/map-view-type.svg +3 -0
  6. data/app/components/avo/field_wrapper_component.html.erb +2 -2
  7. data/app/components/avo/fields/area_field/edit_component.html.erb +7 -0
  8. data/app/components/avo/fields/area_field/edit_component.rb +4 -0
  9. data/app/components/avo/fields/area_field/show_component.html.erb +8 -0
  10. data/app/components/avo/fields/area_field/show_component.rb +4 -0
  11. data/app/components/avo/fields/common/files/controls_component.html.erb +29 -0
  12. data/app/components/avo/fields/common/files/controls_component.rb +19 -0
  13. data/app/components/avo/fields/common/files/list_viewer_component.html.erb +20 -0
  14. data/app/components/avo/fields/common/files/list_viewer_component.rb +41 -0
  15. data/app/components/avo/fields/common/files/view_type/grid_component.html.erb +27 -0
  16. data/app/components/avo/fields/common/{single_file_viewer_component.rb → files/view_type/grid_component.rb} +2 -9
  17. data/app/components/avo/fields/common/files/view_type/list_component.html.erb +22 -0
  18. data/app/components/avo/fields/common/files/view_type/list_component.rb +15 -0
  19. data/app/components/avo/fields/country_field/edit_component.html.erb +2 -1
  20. data/app/components/avo/fields/file_field/edit_component.html.erb +1 -1
  21. data/app/components/avo/fields/file_field/show_component.html.erb +1 -1
  22. data/app/components/avo/fields/files_field/edit_component.html.erb +1 -1
  23. data/app/components/avo/fields/files_field/show_component.html.erb +1 -1
  24. data/app/components/avo/fields/location_field/show_component.html.erb +1 -1
  25. data/app/components/avo/fields/number_field/edit_component.html.erb +2 -1
  26. data/app/components/avo/fields/password_field/edit_component.html.erb +2 -1
  27. data/app/components/avo/fields/select_field/edit_component.html.erb +2 -1
  28. data/app/components/avo/fields/text_field/edit_component.html.erb +2 -1
  29. data/app/components/avo/index/resource_map_component.html.erb +16 -0
  30. data/app/components/avo/index/resource_map_component.rb +109 -0
  31. data/app/components/avo/views/resource_index_component.html.erb +10 -1
  32. data/app/controllers/avo/application_controller.rb +5 -1
  33. data/app/controllers/avo/attachments_controller.rb +15 -8
  34. data/app/views/avo/attachments/destroy.turbo_stream.erb +7 -0
  35. data/app/views/avo/partials/_view_toggle_button.html.erb +9 -0
  36. data/db/factories.rb +15 -0
  37. data/lib/avo/app.rb +12 -6
  38. data/lib/avo/base_action.rb +4 -4
  39. data/lib/avo/base_resource.rb +2 -0
  40. data/lib/avo/fields/area_field.rb +39 -0
  41. data/lib/avo/fields/base_field.rb +6 -2
  42. data/lib/avo/fields/files_field.rb +4 -0
  43. data/lib/avo/fields/location_field.rb +0 -1
  44. data/lib/avo/resources/resource_manager.rb +7 -11
  45. data/lib/avo/services/debug_service.rb +1 -0
  46. data/lib/avo/services/telemetry_service.rb +1 -0
  47. data/lib/avo/version.rb +1 -1
  48. data/lib/generators/avo/tailwindcss/install_generator.rb +4 -1
  49. data/lib/generators/avo/templates/tailwindcss/Procfile.dev +1 -1
  50. data/public/avo-assets/avo.base.css +1395 -1349
  51. metadata +20 -6
  52. data/app/components/avo/fields/common/files_list_viewer_component.html.erb +0 -5
  53. data/app/components/avo/fields/common/files_list_viewer_component.rb +0 -8
  54. data/app/components/avo/fields/common/single_file_viewer_component.html.erb +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1330e65c3c0ee5eda7738928fe8b9dc98a75df09fc9d30012e94c714767233b1
4
- data.tar.gz: ab36b3c80f8ae22c48fc2529373b507616746c6f7e711ebff1210c902a1b3a9d
3
+ metadata.gz: c753dc99c778487821cb4c4a73f67fb2408ea2f5e0becb69da6efa2bc66eaece
4
+ data.tar.gz: 594e206c1029f10ce74e5815bac2cbc9a0fd119cbac25536adf85f672d856e43
5
5
  SHA512:
6
- metadata.gz: c351cedaf01797b64483591b0f5a96bb4ee1dedef576df314b55d7bb668505e601220b4eef33cabdebcf19162508adbc4ad49f6326cad2932d2fe792e31e848f
7
- data.tar.gz: 4aa891eab38f40b7468f43327e26175963b9c1e95016d09756ddac428863e69e3ad000124d04e67570c0f9a1d7ff73196b282b4de76a45f4856814296d04dea3
6
+ metadata.gz: 84872aebb1988fa4e25323031c4ac6f9be0ced56db0913a2073026946c85888e0824d075f8c46e02d9230037480ed4e8057c565f525a18ce5a5df2975302df39
7
+ data.tar.gz: 2e059cfce06864f424a132347f2f957d6e138ae721ca9a73a177cf2af371598b9eec00f1ec9ce0e92ded29f79ba7efbbf3382388b8a092a4d2f0e072ec95d7d9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.0.0.pre8)
4
+ avo (3.0.0.pre9)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -70,7 +70,6 @@ body {
70
70
  @apply opacity-0 translate-y-1;
71
71
  }
72
72
 
73
-
74
73
  .turbo-progress-bar {
75
74
  @apply bg-primary-400;
76
75
  }
@@ -0,0 +1,35 @@
1
+ <svg width="248" height="287" viewBox="0 0 248 287" fill="none" xmlns="http://www.w3.org/2000/svg" data-target="grid-empty-state-svg">
2
+ <path d="M124 270.227C192.483 270.227 248 214.71 248 146.227C248 77.7433 192.483 22.2266 124 22.2266C55.5167 22.2266 0 77.7433 0 146.227C0 214.71 55.5167 270.227 124 270.227Z" fill="rgb(var(--color-primary-100))"/>
3
+ <g filter="rgb(var(--color-primary-100))">
4
+ <path d="M195.093 93.3198H52.9068C48.3412 93.3198 44.6401 97.0209 44.6401 101.586V275.186C44.6401 279.752 48.3412 283.453 52.9068 283.453H195.093C199.659 283.453 203.36 279.752 203.36 275.186V101.586C203.36 97.0209 199.659 93.3198 195.093 93.3198Z" fill="white"/>
5
+ </g>
6
+ <path d="M107.467 118.12H64.48C61.7407 118.12 59.52 120.34 59.52 123.08C59.52 125.819 61.7407 128.04 64.48 128.04H107.467C110.206 128.04 112.427 125.819 112.427 123.08C112.427 120.34 110.206 118.12 107.467 118.12Z" fill="rgb(var(--color-primary-100))"/>
7
+ <path d="M137.227 139.613H64.48C61.7407 139.613 59.52 141.834 59.52 144.573C59.52 147.312 61.7407 149.533 64.48 149.533H137.227C139.966 149.533 142.187 147.312 142.187 144.573C142.187 141.834 139.966 139.613 137.227 139.613Z" fill="rgb(var(--color-primary-100))" opacity="0.6"/>
8
+ <path d="M107.467 162.76H64.48C61.7407 162.76 59.52 164.981 59.52 167.72C59.52 170.459 61.7407 172.68 64.48 172.68H107.467C110.206 172.68 112.427 170.459 112.427 167.72C112.427 164.981 110.206 162.76 107.467 162.76Z" fill="rgb(var(--color-primary-100))"/>
9
+ <path d="M137.227 184.253H64.48C61.7407 184.253 59.52 186.474 59.52 189.213C59.52 191.953 61.7407 194.173 64.48 194.173H137.227C139.966 194.173 142.187 191.953 142.187 189.213C142.187 186.474 139.966 184.253 137.227 184.253Z" fill="rgb(var(--color-primary-100))" opacity="0.6"/>
10
+ <path d="M107.467 207.4H64.48C61.7407 207.4 59.52 209.621 59.52 212.36C59.52 215.099 61.7407 217.32 64.48 217.32H107.467C110.206 217.32 112.427 215.099 112.427 212.36C112.427 209.621 110.206 207.4 107.467 207.4Z" fill="rgb(var(--color-primary-100))"/>
11
+ <path d="M137.227 228.893H64.48C61.7407 228.893 59.52 231.114 59.52 233.853C59.52 236.592 61.7407 238.813 64.48 238.813H137.227C139.966 238.813 142.187 236.592 142.187 233.853C142.187 231.114 139.966 228.893 137.227 228.893Z" fill="rgb(var(--color-primary-100))" opacity="0.6"/>
12
+ <g filter="url(#filter1_d_577_1090)">
13
+ <path d="M195.093 9H52.9068C48.3412 9 44.6401 12.7011 44.6401 17.2667V66.8667C44.6401 71.4322 48.3412 75.1333 52.9068 75.1333H195.093C199.659 75.1333 203.36 71.4322 203.36 66.8667V17.2667C203.36 12.7011 199.659 9 195.093 9Z" fill="rgb(var(--color-primary-500))"/>
14
+ </g>
15
+ <path d="M107.467 27.1865H64.48C61.7407 27.1865 59.52 29.4072 59.52 32.1465C59.52 34.8859 61.7407 37.1065 64.48 37.1065H107.467C110.206 37.1065 112.427 34.8859 112.427 32.1465C112.427 29.4072 110.206 27.1865 107.467 27.1865Z" fill="rgb(var(--color-primary-100))"/>
16
+ <path d="M137.227 48.6799H64.48C61.7407 48.6799 59.52 50.9006 59.52 53.6399C59.52 56.3793 61.7407 58.5999 64.48 58.5999H137.227C139.966 58.5999 142.187 56.3793 142.187 53.6399C142.187 50.9006 139.966 48.6799 137.227 48.6799Z" fill="white"/>
17
+ <defs>
18
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
19
+ <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
20
+ <feOffset dy="-3"/>
21
+ <feGaussianBlur stdDeviation="3"/>
22
+ <feColorMatrix type="matrix" values="0 0 0 0 0.788235 0 0 0 0 0.803922 0 0 0 0 0.85098 0 0 0 0.349 0"/>
23
+ <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_577_1090"/>
24
+ <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_577_1090" result="shape"/>
25
+ <filter id="filter1_d_577_1090" x="38.6401" y="0" width="170.72" height="78.1333" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
26
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
27
+ <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
28
+ <feOffset dy="-3"/>
29
+ <feGaussianBlur stdDeviation="3"/>
30
+ <feColorMatrix type="matrix" values="0 0 0 0 0.788235 0 0 0 0 0.803922 0 0 0 0 0.85098 0 0 0 0.349 0"/>
31
+ <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_577_1090"/>
32
+ <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_577_1090" result="shape"/>
33
+ </filter>
34
+ </defs>
35
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
2
+ <path stroke-linecap="round" stroke-linejoin="round" d="M9 6.75V15m6-6v8.25m.503 3.498l4.875-2.437c.381-.19.622-.58.622-1.006V4.82c0-.836-.88-1.38-1.628-1.006l-3.869 1.934c-.317.159-.69.159-1.006 0L9.503 3.252a1.125 1.125 0 00-1.006 0L3.622 5.689C3.24 5.88 3 6.27 3 6.695V19.18c0 .836.88 1.38 1.628 1.006l3.869-1.934c.317-.159.69-.159 1.006 0l4.994 2.497c.317.158.69.158 1.006 0z"/>
3
+ </svg>
@@ -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 <% else %> md:pt-0 <% if short? %> md:h-10 <% else %> md:h-14 <% end %> <% end %> pt-4 flex self-start items-center <%= @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 %>
@@ -11,7 +11,7 @@
11
11
  <% if on_edit? && field.is_required? %> <span class="text-red-600 ml-1">*</span> <% end %>
12
12
  </div>
13
13
  <div class="flex-1 flex flex-row md:min-h-inherit py-2 <% if stacked? %> pb-4 <% else %><% end %> px-6 <%= @field.get_html(:classes, view: view, element: :content) %>" data-slot="value">
14
- <div class="self-center <% if full_width? || compact? || stacked? %> w-full <% else %> md:w-8/12 <% end %>">
14
+ <div class="self-center w-full <% unless full_width? || compact? || stacked? %> md:w-8/12 <% end %>">
15
15
  <% if on_show? %>
16
16
  <% if field.value.blank? and dash_if_blank %>
17
17
 
@@ -0,0 +1,7 @@
1
+ <%= field_wrapper **field_wrapper_args do %>
2
+ <%= @form.text_field field.id,
3
+ class: classes("w-full"),
4
+ value: field.value.to_s,
5
+ placeholder: field.placeholder,
6
+ disabled: disabled? %>
7
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::AreaField::EditComponent < Avo::Fields::EditComponent
4
+ end
@@ -0,0 +1,8 @@
1
+ <%= field_wrapper **field_wrapper_args do %>
2
+ <% if field.value.present? %>
3
+ <%= area_map field.map_data, **field.mapkick_options %>
4
+ <% else %>
5
+
6
+ <% end %>
7
+ <% end %>
8
+
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::AreaField::ShowComponent < Avo::Fields::ShowComponent
4
+ end
@@ -0,0 +1,29 @@
1
+ <div class="flex">
2
+ <% if can_download_file? %>
3
+ <%= a_link Rails.application.routes.url_helpers.rails_blob_path(file, only_path: true, disposition: :attachment),
4
+ icon: 'heroicons/outline/download',
5
+ color: :primary,
6
+ download: true,
7
+ class: 'text-center',
8
+ title: t('avo.download_file'),
9
+ data: { tippy: :tooltip },
10
+ compact: true,
11
+ size: :xs %>
12
+ <% end %>
13
+ </div>
14
+ <div>
15
+ <% if can_delete_file? %>
16
+ <%= a_link destroy_path,
17
+ icon: 'heroicons/outline/trash',
18
+ color: :red,
19
+ compact: true,
20
+ size: :xs,
21
+ class: 'text-center',
22
+ title: t('avo.delete_file', item: file.filename),
23
+ data: {
24
+ turbo_method: :delete,
25
+ turbo_confirm: t('avo.are_you_sure'),
26
+ tippy: :tooltip
27
+ } %>
28
+ <% end %>
29
+ </div>
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::Common::Files::ControlsComponent < ViewComponent::Base
4
+ include Avo::ApplicationHelper
5
+ include Avo::Fields::Concerns::FileAuthorization
6
+
7
+ attr_reader :file, :field, :resource
8
+ delegate :id, to: :field
9
+
10
+ def initialize(field:, file:, resource:)
11
+ @field = field
12
+ @file = file
13
+ @resource = resource
14
+ end
15
+
16
+ def destroy_path
17
+ Avo::Services::URIService.parse(@resource.record_path).append_paths("active_storage_attachments", id, file.id).to_s
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ <%= content_tag :div, class: wrapper_classes do %>
2
+ <%= turbo_frame_tag @field.id do %>
3
+ <% unless @field.hide_view_type_switcher %>
4
+ <div class="justify-self-end flex justify-end items-center space-x-3">
5
+ <%= render partial: 'avo/partials/view_toggle_button',
6
+ locals: {
7
+ available_view_types: available_view_types,
8
+ view_type: view_type,
9
+ turbo_frame: @field.id,
10
+ }
11
+ %>
12
+ </div>
13
+ <% end %>
14
+ <div class="<%= classes %>">
15
+ <% @field.value.attachments.each do |file| %>
16
+ <%= render view_type_component(file) %>
17
+ <% end %>
18
+ </div>
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::Common::Files::ListViewerComponent < ViewComponent::Base
4
+ include Turbo::FramesHelper
5
+
6
+ attr_reader :field, :resource
7
+
8
+ def initialize(field:, resource:)
9
+ @field = field
10
+ @resource = resource
11
+ end
12
+
13
+ def classes
14
+ base_classes = "py-4 rounded-xl max-w-full"
15
+
16
+ view_type_classes = if view_type == :list
17
+ "flex flex-col space-y-2"
18
+ else
19
+ "relative grid xs:grid-cols-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-6 gap-6"
20
+ end
21
+
22
+ "#{base_classes} #{view_type_classes}"
23
+ end
24
+
25
+ def wrapper_classes
26
+ (field.stacked && !field.hide_view_type_switcher) ? "-mt-9" : ""
27
+ end
28
+
29
+ def available_view_types
30
+ [:list, :grid]
31
+ end
32
+
33
+ def view_type_component(file)
34
+ component = "Avo::Fields::Common::Files::ViewType::#{view_type.to_s.capitalize}Component".constantize
35
+ component.new(field: field, resource: resource, file: file)
36
+ end
37
+
38
+ def view_type
39
+ (resource.params.dig(:view_type) || field.view_type).to_sym
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ <div id="<%= dom_id file %>" class="relative min-h-full max-w-full flex-1 flex flex-col justify-between space-y-2">
2
+ <% if file.present? %>
3
+ <div class="flex flex-col justify-between h-full">
4
+ <% if file.representable? && is_image? %>
5
+ <%= image_tag helpers.main_app.url_for(file), class: 'rounded-lg object-cover w-full aspect-video' %>
6
+ <% elsif is_audio? %>
7
+ <%= audio_tag(helpers.main_app.url_for(file), controls: true, preload: false, class: 'w-full') %>
8
+ <% elsif is_video? %>
9
+ <%= video_tag(helpers.main_app.url_for(file), controls: true, preload: false, class: 'w-full') %>
10
+ <% else %>
11
+ <div class="relative flex flex-col justify-evenly items-center px-2 rounded-lg border bg-white border-gray-500 min-h-24">
12
+ <div class="flex flex-col justify-center items-center w-full">
13
+ <%= helpers.svg 'document-text', class: 'h-10 text-gray-600 mb-2' %>
14
+ </div>
15
+ </div>
16
+ <% end %>
17
+ <% if field.display_filename %>
18
+ <span class="text-gray-500 mt-1 text-sm truncate" title="<%= file.filename %>"><%= file.filename %></span>
19
+ <% end %>
20
+ </div>
21
+ <div class="flex space-x-2">
22
+ <%= render Avo::Fields::Common::Files::ControlsComponent.new(field: field, file: file, resource: resource) %>
23
+ </div>
24
+ <% else %>
25
+
26
+ <% end %>
27
+ </div>
@@ -1,10 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Avo::Fields::Common::SingleFileViewerComponent < ViewComponent::Base
4
- include Avo::ApplicationHelper
5
- include Avo::Fields::Concerns::FileAuthorization
6
-
7
- attr_reader :field
3
+ class Avo::Fields::Common::Files::ViewType::GridComponent < ViewComponent::Base
4
+ attr_reader :field, :resource
8
5
 
9
6
  def initialize(field:, resource:, file: nil)
10
7
  @file = file
@@ -12,10 +9,6 @@ class Avo::Fields::Common::SingleFileViewerComponent < ViewComponent::Base
12
9
  @resource = resource
13
10
  end
14
11
 
15
- def destroy_path
16
- Avo::Services::URIService.parse(@resource.record_path).append_paths("active_storage_attachments", id, file.id).to_s
17
- end
18
-
19
12
  def id
20
13
  field.id
21
14
  end
@@ -0,0 +1,22 @@
1
+ <div id="<%= dom_id file %>" class="relative min-h-full max-w-full flex-1 flex">
2
+ <% if file.present? %>
3
+ <div class="grid grid-cols-6 gap-2 items-center max-w-full w-full">
4
+ <div class="col-span-4 flex-1 flex flex-row items-center text-gray-700 overflow-x-auto mac-styled-scrollbar ">
5
+ <div class="rounded-full bg-slate-100 border border-gray-500 p-1.5 flex items-center justify-center">
6
+ <%= helpers.svg icon_for_file, class: "h-5 text-gray-600" %>
7
+ </div>
8
+ <p class="items-center h-full p-2 flex-shrink-0">
9
+ <%= file.filename %>
10
+ </p>
11
+ </div>
12
+ <div class="text-gray-700 flex-shrink-0 text-sm">
13
+ <%= helpers.number_to_human_size(file.byte_size) %>
14
+ </div>
15
+ <div class="flex space-x-2 justify-end col-span-1 flex-shrink-0">
16
+ <%= render Avo::Fields::Common::Files::ControlsComponent.new(field: field, file: file, resource: resource) %>
17
+ </div>
18
+ </div>
19
+ <% else %>
20
+
21
+ <% end %>
22
+ </div>
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::Common::Files::ViewType::ListComponent < Avo::Fields::Common::Files::ViewType::GridComponent
4
+ def icon_for_file
5
+ if is_image?
6
+ "photo"
7
+ elsif is_audio?
8
+ "speaker-wave"
9
+ elsif is_video?
10
+ "video-camera"
11
+ else
12
+ "document"
13
+ end
14
+ end
15
+ end
@@ -10,6 +10,7 @@
10
10
  data: @field.get_html(:data, view: view, element: :input),
11
11
  disabled: disabled?,
12
12
  style: @field.get_html(:style, view: view, element: :input),
13
- placeholder: @field.include_blank.present? ? nil : @field.placeholder
13
+ placeholder: @field.include_blank.present? ? nil : @field.placeholder,
14
+ autocomplete: @field.autocomplete
14
15
  %>
15
16
  <% end %>
@@ -1,7 +1,7 @@
1
1
  <%= field_wrapper **field_wrapper_args do %>
2
2
  <% if @field.value.present? %>
3
3
  <div class="mb-2">
4
- <%= render Avo::Fields::Common::SingleFileViewerComponent.new resource: @resource, field: @field %>
4
+ <%= render Avo::Fields::Common::Files::ViewType::GridComponent.new resource: @resource, field: @field %>
5
5
  </div>
6
6
  <% end %>
7
7
 
@@ -1,3 +1,3 @@
1
1
  <%= field_wrapper **field_wrapper_args do %>
2
- <%= render Avo::Fields::Common::SingleFileViewerComponent.new resource: @resource, field: @field %>
2
+ <%= render Avo::Fields::Common::Files::ViewType::GridComponent.new resource: @resource, field: @field %>
3
3
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
- <%= render Avo::Fields::Common::FilesListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
2
+ <%= render Avo::Fields::Common::Files::ListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
3
3
 
4
4
  <% if can_upload_file? %>
5
5
  <div class="mt-2">
@@ -1,3 +1,3 @@
1
1
  <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
- <%= render Avo::Fields::Common::FilesListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
2
+ <%= render Avo::Fields::Common::Files::ListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
3
3
  <% end %>
@@ -1,6 +1,6 @@
1
1
  <%= field_wrapper **field_wrapper_args do %>
2
2
  <% if field.value_present? %>
3
- <%= js_map [{latitude: field.value[0], longitude: field.value[1]}] %>
3
+ <%= js_map [{latitude: field.value[0], longitude: field.value[1]}], id: "location-map" %>
4
4
  <% else %>
5
5
 
6
6
  <% end %>
@@ -7,6 +7,7 @@
7
7
  min: @field.min,
8
8
  placeholder: @field.placeholder,
9
9
  step: @field.step,
10
- style: @field.get_html(:style, view: view, element: :input)
10
+ style: @field.get_html(:style, view: view, element: :input),
11
+ autocomplete: @field.autocomplete
11
12
  %>
12
13
  <% end %>
@@ -4,6 +4,7 @@
4
4
  data: @field.get_html(:data, view: view, element: :input),
5
5
  disabled: disabled?,
6
6
  placeholder: @field.placeholder,
7
- style: @field.get_html(:style, view: view, element: :input)
7
+ style: @field.get_html(:style, view: view, element: :input),
8
+ autocomplete: @field.autocomplete
8
9
  %>
9
10
  <% end %>
@@ -10,6 +10,7 @@
10
10
  disabled: disabled?,
11
11
  style: @field.get_html(:style, view: view, element: :input),
12
12
  value: @field.record.present? ? @field.record[@field.id] : @field.value,
13
- placeholder: @field.include_blank.present? ? nil : @field.placeholder
13
+ placeholder: @field.include_blank.present? ? nil : @field.placeholder,
14
+ autocomplete: @field.autocomplete
14
15
  %>
15
16
  <% end %>
@@ -6,6 +6,7 @@
6
6
  placeholder: @field.placeholder,
7
7
  style: @field.get_html(:style, view: view, element: :input),
8
8
  # value: @field.value,
9
- multiple: multiple
9
+ multiple: multiple,
10
+ autocomplete: @field.autocomplete
10
11
  %>
11
12
  <% end %>
@@ -0,0 +1,16 @@
1
+ <% if @resources.present? %>
2
+ <div class="map-view-container grid <%= grid_layout_classes %>">
3
+ <div class="map-component min-h-full <%= map_component_order_class %>">
4
+ <%= js_map(resource_location_markers, **resource_mapkick_options) %>
5
+ </div>
6
+ <% if render_table? %>
7
+ <div class="overflow-auto<%= table_component_order_class %>">
8
+ <%= render(Avo::Index::ResourceTableComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_record: @parent_record, parent_resource: @parent_resource, pagy: @pagy, query: @query)) %>
9
+ </div>
10
+ <% end %>
11
+ </div>
12
+ <% else %>
13
+ <div class="bg-white rounded shadow-panel">
14
+ <%= helpers.empty_state by_association: params[:related_name].present?, view_type: :map %>
15
+ </div>
16
+ <% end %>
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avo
4
+ module Index
5
+ # Render a map view for a list of resources, where each resource is
6
+ # expected to have an attribute/attribute set representing its location.
7
+ class ResourceMapComponent < ViewComponent::Base
8
+ attr_reader :resources
9
+
10
+ def initialize(resources: nil, resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, pagy: nil, query: nil)
11
+ super
12
+ @resources = resources
13
+ @resource = resource
14
+ @reflection = reflection
15
+ @parent_record = parent_record
16
+ @parent_resource = parent_resource
17
+ @pagy = pagy
18
+ @query = query
19
+ end
20
+
21
+ def grid_layout_classes
22
+ return unless render_table?
23
+
24
+ if table_positioned_horizontally
25
+ "grid-flow-row sm:grid-flow-col grid-rows-1 auto-cols-fr"
26
+ elsif table_positioned_vertically
27
+ "grid-flow-row grid-cols-1"
28
+ end
29
+ end
30
+
31
+ def table_positioned_horizontally
32
+ %i[left right].include?(map_view_table_layout)
33
+ end
34
+
35
+ def table_positioned_vertically
36
+ %i[bottom top].include?(map_view_table_layout)
37
+ end
38
+
39
+ def map_component_order_class
40
+ if render_table? && table_positioned_at_the_start
41
+ "order-last"
42
+ else
43
+ "order-first"
44
+ end
45
+ end
46
+
47
+ def table_component_order_class
48
+ if table_positioned_at_the_start
49
+ "order-first"
50
+ else
51
+ "order-last"
52
+ end
53
+ end
54
+
55
+ def table_positioned_at_the_start
56
+ %i[left top].include?(map_view_table_layout)
57
+ end
58
+
59
+ def map_view_table_layout
60
+ map_options.dig(:table, :layout)
61
+ end
62
+
63
+ def resource_location_markers
64
+ # If we have no proc and no default location method, don't try to create markers
65
+ return [] unless resource_mappable?
66
+
67
+ resources
68
+ .map do |resource|
69
+ Avo::ExecutionContext.new(target: marker_proc, record: resource.record).handle
70
+ end
71
+ .compact
72
+ .filter do |coordinates|
73
+ coordinates[:latitude].present? && coordinates[:longitude].present?
74
+ end
75
+ end
76
+
77
+ def resource_mapkick_options
78
+ map_options[:mapkick_options] || {}
79
+ end
80
+
81
+ def render_table?
82
+ map_options.dig(:table, :visible)
83
+ end
84
+
85
+ private
86
+
87
+ def default_record_marker_proc
88
+ lambda {
89
+ {
90
+ latitude: record.coordinates.first,
91
+ longitude: record.coordinates.last
92
+ }
93
+ }
94
+ end
95
+
96
+ def map_options
97
+ @resource.map_view || {}
98
+ end
99
+
100
+ def marker_proc
101
+ map_options[:record_marker] || default_record_marker_proc
102
+ end
103
+
104
+ def resource_mappable?
105
+ map_options[:record_marker].present? || @resources.first.record.respond_to?(:coordinates)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -49,7 +49,16 @@
49
49
  <% end %>
50
50
  <% end %>
51
51
  <% c.with_bare_content do %>
52
- <% if view_type.to_sym == :table %>
52
+ <% if view_type.to_sym == :map %>
53
+ <% if @resources.present? %>
54
+ <div>
55
+ <%= render(Avo::Index::ResourceMapComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_record: @parent_record, parent_resource: @parent_resource, pagy: @pagy, query: @query)) %>
56
+ </div>
57
+ <% else %>
58
+ <%= helpers.empty_state by_association: params[:related_name].present?, view_type: view_type, add_background: true %>
59
+ <% end %>
60
+ <% end %>
61
+ <% if view_type.to_sym == :table || view_type.to_sym == :map %>
53
62
  <% if @records.present? %>
54
63
  <div class="mt-4">
55
64
  <%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: turbo_frame || 'none', index_params: @index_params, resource: @resource, parent_record: parent_record, discreet_pagination: field&.discreet_pagination %>
@@ -107,6 +107,10 @@ module Avo
107
107
  def set_record_to_fill
108
108
  @record_to_fill = @resource.model_class.new if @view == :create
109
109
  @record_to_fill = @record if @view == :update
110
+
111
+ # If resource.record is nil, most likely the user is creating a new record.
112
+ # In that case, to access resource.record in visible and readonly blocks we hydrate the resource with a new record.
113
+ @resource.hydrate(record: @record_to_fill) if @resource.record.nil?
110
114
  end
111
115
 
112
116
  def fill_record
@@ -285,7 +289,7 @@ module Avo
285
289
  if Rails::VERSION::MAJOR === 6
286
290
  ActiveStorage::Current.host = request.base_url
287
291
  elsif Rails::VERSION::MAJOR === 7
288
- ActiveStorage::Current.url_options = request.base_url
292
+ ActiveStorage::Current.url_options = {protocol: request.protocol, host: request.host, port: request.port}
289
293
  end
290
294
  end
291
295
  rescue => exception
@@ -23,17 +23,24 @@ module Avo
23
23
  end
24
24
 
25
25
  def destroy
26
- raise Avo::NotAuthorizedError.new unless authorized_to :delete
26
+ if authorized_to :delete
27
+ attachment = ActiveStorage::Attachment.find(params[:attachment_id])
27
28
 
28
- attachment = ActiveStorage::Attachment.find(params[:attachment_id])
29
- path = resource_path(record: @record, resource: @resource)
29
+ flash[:notice] = if attachment.present?
30
+ @destroyed = attachment.destroy
30
31
 
31
- if attachment.present?
32
- attachment.destroy
33
-
34
- redirect_to params[:referrer] || path, notice: t("avo.attachment_destroyed")
32
+ t("avo.attachment_destroyed")
33
+ else
34
+ t("avo.failed_to_find_attachment")
35
+ end
35
36
  else
36
- redirect_back fallback_location: path, notice: t("avo.failed_to_find_attachment")
37
+ flash[:notice] = t("avo.not_authorized")
38
+ end
39
+
40
+ respond_to do |format|
41
+ format.turbo_stream do
42
+ render "destroy"
43
+ end
37
44
  end
38
45
  end
39
46
 
@@ -0,0 +1,7 @@
1
+ <%= turbo_stream.remove dom_id(@destroyed) if @destroyed.present? %>
2
+
3
+ <turbo-stream action="append" target="alerts">
4
+ <template>
5
+ <%= render Avo::FlashAlertsComponent.new flashes: flash %>
6
+ </template>
7
+ </turbo-stream>