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



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

def list_attributes
  %i[requested_participants approved_participants events_link]
end

.show_associationsObject



24
25
26
# File 'app/decorators/tramway/event/event_decorator.rb', line 24

def show_associations
  %i[participant_form_fields actions]
end

.show_attributesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/decorators/tramway/event/event_decorator.rb', line 9

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

Instance Method Details

#approved_participantsObject



97
98
99
100
101
102
103
104
105
106
107
# File 'app/decorators/tramway/event/event_decorator.rb', line 97

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



43
44
45
# File 'app/decorators/tramway/event/event_decorator.rb', line 43

def background
  object.photo
end

#created_atObject



55
56
57
# File 'app/decorators/tramway/event/event_decorator.rb', line 55

def created_at
  date_view object.created_at
end

#descriptionObject



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

def description
  raw object.description
end

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



65
66
67
68
69
70
71
72
73
74
75
# File 'app/decorators/tramway/event/event_decorator.rb', line 65

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


77
78
79
80
81
82
83
84
85
# File 'app/decorators/tramway/event/event_decorator.rb', line 77

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



59
60
61
62
63
# File 'app/decorators/tramway/event/event_decorator.rb', line 59

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



51
52
53
# File 'app/decorators/tramway/event/event_decorator.rb', line 51

def photo
  image_view object.photo
end

#request_collecting_durationObject



87
88
89
90
91
# File 'app/decorators/tramway/event/event_decorator.rb', line 87

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



93
94
95
# File 'app/decorators/tramway/event/event_decorator.rb', line 93

def requested_participants
  object.participants.active.count
end

#stateObject



109
110
111
# File 'app/decorators/tramway/event/event_decorator.rb', line 109

def state
  state_machine_view object, :state
end

#statusObject



113
114
115
# File 'app/decorators/tramway/event/event_decorator.rb', line 113

def status
  enumerize_view object.status
end