avo 2.4.0 → 2.5.1

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/components/avo/edit/field_wrapper_component.html.erb +2 -2
  4. data/app/components/avo/edit/field_wrapper_component.rb +6 -1
  5. data/app/components/avo/fields/belongs_to_field/autocomplete_component.html.erb +3 -0
  6. data/app/components/avo/fields/belongs_to_field/autocomplete_component.rb +4 -0
  7. data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +26 -27
  8. data/app/components/avo/filters_component.html.erb +3 -3
  9. data/app/components/avo/filters_component.rb +2 -1
  10. data/app/components/avo/paginator_component.html.erb +3 -3
  11. data/app/components/avo/paginator_component.rb +3 -3
  12. data/app/components/avo/sidebar_profile_component.html.erb +0 -3
  13. data/app/components/avo/views/resource_index_component.html.erb +3 -3
  14. data/app/components/avo/views/resource_index_component.rb +10 -3
  15. data/app/controllers/avo/associations_controller.rb +6 -1
  16. data/app/controllers/avo/base_controller.rb +24 -1
  17. data/app/controllers/avo/search_controller.rb +22 -1
  18. data/app/helpers/avo/url_helpers.rb +3 -3
  19. data/app/javascript/js/controllers/filter_controller.js +9 -0
  20. data/app/javascript/js/controllers/search_controller.js +9 -2
  21. data/app/views/avo/base/_boolean_filter.html.erb +23 -15
  22. data/app/views/avo/base/_multiple_select_filter.html.erb +5 -1
  23. data/app/views/avo/base/_select_filter.html.erb +5 -1
  24. data/app/views/avo/base/_text_filter.html.erb +5 -1
  25. data/app/views/avo/base/index.html.erb +1 -0
  26. data/app/views/avo/partials/_sidebar_extra.html.erb +2 -0
  27. data/db/factories.rb +5 -3
  28. data/lib/avo/base_resource.rb +1 -0
  29. data/lib/avo/engine.rb +1 -1
  30. data/lib/avo/fields/belongs_to_field.rb +11 -1
  31. data/lib/avo/fields/has_base_field.rb +2 -0
  32. data/lib/avo/filters/base_filter.rb +22 -0
  33. data/lib/avo/hosts/association_scope_host.rb +8 -0
  34. data/lib/avo/services/authorization_service.rb +8 -10
  35. data/lib/avo/version.rb +1 -1
  36. data/lib/generators/avo/eject_generator.rb +2 -3
  37. data/lib/generators/avo/templates/locales/avo.en.yml +2 -1
  38. data/lib/generators/avo/templates/locales/avo.nb-NO.yml +2 -1
  39. data/lib/generators/avo/templates/locales/avo.pt-BR.yml +2 -1
  40. data/lib/generators/avo/templates/locales/avo.ro.yml +2 -1
  41. data/public/avo-assets/avo.js +22 -22
  42. data/public/avo-assets/avo.js.map +2 -2
  43. metadata +3 -2
@@ -62,6 +62,8 @@ module Avo
62
62
  attr_reader :relation_method
63
63
  attr_reader :types # for Polymorphic associations
64
64
  attr_reader :allow_via_detaching
65
+ attr_reader :scope
66
+ attr_reader :polymorphic_help
65
67
 
66
68
  def initialize(id, **args, &block)
67
69
  args[:placeholder] ||= I18n.t("avo.choose_an_option")
@@ -73,6 +75,8 @@ module Avo
73
75
  @types = args[:types]
74
76
  @relation_method = id.to_s.parameterize.underscore
75
77
  @allow_via_detaching = args[:allow_via_detaching] == true
78
+ @scope = args[:scope]
79
+ @polymorphic_help = args[:polymorphic_help]
76
80
  end
77
81
 
78
82
  def searchable
@@ -111,7 +115,13 @@ module Avo
111
115
  resource = target_resource
112
116
  resource = App.get_resource_by_model_name model if model.present?
113
117
 
114
- ::Avo::Services::AuthorizationService.apply_policy(user, resource.class.query_scope).all.map do |model|
118
+ query = Avo::Services::AuthorizationService.apply_policy(user, resource.class.query_scope)
119
+
120
+ if scope.present?
121
+ query = Avo::Hosts::AssociationScopeHost.new(block: scope, query: query, parent: get_model).handle
122
+ end
123
+
124
+ query.all.map do |model|
115
125
  [model.send(resource.class.title), model.id]
116
126
  end
117
127
  end
@@ -3,6 +3,7 @@ module Avo
3
3
  class HasBaseField < BaseField
4
4
  attr_accessor :display
5
5
  attr_accessor :scope
6
+ attr_accessor :description
6
7
 
7
8
  def initialize(id, **args, &block)
8
9
  super(id, **args, &block)
@@ -10,6 +11,7 @@ module Avo
10
11
  @scope = args[:scope].present? ? args[:scope] : nil
11
12
  @display = args[:display].present? ? args[:display] : :show
12
13
  @searchable = args[:searchable] == true
14
+ @description = args[:description]
13
15
  end
14
16
 
15
17
  def searchable
@@ -1,10 +1,27 @@
1
1
  module Avo
2
2
  module Filters
3
3
  class BaseFilter
4
+ PARAM_KEY = :filters unless const_defined?(:PARAM_KEY)
5
+
4
6
  class_attribute :name, default: "Filter"
5
7
  class_attribute :component, default: "boolean-filter"
6
8
  class_attribute :default, default: nil
7
9
  class_attribute :template, default: "avo/base/select_filter"
10
+ class_attribute :empty_message
11
+
12
+ delegate :params, to: Avo::App
13
+
14
+ class << self
15
+ def decode_filters(filter_params)
16
+ JSON.parse(Base64.decode64(filter_params))
17
+ rescue
18
+ {}
19
+ end
20
+
21
+ def get_empty_message
22
+ empty_message || I18n.t("avo.no_options_available")
23
+ end
24
+ end
8
25
 
9
26
  def apply_query(request, query, value)
10
27
  value.stringify_keys! if value.is_a? Hash
@@ -30,6 +47,11 @@ module Avo
30
47
  rescue
31
48
  default
32
49
  end
50
+
51
+ # Fetch the applied filters from the params
52
+ def applied_filters
53
+ self.class.decode_filters params[PARAM_KEY]
54
+ end
33
55
  end
34
56
  end
35
57
  end
@@ -0,0 +1,8 @@
1
+ module Avo
2
+ module Hosts
3
+ class AssociationScopeHost < BaseHost
4
+ option :parent
5
+ option :query
6
+ end
7
+ end
8
+ end
@@ -71,13 +71,13 @@ module Avo
71
71
  # If no action passed we should raise error if the user wants that.
72
72
  # If not, just allow it.
73
73
  if action.nil?
74
- raise Pundit::NotDefinedError.new 'Policy method is missing' if Avo.configuration.raise_error_on_missing_policy
74
+ raise Pundit::NotDefinedError.new "Policy method is missing" if Avo.configuration.raise_error_on_missing_policy
75
75
 
76
76
  return true
77
77
  end
78
78
 
79
79
  # Add the question mark if it's missing
80
- action = "#{action}?" unless action.end_with? '?'
80
+ action = "#{action}?" unless action.end_with? "?"
81
81
 
82
82
  authorize user, record, action, **args
83
83
  end
@@ -110,14 +110,12 @@ module Avo
110
110
  end
111
111
 
112
112
  def defined_methods(user, record, **args)
113
- begin
114
- Pundit.policy!(user, record).methods
115
- rescue => error
116
- if args[:raise_exception] == false
117
- []
118
- else
119
- raise error
120
- end
113
+ Pundit.policy!(user, record).methods
114
+ rescue => error
115
+ if args[:raise_exception] == false
116
+ []
117
+ else
118
+ raise error
121
119
  end
122
120
  end
123
121
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.4.0" unless const_defined?(:VERSION)
2
+ VERSION = "2.5.1" unless const_defined?(:VERSION)
3
3
  end
@@ -11,13 +11,12 @@ module Generators
11
11
  namespace "avo:eject"
12
12
 
13
13
  TEMPLATES = {
14
- sidebar: "app/views/avo/sidebar/_sidebar.html.erb",
15
14
  logo: "app/views/avo/partials/_logo.html.erb",
16
15
  head: "app/views/avo/partials/_head.html.erb",
17
16
  header: "app/views/avo/partials/_header.html.erb",
18
- profile_dropdown: "app/views/avo/partials/_profile_dropdown.html.erb",
19
17
  footer: "app/views/avo/partials/_footer.html.erb",
20
- scripts: "app/views/avo/partials/_scripts.html.erb"
18
+ scripts: "app/views/avo/partials/_scripts.html.erb",
19
+ sidebar_extra: "app/views/avo/partials/_sidebar_extra.html.erb",
21
20
  }
22
21
 
23
22
  def handle
@@ -107,4 +107,5 @@ en:
107
107
  to_top: Move record to top
108
108
  to_bottom: Move record to bottom
109
109
  empty_dashboard_message: Add cards to this dashboard
110
- no_cards_present: 'No cards present'
110
+ no_cards_present: No cards present
111
+ no_options_available: No options available
@@ -83,5 +83,6 @@ nb-NO:
83
83
  sign_out: 'Logg ut'
84
84
  tools: Redskapene
85
85
  empty_dashboard_message: Legg til kort i dette dashbordet
86
- no_cards_present: 'Ingen kort til stede'
86
+ no_cards_present: Ingen kort til stede
87
+ no_options_available: Ingen tilgjengelige alternativer
87
88
 
@@ -85,4 +85,5 @@ pt-BR:
85
85
  sign_out: 'sair'
86
86
  tools: Ferramentas
87
87
  empty_dashboard_message: Adicionar cartões a este painel
88
- no_cards_present: 'Nenhum cartão presente'
88
+ no_cards_present: Nenhum cartão presente
89
+ no_options_available: Nenhuma opção disponível
@@ -81,4 +81,5 @@ ro:
81
81
  was_successfully_updated: 'a fost actualizat'
82
82
  tools: Instrumente
83
83
  empty_dashboard_message: Adauga carduri in acest dashboard
84
- no_cards_present: 'Niciun card disponibil'
84
+ no_cards_present: Niciun card disponibil
85
+ no_options_available: Nicio optiune disponibila