avo 3.0.0.pre13 → 3.0.0.pre14
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 +1 -1
- data/Gemfile.lock +2 -1
- data/app/components/avo/alert_component.html.erb +1 -1
- data/app/components/avo/base_component.rb +7 -7
- data/app/components/avo/field_wrapper_component.rb +1 -1
- data/app/components/avo/fields/area_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +5 -5
- data/app/components/avo/fields/belongs_to_field/edit_component.rb +4 -4
- data/app/components/avo/fields/boolean_field/edit_component.html.erb +1 -0
- data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/code_field/edit_component.html.erb +1 -0
- data/app/components/avo/fields/country_field/edit_component.html.erb +1 -0
- data/app/components/avo/fields/file_field/index_component.rb +2 -2
- data/app/components/avo/fields/has_one_field/show_component.html.erb +1 -0
- data/app/components/avo/fields/index_component.rb +1 -0
- data/app/components/avo/fields/location_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/markdown_field/edit_component.html.erb +1 -0
- data/app/components/avo/fields/number_field/edit_component.html.erb +1 -0
- data/app/components/avo/fields/password_field/edit_component.html.erb +1 -0
- data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +1 -0
- data/app/components/avo/fields/status_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/text_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/textarea_field/edit_component.html.erb +1 -0
- data/app/components/avo/fields/trix_field/edit_component.html.erb +2 -1
- data/app/components/avo/fields/trix_field/show_component.html.erb +1 -1
- data/app/components/avo/index/resource_controls_component.rb +6 -6
- data/app/components/avo/item_switcher_component.html.erb +9 -4
- data/app/components/avo/item_switcher_component.rb +2 -1
- data/app/components/avo/resource_component.rb +5 -3
- data/app/components/avo/resource_sidebar_component.rb +1 -1
- data/app/components/avo/row_component.html.erb +3 -0
- data/app/components/avo/row_component.rb +12 -0
- data/app/components/avo/sidebar/link_component.html.erb +2 -0
- data/app/components/avo/sidebar/link_component.rb +5 -3
- data/app/components/avo/sidebar_component.html.erb +3 -3
- data/app/components/avo/sidebar_component.rb +4 -4
- data/app/components/avo/sidebar_profile_component.html.erb +3 -3
- data/app/components/avo/views/resource_edit_component.rb +1 -1
- data/app/components/avo/views/resource_index_component.html.erb +1 -1
- data/app/components/avo/views/resource_index_component.rb +8 -8
- data/app/controllers/avo/actions_controller.rb +11 -7
- data/app/controllers/avo/application_controller.rb +71 -66
- data/app/controllers/avo/associations_controller.rb +4 -6
- data/app/controllers/avo/attachments_controller.rb +1 -1
- data/app/controllers/avo/base_controller.rb +22 -15
- data/app/controllers/avo/home_controller.rb +1 -1
- data/app/controllers/avo/search_controller.rb +14 -12
- data/app/controllers/concerns/avo/initializes_avo.rb +2 -5
- data/app/javascript/js/controllers/fields/easy_mde_controller.js +1 -0
- data/app/views/avo/associations/new.html.erb +1 -1
- data/app/views/avo/debug/status.html.erb +1 -1
- data/app/views/avo/partials/_custom_tools_alert.html.erb +2 -2
- data/app/views/avo/partials/_footer.html.erb +1 -1
- data/app/views/avo/partials/_javascript.html.erb +1 -1
- data/app/views/avo/partials/_navbar.html.erb +1 -1
- data/app/views/layouts/avo/application.html.erb +2 -2
- data/avo.gemspec +1 -0
- data/config/initializers/pagy.rb +12 -10
- data/config/routes.rb +3 -3
- data/db/factories.rb +2 -1
- data/lib/avo/base_action.rb +4 -1
- data/lib/avo/base_resource.rb +118 -89
- data/lib/avo/concerns/has_item_type.rb +4 -0
- data/lib/avo/concerns/has_items.rb +20 -15
- data/lib/avo/concerns/model_class_constantized.rb +0 -2
- data/lib/avo/current.rb +22 -1
- data/lib/avo/dsl/field_parser.rb +1 -1
- data/lib/avo/dynamic_router.rb +12 -1
- data/lib/avo/engine.rb +4 -7
- data/lib/avo/fields/base_field.rb +25 -3
- data/lib/avo/fields/belongs_to_field.rb +8 -7
- data/lib/avo/fields/concerns/is_searchable.rb +1 -1
- data/lib/avo/fields/concerns/use_resource.rb +1 -1
- data/lib/avo/fields/field_manager.rb +13 -3
- data/lib/avo/fields/has_base_field.rb +4 -4
- data/lib/avo/fields/has_one_field.rb +1 -1
- data/lib/avo/fields/location_field.rb +18 -1
- data/lib/avo/licensing/h_q.rb +11 -6
- data/lib/avo/licensing/license.rb +1 -1
- data/lib/avo/licensing/license_manager.rb +1 -1
- data/lib/avo/licensing/{null_license.rb → nil_license.rb} +1 -1
- data/lib/avo/loaders/fields_loader.rb +7 -1
- data/lib/avo/plugin_manager.rb +2 -4
- data/lib/avo/reloader.rb +1 -1
- data/lib/avo/resources/items/holder.rb +5 -1
- data/lib/avo/resources/items/item_group.rb +1 -0
- data/lib/avo/resources/items/row.rb +54 -0
- data/lib/avo/resources/resource_manager.rb +4 -7
- data/lib/avo/services/debug_service.rb +6 -6
- data/lib/avo/services/telemetry_service.rb +3 -3
- data/lib/avo/version.rb +1 -1
- data/lib/avo.rb +107 -25
- data/lib/generators/avo/action_generator.rb +8 -8
- data/lib/generators/avo/card_generator.rb +27 -0
- data/lib/generators/avo/filter_generator.rb +8 -8
- data/lib/generators/avo/templates/action.tt +3 -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/cards/partial_card.tt +1 -1
- data/lib/generators/avo/templates/cards/partial_card_sample.tt +1 -1
- data/lib/generators/avo/templates/dashboards/dashboard.tt +1 -1
- data/lib/generators/avo/templates/scope.tt +1 -1
- data/lib/tasks/avo_tasks.rake +1 -28
- data/public/avo-assets/avo.base.css +26 -31
- data/public/avo-assets/avo.base.js +281 -280
- data/public/avo-assets/avo.base.js.map +3 -3
- metadata +21 -8
- data/lib/avo/app.rb +0 -170
- data/lib/generators/avo/card/chartkick_generator.rb +0 -18
- data/lib/generators/avo/card/metric_generator.rb +0 -18
- data/lib/generators/avo/card/partial_generator.rb +0 -19
- data/lib/generators/avo/templates/standalone_action.tt +0 -15
@@ -113,16 +113,16 @@ module Avo
|
|
113
113
|
|
114
114
|
def values_for_type(model = nil)
|
115
115
|
resource = target_resource
|
116
|
-
resource = Avo
|
116
|
+
resource = Avo.resource_manager.get_resource_by_model_class model if model.present?
|
117
117
|
|
118
|
-
query = resource.
|
118
|
+
query = resource.query_scope
|
119
119
|
|
120
120
|
if attach_scope.present?
|
121
121
|
query = Avo::ExecutionContext.new(target: attach_scope, query: query, parent: get_model).handle
|
122
122
|
end
|
123
123
|
|
124
124
|
query.all.map do |record|
|
125
|
-
[resource.
|
125
|
+
[resource.new(record: record).record_title, record.id]
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -180,7 +180,8 @@ module Avo
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def label
|
183
|
-
target_resource.
|
183
|
+
return if target_resource.blank?
|
184
|
+
target_resource.new(record: value)&.record_title
|
184
185
|
end
|
185
186
|
|
186
187
|
def to_permitted_param
|
@@ -232,7 +233,7 @@ module Avo
|
|
232
233
|
|
233
234
|
if is_polymorphic?
|
234
235
|
if value.present?
|
235
|
-
return Avo
|
236
|
+
return Avo.resource_manager.get_resource_by_model_class(value.class)
|
236
237
|
else
|
237
238
|
return nil
|
238
239
|
end
|
@@ -241,9 +242,9 @@ module Avo
|
|
241
242
|
reflection_key = polymorphic_as || id
|
242
243
|
|
243
244
|
if @record._reflections[reflection_key.to_s].klass.present?
|
244
|
-
Avo
|
245
|
+
Avo.resource_manager.get_resource_by_model_class @record._reflections[reflection_key.to_s].klass.to_s
|
245
246
|
elsif @record._reflections[reflection_key.to_s].options[:class_name].present?
|
246
|
-
Avo
|
247
|
+
Avo.resource_manager.get_resource_by_model_class @record._reflections[reflection_key.to_s].options[:class_name]
|
247
248
|
else
|
248
249
|
App.get_resource_by_name reflection_key.to_s
|
249
250
|
end
|
@@ -5,7 +5,7 @@ module Avo
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
def is_searchable?
|
8
|
-
defined?(
|
8
|
+
defined?(Avo::Pro) && @searchable && Avo.license.has_with_trial(:searchable_associations)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -5,7 +5,7 @@ module Avo
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
def use_resource
|
8
|
-
Avo
|
8
|
+
Avo.resource_manager.get_resource @use_resource
|
9
9
|
rescue
|
10
10
|
# On boot we eager load the resources before the app is set.
|
11
11
|
# Because of that, we don't have a resource manager.
|
@@ -11,12 +11,22 @@ module Avo
|
|
11
11
|
|
12
12
|
attr_reader :fields
|
13
13
|
|
14
|
-
alias_method :all, :fields
|
15
|
-
|
16
14
|
def initialize
|
17
15
|
@fields = []
|
18
16
|
end
|
19
17
|
|
18
|
+
def all
|
19
|
+
fields
|
20
|
+
.map do |field|
|
21
|
+
field[:name] = field[:name].to_s
|
22
|
+
|
23
|
+
field
|
24
|
+
end
|
25
|
+
.uniq do |field|
|
26
|
+
field[:name]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
20
30
|
# This method will find all fields available in the Avo::Fields namespace and add them to the fields class_variable array
|
21
31
|
# so later we can instantiate them on our resources.
|
22
32
|
#
|
@@ -36,7 +46,7 @@ module Avo
|
|
36
46
|
|
37
47
|
def load_field(method_name, klass)
|
38
48
|
fields.push(
|
39
|
-
name: method_name,
|
49
|
+
name: method_name.to_s,
|
40
50
|
class: klass
|
41
51
|
)
|
42
52
|
end
|
@@ -27,7 +27,7 @@ module Avo
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def field_resource
|
30
|
-
resource || Avo
|
30
|
+
resource || Avo.resource_manager.get_resource_by_model_class(@record.class)
|
31
31
|
end
|
32
32
|
|
33
33
|
def turbo_frame
|
@@ -57,11 +57,11 @@ module Avo
|
|
57
57
|
|
58
58
|
def target_resource
|
59
59
|
if @record._reflections[id.to_s].klass.present?
|
60
|
-
Avo
|
60
|
+
Avo.resource_manager.get_resource_by_model_class @record._reflections[id.to_s].klass.to_s
|
61
61
|
elsif @record._reflections[id.to_s].options[:class_name].present?
|
62
|
-
Avo
|
62
|
+
Avo.resource_manager.get_resource_by_model_class @record._reflections[id.to_s].options[:class_name]
|
63
63
|
else
|
64
|
-
Avo
|
64
|
+
Avo.resource_manager.get_resource_by_name id.to_s
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -29,7 +29,7 @@ module Avo
|
|
29
29
|
related_record = nil
|
30
30
|
else
|
31
31
|
related_class = model.class.reflections[name.to_s.downcase].class_name
|
32
|
-
related_resource = Avo
|
32
|
+
related_resource = Avo.resource_manager.get_resource_by_model_class(related_class)
|
33
33
|
related_record = related_resource.find_record value
|
34
34
|
end
|
35
35
|
|
@@ -3,13 +3,14 @@
|
|
3
3
|
module Avo
|
4
4
|
module Fields
|
5
5
|
class LocationField < BaseField
|
6
|
-
attr_reader :stored_as
|
6
|
+
attr_reader :stored_as, :zoom
|
7
7
|
|
8
8
|
def initialize(id, **args, &block)
|
9
9
|
hide_on :index
|
10
10
|
super(id, **args, &block)
|
11
11
|
|
12
12
|
@stored_as = args[:stored_as].present? ? args[:stored_as] : nil # You can pass it an array of db columns [:latitude, :longitude]
|
13
|
+
@zoom = args[:zoom].present? ? args[:zoom].to_i : 15
|
13
14
|
end
|
14
15
|
|
15
16
|
def value_as_array?
|
@@ -59,11 +60,27 @@ module Avo
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
63
|
+
def value
|
64
|
+
if value_as_array?
|
65
|
+
[@record.send(stored_as.first), @record.send(stored_as.last)]
|
66
|
+
else
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
62
71
|
def value_present?
|
63
72
|
return value.first.present? && value.second.present? if value.is_a?(Array) && value.count == 2
|
64
73
|
|
65
74
|
value.present?
|
66
75
|
end
|
76
|
+
|
77
|
+
def assign_value(record:, value:)
|
78
|
+
return super if stored_as.blank?
|
79
|
+
|
80
|
+
stored_as.each_with_index do |database_id, index|
|
81
|
+
record.send("#{database_id}=", value[index])
|
82
|
+
end
|
83
|
+
end
|
67
84
|
end
|
68
85
|
end
|
69
86
|
end
|
data/lib/avo/licensing/h_q.rb
CHANGED
@@ -4,6 +4,7 @@ module Avo
|
|
4
4
|
attr_accessor :current_request
|
5
5
|
attr_accessor :cache_store
|
6
6
|
|
7
|
+
# ENDPOINT = "https://v3.avohq.io/api/v1/licenses/check".freeze unless const_defined?(:ENDPOINT)
|
7
8
|
ENDPOINT = "https://avohq.io/api/v1/licenses/check".freeze unless const_defined?(:ENDPOINT)
|
8
9
|
REQUEST_TIMEOUT = 5 unless const_defined?(:REQUEST_TIMEOUT) # seconds
|
9
10
|
CACHE_TIME = 3600 unless const_defined?(:CACHE_TIME) # seconds
|
@@ -16,7 +17,7 @@ module Avo
|
|
16
17
|
|
17
18
|
def initialize(current_request = nil)
|
18
19
|
@current_request = current_request
|
19
|
-
@cache_store = Avo
|
20
|
+
@cache_store = Avo.cache_store
|
20
21
|
end
|
21
22
|
|
22
23
|
def response
|
@@ -69,10 +70,10 @@ module Avo
|
|
69
70
|
app_name: app_name
|
70
71
|
}
|
71
72
|
|
72
|
-
metadata = Avo::Services::DebugService.avo_metadata
|
73
|
-
if metadata[:resources_count] != 0
|
74
|
-
|
75
|
-
end
|
73
|
+
# metadata = Avo::Services::DebugService.avo_metadata
|
74
|
+
# if metadata[:resources_count] != 0
|
75
|
+
# result[:avo_metadata] = "metadata"
|
76
|
+
# end
|
76
77
|
|
77
78
|
result
|
78
79
|
end
|
@@ -149,7 +150,11 @@ module Avo
|
|
149
150
|
def perform_request
|
150
151
|
Avo.logger.debug "Performing request to avohq.io API to check license availability." if Rails.env.development?
|
151
152
|
|
152
|
-
|
153
|
+
if Rails.env.test?
|
154
|
+
OpenStruct.new({code: 200, parsed_response: {id: "pro", valid: true}})
|
155
|
+
else
|
156
|
+
HTTParty.post ENDPOINT, body: payload.to_json, headers: {"Content-type": "application/json"}, timeout: REQUEST_TIMEOUT
|
157
|
+
end
|
153
158
|
end
|
154
159
|
|
155
160
|
def app_name
|
@@ -6,7 +6,7 @@ module Avo
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def method_missing(method, *args, &block)
|
9
|
-
matched_field = Avo
|
9
|
+
matched_field = Avo.field_manager.find do |field|
|
10
10
|
field[:name].to_s == method.to_s
|
11
11
|
end
|
12
12
|
|
@@ -22,6 +22,12 @@ module Avo
|
|
22
22
|
add_field field
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
def respond_to_missing?(method)
|
27
|
+
Avo.field_manager.find do |field|
|
28
|
+
field[:name].to_s == method.to_s
|
29
|
+
end
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
data/lib/avo/plugin_manager.rb
CHANGED
@@ -25,15 +25,13 @@ module Avo
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def register_field(method_name, klass)
|
28
|
-
Avo
|
28
|
+
Avo.field_manager.load_field method_name, klass
|
29
29
|
end
|
30
30
|
|
31
31
|
def register_resource_tool
|
32
|
-
# puts ["register_resource_tool->"].inspect
|
33
32
|
end
|
34
33
|
|
35
34
|
def register_tool
|
36
|
-
# puts ["register_tool->"].inspect
|
37
35
|
end
|
38
36
|
|
39
37
|
def as_json(*arg)
|
@@ -47,7 +45,7 @@ module Avo
|
|
47
45
|
|
48
46
|
def installed?(name)
|
49
47
|
plugins.any? do |plugin|
|
50
|
-
plugin.klass.to_s.
|
48
|
+
plugin.klass.to_s.chomp("::Plugin").underscore.tr("/", "-") == name.to_s
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
data/lib/avo/reloader.rb
CHANGED
@@ -46,7 +46,7 @@ class Avo::Reloader
|
|
46
46
|
if reload_lib?
|
47
47
|
dirs[Avo::Engine.root.join("lib", "avo").to_s] = ["rb"]
|
48
48
|
if Avo.avo_filters_installed?
|
49
|
-
dirs[
|
49
|
+
dirs[Avo::DynamicFilters::Engine.root.join("lib", "avo", "dynamic_filters").to_s] = ["rb"]
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -22,7 +22,7 @@ class Avo::Resources::Items::Holder
|
|
22
22
|
name: field_name,
|
23
23
|
as: as,
|
24
24
|
# resource: resource_class.name,
|
25
|
-
message: "There's an invalid field configuration for this resource. <br/> <code class='px-1 py-px rounded bg-red-600'>field :#{field_name}, as:
|
25
|
+
message: "There's an invalid field configuration for this resource. <br/> <code class='px-1 py-px rounded bg-red-600'>field :#{field_name}, as: :#{as}</code>"
|
26
26
|
})
|
27
27
|
end
|
28
28
|
|
@@ -41,6 +41,10 @@ class Avo::Resources::Items::Holder
|
|
41
41
|
add_item Avo::Resources::Items::Tab::Builder.parse_block(name: name, **args, &block)
|
42
42
|
end
|
43
43
|
|
44
|
+
def row(**args, &block)
|
45
|
+
add_item Avo::Resources::Items::Row::Builder.parse_block(**args, &block)
|
46
|
+
end
|
47
|
+
|
44
48
|
def tool(klass, **args)
|
45
49
|
instance = klass.new(**args)
|
46
50
|
add_item instance
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Avo::Resources::Items::Row
|
2
|
+
include Avo::Concerns::IsResourceItem
|
3
|
+
include Avo::Concerns::HasItems
|
4
|
+
include Avo::Concerns::HasItemType
|
5
|
+
include Avo::Concerns::IsVisible
|
6
|
+
|
7
|
+
class_attribute :item_type, default: :row
|
8
|
+
|
9
|
+
attr_reader :view
|
10
|
+
attr_accessor :items_holder
|
11
|
+
|
12
|
+
delegate :items, :add_item, to: :items_holder
|
13
|
+
|
14
|
+
def initialize(view: nil)
|
15
|
+
@view = view
|
16
|
+
@items_holder = Avo::Resources::Items::Holder.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def hydrate(view: nil, resource: nil, **args)
|
20
|
+
@view = view
|
21
|
+
@resource = resource
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def has_items?
|
27
|
+
@items.present?
|
28
|
+
end
|
29
|
+
|
30
|
+
class Builder
|
31
|
+
class << self
|
32
|
+
def parse_block(**args, &block)
|
33
|
+
Docile.dsl_eval(new(**args), &block).build
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :items_holder
|
38
|
+
|
39
|
+
delegate :field, to: :items_holder
|
40
|
+
delegate :tool, to: :items_holder
|
41
|
+
delegate :items, to: :items_holder
|
42
|
+
|
43
|
+
def initialize(**args)
|
44
|
+
@row = Avo::Resources::Items::Row.new(**args)
|
45
|
+
@items_holder = Avo::Resources::Items::Holder.new
|
46
|
+
end
|
47
|
+
|
48
|
+
# Fetch the tab
|
49
|
+
def build
|
50
|
+
@row.items_holder = @items_holder
|
51
|
+
@row
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -66,9 +66,6 @@ module Avo
|
|
66
66
|
# We need to de-duplicate them
|
67
67
|
klass.name
|
68
68
|
end
|
69
|
-
.map do |resource|
|
70
|
-
resource.new if resource.is_a? Class
|
71
|
-
end
|
72
69
|
end
|
73
70
|
|
74
71
|
def check_bad_resources
|
@@ -76,13 +73,13 @@ module Avo
|
|
76
73
|
has_model = resource.model_class.present?
|
77
74
|
|
78
75
|
unless has_model
|
79
|
-
possible_model = resource.
|
76
|
+
possible_model = resource.to_s.gsub "Avo::Resources::", ""
|
80
77
|
possible_model = possible_model.gsub "Resource", ""
|
81
78
|
|
82
|
-
Avo
|
79
|
+
Avo.error_manager.add({
|
83
80
|
url: "https://docs.avohq.io/2.0/resources.html#custom-model-class",
|
84
81
|
target: "_blank",
|
85
|
-
message: "#{resource
|
82
|
+
message: "#{resource} does not have a valid model assigned. It failed to find the #{possible_model} model. \n\r Please create that model or assign one using self.model_class = YOUR_MODEL"
|
86
83
|
})
|
87
84
|
end
|
88
85
|
end
|
@@ -100,7 +97,7 @@ module Avo
|
|
100
97
|
resource = "Avo::Resources::#{resource}" unless resource.to_s.starts_with?("Avo::Resources::")
|
101
98
|
|
102
99
|
resources.find do |available_resource|
|
103
|
-
resource.to_s == available_resource.
|
100
|
+
resource.to_s == available_resource.to_s
|
104
101
|
end
|
105
102
|
end
|
106
103
|
|
@@ -12,7 +12,7 @@ class Avo::Services::DebugService
|
|
12
12
|
payload[:hq_payload] = hq&.payload
|
13
13
|
payload[:thread_count] = get_thread_count
|
14
14
|
payload[:license_abilities] = Avo::Current&.license&.abilities
|
15
|
-
payload[:cache_store] = Avo
|
15
|
+
payload[:cache_store] = Avo.cache_store&.class&.to_s
|
16
16
|
payload[:avo_metadata] = avo_metadata
|
17
17
|
payload[:app_timezone] = Time.current.zone
|
18
18
|
payload[:cache_key] = Avo::Licensing::HQ.cache_key
|
@@ -31,8 +31,8 @@ class Avo::Services::DebugService
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def avo_metadata
|
34
|
-
resources = Avo
|
35
|
-
dashboards = defined?(
|
34
|
+
resources = Avo.resource_manager.all
|
35
|
+
dashboards = defined?(Avo::Dashboards) ? Avo::Dashboards.dashboard_manager.all : []
|
36
36
|
field_definitions = resources.map(&:get_field_definitions)
|
37
37
|
fields_count = field_definitions.map(&:count).sum
|
38
38
|
fields_per_resource = sprintf("%0.01f", fields_count / (resources.count + 0.0))
|
@@ -55,11 +55,11 @@ class Avo::Services::DebugService
|
|
55
55
|
fields_per_resource: fields_per_resource,
|
56
56
|
custom_fields_count: custom_fields_count,
|
57
57
|
field_types: field_types,
|
58
|
-
# **other_metadata(:actions), #
|
58
|
+
# **other_metadata(:actions), # TODO: this is fetching actions without hydration
|
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
|
62
|
+
cache_store: Avo.cache_store&.class&.to_s,
|
63
63
|
**config_metadata
|
64
64
|
}
|
65
65
|
# rescue => error
|
@@ -69,7 +69,7 @@ class Avo::Services::DebugService
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def other_metadata(type = :actions)
|
72
|
-
resources = Avo
|
72
|
+
resources = Avo.resource_manager.all
|
73
73
|
|
74
74
|
types = resources.map(&:"get_#{type}")
|
75
75
|
type_count = types.flatten.uniq.count
|
@@ -23,7 +23,7 @@ class Avo::Services::TelemetryService
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def avo_metadata
|
26
|
-
resources = Avo
|
26
|
+
resources = Avo.resource_manager.all
|
27
27
|
dashboards = Avo::Current.app.dashboard_manager.all
|
28
28
|
field_definitions = resources.map(&:get_field_definitions)
|
29
29
|
fields_count = field_definitions.map(&:count).sum
|
@@ -51,7 +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
|
54
|
+
cache_store: Avo.cache_store&.class&.to_s,
|
55
55
|
**config_metadata
|
56
56
|
}
|
57
57
|
# rescue => error
|
@@ -61,7 +61,7 @@ class Avo::Services::TelemetryService
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def other_metadata(type = :actions)
|
64
|
-
resources = Avo
|
64
|
+
resources = Avo.resource_manager.all
|
65
65
|
|
66
66
|
types = resources.map(&:"get_#{type}")
|
67
67
|
type_count = types.flatten.uniq.count
|
data/lib/avo/version.rb
CHANGED
data/lib/avo.rb
CHANGED
@@ -11,31 +11,9 @@ loader.inflector.inflect(
|
|
11
11
|
loader.ignore("#{__dir__}/generators")
|
12
12
|
loader.setup
|
13
13
|
|
14
|
-
# .//*,,.....,,*/(*
|
15
|
-
# **,,..............,*#.
|
16
|
-
# ,*,,..... .....*/#.
|
17
|
-
# **,,.... ....,*/%%
|
18
|
-
# ,**,,....... . ....*/#&%
|
19
|
-
# **,,,...... . . ....*/#&&%
|
20
|
-
# **,,........ . . ...,//#&&&.
|
21
|
-
# */*,,..*//***,,,,*/(,.. .. .....*//%&%&*
|
22
|
-
# ,/**,..**/******,,***/(###,...........,//(%&&%.
|
23
|
-
# /**,,..((//*****////((##%%%%%*.........*//%%&&%
|
24
|
-
# ****,...#/**,,,*,*/(#%##%%%%&&&(*,.....,*/(%&&&/
|
25
|
-
# /**,....(/*,,,,,,,*(##%%%%%&&&&&(,.....,*(#&&&&.
|
26
|
-
# ,//*,.....(/*,,**//(##%%%%&&&&@&&%/,....,*((&&&&*
|
27
|
-
# .//*,,.....(((//(((##%%%&&&&&&&&@#/,....,*/#%&&&#
|
28
|
-
# (/**,,......###%%%%%&&&&&&&&&&@#/,,...,,*/#&&&&&
|
29
|
-
# (/**,,........%%%%%&&&&&&&&@%(*,...,,,*//(&&&&%.
|
30
|
-
# ///*,,,.........,*#&&&&#(/,,.....,,,*//(%&&&&%*
|
31
|
-
# (//**,,,.....................,,,,*//(%&&&&&&*
|
32
|
-
# *(///**,,,,............,,,,,,**/((&&&&&&&%.
|
33
|
-
# ((///*****,,,,,,,,,,,,***//((&&&&&%&%&#
|
34
|
-
# .((((////********///(((%&%&&&&%%%%%
|
35
|
-
# (############%%%%%%%%%%%%%%%*
|
36
|
-
# ,(############%%%%%#*
|
37
|
-
|
38
14
|
module Avo
|
15
|
+
extend ActiveSupport::LazyLoadHooks
|
16
|
+
|
39
17
|
ROOT_PATH = Pathname.new(File.join(__dir__, ".."))
|
40
18
|
IN_DEVELOPMENT = ENV["AVO_IN_DEVELOPMENT"] == "1"
|
41
19
|
PACKED = !IN_DEVELOPMENT
|
@@ -64,8 +42,112 @@ module Avo
|
|
64
42
|
class DeprecatedAPIError < StandardError; end
|
65
43
|
|
66
44
|
class << self
|
45
|
+
attr_reader :logger
|
46
|
+
attr_reader :cache_store
|
47
|
+
attr_reader :field_manager
|
48
|
+
|
49
|
+
delegate :license, :app, :error_manager, :tool_manager, :resource_manager, to: Avo::Current
|
50
|
+
|
51
|
+
def boot
|
52
|
+
boot_logger
|
53
|
+
boot_fields
|
54
|
+
@cache_store = get_cache_store
|
55
|
+
plugin_manager.boot_plugins
|
56
|
+
Avo.run_load_hooks(:boot, self)
|
57
|
+
end
|
58
|
+
|
59
|
+
def init
|
60
|
+
Avo::Current.error_manager = Avo::ErrorManager.build
|
61
|
+
Avo::Current.resource_manager = Avo::Resources::ResourceManager.build
|
62
|
+
Avo::Current.tool_manager = Avo::Tools::ToolManager.build
|
63
|
+
|
64
|
+
Avo.run_load_hooks(:init, self)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Renerate a dynamic root path using the URIService
|
68
|
+
def root_path(paths: [], query: {}, **args)
|
69
|
+
Avo::Services::URIService.parse(Avo::Current.view_context.avo.root_url.to_s)
|
70
|
+
.append_paths(paths)
|
71
|
+
.append_query(query)
|
72
|
+
.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
def mount_path
|
76
|
+
Avo::Engine.routes.find_script_name({})
|
77
|
+
end
|
78
|
+
|
79
|
+
def main_menu
|
80
|
+
return unless Avo.plugin_manager.installed?("avo-menu")
|
81
|
+
|
82
|
+
# Return empty menu if the app doesn't have the profile menu configured
|
83
|
+
return Avo::Menu::Builder.new.build unless has_main_menu?
|
84
|
+
|
85
|
+
Avo::Menu::Builder.parse_menu(&Avo.configuration.main_menu)
|
86
|
+
end
|
87
|
+
|
88
|
+
def profile_menu
|
89
|
+
return unless Avo.plugin_manager.installed?("avo-menu")
|
90
|
+
|
91
|
+
# Return empty menu if the app doesn't have the profile menu configured
|
92
|
+
return Avo::Menu::Builder.new.build unless has_profile_menu?
|
93
|
+
|
94
|
+
Avo::Menu::Builder.parse_menu(&Avo.configuration.profile_menu)
|
95
|
+
end
|
96
|
+
|
97
|
+
def app_status
|
98
|
+
license.valid?
|
99
|
+
end
|
100
|
+
|
67
101
|
def avo_filters_installed?
|
68
|
-
defined?(
|
102
|
+
defined?(Avo::DynamicFilters).present?
|
103
|
+
end
|
104
|
+
|
105
|
+
def has_main_menu?
|
106
|
+
return false if Avo.license.lacks_with_trial(:menu_editor)
|
107
|
+
return false if Avo.configuration.main_menu.nil?
|
108
|
+
|
109
|
+
true
|
110
|
+
end
|
111
|
+
|
112
|
+
def has_profile_menu?
|
113
|
+
return false if Avo.license.lacks_with_trial(:menu_editor)
|
114
|
+
return false if Avo.configuration.profile_menu.nil?
|
115
|
+
|
116
|
+
true
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def boot_logger
|
122
|
+
file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log"))
|
123
|
+
|
124
|
+
file_logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
125
|
+
file_logger.formatter = proc do |severity, time, progname, msg|
|
126
|
+
"[Avo] #{time}: #{msg}\n".tap do |i|
|
127
|
+
puts i
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
@logger = file_logger
|
132
|
+
end
|
133
|
+
|
134
|
+
def boot_fields
|
135
|
+
@field_manager = Avo::Fields::FieldManager.build
|
136
|
+
end
|
137
|
+
|
138
|
+
def get_cache_store
|
139
|
+
if Rails.env.production?
|
140
|
+
case Rails.cache.class.to_s
|
141
|
+
when "ActiveSupport::Cache::MemCacheStore", "ActiveSupport::Cache::RedisCacheStore"
|
142
|
+
Rails.cache
|
143
|
+
else
|
144
|
+
ActiveSupport::Cache.lookup_store(:file_store, Rails.root.join("tmp", "cache"))
|
145
|
+
end
|
146
|
+
elsif Rails.env.test?
|
147
|
+
Rails.cache
|
148
|
+
else
|
149
|
+
ActiveSupport::Cache.lookup_store(:memory_store)
|
150
|
+
end
|
69
151
|
end
|
70
152
|
end
|
71
153
|
end
|