Merge remote-tracking branch 'origin/dev_aliyun' into dev_aliyun

dev_sync_trustie
杨树明 5 years ago
commit 10e52f9c64

@ -20,10 +20,14 @@ class Admins::CompetitionSettingsController < Admins::BaseController
end
def basic_form_params
params.permit(:identifier, :name, :sub_title, :sponsor_schools, :region_schools, :start_time, :end_time, :mode, :identifier, :bonus, :awards_count, :description, :course_id, :teach_start_time, :teach_end_time)
params.permit(:identifier, :name, :sub_title, :start_time, :end_time, :mode,
:identifier, :bonus, :awards_count, :description, :course_id, :teach_start_time,
:teach_end_time, sponsor_schools: [], region_schools: [])
end
def nav_form_params
params.permit(:enroll_end_time, competition_staffs: %i[category minimum maximum mutiple_limited], navbar: %i[module_type name hidden position url])
params.permit(:enroll_end_time,
competition_staffs: %i[category minimum maximum mutiple_limited],
navbar: %i[module_type name hidden position url])
end
end

@ -35,16 +35,18 @@ class Admins::CompetitionBasicSettingService < ApplicationService
end
# 主办方设置
new_school_ids = (params[:sponsor_schools] || []) - competition.sponsor_schools.pluck(:school_id)
delete_school_ids = competition.sponsor_schools.pluck(:school_id) - (params[:sponsor_schools] || [])
params[:sponsor_schools] = Array.wrap(params[:sponsor_schools]).map(&:to_i)
new_school_ids = params[:sponsor_schools] - competition.sponsor_schools.pluck(:school_id)
delete_school_ids = competition.sponsor_schools.pluck(:school_id) - params[:sponsor_schools]
new_school_ids.each do |school_id|
CompetitionSchool.create!(competition_id: competition.id, school_id: school_id, source: 'sponsor')
end
competition.sponsor_schools.where(school_id: delete_school_ids).destroy_all
# 开放范围设置
new_region_school_ids = (params[:region_schools] || []) - competition.region_schools.pluck(:school_id)
delete_region_school_ids = competition.region_schools.pluck(:school_id) - (params[:region_schools] || [])
params[:region_schools] = Array.wrap(params[:region_schools]).map(&:to_i)
new_region_school_ids = params[:region_schools] - competition.region_schools.pluck(:school_id)
delete_region_school_ids = competition.region_schools.pluck(:school_id) - params[:region_schools]
new_region_school_ids.each do |school_id|
CompetitionSchool.create!(competition_id: competition.id, school_id: school_id, source: 'region')
end

@ -98,7 +98,8 @@
主办方
</div>
<div class="col-5 text-left sponsorPanel">
<%= select_tag :sponsor_schools, options_for_select([], @competition.sponsor_schools), class: 'form-control sponsor-select' %>
<% sponsor_data = @competition.sponsor_schools.map { |s| [s.school.name, s.school.id] } %>
<%= select_tag :sponsor_schools, options_for_select(sponsor_data, @competition.sponsor_schools.map(&:school_id)), class: 'form-control sponsor-select', multiple: true %>
</div>
</div>
@ -107,7 +108,8 @@
开放范围
</div>
<div class="col-5 text-left sponsorPanel">
<%= select_tag :region_schools, options_for_select([], @competition.region_schools), class: 'form-control allow-school-select' %>
<% region_data = @competition.region_schools.map { |s| [s.school.name, s.school.id] } %>
<%= select_tag :region_schools, options_for_select(region_data, @competition.region_schools.map(&:school_id)), class: 'form-control allow-school-select', multiple: true %>
</div>
</div>

Loading…
Cancel
Save