Date: Fri, 26 Jul 2019 10:17:03 +0800
Subject: [PATCH 2/6] competition team detail
---
.../competition_teams_controller.rb | 41 +++++++++++++++++--
app/models/shixun.rb | 2 +-
app/views/competition_teams/show.html.erb | 26 +++++++++---
3 files changed, 60 insertions(+), 9 deletions(-)
diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb
index 2bbbd6ef..72732a1a 100644
--- a/app/controllers/competition_teams_controller.rb
+++ b/app/controllers/competition_teams_controller.rb
@@ -17,7 +17,8 @@ class CompetitionTeamsController < ApplicationController
@team_user_ids = @team.team_members.pluck(:user_id)
- shixuns = Shixun.where(user_id: @team_user_ids, status: 2).where('shixuns.created_at > ?', Time.parse('2018-06-01'))
+ shixuns = Shixun.where(user_id: @team_user_ids, status: 2)
+ .where('shixuns.created_at > ? && shixuns.created_at <= ?', Time.parse('2018-06-01'), @competition.end_time)
shixuns = shixuns.joins('left join shixuns forked_shixuns on forked_shixuns.fork_from = shixuns.id and forked_shixuns.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)
@@ -30,18 +31,30 @@ class CompetitionTeamsController < ApplicationController
forked_myshixun_count_map = get_valid_myshixun_count(forked_shixun_map.keys)
forked_myshixun_count_map.each { |k, v| @myshixun_count_map[forked_shixun_map[k]] += v }
- # todo:使用新版course_members
+ @course_count_map = get_valid_course_count(shixun_ids)
+ forked_map = get_valid_course_count(forked_shixun_map.keys)
+ @forked_course_count_map = {}
+ forked_map.each do |forked_id, course_count|
+ @forked_course_count_map[forked_shixun_map[forked_id]] ||= 0
+ @forked_course_count_map[forked_shixun_map[forked_id]] += course_count
+ end
+
+
+ # 课堂
course_ids = Course.where('courses.created_at > ?', Time.parse('2018-06-01'))
+ .where('courses.created_at <= ?', @competition.end_time)
.joins('join course_members on course_members.course_id = courses.id and course_members.role in (1,2,3)')
.where(course_members: { user_id: @team_user_ids }).pluck(:id)
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').having('shixun_homework_count > 0')
+ course_ids = @courses.map(&:id)
@course_myshixun_map = Myshixun.joins(student_works: :homework_common)
- .where(homework_commons: { course_id: @courses.map(&:id) })
+ .where(homework_commons: { course_id: course_ids })
.where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)')
.group('homework_commons.course_id').count
+ @course_shixun_count_map = get_valid_shixun_count(course_ids)
end
def search_teacher
@@ -345,6 +358,28 @@ class CompetitionTeamsController < ApplicationController
.group('shixun_id').count
end
+ def get_valid_course_count(ids)
+ percentage_sql = StudentWork.where('homework_common_id = homework_commons.id')
+ .select('count(compelete_status !=0 ) as finish, count(*) as total')
+ .having('finish > (total / 2)').to_sql
+
+ Course.joins(shixun_homework_commons: :homework_commons_shixuns)
+ .where('shixun_id in (?)', ids)
+ .where("exists (#{percentage_sql})")
+ .group('shixun_id').count
+ end
+
+ def get_valid_shixun_count(ids)
+ percentage_sql = StudentWork.where('homework_common_id = homework_commons.id')
+ .select('count(compelete_status !=0 ) as finish, count(*) as total')
+ .having('finish > (total / 2)').to_sql
+ Shixun.joins(homework_commons_shixuns: :homework_common)
+ .where(homework_commons: { homework_type: 3 })
+ .where('course_id in (?)', ids)
+ .where("exists (#{percentage_sql})")
+ .group('course_id').count
+ end
+
def record_agent_user_action
# 记录是否是引流用户的行为
ip = request.remote_ip
diff --git a/app/models/shixun.rb b/app/models/shixun.rb
index 0d201ed3..35193f2d 100644
--- a/app/models/shixun.rb
+++ b/app/models/shixun.rb
@@ -32,7 +32,7 @@ class Shixun < ActiveRecord::Base
has_many :users, :through => :shixun_members
has_many :shixun_members, :dependent => :destroy
has_one :repository, :dependent => :destroy
- has_many :homework_commons_shixunses
+ has_many :homework_commons_shixuns, class_name: 'HomeworkCommonsShixuns'
has_many :homework_challenge_settings, :dependent => :destroy
has_many :challenges, :dependent => :destroy
has_many :myshixuns, :dependent => :destroy
diff --git a/app/views/competition_teams/show.html.erb b/app/views/competition_teams/show.html.erb
index 129fa32a..f8e1f1c5 100644
--- a/app/views/competition_teams/show.html.erb
+++ b/app/views/competition_teams/show.html.erb
@@ -20,11 +20,23 @@
<%
total_myshixun_count = 0
total_forked_myshixun_count = 0
+ total_shixun_score = 0
%>
<% @shixuns.each do |shixun| %>
<%
total_myshixun_count += shixun.myshixuns_count
total_forked_myshixun_count += shixun['forked_myshixun_count'].to_i
+
+ valid_course_count = @course_count_map.fetch(shixun.id, 0)
+ valid_student_count = @myshixun_count_map.fetch(shixun.id, 0)
+ score =
+ if shixun.fork_from.blank?
+ 500 + 50 * valid_course_count + 10 * valid_student_count
+ else
+ 100 + 10 * valid_course_count + 5 * valid_student_count
+ end
+ score += @forked_course_count_map.fetch(shixun.id, 0)
+ total_shixun_score += score
%>
<%= shixun.creator.show_real_name %> |
@@ -39,7 +51,7 @@
<%= 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, '--') %> |
- -- |
+ <%= score.zero? ? '--' : score %> |
<% end %>
@@ -50,7 +62,7 @@
<%= total_myshixun_count %> |
<%= total_forked_myshixun_count %> |
<%= @myshixun_count_map.values.reduce(:+) %> |
- -- |
+ <%= total_shixun_score %> |
@@ -73,11 +85,15 @@
<%
total_members_count = 0
total_shixun_homework_count = 0
+ total_course_score = 0
%>
<% @courses.each do |course| %>
<%
total_members_count += course.members_count.to_i
total_shixun_homework_count += course['shixun_homework_count'].to_i
+
+ score = 500 + 5 * @course_shixun_count_map.fetch(course.id, 0) * @course_myshixun_map.fetch(course.id, 0)
+ total_course_score += score
%>
<%= course.teachers.where(user_id: @team_user_ids).first.user.show_real_name %> |
@@ -89,7 +105,7 @@
<%= course.members_count %> |
<%= course['shixun_homework_count'].presence || '--' %> |
<%= @course_myshixun_map.fetch(course.id, '--') %> |
- -- |
+ <%= score.zero? ? '--' : score %> |
<% end %>
@@ -99,8 +115,8 @@
<%= @courses.size %> |
<%= total_members_count %> |
<%= total_shixun_homework_count %> |
- <%= @course_myshixun_map.values.reduce(:+) %> |
- -- |
+ <%= @course_myshixun_map.values.reduce(:+) || 0 %> |
+ <%= total_course_score %> |
From 2c4ce7e049eaa70bbc2b016420e0438f1f8e1b5a Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Fri, 26 Jul 2019 10:24:48 +0800
Subject: [PATCH 3/6] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E8=AF=95=E7=94=A8?=
=?UTF-8?q?=E6=8E=88=E6=9D=83=E7=9A=84=E5=88=A4=E6=96=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/helpers/application_helper.rb | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 5737f99b..6a62503e 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -628,17 +628,19 @@ module ApplicationHelper
return
end
=end
- if !User.current.profile_completed?
- redirect_to my_account_path
- Rails.logger.info("check_authentication end")
- elsif User.current.certification != 1 # 系统没有授权
- day_cer = UserDayCertification.where(:user_id => User.current.id).last
- unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400
- redirect_to my_account_path
- Rails.logger.info("check_authentication end")
- return
- end
- end
+
+ # 暂时不需要试用授权
+ # if !User.current.profile_completed?
+ # redirect_to my_account_path
+ # Rails.logger.info("check_authentication end")
+ # elsif User.current.certification != 1 # 系统没有授权
+ # day_cer = UserDayCertification.where(:user_id => User.current.id).last
+ # unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400
+ # redirect_to my_account_path
+ # Rails.logger.info("check_authentication end")
+ # return
+ # end
+ # end
end
def match_specific_symbol(str)
From a264ce6ea24af5965c832f0832a700c48175117d Mon Sep 17 00:00:00 2001
From: p31729568
Date: Fri, 26 Jul 2019 10:52:53 +0800
Subject: [PATCH 4/6] add user profile completed check
---
app/controllers/libraries_controller.rb | 2 ++
app/controllers/project_packages_controller.rb | 5 +++--
.../competitions/_qg_second_opensource.html.erb | 13 +++++++++++++
app/views/competitions/enroll.html.erb | 16 ++++++++++++++--
4 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/app/controllers/libraries_controller.rb b/app/controllers/libraries_controller.rb
index ac861841..a1e8a56c 100644
--- a/app/controllers/libraries_controller.rb
+++ b/app/controllers/libraries_controller.rb
@@ -1,7 +1,9 @@
class LibrariesController < ApplicationController
+ include ApplicationHelper
layout 'base_library'
before_filter :require_login, :except => [:index, :show]
+ before_filter :check_authentication, except: [:index, :show]
after_filter :increment_visit_count, only: [:show, :create, :edit, :update]
def index
diff --git a/app/controllers/project_packages_controller.rb b/app/controllers/project_packages_controller.rb
index 6721c1c4..7a0990f3 100644
--- a/app/controllers/project_packages_controller.rb
+++ b/app/controllers/project_packages_controller.rb
@@ -1,10 +1,11 @@
# encoding=utf-8
# For react
class ProjectPackagesController < ApplicationController
- before_filter :require_login, :except => [:index, :show]
-
include ApplicationHelper
+ before_filter :require_login, except: [:index]
+ before_filter :check_authentication, except: [:index]
+
def show
render_react
end
diff --git a/app/views/competitions/_qg_second_opensource.html.erb b/app/views/competitions/_qg_second_opensource.html.erb
index 8aef0390..47fc814b 100644
--- a/app/views/competitions/_qg_second_opensource.html.erb
+++ b/app/views/competitions/_qg_second_opensource.html.erb
@@ -57,6 +57,14 @@
%>
var userEnrolled = <%= user_enrolled %>;
+ var userProfileModal = function(url, str) {
+ var htmlvalue = '';
+ pop_box_new(htmlvalue, 480, 205);
+ }
+
$(".enroll-btn.active").on("click", function(){
var url = $(this).data("url");
@@ -65,6 +73,11 @@
return;
}
+ if (<%= !@user.profile_completed? %>) {
+ userProfileModal('/my/account', '您需要去完善您的个人资料,才能使用此功能');
+ return
+ }
+
if (!userEnrolled) {
$.ajax({
url: "/api/courses/apply_to_join_course.json",
diff --git a/app/views/competitions/enroll.html.erb b/app/views/competitions/enroll.html.erb
index ee439267..c2a3d029 100644
--- a/app/views/competitions/enroll.html.erb
+++ b/app/views/competitions/enroll.html.erb
@@ -5,8 +5,10 @@
<% if @maximum_staff > 1 %>
<%= @competition.sub_title %>
- <% unless User.current.logged? %>
+ <% if !User.current.logged? %>
<%= link_to "创建战队", signin_path, :remote => true, :class => "enroll-in-b enroll-in-b-green fr" %>
+ <% elsif !User.current.try(:profile_completed?) %>
+ <%= link_to "创建战队", 'javascript:void(0)', :class => "enroll-in-b enroll-in-b-green fr", onclick: "userProfileModal()" %>
<% else %>
<% unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %>
<% if !@can_enroll %>
@@ -19,8 +21,10 @@
<% end %>
<% end %>
- <% unless User.current.logged? %>
+ <% if !User.current.logged? %>
<%= link_to "加入战队", signin_path, :remote => true, :class => "enroll-in-b fr" %>
+ <% elsif !User.current.try(:profile_completed?) %>
+ <%= link_to "加入战队", 'javascript:void(0)', :class => "enroll-in-b fr", onclick: "userProfileModal()" %>
<% else %>
<% unless @competition.enroll_end_time.present? && @competition.enroll_end_time < Time.now %>
<% if !@can_enroll %>
@@ -153,6 +157,14 @@
pop_box_new(htmlvalue, 500, 205);
}
+ function userProfileModal() {
+ var htmlvalue = '
';
+ pop_box_new(htmlvalue, 480, 205);
+ }
+
function joinSure() {
if ($("#codeinput").val().trim() == "") {
$("#codeInput-notice").html("请输入邀请码");
From a7606d41dd63bdab08ed1f5f27a50250fcae2ba9 Mon Sep 17 00:00:00 2001
From: p31729568
Date: Fri, 26 Jul 2019 10:55:57 +0800
Subject: [PATCH 5/6] add flag to redirect user profile
---
app/helpers/application_helper.rb | 2 +-
app/views/competitions/_qg_second_opensource.html.erb | 2 +-
app/views/competitions/enroll.html.erb | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 5737f99b..10e64bcf 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -629,7 +629,7 @@ module ApplicationHelper
end
=end
if !User.current.profile_completed?
- redirect_to my_account_path
+ redirect_to my_account_path(need_profile_completed: true)
Rails.logger.info("check_authentication end")
elsif User.current.certification != 1 # 系统没有授权
day_cer = UserDayCertification.where(:user_id => User.current.id).last
diff --git a/app/views/competitions/_qg_second_opensource.html.erb b/app/views/competitions/_qg_second_opensource.html.erb
index 47fc814b..87847a46 100644
--- a/app/views/competitions/_qg_second_opensource.html.erb
+++ b/app/views/competitions/_qg_second_opensource.html.erb
@@ -74,7 +74,7 @@
}
if (<%= !@user.profile_completed? %>) {
- userProfileModal('/my/account', '您需要去完善您的个人资料,才能使用此功能');
+ userProfileModal('/my/account?need_profile_completed=true', '您需要去完善您的个人资料,才能使用此功能');
return
}
diff --git a/app/views/competitions/enroll.html.erb b/app/views/competitions/enroll.html.erb
index c2a3d029..d5dde153 100644
--- a/app/views/competitions/enroll.html.erb
+++ b/app/views/competitions/enroll.html.erb
@@ -161,7 +161,7 @@
var htmlvalue = '';
+ '立即完善';
pop_box_new(htmlvalue, 480, 205);
}
From 3275a3fff05d6aaeb337171ff6b4d332945c658a Mon Sep 17 00:00:00 2001
From: p31729568
Date: Fri, 26 Jul 2019 11:04:08 +0800
Subject: [PATCH 6/6] add user profile check to join course btn
---
app/views/competitions/enroll.html.erb | 2 +-
app/views/layouts/_logined_header.html.erb | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/app/views/competitions/enroll.html.erb b/app/views/competitions/enroll.html.erb
index d5dde153..4afb4ceb 100644
--- a/app/views/competitions/enroll.html.erb
+++ b/app/views/competitions/enroll.html.erb
@@ -161,7 +161,7 @@
var htmlvalue = '';
+ '立即完善';
pop_box_new(htmlvalue, 480, 205);
}
diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb
index 6b9cde10..e0bb5701 100644
--- a/app/views/layouts/_logined_header.html.erb
+++ b/app/views/layouts/_logined_header.html.erb
@@ -85,7 +85,13 @@
<%= link_to '新建项目', new_project_path() %>
- - <%= link_to "加入课堂", join_private_courses_path, :remote => true %>
+ -
+ <% if User.current.profile_completed? %>
+ <%= link_to "加入课堂", join_private_courses_path, :remote => true %>
+ <% else %>
+ <%= link_to "加入课堂", 'javascript:void(0)', onclick: 'showUserProfileModal()' %>
+ <% end %>
+
@@ -154,4 +160,12 @@
<% end %>
});
+
+ function showUserProfileModal() {
+ var htmlvalue = '';
+ pop_box_new(htmlvalue, 480, 205);
+ }
\ No newline at end of file