From d7ce826e5691fdb27de307a5e3cfbf42eaad4dba Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 5 Jul 2019 11:15:34 +0800 Subject: [PATCH 1/2] 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 From 4ccde9d71c5e6d348139be32d84ef20430e9d5eb Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 5 Jul 2019 11:30:22 +0800 Subject: [PATCH 2/2] fix --- app/controllers/competition_teams_controller.rb | 3 ++- app/views/competition_teams/show.html.erb | 4 +++- app/views/competitions/_header.html.erb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index 6ecbb9aa..5b46986a 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -26,10 +26,11 @@ class CompetitionTeamsController < ApplicationController .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') .group('shixun_id').count + # todo:使用新版course_members 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 = Course.where(id: course_ids).joins(:shixun_homework_commons).where('homework_commons.publish_time < now()') @courses = courses.select('courses.id, courses.name, courses.members_count, count(*) shixun_homework_count') .group('courses.id').order('shixun_homework_count desc') diff --git a/app/views/competition_teams/show.html.erb b/app/views/competition_teams/show.html.erb index 31937688..bc176c1e 100644 --- a/app/views/competition_teams/show.html.erb +++ b/app/views/competition_teams/show.html.erb @@ -82,7 +82,9 @@ <%= course.teachers.where(user_id: @team_user_ids).first.user.show_real_name %> - <%= course.name %> + <%= link_to course_path(course), target: '_blank' do %> + <%= course.name %> + <% end %> <%= course.members_count %> <%= course['shixun_homework_count'].presence || '--' %> diff --git a/app/views/competitions/_header.html.erb b/app/views/competitions/_header.html.erb index 4017f82b..b6790839 100644 --- a/app/views/competitions/_header.html.erb +++ b/app/views/competitions/_header.html.erb @@ -46,7 +46,7 @@ 排行榜 <% when '报名' %> -
  • +
  • 报名
  • <% else %>