Merge branch 'dev_race' into develop

dev_bj
p31729568 6 years ago
commit 0b41298aa0

@ -38,32 +38,34 @@ class CompetitionTeamsController < ApplicationController
end
def create
if params[:name]
# 判断用户是否已创建过战队
if @competition.competition_teams.where(:user_id => User.current.id).count > 0 && !User.current.is_teacher
@status = 1
else
invite_code = generate_team_code
teacher_id = User.current.user_extensions.identity == 0 ? User.current.id : params[:teacher]
new_team = CompetitionTeam.create(:competition_id => @competition.id, :name => params[:name],
:invite_code => invite_code, :user_id => User.current.id, :teacher_id => teacher_id)
new_team.team_members << TeamMember.new(:user_id => User.current.id, :role => 1, :competition_id => @competition.id, :is_teacher => User.current.user_extensions.identity == 0 ? 1 : 0)
if params[:member_ids]
params[:member_ids].each do |user_id|
new_team.team_members << TeamMember.new(:user_id => user_id, :role => 2, :competition_id => @competition.id)
end
end
if params[:teacher] && params[:teacher].strip != ""
new_team.team_members << TeamMember.new(:user_id => params[:teacher], :role => 2, :competition_id => @competition.id, :is_teacher => 1)
# 创建成功且配置了指导老师
@status = 0
elsif User.current.user_extensions.identity != 0
# 创建成功未配置指导老师
@status = 2
elsif User.current.user_extensions.identity == 0
@status = 0
end
# 判断用户是否已创建过战队
if @competition.competition_teams.where(:user_id => User.current.id).count > 0 && !User.current.is_teacher
@status, @message = -1, '您已创建过战队,不能重复创建'
return
end
if params[:name].blank?
@status, @message = -1, '战队名称不能为空'
return
end
is_teacher = User.current.user_extensions.identity == 0
return unless member_and_teacher_count_valid?(is_teacher)
ActiveRecord::Base.transaction do
invite_code = generate_team_code
new_team = CompetitionTeam.create(:competition_id => @competition.id, :name => params[:name],
:invite_code => invite_code, :user_id => User.current.id)
new_team.team_members.create!(user_id: User.current.id, role: 1, competition_id: @competition.id, is_teacher: User.current.user_extensions.identity == 0 ? 1 : 0)
params[:member_ids].try(:each) do |user_id|
next if user_id.to_i == User.current.id
new_team.team_members.create!(user_id: user_id, role: 2, competition_id: @competition.id)
end
params[:teacher_ids].try(:each) do |user_id|
next if user_id.to_i == User.current.id
new_team.team_members.create!(user_id: user_id, role: 3, competition_id: @competition.id, is_teacher: 1)
end
end
end
@ -89,79 +91,80 @@ class CompetitionTeamsController < ApplicationController
end
def update
unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now
if params[:name]
teacher_id = User.current.user_extensions.identity == 0 ? User.current.id : params[:teacher]
@team.update_attributes(:name => params[:name], :teacher_id => teacher_id)
@team.team_members.update_all(:is_teacher => 0)
if @team.user.user_extensions.identity == 0
@team.team_members.where(:user_id => @team.user_id).update_all(:is_teacher => 1)
end
is_teacher = @team.user.user_extensions.identity == 0
return unless member_and_teacher_count_valid?(is_teacher)
ActiveRecord::Base.transaction do
unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now
@team.update_attributes(name: params[:name]) if params[:name].present?
team_member_ids = @team.team_members.where(:role => 2, :is_teacher => 0).map(&:user_id)
new_member_ids = (params[:member_ids] || []).collect(&:to_i)
team_member_ids = @team.team_members.where(role: 2, is_teacher: 0).pluck(:user_id)
new_member_ids = (params[:member_ids].presence || []).map(&:to_i)
new_member_ids << @team.user_id unless is_teacher
# 删除的成员
delete_member_ids = team_member_ids - new_member_ids
@team.team_members.where(:role => 2, :user_id => delete_member_ids).destroy_all
@team.team_members.where(role: 2, user_id: delete_member_ids).delete_all
# 新增加的成员
(new_member_ids - team_member_ids).each do |user_id|
@team.team_members << TeamMember.new(:user_id => user_id, :role => 2, :competition_id => @competition.id)
next if user_id.to_i == @team.user_id
@team.team_members.create!(user_id: user_id, role: 2, competition_id: @competition.id)
end
end
end
# 判断之前是否已存在指导老师,不存在则创建 否则更新
if params[:teacher] && params[:teacher].strip != ""
o_teacher = @team.team_members.where(:is_teacher => 1).first
unless o_teacher.present? && o_teacher.user_id == params[:teacher].to_i
if o_teacher.present?
o_teacher.update_attributes(:user_id => params[:teacher])
else
teacher = @team.team_members.where(:user_id => params[:teacher]).first
if teacher.present?
teacher.update_column("is_teacher", 1)
else
@team.team_members << TeamMember.new(:user_id => params[:teacher], :role => 2, :competition_id => @competition.id, :is_teacher => 1)
end
end
teacher_ids = @team.teachers.pluck(:user_id)
new_teacher_ids = (params[:teacher_ids].presence || []).map(&:to_i)
new_teacher_ids << @team.user_id if is_teacher
# 删除的老师
delete_teacher_ids = teacher_ids - new_teacher_ids
@team.team_members.where(role: 3, user_id: delete_teacher_ids).delete_all
# 新增加的老师
(new_teacher_ids - teacher_ids).each do |user_id|
next if user_id.to_i == @team.user_id
@team.team_members.create!(user_id: user_id, role: 3, competition_id: @competition.id, is_teacher: true)
end
@team.update_attributes(:teacher_id => params[:teacher])
elsif @team.user.user_extensions.identity != 0
@team.update_attributes(:teacher_id => nil)
@team.team_members.where(:is_teacher => 1).destroy_all
end
end
# @status:提示语标志0加入成功1邀请码错误2已经加入了其他队, 3超过人数限制4已有指导老师5只有学生和老师身份的用户才能加入战队
def join_team
team = @competition.competition_teams.where(:invite_code => params[:code]).first
if team.present?
if TeamMember.where(:user_id => User.current.id, :competition_team_id => @competition.competition_teams.map(&:id), :is_teacher => 0).count > 0
@status = 2
else
# 老师身份加入战队判断是否已有指导老师
if User.current.user_extensions.identity == 0
if team.teacher_id.present?
@status = 4
else
@status = 0
team.update_attributes(:teacher_id => User.current.id)
team.team_members << TeamMember.new(:user_id => User.current.id, :role => 2, :competition_id => @competition.id, :is_teacher => 1)
end
elsif User.current.user_extensions.identity == 1
if team.team_members.count < @competition.max_num.to_i
team.team_members << TeamMember.new(:user_id => User.current.id, :role => 2, :competition_id => @competition.id)
@status = 0
else
@status = 3
end
else
@status = 5
end
team = @competition.competition_teams.where(invite_code: params[:code]).first
if team.blank?
@status, @message = -1, '战队邀请码错误'
return
end
if TeamMember.where(:user_id => User.current.id, :competition_team_id => @competition.competition_teams.map(&:id), :is_teacher => 0).count > 0
@status, @message = -1, '您已加入战队,不能重复加'
return
end
if team.team_members.where(user_id: User.current.id).exists?
@status, @message = -1, '您已加入该战队'
return
end
# 老师身份加入战队
if User.current.user_extensions.identity == 0
teacher_staff = @competition.where(category: 'teacher').first
if teacher_staff.blank?
@status, @message = -1, '该竞赛不能配备导师'
return
end
if team.teachers.count + 1 > teacher_staff.maximum
@status, @message = -1, '该战队导师人数已满'
return
end
team.team_members.create!(user_id: User.current.id, role: 3, competition_id: @competition.id, is_teacher: true)
else
@status = 1
max_member_count = @competition.where('category != "teacher"').sum(:maximum)
if team.members.count + 1 > max_member_count
@status, @message = -1, '该战队成员人数已满'
return
end
team.team_members.create!(user_id: User.current.id, role: 2, competition_id: @competition.id)
end
end
@ -169,9 +172,6 @@ class CompetitionTeamsController < ApplicationController
def exit_team
team_member = @team.team_members.where(:user_id => User.current.id).first
if team_member.present?
if team_member.is_teacher
@team.update_attributes(:teacher_id => nil)
end
if team_member.user_id != @team.user_id
team_member.destroy
@status = 1
@ -214,4 +214,33 @@ class CompetitionTeamsController < ApplicationController
rescue ActiveRecord::RecordNotFound
render_404
end
def member_and_teacher_count_valid?(is_teacher)
teacher_staff = @competition.competition_staffs.where(category: 'teacher').first
teacher_count = params[:teacher_ids].try(:size) || 0
teacher_count += 1 if is_teacher
# 检查老师数量
if teacher_staff.blank? && teacher_count > 0
@status, @message = -1, '该竞赛不能配备导师'
return false
elsif teacher_staff.present? && (teacher_staff.minimum > teacher_count || teacher_staff.maximum < teacher_count)
@status = -1
@message = teacher_staff.maximum == teacher_staff.maximum ? "导师数量应为#{teacher_staff.minimum}" : "导师数量应为#{teacher_staff.minimum}-#{teacher_staff.maximum}"
return false
end
member_relations = @competition.competition_staffs.where('category != "teacher"')
min_member_count = member_relations.sum(:minimum)
max_member_count = member_relations.sum(:maximum)
member_count = params[:member_ids].try(:size) || 0
member_count += 1 unless is_teacher
# 检查成员数据
if min_member_count > member_count || member_count > max_member_count
@status = -1
@message = min_member_count == max_member_count ? "成员数量应为#{max_member_count}" : "成员数量应为#{min_member_count}-#{max_member_count}"
return false
end
true
end
end

@ -110,7 +110,8 @@ class CompetitionsController < ApplicationController
@team_members_count = TeamMember.where(:competition_team_id => @teams.pluck(:id)).count
@is_enroll = CompetitionTeam.where(:id => TeamMember.where(:user_id => @user, :competition_team_id => @competition.competition_teams.map(&:id)).pluck(:competition_team_id)).reorder("created_at desc")
@show_notice = (@competition.identifier == "gcc-dev-2018" || @competition.identifier == "gcc-annotation-2018") && @competition.competition_teams.where(:user_id => User.current.id, :teacher_id => nil).count > 0
@show_notice = (@competition.identifier == "gcc-dev-2018" || @competition.identifier == "gcc-annotation-2018") &&
@competition.competition_teams.joins(:team_members).where(:user_id => User.current.id).group('competition_teams.id').sum('IF(team_members.is_teacher=1, 1, 0)').values.any?(&:zero?)
@teams = paginateHelper @teams, 50
respond_to do |format|
format.js
@ -458,41 +459,51 @@ class CompetitionsController < ApplicationController
def competition_setting
# @competition = Competition.find params[:id]
if params[:md_name]
md_modules = @competition.competition_modules.where(:md_edit => true)
md_modules.destroy_all if md_modules
params[:md_name].each_with_index do |name, index|
hidden = params[:md_checked][index].to_i == 0 ? 1 : 0
cm = CompetitionModule.create(:competition_id => @competition.id,:name => name, :position => params[:md_position][index], :hidden => hidden, :md_edit => true)
# 创建md_contents
CompetitionModuleMdContent.create(:competition_module_id => cm.id)
ActiveRecord::Base.transaction do
if params[:md_name]
md_modules = @competition.competition_modules.where(:md_edit => true)
md_modules.destroy_all if md_modules
params[:md_name].each_with_index do |name, index|
hidden = params[:md_checked][index].to_i == 0 ? 1 : 0
cm = CompetitionModule.create(:competition_id => @competition.id,:name => name, :position => params[:md_position][index], :hidden => hidden, :md_edit => true)
# 创建md_contents
CompetitionModuleMdContent.create(:competition_module_id => cm.id)
end
end
end
if params[:competition_module]
@competition.competition_modules.where(:id => params[:competition_module], :md_edit => false).update_all(:hidden => 0)
none_modules = @competition.competition_modules.where("name != '首页' and md_edit = false").map(&:id).join(",").split(",") - params[:competition_module]
@competition.competition_modules.where(:id => none_modules).update_all(:hidden => 1)
end
if params[:name]
@competition.competition_modules.where("name not in ('首页', '报名', '通知公告', '排行榜', '资料下载') and md_edit = false").each_with_index do |mod, index|
mod.update_attribute("name", params[:name][index])
if params[:competition_module]
@competition.competition_modules.where(:id => params[:competition_module], :md_edit => false).update_all(:hidden => 0)
none_modules = @competition.competition_modules.where("name != '首页' and md_edit = false").map(&:id).join(",").split(",") - params[:competition_module]
@competition.competition_modules.where(:id => none_modules).update_all(:hidden => 1)
end
end
if params[:url]
@competition.competition_modules.where("name not in ('首页', '报名', '通知公告', '排行榜') and md_edit = false").each_with_index do |mod, index|
mod.update_attribute("url", params[:url][index])
if params[:name]
@competition.competition_modules.where("name not in ('首页', '报名', '通知公告', '排行榜', '资料下载') and md_edit = false").each_with_index do |mod, index|
mod.update_attribute("name", params[:name][index])
end
end
end
if params[:position]
@competition.competition_modules.where(:md_edit => false).each_with_index do |mod, index|
mod.update_attribute("position", params[:position][index])
if params[:url]
@competition.competition_modules.where("name not in ('首页', '报名', '通知公告', '排行榜') and md_edit = false").each_with_index do |mod, index|
mod.update_attribute("url", params[:url][index])
end
end
end
@competition.update_attributes(:identifier => params[:identifier], :min_num => params[:min_num], :max_num => params[:max_num], :enroll_end_time => params[:enroll_end_time])
if params[:new_name]
params[:new_name].each_with_index do |new_module, index|
@competition.competition_modules << CompetitionModule.new(:name => new_module, :position => params[:new_position][index], :hidden => 0, :url => params[:new_url][index])
if params[:position]
@competition.competition_modules.where(:md_edit => false).each_with_index do |mod, index|
mod.update_attribute("position", params[:position][index])
end
end
@competition.update_attributes(:identifier => params[:identifier], :enroll_end_time => params[:enroll_end_time])
if params[:competition_staffs].present?
@competition.competition_staffs.delete_all
params[:competition_staffs].each_with_index do |staff_params, index|
@competition.competition_staffs.create(staff_params.merge(position: index + 1))
end
end
if params[:new_name]
params[:new_name].each_with_index do |new_module, index|
@competition.competition_modules << CompetitionModule.new(:name => new_module, :position => params[:new_position][index], :hidden => 0, :url => params[:new_url][index])
end
end
end
end

@ -13,6 +13,7 @@ class Competition < ActiveRecord::Base
has_many :chart_rules, :dependent => :destroy
has_many :competition_scores, :dependent => :destroy
has_many :competition_text_configs, :dependent => :destroy
has_many :competition_staffs, dependent: :destroy
acts_as_attachable
after_create :create_competition_modules

@ -0,0 +1,22 @@
class CompetitionStaff < ActiveRecord::Base
default_scope order: 'position asc'
attr_accessible :minimum, :maximum, :category, :position
belongs_to :competition
validates :position, numericality: { only_integer: true }
validates :minimum, numericality: { only_integer: true, greater_than: 0 }
validates :maximum, numericality: { only_integer: true, greater_than_or_equal_to: lambda { |obj| obj.minimum } }
validates :category, presence: true, inclusion: { in: %w(all teacher student profession) }
def category_text
I18n.t("competition_staff.category.#{category}", locale: 'zh')
end
def self.category_options
%w(all teacher student profession).map do |category|
[I18n.t("competition_staff.category.#{category}", locale: 'zh'), category]
end
end
end

@ -2,7 +2,10 @@
class CompetitionTeam < ActiveRecord::Base
belongs_to :user
belongs_to :competition
has_many :team_members, :dependent => :destroy
has_many :members, conditions: 'is_teacher = 0', class_name: 'TeamMember'
has_many :teachers, conditions: 'is_teacher = 1', class_name: 'TeamMember'
has_many :competition_scores, :dependent => :destroy
# team_type 0组队 1个人
# attr_accessible :invite_code, :name, :team_type

@ -3,5 +3,5 @@ class TeamMember < ActiveRecord::Base
belongs_to :competition
belongs_to :user
# role 1创建者 2成员 3指导老师
# attr_accessible :role
attr_accessible :role, :user_id, :competition_id, :is_teacher
end

@ -1,7 +1,12 @@
<% none_edit = @team.try(:id).present? && @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %>
<%= labelled_form_for @team, :html => {:id => 'competition_team_form', :multipart => true, :remote => true} do |f| %>
<input type="hidden" id="max_num" value="<%= @competition.max_num %>">
<input type="hidden" id="min_num" value="<%= @competition.min_num %>">
<% teacher_staff = @competition.competition_staffs.where(category: 'teacher').first %>
<% min_member_staff = @competition.competition_staffs.where('category != "teacher"').sum(:minimum) %>
<% max_member_staff = @competition.competition_staffs.where('category != "teacher"').sum(:maximum) %>
<input type="hidden" id="teacher_maximum" value="<%= teacher_staff.try(:maximum) || 0 %>">
<input type="hidden" id="teacher_minimum" value="<%= teacher_staff.try(:minimum) || 0 %>">
<input type="hidden" id="member_maximum" value="<%= max_member_staff || 0 %>">
<input type="hidden" id="member_minimum" value="<%= min_member_staff || 0 %>">
<input type="hidden" id="team_id" value="<%= @team.try(:id) %>">
<input type="hidden" name="com_id" value="<%= @competition.id %>">
@ -15,7 +20,8 @@
</div>
<p style="line-height: 27px;height: 27px"><span id="team_name_notice" class="color-orange-tip ml73 none"></span></p>
<div class="df pl20 pr20">
<% if teacher_staff.present? %>
<div class="df pl20 pr20">
<label class="ml10 mt3">导师:</label>
<div class="flex1 pr search-new">
<input type="text" class="input-100-35 fl" <%= @team_user.user_extensions.identity == 0 ? "disabled" : "" %> autocomplete="off" placeholder="请您输入老师姓名进行搜索" id="teacher_search_input"
@ -31,73 +37,82 @@
<a class="fl ml20 white-btn edu-blueback-btn mt4" onclick="add_teacher()">添加导师</a>
</div>
<p style="line-height: 27px;height: 27px"><span id="teacher_notice" class="color-orange-tip ml73 none"></span></p>
<div class="df pl20 pr20">
<label class="mt3"><span class="mr3 color-orange">*</span>队员:</label>
<div class="flex1 search-new">
<input type="text" class="search-new-input fl" <%= none_edit ? "disabled" : "" %> autocomplete="off" style="width: 100%" placeholder="请您输入想要添加的成员搜索" id="user_search_input">
<span class="search-span" style="background: #fff;"></span>
<input type="hidden" id="member_id" data-select="0">
<input type="hidden" id="member_name">
<input type="hidden" id="member_school">
<input type="hidden" id="member_student_id">
<a class="fl searchicon" style="top:0px;" onclick="search_non_member_user()"><i class="iconfont icon-sousuo fl"></i></a>
<ul class="pointerTeacher none" id="pointerStudent">
</ul>
<% end %>
<% if min_member_staff > 0 %>
<div class="df pl20 pr20">
<label class="mt3"><span class="mr3 color-orange">*</span>队员:</label>
<div class="flex1 search-new">
<input type="text" class="search-new-input fl" <%= none_edit ? "disabled" : "" %> autocomplete="off" style="width: 100%" placeholder="请您输入想要添加的成员搜索" id="user_search_input">
<span class="search-span" style="background: #fff;"></span>
<input type="hidden" id="member_id" data-select="0">
<input type="hidden" id="member_name">
<input type="hidden" id="member_school">
<input type="hidden" id="member_student_id">
<a class="fl searchicon" style="top:0px;" onclick="search_non_member_user()"><i class="iconfont icon-sousuo fl"></i></a>
<ul class="pointerTeacher none" id="pointerStudent">
</ul>
</div>
<a class="fl ml20 white-btn edu-blueback-btn mt4" onclick="<%= none_edit ? '' : 'add_member()' %>">添加成员</a>
</div>
<a class="fl ml20 white-btn edu-blueback-btn mt4" onclick="<%= none_edit ? '' : 'add_member()' %>">添加成员</a>
</div>
<p style="line-height: 27px;height: 27px"><span id="member_notice" class="color-orange-tip ml73 none"></span></p>
<% end %>
<div class="bor-grey-e ml20 mr20 mt5" id="member_block">
<p class="pt10 pb10 clearfix bor-bottom-greyE personListLine">
<span class="t-c-1">姓名</span>
<span class="t-c-2">角色</span>
<span class="t-c-3">单位</span>
<span class="t-c-4">其他</span>
<span class="t-c-5">操作</span>
<div class="bor-grey-e ml20 mr20 mt5" id="member_block">
<p class="pt10 pb10 clearfix bor-bottom-greyE personListLine">
<span class="t-c-1">姓名</span>
<span class="t-c-2">角色</span>
<span class="t-c-3">单位</span>
<span class="t-c-4">其他</span>
<span class="t-c-5">操作</span>
</p>
<% if @team.try(:id).present? %>
<% creator_teacher = @team.user.user_extensions.identity == 0 %>
<p class="personListLine clearfix pt5 pb5 personListMember <%= creator_teacher ? 'team-teacher' : 'team-member' %>" id="create_li">
<span class="t-c-1"><%= @team.user.show_name %></span>
<span class="t-c-2"><%= @team.user.user_extensions.identity == 0 ? "导师/创建者" : "创建者" %></span>
<span class="t-c-3"><%= @team.user.school_name %></span>
<span class="t-c-4"><%= @team.user.user_extensions.identity == 0 ? "职称:#{@team.user.identity}" : "学号:#{@team.user.user_extensions.student_id.present? ? @team.user.user_extensions.student_id : "--"}" %></span>
<span class="t-c-5"></span>
</p>
<% if @team.try(:id).present? %>
<p class="personListLine clearfix pt5 pb5 personListMember" id="create_li">
<span class="t-c-1"><%= @team.user.show_name %></span>
<span class="t-c-2"><%= @team.user.user_extensions.identity == 0 ? "导师/创建者" : "创建者" %></span>
<span class="t-c-3"><%= @team.user.school_name %></span>
<span class="t-c-4"><%= @team.user.user_extensions.identity == 0 ? "职称:#{@team.user.identity}" : "学号:#{@team.user.user_extensions.student_id.present? ? @team.user.user_extensions.student_id : "--"}" %></span>
<span class="t-c-5"></span>
<% @team.teachers.includes(user: :user_extensions).each do |teacher| %>
<% next if teacher.user_id == @team.user_id %>
<p class="personListLine clearfix pt5 pb5 personListMember team-teacher team-teacher-<%= teacher.user.id %>">
<input type="hidden" name="teacher_ids[]" value="<%= teacher.user.id %>">
<span class="t-c-1"><%= teacher.user.show_name %></span>
<span class="t-c-2">导师</span>
<span class="t-c-3"><%= teacher.user.school_name %></span>
<span class="t-c-4">职称:<%= teacher.user.identity %></span>
<span class="t-c-5"><span class="delete_member" data-tip-down="删除"><i class="iconfont icon-guanbi font-14 color-grey-c"></i></span></span>
</p>
<% if @team.teacher.present? && @team.teacher != @team.user %>
<p class="personListLine clearfix pt5 pb5 personListMember">
<input type="hidden" name="teacher" value="<%= @team.teacher_id %>">
<span class="t-c-1"><%= @team.teacher.show_name %></span>
<span class="t-c-2">导师</span>
<span class="t-c-3"><%= @team.teacher.school_name %></span>
<span class="t-c-4">职称:<%= @team.teacher.identity %></span>
<span class="t-c-5"><span class="delete_member" data-tip-down="删除"><i class="iconfont icon-guanbi font-14 color-grey-c"></i></span></span>
</p>
<% end %>
<% @team.team_members.where(:role => 2, :is_teacher => 0).each do |team_user| %>
<p class="personListLine clearfix pt3 pb3 personListMember">
<input type="hidden" name="member_ids[]" value="<%= team_user.user_id %>">
<span class="t-c-1"><%= team_user.user.show_name %></span>
<span class="t-c-2">成员</span>
<span class="t-c-3"><%= team_user.user.school_name %></span>
<span class="t-c-4">学号:<%= team_user.user.user_extensions.student_id.present? ? team_user.user.user_extensions.student_id : "--" %></span>
<span class="t-c-5">
<% unless none_edit %>
<span class="delete_member" data-tip-down="删除"><i class="iconfont icon-guanbi font-14 color-grey-c"></i></span>
<% end %>
</span>
</p>
<% end %>
<% else %>
<p class="personListLine clearfix pt5 pb5 personListMember" id="create_li">
<span class="t-c-1"><%= @team_user.show_name %></span>
<span class="t-c-2"><%= @team_user.user_extensions.identity == 0 ? "导师/创建者" : "创建者" %></span>
<span class="t-c-3"><%= @team_user.school_name %></span>
<span class="t-c-4"><%= @team_user.user_extensions.identity == 0 ? "职称:#{@team_user.identity}" : "学号:#{@team_user.user_extensions.student_id.present? ? @team_user.user_extensions.student_id : "--"}" %></span>
<span class="t-c-5"></span>
<% end %>
<% @team.members.includes(user: :user_extensions).each do |team_user| %>
<% next if team_user.user_id == @team.user_id %>
<p class="personListLine clearfix pt3 pb3 personListMember team-member">
<input type="hidden" name="member_ids[]" value="<%= team_user.user_id %>">
<span class="t-c-1"><%= team_user.user.show_name %></span>
<span class="t-c-2">成员</span>
<span class="t-c-3"><%= team_user.user.school_name %></span>
<span class="t-c-4">学号:<%= team_user.user.user_extensions.student_id.present? ? team_user.user.user_extensions.student_id : "--" %></span>
<span class="t-c-5">
<% unless none_edit %>
<span class="delete_member" data-tip-down="删除"><i class="iconfont icon-guanbi font-14 color-grey-c"></i></span>
<% end %>
</span>
</p>
<% end %>
</div>
<% else %>
<% creator_teacher = @team_user.user_extensions.identity == 0 %>
<p class="personListLine clearfix pt5 pb5 personListMember <%= creator_teacher ? 'team-teacher' : 'team-member' %>" id="create_li">
<span class="t-c-1"><%= @team_user.show_name %></span>
<span class="t-c-2"><%= @team_user.user_extensions.identity == 0 ? "导师/创建者" : "创建者" %></span>
<span class="t-c-3"><%= @team_user.school_name %></span>
<span class="t-c-4"><%= @team_user.user_extensions.identity == 0 ? "职称:#{@team_user.identity}" : "学号:#{@team_user.user_extensions.student_id.present? ? @team_user.user_extensions.student_id : "--"}" %></span>
<span class="t-c-5"></span>
</p>
<% end %>
</div>
<p class="color-orange none ml20" id="competition_team_form_notice"></p>
<div class="clearfix edu-txt-center mt20">
@ -111,69 +126,81 @@
<script>
function submit_competition_team_form(){
if($("input[name='name']").val().trim() == ""){
$("#team_name_notice").html("请输入战队名").show();
} else{
var max_num = parseInt($("#max_num").val());
var min_num = parseInt($("#min_num").val());
if($("#member_block .personListMember").length > max_num || $("#member_block .personListMember").length < min_num){
$("#competition_team_form_notice").html("战队成员需为"+min_num+"-"+max_num+"人").show();
} else{
$("#team_name_notice").hide();
$("#competition_team_form_notice").hide();
$("#competition_team_form").submit();
hideModal();
}
$("#team_name_notice").html("请输入战队名").show();
return;
}
var teacherMaximum = parseInt($("#teacher_maximum").val());
var teacherMinimum = parseInt($("#teacher_minimum").val());
var memberMaximum = parseInt($("#member_maximum").val());
var memberMinimum = parseInt($("#member_minimum").val());
var teacherCount = $("#member_block .personListMember.team-teacher").length;
if (teacherMaximum != 0 && teacherCount > teacherMaximum || teacherMinimum != 0 && teacherCount < teacherMinimum) {
$("#competition_team_form_notice").html("战队导师需为"+teacherMinimum+"-"+teacherMaximum+"人,现为" + teacherCount + '人').show();
return;
}
var memberCount = $("#member_block .personListMember.team-member").length;
if (memberMaximum != 0 && memberCount > memberMaximum || memberMinimum != 0 && memberCount < memberMinimum) {
$("#competition_team_form_notice").html("战队成员需为"+memberMinimum+"-"+memberMaximum+"人,现为" + memberCount + '人').show();
return;
}
$("#team_name_notice").hide();
$("#competition_team_form_notice").hide();
$("#competition_team_form").submit();
hideModal();
}
function add_teacher(){
if($("#teacher_search_input").attr("disabled") != "disabled"){
if($("#teacher_name").val() == "" || $("#teacher_name").val() != $("#teacher_search_input").val()){
$("#teacher_id").attr("data-select", 0);
$("#teacher_notice").html("指导老师需从搜索下拉列表中选择").show();
} else{
if($("#teacher_id").attr("data-select") == 1){
$("#teacher_notice").html("该老师已添加").show();
} else{
$("#teacher_notice").hide();
$("input[name='teacher']").parent().remove();
var li = '<p class="personListLine clearfix pt3 pb3 personListMember">' +
' <input type="hidden" name="teacher" value="'+$("#teacher_id").val()+'">' +
' <span class="t-c-1">'+$("#teacher_name").val()+'</span>' +
' <span class="t-c-2">导师</span>' +
' <span class="t-c-3">'+$("#teacher_school").val()+'</span>' +
' <span class="t-c-4">职称:'+$("#teacher_title").val()+'</span>' +
' <span class="t-c-5"><span class="delete_member" data-tip-down="删除"><i class="iconfont icon-guanbi font-14 color-grey-c"></i></span></span>' +
' </p>';
$(li).insertAfter($("#create_li"));
$("#teacher_id").attr("data-select", 1);
}
}
if($("#teacher_search_input").attr("disabled") != "disabled"){
if($("#teacher_name").val() == "" || $("#teacher_name").val() != $("#teacher_search_input").val()){
$("#teacher_id").attr("data-select", 0);
$("#teacher_notice").html("指导老师需从搜索下拉列表中选择").show();
return;
}
if($("#teacher_id").attr("data-select") == 1 || $(".team-teacher.team-teacher-" + $("#teacher_id").val()).length != 0){
$("#teacher_notice").html("该老师已添加").show();
return;
}
$("#teacher_notice").hide();
var li = '<p class="personListLine clearfix pt3 pb3 personListMember team-teacher team-teacher-' + $("#teacher_id").val() + '">' +
' <input type="hidden" name="teacher_ids[]" value="'+$("#teacher_id").val()+'">' +
' <span class="t-c-1">'+$("#teacher_name").val()+'</span>' +
' <span class="t-c-2">导师</span>' +
' <span class="t-c-3">'+$("#teacher_school").val()+'</span>' +
' <span class="t-c-4">职称:'+$("#teacher_title").val()+'</span>' +
' <span class="t-c-5"><span class="delete_member" data-tip-down="删除"><i class="iconfont icon-guanbi font-14 color-grey-c"></i></span></span>' +
' </p>';
$(li).insertAfter($("#create_li"));
$("#teacher_id").attr("data-select", 1);
}
}
function add_member(){
$("#member_notice").hide();
if($("#member_name").val() == "" || $("#member_name").val() != $("#user_search_input").val()){
$("#member_id").attr("data-select", 0);
$("#member_notice").html("队员需从搜索下拉列表中选择").show();
} else{
if($("#member_id").attr("data-select") == 1){
$("#member_notice").html("该队员已添加").show();
} else{
$("#member_notice").hide();
var li = '<p class="personListLine clearfix pt3 pb3 personListMember">' +
' <input type="hidden" name="member_ids[]" value="'+$("#member_id").val()+'">' +
' <span class="t-c-1">'+$("#member_name").val()+'</span>' +
' <span class="t-c-2">成员</span>' +
' <span class="t-c-3">'+$("#member_school").val()+'</span>' +
' <span class="t-c-4">学号:'+$("#member_student_id").val()+'</span>' +
' <span class="t-c-5"><span class="delete_member" data-tip-down="删除"><i class="iconfont icon-guanbi font-14 color-grey-c"></i></span></span>' +
' </p>';
$("#member_block").append(li);
$("#member_id").attr("data-select", 1);
}
}
$("#member_notice").hide();
if($("#member_name").val() == "" || $("#member_name").val() != $("#user_search_input").val()){
$("#member_id").attr("data-select", 0);
$("#member_notice").html("队员需从搜索下拉列表中选择").show();
return;
}
if($("#member_id").attr("data-select") == 1 || $(".team-member.team-member-" + $("#member_id").val()).length != 0){
$("#member_notice").html("该队员已添加").show();
return;
}
$("#member_notice").hide();
var li = '<p class="personListLine clearfix pt3 pb3 personListMember team-member team-member-' + $("#member_id").val() + '">' +
' <input type="hidden" name="member_ids[]" value="'+$("#member_id").val()+'">' +
' <span class="t-c-1">'+$("#member_name").val()+'</span>' +
' <span class="t-c-2">成员</span>' +
' <span class="t-c-3">'+$("#member_school").val()+'</span>' +
' <span class="t-c-4">学号:'+$("#member_student_id").val()+'</span>' +
' <span class="t-c-5"><span class="delete_member" data-tip-down="删除"><i class="iconfont icon-guanbi font-14 color-grey-c"></i></span></span>' +
' </p>';
$("#member_block").append(li);
$("#member_id").attr("data-select", 1);
}
$("#user_search_input").on("keydown", function(event){

@ -1,4 +1,4 @@
<p class="pl30 color-orange-tip mt5 pb5 bor-bottom-greyE">只能指定1名指导老师,允许修改</p>
<p class="pl30 color-orange-tip mt5 pb5 bor-bottom-greyE">请选择指导老师,允许修改</p>
<% @teachers.each do |teacher| %>
<li class="clearfix">
<input type="hidden" value="<%= teacher.id %>">

@ -1,7 +1,5 @@
<% if @status == 0 %>
<% if @status == -1 %>
notice_box("<%= @message %>");
<% else %>
notice_box_redirect("<%= enroll_competition_path(@competition) %>", "创建成功");
<% elsif @status == 2 %>
notice_box_redirect("<%= enroll_competition_path(@competition) %>", "创建成功,请尽快填写指导老师");
<% elsif @status == 1 %>
notice_box("您已创建过战队,不能重复创建");
<% end %>

@ -1,13 +1,5 @@
<% if @status == 0 %>
notice_box_redirect("<%= enroll_competition_path(@competition) %>", "加入成功");
<% elsif @status == 1 %>
notice_box("战队邀请码错误");
<% elsif @status == 2 %>
notice_box("您已加入战队,不能重复加");
<% elsif @status == 3 %>
notice_box("战队成员已满,无法加入");
<% elsif @status == 4 %>
notice_box("战队已有指导老师,无法加入");
<% elsif @status == 5 %>
notice_box("非老师/学生身份无法加入战队");
<% if @status != -1 %>
notice_box_redirect("<%= enroll_competition_path(@competition) %>", "加入成功");
<% else %>
notice_box('<%= @message %>')
<% end %>

@ -1 +1,5 @@
<% if @status != -1 %>
notice_box_redirect("<%= enroll_competition_path(@competition) %>", "更新成功");
<% else %>
notice_box("<%= @message %>")
<% end %>

@ -1,65 +1,33 @@
<p class="second_1" style="background: url('/images/educoder/competition/qg/qg_two_1.png') no-repeat top center;"></p>
<p class="second_2" style="background: url('/images/educoder/competition/qg/qg_two_2.png') no-repeat top center;"></p>
<div class="second_3" style="background: url('/images/educoder/competition/qg/qg_two_3.png') no-repeat top center;">
<div class="enter_panel">
<ul class="mb40">
<p class="mb30 font-22 enter_title"><span class="mr20 font-bd">第一阶段</span><span>2019-6-25 09:00-2019-7-10 24:00 </span></p>
<li class="inline enter_btn">
<a href="javascript:void(0)" class="active">Java入口</a>
<a href="javascript:void(0)" class="active">C/C++入口</a>
<a href="javascript:void(0)">Python入口</a>
</li>
</ul>
<ul>
<p class="mb30 font-22 enter_title"><span class="mr20 font-bd">第一阶段</span><span>2019-6-25 09:00-2019-7-10 24:00 </span></p>
<li class="inline enter_btn">
<a href="javascript:void(0)">Java入口</a>
<a href="javascript:void(0)">C/C++入口</a>
<a href="javascript:void(0)">Python入口</a>
</li>
</ul>
<% index = 0 %>
<div class="second_1" style="background: url(<%= named_attachment_path(@images.first, @images.first.try(:filename)) %>) no-repeat top center;"></div>
<% index += 1 %>
<div class="second_2" style="background: url(<%= named_attachment_path(@images[index], @images[index].try(:filename)) %>) no-repeat top center;"></div>
<% index += 1 %>
<% @competition.competition_stages.each_with_index do |stage, i| %>
<div class="second_3" style="background: url(<%= named_attachment_path(@images[index], @images[index].try(:filename)) %>) no-repeat top center;">
<div class="enter_panel">
<% stage.competition_stage_sections.each do |section| %>
<ul class="mb40">
<p class="mb30 font-22 enter_title">
<span class="mr20 font-bd"><%= section.name %></span>
<span><%= format_time section.start_time %> ~ <%= com_end_time section.end_time %></span>
</p>
<li class="inline enter_btn">
<% "@urls[i][j][k]表示: 第i个比赛的第j个对象的第k个url入口" %>
<% section.competition_entries.each_with_index do |entry| %>
<a class="li-1" href="<%= Time.now > section.start_time ? "#{entry.url}" : "javascript:void(0);" %>" <%= Time.now > section.start_time ? 'target="_blank"' : "" %> ><%= entry.name %></a>
<% end %>
</li>
</ul>
<% end %>
</div>
</div>
</div>
<div class="second_4" style="background: url('/images/educoder/competition/qg/qg_two_4.png') no-repeat top center;">
<div class="enter_panel">
<ul class="mb40">
<p class="mb30 font-22 enter_title"><span class="mr20 font-bd">第一阶段</span><span>2019-6-25 09:00-2019-7-10 24:00 </span></p>
<li class="inline enter_btn">
<a href="javascript:void(0)" class="active">Java入口</a>
<a href="javascript:void(0)" class="active">C/C++入口</a>
<a href="javascript:void(0)">Python入口</a>
</li>
</ul>
<ul>
<p class="mb30 font-22 enter_title"><span class="mr20 font-bd">第一阶段</span><span>2019-6-25 09:00-2019-7-10 24:00 </span></p>
<li class="inline enter_btn">
<a href="javascript:void(0)">Java入口</a>
<a href="javascript:void(0)">C/C++入口</a>
<a href="javascript:void(0)">Python入口</a>
</li>
</ul>
</div>
</div>
<div class="second_5" style="background: url('/images/educoder/competition/qg/qg_two_5.png') no-repeat top center;">
<div class="enter_panel">
<ul class="mb40">
<p class="mb30 font-22 enter_title"><span class="mr20 font-bd">第一阶段</span><span>2019-6-25 09:00-2019-7-10 24:00 </span></p>
<li class="inline enter_btn">
<a href="javascript:void(0)" class="active">Java入口</a>
<a href="javascript:void(0)" class="active">C/C++入口</a>
<a href="javascript:void(0)">Python入口</a>
</li>
</ul>
<ul>
<p class="mb30 font-22 enter_title"><span class="mr20 font-bd">第一阶段</span><span>2019-6-25 09:00-2019-7-10 24:00 </span></p>
<li class="inline enter_btn">
<a href="javascript:void(0)">Java入口</a>
<a href="javascript:void(0)">C/C++入口</a>
<a href="javascript:void(0)">Python入口</a>
</li>
</ul>
</div>
</div>
<p class="second_6" style="background: url('/images/educoder/competition/qg/qg_two_6.png') no-repeat top center;"></p>
<p class="second_7" style="background: url('/images/educoder/competition/qg/qg_two_7.png') no-repeat top center;"></p>
<p class="second_8" style="background: url('/images/educoder/competition/qg/qg_two_8.png') no-repeat top center;"></p>
<% index += 1 %>
<% end %>
<div class="second_6" style="background: url(<%= named_attachment_path(@images[index], @images[index].try(:filename)) %>) no-repeat top center;"></div>
<% index += 1 %>
<div class="second_7" style="background: url(<%= named_attachment_path(@images[index], @images[index].try(:filename)) %>) no-repeat top center;"></div>
<% index += 1 %>
<div class="second_8" style="background: url(<%= named_attachment_path(@images[index], @images[index].try(:filename)) %>) no-repeat top center;"></div>

@ -83,7 +83,7 @@
</span>
<span class="fl mr40 mt13 font-16">邀请码:<label class="color-orange"><%= team.invite_code %></label></span>
<% if @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %>
<% if (User.current.admin? || User.current == team.user) && team.user_id != team.teacher_id %>
<% if User.current.admin? || User.current == team.user %>
<a href="<%= edit_competition_team_path(team) %>" data-remote="true" class="fl mt13 mr20" data-tip-down="编辑"><i class="iconfont icon-bianjidaibeijing color-blue fl"></i></a>
<% end %>
<% else %>

@ -7,5 +7,7 @@
<%= render :partial => "qg_competition" %>
<% elsif @competition.identifier == "gcc-annotation-2018" %>
<%= render :partial => "annotation_2018_competition" %>
<% elsif @competition.identifier == "gcc-dev-2019" %>
<%= render :partial => "qg_second_competition" %>
<% end %>
</div>

@ -68,13 +68,29 @@
<% end %>
<% if com_module.name == "报名" %>
<div class="fl ContentFillinthebox">
<input type="text" autocomplete="off" class="Other_boxinput" name="min_num" placeholder="1" value="<%= @competition.min_num %>"/> ~
<input type="text" autocomplete="off" class="Other_boxinput" name="max_num" placeholder="1" value="<%= @competition.max_num %>"/> 人
</div>
<div class="fl ml20">
<span>报名截止:</span>
<input type="text" class="winput-240-30" readonly placeholder="请选择截止时间" value="<%= format_time @competition.enroll_end_time %>" name="enroll_end_time" id="enroll_end_time"/>
<div class="fl">
<div class="ContentFillinthebox mb10">
<span>报名截止时间:</span>
<input type="text" class="winput-240-30" readonly placeholder="请选择截止时间" value="<%= format_time @competition.enroll_end_time %>" name="enroll_end_time" id="enroll_end_time"/>
</div>
<div class="competition-staff">
<div>报名要求:<i class="fa fa-plus-circle color-green font-16 ml10 add-competition-staff-btn"></i></div>
<div class="competition-staff-settings mb10 ml30">
<% @competition.competition_staffs.each do |staff| %>
<div class="competition-staff-row mb10">
<%= select_tag('competition_staffs[][category]', options_for_select(CompetitionStaff.category_options, staff.category), class: 'winput-120-30') %>
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][minimum]" required="required" value="<%= staff.minimum %>"/>
&nbsp;&nbsp;~&nbsp;&nbsp;
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][maximum]" required="required" value="<%= staff.maximum %>"/>
<span class="competition-staff-operate ml10">
<i class="fa fa-trash-o ml5 font-16 delete-icon"></i>
<i class="fa fa-plus-circle color-green font-16 ml10 add-icon"></i>
</span>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
<% if com_module.name != "首页" && com_module.name != "报名" && com_module.name != "通知公告" && com_module.name != "排行榜" %>
@ -149,6 +165,20 @@
</div>
</div>
<div class="competition-staff-row-example" style="display: none">
<div class="competition-staff-row mb10">
<%= select_tag('competition_staffs[][category]', options_for_select(CompetitionStaff.category_options, ''), class: 'winput-120-30') %>
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][minimum]" require="required" value="1"/>
&nbsp;&nbsp;~&nbsp;&nbsp;
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][maximum]" required="required" value="1"/>
<span class="competition-staff-operate ml10">
<i class="fa fa-trash-o ml5 font-16 delete-icon"></i>
<i class="fa fa-plus-circle color-green font-16 ml10 add-icon"></i>
</span>
</div>
</div>
<% content_for :header_tags do %>
@ -504,4 +534,17 @@
}
})
}
$(function(){
$('.add-competition-staff-btn').on('click', function(){
$('.competition-staff-settings').append($('.competition-staff-row-example').html());
});
$('.competition-staff-settings').on('click', '.add-icon', function(){
$('.competition-staff-settings').append($('.competition-staff-row-example').html());
});
$('.competition-staff-settings').on('click', '.delete-icon', function(){
$(this).parents('.competition-staff-row').remove();
});
})
</script>

@ -0,0 +1,7 @@
'zh':
competition_staff:
category:
all: 不限
teacher: 教师
student: 学生
profession: 专业人士

@ -0,0 +1,13 @@
class CreateCompetitionStaffs < ActiveRecord::Migration
def change
create_table :competition_staffs do |t|
t.references :competition
t.integer :position
t.string :category
t.integer :minimum
t.integer :maximum
t.timestamps
end
end
end

@ -105,3 +105,7 @@ a:hover.edu-admin-nav-a,.active a.edu-admin-nav-a{color: #5faee3;}
/*超级管理员----技术体系*/
.createsystem{cursor: pointer;width: 100%;height: 70px;line-height: 70px;border:1px dashed #FF7500;color: #FF7500;text-align: center;margin:15px 0px 20px 0px;border-radius: 4px;}
.infoul li{list-style-type: disc}
/* 竞赛配置 */
.competition-staff-settings .competition-staff-row .competition-staff-operate .add-icon { display: none; }
.competition-staff-settings .competition-staff-row:last-child .competition-staff-operate .add-icon { display: inline; }

@ -721,7 +721,7 @@ a.enterLink{cursor: pointer;color: #418CCD!important;background: none!important;
.personListLine > span{float: left;text-align: center;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;}
.t-c-1{width: 120px;}
.t-c-2{width: 150px;text-align: left!important;}
.t-c-3{width: 210px;}
.t-c-3{width: 210px;min-height:20px;}
.t-c-4{width: 200px;}
.t-c-5{width: 80px;}
/*东北赛区*/

Loading…
Cancel
Save