Class: Tramway::Event::ParticipantDecorator

Inherits:
ApplicationDecorator
  • Object
show all
Includes:
HTMLTagsHelpers
Defined in:
app/decorators/tramway/event/participant_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collectionsObject



6
7
8
# File 'app/decorators/tramway/event/participant_decorator.rb', line 6

def collections
  %i[all requested waiting prev_approved without_answer approved rejected reserved]
end

.list_attributesObject



10
11
12
# File 'app/decorators/tramway/event/participant_decorator.rb', line 10

def list_attributes
  [:list_fields]
end

.show_attributesObject



15
16
17
# File 'app/decorators/tramway/event/participant_decorator.rb', line 15

def show_attributes
  %i[id event values created_at updated_at participation_state comment]
end

Instance Method Details

#created_atObject



99
100
101
# File 'app/decorators/tramway/event/participant_decorator.rb', line 99

def created_at
  date_view object.created_at
end

#eventObject



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

def event
  object.event.title
end

#list_fieldsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/decorators/tramway/event/participant_decorator.rb', line 37

def list_fields
   :table, class: :table do
    concat((:tr) do
      concat((:td) do
        object.class.human_attribute_name(:event)
      end)
      concat((:td) do
        object.event.title
      end)
    end)
    object.event.participant_form_fields.map do |field|
      hash = if field.options.is_a?(Hash)
               field.options
             else
               begin
                 JSON.parse(field.options.present? ? field.options : '{}')
               rescue StandardError => e
                 I18n.t('.invalid_field_with_error', e)
               end
             end
      if hash.is_a? Hash
        if hash.dig('list_field') == 'true'
          concat((:tr) do
            concat((:td) do
              field.title
            end)
            concat((:td) do
              value = object.values&.dig(field.title)
              if russian_phone_number?(value)
                tel_tag value
              else
                value
              end
            end)
          end)
        end
      else
        hash
      end
    end.compact
  end
end

#participation_stateObject



107
108
109
# File 'app/decorators/tramway/event/participant_decorator.rb', line 107

def participation_state
  state_machine_view object, :participation_state
end

#participation_state_button_color(event) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/decorators/tramway/event/participant_decorator.rb', line 113

def participation_state_button_color(event)
  case event
  when :previous_approve, :approve
    :success
  when :wait_for_decision, :not_got_answer
    :warning
  when :reject
    :danger
  when :reserve
    :warning
  when :return_to_requested
    :warning
  end
end

#titleObject



22
23
24
25
26
27
28
29
30
31
# File 'app/decorators/tramway/event/participant_decorator.rb', line 22

def title
  if object.values.present?
    first_name = object.values['Фамилия']
    last_name = object.values['Имя']
    patronymic = object.values['Отчество']
    "#{first_name} #{last_name} #{patronymic}"
  else
    '(участник не ввёл ФИО)'
  end
end

#updated_atObject



103
104
105
# File 'app/decorators/tramway/event/participant_decorator.rb', line 103

def updated_at
  date_view object.updated_at
end

#valuesObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/decorators/tramway/event/participant_decorator.rb', line 80

def values
   :table, class: :table do
    object.values&.each do |key, value|
      concat((:tr) do
        concat((:td) do
          key
        end)
        concat((:td) do
          concat(if russian_phone_number?(value)
                   tel_tag value
                 else
                   value
                 end)
        end)
      end)
    end
  end
end