\n' +
@@ -209,7 +210,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 +249,6 @@ $(function () {
});
});
-
-
// 排行榜设置
//删除小阶段
$("#large_panel").on("click",".small_panel_item_del",function () {
@@ -260,7 +259,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('
');
+ 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);
+ }
+ });
+ });
});
@@ -374,16 +455,14 @@ function addNewTab() {
var html = '
';
$("#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 537240bde..5445d59a9 100644
--- a/app/controllers/admins/competition_stages_controller.rb
+++ b/app/controllers/admins/competition_stages_controller.rb
@@ -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
\ No newline at end of file
diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb
index 8b69f1872..3ffd4a813 100644
--- a/app/controllers/competitions/competition_teams_controller.rb
+++ b/app/controllers/competitions/competition_teams_controller.rb
@@ -116,7 +116,8 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
keyword = params[:keyword].to_s.strip
if keyword.present?
- teams = teams.joins(users: { user_extension: :school }).where('schools.name LIKE ?', "%#{keyword}%")
+ teams = teams.joins(users: { user_extension: :school })
+ .where('competition_teams.name LIKE :keyword OR schools.name LIKE :keyword', keyword: "%#{keyword}%")
end
@all_count = teams.count
diff --git a/app/controllers/competitions/teachers_controller.rb b/app/controllers/competitions/teachers_controller.rb
index 76c7cfe6a..04ab1bdd0 100644
--- a/app/controllers/competitions/teachers_controller.rb
+++ b/app/controllers/competitions/teachers_controller.rb
@@ -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)
diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb
index bbd2a06fa..039d5e5c8 100644
--- a/app/controllers/polls_controller.rb
+++ b/app/controllers/polls_controller.rb
@@ -1363,7 +1363,7 @@ class PollsController < ApplicationController
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| ActionController::Base.helpers.strip_tags(k) if k.present?}
poll_un_anony = poll.un_anonymous
if poll_un_anony #是否匿名,默认为false
- user_info = %w(登陆名 真实姓名 邮箱 学号 学员单位)
+ user_info = %w(登陆名 真实姓名 分班 邮箱 学号 学员单位)
else
user_info = []
end
@@ -1436,9 +1436,10 @@ class PollsController < ApplicationController
if poll_un_anony
user_login = u_user.login
user_name = u_user.real_name.present? ? u_user.real_name : "--"
+ user_class = poll.course.user_group_name
user_student_id = u_user.student_id.present? ? u_user.student_id : "--"
user_school_name = u_user.school_name.present? ? u_user.school_name : "--"
- user_cell += [user_login,user_name, u_user.mail, user_student_id, user_school_name]
+ user_cell += [user_login,user_name, user_class, u_user.mail, user_student_id, user_school_name]
end
all_user_cell = user_cell + user_answer_array
user_commit.push(all_user_cell)
diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb
index 534a78dc1..1274e07c7 100644
--- a/app/helpers/export_helper.rb
+++ b/app/helpers/export_helper.rb
@@ -300,8 +300,7 @@ module ExportHelper
export_ex_users.includes(user: :user_extension).each_with_index do |e_user,index|
user_info = e_user.user
- member = course.students.find_by_user_id(e_user.user_id)
- user_course = member.try(:course_group_name)
+ user_course = course.user_group_name(e_user.user_id)
user_obj_score = e_user.objective_score < 0.0 ? 0.0 : e_user.objective_score.round(1).to_s
user_suj_score = e_user.subjective_score < 0.0 ? 0.0 : e_user.subjective_score.round(1).to_s
user_score = e_user.score.present? ? e_user.score.round(1).to_s : 0.0
diff --git a/app/models/competition_stage_section.rb b/app/models/competition_stage_section.rb
index 027e7ec69..3c8794ad8 100644
--- a/app/models/competition_stage_section.rb
+++ b/app/models/competition_stage_section.rb
@@ -1,4 +1,5 @@
class CompetitionStageSection < ApplicationRecord
+ # score_source 0: 经验值, 1:预测准确率
belongs_to :competition
belongs_to :competition_stage
diff --git a/app/models/course.rb b/app/models/course.rb
index 6dd361733..01eed30db 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -130,6 +130,10 @@ class Course < ApplicationRecord
course_members.find_by(user_id: user_id, role: %i(STUDENT))
end
+ def user_group_name(user_id)
+ students.find_by(user_id: user_id)&.course_group_name
+ end
+
def teacher_group(user_id)
data =
diff --git a/app/models/weapp_settings/advert.rb b/app/models/weapp_settings/advert.rb
index 564e85565..993b1fd85 100644
--- a/app/models/weapp_settings/advert.rb
+++ b/app/models/weapp_settings/advert.rb
@@ -1,2 +1,3 @@
class WeappSettings::Advert < WeappSetting
+ default_scope { order(position: :asc) }
end
\ No newline at end of file
diff --git a/app/services/admins/competition_stage_create_service.rb b/app/services/admins/competition_stage_create_service.rb
new file mode 100644
index 000000000..d11276ef3
--- /dev/null
+++ b/app/services/admins/competition_stage_create_service.rb
@@ -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
\ No newline at end of file
diff --git a/app/services/admins/competition_stage_update_service.rb b/app/services/admins/competition_stage_update_service.rb
new file mode 100644
index 000000000..51bed5b8d
--- /dev/null
+++ b/app/services/admins/competition_stage_update_service.rb
@@ -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
\ No newline at end of file
diff --git a/app/services/admins/drag_weapp_advert_service.rb b/app/services/admins/drag_weapp_advert_service.rb
index b041c9d18..8bfb7c317 100644
--- a/app/services/admins/drag_weapp_advert_service.rb
+++ b/app/services/admins/drag_weapp_advert_service.rb
@@ -9,22 +9,22 @@ class Admins::DragWeappAdvertService < ApplicationService
def call
return if move.position + 1 == after&.position # 未移动
- carousels = WeappSettings::Advert.all
+ adverts = WeappSettings::Advert.all
ActiveRecord::Base.transaction do
if after.blank? || move.id == after.id # 移动至末尾
- total = carousels.count
+ total = adverts.count
- carousels.where('position > ?', move.position).update_all('position = position - 1')
+ adverts.where('position > ?', move.position).update_all('position = position - 1')
move.update!(position: total)
return
end
if move.position > after.position # 前移
- carousels.where('position >= ? AND position < ?', after.position, move.position).update_all('position = position + 1')
+ adverts.where('position >= ? AND position < ?', after.position, move.position).update_all('position = position + 1')
move.update!(position: after.position)
else # 后移
- carousels.where('position > ? AND position < ?', move.position, after.position).update_all('position = position - 1')
+ adverts.where('position > ? AND position < ?', move.position, after.position).update_all('position = position - 1')
move.update!(position: after.position - 1)
end
end
diff --git a/app/services/competitions/create_personal_team_service.rb b/app/services/competitions/create_personal_team_service.rb
index 82adec0cf..998a13880 100644
--- a/app/services/competitions/create_personal_team_service.rb
+++ b/app/services/competitions/create_personal_team_service.rb
@@ -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?
diff --git a/app/services/competitions/join_team_service.rb b/app/services/competitions/join_team_service.rb
index 7ec453013..daaca30d1 100644
--- a/app/services/competitions/join_team_service.rb
+++ b/app/services/competitions/join_team_service.rb
@@ -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?
diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb
index a8ee780e2..44e3da7ee 100644
--- a/app/views/admins/competition_settings/index.html.erb
+++ b/app/views/admins/competition_settings/index.html.erb
@@ -238,10 +238,8 @@
人
@@ -341,10 +339,10 @@
-
+
<% 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 %>
<% stage.competition_stage_sections.each_with_index do |section, j| %>
-
+
第<%= j + 1 %>阶段
有效时间:
- <%= 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: '有效开始时间' %>
~
- <%= 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: '有效结束时间' %>
任务完成要求:
-
+
/
-
+
(总任务)
成绩来源:
-
-
+
删除
@@ -403,72 +410,74 @@
<% end %>
+
<% end %>
<% end %>
<% else %>
+ <%= form_tag(admins_competition_competition_stages_path(competition_id: @competition.id), method: :post, class: 'stage-update-form new-stage-form flex-1', remote: true) do %>
+
+
+
tab标题
+
+
+
+
总排行榜占比:
+
+
+
%
+
+
删除
+
保存
+
+
+
+
第1阶段
+
+
+
有效时间:
+
+ <%= text_field_tag 'stage[][start_time]', '', autocomplete: 'off', class: 'section-start-time form-control', placeholder: '有效开始时间' %>
+
+
~
+
+ <%= text_field_tag 'stage[][end_time]', '', autocomplete: 'off', class: 'section-end-time form-control', placeholder: '有效结束时间' %>
+
+
任务完成要求:
+
+
+
+
/
+
+
+
+
(总任务)
+
成绩来源:
+
+
+
+
+
+
+
+
+
+
+ 删除
+
+
+
+
+ <% end %>
<% end %>
-
-
-
tab标题
-
-
-
-
总排行榜占比:
-
-
-
%
-
-
删除
-
保存
-
-
-
-
第1阶段
-
-
-
有效时间:
-
-
-
-
~
-
-
-
-
任务完成要求:
-
-
-
-
/
-
-
-
-
(总任务)
-
成绩来源:
-
-
-
-
-
-
-
-
-
-
- 删除
-
-
-
-
+
diff --git a/public/react/src/modules/competition/Registration.js b/public/react/src/modules/competition/Registration.js
index 0835fd88b..76fc40ba8 100644
--- a/public/react/src/modules/competition/Registration.js
+++ b/public/react/src/modules/competition/Registration.js
@@ -830,7 +830,7 @@ class Registration extends React.Component {
}
{
- type === 2 || type === 4 || type === 5 ?
+ type === 4 || type === 5 ?
(
count < 20 ?
);
}
const cpersondiv1 = (
-
+
{
cpersondiv1Items.length === 0 ?
@@ -1062,7 +1073,10 @@ class PersonModal extends Component {
var persondiv2Items = [];
if (member_ids) {
persondiv2Items = member_ids.map((item, index) =>
-
+
+
+
+
+
);
}
const persondiv2 = (
{/*this.state.loading2*/}
-
+
{
persondiv2Items.length === 0 ?
@@ -1205,16 +1219,16 @@ class PersonModal extends Component {
width="620px"
>
-
+ {/**/}
{/*队名*/}