Class: Locomotive::ContentTypePresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/locomotive/content_type_presenter.rb

Instance Attribute Summary

Attributes inherited from BasePresenter

#__ability, #__depth

Instance Method Summary collapse

Methods inherited from BasePresenter

#_id, #ability?, #after_initialize, #errors, #formatted_time, getters_or_setters_to_hash, getters_to_hash, #html_view?, #include_errors?, setters_to_hash, #site, #true

Methods included from Presentable

#after_initialize, #as_json, #attributes=, #getters, #initialize, #property_options, #setters

Instance Method Details

#entries_custom_fieldsObject

other getters / setters ##



27
28
29
30
# File 'app/presenters/locomotive/content_type_presenter.rb', line 27

def entries_custom_fields
  list = self.__source.ordered_entries_custom_fields
  list ? list.map(&:as_json) : []
end

#entries_custom_fields=(fields) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/presenters/locomotive/content_type_presenter.rb', line 32

def entries_custom_fields=(fields)
  destroyed_fields = []

  fields.each do |attributes|
    id_or_name  = attributes.delete('id') || attributes.delete('_id') || attributes['name']
    field       = self.__source.find_entries_custom_field(id_or_name)

    if field && !!attributes.delete('_destroy')
      destroyed_fields << { _id: field._id, _destroy: true }
      next
    end

    field ||= self.__source.entries_custom_fields.build

    field.from_presenter(attributes)
  end

  # shift to the accepts_nested_attributes function to delete fields
  self.__source.entries_custom_fields_attributes = destroyed_fields
end

#group_by_field_nameObject



58
59
60
# File 'app/presenters/locomotive/content_type_presenter.rb', line 58

def group_by_field_name
  self.__source.group_by_field.try(:name)
end

#group_by_field_name=(name) ⇒ Object



62
63
64
65
# File 'app/presenters/locomotive/content_type_presenter.rb', line 62

def group_by_field_name=(name)
  field = self.__source.find_entries_custom_field(name)
  self.__source.group_by_field_id = field.try(:_id)
end

#nameObject

properties ##



6
# File 'app/presenters/locomotive/content_type_presenter.rb', line 6

properties  :name, :slug

#order_by_field_nameObject



53
54
55
56
# File 'app/presenters/locomotive/content_type_presenter.rb', line 53

def order_by_field_name
  value = self.__source.order_by
  self.__source.find_entries_custom_field(value).try(:name) || value
end

#public_submission_account_emailsObject



67
68
69
70
71
# File 'app/presenters/locomotive/content_type_presenter.rb', line 67

def 
  (self.__source.public_submission_accounts || []).collect do |_id|
    Locomotive::Account.where(_id: _id).first.try(:email)
  end.compact
end

#public_submission_account_emails=(emails) ⇒ Object



73
74
75
76
77
# File 'app/presenters/locomotive/content_type_presenter.rb', line 73

def (emails)
  self.__source.public_submission_accounts = emails.collect do |email|
    Locomotive::Account.where(email: email).first
  end.compact.collect(&:id)
end