Class: Locomotive::ContentType

Instance Method Summary collapse

Methods included from Locomotive::Concerns::ContentType::FilterFields

#sanitize_filter_fields

Methods included from Locomotive::Concerns::ContentType::PublicSubmissionTitleTemplate

#public_submission_title

Methods included from Locomotive::Concerns::ContentType::ClassHelpers

#class_name_to_content_type, #entries_class, #entries_class_name

Methods included from Locomotive::Concerns::ContentType::OrderBy

#order_by_attribute, #order_by_definition, #order_manually?, #sortable_column

Methods included from Locomotive::Concerns::ContentType::GroupBy

#group_by=, #group_by_field, #groupable?, #list_of_groups

Methods included from Locomotive::Concerns::ContentType::EntryTemplate

#render_entry_template, #steam_repositories, #to_steam, #to_steam_entry

Methods included from Locomotive::Concerns::ContentType::Label

#label_field_id=, #label_field_name=

Instance Method Details

#entriesObject

behaviours ##


37
# File 'app/models/locomotive/content_type.rb', line 37

has_many :entries,   class_name: 'Locomotive::ContentEntry', dependent: :destroy

#find_entries_custom_field(id_or_name) ⇒ Object

Find a custom field describing an entry based on its id in first or its name if not found.

Parameters:

  • id_or_name (String)

    The id of name of the field

Returns:

  • (Object)

    The custom field or nit if not found


94
95
96
97
98
99
# File 'app/models/locomotive/content_type.rb', line 94

def find_entries_custom_field(id_or_name)
  return nil if id_or_name.nil? # bypass the memoization

  _field = self.entries_custom_fields.find(id_or_name) rescue nil
  _field || self.entries_custom_fields.where(name: id_or_name).first
end

#hidden?Boolean

Returns:


112
113
114
# File 'app/models/locomotive/content_type.rb', line 112

def hidden?
  (self.display_settings || {})['hidden']
end

#is_field_with_ui_enabled?(id_or_name) ⇒ Boolean

Tell if a field has to be displayed in the UI

Returns:


103
104
105
# File 'app/models/locomotive/content_type.rb', line 103

def is_field_with_ui_enabled?(id_or_name)
  self.find_entries_custom_field(id_or_name)&.ui_enabled?
end

#localized?Boolean

A localized content type owns at least one localized field.

Returns:


108
109
110
# File 'app/models/locomotive/content_type.rb', line 108

def localized?
  self.entries_custom_fields.where(localized: true).count > 0
end

#nameObject

validations ##


20
# File 'app/models/locomotive/content_type.rb', line 20

field :name

#orderedObject

named scopes ##


40
# File 'app/models/locomotive/content_type.rb', line 40

scope :ordered, -> { order_by(updated_at: :desc) }

#ordered_entries(options = nil) ⇒ Criteria

Order the list of entries, paginate it if requested and filter it.

Parameters:

  • options (Hash) (defaults to: nil)

    Options to filter (where key), order (order_by key) and paginate (page, per_page keys)

Returns:

  • (Criteria)

    A Mongoid criteria if not paginated (array otherwise).


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/locomotive/content_type.rb', line 71

def ordered_entries(options = nil)
  options ||= {}

  # pagination
  page, per_page = options.delete(:page), options.delete(:per_page)

  # order list
  _order_by_definition = (options || {}).delete(:order_by).try(:split) || self.order_by_definition

  # get list
  _entries = self.entries.order_by([_order_by_definition]).where(options[:where] || {})

  # pagination or full list
  page ? _entries.page(page).per(per_page) : _entries
end

#touch_site_attributeObject


116
117
118
# File 'app/models/locomotive/content_type.rb', line 116

def touch_site_attribute
  :content_version
end