Class: Locomotive::ContentType
- Inherits:
-
Object
- Object
- Locomotive::ContentType
- Includes:
- CustomFields::Source, Locomotive::Concerns::ContentType::ClassHelpers, Locomotive::Concerns::ContentType::DefaultValues, Locomotive::Concerns::ContentType::EntryTemplate, Locomotive::Concerns::ContentType::FilterFields, Locomotive::Concerns::ContentType::GroupBy, Locomotive::Concerns::ContentType::Import, Locomotive::Concerns::ContentType::Label, Locomotive::Concerns::ContentType::OrderBy, Locomotive::Concerns::ContentType::PublicSubmissionTitleTemplate, Locomotive::Concerns::ContentType::Sync, Locomotive::Concerns::Shared::SiteScope, Mongoid::Document
- Defined in:
- app/models/locomotive/content_type.rb
Instance Method Summary collapse
-
#entries ⇒ Object
behaviours ##.
-
#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.
- #hidden? ⇒ Boolean
-
#is_field_with_ui_enabled?(id_or_name) ⇒ Boolean
Tell if a field has to be displayed in the UI.
-
#localized? ⇒ Boolean
A localized content type owns at least one localized field.
-
#name ⇒ Object
validations ##.
-
#ordered ⇒ Object
named scopes ##.
-
#ordered_entries(options = nil) ⇒ Criteria
Order the list of entries, paginate it if requested and filter it.
- #touch_site_attribute ⇒ Object
Methods included from Locomotive::Concerns::ContentType::Import
#can_import?, #cancel_import, #change_import_state, #finish_import, #import_state, #import_status, #importing?, #on_imported_row, #start_import
Methods included from Locomotive::Concerns::ContentType::FilterFields
Methods included from Locomotive::Concerns::ContentType::PublicSubmissionTitleTemplate
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
#entries ⇒ Object
behaviours ##
38 |
# File 'app/models/locomotive/content_type.rb', line 38 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.
95 96 97 98 99 100 |
# File 'app/models/locomotive/content_type.rb', line 95 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
113 114 115 |
# File 'app/models/locomotive/content_type.rb', line 113 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
104 105 106 |
# File 'app/models/locomotive/content_type.rb', line 104 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.
109 110 111 |
# File 'app/models/locomotive/content_type.rb', line 109 def localized? self.entries_custom_fields.where(localized: true).count > 0 end |
#name ⇒ Object
validations ##
21 |
# File 'app/models/locomotive/content_type.rb', line 21 field :name |
#ordered ⇒ Object
named scopes ##
41 |
# File 'app/models/locomotive/content_type.rb', line 41 scope :ordered, -> { order_by(updated_at: :desc) } |
#ordered_entries(options = nil) ⇒ Criteria
Order the list of entries, paginate it if requested and filter it.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/locomotive/content_type.rb', line 72 def ordered_entries( = nil) ||= {} # pagination page, per_page = .delete(:page), .delete(:per_page) # order list _order_by_definition = ( || {}).delete(:order_by).try(:split) || self.order_by_definition # get list _entries = self.entries.order_by([_order_by_definition]).where([:where] || {}) # pagination or full list page ? _entries.page(page).per(per_page) : _entries end |
#touch_site_attribute ⇒ Object
117 118 119 |
# File 'app/models/locomotive/content_type.rb', line 117 def touch_site_attribute :content_version end |