lib/ab_admin/models/structure.rb in ab_admin-0.3.6 vs lib/ab_admin/models/structure.rb in ab_admin-0.4.0
- old
+ new
@@ -4,26 +4,37 @@
extend ActiveSupport::Concern
included do
include AbAdmin::Concerns::Headerable
include AbAdmin::Concerns::NestedSet
+ extend EnumField::EnumeratedAttribute
- enumerated_attribute :structure_type, id_attribute: :kind
- enumerated_attribute :position_type, id_attribute: :position
+ enumerated_attribute :structure_type
+ enumerated_attribute :position_type
- validates_presence_of :title
- validates_numericality_of :position, only_integer: true
+ validates_numericality_of :position_type_id, only_integer: true
+ validates_numericality_of :structure_type_id, only_integer: true
has_one :static_page, dependent: :destroy
- has_many :visible_children, class_name: name, foreign_key: 'parent_id', conditions: {is_visible: true}
+ has_many :visible_children, -> { where(is_visible: true) }, class_name: name, foreign_key: 'parent_id'
- scope :visible, where(is_visible: true)
- scope :with_kind, proc {|structure_type| where(kind: structure_type.id) }
- scope :with_position, proc {|position_type| where(position: position_type.id).order('lft DESC') }
+ scope :visible, lambda { where(is_visible: true) }
+ scope :with_type, lambda { |structure_type| where(structure_type_id: structure_type.id) }
+ scope :with_depth, lambda { |level| where(depth: level.to_i) }
+ scope :with_position, lambda { |position_type| where(position_type_id: position_type.id).order('lft DESC') }
+
+ scope :with_kind, lambda { |structure_type|
+ ActiveSupport::Deprecation.warn('with_kind is deprecated, use with_type instead')
+ with_type.call(structure_type)
+ }
end
def redirect?
- kind == StructureType.redirect.id
+ structure_type_id == StructureType.redirect.id
+ end
+
+ def admin_title
+ [title, structure_type.title, position_type.title, "#{self.class.han(:is_visible)}: #{is_visible ? '+' : '-'}"].join(' | ')
end
end
end
end