Class: Tramway::Event::EventDecorator

Inherits:
Core::ApplicationDecorator
  • Object
show all
Defined in:
app/decorators/tramway/event/event_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collectionsObject



5
6
7
# File 'app/decorators/tramway/event/event_decorator.rb', line 5

def collections
  [:all]
end

.list_attributesObject



17
18
19
# File 'app/decorators/tramway/event/event_decorator.rb', line 17

def list_attributes
  %i[requested_participants approved_participants events_link]
end

.show_associationsObject



13
14
15
# File 'app/decorators/tramway/event/event_decorator.rb', line 13

def show_associations
  %i[participant_form_fields actions sections partakings]
end

.show_attributesObject



9
10
11
# File 'app/decorators/tramway/event/event_decorator.rb', line 9

def show_attributes
  %i[title duration events_link state created_at photo request_collecting_duration description participants_list]
end

Instance Method Details

#approved_participantsObject



83
84
85
86
87
88
89
90
91
92
93
# File 'app/decorators/tramway/event/event_decorator.rb', line 83

def approved_participants
  if object.end_date.present?
    if DateTime.now < object.end_date
      I18n.t('activerecord.attributes.tramway/event/event.not_yet_held')
    else
      object.participants.approved.count
    end
  else
    I18n.t('activerecord.attributes.tramway/event/event.does_not_have_end_date')
  end
end

#backgroundObject



29
30
31
# File 'app/decorators/tramway/event/event_decorator.rb', line 29

def background
  object.photo
end

#created_atObject



41
42
43
# File 'app/decorators/tramway/event/event_decorator.rb', line 41

def created_at
  date_view object.created_at
end

#descriptionObject



33
34
35
# File 'app/decorators/tramway/event/event_decorator.rb', line 33

def description
  raw object.description
end

#duration(begin_date: object.begin_date, end_date: object.end_date) ⇒ Object Also known as: tagline



51
52
53
54
55
56
57
58
59
60
61
# File 'app/decorators/tramway/event/event_decorator.rb', line 51

def duration(begin_date: object.begin_date, end_date: object.end_date)
  return unless begin_date.present? || end_date.present?

  if begin_date.to_date == end_date.to_date
    I18n.l(begin_date, format: '%d %B %Y').to_s
  elsif begin_date.month == end_date.month
    "#{I18n.t('date.from')} #{I18n.l(begin_date, format: '%d')} #{I18n.t('date.to')} #{I18n.l(end_date, format: '%d %B %Y')}"
  else
    "#{I18n.t('date.from')} #{I18n.l(begin_date, format: '%d %B %Y')} #{I18n.t('date.to')} #{I18n.l(end_date, format: '%d %B %Y')}"
  end
end


63
64
65
66
67
68
69
70
71
# File 'app/decorators/tramway/event/event_decorator.rb', line 63

def events_link
  event_link = Tramway::Event::Engine.routes.url_helpers.event_path object
  event_url = [(ENV['PROJECT_URL'] || configus.host), event_link].join
  (:pre) do
    id = "event#{object.id}"
    concat link_to event_url, event_url, id: id
    concat copy_to_clipboard id
  end
end

#participants_listObject



45
46
47
48
49
# File 'app/decorators/tramway/event/event_decorator.rb', line 45

def participants_list
   :a, href: ::Tramway::Admin::Engine.routes.url_helpers.records_path(model: ::Tramway::Event::Participant, filter: { event_id_eq: object.id }) do
    I18n.t('helpers.links.open')
  end
end

#photoObject



37
38
39
# File 'app/decorators/tramway/event/event_decorator.rb', line 37

def photo
  image_view object.photo
end

#request_collecting_durationObject



73
74
75
76
77
# File 'app/decorators/tramway/event/event_decorator.rb', line 73

def request_collecting_duration
  return if object.request_collecting_begin_date.nil? || object.request_collecting_end_date.nil?

  duration begin_date: object.request_collecting_begin_date, end_date: object.request_collecting_end_date
end

#requested_participantsObject



79
80
81
# File 'app/decorators/tramway/event/event_decorator.rb', line 79

def requested_participants
  object.participants.count
end

#stateObject



95
96
97
# File 'app/decorators/tramway/event/event_decorator.rb', line 95

def state
  state_machine_view object, :state
end