dev_bj
caishi 5 years ago
commit c408c1ecce

@ -1,7 +1,7 @@
class CompetitionTeamsController < ApplicationController
include ApplicationHelper
before_filter :find_team, :except => [:new, :create, :join_team, :search_non_user, :personal_enroll, :check_team_identity, :search_teacher]
before_filter :find_competition, :only => [:new, :create, :join_team, :search_non_user, :personal_enroll]
before_filter :find_competition, :only => [:new, :create, :join_team, :search_teacher, :search_non_user, :personal_enroll]
before_filter :require_login
skip_before_filter :verify_authenticity_token, :only => [:edit_rule]
layout 'base_competition'
@ -13,6 +13,10 @@ class CompetitionTeamsController < ApplicationController
end
def search_teacher
if params[:team] && params[:team] != ""
@team = @competition.competition_teams.where(:id => params[:team]).first
end
condition = "%#{params[:search].strip}%".gsub(" ","")
@teachers = User.joins(:user_extensions).where("status = 1 and LOWER(concat(lastname, firstname, login, nickname)) LIKE '#{condition}' and user_extensions.identity = 0")
end
@ -38,9 +42,13 @@ class CompetitionTeamsController < ApplicationController
end
def create
teacher_limited = @competition.teacher_enroll_mutiple_limited
member_limited = @competition.member_enroll_mutiple_limited
# 判断用户是否已创建过战队
if @competition.competition_teams.where(:user_id => User.current.id).count > 0 && !User.current.is_teacher
@status, @message = -1, '您已创建过战队,不能重复创建'
if @competition.team_members.where(user_id: User.current.id).count > 0 &&
((User.current.is_teacher && teacher_limited) || (!User.current.is_teacher && member_limited))
@status, @message = -1, '您已经在战队中了'
return
end
@ -52,6 +60,11 @@ class CompetitionTeamsController < ApplicationController
is_teacher = User.current.user_extensions.identity == 0
return unless member_and_teacher_count_valid?(is_teacher)
# 检查老师多次报名限制
return unless check_teacher_enroll_limited?(@competition, (params[:teacher_ids].presence || []).map(&:to_i) - [User.current.id])
# 检查成员多次报名限制
return unless check_member_enroll_limited?(@competition, (params[:member_ids].presence || []).map(&:to_i) - [User.current.id])
ActiveRecord::Base.transaction do
invite_code = generate_team_code
new_team = CompetitionTeam.create(:competition_id => @competition.id, :name => params[:name],
@ -104,8 +117,12 @@ class CompetitionTeamsController < ApplicationController
# 删除的成员
delete_member_ids = team_member_ids - new_member_ids
@team.team_members.where(role: 2, user_id: delete_member_ids).delete_all
# 新增加的成员
(new_member_ids - team_member_ids).each do |user_id|
ids = new_member_ids - team_member_ids
raise @message unless check_member_enroll_limited?(@competition, ids) # 有成员已经加入其他战队,并且只能一次报名
ids.each do |user_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
@ -117,12 +134,19 @@ class CompetitionTeamsController < ApplicationController
# 删除的老师
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|
ids = new_teacher_ids - teacher_ids
raise @message unless check_teacher_enroll_limited?(@competition, ids) # 有老师已经加入其他战队,并且只能一次报名
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
end
rescue => ex
@status = -1
@message = ex.message
end
# @status:提示语标志0加入成功1邀请码错误2已经加入了其他队, 3超过人数限制4已有指导老师5只有学生和老师身份的用户才能加入战队
@ -133,7 +157,8 @@ class CompetitionTeamsController < ApplicationController
return
end
if TeamMember.where(:user_id => User.current.id, :competition_team_id => @competition.competition_teams.map(&:id), :is_teacher => 0).count > 0
enroll_limited = (User.current.is_teacher ? @competition.teacher_enroll_mutiple_limited : @competition.member_enroll_mutiple_limited)
if enroll_limited && @competition.team_members.exists?(user_id: User.current.id)
@status, @message = -1, '您已加入战队,不能重复加'
return
end
@ -243,4 +268,30 @@ class CompetitionTeamsController < ApplicationController
true
end
def check_teacher_enroll_limited?(competition, user_ids)
teacher_limited = competition.teacher_enroll_mutiple_limited
return true unless teacher_limited && user_ids.present?
repeat_teachers = competition.team_members.where(user_id: user_ids).includes(:user).to_a
if repeat_teachers.size > 0
@status, @message = -1, "导师#{repeat_teachers.map{|t| t.user.show_real_name}.join('')}已经加入其它战队了"
return false
end
true
end
def check_member_enroll_limited?(competition, user_ids)
member_limited = competition.member_enroll_mutiple_limited
return true unless member_limited && user_ids.present?
repeat_members = competition.team_members.where(user_id: user_ids).includes(:user).to_a
if repeat_members.size > 0
@status, @message = -1, "成员#{repeat_members.map{|t| t.user.show_real_name}.join('')}已经加入其它战队了"
return false
end
true
end
end

@ -111,6 +111,7 @@ class CompetitionsController < ApplicationController
@search_teams_count = @teams.count
@team_members_count = TeamMember.where(:competition_team_id => @teams.pluck(:id)).count
@can_enroll = !(@user.is_teacher ? @competition.teacher_enroll_mutiple_limited : @competition.member_enroll_mutiple_limited) || !@competition.team_members.exists?(user_id: User.current.id)
@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.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?)
@ -580,7 +581,7 @@ class CompetitionsController < ApplicationController
section_entries.destroy_all
else
if params[:entry_name].length < section_entries.size
section_entries[params[:entry_name].length, section_entries.size - 1].destroy_all
section_entries[params[:entry_name].length, section_entries.size - 1].each(&:destroy)
end
params[:entry_name].each_with_index do |name, index|

@ -32,4 +32,12 @@ class Competition < ActiveRecord::Base
def member_count
self.team_members.count == 0 ? 0 : self.team_members.count + 268
end
def teacher_enroll_mutiple_limited
competition_staffs.where(category: 'teacher').first.try(:mutiple_limited)
end
def member_enroll_mutiple_limited
competition_staffs.where(category: 'student').first.try(:mutiple_limited)
end
end

@ -1,7 +1,7 @@
class CompetitionStaff < ActiveRecord::Base
default_scope order: 'position asc'
attr_accessible :minimum, :maximum, :category, :position
attr_accessible :minimum, :maximum, :category, :position, :mutiple_limited
belongs_to :competition

@ -247,8 +247,8 @@
function search_teacher_user(){
if($("#teacher_search_input").val().trim() != ""){
$.post("<%= search_teacher_competition_teams_path() %>",
{"search": $("#teacher_search_input").val().trim()});
$.post("<%= search_teacher_competition_teams_path(:com_id => @competition.id) %>",
{"search": $("#teacher_search_input").val().trim(), "team": $("#team_id").val()});
}
}

@ -1,5 +1,5 @@
<% @users.each do |user| %>
<% has_enroll = @team.present? ? @competition.team_members.where("user_id = '#{user.id}' and id != #{@team.id}").count > 0 : @competition.team_members.where("user_id = '#{user.id}'").count > 0 %>
<% has_enroll = @competition.member_enroll_mutiple_limited && (@team.present? ? @competition.team_members.where("user_id = '#{user.id}' and id != #{@team.id}").count > 0 : @competition.team_members.where("user_id = '#{user.id}'").count > 0) %>
<li class="clearfix <%= has_enroll ? 'added' : 'unadded' %>">
<input type="hidden" value="<%= user.id %>">
<span class="pt-s task-hide"><%= user.show_name %></span>

@ -1,10 +1,15 @@
<p class="pl30 color-orange-tip mt5 pb5 bor-bottom-greyE">请选择指导老师,允许修改</p>
<% @teachers.each do |teacher| %>
<li class="clearfix">
<% has_enroll = @competition.teacher_enroll_mutiple_limited && (@team.present? ? @competition.team_members.where("user_id = '#{teacher.id}' and id != #{@team.id}").count > 0 : @competition.team_members.where("user_id = '#{teacher.id}'").count > 0) %>
<li class="clearfix <%= has_enroll ? 'added' : 'unadded' %>">
<input type="hidden" value="<%= teacher.id %>">
<span class="pt-s task-hide"><%= teacher.show_name %></span>
<span class="pt-s-n task-hide"><%= teacher.identity %></span>
<span class="pt-l task-hide"><%= teacher.school_name %></span>
<% if has_enroll %>
<span class="pt-s color-orange-tip task-hide">已加入其他战队</span>
<% end %>
</li>
<% end %>
@ -14,7 +19,7 @@
e.stopPropagation();
});
/*从下拉列表中选择指导老师*/
$("#pointerTeacher li").click(function(e){
$("#pointerTeacher li.unadded").click(function(e){
var name=$(this).find(".pt-s").html().trim();
$("#pointerTeacher").siblings("#teacher_search_input").val(name);
$("#pointerTeacher").siblings("#teacher_id").val($(this).find("input").val().trim());

@ -2,14 +2,14 @@
<div class="enroll-t" style="background:url('/images/educoder/competition/anon.png') no-repeat top center;">
<div class="educontent edu-txt-center">
<p class="main_title"><%= @competition.name %></p>
<% if @minimum_staff > 1 %>
<% if @maximum_staff > 1 %>
<p class="sub_title"><%= @competition.sub_title %></p>
<p class="edu-txt-right inline mt20">
<% unless User.current.logged? %>
<%= link_to "创建战队", signin_path, :remote => true, :class => "enroll-in-b enroll-in-b-green fr" %>
<% else %>
<% unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %>
<% if @is_enroll.present? && !@user.is_teacher %>
<% if !@can_enroll %>
<a onclick="notice_box('您已经加入了战队,不能再创建')" class="enroll-in-b enroll-in-b-green fr">创建战队</a>
<% else %>
<a href="<%= new_competition_team_path(:com_id => @competition.id) %>" data-remote="true" class="enroll-in-b enroll-in-b-green fr">创建战队</a>
@ -23,7 +23,7 @@
<%= link_to "加入战队", signin_path, :remote => true, :class => "enroll-in-b fr" %>
<% else %>
<% unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %>
<% if @is_enroll.present? && !@user.is_teacher %>
<% if !@can_enroll %>
<a onclick="notice_box('您已经加入了战队,不能重复加入')" class="enroll-in-b fr">加入战队</a>
<% else %>
<a class="enroll-in-b fr" onclick="joinTeam();">加入战队</a>
@ -40,7 +40,7 @@
<% else %>
<p class="edu-txt-right inline mt20">
<% unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %>
<% if @is_enroll.present? %>
<% if !@can_enroll %>
<a href="javascript:void(0)" onclick="notice_box('您已报名')" class="enroll-in-b enroll-in-b-green fr">立即报名</a>
<% else %>
<%= link_to "立即报名", personal_enroll_competition_teams_path(:com_id => @competition.id), :remote => true, :class => "enroll-in-b enroll-in-b-green fr" %>
@ -97,6 +97,10 @@
<a href="javascript:void(0)" class="font-16 color-grey-c fl mt12" onclick="delete_confirm_box('<%= exit_team_competition_team_path(team) %>', '是否确认退出战队')">退出</a>
<% end %>
<% end %>
<% if @competition.identifier == 'gcc-course-2019' %>
<%= link_to '战队详情', competition_team_path(id: @competition.id) %>
<% end %>
</li>
<% end %>
</div>

@ -78,12 +78,24 @@
<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]" value="<%= staff.minimum %>"/>
&nbsp;&nbsp;~&nbsp;&nbsp;
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][maximum]" value="<%= staff.maximum %>"/>
<span class="competition-staff-operate ml10">
<div class="fl">
<%= 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]" value="<%= staff.minimum %>"/>
&nbsp;&nbsp;~&nbsp;&nbsp;
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][maximum]" value="<%= staff.maximum %>"/>
</div>
<div class="radio-check fl mt10 ml20" style="width: 120px;">
<input <%= staff.mutiple_limited? ? '' : 'checked="checked"' %> name="competition_staffs[][mutiple_limited]" class="mutiple-limited-radio" type="checkbox" value="false">
<label class="mr20">可多次报名</label>
</div>
<div class="radio-check fl mt10" style="width: 120px;">
<input <%= staff.mutiple_limited? ? 'checked="checked"' : '' %> name="competition_staffs[][mutiple_limited]" class="mutiple-limited-radio" type="checkbox" value="true">
<label class="mr20">仅一次报名</label>
</div>
<span class="competition-staff-operate fl 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>
@ -167,15 +179,27 @@
<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]" value="1"/>
&nbsp;&nbsp;~&nbsp;&nbsp;
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][maximum]" 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 class="fl">
<%= 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]" value="1"/>
&nbsp;&nbsp;~&nbsp;&nbsp;
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][maximum]" value="1"/>
</div>
<div class="radio-check fl mt10 ml20" style="width: 120px;">
<input checked="checked" name="competition_staffs[][mutiple_limited]" class="mutiple-limited-radio" type="checkbox" value="false">
<label class="mr20">可多次报名</label>
</div>
<div class="radio-check fl mt10" style="width: 120px;">
<input name="competition_staffs[][mutiple_limited]" type="checkbox" class="mutiple-limited-radio" value="true">
<label class="mr20">仅一次报名</label>
</div>
<span class="competition-staff-operate fl 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>
@ -546,5 +570,14 @@
$('.competition-staff-settings').on('click', '.delete-icon', function(){
$(this).parents('.competition-staff-row').remove();
});
$('.competition-staff-settings').on('click', '.mutiple-limited-radio', function(){
var radio = $(this);
if (radio.is(':checked')) {
radio.parent().siblings().find('.mutiple-limited-radio').attr('checked', false)
} else {
radio.parent().siblings().find('.mutiple-limited-radio').attr('checked', true)
}
})
})
</script>

@ -0,0 +1,5 @@
class AddMultipleLimitedToCompetitionStaffs < ActiveRecord::Migration
def change
add_column :competition_staffs, :mutiple_limited, :boolean, default: false
end
end

@ -4,7 +4,7 @@ namespace :competition_notice do
task :send_message => :environment do
puts "--------------------------------competition_notice send_message start"
attachment = Attachment.where(id: 230670).first
attachment = Attachment.where(id: 375091).first
if attachment.present?
path = attachment.disk_directory
name = attachment.disk_filename

@ -917,4 +917,54 @@ html>body #ajax-indicator { position: fixed; }
padding-bottom: 235px;
min-width: 1200px;
padding-top: 60px;
}
}
/* css3 radio */
.radio-check {
position: relative;
height: 35px;
}
.radio-check > input {
position: absolute;
left: 0;
top: 0;
width: 14px;
height: 14px;
opacity: 0;
z-index: 100;
}
.radio-check > label {
position: absolute;
left: 20px;
line-height: 14px;
top: 0px;
}
.radio-check > label:before {
content: '';
position: absolute;
left: -20px;
top: 0px;
display: inline-block;
width: 14px;
height: 14px;
border-radius: 50%;
border: 1px solid #ddd;
}
.radio-check > label:after {
content: '';
position: absolute;
left: -20px;
top: 0px;
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
margin-top: 4px;
margin-left: 4px;
}
.radio-check input[type='checkbox']:checked + label:before {
border-color: #29BD8B;
}
.radio-check input[type='checkbox']:checked + label:after {
background: #29BD8B;
}

Loading…
Cancel
Save