avo 2.4.1 → 2.5.2.pre.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/app/assets/builds/avo.css +8851 -0
- data/app/assets/builds/avo.js +423 -0
- data/app/assets/builds/avo.js.map +7 -0
- data/app/components/avo/card_component.rb +12 -0
- data/app/components/avo/edit/field_wrapper_component.html.erb +2 -2
- data/app/components/avo/edit/field_wrapper_component.rb +6 -1
- data/app/components/avo/fields/belongs_to_field/autocomplete_component.html.erb +3 -0
- data/app/components/avo/fields/belongs_to_field/autocomplete_component.rb +4 -0
- data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +26 -27
- data/app/components/avo/filters_component.html.erb +3 -3
- data/app/components/avo/filters_component.rb +2 -1
- data/app/components/avo/paginator_component.html.erb +3 -3
- data/app/components/avo/paginator_component.rb +3 -3
- data/app/components/avo/views/resource_index_component.html.erb +3 -3
- data/app/components/avo/views/resource_index_component.rb +10 -3
- data/app/controllers/avo/associations_controller.rb +6 -1
- data/app/controllers/avo/base_controller.rb +24 -1
- data/app/controllers/avo/search_controller.rb +22 -1
- data/app/helpers/avo/url_helpers.rb +3 -3
- data/app/javascript/js/controllers/filter_controller.js +9 -0
- data/app/javascript/js/controllers/search_controller.js +9 -2
- data/app/views/avo/base/_boolean_filter.html.erb +23 -15
- data/app/views/avo/base/_multiple_select_filter.html.erb +5 -1
- data/app/views/avo/base/_select_filter.html.erb +5 -1
- data/app/views/avo/base/_text_filter.html.erb +5 -1
- data/app/views/avo/base/index.html.erb +1 -0
- data/app/views/avo/dashboards/_chartkick_card.html.erb +1 -1
- data/app/views/avo/dashboards/_metric_card.html.erb +1 -1
- data/app/views/avo/partials/_sidebar_extra.html.erb +2 -0
- data/db/factories.rb +5 -3
- data/lib/avo/base_resource.rb +1 -0
- data/lib/avo/engine.rb +1 -1
- data/lib/avo/fields/belongs_to_field.rb +11 -1
- data/lib/avo/fields/has_base_field.rb +2 -0
- data/lib/avo/filters/base_filter.rb +22 -0
- data/lib/avo/hosts/association_scope_host.rb +8 -0
- data/lib/avo/services/authorization_service.rb +8 -10
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/eject_generator.rb +2 -3
- data/lib/generators/avo/templates/cards/chartkick_card.tt +1 -1
- data/lib/generators/avo/templates/cards/chartkick_card_sample.tt +1 -1
- data/lib/generators/avo/templates/cards/metric_card.tt +1 -1
- data/lib/generators/avo/templates/cards/metric_card_sample.tt +1 -1
- data/lib/generators/avo/templates/locales/avo.en.yml +2 -1
- data/lib/generators/avo/templates/locales/avo.nb-NO.yml +2 -1
- data/lib/generators/avo/templates/locales/avo.pt-BR.yml +2 -1
- data/lib/generators/avo/templates/locales/avo.ro.yml +2 -1
- data/public/avo-assets/avo.js +22 -22
- data/public/avo-assets/avo.js.map +2 -2
- metadata +8 -4
@@ -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
|
-
|
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
|
@@ -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
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
@@ -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
|
@@ -9,7 +9,7 @@ class <%= class_name.camelize %> < Avo::Dashboards::ChartkickCard
|
|
9
9
|
# self.chart_options = { library: { plugins: { legend: { display: true } } } }
|
10
10
|
# self.flush = true
|
11
11
|
|
12
|
-
query
|
12
|
+
def query
|
13
13
|
points = 16
|
14
14
|
i = Time.new.year.to_i - points
|
15
15
|
base_data = Array.new(points).map do
|
@@ -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:
|
84
|
+
no_cards_present: Niciun card disponibil
|
85
|
+
no_options_available: Nicio optiune disponibila
|