avo 2.17.1.pre.1.zeitwerk.eager.load.dir → 2.17.1.pre.3

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -2
  3. data/Gemfile.lock +5 -11
  4. data/app/components/avo/button_component.rb +2 -2
  5. data/app/components/avo/fields/common/single_file_viewer_component.html.erb +3 -3
  6. data/app/components/avo/fields/date_field/edit_component.html.erb +2 -0
  7. data/app/components/avo/fields/date_field/index_component.html.erb +1 -0
  8. data/app/components/avo/fields/date_field/show_component.html.erb +1 -0
  9. data/app/components/avo/fields/date_time_field/edit_component.html.erb +2 -0
  10. data/app/components/avo/fields/date_time_field/index_component.html.erb +1 -0
  11. data/app/components/avo/fields/date_time_field/show_component.html.erb +1 -0
  12. data/app/components/avo/fields/time_field/edit_component.html.erb +40 -0
  13. data/app/components/avo/fields/time_field/edit_component.rb +4 -0
  14. data/app/components/avo/fields/time_field/index_component.html.erb +15 -0
  15. data/app/components/avo/fields/time_field/index_component.rb +4 -0
  16. data/app/components/avo/fields/time_field/show_component.html.erb +15 -0
  17. data/app/components/avo/fields/time_field/show_component.rb +4 -0
  18. data/app/components/avo/index/resource_controls_component.html.erb +2 -2
  19. data/app/components/avo/sidebar_profile_component.html.erb +4 -1
  20. data/app/components/avo/views/resource_edit_component.html.erb +10 -12
  21. data/app/components/avo/views/resource_show_component.html.erb +21 -25
  22. data/app/controllers/avo/associations_controller.rb +1 -4
  23. data/app/javascript/js/controllers/fields/date_field_controller.js +61 -21
  24. data/app/javascript/js/controllers/search_controller.js +3 -0
  25. data/avo.gemspec +1 -1
  26. data/config/routes.rb +1 -1
  27. data/db/factories.rb +1 -0
  28. data/lib/avo/app.rb +0 -6
  29. data/lib/avo/concerns/handles_field_args.rb +4 -0
  30. data/lib/avo/dynamic_router.rb +15 -19
  31. data/lib/avo/engine.rb +0 -9
  32. data/lib/avo/fields/base_field.rb +5 -1
  33. data/lib/avo/fields/date_field.rb +2 -0
  34. data/lib/avo/fields/time_field.rb +55 -0
  35. data/lib/avo/version.rb +1 -1
  36. data/public/avo-assets/avo.base.js +64 -64
  37. data/public/avo-assets/avo.base.js.map +2 -2
  38. metadata +23 -2
@@ -1,25 +1,21 @@
1
1
  module Avo
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
2
+ module DynamicRouter
3
+ def self.routes(router)
4
+ Rails.application.eager_load! unless Rails.env.production?
7
5
 
8
- BaseResource.descendants
9
- .select do |resource|
10
- resource != :BaseResource
11
- end
12
- .select do |resource|
13
- resource.is_a? Class
14
- end
15
- # .select do |resource|
16
- # resource.model_class.present?
17
- # end
18
- .map do |resource|
19
- resources resource.new.route_key
20
- end
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
21
18
  end
22
- end
23
19
  end
24
20
  end
25
21
  end
data/lib/avo/engine.rb CHANGED
@@ -17,15 +17,6 @@ module Avo
17
17
  ::Avo::App.boot
18
18
  end
19
19
 
20
- # initializer "eager load resources" do |app|
21
- # # puts ["app.root->", app.root.join('app', 'avo', 'resources')].inspect
22
- # app.config.to_prepare do
23
- # puts ["app.config.to_prepare->", app.root.join('app', 'avo', 'resources')].inspect
24
- # Rails.autoloaders.main.eager_load_dir(app.root.join('app', 'avo', 'resources'))
25
- # puts [".to_prepare BaseResource.descendants->", BaseResource.descendants].inspect
26
- # end
27
- # end
28
-
29
20
  initializer "avo.autoload" do |app|
30
21
  [
31
22
  ["app", "avo", "fields"],
@@ -162,7 +162,7 @@ module Avo
162
162
  property ||= id
163
163
 
164
164
  # Get model value
165
- final_value = @model.send(property) if (model_or_class(@model) == "model") && @model.respond_to?(property)
165
+ final_value = @model.send(property) if is_model?(@model) && @model.respond_to?(property)
166
166
 
167
167
  # On new views and actions modals we need to prefill the fields
168
168
  if @view.in?([:new, :create]) || @action.present?
@@ -263,6 +263,10 @@ module Avo
263
263
  "model"
264
264
  end
265
265
  end
266
+
267
+ def is_model?(model)
268
+ model_or_class(model) == "model"
269
+ end
266
270
  end
267
271
  end
268
272
  end
@@ -5,6 +5,7 @@ module Avo
5
5
  attr_reader :picker_format
6
6
  attr_reader :disable_mobile
7
7
  attr_reader :format
8
+ attr_reader :picker_options
8
9
 
9
10
  def initialize(id, **args, &block)
10
11
  super(id, **args, &block)
@@ -13,6 +14,7 @@ module Avo
13
14
  add_string_prop args, :picker_format, "Y-m-d"
14
15
  add_string_prop args, :format, "yyyy-LL-dd"
15
16
  add_boolean_prop args, :disable_mobile
17
+ add_object_prop args, :picker_options
16
18
  end
17
19
 
18
20
  def formatted_value
@@ -0,0 +1,55 @@
1
+ module Avo
2
+ module Fields
3
+ class TimeField < DateField
4
+ attr_reader :format
5
+ attr_reader :picker_format
6
+ attr_reader :time_24hr
7
+ attr_reader :timezone
8
+ attr_reader :relative
9
+
10
+ def initialize(id, **args, &block)
11
+ super(id, **args, &block)
12
+
13
+ add_boolean_prop args, :time_24hr
14
+ add_string_prop args, :picker_format, "H:i:S"
15
+ add_string_prop args, :format, "TT"
16
+ add_string_prop args, :timezone
17
+ add_boolean_prop args, :relative, true
18
+ end
19
+
20
+ def formatted_value
21
+ return nil if value.nil?
22
+
23
+ value.utc.to_time.iso8601
24
+ end
25
+
26
+ def edit_formatted_value
27
+ return nil if value.nil?
28
+
29
+ value.utc.iso8601
30
+ end
31
+
32
+ def fill_field(model, key, value, params)
33
+ if value.in?(["", nil])
34
+ model[id] = value
35
+
36
+ return model
37
+ end
38
+
39
+ return model if value.blank?
40
+
41
+ model[id] = utc_time(value)
42
+
43
+ model
44
+ end
45
+
46
+ def utc_time(value)
47
+ if timezone.present?
48
+ ActiveSupport::TimeZone.new(timezone).local_to_utc(Time.parse(value))
49
+ else
50
+ value
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.17.1.pre.1.zeitwerk.eager.load.dir" unless const_defined?(:VERSION)
2
+ VERSION = "2.17.1.pre.3" unless const_defined?(:VERSION)
3
3
  end