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
@@ -11,6 +11,15 @@
11
11
  new_icon: 'grid-view-type',
12
12
  translation_key: 'avo.grid_view',
13
13
  },
14
+ list: {
15
+ new_view_type: 'list',
16
+ new_icon: 'queue-list',
17
+ },
18
+ map: {
19
+ new_view_type: 'map',
20
+ new_icon: 'map-view-type',
21
+ translation_key: 'avo.map_view',
22
+ },
14
23
  }
15
24
  %>
16
25
  <div class="flex">
data/db/factories.rb CHANGED
@@ -48,6 +48,20 @@ FactoryBot.define do
48
48
  progress { Faker::Number.between(from: 0, to: 100) }
49
49
  end
50
50
 
51
+ trait :with_files do
52
+ after(:create) do |project|
53
+ ["watch.jpg", "dummy-video.mp4"].each do |filename|
54
+ file = Rails.root.join("db", "seed_files", filename)
55
+ project.files.attach(io: file.open, filename: filename)
56
+ end
57
+
58
+ ["dummy-file.txt", "dummy-audio.mp3"].each do |filename|
59
+ file = Avo::Engine.root.join("spec", "dummy", filename)
60
+ project.files.attach(io: file.open, filename: filename)
61
+ end
62
+ end
63
+ end
64
+
51
65
  factory :comment do
52
66
  body { Faker::Lorem.paragraphs(number: rand(4...10)).join(" ") }
53
67
  posted_at { Time.now - rand(10...365).days }
@@ -104,6 +118,7 @@ FactoryBot.define do
104
118
  description { Faker::Address.community }
105
119
  status { ["open", "closed"].sample }
106
120
  tiny_description { Faker::Address.community }
121
+ city_center_area { [[[10.0, 11.2], [10.5, 11.9], [10.8, 12.0], [10.0, 11.2]]].to_json }
107
122
  end
108
123
 
109
124
  factory :product do
data/lib/avo/app.rb CHANGED
@@ -28,15 +28,21 @@ module Avo
28
28
  def boot
29
29
  init_logger
30
30
  init_fields
31
- init_cache_store
31
+ self.cache_store = get_cache_store
32
32
  end
33
33
 
34
- def init_cache_store
35
- # The cache store should be set when the app boots up.
36
- if Rails.cache.instance_of?(ActiveSupport::Cache::NullStore)
37
- self.cache_store ||= ActiveSupport::Cache::MemoryStore.new
34
+ def get_cache_store
35
+ if Rails.env.production?
36
+ case Rails.cache.class.to_s
37
+ when "ActiveSupport::Cache::MemCacheStore", "ActiveSupport::Cache::RedisCacheStore"
38
+ Rails.cache
39
+ else
40
+ ActiveSupport::Cache.lookup_store(:file_store, "/tmp/cache")
41
+ end
42
+ elsif Rails.env.test?
43
+ Rails.cache
38
44
  else
39
- self.cache_store = Rails.cache
45
+ ActiveSupport::Cache.lookup_store(:memory_store)
40
46
  end
41
47
  end
42
48
 
@@ -59,10 +59,10 @@ module Avo
59
59
  end
60
60
 
61
61
  def initialize(record: nil, resource: nil, user: nil, view: nil, arguments: {})
62
- self.class.record = record if record.present?
63
- self.class.resource = resource if resource.present?
64
- self.class.user = user if user.present?
65
- self.class.view = view if view.present?
62
+ self.class.record = record
63
+ self.class.resource = resource
64
+ self.class.user = user
65
+ self.class.view = view
66
66
  @arguments = arguments
67
67
 
68
68
  self.class.message ||= I18n.t("avo.are_you_sure_you_want_to_run_this_option")
@@ -64,6 +64,7 @@ module Avo
64
64
  class_attribute :keep_filters_panel_open, default: false
65
65
  class_attribute :extra_params
66
66
  class_attribute :link_to_child_resource, default: false
67
+ class_attribute :map_view
67
68
 
68
69
  # EXTRACT:
69
70
  class_attribute :ordering
@@ -335,6 +336,7 @@ module Avo
335
336
  view_types = [:table]
336
337
 
337
338
  view_types << :grid if get_grid_fields.present?
339
+ view_types << :map if map_view.present?
338
340
 
339
341
  view_types
340
342
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avo
4
+ module Fields
5
+ class AreaField < BaseField
6
+ attr_reader :mapkick_options
7
+ attr_reader :datapoint_options
8
+
9
+ def initialize(id, **args, &block)
10
+ hide_on :index
11
+
12
+ super(id, **args, &block)
13
+
14
+ @geometry = args[:geometry].presence || :polygon # Accepts: `:polygon` or `:multi_polygon`
15
+ @mapkick_options = args[:mapkick_options].presence || {}
16
+ @datapoint_options = args[:datapoint_options].presence || {}
17
+ end
18
+
19
+ def map_data
20
+ data_source = {
21
+ geometry: {
22
+ type: @geometry.to_s.classify,
23
+ coordinates: value
24
+ }
25
+ }
26
+
27
+ [data_source.merge(datapoint_options)]
28
+ end
29
+
30
+ def coordinates
31
+ value.present? ? JSON.parse(value) : []
32
+ end
33
+
34
+ def geometry
35
+ @geometry.to_s.classify
36
+ end
37
+ end
38
+ end
39
+ end
@@ -33,6 +33,7 @@ module Avo
33
33
  attr_reader :nullable
34
34
  attr_reader :null_values
35
35
  attr_reader :format_using
36
+ attr_reader :autocomplete
36
37
  attr_reader :help
37
38
  attr_reader :default
38
39
  attr_reader :as_label
@@ -42,7 +43,6 @@ module Avo
42
43
  attr_reader :for_presentation_only
43
44
 
44
45
  # Private options
45
- attr_reader :updatable
46
46
  attr_reader :computable # if allowed to be computable
47
47
  attr_reader :computed # if block is present
48
48
  attr_reader :computed_value # the value after computation
@@ -68,6 +68,7 @@ module Avo
68
68
  @null_values = args[:null_values] || [nil, ""]
69
69
  @format_using = args[:format_using] || nil
70
70
  @placeholder = args[:placeholder]
71
+ @autocomplete = args[:autocomplete] || nil
71
72
  @help = args[:help] || nil
72
73
  @default = args[:default] || nil
73
74
  @visible = args[:visible]
@@ -83,7 +84,6 @@ module Avo
83
84
 
84
85
  @args = args
85
86
 
86
- @updatable = !disabled
87
87
  @computable = true
88
88
  @computed = block.present?
89
89
  @computed_value = nil
@@ -264,6 +264,10 @@ module Avo
264
264
  options
265
265
  end
266
266
 
267
+ def updatable
268
+ !is_disabled? && visible?
269
+ end
270
+
267
271
  private
268
272
 
269
273
  def model_or_class(model)
@@ -6,6 +6,8 @@ module Avo
6
6
  attr_accessor :direct_upload
7
7
  attr_accessor :accept
8
8
  attr_reader :display_filename
9
+ attr_reader :view_type
10
+ attr_reader :hide_view_type_switcher
9
11
 
10
12
  def initialize(id, **args, &block)
11
13
  super(id, **args, &block)
@@ -15,6 +17,8 @@ module Avo
15
17
  @direct_upload = args[:direct_upload].present? ? args[:direct_upload] : false
16
18
  @accept = args[:accept].present? ? args[:accept] : nil
17
19
  @display_filename = args[:display_filename].nil? ? true : args[:display_filename]
20
+ @view_type = args[:view_type] || :grid
21
+ @hide_view_type_switcher = args[:hide_view_type_switcher]
18
22
  end
19
23
 
20
24
  def view_component_name
@@ -7,7 +7,6 @@ module Avo
7
7
 
8
8
  def initialize(id, **args, &block)
9
9
  hide_on :index
10
-
11
10
  super(id, **args, &block)
12
11
 
13
12
  @stored_as = args[:stored_as].present? ? args[:stored_as] : nil # You can pass it an array of db columns [:latitude, :longitude]
@@ -90,16 +90,12 @@ module Avo
90
90
 
91
91
  # Filters out the resources that are missing the model_class
92
92
  def valid_resources
93
- resources
94
- .select do |resource|
95
- resource.model_class.present?
96
- end
97
- .sort_by(&:to_s)
93
+ resources.select { |resource| resource.model_class.present? }.sort_by(&:name)
98
94
  end
99
95
 
100
96
  # Returns the Avo resource by camelized name
101
97
  #
102
- # get_resource_by_name('User') => Avo::Resources::User
98
+ # get_resource_by_name('User') => instance of Avo::Resources::User
103
99
  def get_resource(resource)
104
100
  resource = "Avo::Resources::#{resource}" unless resource.to_s.starts_with?("Avo::Resources::")
105
101
 
@@ -110,7 +106,7 @@ module Avo
110
106
 
111
107
  # Returns the Avo resource by singular snake_cased name
112
108
  #
113
- # get_resource_by_name('user') => Avo::Resources::User
109
+ # get_resource_by_name('user') => instance of Avo::Resources::User
114
110
  def get_resource_by_name(name)
115
111
  get_resource name.singularize.camelize
116
112
  end
@@ -118,8 +114,8 @@ module Avo
118
114
  # Returns the Avo resource by singular snake_cased name
119
115
  # From all the resources that use the same model_class, it will fetch the first one in alphabetical order
120
116
  #
121
- # get_resource_by_name('User') => Avo::Resources::User
122
- # get_resource_by_name(User) => Avo::Resources::User
117
+ # get_resource_by_name('User') => instance of Avo::Resources::User
118
+ # get_resource_by_name(User) => instance of Avo::Resources::User
123
119
 
124
120
  def get_resource_by_model_class(klass)
125
121
  # Fetch the mappings imposed by the user.
@@ -135,8 +131,8 @@ module Avo
135
131
 
136
132
  # Returns the Avo resource by singular snake_cased name
137
133
  #
138
- # get_resource_by_controller_name('delayed_backend_active_record_jobs') => DelayedJobResource
139
- # get_resource_by_controller_name('users') => Avo::Resources::User
134
+ # get_resource_by_controller_name('delayed_backend_active_record_jobs') => instance of Avo::Resources::DelayedJob
135
+ # get_resource_by_controller_name('users') => instance of Avo::Resources::User
140
136
  def get_resource_by_controller_name(name)
141
137
  valid_resources
142
138
  .find do |resource|
@@ -59,6 +59,7 @@ class Avo::Services::DebugService
59
59
  **other_metadata(:filters),
60
60
  main_menu_present: Avo.configuration.main_menu.present?,
61
61
  profile_menu_present: Avo.configuration.profile_menu.present?,
62
+ cache_store: Avo::App.cache_store&.class&.to_s,
62
63
  **config_metadata
63
64
  }
64
65
  # rescue => error
@@ -51,6 +51,7 @@ class Avo::Services::TelemetryService
51
51
  **other_metadata(:filters),
52
52
  main_menu_present: Avo.configuration.main_menu.present?,
53
53
  profile_menu_present: Avo.configuration.profile_menu.present?,
54
+ cache_store: Avo::App.cache_store&.class&.to_s,
54
55
  **config_metadata
55
56
  }
56
57
  # rescue => error
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.0.0.pre8" unless const_defined?(:VERSION)
2
+ VERSION = "3.0.0.pre9" unless const_defined?(:VERSION)
3
3
  end
@@ -21,7 +21,7 @@ module Generators
21
21
  end
22
22
 
23
23
  if Rails.root.join("Procfile.dev").exist?
24
- append_to_file "Procfile.dev", "avo_css: bin/rails avo:tailwindcss:watch\n"
24
+ append_to_file "Procfile.dev", "avo_css: yarn avo:tailwindcss --watch\n"
25
25
  else
26
26
  say "Add default Procfile.dev"
27
27
  copy_file template_path("Procfile.dev"), "Procfile.dev"
@@ -38,6 +38,9 @@ module Generators
38
38
 
39
39
  say "Adding the CSS asset to the partial"
40
40
  prepend_to_file Rails.root.join("app", "views", "avo", "partials", "_pre_head.html.erb"), "<%= stylesheet_link_tag \"avo.tailwind.css\", media: \"all\" %>"
41
+
42
+ say "Ensure you have the following script in your package.json file.", :yellow
43
+ say %("scripts": { "avo:tailwindcss": "tailwindcss -i ./app/assets/stylesheets/avo.tailwind.css -o ./app/assets/builds/avo.tailwind.css --minify" }), :green
41
44
  end
42
45
 
43
46
  no_tasks do
@@ -1,2 +1,2 @@
1
1
  web: bin/rails server -p 3000
2
- avo_css: bin/rails avo:tailwindcss:watch
2
+ avo_css: yarn avo:tailwindcss --watch