lib/avo/base_resource.rb in avo-2.7.1.pre.1 vs lib/avo/base_resource.rb in avo-2.8.0
- old
+ new
@@ -1,15 +1,17 @@
module Avo
class BaseResource
extend ActiveSupport::DescendantsTracker
- extend FieldsCollector
extend HasContext
include ActionView::Helpers::UrlHelper
include Avo::Concerns::HasTools
+ include Avo::Concerns::HasFields
+ include Avo::Concerns::HasStimulusControllers
- delegate :view_context, to: "Avo::App"
+ delegate :view_context, to: ::Avo::App
+ delegate :simple_format, :content_tag, to: :view_context
delegate :main_app, to: :view_context
delegate :avo, to: :view_context
delegate :resource_path, to: :view_context
delegate :resources_path, to: :view_context
delegate :t, to: ::I18n
@@ -26,16 +28,14 @@
class_attribute :search_query, default: nil
class_attribute :search_query_help, default: ""
class_attribute :includes, default: []
class_attribute :model_class
class_attribute :translation_key
- class_attribute :translation_enabled, default: false
class_attribute :default_view_type, default: :table
class_attribute :devise_password_optional, default: false
class_attribute :actions_loader
class_attribute :filters_loader
- class_attribute :fields
class_attribute :grid_loader
class_attribute :visible_on_sidebar, default: true
class_attribute :unscoped_queries_on_index, default: false
class_attribute :resolve_query_scope
class_attribute :resolve_find_scope
@@ -104,12 +104,10 @@
unless self.class.model_class.present?
if model_class.present?
self.class.model_class = model_class.base_class
end
end
-
- self.class.translation_enabled = ::Avo::App.translation_enabled
end
def hydrate(model: nil, view: nil, user: nil, params: nil)
@view = view if view.present?
@user = user if user.present?
@@ -126,22 +124,22 @@
def get_field_definitions
return [] if self.class.fields.blank?
fields = self.class.fields.map do |field|
- field.hydrate(resource: self, panel_name: default_panel_name, user: user, translation_enabled: translation_enabled)
+ field.hydrate(resource: self, panel_name: default_panel_name, user: user)
end
if Avo::App.license.lacks_with_trial(:custom_fields)
fields = fields.reject do |field|
field.custom?
end
end
if Avo::App.license.lacks_with_trial(:advanced_fields)
fields = fields.reject do |field|
- field.type == 'tags'
+ field.type == "tags"
end
end
fields
end
@@ -286,34 +284,38 @@
return self.class.description if self.class.description.is_a? String
end
end
def translation_key
- return "avo.resource_translations.#{class_name_without_resource.underscore}" if self.class.translation_enabled
+ return "avo.resource_translations.#{class_name_without_resource.underscore}" if ::Avo::App.translation_enabled
self.class.translation_key
end
def name
default = class_name_without_resource.titlecase
return @name if @name.present?
- return t(translation_key, count: 1, default: default).capitalize if translation_key
-
- default
+ if translation_key && ::Avo::App.translation_enabled
+ t(translation_key, count: 1, default: default).capitalize
+ else
+ default
+ end
end
def singular_name
name
end
def plural_name
default = name.pluralize
- return t(translation_key, count: 2, default: default).capitalize if translation_key
-
- default
+ if translation_key && ::Avo::App.translation_enabled
+ t(translation_key, count: 2, default: default).capitalize
+ else
+ default
+ end
end
def underscore_name
return @name if @name.present?