From c501af70baa7207d854498d17e1f57fe3a61664d Mon Sep 17 00:00:00 2001
From: guange <8863824@gmail.com>
Date: Mon, 27 Jun 2016 11:09:25 +0800
Subject: [PATCH] .
---
.access_token | 1 +
Gemfile | 3 +-
app/api/mobile/apis/courses.rb | 3 +-
app/controllers/projects_controller.rb | 21 +++--
app/controllers/wechats_controller.rb | 15 ++--
app/helpers/courses_helper.rb | 86 ++++++++++---------
app/models/course.rb | 9 ++
app/views/wechats/user_activities.html.erb | 43 +++++-----
config/menu.yml | 10 ++-
config/wechat.yml | 2 +-
public/assets/wechat/class_list.html | 10 +++
.../wechat/controllers/class_list.js | 18 ++++
public/javascripts/wechat/others/routes.js | 1 +
13 files changed, 140 insertions(+), 82 deletions(-)
create mode 100644 .access_token
create mode 100644 public/assets/wechat/class_list.html
create mode 100644 public/javascripts/wechat/controllers/class_list.js
diff --git a/.access_token b/.access_token
new file mode 100644
index 000000000..ae71675eb
--- /dev/null
+++ b/.access_token
@@ -0,0 +1 @@
+{"access_token":"_-LoF1vaOEfUwHI2E5iF7IOIyhvTQAhdkyrwp0ISL0q2Nqb8QMcO9K4Z_kNXxporFsN3xJxOdd8EcCPLVxxzqbBm02m9gmGdp_ENBf9K5nHcneKNTpdoIII7B-9FXHRwCYPaADAJFW","expires_in":7200,"got_token_at":1466770839}
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index a8131fb3f..4012237ef 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,9 +1,9 @@
source 'https://ruby.taobao.org/'
-### ����ִ��bundle config mirror.https://rubygems.org https://gems.ruby-china.org �л���ruby-chinaԴ
unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
+ gem "rmagick", ">= 2.0.0"
end
gem 'certified'
@@ -31,7 +31,6 @@ gem 'acts-as-taggable-on', '2.4.1'
gem 'spreadsheet'
gem 'ruby-ole'
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
-#gem "rmagick", ">= 2.0.0"
gem 'binding_of_caller'
gem 'chinese_pinyin'
# gem 'sunspot_rails', '~> 1.3.3'
diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb
index 6696b8360..08b4dc98b 100644
--- a/app/api/mobile/apis/courses.rb
+++ b/app/api/mobile/apis/courses.rb
@@ -14,8 +14,9 @@ module Mobile
optional :token, type: String
end
get do
+ authenticate!
cs = CoursesService.new
- courses = cs.course_list(params,current_user.nil? ? User.find(2):current_user)
+ courses = cs.course_list(params,current_user)
present :data, courses, with: Mobile::Entities::Course
present :status, 0
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index c8b272480..6029e7e37 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -100,8 +100,8 @@ class ProjectsController < ApplicationController
render_404
end
- def course
- render_404
+ def courserender_404
+
end
# Time 2015-01-29 11:19:11
@@ -299,6 +299,8 @@ class ProjectsController < ApplicationController
if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
return
end
+
+ logger.debug "111111111"*100
# over
@author = params[:user_id].blank? ? nil : User.active.find(params[:user_id])
@page = params[:page] ? params[:page].to_i + 1 : 0
@@ -319,6 +321,7 @@ class ProjectsController < ApplicationController
else
@events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10);
end
+ logger.debug "2"*100
# g = Gitlab.client
unless @project.gpid.nil? || @project.project_score.changeset_num == 0
# rep_statics_commit = @project.rep_statics.order("commits_num desc")
@@ -332,12 +335,20 @@ class ProjectsController < ApplicationController
@a_commits_del = rep_statics_code.map {|s| s.del.to_i }
@a_commits_changeset = rep_statics_code.map {|s| s.changeset.to_i }
g = Gitlab.client
+ logger.debug "3"*100
begin
- g_branch = g.project(@project.gpid).default_branch.to_s
- rescue
- logger.error("get gitlab project failed!")
+ gid = @project.gpid
+ logger.debug "31"*100
+ g_branch = g.project(gid)
+ logger.debug "4"*100
+ g_branch = g_branch.default_branch.to_s
+ logger.debug "5"*100
+ rescue =>e
+ logger.error("get gitlab project failed: " + e)
end
+ logger.debug "6"*100
@rev = g_branch.nil? ? "master" : g_branch
+ logger.debug "7"*100
end
# 根据对应的请求,返回对应的数据
respond_to do |format|
diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb
index 7dcfa1948..09bcba78c 100644
--- a/app/controllers/wechats_controller.rb
+++ b/app/controllers/wechats_controller.rb
@@ -65,7 +65,7 @@ class WechatsController < ActionController::Base
end
on :click, with: 'DEV' do |request, key|
- request.reply.text "此功能正在开发中,请耐心等待。"
+ request.reply.text "此功能正在开发中,很快就会上线,谢谢!"
end
# When user view URL in the menu button
on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view|
@@ -138,7 +138,7 @@ class WechatsController < ActionController::Base
unless uw
sendBind(request)
else
- request.reply.text "请直接回复6位班级邀请码\n(不区分大小写):"
+ request.reply.text "请直接回复5位班级邀请码\n(不区分大小写):"
end
end
@@ -163,7 +163,6 @@ class WechatsController < ActionController::Base
if uw && uw.user
request.reply.text "欢迎回来, #{uw.user.show_name}"
else
- request.reply.text "欢迎关注Trustie创新实践社区"
sendBind(request)
end
end
@@ -188,7 +187,7 @@ class WechatsController < ActionController::Base
course = nil
course = Course.where(qrcode: params[:ticket]).first if params[:ticket]
course = Course.where(invite_code: params[:invite_code]).first if params[:invite_code]
- raise "课程不存在" unless course
+ raise "班级不存在,请确认您的邀请码是否输入正确,谢谢!" unless course
cs = CoursesService.new
status = cs.join_course({invite_code: course.invite_code}, user)
@@ -239,14 +238,14 @@ class WechatsController < ActionController::Base
code = params[:code] || session[:wechat_code]
openid = get_openid_from_code(code)
- raise "无法获取到openid,请在微信中打开本页面" unless openid
- raise "此微信号已绑定用户, 不能重复绑定" if user_binded?(openid)
+ raise "无法获取到openid,请在微信中打开本页面" unless openid
+ raise "此微信号已绑定用户,不能重复绑定" if user_binded?(openid)
user, last_login_on = User.try_to_login(params[:username], params[:password])
- raise "用户名或密码错误,请重新输入" unless user
+ raise "用户名或密码错误,请重新输入" unless user
#补全用户信息
- raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat
+ raise "此用户已经绑定过公众号,请换一个帐户试试" if user.user_wechat
UserWechat.create!(
openid: openid,
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index 47d343e8f..bb144472b 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -44,9 +44,9 @@ module CoursesHelper
def visible_excellent_course obj
# if course.is_pu
end
-
+
# 返回x项目成员数量,即roles表中定义的所有成员
- def projectCount project
+ def projectCount project
#searchCountByRoles project, AllPeople
project.members.count
end
@@ -147,10 +147,10 @@ module CoursesHelper
# 返回学生数量,即roles表中定义的Reporter
#def studentCount project
- # searchStudent(project).count
- # or
- # searchStudent(project).count
- # end
+ # searchStudent(project).count
+ # or
+ # searchStudent(project).count
+ # end
# 判断用户是否是课程的管理员
# add by nwb
@@ -225,11 +225,11 @@ module CoursesHelper
#end
# 注意:此方法有问题,速度慢且结果不准
- # alias studentCountOrigin studentCount
+ # alias studentCountOrigin studentCount
#def studentCount course
- # count = studentCountOrigin course
- #garble count
- # end
+ # count = studentCountOrigin course
+ #garble count
+ # end
#获取课程所有成员
def course_all_member course
@@ -265,27 +265,18 @@ module CoursesHelper
def garble count
count = count.round( 1-count.to_s.size ).to_i
return count.to_s if count.to_s.size.eql?(1)
- count.to_s << '+'
+ count.to_s << '+'
end
# =====================================================================================
# return people list
- def searchPeopleByName(course, role_name)
- course.members.select{|m|
- m.roles.any?{|r|r.name == role_name}
- }
- end
-
def searchTeacherAndAssistant project
- searchPeopleByName(project, 'Manager').concat(
- searchPeopleByName(project, 'Teacher')
- ).concat(
- searchPeopleByName(project, 'TeachingAsistant')
- )
- end
-
- def searchStudent project
- searchPeopleByName(project, 'Student')
+ #searchPeopleByRoles(project, TeacherRoles)
+ members = []
+ project.members.includes(:user).each do |m|
+ members << m if m && m.user && m.user.allowed_to?(:as_teacher,project)
+ end
+ members
end
def TeacherAndAssistantCount course
@@ -302,6 +293,19 @@ module CoursesHelper
members
end
+ def searchStudent project
+ #searchPeopleByRoles(project, StudentRoles)
+ members = []
+ project.members.each do |m|
+ if m && m.user && m.user.allowed_to?(:as_student,project)
+ members << m
+ end
+ end
+ members
+ end
+
+
+
def searchStudent_by_name project, name
#searchPeopleByRoles(project, StudentRoles)
members = []
@@ -320,29 +324,29 @@ module CoursesHelper
mems = []
if name != ""
name = name.to_s.downcase
- members.each do |m|
+ members.each do |m|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
mems << m
end
end
else
- mems = members
- end
+ mems = members
+ end
mems
end
def searchgroupmember_by_name members, name, group
#searchPeopleByRoles(project, StudentRoles)
mems = []
if name != ""
- members.each do |m|
- if m.course_group_id == group.id
- username = m.user[:lastname].to_s + m.user[:firstname].to_s
- if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name))
- mems << m
+ members.each do |m|
+ if m.course_group_id == group.id
+ username = m.user[:lastname].to_s + m.user[:firstname].to_s
+ if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name))
+ mems << m
+ end
+ end
end
- end
- end
else
mems = members
end
@@ -454,7 +458,7 @@ module CoursesHelper
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
-
+
def findCourseTime project
str = ""
begin
@@ -679,9 +683,9 @@ module CoursesHelper
#file_count
Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment|
if attachment.is_public? || User.current.member_of_course?(@course) || User.current.admin?
- activities[attachment.container_id]+=1
+ activities[attachment.container_id]+=1
else
- activities[attachment.container_id]
+ activities[attachment.container_id]
end
end
@@ -700,8 +704,8 @@ module CoursesHelper
#news
News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news|
if news.author.member_of_course?(@course)
- activities[news.course_id]+=1
- end
+ activities[news.course_id]+=1
+ end
end
#homework_count
diff --git a/app/models/course.rb b/app/models/course.rb
index 195e7cf9f..b623f1f5c 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -457,6 +457,15 @@ class Course < ActiveRecord::Base
end
end
+ # 延迟生成邀请码
+ def invite_code
+ code = read_attribute[:invite_code]
+ if !code || code.size < 5
+ code = generate_invite_code
+ end
+ return code
+ end
+
# 生成邀请码
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
def generate_invite_code
diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb
index 80d254dae..e21f5d6c7 100644
--- a/app/views/wechats/user_activities.html.erb
+++ b/app/views/wechats/user_activities.html.erb
@@ -28,27 +28,28 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+