diff --git a/app/assets/javascripts/admins/competition_settings/index.js b/app/assets/javascripts/admins/competition_settings/index.js index 9eb53d529..e974d2550 100644 --- a/app/assets/javascripts/admins/competition_settings/index.js +++ b/app/assets/javascripts/admins/competition_settings/index.js @@ -107,6 +107,34 @@ $(document).on('turbolinks:load', function(){ } }); }); + + var selectOptions = { + theme: 'bootstrap4', + placeholder: '请输入要添加的单位名称', + multiple: true, + minimumInputLength: 1, + ajax: { + delay: 500, + url: '/api/schools/for_option.json', + dataType: 'json', + data: function(params){ + return { keyword: params.term }; + }, + processResults: function(data){ + return { results: data.schools } + } + }, + templateResult: function (item) { + if(!item.id || item.id === '') return item.text; + return item.name || item.text; + }, + templateSelection: function(item){ + return item.name || item.text; + } + } + + $('.sponsor-select').select2(selectOptions); + $('.allow-school-select').select2(selectOptions); } }); @@ -291,7 +319,7 @@ $(function () { } }); - $('form.stage-update-form').on('click', ".update-stage", function () { + $('.competition-chart-setting').on('click', ".update-stage", function () { var updateForm = $(this).parents("form"); $(this).attr('disabled', 'disabled'); updateForm.find('.error').html(''); @@ -450,24 +478,83 @@ function Del_tab(item) { $(item).parents(".large_panel_part").remove(); } //新增tab -function addNewTab() { - var count = parseInt($("#large_panel").find(".large_panel_part").length)+1; - var html = '
\n' + - ' tab标题\n' + - '
\n' + - ' \n' + - '
\n' + - ' 总排行榜占比:\n' + - '
\n' + - ' \n' + - '
%\n' + - '
\n' + - ' 新增子阶段\n' + - '
\n' + - ' 删除\n' + - ' 保存\n' + - '
\n' + - '
'; - $("#large_panel").append(html); - +function addNewTab(competition_id) { + if($(".new-stage-form").length > 0){ + alert("请先保存上一个tab"); + } else { + var count = parseInt($("#large_panel").find(".large_panel_part").length)+1; + var html = '
' + + '
\n' + + ' tab标题\n' + + '
\n' + + ' \n' + + '
\n' + + ' 总排行榜占比:\n' + + '
\n' + + ' \n' + + '
%\n' + + '
\n' + + ' 新增子阶段\n' + + '
\n' + + ' 删除\n' + + ' 保存\n' + + '
\n' + + '
\n' + + '
\n' + + ' 第1阶段\n' + + '
\n' + + '
\n' + + ' 有效时间:\n' + + '
\n' + + ' \n' + + '
\n' + + ' ~\n' + + '
\n' + + ' \n' + + '
\n' + + ' 任务完成要求:\n' + + '
\n' + + ' \n' + + '
\n' + + ' /\n' + + '
\n' + + ' \n' + + '
\n' + + ' (总任务)\n' + + ' 成绩来源:\n' + + '
\n' + + ' \n' + + '
\n' + + '
\n' + + '
\n' + + '
\n' + + ' 任务1\n' + + '
\n' + + ' \n' + + '
\n' + + '
\n' + + '
\n' + + ' 任务2\n' + + '
\n' + + ' \n' + + '
\n' + + '
\n' + + '
\n' + + ' 任务3\n' + + '
\n' + + ' \n' + + '
\n' + + '
\n' + + '
\n' + + '
\n' + + ' \n' + + ' 删除\n' + + ' \n' + + '
\n' + + '
'; + $("#large_panel").append(html); + } } \ No newline at end of file diff --git a/app/controllers/admins/competition_stages_controller.rb b/app/controllers/admins/competition_stages_controller.rb index 5445d59a9..63e2429e3 100644 --- a/app/controllers/admins/competition_stages_controller.rb +++ b/app/controllers/admins/competition_stages_controller.rb @@ -1,14 +1,8 @@ class Admins::CompetitionStagesController < Admins::BaseController def create - Admins::CompetitionStageUpdateService.call(current_competition, update_form_params) + Admins::CompetitionStageCreateService.call(current_competition, update_form_params) render_ok - if current_competition.competition_stages.exists?(name: params[:stage_name]) - render_error "已存在同名的阶段" - else - current_competition.competition_stages << CompetitionStage.new(name: params[:stage_name]) - render_ok - end end def update diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index 2c3d00529..18e5bb371 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -30,6 +30,8 @@ class Competitions::CompetitionsController < Competitions::BaseController def show @competition = current_competition + + current_competition.increment(:visits) end def update diff --git a/app/services/admins/competition_stage_create_service.rb b/app/services/admins/competition_stage_create_service.rb index d11276ef3..4389a727d 100644 --- a/app/services/admins/competition_stage_create_service.rb +++ b/app/services/admins/competition_stage_create_service.rb @@ -10,8 +10,6 @@ class Admins::CompetitionStageCreateService < ApplicationService ActiveRecord::Base.transaction do stage = CompetitionStage.create!(competition_id: competition.id, name: params[:stage_name], score_rate: (params[:score_rate].to_i / 100).round(2)) - stage.competition_stage_sections.destroy_all - params[:stage].each do |section| stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id, start_time: section["start_time"], end_time: section["end_time"], diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index 44e3da7ee..f59f659ee 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -97,13 +97,8 @@
主办方
-
- + - +
+ <%= select_tag :sponsor_ids, options_for_select([], nil), class: 'form-control sponsor-select' %>
@@ -111,13 +106,8 @@
开放范围
-
- + - +
+ <%= select_tag :allow_school_ids, options_for_select([], nil), class: 'form-control allow-school-select' %>
@@ -333,7 +323,7 @@
排行榜设置 - + 新增tab + + 新增tab 实训ID填写示例:实训地址为https://www.educoder.net/shixuns/u5plmgka/challenges,则填写“u5plmgka”
@@ -430,7 +420,7 @@ 新增子阶段
删除 - 保存 + 保存
@@ -462,7 +452,26 @@
-
+
+
+ 任务1 +
+ +
+
+
+ 任务2 +
+ +
+
+
+ 任务3 +
+ +
+
+
删除 @@ -481,4 +490,4 @@ -<% end %> +<% end %> \ No newline at end of file