avo 2.8.0 → 2.9.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.

Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +11 -0
  4. data/app/assets/stylesheets/avo.css +4 -4
  5. data/app/assets/stylesheets/css/{components → fields}/code.css +0 -0
  6. data/app/assets/stylesheets/css/{components → fields}/progress.css +0 -0
  7. data/app/assets/stylesheets/css/{components → fields}/status.css +0 -0
  8. data/app/assets/stylesheets/css/fields/trix.css +17 -0
  9. data/app/components/avo/actions_component.html.erb +5 -13
  10. data/app/components/avo/actions_component.rb +39 -1
  11. data/app/components/avo/common_field_wrapper_component.html.erb +1 -1
  12. data/app/components/avo/fields/belongs_to_field/edit_component.rb +1 -1
  13. data/app/components/avo/fields/trix_field/edit_component.html.erb +1 -0
  14. data/app/components/avo/fields/trix_field/show_component.html.erb +1 -1
  15. data/app/components/avo/sidebar/item_switcher_component.html.erb +2 -2
  16. data/app/components/avo/views/resource_edit_component.html.erb +6 -4
  17. data/app/components/avo/views/resource_edit_component.rb +31 -3
  18. data/app/components/avo/views/resource_index_component.html.erb +1 -1
  19. data/app/components/avo/views/resource_show_component.html.erb +2 -2
  20. data/app/controllers/avo/base_controller.rb +11 -6
  21. data/app/helpers/avo/url_helpers.rb +8 -9
  22. data/app/javascript/js/controllers.js +0 -2
  23. data/app/views/avo/base/edit.html.erb +2 -1
  24. data/app/views/avo/base/new.html.erb +1 -1
  25. data/app/views/avo/partials/_custom_tools_alert.html.erb +21 -7
  26. data/app/views/avo/partials/_table_header.html.erb +9 -1
  27. data/bin/test +1 -0
  28. data/lib/avo/app.rb +18 -1
  29. data/lib/avo/base_action.rb +7 -2
  30. data/lib/avo/base_resource.rb +6 -1
  31. data/lib/avo/concerns/fetches_things.rb +19 -12
  32. data/lib/avo/concerns/has_model.rb +11 -0
  33. data/lib/avo/dynamic_router.rb +1 -1
  34. data/lib/avo/engine.rb +1 -3
  35. data/lib/avo/fields/base_field.rb +1 -0
  36. data/lib/avo/fields/concerns/is_required.rb +17 -0
  37. data/lib/avo/hosts/view_record_host.rb +7 -0
  38. data/lib/avo/menu/base_item.rb +4 -0
  39. data/lib/avo/menu/dashboard.rb +5 -0
  40. data/lib/avo/menu/resource.rb +5 -0
  41. data/lib/avo/version.rb +1 -1
  42. data/lib/avo.rb +1 -0
  43. data/lib/generators/avo/install_generator.rb +1 -4
  44. data/public/avo-assets/avo.css +467 -1069
  45. data/public/avo-assets/avo.js +70 -70
  46. data/public/avo-assets/avo.js.map +3 -3
  47. metadata +9 -8
  48. data/app/components/avo/views/resource_new_component.html.erb +0 -60
  49. data/app/components/avo/views/resource_new_component.rb +0 -39
  50. data/app/javascript/js/controllers/custom/course_resource_controller.js +0 -102
@@ -22,6 +22,13 @@ module Avo
22
22
  end
23
23
  end
24
24
 
25
+ # Filters out the resources that are missing the model_class
26
+ def valid_resources
27
+ resources.select do |resource|
28
+ resource.model_class.present?
29
+ end
30
+ end
31
+
25
32
  # Returns the Avo resource by camelized name
26
33
  #
27
34
  # get_resource_by_name('User') => UserResource
@@ -45,9 +52,10 @@ module Avo
45
52
  # get_resource_by_name('User') => UserResource
46
53
  # get_resource_by_name(User) => UserResource
47
54
  def get_resource_by_model_name(name)
48
- resources.find do |resource|
49
- resource.model_class.model_name.name == name.to_s
50
- end
55
+ valid_resources
56
+ .find do |resource|
57
+ resource.model_class.model_name.name == name.to_s
58
+ end
51
59
  end
52
60
 
53
61
  # Returns the Avo resource by singular snake_cased name
@@ -55,9 +63,10 @@ module Avo
55
63
  # get_resource_by_controller_name('delayed_backend_active_record_jobs') => DelayedJobResource
56
64
  # get_resource_by_controller_name('users') => UserResource
57
65
  def get_resource_by_controller_name(name)
58
- resources.find do |resource|
59
- resource.model_class.to_s.pluralize.underscore.tr("/", "_") == name.to_s
60
- end
66
+ valid_resources
67
+ .find do |resource|
68
+ resource.model_class.to_s.pluralize.underscore.tr("/", "_") == name.to_s
69
+ end
61
70
  end
62
71
 
63
72
  # Returns the Avo resource by some name
@@ -73,9 +82,10 @@ module Avo
73
82
  end
74
83
 
75
84
  def get_available_resources(user = nil)
76
- resources.select do |resource|
77
- Services::AuthorizationService.authorize user, resource.model_class, Avo.configuration.authorization_methods.stringify_keys["index"], raise_exception: false
78
- end
85
+ valid_resources
86
+ .select do |resource|
87
+ Services::AuthorizationService.authorize user, resource.model_class, Avo.configuration.authorization_methods.stringify_keys["index"], raise_exception: false
88
+ end
79
89
  .sort_by { |r| r.name }
80
90
  end
81
91
 
@@ -85,9 +95,6 @@ module Avo
85
95
 
86
96
  def resources_for_navigation(user = nil)
87
97
  get_available_resources(current_user)
88
- .select do |resource|
89
- resource.model_class.present?
90
- end
91
98
  .select do |resource|
92
99
  resource.visible_on_sidebar
93
100
  end
@@ -0,0 +1,11 @@
1
+ module Avo
2
+ module Concerns
3
+ module HasModel
4
+ extend ActiveSupport::Concern
5
+
6
+ def has_model_id?
7
+ model.present? && model.id.present?
8
+ end
9
+ end
10
+ end
11
+ end
@@ -14,7 +14,7 @@ module Avo
14
14
  # resource.model_class.present?
15
15
  # end
16
16
  .map do |resource|
17
- router.resources resource.new.model_key
17
+ router.resources resource.new.route_key
18
18
  end
19
19
  end
20
20
  end
data/lib/avo/engine.rb CHANGED
@@ -17,8 +17,6 @@ module Avo
17
17
  ::Avo::App.boot
18
18
  end
19
19
 
20
- config.i18n.load_path += Dir[Avo::Engine.root.join("lib", "generators", "avo", "templates", "locales", "*.{rb,yml}")]
21
-
22
20
  initializer "avo.autoload" do |app|
23
21
  [
24
22
  ["app", "avo", "fields"],
@@ -73,7 +71,7 @@ module Avo
73
71
  begin
74
72
  Licensing::HQ.new.clear_response
75
73
  rescue => exception
76
- puts "Failed to clear Avo HQ response: #{e.message}"
74
+ puts "Failed to clear Avo HQ response: #{exception.message}"
77
75
  end
78
76
  end
79
77
  end
@@ -9,6 +9,7 @@ module Avo
9
9
 
10
10
  include Avo::Concerns::HandlesFieldArgs
11
11
  include Avo::Concerns::HasHTMLAttributes
12
+ include Avo::Fields::Concerns::IsRequired
12
13
 
13
14
  delegate :view_context, to: ::Avo::App
14
15
  delegate :simple_format, :content_tag, to: :view_context
@@ -0,0 +1,17 @@
1
+ module Avo
2
+ module Fields
3
+ module Concerns
4
+ module IsRequired
5
+ extend ActiveSupport::Concern
6
+
7
+ def is_required?
8
+ if required.respond_to? :call
9
+ Avo::Hosts::ViewRecordHost.new(block: required, record: model, view: view).handle
10
+ else
11
+ required
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Avo
2
+ module Hosts
3
+ class ViewRecordHost < RecordHost
4
+ option :view
5
+ end
6
+ end
7
+ end
@@ -17,4 +17,8 @@ class Avo::Menu::BaseItem
17
17
  Avo::Hosts::BaseHost.new(block: visible).handle
18
18
  end
19
19
  end
20
+
21
+ def navigation_label
22
+ label || entity_label
23
+ end
20
24
  end
@@ -2,6 +2,7 @@ class Avo::Menu::Dashboard < Avo::Menu::BaseItem
2
2
  extend Dry::Initializer
3
3
 
4
4
  option :dashboard
5
+ option :label, optional: true
5
6
 
6
7
  def parsed_dashboard
7
8
  dashboard_by_id || dashboard_by_name
@@ -14,4 +15,8 @@ class Avo::Menu::Dashboard < Avo::Menu::BaseItem
14
15
  def dashboard_by_id
15
16
  Avo::App.get_dashboard_by_id dashboard.to_s
16
17
  end
18
+
19
+ def entity_label
20
+ parsed_dashboard.navigation_label
21
+ end
17
22
  end
@@ -2,8 +2,13 @@ class Avo::Menu::Resource < Avo::Menu::BaseItem
2
2
  extend Dry::Initializer
3
3
 
4
4
  option :resource
5
+ option :label, optional: true
5
6
 
6
7
  def parsed_resource
7
8
  Avo::App.guess_resource resource.to_s
8
9
  end
10
+
11
+ def entity_label
12
+ parsed_resource.navigation_label
13
+ end
9
14
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.8.0" unless const_defined?(:VERSION)
2
+ VERSION = "2.9.0" unless const_defined?(:VERSION)
3
3
  end
data/lib/avo.rb CHANGED
@@ -7,6 +7,7 @@ loader.inflector.inflect(
7
7
  "html" => "HTML",
8
8
  "has_html_attributes" => "HasHTMLAttributes"
9
9
  )
10
+ loader.ignore("#{__dir__}/generators")
10
11
  loader.setup
11
12
 
12
13
  # .//*,,.....,,*/(*
@@ -13,10 +13,7 @@ module Generators
13
13
  route "mount Avo::Engine, at: Avo.configuration.root_path"
14
14
 
15
15
  template "initializer/avo.tt", "config/initializers/avo.rb"
16
- template "locales/avo.en.yml", "config/locales/avo.en.yml"
17
- template "locales/avo.nb-NO.yml", "config/locales/avo.nb-NO.yml"
18
- template "locales/avo.pt-BR.yml", "config/locales/avo.pt-BR.yml"
19
- template "locales/avo.ro.yml", "config/locales/avo.ro.yml"
16
+ directory File.join(__dir__, "templates", "locales"), "config/locales"
20
17
  end
21
18
  end
22
19
  end