avo 2.29.1.pre.pr1652 → 2.30.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d2125434870241611526a666d97850dd666741c17ebe191c8496dfc0804faf0
4
- data.tar.gz: f05693aeee46a349b98329592a9f4bc0ae1b35f6922e8fd83d7ef7dd120bbc3d
3
+ metadata.gz: 47a6931f5fd184bfb437e0541849e04f4452764059b23582ca000a977f805bc8
4
+ data.tar.gz: ba1137efa1e302b64bb86635b7c6327cd145d0fa68b787f8540bd5089a9e8bd9
5
5
  SHA512:
6
- metadata.gz: 70967faaf46f6552646994b4cf3d5d080b8059d2909826169ac63021b11699875d4c3d81282eb9f65e074b208711b2260d220656cde4aa422503569070176421
7
- data.tar.gz: 300be7ff2c5c9d04ada4995820318ec3076c6a1ba5954c1ccc88792d35117e1db13d3e89f84d41c8db44f322cc1df19fe7625b3d86772813e96a58f11cb1379a
6
+ metadata.gz: d0a68869c9647f57f3d3ffe1699e7e6fd1a2c0cc4fcbceadb127b1312893cf53eb8d2a89df9c160a058a824846bd128ed9e681eecbe06dd90c61bd91641a5132
7
+ data.tar.gz: e92694271216d763281657edc6b128f05dd8ff104b7228eabeca8570bb86dad6c91a2712410655a744f600db466fea2a25f349182881ab32fecceef3d1763669
data/Gemfile CHANGED
@@ -165,3 +165,5 @@ gem "sprockets-rails"
165
165
  gem "image_processing", "~> 1.12"
166
166
 
167
167
  gem "prefixed_ids"
168
+
169
+ gem "mapkick-rb", "~> 0.1.4"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.29.1.pre.pr1652)
4
+ avo (2.30.0)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
@@ -222,7 +222,7 @@ GEM
222
222
  image_processing (1.12.2)
223
223
  mini_magick (>= 4.9.5, < 5)
224
224
  ruby-vips (>= 2.0.17, < 3)
225
- inline_svg (1.8.0)
225
+ inline_svg (1.9.0)
226
226
  activesupport (>= 3.0)
227
227
  nokogiri (>= 1.6)
228
228
  iso (0.4.0)
@@ -247,6 +247,7 @@ GEM
247
247
  manifester (0.1.8)
248
248
  rails (>= 6.0)
249
249
  zeitwerk
250
+ mapkick-rb (0.1.4)
250
251
  marcel (1.0.2)
251
252
  matrix (0.4.2)
252
253
  meta-tags (2.18.0)
@@ -274,7 +275,7 @@ GEM
274
275
  nokogiri (1.14.2-x86_64-linux)
275
276
  racc (~> 1.4)
276
277
  orm_adapter (0.5.0)
277
- pagy (6.0.2)
278
+ pagy (6.0.3)
278
279
  parallel (1.22.1)
279
280
  parser (3.2.0.0)
280
281
  ast (~> 2.4.1)
@@ -492,6 +493,7 @@ DEPENDENCIES
492
493
  launchy
493
494
  listen (>= 3.5.1)
494
495
  manifester
496
+ mapkick-rb (~> 0.1.4)
495
497
  meta-tags
496
498
  net-smtp
497
499
  pg (>= 0.18, < 2.0)
@@ -16,7 +16,9 @@
16
16
  </div>
17
17
  </div>
18
18
  <% end %>
19
- <span class="text-gray-500 mt-2 text-sm truncate" title="<%= file.filename %>"><%= file.filename %></span>
19
+ <% if field.display_filename %>
20
+ <span class="text-gray-500 mt-2 text-sm truncate" title="<%= file.filename %>"><%= file.filename %></span>
21
+ <% end %>
20
22
  </div>
21
23
  <div class="flex space-x-2">
22
24
  <div class="flex">
@@ -4,6 +4,8 @@ class Avo::Fields::Common::SingleFileViewerComponent < ViewComponent::Base
4
4
  include Avo::ApplicationHelper
5
5
  include Avo::Fields::Concerns::FileAuthorization
6
6
 
7
+ attr_reader :field
8
+
7
9
  def initialize(field:, resource:, file: nil)
8
10
  @file = file
9
11
  @field = field
@@ -15,29 +17,29 @@ class Avo::Fields::Common::SingleFileViewerComponent < ViewComponent::Base
15
17
  end
16
18
 
17
19
  def id
18
- @field.id
20
+ field.id
19
21
  end
20
22
 
21
23
  def file
22
- @file || @field.value.attachment
24
+ @file || field.value.attachment
23
25
  rescue
24
26
  nil
25
27
  end
26
28
 
27
29
  def is_image?
28
- file.image? || @field.is_image
30
+ file.image? || field.is_image
29
31
  rescue
30
32
  false
31
33
  end
32
34
 
33
35
  def is_audio?
34
- file.audio? || @field.is_audio
36
+ file.audio? || field.is_audio
35
37
  rescue
36
38
  false
37
39
  end
38
40
 
39
41
  def is_video?
40
- file.video? || @field.is_video
42
+ file.video? || field.is_video
41
43
  rescue
42
44
  false
43
45
  end
@@ -0,0 +1,22 @@
1
+ <%= field_wrapper **field_wrapper_args do %>
2
+ <% if field.value_as_array? %>
3
+ <div class="flex gap-4">
4
+ <%= @form.text_field @field.as_lat_long_field_id(:lat),
5
+ value: @field.as_lat_long_value(:lat),
6
+ class: classes("w-full"),
7
+ placeholder: @field.as_lat_long_placeholder(:lat)
8
+ %>
9
+ <%= @form.text_field @field.as_lat_long_field_id(:long),
10
+ value: @field.as_lat_long_value(:long),
11
+ class: classes("w-full"),
12
+ placeholder: @field.as_lat_long_placeholder(:long)
13
+ %>
14
+ </div>
15
+ <% else %>
16
+ <%= @form.text_field @field.id,
17
+ value: @field.value,
18
+ class: classes("w-full"),
19
+ placeholder: @field.placeholder
20
+ %>
21
+ <% end %>
22
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::LocationField::EditComponent < Avo::Fields::EditComponent
4
+ end
@@ -0,0 +1,7 @@
1
+ <%= field_wrapper **field_wrapper_args do %>
2
+ <% if field.value_present? %>
3
+ <%= js_map [{latitude: field.value[0], longitude: field.value[1]}] %>
4
+ <% else %>
5
+
6
+ <% end %>
7
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::LocationField::ShowComponent < Avo::Fields::ShowComponent
4
+ end
@@ -85,10 +85,6 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
85
85
  args[:via_relation] = @reflection.name
86
86
  end
87
87
 
88
- if @reflection.parent_reflection.present? && @reflection.parent_reflection.inverse_of.present?
89
- args[:via_relation] = @reflection.parent_reflection.inverse_of.name
90
- end
91
-
92
88
  if @reflection.inverse_of.present?
93
89
  args[:via_relation] = @reflection.inverse_of.name
94
90
  end
@@ -1,3 +1,5 @@
1
+ import 'mapkick/bundle'
2
+
1
3
  import { Alert, Popover } from 'tailwindcss-stimulus-components'
2
4
  import { Application } from '@hotwired/stimulus'
3
5
 
data/db/factories.rb CHANGED
@@ -90,6 +90,7 @@ FactoryBot.define do
90
90
  factory :city do
91
91
  name { Faker::Address.city }
92
92
  population { rand(10000..999000) }
93
+ coordinates { [Faker::Address.latitude, Faker::Address.longitude] }
93
94
  is_capital { [true, false].sample }
94
95
  features { Faker::Address.community }
95
96
  metadata { Faker::Address.community }
@@ -11,7 +11,7 @@ module Avo
11
11
 
12
12
  class_attribute :id
13
13
 
14
- def initialize(dashboard: nil, label: nil, invisible: false, index: nil, visible: nil)
14
+ def initialize(dashboard: nil, label: nil, invisible: false, index: nil, visible: true)
15
15
  @dashboard = dashboard
16
16
  @label = label
17
17
  @invisible = invisible
@@ -7,6 +7,7 @@ module Avo
7
7
  attr_accessor :is_audio
8
8
  attr_accessor :direct_upload
9
9
  attr_accessor :accept
10
+ attr_reader :display_filename
10
11
 
11
12
  def initialize(id, **args, &block)
12
13
  super(id, **args, &block)
@@ -17,6 +18,7 @@ module Avo
17
18
  @is_audio = args[:is_audio].present? ? args[:is_audio] : false
18
19
  @direct_upload = args[:direct_upload].present? ? args[:direct_upload] : false
19
20
  @accept = args[:accept].present? ? args[:accept] : nil
21
+ @display_filename = args[:display_filename].nil? ? true : args[:display_filename]
20
22
  end
21
23
 
22
24
  def path
@@ -5,6 +5,7 @@ module Avo
5
5
  attr_accessor :is_image
6
6
  attr_accessor :direct_upload
7
7
  attr_accessor :accept
8
+ attr_reader :display_filename
8
9
 
9
10
  def initialize(id, **args, &block)
10
11
  super(id, **args, &block)
@@ -13,6 +14,7 @@ module Avo
13
14
  @is_image = args[:is_image].present? ? args[:is_image] : @is_avatar
14
15
  @direct_upload = args[:direct_upload].present? ? args[:direct_upload] : false
15
16
  @accept = args[:accept].present? ? args[:accept] : nil
17
+ @display_filename = args[:display_filename].nil? ? true : args[:display_filename]
16
18
  end
17
19
 
18
20
  def view_component_name
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avo
4
+ module Fields
5
+ class LocationField < BaseField
6
+ attr_reader :stored_as
7
+
8
+ def initialize(id, **args, &block)
9
+ hide_on :index
10
+
11
+ super(id, **args, &block)
12
+
13
+ @stored_as = args[:stored_as].present? ? args[:stored_as] : nil # You can pass it an array of db columns [:latitude, :longitude]
14
+ end
15
+
16
+ def value_as_array?
17
+ stored_as.is_a?(Array) && stored_as.count == 2
18
+ end
19
+
20
+ def as_lat_long_field_id(get)
21
+ if get == :lat
22
+ "#{id}[#{stored_as.first}]"
23
+ elsif get == :long
24
+ "#{id}[#{stored_as.last}]"
25
+ end
26
+ end
27
+
28
+ def as_lat_long_placeholder(get)
29
+ if get == :lat
30
+ "Enter #{stored_as.first}"
31
+ elsif get == :long
32
+ "Enter #{stored_as.last}"
33
+ end
34
+ end
35
+
36
+ def as_lat_long_value(get)
37
+ if get == :lat
38
+ model.send(stored_as.first)
39
+ elsif get == :long
40
+ model.send(stored_as.last)
41
+ end
42
+ end
43
+
44
+ def fill_field(model, key, value, params)
45
+ if value_as_array?
46
+ latitude_field, longitude_field = stored_as
47
+ model.send("#{latitude_field}=", value[latitude_field])
48
+ model.send("#{longitude_field}=", value[longitude_field])
49
+ model
50
+ else
51
+ super(model, key, value.split(","), params)
52
+ end
53
+ end
54
+
55
+ def to_permitted_param
56
+ if value_as_array?
57
+ [:"#{id}", "#{id}": {}]
58
+ else
59
+ super
60
+ end
61
+ end
62
+
63
+ def value_present?
64
+ return value.first.present? && value.second.present? if value.is_a?(Array) && value.count == 2
65
+
66
+ value.present?
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.29.1.pre.pr1652" unless const_defined?(:VERSION)
2
+ VERSION = "2.30.0" unless const_defined?(:VERSION)
3
3
  end
@@ -216,7 +216,7 @@ module Generators
216
216
  fields[enum] = {
217
217
  field: "select",
218
218
  options: {
219
- enum: "::#{model_class.capitalize}.#{enum.pluralize}"
219
+ enum: "::#{model_class.classify}.#{enum.pluralize}"
220
220
  }
221
221
  }
222
222
  end