Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions app/controllers/admin/speakers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index

def edit
@speaker = Speaker.find_by_id(params[:id])
@speaker_form = SpeakerForm.new(speaker: @speaker)
@speaker_form = SpeakerForm.new(speaker: @speaker, conference: @conference)
@speaker_form.load
end

Expand All @@ -18,7 +18,7 @@ def edit
def update
@speaker = Speaker.find(params[:id])

@speaker_form = SpeakerForm.new(speaker_params, speaker: @speaker)
@speaker_form = SpeakerForm.new(speaker_params, speaker: @speaker, conference: @conference)
@speaker_form.sub = @speaker.sub
@speaker_form.email = @speaker.email

Expand Down Expand Up @@ -108,16 +108,31 @@ def speaker_params
:github_id,
:avatar,
:conference_id,
talks_attributes: [:id, :title, :abstract, :conference_id, :_destroy, :talk_category_id, :talk_time_id])
:additional_documents,
talks_attributes:)
end

def talks_attributes
attr = [:id, :type, :title, :abstract, :document_url, :conference_id, :_destroy, :talk_category_id, :talk_difficulty_id, :talk_time_id, :sponsor_id]
h = {}
@conference.proposal_item_configs.map(&:label).uniq.each do |label|
conf = @conference.proposal_item_configs.find_by(label:)
if conf.instance_of?(::ProposalItemConfigCheckBox)
h[conf.label.pluralize.to_sym] = []
elsif conf.instance_of?(::ProposalItemConfigRadioButton)
attr << conf.label.pluralize.to_sym
end
end
attr.append(h)
end

helper_method :speaker_url, :session_type_name, :speaker_check_in_status

def speaker_url
case action_name
when 'new'
"/#{params[:event]}/admin/speaker"
when 'edit'
"/#{params[:event]}/admin/speakers"
when 'edit', 'update'
"/#{params[:event]}/admin/speakers/#{params[:id]}"
end
end
Expand Down
14 changes: 12 additions & 2 deletions app/forms/speaker_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def talks_attributes=(attributes)
@talks ||= []
@destroy_talks ||= []
attributes.each do |_i, params|
next if params.nil?

# Normalize parameter keys to symbols
params = params.symbolize_keys

if params.key?(:id)
# talk is already exists
if params[:_destroy] == '1'
Expand All @@ -42,7 +47,9 @@ def talks_attributes=(attributes)

proposal_item_params = {}
proposal_item_config_labels.each do |label|
proposal_item_params[label.pluralize] = params.delete(label.pluralize)
pluralized_label = label.pluralize
symbol_key = pluralized_label.to_sym
proposal_item_params[pluralized_label] = params.delete(symbol_key)
end
proposal_item_config_labels.each do |label|
talk.create_or_update_proposal_item(label, proposal_item_params[label.pluralize]) if proposal_item_params[label.pluralize].present?
Expand All @@ -59,9 +66,12 @@ def talks_attributes=(attributes)
params[:video_published] = true
proposal_item_params = {}
proposal_item_config_labels.each do |label|
proposal_item_params[label.pluralize] = params.delete(label.pluralize)
pluralized_label = label.pluralize
symbol_key = pluralized_label.to_sym
proposal_item_params[pluralized_label] = params.delete(symbol_key)
end
t = Talk.new(params)
t.conference = @conference if @conference
proposal_item_config_labels.each do |label|
t.create_or_update_proposal_item(label, proposal_item_params[label.pluralize]) if proposal_item_params[label.pluralize].present?
end
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/speakers_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module SpeakersHelper
def link_to_add_talk_fields(name, f, association, **args)
new_object = f.object.to_model.class.reflect_on_association(association).klass.new
new_object = Talk.new(conference: @conference, type: 'Session')
id = new_object.object_id
fields = f.fields_for(association, new_object, child_index: id) do |builder|
render("speaker_dashboard/speakers/#{association.to_s.singularize}_fields", f: builder)
fields = f.fields_for(:talks_attributes, new_object, child_index: id) do |builder|
render("speaker_dashboard/speakers/#{association.to_s.singularize}_fields", f: builder, form_index: id)
end
link_to(name, '#', class: 'add_talk_fields ' + args[:class], data: { id:, fields: fields.gsub("\n", '') }, style: args[:style])
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/speakers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<h2>Editing Speaker</h2>

<%= render 'speaker_dashboard/speakers/form', speaker: @speaker %>
<%= render 'speaker_dashboard/speakers/form' %>

<%= link_to 'Back', admin_speakers_url %>
<% end %>
8 changes: 5 additions & 3 deletions app/views/speaker_dashboard/speakers/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_with(url: speaker_url, model: @speaker_form) do |form| %>
<%= form_with(model: @speaker_form, url: speaker_url, method: (action_name == 'edit' ? :patch : :post), local: true, data: { turbo: false }) do |form| %>
<section class="speaker-information py-3">
<a id="speaker"><h3 class="py-3">登壇者情報</h3></a>

Expand All @@ -14,8 +14,10 @@


<div class="talk-fields">
<%= form.fields_for :talks do |talk| %>
<%= render 'speaker_dashboard/speakers/talk_fields', :f => talk, :conference => @conference %>
<% @speaker_form.talks.each_with_index do |talk_obj, index| %>
<%= form.fields_for :talks_attributes, talk_obj, index: index do |talk| %>
<%= render 'speaker_dashboard/speakers/talk_fields', :f => talk, :conference => @conference, :form_index => index %>
<% end %>
<% end %>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if f.object&.proposal&.accepted? %>
<%= radio_button_tag "speaker[talks_attributes][#{f.options[:child_index]}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, disabled: 'disabled'} %>
<%= radio_button_tag "speaker[talks_attributes][#{form_index}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, disabled: 'disabled'} %>
<% else %>
<%= radio_button_tag "speaker[talks_attributes][#{f.options[:child_index]}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, id: "#{label}_#{item.params}"} %>
<%= radio_button_tag "speaker[talks_attributes][#{form_index}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, id: "#{label}_#{item.params}"} %>
<% end %>
<%= label label, item.params, {class: 'form-check-label'} %><br>
4 changes: 2 additions & 2 deletions app/views/speaker_dashboard/speakers/_session_times.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% classes += " #{item.params.split(' ').first}" if :session_times == label %>
<% if (label == :session_times && item.key.to_i == SessionTime::TWENTY_MINUTES) || (f.object&.proposal&.accepted?) %>
<%= radio_button_tag "speaker[talks_attributes][#{f.options[:child_index]}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, disabled: 'disabled'} %>
<%= radio_button_tag "speaker[talks_attributes][#{form_index}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, disabled: 'disabled'} %>
<% else %>
<%= radio_button_tag "speaker[talks_attributes][#{f.options[:child_index]}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, id: "#{label}_#{item.params}"} %>
<%= radio_button_tag "speaker[talks_attributes][#{form_index}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, id: "#{label}_#{item.params}"} %>
<% end %>
<%= label label, item.params, {class: 'form-check-label'} %><br>
45 changes: 24 additions & 21 deletions app/views/speaker_dashboard/speakers/_talk_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,39 @@
<% end %>

<div class="talk-field">
<% if f.object.persisted? %>
<%= hidden_field_tag "speaker[talks_attributes][#{form_index}][id]", f.object.id %>
<% end %>

<div class="field pb-3">
<%= f.label :title, '講演タイトル - Abstract Title(★★★)' %>*
<%= label_tag "speaker_talks_attributes_#{form_index}_title", '講演タイトル - Abstract Title(★★★)', class: 'form-label' %>*
<p class="field-description" style="font-size: 0.7em">(最大60文字)受講者の目を引くようなるべく具体的なテクノロジー名を含めることをおすすめします - (Maximum 60 characters) Include concrete technology names as possible to attract attendees</p>
<%= f.text_field :title, class: "form-control", required: true %>
<%= text_field_tag "speaker[talks_attributes][#{form_index}][title]", f.object.title, class: "form-control", required: true %>
</div>

<div class="field pb-3">
<%= f.label :abstract, '講演内容 - Abstract(★★★)' %>
<%= label_tag "speaker_talks_attributes_#{form_index}_abstract", '講演内容 - Abstract(★★★)', class: 'form-label' %>
<p class="field-description" style="font-size: 0.7em">(最大500文字)どんな人に向けた講演かこの講演によって受講者がどんな情報を得られるかを含めることをおすすめします - (Maximum 500 letters) Include a session for what kind of person, what kind of information the attendee can get</p>
<%= f.text_area :abstract, {class: "form-control abstract"} %>
<%= text_area_tag "speaker[talks_attributes][#{form_index}][abstract]", f.object.abstract, class: "form-control abstract" %>
</div>

<% unless ['cicd2021', 'o11y2022', 'cnsec2022', 'cicd2023'].include?(@conference.abbr) %>
<div class="field pb-3">
<%= f.label :talk_category_id, "主なカテゴリ - Main Category(★★)" %>*
<%= label_tag "speaker_talks_attributes_#{form_index}_talk_category_id", "主なカテゴリ - Main Category(★★)", class: 'form-label' %>*
<p class="field-description" style="font-size: 0.7em">必ずしもCNCFのプロジェクトに関する内容でなくても問題ありません - It does not necessarily have to be content of the CNCF project</p>
<%= f.collection_select :talk_category_id, @conference.talk_categories, :id, :name, {prompt: ""}, class: "form-control talk-categories", required: true %>
<%= collection_select nil, "speaker[talks_attributes][#{form_index}][talk_category_id]", @conference.talk_categories, :id, :name, {prompt: "", selected: f.object.talk_category_id}, class: "form-control talk-categories", required: true %>
</div>
<% end %>

<div class="field pb-3">
<%= f.label :talk_difficulty_id, "受講者レベル - Audience Experience Level(★★)" %>*
<%= f.collection_select :talk_difficulty_id, @conference.talk_difficulties, :id, :name, {prompt: ""}, class: "form-control", required: true %>
<%= label_tag "speaker_talks_attributes_#{form_index}_talk_difficulty_id", "受講者レベル - Audience Experience Level(★★)", class: 'form-label' %>*
<%= collection_select nil, "speaker[talks_attributes][#{form_index}][talk_difficulty_id]", @conference.talk_difficulties, :id, :name, {prompt: "", selected: f.object.talk_difficulty_id}, class: "form-control", required: true %>
</div>

<% if @conference.speaker_entry_disabled? %>
<div class="field pb-3">
<%= f.label :document_url, "セッション資料公開URL" %>
<%= f.text_field :document_url, class: "form-control" %>
<%= label_tag "speaker_talks_attributes_#{form_index}_document_url", "セッション資料公開URL", class: 'form-label' %>
<%= text_field_tag "speaker[talks_attributes][#{form_index}][document_url]", f.object.document_url, class: "form-control" %>
</div>
<% end %>

Expand All @@ -49,31 +52,31 @@

<% if first_item.class.to_s == 'ProposalItemConfigCheckBox' %>
<% existing_items = f.object&.persisted? ? f.object.proposal_items.find_by(label: first_item.label)&.params : []%>
<%= label_tag "speaker_talks_attributes_#{f.options[:child_index]}_#{first_item.label}", first_item.item_name, {class: 'form-check-label'}%>*
<%= label_tag "speaker_talks_attributes_#{form_index}_#{first_item.label}", first_item.item_name, {class: 'form-check-label'}%>*
<div class="form-check">
<% @conference.proposal_item_configs.where(item_number: item_number).each do |item|%>
<% label = item.label.pluralize.to_sym %>
<% checked = existing_items ? existing_items.include?(item.id.to_s) : false%>
<%= check_box_tag "speaker[talks_attributes][#{f.options[:child_index]}][#{label}][]", item.id, checked, {id: "#{label}_#{item.params}", class: 'form-check-input'} %>
<%= check_box_tag "speaker[talks_attributes][#{form_index}][#{label}][]", item.id, checked, {id: "#{label}_#{item.params}", class: 'form-check-input'} %>
<%= label label, item.params, {class: 'form-check-label'} %><br>
<% end %>
</div>

<% elsif first_item.class.to_s == 'ProposalItemConfigRadioButton' %>
<% existing_items = f.object&.persisted? ? f.object.proposal_items.find_by(label: first_item.label)&.params : []%>
<%= label_tag "speaker_talks_attributes_#{f.options[:child_index]}_#{first_item.label}[]", first_item.item_name, {class: 'form-check-label'}%>*<br>
<%= label_tag "speaker_talks_attributes_#{form_index}_#{first_item.label}[]", first_item.item_name, {class: 'form-check-label'}%>*<br>
<p class="field-description" style="font-size: 0.7em"><%= first_item.description&.html_safe %></p>
<% @conference.proposal_item_configs.where(item_number: item_number).each do |item|%>
<% label = first_item.label.pluralize.to_sym %>
<% checked = existing_items ? existing_items.include?(item.id.to_s) : false%>
<% classes = "radio_button_#{label}" %>
<% case item.label %>
<% when 'presentation_method' then %>
<%= render 'speaker_dashboard/speakers/presentation_method', f: f, existing_items: existing_items, first_item: first_item, item: item, classes: classes, label: label, checked: checked %>
<%= render 'speaker_dashboard/speakers/presentation_method', f: f, existing_items: existing_items, first_item: first_item, item: item, classes: classes, label: label, checked: checked, form_index: form_index %>
<% when 'session_time' then %>
<%= render 'speaker_dashboard/speakers/session_times', f: f, existing_items: existing_items, first_item: first_item, item: item, classes: classes, label: label, checked: checked %>
<%= render 'speaker_dashboard/speakers/session_times', f: f, existing_items: existing_items, first_item: first_item, item: item, classes: classes, label: label, checked: checked, form_index: form_index %>
<% else %>
<%= radio_button_tag "speaker[talks_attributes][#{f.options[:child_index]}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, id: "#{label}_#{item.params}"} %>
<%= radio_button_tag "speaker[talks_attributes][#{form_index}][#{label}]", item.id, checked, {required: true, class: classes, params: item.params, id: "#{label}_#{item.params}"} %>
<%= label label, item.params, {class: 'form-check-label'} %><br>
<% end %>
<% end %>
Expand All @@ -83,14 +86,14 @@
<% end %>

<% if @sponsor %>
<%= f.hidden_field :sponsor_id, value: @sponsor.id %>
<%= f.hidden_field :type, value: 'SponsorSession' %>
<%= hidden_field_tag "speaker[talks_attributes][#{form_index}][sponsor_id]", @sponsor.id %>
<%= hidden_field_tag "speaker[talks_attributes][#{form_index}][type]", 'SponsorSession' %>
<% else %>
<%= f.hidden_field :type, value: 'Session' %>
<%= hidden_field_tag "speaker[talks_attributes][#{form_index}][type]", 'Session' %>
<% end %>

<%= f.hidden_field :_destroy, class: "destroy_flag_field" %>
<%= f.hidden_field :conference_id, value: @conference.id %>
<%= hidden_field_tag "speaker[talks_attributes][#{form_index}][_destroy]", "false", class: "destroy_flag_field" %>
<%= hidden_field_tag "speaker[talks_attributes][#{form_index}][conference_id]", @conference.id %>

<% if @conference.speaker_entry_enabled? || admin? %>
<%= link_to 'Delete Talk', '#', class: 'remove_talk_field btn btn-danger' %>
Expand Down
Loading