tramway-event 1.2.6 → 1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aeaf1831c90a314a57b6714c03e4b885886d52a7a8eaffb1d8eda77754c75c9f
4
- data.tar.gz: 908ce7b8500ca72a441891db385b24009c2a70dd863b800fda793f5030b8fd2d
3
+ metadata.gz: 561ce6e60c09b2065aa0054c1203e7f8faafb38308dbb1ec01e55bfebf606a18
4
+ data.tar.gz: b2d52e2dac5e50dde7ed0099ad907c369d2ecc50ff6c087f1147cc6b587df220
5
5
  SHA512:
6
- metadata.gz: 72007c767c2ae711318b0db93799f4165af55ad409d5827c592c72e69edd4884c18f2091242e98238f4c6d356771aa277aaf4673ca2be32bd636d5334da6144d
7
- data.tar.gz: 046746fe950723ae07fac8f7d6571b7888ef2413e2bf024bf1105473d62a4de6f5691785d02a2ae2e11580719366a123fb069fc39952bce1b893b7c399e8993d
6
+ metadata.gz: 7237e9582084934e3f564719199efa0f9587a0f999623e2bcdb1158f23e5f3e614094025f007d5c41bd7f5b7551c40eb790c0ba33598cacf72a6ea07b8c63e45
7
+ data.tar.gz: '09b550168725e0d6ee8e67a8e49fac7a5abedc621a605bc8a47a5b746c300cc53428d91491d1718f84666e163569d271731a23b00a86c234d4e6438ee841e1b6'
@@ -1,9 +1,7 @@
1
1
  class Tramway::Event::ParticipantsController < Tramway::Event::ApplicationController
2
2
  def create
3
3
  event = ::Tramway::Event::Event.find params[:tramway_event_participant][:event_id]
4
- class_name = "ParticipantExtendedForm#{request.uuid.gsub('-', '')}"
5
- form_class = ::Tramway::Core::ExtendableForm.new(class_name, *(event.participant_form_fields.inputs_list.map(&:title)).map(&:to_sym))
6
- @participant_form = form_class.new ::Tramway::Event::Participant.new event_id: event.id
4
+ @participant_form = ::Tramway::Event::ParticipantExtendedFormCreator.create_form_class(request.uuid, event).new ::Tramway::Event::Participant.new event_id: event.id
7
5
  if @participant_form.submit params[:tramway_event_participant].except :event_id
8
6
  redirect_to event_path event, flash: :success
9
7
  else
@@ -6,15 +6,17 @@ class Tramway::Event::ParticipantDecorator < ::Tramway::Core::ApplicationDecorat
6
6
  end
7
7
 
8
8
  def title
9
- first_name = object.values['Фамилия']
10
- last_name = object.values['Имя']
11
- patronymic = object.values['Отчество']
12
- "#{first_name} #{last_name} #{patronymic}"
9
+ if object.values.present?
10
+ first_name = object.values['Фамилия']
11
+ last_name = object.values['Имя']
12
+ patronymic = object.values['Отчество']
13
+ "#{first_name} #{last_name} #{patronymic}"
14
+ end
13
15
  end
14
16
 
15
17
  def values
16
18
  content_tag :table, class: :table do
17
- object.values.each do |key, value|
19
+ object.values&.each do |key, value|
18
20
  concat(content_tag(:tr) do
19
21
  concat(content_tag(:td) do
20
22
  key
@@ -1,6 +1,9 @@
1
- class Tramway::Event::ParticipantExtendedFormCreator
1
+ class Tramway::Event::ParticipantExtendedFormCreator < Tramway::Core::FormCreator
2
2
  def self.create_form_class(uuid, event)
3
3
  class_name = "ParticipantExtendedForm#{uuid.gsub('-', '')}"
4
- ::Tramway::Core::ExtendableForm.new(class_name, *event.participant_form_fields.inputs_list.map(&:title).map(&:to_sym))
4
+ properties = event.participant_form_fields.inputs_list.reduce({}) do |hash, field|
5
+ hash.merge! field.title.to_sym => field
6
+ end
7
+ ::Tramway::Core::ExtendableForm.new(class_name, **properties)
5
8
  end
6
9
  end
@@ -1,9 +1,15 @@
1
+ require 'securerandom'
2
+
1
3
  class Tramway::Event::ParticipantForm < ::Tramway::Core::ApplicationForm
2
- properties :event_id, :values
4
+ association :event
3
5
 
4
- def initialize(object, event)
5
- form_object = super object
6
- form_properties event_id: :default
7
- form_object
6
+ def self.new(object)
7
+ if object.event_id.present?
8
+ ::Tramway::Event::ParticipantExtendedFormCreator.create_form_class(SecureRandom.hex, object.event).new object
9
+ else
10
+ super(object).tap do |obj|
11
+ obj.form_properties event: :association
12
+ end
13
+ end
8
14
  end
9
15
  end
@@ -7,13 +7,5 @@
7
7
  = simple_form_for @participant_form, url: ::Tramway::Event::Engine.routes.url_helpers.participants_path, method: :post, html: { class: class_name, id: class_name } do |f|
8
8
  = f.input :event_id, as: :hidden, input_html: { value: event.id, class: class_name, id: "#{class_name}_event_id", name: "#{class_name}[event_id]" }
9
9
  - event.participant_form_fields.inputs_list.each do |field|
10
- - case field.field_type
11
- - when 'text', 'string', 'numeric', 'date_picker'
12
- = f.input field.title.to_sym, as: field.field_type, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
13
- - when 'select'
14
- - parsed_json = JSON.parse(field.options) unless field.options == ''
15
- - if parsed_json && parsed_json['collection']['name']
16
- = f.input field.title.to_sym, as: :select, collection: collection_list_by(name: parsed_json['collection']['name']), input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
17
- - else
18
- = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
10
+ = render 'tramway/core/shared/input_extended', field: field, class_name: class_name, f: f
19
11
  = f.button :submit, t('.submit_form')
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Event
3
- VERSION = '1.2.6'
3
+ VERSION = '1.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov