dev_sync_trustie
cxt 5 years ago
parent 380f2a62d7
commit 178d70924f

@ -29,6 +29,9 @@ $(document).on('turbolinks:load', function(){
$(".nav-setting-form .enroll_end_time").datetimepicker(timeOptions);
$(".stage-update-form .section-start-time").datetimepicker(timeOptions);
$(".stage-update-form .section-end-time").datetimepicker(timeOptions);
defineDateRangeSelect('.teaching-mode-date');
// defineTimeRangeSelect('.competition-start-end-date');
@ -209,7 +212,7 @@ $(function () {
$("#requireForm").on("click",".delRequrieBtn",function () {
$(this).parents(".requireForm_item").remove();
})
});
$('.competition-staff-settings').on('click', '.mutiple-limited-radio', function(){
var radio = $(this);
@ -248,8 +251,6 @@ $(function () {
});
});
// 排行榜设置
//删除小阶段
$("#large_panel").on("click",".small_panel_item_del",function () {
@ -260,7 +261,89 @@ $(function () {
console.log(i);
$(list).find(".subName").eq(i).html("第"+parseInt(i+1)+"阶段");
}
})
});
$('form.stage-update-form').validate({
errorElement: 'span',
errorClass: 'danger text-danger',
rules: {
stage_name: "required",
"stage[][start_time]": "required",
"stage[][end_time]": "required",
"stage[][mission_count]": {
required: true,
min: 1
},
"stage[][entry]": {
required: true,
min: 1
},
score_rate: {
required: true,
range: [0, 100]
}
},
messages: {
"stage[][mission_count]": {
min: ">=1"
},
"stage[][entry]": {
min: ">=1"
},
}
});
$('form.stage-update-form').on('click', ".update-stage", function () {
var updateForm = $(this).parents("form");
$(this).attr('disabled', 'disabled');
updateForm.find('.error').html('');
var valid = updateForm.valid();
updateForm.find('input[name="stage[][identifiers][]"]').each(function(_, e){
var $ele = $(e);
if($ele.val() === undefined || $ele.val().length === 0){
$ele.addClass('danger text-danger');
valid = false;
} else {
$ele.removeClass('danger text-danger');
}
});
if (!valid) return;
updateForm.find('input[name="stage[][mission_count]"]').each(function(_, e){
var $missionCount = $(e);
var $entryCount = $(e).parents("div.row").find('input[name="stage[][mission_count]"]');
if(parseInt($missionCount.val()) > parseInt($entryCount.val()) ){
$missionCount.addClass('danger text-danger');
$missionCount.after('<span class="danger text-danger">不能大于总任务数</span>');
valid = false;
} else {
$missionCount.removeClass('danger text-danger');
$missionCount.siblings().remove();
}
});
$.ajax({
method: 'POST',
dataType: 'json',
url: updateForm.attr('action'),
data: new FormData(updateForm[0]),
processData: false,
contentType: false,
success: function (data) {
$.notify({message: '保存成功'});
// window.location.reload();
},
error: function (res) {
var data = res.responseJSON;
$navForm.find('.error').html(data.message);
},
complete: function () {
$navForm.find('.submit-btn').attr('disabled', false);
}
});
});
});
@ -382,8 +465,6 @@ function addNewTab() {
' </div><span class=" mt-2">%</span>\n' +
' <div class="flex-1">\n' +
' <a href="javascript:void(0)"class="btn btn-outline-primary export-action ml20 add_task_sub" onclick="add_task_sub(this)">新增子阶段</a>\n' +
' <a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">发送短信提醒</a>\n' +
' <a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">计算成绩</a>\n' +
' </div>\n' +
' <a href="javascript:void(0)" class="btn btn-default ml20" onclick="Del_tab(this)">删除</a>\n' +
' <a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">保存</a>\n' +

@ -1,16 +1,18 @@
class Admins::CompetitionStagesController < Admins::BaseController
def create
if @competition.competition_stages.exists?(name: params[:stage_name])
Admins::CompetitionStageUpdateService.call(current_competition, update_form_params)
render_ok
if current_competition.competition_stages.exists?(name: params[:stage_name])
render_error "已存在同名的阶段"
else
@competition.competition_stages << CompetitionStage.new(name: params[:stage_name])
current_competition.competition_stages << CompetitionStage.new(name: params[:stage_name])
render_ok
end
end
def update
current_stage.update_attributes!(name: params[:stage_name], score_rate: params[:score_rate])
Admins::CompetitionStageUpdateService.call(current_competition, update_form_params, current_stage)
render_ok
end
@ -78,6 +80,11 @@ class Admins::CompetitionStagesController < Admins::BaseController
end
def current_stage
@_current_stage ||= CompetitionStage.find_by!(competition_id: params[:competition_id], id: params[:stage_id])
@_current_stage ||= CompetitionStage.find_by!(competition_id: params[:competition_id], id: params[:id])
end
def update_form_params
params.permit(:stage_name, :score_rate, stage: [:start_time, :end_time, :mission_count, :entry, :score_source, identifiers: []])
end
end

@ -7,6 +7,7 @@ class Competitions::TeachersController < Competitions::BaseController
end
teachers = User.joins(:user_extension).where(status: 1, user_extensions: { identity: 0 })
teachers = teachers.where(user_extensions: { school_id: current_competition.region_schools.pluck(:school_id) }) if current_competition.region_schools.size > 0
teachers = teachers.where.not(id: params[:teacher_ids]) if params[:teacher_ids].present?
teachers = teachers.where('LOWER(CONCAT(lastname, firstname, login, nickname)) LIKE ?', "%#{keyword}%")
@teachers = teachers.includes(user_extension: :school).limit(10)

@ -1,4 +1,5 @@
class CompetitionStageSection < ApplicationRecord
# score_source 0: 经验值, 1预测准确率
belongs_to :competition
belongs_to :competition_stage

@ -0,0 +1,29 @@
class Admins::CompetitionStageCreateService < ApplicationService
attr_reader :competition, :params
def initialize(competition, params)
@params = params
@competition = competition
end
def call
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"],
mission_count: section["mission_count"], entry: section["entry"],
score_source: section["score_source"])
section["identifiers"].each do |identifier|
CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id,
shixun_identifier: identifier)
end
end
stage
end
end
end

@ -0,0 +1,30 @@
class Admins::CompetitionStageUpdateService < ApplicationService
attr_reader :competition, :params, :stage
def initialize(competition, params, stage)
@params = params
@competition = competition
@stage = stage
end
def call
ActiveRecord::Base.transaction do
stage.update_attributes!(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"],
mission_count: section["mission_count"], entry: section["entry"],
score_source: section["score_source"])
section["identifiers"].each do |identifier|
CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id,
shixun_identifier: identifier)
end
end
stage
end
end
end

@ -11,7 +11,7 @@ class Competitions::CreatePersonalTeamService < ApplicationService
def call
raise Error, '个人赛才能报名' unless competition.personal?
raise Error, '本竞赛只对指定单位/学校开放' unless competition.open?(user)
raise Error, '本竞赛只面向部分学校/单位开放,你暂时没有参赛资格' unless competition.open?(user)
is_teacher = user.is_teacher?
raise Error, '本竞赛的参赛者限定为:学生' if is_teacher && competition.teacher_enroll_forbidden?

@ -13,7 +13,7 @@ class Competitions::JoinTeamService < ApplicationService
invite_code = params[:invite_code].to_s.strip
raise Error, '战队邀请码不能为空' if invite_code.blank?
raise Error, '本竞赛只对指定单位/学校开放' unless competition.open?(user)
raise Error, '本竞赛只面向部分学校/单位开放,你暂时没有参赛资格' unless competition.open?(user)
is_teacher = user.is_teacher?
raise Error, '本竞赛的参赛者限定为:学生' if is_teacher && competition.teacher_enroll_forbidden?

@ -341,10 +341,10 @@
</div>
<div class="card-body">
<div id="large_panel" class="large_panel">
<div id="large_panel" class="large_panel competition-chart-setting">
<% if @competition.competition_stages.count > 0 %>
<% @competition.competition_stages.each_with_index do |stage, index| %>
<%= form_tag(admins_competition_competition_stage_path(competition_id: @competition.id, id: stage.id), method: :put, class: 'stage_update_form flex-1', remote: true) do %>
<% @competition.competition_stages.includes(competition_stage_sections: :competition_entries).each_with_index do |stage, index| %>
<%= form_tag(admins_competition_competition_stage_path(competition_id: @competition.id, id: stage.id), method: :put, class: 'stage-update-form flex-1', remote: true) do %>
<div class="large_panel_part" attr_line="1">
<div class="row d-flex">
<span class="col-1 mt-2">tab标题</span>
@ -361,41 +361,50 @@
<a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">计算成绩</a>
</div>
<a href="javascript:void(0)" class="btn btn-default ml20" onclick="Del_tab(this)">删除</a>
<a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">保存</a>
<a href="javascript:void(0)" class="btn btn-outline-primary export-action update-stage ml20">保存</a>
</div>
<div id="small_panel_<%= index + 1 %>" class="small_panel">
<% stage.competition_stage_sections.each_with_index do |section, j| %>
<div class="row d-flex small_panel_item" attr_line="sub_1_1" count="<%= j + 1 %>">
<div class="row d-flex small_panel_item" attr_line="sub_<%= index %>_<%= j %>" count="<%= j + 1 %>">
<span class="col-1 mt-2 subName">第<%= j + 1 %>阶段</span>
<div class="flex-1">
<div class="row">
<span class="mt-2 ml20">有效时间:</span>
<div class="col-2 no_padding input_middle">
<%= text_field_tag 'stage[][start_time]', section.start_time&.strftime('%Y-%m-%d %H:%M'), autocomplete: 'off', class: 'section_start_time form-control', placeholder: '有效开始时间' %>
<%= text_field_tag 'stage[][start_time]', section.start_time&.strftime('%Y-%m-%d %H:%M'), autocomplete: 'off', class: 'section-start-time form-control', placeholder: '有效开始时间' %>
</div>
<span class="mt-2">~</span>
<div class="col-2 no_padding input_middle">
<%= text_field_tag 'stage[][end_time]', section.end_time&.strftime('%Y-%m-%d %H:%M'), autocomplete: 'off', class: 'section_end_time form-control', placeholder: '有效结束时间' %>
<%= text_field_tag 'stage[][end_time]', section.end_time&.strftime('%Y-%m-%d %H:%M'), autocomplete: 'off', class: 'section-end-time form-control', placeholder: '有效结束时间' %>
</div>
<span class="col-2 text-right mt-2 no_padding">任务完成要求:</span>
<div class="col-1 no_padding input_small">
<input type="number" class="form-control" name="stage[][end_time]"/>
<input type="number" class="form-control" value="<%= section.mission_count %>" name="stage[][mission_count]"/>
</div>
<span class="mt-2 ml10 mr10">/</span>
<div class="col-1 no_padding input_small">
<input type="number" class="form-control task_all" onchange="change_total(this)" name="task_require_all_1_1"/>
<input type="number" class="form-control task_all" value="<%= section.entry %>" onchange="change_total(this)" name="stage[][entry]"/>
</div>
<span class=" mt-2">(总任务)</span>
<span class="col-1 text-right mt-2 no_padding">成绩来源:</span>
<div class="col-2 no_padding input_middle">
<select class="form-control" name="source_1_1">
<option>经验值</option>
<option>预测准确率</option>
<select class="form-control" name="stage[][score_source]">
<option value="0" <%= section.score_source == 0 ? "selected='selected'" : "" %>>经验值</option>
<option value="1" <%= section.score_source == 1 ? "selected='selected'" : "" %>>预测准确率</option>
</select>
</div>
</div>
<div class="row mt-2" id="task_Input_sub_1_1"></div>
<div class="row mt-2" id="task_Input_sub_<%= index %>_<%= j %>">
<% section.competition_entries.each_with_index do |entry, z| %>
<div class="col-4 row task_Input_div">
<span class="col-3 text-center mt-3">任务<%= z+1 %></span>
<div class="col-8">
<input type="text" class="form-control mt-2" value="<%= entry.shixun_identifier %>" name="stage[][identifiers][]" placeholder="请填写实训ID">
</div>
</div>
<% end %>
</div>
</div>
<span>
<a href="javascript:void(0)" class="btn btn-default ml20 small_panel_item_del">删除</a>
@ -403,21 +412,17 @@
</div>
<% end %>
</div>
<div class="error my-2 danger text-danger"></div>
</div>
<% end %>
<% end %>
<% else %>
<% end %>
</div>
</div>
<div class="card-body">
<div id="large_panel" class="large_panel">
<%= form_tag(admins_competition_competition_stages_path(competition_id: @competition.id), method: :post, class: 'stage_update_form flex-1', remote: true) do %>
<div class="large_panel_part" attr_line="1">
<div class="row d-flex">
<span class="col-1 mt-2">tab标题</span>
<div class="col-2 no_padding">
<input type="text" class="form-control" name="tab_title_1"/>
<input type="text" class="form-control" name="stage_name"/>
</div>
<span class="col-1 text-right mt-2 no_padding">总排行榜占比:</span>
<div class="col-1 no_padding">
@ -425,8 +430,6 @@
</div><span class=" mt-2">%</span>
<div class="flex-1">
<a href="javascript:void(0)"class="btn btn-outline-primary export-action ml20 add_task_sub" onclick="add_task_sub(this)">新增子阶段</a>
<a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">发送短信提醒</a>
<a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">计算成绩</a>
</div>
<a href="javascript:void(0)" class="btn btn-default ml20" onclick="Del_tab(this)">删除</a>
<a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">保存</a>
@ -469,6 +472,14 @@
</div>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
<div class="card-body">
<div id="large_panel" class="large_panel">
</div>
</div>
</div>

Loading…
Cancel
Save