Class: Tramway::Event::EventDecorator
- Inherits:
-
Core::ApplicationDecorator
- Object
- Core::ApplicationDecorator
- Tramway::Event::EventDecorator
- Defined in:
- app/decorators/tramway/event/event_decorator.rb
Class Method Summary collapse
- .collections ⇒ Object
- .list_attributes ⇒ Object
- .show_associations ⇒ Object
- .show_attributes ⇒ Object
Instance Method Summary collapse
- #approved_participants ⇒ Object
- #background ⇒ Object
- #created_at ⇒ Object
- #description ⇒ Object
- #duration(begin_date: object.begin_date, end_date: object.end_date) ⇒ Object (also: #tagline)
- #events_link ⇒ Object
- #participants_list ⇒ Object
- #photo ⇒ Object
- #request_collecting_duration ⇒ Object
- #requested_participants ⇒ Object
- #state ⇒ Object
Class Method Details
.collections ⇒ Object
5 6 7 |
# File 'app/decorators/tramway/event/event_decorator.rb', line 5 def collections [:all] end |
.list_attributes ⇒ Object
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_associations ⇒ Object
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_attributes ⇒ Object
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_participants ⇒ Object
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 |
#background ⇒ Object
29 30 31 |
# File 'app/decorators/tramway/event/event_decorator.rb', line 29 def background object.photo end |
#created_at ⇒ Object
41 42 43 |
# File 'app/decorators/tramway/event/event_decorator.rb', line 41 def created_at date_view object.created_at end |
#description ⇒ Object
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 |
#events_link ⇒ Object
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 content_tag(:pre) do id = "event#{object.id}" concat link_to event_url, event_url, id: id concat copy_to_clipboard id end end |
#participants_list ⇒ Object
45 46 47 48 49 |
# File 'app/decorators/tramway/event/event_decorator.rb', line 45 def participants_list content_tag :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 |
#photo ⇒ Object
37 38 39 |
# File 'app/decorators/tramway/event/event_decorator.rb', line 37 def photo image_view object.photo end |
#request_collecting_duration ⇒ Object
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_participants ⇒ Object
79 80 81 |
# File 'app/decorators/tramway/event/event_decorator.rb', line 79 def requested_participants object.participants.count end |
#state ⇒ Object
95 96 97 |
# File 'app/decorators/tramway/event/event_decorator.rb', line 95 def state state_machine_view object, :state end |