From 5467fe75d0bc1977d334bdb7c7f9c69930e29a03 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 25 Oct 2019 15:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/competition_settings/index.js | 101 ++++++++++++++---- .../admins/competition_stages_controller.rb | 8 +- .../competition_stage_create_service.rb | 2 - .../competition_settings/index.html.erb | 25 ++++- 4 files changed, 103 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/admins/competition_settings/index.js b/app/assets/javascripts/admins/competition_settings/index.js index 9eb53d529..2dbd65299 100644 --- a/app/assets/javascripts/admins/competition_settings/index.js +++ b/app/assets/javascripts/admins/competition_settings/index.js @@ -291,7 +291,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 +450,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/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..66904fc48 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -333,7 +333,7 @@
排行榜设置 - + 新增tab + + 新增tab 实训ID填写示例:实训地址为https://www.educoder.net/shixuns/u5plmgka/challenges,则填写“u5plmgka”
@@ -430,7 +430,7 @@ 新增子阶段
删除 - 保存 + 保存
@@ -462,7 +462,26 @@
-
+
+
+ 任务1 +
+ +
+
+
+ 任务2 +
+ +
+
+
+ 任务3 +
+ +
+
+
删除