dev_sync_trustie
cxt 5 years ago
parent a9c69f204e
commit 03117b8b5a

@ -57,7 +57,7 @@ $(document).on('turbolinks:load', function(){
$basicForm.find('.error').html(''); $basicForm.find('.error').html('');
var valid = $basicForm.valid(); var valid = $basicForm.valid();
if ($("input[name='mode'[checked]]").val() == 2) { if ($("input[name='mode']:checked").val() == 2) {
var $courseId = $("input[name='course_id'"); var $courseId = $("input[name='course_id'");
if ($courseId.val() === undefined || $course_id.val().length === 0) { if ($courseId.val() === undefined || $course_id.val().length === 0) {
$courseId.addClass('danger text-danger'); $courseId.addClass('danger text-danger');
@ -65,7 +65,7 @@ $(document).on('turbolinks:load', function(){
} else { } else {
$courseId.removeClass('danger text-danger'); $courseId.removeClass('danger text-danger');
} }
} else if ($("input[name='mode'[checked]]").val() == 4) { } else if ($("input[name='mode']:checked").val() == 4) {
var $techStartTime = $("input[name='teach_start_time'"); var $techStartTime = $("input[name='teach_start_time'");
var $techEndTime = $("input[name='teach_end_time'"); var $techEndTime = $("input[name='teach_end_time'");
if ($techStartTime.val() === undefined || $techStartTime.val().length === 0) { if ($techStartTime.val() === undefined || $techStartTime.val().length === 0) {
@ -85,7 +85,7 @@ $(document).on('turbolinks:load', function(){
if (!valid) return; if (!valid) return;
$.ajax({ $.ajax({
method: 'PUT', method: 'POST',
dataType: 'json', dataType: 'json',
url: $basicForm.attr('action'), url: $basicForm.attr('action'),
data: new FormData($basicForm[0]), data: new FormData($basicForm[0]),
@ -97,10 +97,10 @@ $(document).on('turbolinks:load', function(){
}, },
error: function (res) { error: function (res) {
var data = res.responseJSON; var data = res.responseJSON;
$form.find('.error').html(data.message); $basicForm.find('.error').html(data.message);
}, },
complete: function () { complete: function () {
$form.find('.submit-btn').attr('disabled', false); $basicForm.find('.submit-btn').attr('disabled', false);
} }
}); });
}); });

@ -4,7 +4,12 @@ class Admins::CompetitionSettingsController < Admins::BaseController
end end
def basic_setting def basic_setting
Admins::CompetitionBasicSettingService.call(current_competition, form_params) Admins::CompetitionBasicSettingService.call(current_competition, basic_form_params)
render_ok
end
def nav_setting
Admins::CompetitionNavSettingService.call(current_competition, basic_form_params)
render_ok render_ok
end end
@ -14,7 +19,7 @@ class Admins::CompetitionSettingsController < Admins::BaseController
@_current_competition ||= Competition.find(params[:competition_id]) @_current_competition ||= Competition.find(params[:competition_id])
end end
def form_params def basic_form_params
params.permit(:identifier, :name, :nav_logo, :login_logo, :tab_logo, :footer, navbar: %i[name link hidden]) params.permit(:identifier, :name, :sub_title, :start_time, :end_time, :mode, :identifier, :bonus, :awards_count, :description, :course_id, :teach_start_time, :teach_end_time)
end end
end end

@ -100,10 +100,21 @@ class Competition < ApplicationRecord
private private
def get_module_name type
case type
when 'home' then '首页'
when 'enroll' then '报名'
when 'inform' then '通知公告'
when 'chart' then '排行榜'
when 'resource' then '资料下载'
else ''
end
end
def create_competition_modules def create_competition_modules
CompetitionModule.bulk_insert(*%i[competition_id name position created_at updated_at]) do |worker| CompetitionModule.bulk_insert(*%i[competition_id module_type name position created_at updated_at]) do |worker|
%w(首页 报名 通知公告 排行榜 资料下载).each_with_index do |name, index| %w(home enroll inform chart resource).each_with_index do |type, index|
worker.add(competition_id: id, name: name, position: index + 1) worker.add(competition_id: id, module_type: type, name: get_module_name(type), position: index + 1, )
end end
end end
end end

@ -6,16 +6,16 @@ class CompetitionModule < ApplicationRecord
has_one :competition_module_md_content, dependent: :destroy has_one :competition_module_md_content, dependent: :destroy
def module_url def module_url
case name case module_type
when "首页", "赛制介绍" when "home"
"/competitions/#{competition.identifier}" "/competitions/#{competition.identifier}"
when "通知公告" when "inform"
"/competitions/#{competition.identifier}/informs?status=1" "/competitions/#{competition.identifier}/informs?status=1"
when "参赛手册" when "manual"
"/competitions/#{competition.identifier}/informs?status=2" "/competitions/#{competition.identifier}/informs?status=2"
when "排行榜" when "chart"
"/competitions/#{competition.identifier}/charts" "/competitions/#{competition.identifier}/charts"
when "报名" when "enroll"
"/competitions/#{competition.identifier}/competition_teams" "/competitions/#{competition.identifier}/competition_teams"
else else
url || "/competitions/#{competition.identifier}/md_content?md_content_id=#{competition_module_md_content&.id}" url || "/competitions/#{competition.identifier}/md_content?md_content_id=#{competition_module_md_content&.id}"

@ -13,7 +13,7 @@ class Admins::CompetitionBasicSettingService < ApplicationService
competition.start_time = params[:start_time] competition.start_time = params[:start_time]
competition.end_time = params[:end_time] competition.end_time = params[:end_time]
competition.mode = params[:mode] competition.mode = params[:mode]
competition.identifier = strip params[:indentifier] competition.identifier = strip params[:identifier]
competition.bonus = params[:bonus] competition.bonus = params[:bonus]
competition.awards_count = params[:awards_count] competition.awards_count = params[:awards_count]
competition.description = strip params[:description] competition.description = strip params[:description]
@ -22,9 +22,18 @@ class Admins::CompetitionBasicSettingService < ApplicationService
if competition.mode == 1 || competition.mode == 4 if competition.mode == 1 || competition.mode == 4
competition.competition_mode_setting.destroy competition.competition_mode_setting.destroy
elsif competition.mode == 2 else
setting = competition.competition_mode_setting || CompetitionModeSetting.create!(competition_id: competition.id)
if competition.mode == 2
setting.course_id = params[:course_id]
elsif competition.mode == 3
setting.start_time = params[:teach_start_time]
setting.end_time = params[:teach_end_time]
end
setting.save!
end end
competition
end end
end end
end end

@ -0,0 +1,39 @@
class Admins::CompetitionNavSettingService < ApplicationService
attr_reader :competition, :params
def initialize(competition, params)
@params = params
@competition = competition
end
def call
ActiveRecord::Base.transaction do
competition.name = strip params[:name]
competition.sub_title = strip params[:sub_title]
competition.start_time = params[:start_time]
competition.end_time = params[:end_time]
competition.mode = params[:mode]
competition.identifier = strip params[:identifier]
competition.bonus = params[:bonus]
competition.awards_count = params[:awards_count]
competition.description = strip params[:description]
competition.save!
if competition.mode == 1 || competition.mode == 4
competition.competition_mode_setting.destroy
else
setting = competition.competition_mode_setting || CompetitionModeSetting.create!(competition_id: competition.id)
if competition.mode == 2
setting.course_id = params[:course_id]
elsif competition.mode == 3
setting.start_time = params[:teach_start_time]
setting.end_time = params[:teach_end_time]
end
setting.save!
end
competition
end
end
end

@ -17,7 +17,7 @@ end
json.stages json.stages
if @competition.mode == 1 if @competition.mode == 2
json.course_id @competition.competition_mode_setting&.course_id json.course_id @competition.competition_mode_setting&.course_id
json.member_of_course @user.member_of_course?(@competition.competition_mode_setting&.course) json.member_of_course @user.member_of_course?(@competition.competition_mode_setting&.course)
end end

@ -0,0 +1,28 @@
class MigrateCompetitionModuleType < ActiveRecord::Migration[5.2]
def change
add_column :competition_modules, :module_type, :string
Competition.all.each do |competition|
competition.competition_modules.each do |com_module|
mod_type = ""
case com_module.name
when '首页'
mod_type = "home"
when '报名'
mod_type = "enroll"
when '通知公告'
mod_type = "inform"
when '参赛手册'
mod_type = "manual"
when '排行榜'
mod_type = "chart"
when '资料下载 '
mod_type = "resource"
else
mod_type = "md"
end
com_module.update_attributes!(module_type: mod_type)
end
end
end
end
Loading…
Cancel
Save