From 6b49e92424e6f700fc91b1e07d90ac55b8d43203 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 17:23:15 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/competiton_notice_20190704.rake | 35 +++++++++++++++++++++++ lib/trustie/sms/sms.rb | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 lib/tasks/competiton_notice_20190704.rake diff --git a/lib/tasks/competiton_notice_20190704.rake b/lib/tasks/competiton_notice_20190704.rake new file mode 100644 index 00000000..92a273fe --- /dev/null +++ b/lib/tasks/competiton_notice_20190704.rake @@ -0,0 +1,35 @@ +#coding=utf-8 +namespace :competition_notice do + require 'simple_xlsx_reader' + + task :send_message => :environment do + puts "--------------------------------competition_notice send_message start" + attachment = Attachment.where(id: 230670).first + if attachment.present? + path = attachment.disk_directory + name = attachment.disk_filename + if name.split(".").last == "xlsx" + doc = SimpleXlsxReader.open("files/#{path}/#{name}") + sheet = doc.sheets.first + lists = sheet.rows + + lists.each_with_index do |list, index| + if index > 0 + puts "--------------------------------user_name:#{list[0]}, user_phone:#{list[1]}" + user_name = list[0] + user_phone = list[1] + if user_name.present? && user_phone.present? + begin + status = Trustie::Sms.send(mobile: user_phone, send_type:'competition_notice' , name: user_name) + rescue => e + puts "--------------------------------发送验证码出错: #{user_name}---#{user_phone}" + end + end + end + end + else + puts "--------------------------------只支持xlsx文件" + end + end + end +end diff --git a/lib/trustie/sms/sms.rb b/lib/trustie/sms/sms.rb index 7c2dad4c..03b1dbe7 100644 --- a/lib/trustie/sms/sms.rb +++ b/lib/trustie/sms/sms.rb @@ -31,6 +31,8 @@ module Trustie params['text'] = "" if send_type.nil? params['text'] = "【Edu实训】" + code + "(手机验证码)。如非本人操作,请忽略。" + elsif send_type == "competition_notice" + params['text'] = "【Edu实训】亲爱的#{name},你参与的全国绿色计算大赛2019于7月1日开始,请及时完善信息,详戳→http://opengcc.org.cn/" elsif send_type == "teacher_register" params['text'] = "【Edu实训】亲爱的#{user_name},有新的老师#{name}注册啦,请尽快处理" elsif send_type == 'competition_start' From c0c94148545471d7b2dfd9d84b5c525979116880 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 17:24:23 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=BC=B9=E6=A1=86=E4=B8=AD=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E8=AE=AD=E5=88=9B=E5=BB=BA=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/student_work/_shixun_work_show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/student_work/_shixun_work_show.html.erb b/app/views/student_work/_shixun_work_show.html.erb index ee9cd765..77e3062f 100644 --- a/app/views/student_work/_shixun_work_show.html.erb +++ b/app/views/student_work/_shixun_work_show.html.erb @@ -3,8 +3,8 @@

- <%= link_to @shixun.owner.try(:show_real_name), user_path(@shixun.owner), :class => "color-grey3 fl", :target => "_blank" %> - / + <%#= link_to @shixun.owner.try(:show_real_name), user_path(@shixun.owner), :class => "color-grey3 fl", :target => "_blank" %> + <%= link_to @shixun.name, shixun_path(@shixun), :class => "edu-info-dark fl task-hide",:style=>"max-width:300px", :target => "_blank" %>

<% if User.current.has_teacher_role(@homework.course) || User.current.admin? || @work.user == User.current %> From 2bbffda6677efa8dddd70a69e25c7e1119f7c003 Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Thu, 4 Jul 2019 17:25:28 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E6=88=98=E9=98=9F=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../competitions/_competition_team_detail.html.erb | 10 ++++++++++ .../_qg_second_course_competition.html.erb | 4 ++-- public/stylesheets/educoder/edu-all.css | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 app/views/competitions/_competition_team_detail.html.erb diff --git a/app/views/competitions/_competition_team_detail.html.erb b/app/views/competitions/_competition_team_detail.html.erb new file mode 100644 index 00000000..88dd992d --- /dev/null +++ b/app/views/competitions/_competition_team_detail.html.erb @@ -0,0 +1,10 @@ +
+

+ 战队详情 + 返回 +

+
+

实训项目

+
+
+
\ No newline at end of file diff --git a/app/views/competitions/_qg_second_course_competition.html.erb b/app/views/competitions/_qg_second_course_competition.html.erb index b808deab..6724ed7e 100644 --- a/app/views/competitions/_qg_second_course_competition.html.erb +++ b/app/views/competitions/_qg_second_course_competition.html.erb @@ -21,8 +21,8 @@ <%= first_section.competition_entries[1].name %>
- <%= first_section.competition_entries[2].name %> + +
<% index += 1 %> diff --git a/public/stylesheets/educoder/edu-all.css b/public/stylesheets/educoder/edu-all.css index 24d992c9..04bad365 100644 --- a/public/stylesheets/educoder/edu-all.css +++ b/public/stylesheets/educoder/edu-all.css @@ -711,7 +711,7 @@ li.challenge_box:last-child{ .second_course_2{min-height: 823px;} .second_course_3{min-height: 690px;} .second_course_4{min-height: 514px;} -.second_course_5{min-height: 737px;padding-top: 190px;box-sizing: border-box;position: relative} +.second_course_5{min-height: 627px;padding-top: 190px;box-sizing: border-box;position: relative} .second_course_6{min-height: 1225px;} .course_competition_panel{ margin:30px 40px 40px;border:1px solid #ABDCF1;background: #F1F8FD;justify-content: center;align-items: center;display: -webkit-flex; From ddced1fa74d7535315498c521504fe2ac0e2b906 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 4 Jul 2019 17:27:48 +0800 Subject: [PATCH 04/10] competition setting --- .../competition_teams_controller.rb | 57 +++++++++++++++-- app/controllers/competitions_controller.rb | 3 +- app/models/competition.rb | 8 +++ app/models/competition_staff.rb | 2 +- .../_search_member_list.html.erb | 2 +- app/views/competitions/enroll.html.erb | 12 ++-- .../_competition_list_page.html.erb | 63 ++++++++++++++----- ..._multiple_limited_to_competition_staffs.rb | 5 ++ public/stylesheets/educoder/edu-main.css | 52 ++++++++++++++- 9 files changed, 176 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20190704063532_add_multiple_limited_to_competition_staffs.rb diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index 817de9be..fb41d3f8 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -38,9 +38,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 +56,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 +113,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 +130,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 +153,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 +264,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}}已经加入其它战队了" + 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}}已经加入其它战队了" + return false + end + + true + end end diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb index c890ff6b..0e9fb376 100644 --- a/app/controllers/competitions_controller.rb +++ b/app/controllers/competitions_controller.rb @@ -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| diff --git a/app/models/competition.rb b/app/models/competition.rb index d66aac1a..96747b0b 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -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 diff --git a/app/models/competition_staff.rb b/app/models/competition_staff.rb index 1a949460..6609cdbb 100644 --- a/app/models/competition_staff.rb +++ b/app/models/competition_staff.rb @@ -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 diff --git a/app/views/competition_teams/_search_member_list.html.erb b/app/views/competition_teams/_search_member_list.html.erb index bf4a9b8d..2bdd8340 100644 --- a/app/views/competition_teams/_search_member_list.html.erb +++ b/app/views/competition_teams/_search_member_list.html.erb @@ -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) %>
  • <%= user.show_name %> diff --git a/app/views/competitions/enroll.html.erb b/app/views/competitions/enroll.html.erb index 075bfe40..eca04c58 100644 --- a/app/views/competitions/enroll.html.erb +++ b/app/views/competitions/enroll.html.erb @@ -2,14 +2,14 @@

    <%= @competition.name %>

    - <% if @minimum_staff > 1 %> + <% if @maximum_staff > 1 %>

    <%= @competition.sub_title %>

    <% 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 %> 创建战队 <% else %> 创建战队 @@ -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 %> 加入战队 <% else %> 加入战队 @@ -40,7 +40,7 @@ <% else %>

    <% unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %> - <% if @is_enroll.present? %> + <% if !@can_enroll %> 立即报名 <% 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 @@ 退出 <% end %> <% end %> + + <% if @competition.identifier == 'gcc-course-2019' %> + <%= link_to '战队详情', competition_team_path(id: @competition.id) %> + <% end %>

  • <% end %> diff --git a/app/views/managements/_competition_list_page.html.erb b/app/views/managements/_competition_list_page.html.erb index 073d1133..e5f2d6a5 100644 --- a/app/views/managements/_competition_list_page.html.erb +++ b/app/views/managements/_competition_list_page.html.erb @@ -78,12 +78,24 @@
    <% @competition.competition_staffs.each do |staff| %>
    - <%= select_tag('competition_staffs[][category]', options_for_select(CompetitionStaff.category_options, staff.category), class: 'winput-120-30') %> - -   ~   - - 人 - +
    + <%= select_tag('competition_staffs[][category]', options_for_select(CompetitionStaff.category_options, staff.category), class: 'winput-120-30') %> + +   ~   + + 人 +
    + +
    + name="competition_staffs[][mutiple_limited]" class="mutiple-limited-radio" type="checkbox" value="false"> + +
    +
    + name="competition_staffs[][mutiple_limited]" class="mutiple-limited-radio" type="checkbox" value="true"> + +
    + + @@ -167,15 +179,27 @@ @@ -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) + } + }) }) diff --git a/db/migrate/20190704063532_add_multiple_limited_to_competition_staffs.rb b/db/migrate/20190704063532_add_multiple_limited_to_competition_staffs.rb new file mode 100644 index 00000000..a4b53c96 --- /dev/null +++ b/db/migrate/20190704063532_add_multiple_limited_to_competition_staffs.rb @@ -0,0 +1,5 @@ +class AddMultipleLimitedToCompetitionStaffs < ActiveRecord::Migration + def change + add_column :competition_staffs, :mutiple_limited, :boolean, default: false + end +end diff --git a/public/stylesheets/educoder/edu-main.css b/public/stylesheets/educoder/edu-main.css index 711a1f96..881f7ed9 100644 --- a/public/stylesheets/educoder/edu-main.css +++ b/public/stylesheets/educoder/edu-main.css @@ -917,4 +917,54 @@ html>body #ajax-indicator { position: fixed; } padding-bottom: 235px; min-width: 1200px; padding-top: 60px; -} \ No newline at end of file +} + +/* 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; +} From cd2662731b757fb5675b987e8262034a7853eeac Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 17:29:18 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/competiton_notice_20190704.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/competiton_notice_20190704.rake b/lib/tasks/competiton_notice_20190704.rake index 92a273fe..0dc7e6fb 100644 --- a/lib/tasks/competiton_notice_20190704.rake +++ b/lib/tasks/competiton_notice_20190704.rake @@ -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 From 3c91b68f03289135928ed9ad8ddbe858ef1db987 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 4 Jul 2019 18:06:21 +0800 Subject: [PATCH 06/10] fix --- app/controllers/competition_teams_controller.rb | 10 +++++++--- .../competition_teams/_competition_team_form.html.erb | 4 ++-- .../competition_teams/_search_teacher_list.html.erb | 9 +++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index fb41d3f8..f39c7708 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -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 @@ -271,7 +275,7 @@ class CompetitionTeamsController < ApplicationController 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}}已经加入其它战队了" + @status, @message = -1, "导师#{repeat_teachers.map{|t| t.user.show_real_name}.join(',')}已经加入其它战队了" return false end @@ -284,7 +288,7 @@ class CompetitionTeamsController < ApplicationController 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}}已经加入其它战队了" + @status, @message = -1, "成员#{repeat_members.map{|t| t.user.show_real_name}.join(',')}已经加入其它战队了" return false end diff --git a/app/views/competition_teams/_competition_team_form.html.erb b/app/views/competition_teams/_competition_team_form.html.erb index 359a1d11..fbba4618 100644 --- a/app/views/competition_teams/_competition_team_form.html.erb +++ b/app/views/competition_teams/_competition_team_form.html.erb @@ -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()}); } } diff --git a/app/views/competition_teams/_search_teacher_list.html.erb b/app/views/competition_teams/_search_teacher_list.html.erb index 54538382..9847daec 100644 --- a/app/views/competition_teams/_search_teacher_list.html.erb +++ b/app/views/competition_teams/_search_teacher_list.html.erb @@ -1,10 +1,15 @@

    请选择指导老师,允许修改

    <% @teachers.each do |teacher| %> -
  • + <% 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) %> + +
  • <%= teacher.show_name %> <%= teacher.identity %> <%= teacher.school_name %> + <% if has_enroll %> + 已加入其他战队 + <% end %>
  • <% 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()); From a0f3a7bd1c75ba0f429bac870f470d9f1a9e3c04 Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Thu, 4 Jul 2019 18:09:51 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_competition_team_detail.html.erb | 37 +++++++++++++++++-- .../_qg_second_course_competition.html.erb | 2 +- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/views/competitions/_competition_team_detail.html.erb b/app/views/competitions/_competition_team_detail.html.erb index 88dd992d..9574db58 100644 --- a/app/views/competitions/_competition_team_detail.html.erb +++ b/app/views/competitions/_competition_team_detail.html.erb @@ -1,10 +1,39 @@ -
    -

    +

    +

    战队详情 返回

    -
    +

    实训项目

    -
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    创建者名称学习人数fork版的学习人数有效作品数制作应用经验值
    胡莎莎 + 单链表的学习与应用(I) + 2.5万14562.5万4545667
    合计:65.5万78782.5万245364
    \ No newline at end of file diff --git a/app/views/competitions/_qg_second_course_competition.html.erb b/app/views/competitions/_qg_second_course_competition.html.erb index 50697e7b..55862a23 100644 --- a/app/views/competitions/_qg_second_course_competition.html.erb +++ b/app/views/competitions/_qg_second_course_competition.html.erb @@ -14,7 +14,7 @@ is_start = Time.now > first_section.start_time %>
    -
    +
    <%= first_section.competition_entries[0].name %> From d61f1838fc26f0fe2f63445211bb45b557fb99cb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 09:45:51 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/zip_service.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/services/zip_service.rb b/app/services/zip_service.rb index cb278e98..009fee77 100644 --- a/app/services/zip_service.rb +++ b/app/services/zip_service.rb @@ -314,6 +314,7 @@ module ZipService rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" # 文件名过长 + index = 1 if rename_zipfile.size > MAX_PATH rename_zipfile = rename_zipfile[0,rename_zipfile.size-4][0,MAX_PATH-4] + rename_zipfile[-4,4] end @@ -329,7 +330,10 @@ module ZipService begin zipfile.add(rename_file, filename) rescue Exception => e - zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)} + rename_file = rename_same_file(rename_file, index) + index += 1 + zipfile.add(rename_file, filename) + # zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)} next end end @@ -376,4 +380,11 @@ module ZipService attach = Attachment.find_by_disk_filename(name) attach.filename end + + def rename_same_file(name, index) + basename = File.basename(name, ".*") + new_basename = basename + "_" + index.to_s + extname = File.extname(name) + new_basename + extname + end end \ No newline at end of file From af72a800ce389fbc9db0d5a9625d532c91101f02 Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Fri, 5 Jul 2019 10:24:16 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=88=98=E9=98=9F=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_competition_team_detail.html.erb | 113 +++++++++++++----- public/stylesheets/educoder/edu-all.css | 41 +++++++ 2 files changed, 125 insertions(+), 29 deletions(-) diff --git a/app/views/competitions/_competition_team_detail.html.erb b/app/views/competitions/_competition_team_detail.html.erb index 9574db58..a44f8717 100644 --- a/app/views/competitions/_competition_team_detail.html.erb +++ b/app/views/competitions/_competition_team_detail.html.erb @@ -1,39 +1,94 @@ -
    -

    +

    +

    战队详情 返回

    -
    -

    实训项目

    - - - - - - - - +
    +

    实训项目

    +
    创建者名称学习人数fork版的学习人数有效作品数制作应用经验值
    + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + +
    创建者名称学习人数fork版的学习人数有效作品数经验值
    胡莎莎 - 单链表的学习与应用(I) - 2.5万14562.5万4545667
    张三 + MySQL数据库编程开发实训(基础入门篇)MySQL数据库编程开发实训(基础入门篇) + 原创 + 1545124611154987
    合计612万112233
    +
    + +
    +

    翻转课堂

    + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + +
    创建者名称学生数量发布的实训作业数量有效作品数经验值
    张三 + MySQL数据库编程开发实训(基础入门篇)MySQL数据库编程开发实训(基础入门篇) + 1545124611154987
    合计:65.5万78782.5万245364
    合计612万112233
    -
    \ No newline at end of file +
    + + \ No newline at end of file diff --git a/public/stylesheets/educoder/edu-all.css b/public/stylesheets/educoder/edu-all.css index 60018b85..13639287 100644 --- a/public/stylesheets/educoder/edu-all.css +++ b/public/stylesheets/educoder/edu-all.css @@ -728,6 +728,47 @@ li.challenge_box:last-child{ width: 360px;height: 70px;background: #2CDAD4;color: #fff!important;font-size: 30px;line-height: 70px;text-align: center; margin:0px auto;display: block; } +table.tBodyScroll tbody tr td{ + padding:6px 5px;box-sizing: border-box;font-size: 16px;color: #05101A;font-weight: normal; +} +table.tBodyScroll tbody { + display:block; + max-height:420px; + overflow-y:auto; +} +.connectTag{ + display: inline-block;background: #4CACFF;border-radius: 12px;height: 24px;line-height: 24px;color: #fff; + padding:0px 12px;font-size: 14px; +} +table.tBodyScroll thead,table.tBodyScroll tfoot,table.tBodyScroll tbody tr { + display:table; + width:100%; + table-layout:fixed; +} + +table.tBodyScroll thead,table.tBodyScroll tfoot { + width:100%; +} +table.tBodyScroll tfoot tr th{ + padding:10px 5px;box-sizing: border-box;border-top: 1px solid #eaeaea;font-weight: normal!important; +} +.lastPart,.tfootLastPart{ + width: calc( 100% - 1em )!important; +} +.lastPart tr th:last-child,.tfootLastPart tr th:last-child{position: relative;} +.tfootLastPart tr th:last-child:after{ + content: '';width: 1em;height: 100%;position: absolute;right: -1em;top:0px;border-top: 1px solid #eaeaea; +} +.lastPart tr th:last-child:after{ + content: '';background: #F5F5F5;width: 1em;height: 100%;position: absolute;right: -1em;top:0px +} +table.tBodyScroll thead th{ + background: #F5F5F5;color: #656565;padding:10px 5px;box-sizing: border-box; +} +.modalTitle{display: block;padding: 0px 30px;position: relative;line-height: 20px} +.modalTitle:before{ + position: absolute;height: 100%;width: 2px;content: '';background: #4cacff;left: 0px;top: 0px; +} From d7ce826e5691fdb27de307a5e3cfbf42eaad4dba Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 5 Jul 2019 11:15:34 +0800 Subject: [PATCH 10/10] add competition feature --- .../competition_teams_controller.rb | 27 ++++ app/controllers/competitions_controller.rb | 14 ++- .../_competition_team_form.html.erb | 5 +- app/views/competition_teams/show.html.erb | 118 ++++++++++++++++++ .../_competition_team_detail.html.erb | 94 -------------- app/views/competitions/_header.html.erb | 2 +- app/views/competitions/enroll.html.erb | 2 +- app/views/competitions/index.html.erb | 18 +++ app/views/competitions/publish.js.erb | 1 + app/views/managements/_competionList.html.erb | 4 + config/routes.rb | 1 + ...021338_add_published_at_to_competitions.rb | 5 + 12 files changed, 188 insertions(+), 103 deletions(-) create mode 100644 app/views/competition_teams/show.html.erb delete mode 100644 app/views/competitions/_competition_team_detail.html.erb create mode 100644 app/views/competitions/publish.js.erb create mode 100644 db/migrate/20190705021338_add_published_at_to_competitions.rb diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index f39c7708..6ecbb9aa 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -12,6 +12,33 @@ class CompetitionTeamsController < ApplicationController @team_user = User.current end + def show + return render_404 if @competition.identifier != 'gcc-course-2019' + + @team_user_ids = @team.team_members.pluck(:user_id) + + shixuns = Shixun.where(user_id: @team_user_ids, status: 2) + shixuns = shixuns.joins('left join shixuns forked_shixuns on forked_shixuns.fork_from = shixuns.id and forked_shixuns.status = 2') + shixuns = shixuns.joins('left join myshixuns on myshixuns.shixun_id = shixuns.id and exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') + shixuns = shixuns.select('shixuns.id, shixuns.identifier, shixuns.user_id, shixuns.myshixuns_count, shixuns.name, shixuns.fork_from, sum(forked_shixuns.myshixuns_count) forked_myshixun_count') + @shixuns = shixuns.group('shixuns.id').order('shixuns.myshixuns_count desc').includes(:creator) + @myshixun_count_map = Myshixun.where(shixun_id: @shixuns.map(&:id)) + .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') + .group('shixun_id').count + + course_ids = Course.joins('join members on members.course_id = courses.id') + .joins('join member_roles on member_roles.member_id = members.id and member_roles.role_id in (3,7,9)') + .where(members: { user_id: @team_user_ids }).pluck(:id) + courses = Course.where(id: course_ids).joins(:shixun_homework_commons) + @courses = courses.select('courses.id, courses.name, courses.members_count, count(*) shixun_homework_count') + .group('courses.id').order('shixun_homework_count desc') + + @course_myshixun_map = Myshixun.joins(student_works: :homework_common) + .where(homework_commons: { course_id: @courses.map(&:id) }) + .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') + .group('homework_commons.course_id').count + end + def search_teacher if params[:team] && params[:team] != "" @team = @competition.competition_teams.where(:id => params[:team]).first diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb index 0e9fb376..a868cbf0 100644 --- a/app/controllers/competitions_controller.rb +++ b/app/controllers/competitions_controller.rb @@ -4,7 +4,7 @@ class CompetitionsController < ApplicationController :edit_md_content, :update_md_content, :new_competition_stage, :new_stage_section, :update_competition_stage] before_filter :find_inform, :only => [:edit_inform, :update_inform] - before_filter :require_login, :only => [:enroll_portal] + before_filter :require_login, :only => [:enroll_portal, :publish] skip_before_filter :verify_authenticity_token, :only => [:edit_rule] layout 'base_competition' @@ -25,7 +25,7 @@ class CompetitionsController < ApplicationController end def index - @competitions = Competition.where(:status => 1).reorder("online_time desc") + @competitions = Competition.where('status = 1 or published_at is not null').reorder("published_at desc, online_time desc") respond_to do |format| format.html { render :layout => "base_edu"} format.js @@ -438,10 +438,10 @@ class CompetitionsController < ApplicationController def online_switch if @competition.present? if @competition.status - @competition.update_attributes(:status => 0) + @competition.update_attributes(status: false, published_at: nil) @btn_html = "上架" else - @competition.update_attributes(:status => 1, :online_time => Time.now) + @competition.update_attributes(status: true, online_time: Time.now, published_at: nil) @btn_html = "下架" end end @@ -601,6 +601,12 @@ class CompetitionsController < ApplicationController @competition.competition_stage_sections.where(:id => params[:section_id]).destroy_all end + def publish + return render_403 unless admin_or_business? + + @competition.update_column(:published_at, Time.now) + end + private def chart_exp_score_mo myshixuns, s_time, e_time diff --git a/app/views/competition_teams/_competition_team_form.html.erb b/app/views/competition_teams/_competition_team_form.html.erb index fbba4618..c68cc3b2 100644 --- a/app/views/competition_teams/_competition_team_form.html.erb +++ b/app/views/competition_teams/_competition_team_form.html.erb @@ -24,13 +24,12 @@
    - autocomplete="off" placeholder="请您输入老师姓名进行搜索;可以后续再添加导师" id="teacher_search_input" - value="<%= @team.try(:id).present? ? @team.teacher.try(:show_name) : (@team_user.user_extensions.identity == 0 ? @team_user.show_name : "") %>"> + "> "> - +
    diff --git a/app/views/competition_teams/show.html.erb b/app/views/competition_teams/show.html.erb new file mode 100644 index 00000000..31937688 --- /dev/null +++ b/app/views/competition_teams/show.html.erb @@ -0,0 +1,118 @@ +
    +

    + 战队详情 + <%= link_to '返回', enroll_competition_path(@competition), class: 'color-grey-9 fr' %> +

    +
    +

    实训项目

    + + + + + + + + + + + + + <% + total_myshixun_count = 0 + total_forked_myshixun_count = 0 + %> + <% @shixuns.each do |shixun| %> + <% + total_myshixun_count += shixun.myshixuns_count + total_forked_myshixun_count += shixun['forked_myshixun_count'].to_i + %> + + + + + + + + + <% end %> + + + + + + + + + + + +
    创建者名称学习人数fork版的学习人数有效作品数经验值
    <%= shixun.creator.show_real_name %> + <%= link_to shixun_path(shixun), target: '_blank' do %> + <%= shixun.name %> + <% end %> + <% if shixun.fork_from.blank? %> + 原创 + <% end %> + <%= shixun.myshixuns_count.to_i.zero? ? '--' : shixun.myshixuns_count.to_i %><%= shixun['forked_myshixun_count'].to_i.zero? ? '--' : shixun['forked_myshixun_count'].to_i %><%= @myshixun_count_map.fetch(shixun.id, '--') %>--
    合计<%= @shixuns.size %><%= total_myshixun_count %><%= total_forked_myshixun_count %><%= @myshixun_count_map.values.reduce(:+) %>--
    +
    + +
    +

    翻转课堂

    + + + + + + + + + + + + + <% + total_members_count = 0 + total_shixun_homework_count = 0 + %> + <% @courses.each do |course| %> + <% + total_members_count += course.members_count.to_i + total_shixun_homework_count += course['shixun_homework_count'].to_i + %> + + + + + + + + + <% end %> + + + + + + + + + + + +
    创建者名称学生数量发布的实训作业数量有效作品数经验值
    <%= course.teachers.where(user_id: @team_user_ids).first.user.show_real_name %> + <%= course.name %> + <%= course.members_count %><%= course['shixun_homework_count'].presence || '--' %><%= @course_myshixun_map.fetch(course.id, '--') %>--
    合计<%= @courses.size %><%= total_members_count %><%= total_shixun_homework_count %><%= @course_myshixun_map.values.reduce(:+) %>--
    +
    +
    + + \ No newline at end of file diff --git a/app/views/competitions/_competition_team_detail.html.erb b/app/views/competitions/_competition_team_detail.html.erb deleted file mode 100644 index a44f8717..00000000 --- a/app/views/competitions/_competition_team_detail.html.erb +++ /dev/null @@ -1,94 +0,0 @@ -
    -

    - 战队详情 - 返回 -

    -
    -

    实训项目

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    创建者名称学习人数fork版的学习人数有效作品数经验值
    张三 - MySQL数据库编程开发实训(基础入门篇)MySQL数据库编程开发实训(基础入门篇) - 原创 - 1545124611154987
    合计612万112233
    -
    - -
    -

    翻转课堂

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    创建者名称学生数量发布的实训作业数量有效作品数经验值
    张三 - MySQL数据库编程开发实训(基础入门篇)MySQL数据库编程开发实训(基础入门篇) - 1545124611154987
    合计612万112233
    -
    -
    - - \ No newline at end of file diff --git a/app/views/competitions/_header.html.erb b/app/views/competitions/_header.html.erb index 6aa4c1a2..4017f82b 100644 --- a/app/views/competitions/_header.html.erb +++ b/app/views/competitions/_header.html.erb @@ -46,7 +46,7 @@ 排行榜 <% when '报名' %> -
  • +
  • 报名
  • <% else %> diff --git a/app/views/competitions/enroll.html.erb b/app/views/competitions/enroll.html.erb index eca04c58..746251f1 100644 --- a/app/views/competitions/enroll.html.erb +++ b/app/views/competitions/enroll.html.erb @@ -99,7 +99,7 @@ <% end %> <% if @competition.identifier == 'gcc-course-2019' %> - <%= link_to '战队详情', competition_team_path(id: @competition.id) %> + <%= link_to '战队详情', competition_team_path(id: team.id), class: 'fl mt13 ml10' %> <% end %> <% end %> diff --git a/app/views/competitions/index.html.erb b/app/views/competitions/index.html.erb index 3f03f6ef..19627026 100644 --- a/app/views/competitions/index.html.erb +++ b/app/views/competitions/index.html.erb @@ -2,6 +2,7 @@ <% if @competitions.count > 0 %> <% else %> diff --git a/app/views/competitions/publish.js.erb b/app/views/competitions/publish.js.erb new file mode 100644 index 00000000..4fd255a7 --- /dev/null +++ b/app/views/competitions/publish.js.erb @@ -0,0 +1 @@ +notice_box_redirect('<%= competition_managements_path %>', '发布成功') \ No newline at end of file diff --git a/app/views/managements/_competionList.html.erb b/app/views/managements/_competionList.html.erb index f2c4921f..ddc8b69b 100644 --- a/app/views/managements/_competionList.html.erb +++ b/app/views/managements/_competionList.html.erb @@ -65,6 +65,10 @@ 取消 保存 <%= competition.status ? "下架" : "上架" %> + + <% if !competition.status? && competition.published_at.blank? %> + <%= link_to '发布', publish_competition_path(competition), class: 'mr10', method: :post, remote: true %> + <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 2bc0038c..c9d01c3b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -260,6 +260,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 get 'send_message' get 'export_chart_score' post 'competition_images' + post 'publish' end collection do post 'new_competition' diff --git a/db/migrate/20190705021338_add_published_at_to_competitions.rb b/db/migrate/20190705021338_add_published_at_to_competitions.rb new file mode 100644 index 00000000..a3420621 --- /dev/null +++ b/db/migrate/20190705021338_add_published_at_to_competitions.rb @@ -0,0 +1,5 @@ +class AddPublishedAtToCompetitions < ActiveRecord::Migration + def change + add_column :competitions, :published_at, :datetime + end +end