|
|
|
@ -14,6 +14,59 @@ class Admins::CompetitionStagesController < Admins::BaseController
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
current_stage.destroy!
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_stage_section
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
new_section = CompetitionStageSection.create!(competition_id: current_stage.competition_id, competition_stage_id: current_stage.id,
|
|
|
|
|
start_time: params[:new_start_time], end_time: params[:new_end_time],
|
|
|
|
|
entry: params[:entry], mission_count: params[:mission_count], score_source: params[:score_source])
|
|
|
|
|
unless params[:shixun_identifiers].blank?
|
|
|
|
|
params[:shixun_identifiers].each do |identifier|
|
|
|
|
|
new_section.competition_entries << CompetitionEntry.new(competition_stage_id: current_stage.id, shixun_identifier: identifier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_stage_section
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
section = current_stage.competition_stage_sections.find_by!(id: params[:section_id])
|
|
|
|
|
if section.present?
|
|
|
|
|
section_entries = section.competition_entries
|
|
|
|
|
if !params[:shixun_identifiers]
|
|
|
|
|
section_entries.destroy_all
|
|
|
|
|
else
|
|
|
|
|
if params[:shixun_identifiers].length < section_entries.size
|
|
|
|
|
section_entries[params[:shixun_identifiers].length, section_entries.size - 1].each(&:destroy)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
params[:shixun_identifiers].each_with_index do |identifier, index|
|
|
|
|
|
entry = section_entries[index]
|
|
|
|
|
if entry.present?
|
|
|
|
|
entry.update_attributes!(shixun_identifier: identifier)
|
|
|
|
|
else
|
|
|
|
|
section.competition_entries << CompetitionEntry.new(competition_stage_id: current_stage.id, shixun_identifier: identifier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
section.update_attributes!(start_time: params[:new_start_time], end_time: params[:new_end_time],
|
|
|
|
|
entry: params[:entry], mission_count: params[:mission_count], score_source: params[:score_source])
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy_stage_section
|
|
|
|
|
section = current_stage.competition_stage_sections.find_by!(id: params[:section_id])
|
|
|
|
|
section.destroy!
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def current_competition
|
|
|
|
|