lib/avo/base_resource.rb in avo-1.19.1.pre.9 vs lib/avo/base_resource.rb in avo-1.19.1.pre.10

- old
+ new

@@ -17,10 +17,11 @@ attr_accessor :user attr_accessor :params class_attribute :id, default: :id class_attribute :title, default: :id + class_attribute :description, default: :id class_attribute :search_query, default: nil class_attribute :search_query_help, default: '' class_attribute :includes, default: [] class_attribute :model_class class_attribute :translation_key @@ -152,10 +153,16 @@ hydrate_fields(model: @model, view: @view) fields end + def get_field(id) + get_field_definitions.find do |f| + f.id == id.to_sym + end + end + def get_grid_fields return if self.class.grid_loader.blank? self.class.grid_loader.hydrate(model: @model, view: @view, resource: self) end @@ -222,10 +229,20 @@ return @model.send title if @model.present? name end + def resource_description + return instance_exec(&self.class.description) if self.class.description.respond_to? :call + + # Show the description only on the resource index view. + # If the user wants to conditionally it on all pages, they should use a block. + if view == :index + 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 self.class.translation_key end @@ -440,9 +457,9 @@ rescue nil end def form_scope - model.class.base_class.to_s.underscore.downcase + model_class.base_class.to_s.underscore.downcase end end end