diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb index b4fb90ea7..4d07c23f8 100644 --- a/app/api/mobile/apis/activities.rb +++ b/app/api/mobile/apis/activities.rb @@ -13,50 +13,55 @@ module Mobile requires :container_type, type: String end post do - authenticate! + begin + authenticate! - user = current_user + user = current_user - container_type = params[:container_type] ? params[:container_type] : "All" + container_type = params[:container_type] ? params[:container_type] : "All" - if container_type == "All" || container_type == "Project" - shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) - user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")" - project_types = "('Message','Issue','Project')" - end + if container_type == "All" || container_type == "Project" + shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) + user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")" + project_types = "('Message','Issue','Project')" + end - if container_type == "All" || container_type == "Course" - shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) - user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course')" - end + if container_type == "All" || container_type == "Course" + shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) + user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" + course_types = "('Message','News','HomeworkCommon','Poll','Course')" + end - page = params[:page] ? params[:page] : 0 - principal_types = "JournalsForMessage" - watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(',')) - user_ids = "(" + user.id.to_s + watched_user_ids + ")" - watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").count == 0 ? " " :Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",") - blog_ids = "(" + watched_user_blog_ids + ")" + page = params[:page] ? params[:page] : 0 + principal_types = "JournalsForMessage" + watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(',')) + user_ids = "(" + user.id.to_s + watched_user_ids + ")" + watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").count == 0 ? " " :Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",") + blog_ids = "(" + watched_user_blog_ids + ")" - if container_type == "Course" - activities = UserActivity.where("(container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc') - elsif container_type == "Project" - activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})").order('updated_at desc') - else - activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') + if container_type == "Course" + activities = UserActivity.where("(container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc') + elsif container_type == "Project" + activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})").order('updated_at desc') + else + activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') + end + all_count = activities.count + activities = activities.limit(10).offset(page * 10) + count = activities.count + present :data, activities, with: Mobile::Entities::Activity,user: user + present :all_count, all_count + present :count, count + present :page, page + present :status, 0 + present :container_type, container_type + rescue Exception=>e + present :status, -1 + present :message, e.message end - all_count = activities.count - activities = activities.limit(10).offset(page * 10) - count = activities.count - present :data, activities, with: Mobile::Entities::Activity,user: user - present :all_count, all_count - present :count, count - present :page, page - present :status, 0 - present :container_type, container_type end end end diff --git a/app/api/mobile/apis/blog_comments.rb b/app/api/mobile/apis/blog_comments.rb index 39b6a486a..ddfd65524 100644 --- a/app/api/mobile/apis/blog_comments.rb +++ b/app/api/mobile/apis/blog_comments.rb @@ -7,17 +7,22 @@ module Mobile desc "get special topic" post ':id' do - user = current_user + begin + user = current_user - #0一级回复的更多 1 二级回复的更多 - type = params[:type] || 0 - page = params[:page] || 0 + #0一级回复的更多 1 二级回复的更多 + type = params[:type] || 0 + page = params[:page] || 0 - blog = BlogComment.find params[:id] - present :data, blog, with: Mobile::Entities::BlogComment,user: user,type: type,page: page - present :type, type - present :page, page - present :status, 0 + blog = BlogComment.find params[:id] + present :data, blog, with: Mobile::Entities::BlogComment,user: user,type: type,page: page + present :type, type + present :page, page + present :status, 0 + rescue Exception=>e + present :status, -1 + present :message, e.message + end end end end diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 575048211..369185ca2 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -167,8 +167,20 @@ module Mobile requires :course_id, type: Integer, desc: "课程id" end get 'teachers' do + + course = Course.find(params[:course_id]) + cs = CoursesService.new teachers = cs.course_teacher_or_student_list({role: '1'}, params[:course_id],current_user) + + teachers.each do |m| + if m[:id] == course.tea_id + teachers.delete(m) + teachers.insert(0,m) + break + end + end + present :data, teachers, with: Mobile::Entities::User present :status, 0 end diff --git a/app/api/mobile/apis/issues.rb b/app/api/mobile/apis/issues.rb index 36b558652..dfd5a3335 100644 --- a/app/api/mobile/apis/issues.rb +++ b/app/api/mobile/apis/issues.rb @@ -8,17 +8,25 @@ module Mobile desc "get special issuse" post ':id' do - authenticate! - user = current_user + begin + # authenticate! + user = current_user - #0一级回复的更多 1 二级回复的更多 - type = params[:type] || 0 - page = params[:page] || 0 - issue = Issue.find params[:id] - present :data, issue, with: Mobile::Entities::Issue,user: user,type: type,page: page - present :type, type - present :page, page - present :status, 0 + #is_public true 公开 false 私有 1公开 0私有 + + #0一级回复的更多 1 二级回复的更多 + type = params[:type] || 0 + page = params[:page] || 0 + issue = Issue.find params[:id] + present :data, issue, with: Mobile::Entities::Issue,user: user,type: type,page: page + present :type, type + present :page, page + present :is_public, issue.project.is_public + present :status, 0 + rescue Exception=>e + present :status, -1 + present :message, e.message + end end end end diff --git a/app/api/mobile/apis/journal_for_messages.rb b/app/api/mobile/apis/journal_for_messages.rb index 6ac484513..0ef875780 100644 --- a/app/api/mobile/apis/journal_for_messages.rb +++ b/app/api/mobile/apis/journal_for_messages.rb @@ -7,18 +7,33 @@ module Mobile desc "get special journal" post ':id' do - authenticate! - user = current_user + begin + # authenticate! + user = current_user - #0一级回复的更多 1 二级回复的更多 - type = params[:type] || 0 - page = params[:page] || 0 + #0一级回复的更多 1 二级回复的更多 + type = params[:type] || 0 + page = params[:page] || 0 - jour = JournalsForMessage.find params[:id] - present :data, jour, with: Mobile::Entities::Jours,user: user,type: type,page: page - present :type, type - present :page, page - present :status, 0 + jour = JournalsForMessage.find params[:id] + + is_public = 1 + + if jour.jour_type == "Project" + is_public = jour.project.is_public + elsif jour.jour_type == "Course" + is_public = jour.course.is_public + end + + present :data, jour, with: Mobile::Entities::Jours,user: user,type: type,page: page + present :type, type + present :page, page + present :is_public, is_public + present :status, 0 + rescue Exception=>e + present :status, -1 + present :message, e.message + end end end end diff --git a/app/api/mobile/apis/messages.rb b/app/api/mobile/apis/messages.rb index ceda5058f..963d2f4ab 100644 --- a/app/api/mobile/apis/messages.rb +++ b/app/api/mobile/apis/messages.rb @@ -7,17 +7,36 @@ module Mobile desc "get special topic" post ':id' do - authenticate! - user = current_user + begin + # authenticate! + user = current_user - #0一级回复的更多 1 二级回复的更多 - type = params[:type] || 0 - page = params[:page] || 0 - message = Message.find params[:id] - present :data, message, with: Mobile::Entities::Message,user: user,type: type,page: page - present :type, type - present :page, page - present :status, 0 + #0一级回复的更多 1 二级回复的更多 + type = params[:type] || 0 + page = params[:page] || 0 + message = Message.find params[:id] + + is_public = 1 + type_name = "" + + if message.project + is_public = message.project.is_public + type_name = "project" + elsif message.course + is_public = message.course.is_public + type_name = "course" + end + + present :data, message, with: Mobile::Entities::Message,user: user,type: type,page: page + present :type, type + present :page, page + present :is_public, is_public + present :type_name, type_name + present :status, 0 + rescue Exception=>e + present :status, -1 + present :message, e.message + end end end end diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 5b7159301..6d46b2f59 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -11,69 +11,208 @@ module Mobile params do requires :type, type: String requires :content, type: String - requires :token, type: String end post ':id' do + unless current_user + #如果当前用户不存在 则需要根据微信昵称注册一个帐号 + openid = session[:wechat_openid] + raise "无法获取到openid,请在微信中打开本页面" unless openid + us = UsersService.new + + access_token = session[:access_token] + refresh_token = session[:refresh_token] + + if access_token.present? && refresh_token.present? + begin + refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) + rescue + info = Wechat.api.web_access_token(session[:wechat_code]) + openid =info["openid"] + access_token =info["access_token"] + if access_token + session[:access_token] = access_token + end + refresh_token = info["refresh_token"] + if refresh_token + session[:refresh_token] = refresh_token + end + refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) + end + + access_token = refreshinfo["access_token"] + refresh_token = refreshinfo["refresh_token"] + session[:access_token] = access_token + session[:refresh_token] = refresh_token + + #获取用户信息 + userinfo = Wechat.api.web_userinfo(access_token,openid) + Rails.logger.info "userinfo!!!!!!!!!" + Rails.logger.info userinfo + name = userinfo["nickname"] + else + name = openid[0..3]+"***"+openid.last + end + + user = us.register ({:login=>openid, :mail=>"#{openid}@163.com", + :password=>"12345678", :password_confirmation=>"12345678", + :should_confirmation_password => true}) + raise user.errors.full_messages.first if user.new_record? + user.update_attributes(:lastname=>name) + #自动激活 + if Setting.self_registration != '3' + user.activate + user.last_login_on = Time.now + if user.save + UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) + end + end + UserWechat.create!( + openid: openid, + user: user, + bindtype: 1 + ) + end + authenticate! + + subscribe = 0 #默认未关注 + + #-------------------获取用户是否关注此公众号----------------------------- + openid = session[:wechat_openid] + raise "无法获取到openid,请在微信中打开本页面" unless openid + user_info = Wechat.api.user(openid) + Rails.logger.info "user_info!!!!!!!!!" + Rails.logger.info user_info + subscribe = user_info["subscribe"] + + status = 0 + tip = 0 #0班级1项目 type = params[:type] result = 1 if params[:content]!="" && current_user case type when "HomeworkCommon" homework_common = HomeworkCommon.find(params[:id]) + + #如果是私有的 并且不是成员则不能回复 + # is_public = homework_common.course.is_public + # if is_public == 0 && !current_user.member_of_course?(homework_common.course) + # status = -1 + # tip = 0 + # else + # feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) + # if (feedback.errors.empty?) + # homework_common.update_column(:updated_at, Time.now) + # result = 2 + # end + # end feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) if (feedback.errors.empty?) homework_common.update_column(:updated_at, Time.now) result = 2 end + when "News" news = News.find(params[:id]) - comment = Comment.new - comment.comments = params[:content] - comment.author = current_user - if news.comments << comment - result = 2 + + # if news.project + # if news.project.is_public == false && !current_user.member_of?(news.project) + # status = -1 + # tip = 1 + # end + # elsif news.course + # if news.course.is_public == 0 && !current_user.member_of_course?(news.course) + # status = -1 + # tip = 0 + # end + # end + + if status == 0 + comment = Comment.new + comment.comments = params[:content] + comment.author = current_user + if news.comments << comment + result = 2 + end end when "Message" message = Message.find(params[:id]) board = Board.find(message.board_id) - topic = message.root - reply = Message.new - reply.author = current_user - reply.board = board - reply.content = params[:content] - reply.parent_id = params[:id] - reply.subject = "RE: #{topic.subject}" - if topic.children << reply - result = 2 + + # if message.project + # if message.project.is_public == false && !current_user.member_of?(message.project) + # status = -1 + # tip = 1 + # end + # elsif message.course + # if message.course.is_public == 0 && !current_user.member_of_course?(message.course) + # status = -1 + # tip = 0 + # end + # end + + if status == 0 + topic = message.root + reply = Message.new + reply.author = current_user + reply.board = board + reply.content = params[:content] + reply.parent_id = params[:id] + reply.subject = "RE: #{topic.subject}" + if topic.children << reply + result = 2 + end end when "JournalsForMessage" jour = JournalsForMessage.find params[:id] - parent_id = params[:id] - author_id = current_user.id - reply_user_id = jour.user_id - reply_id = params[:id] - content = params[:content] - options = {:user_id => author_id, - :status => true, - :m_parent_id => parent_id, - :m_reply_id => reply_id, - :reply_id => reply_user_id, - :notes => content, - :is_readed => false} - jfm = jour.user.add_jour(nil, nil, nil, options) - if jfm.errors.empty? - (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) - result = 2 + + # if jour.jour_type == "Project" + # if jour.project.is_public == false && !current_user.member_of?(jour.project) + # status = -1 + # tip = 1 + # end + # elsif jour.jour_type == "Course" + # if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course) + # status = -1 + # tip = 0 + # end + # end + + if status == 0 + parent_id = params[:id] + author_id = current_user.id + reply_user_id = jour.user_id + reply_id = params[:id] + content = params[:content] + options = {:user_id => author_id, + :status => true, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + jfm = jour.user.add_jour(nil, nil, nil, options) + if jfm.errors.empty? + (JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now) + result = 2 + end end when 'Issue' issue = Issue.find params[:id] - is_jour = Journal.new - is_jour.user_id = current_user.id - is_jour.notes = params[:content] - is_jour.journalized = issue - if is_jour.save - result = 2 + + # if issue.project.is_public == false && !current_user.member_of?(issue.project) + # status = -1 + # tip = 1 + # end + + if status == 0 + is_jour = Journal.new + is_jour.user_id = current_user.id + is_jour.notes = params[:content] + is_jour.journalized = issue + if is_jour.save + result = 2 + end end when 'BlogComment' blog = BlogComment.find(params[:id]).root @@ -97,7 +236,9 @@ module Mobile result = 3 end present :result, result - present :status, 0 + present :status, status + present :tip, tip + present :subscribe,subscribe end end end diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index 6e012ca4b..c2e2fcb5c 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -7,17 +7,32 @@ module Mobile desc "get special news" post ':id' do - authenticate! - user = current_user + begin + # authenticate! + user = current_user - #0一级回复的更多 1 二级回复的更多 - type = params[:type] || 0 - page = params[:page] || 0 - news = News.find params[:id] - present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page - present :type, type - present :page, page - present :status, 0 + #0一级回复的更多 1 二级回复的更多 + type = params[:type] || 0 + page = params[:page] || 0 + news = News.find params[:id] + + is_public = 1 + + if news.project + is_public = news.project.is_public + elsif news.course + is_public = news.course.is_public + end + + present :data, news, with: Mobile::Entities::News,user: user,type: type,page: page + present :type, type + present :page, page + present :is_public, is_public + present :status, 0 + rescue Exception=>e + present :status, -1 + present :message, e.message + end end end end diff --git a/app/api/mobile/apis/syllabuses.rb b/app/api/mobile/apis/syllabuses.rb index 8538fae99..100760f8e 100644 --- a/app/api/mobile/apis/syllabuses.rb +++ b/app/api/mobile/apis/syllabuses.rb @@ -28,9 +28,10 @@ module Mobile ss = SyllabusesService.new sy = ::Syllabus.find(params[:id]) - sy.courses = sy.courses.not_deleted - present :data, sy, with: Mobile::Entities::Syllabus,user: current_user + result = {:title=>sy.title, :id=>sy.id , :user_id=>sy.user_id,:courses=>sy.courses.not_deleted} + + present :data, result, with: Mobile::Entities::Syllabus,user: current_user present :status, 0 end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 9b1be37c3..764dc957f 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -29,7 +29,7 @@ module Mobile logger.debug "openid ============== #{openid}" raise "无法获取到openid,请在微信中打开本页面" unless openid uw = UserWechat.where(openid: openid).first - raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw + raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw && uw.real? user, last_login_on = User.try_to_login(params[:login], params[:password]) raise "用户名或密码错误,请重新输入" unless user @@ -37,12 +37,17 @@ module Mobile raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat - UserWechat.create!( + if uw && !uw.real? + uw.migrate_user(user) + else + UserWechat.create!( openid: openid, user: user - ) + ) + end + ws = WechatService.new - ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.login, Time.now.strftime("%Y-%m-%d")) + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.show_name+"("+user.login+")", Time.now.strftime("%Y-%m-%d")) present status: 0, message: '您已成功绑定Trustie平台' end @@ -53,22 +58,38 @@ module Mobile requires :password, type: String, desc: 'password' end post do - openid = session[:wechat_openid] logger.debug "openid ============== #{openid}" raise "无法获取到openid,请在微信中打开本页面" unless openid - + uw = UserWechat.where(openid: openid).first + raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw && uw.real? us = UsersService.new user = us.register params.merge(:password_confirmation => params[:password], :should_confirmation_password => true) raise user.errors.full_messages.first if user.new_record? - UserWechat.create!( + #自动激活 + if Setting.self_registration != '3' + # user = automatically_register(user) + user.activate + user.last_login_on = Time.now + if user.save + UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) + end + end + + if uw && !uw.real? + user.update_attributes(:lastname=>uw.user[:lastname]) + uw.migrate_user(user) + else + UserWechat.create!( openid: openid, user: user - ) + ) + end + ws = WechatService.new - ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.login, Time.now.strftime("%Y-%m-%d")) + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.show_name+"("+user.login+")", Time.now.strftime("%Y-%m-%d")) present :data, user, with: Mobile::Entities::User present :status, 0 end diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb index 9d03eed9f..572ce5e0b 100644 --- a/app/api/mobile/apis/whomeworks.rb +++ b/app/api/mobile/apis/whomeworks.rb @@ -7,23 +7,32 @@ module Mobile desc "get one homework" post ':id' do - authenticate! - user = current_user + begin + # authenticate! + user = current_user - #0一级回复的更多 1 二级回复的更多 - type = params[:type] || 0 - page = params[:page] || 0 + #0一级回复的更多 1 二级回复的更多 + type = params[:type] || 0 + page = params[:page] || 0 - if type == 0 - homework = HomeworkCommon.find params[:id] - present :data, homework, with: Mobile::Entities::Whomework,user: user,type: type,page: page,comment_type: "homework" - else - jour = JournalsForMessage.find params[:id] - present :data, jour, with: Mobile::Entities::Jours,user: user,type: type,page: page,comment_type: "homework" + is_public = 1 + + if type == 0 + homework = HomeworkCommon.find params[:id] + is_public = homework.course.is_public + present :data, homework, with: Mobile::Entities::Whomework,user: user,type: type,page: page,comment_type: "homework" + else + jour = JournalsForMessage.find params[:id] + present :data, jour, with: Mobile::Entities::Jours,user: user,type: type,page: page,comment_type: "homework" + end + present :type, type + present :page, page + present :is_public, is_public + present :status, 0 + rescue Exception=>e + present :status, -1 + present :message, e.message end - present :type, type - present :page, page - present :status, 0 end end end diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index aaf5dd78b..fc78cc14e 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -65,9 +65,9 @@ module Mobile end member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0] - roleName = member.roles[0].name if member + role_ids = member.role_ids if member - if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" ) + if role_ids && (role_ids.include?(7) || role_ids.include?(9) ) can_setting = true end @@ -76,6 +76,15 @@ module Mobile end can_setting end + expose :is_member, if: lambda { |instance, options| options[:user] } do |instance, options| + current_user = options[:user] + if instance[:course] + course = instance[:course] + else + course = instance + end + current_user.member_of_course?(course) + end expose :teacher, using: Mobile::Entities::User do |c, opt| if c.is_a? ::Course c.teacher diff --git a/app/api/mobile/entities/project.rb b/app/api/mobile/entities/project.rb index 073f7cd0f..8da151b42 100644 --- a/app/api/mobile/entities/project.rb +++ b/app/api/mobile/entities/project.rb @@ -23,6 +23,16 @@ module Mobile current_user.id == instance.user_id end + expose :is_member, if: lambda { |instance, options| options[:user] } do |instance, options| + current_user = options[:user] + if instance[:project] + project = instance[:project] + else + project = instance + end + current_user.member_of?(project) + end + expose :member_count, if: lambda { |instance, options| options[:user] } do |instance, options| instance.members.count diff --git a/app/api/mobile/entities/syllabus.rb b/app/api/mobile/entities/syllabus.rb index e4dd2e07a..4e9f858c8 100644 --- a/app/api/mobile/entities/syllabus.rb +++ b/app/api/mobile/entities/syllabus.rb @@ -5,8 +5,8 @@ module Mobile expose :id expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options| current_user = options[:user] - can_setting = instance.user_id == current_user.id ? true : false - can_setting = false if instance.id.nil? + can_setting = instance[:user_id] == current_user.id ? true : false + can_setting = false if instance[:id].nil? can_setting end expose :courses, using: Mobile::Entities::Course diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 62d55b01d..25cc85ae2 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -61,7 +61,7 @@ class AdminController < ApplicationController if params[:syllabus_id] && params[:course_id] course = Course.where("id = #{params[:course_id].to_i}").first unless course.nil? - course.update_column('syllabus_id', params[:syllabus_id].to_i) + course.update_attribute(:syllabus_id, params[:syllabus_id].to_i) @flag = true end end @@ -82,7 +82,7 @@ class AdminController < ApplicationController syllabus.update_attributes(:title => params[:title], :eng_name => params[:eng_name], :user_id => @user.id) syllabus.description = Message.where("id = 19412").first.nil? ? nil : Message.where("id = 19412").first.content if syllabus.save - course.update_column('syllabus_id', syllabus.id) + course.update_attribute(:syllabus_id, params[:syllabus_id].to_i) @flag = params[:flag].to_i @course = course respond_to do |format| diff --git a/app/controllers/applied_project_controller.rb b/app/controllers/applied_project_controller.rb index 41f069020..30978367c 100644 --- a/app/controllers/applied_project_controller.rb +++ b/app/controllers/applied_project_controller.rb @@ -53,7 +53,7 @@ class AppliedProjectController < ApplicationController else @project = Project.find(params[:project_id]) end - if !@project || params[:invite_code].upcase.to_s != @project.invite_code + if !@project || params[:invite_code].strip.upcase.to_s != @project.invite_code @flag = 1 elsif User.current.member_of?(@project) @flag = 2 @@ -75,6 +75,8 @@ class AppliedProjectController < ApplicationController @project.project_infos << project_info @project.user_grades << user_grades unless user_grades.first.user_id.nil? + ps = ProjectsService.new + ps.send_wechat_join_project_notice User.current,@project,5,0 else @flag = 4 role = params[:member] == "member_manager" ? 3 : (params[:member] == "member_developer" ? 4 :5) diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 0e48cd962..66cbf27b8 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -10,7 +10,7 @@ class AtController < ApplicationController @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }.sort{|x,y| to_pinyin(x.show_name) <=> to_pinyin(y.show_name)} if users #加上all - if @user && @users.size > 0 + if User.current.logged? && @users.size > 0 allUser = Struct.new(:id, :name).new allUser.id = @users.map{|u| u.id}.join(",") allUser.name = "all" diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index ed2b2ebfa..cd3870e9a 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -77,19 +77,25 @@ class FilesController < ApplicationController if params[:insite] if q == "%%" @result = [] - @searched_attach = paginateHelper @result,10 + # @searched_attach = paginateHelper @result,10 else @result = find_public_attache q,sort @result = visable_attachemnts_insite @result,@course - @searched_attach = paginateHelper @result,10 + # @searched_attach = paginateHelper @result,10 end else @result = find_course_attache q,@course,sort @result = visable_attachemnts @result - @searched_attach = paginateHelper @result,10 - + # @searched_attach = paginateHelper @result,10 @tag_list = get_course_tag_list @course end + @all_attachments = @result + @limit = 10 + @feedback_count = @all_attachments.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 #rescue Exception => e # #render 'stores' # redirect_to search_course_files_url @@ -144,18 +150,26 @@ class FilesController < ApplicationController if params[:insite] if q == "%%" @project_attachment_result = [] - @searched_attach = paginateHelper @project_attachment_result, 10 + # @searched_attach = paginateHelper @project_attachment_result, 10 else @project_attachment_result = find_public_attache q,sort @project_attachment_result = visable_attachemnts_insite @project_attachment_result, @project - @searched_attach = paginateHelper @project_attachment_result, 10 + # @searched_attach = paginateHelper @project_attachment_result, 10 end else @project_attachment_result = find_project_attache q, @project,sort @project_attachment_result = visable_attachemnts @project_attachment_result - @searched_attach = paginateHelper @project_attachment_result,10 + # @searched_attach = paginateHelper @project_attachment_result,10 @tag_list = get_project_tag_list @project end + + @all_attachments = @project_attachment_result + @limit = 10 + @feedback_count = @all_attachments.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 #rescue Exception => e # #render 'stores' # redirect_to search_course_files_url @@ -867,7 +881,17 @@ class FilesController < ApplicationController else @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank? end - @searched_attach = paginateHelper @result,10 + + @all_attachments = @result + @limit = 10 + @feedback_count = @all_attachments.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 + + + # @searched_attach = paginateHelper @result,10 if @project @tag_list = get_project_tag_list @project @result_search_project = @result diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index f14416442..d661350c6 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -84,7 +84,8 @@ class MembersController < ApplicationController # 添加成功后,申请人收到消息 AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id , :status => 6, :viewed => false, :applied_user_id => @applied_message.user_id, :role => applied_project.role, :project_id => applied_project.project_id) - + ps = ProjectsService.new + ps.send_wechat_join_project_notice user,project,ap_role,0 # 添加成功后,批准人收到消息 # AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id , # :status => 7, :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => applied_project.role, :project_id => applied_project.project_id) @@ -114,6 +115,11 @@ class MembersController < ApplicationController @applied_message = AppliedMessage.find(params[:applied_message_id]) # AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 5, # :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => applied_project.role, :project_id => applied_project.project_id) + ps = ProjectsService.new + user = User.find(@applied_message.applied_user_id) + ap_role = applied_project.try(:role) + ps.send_wechat_join_project_notice user,project,ap_role,1 + applied_project.delete end diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 58d1cb3b2..5e21f9af0 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,7 +1,8 @@ class PullRequestsController < ApplicationController before_filter :find_project_and_repository - before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pull_request, :pull_request_commits, :pull_request_changes, :new] + before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pull_request, :pull_request_commits, :pull_request_changes, :new, + :update_pull_request, :pull_request_comments, :create_pull_request_comment] layout "base_projects" include PullRequestsHelper include ApplicationHelper @@ -14,9 +15,19 @@ class PullRequestsController < ApplicationController @requests = @g.merge_requests(@project.gpid).select{|request| request.state == "opened" || request.state == "reopened"} when "2" @requests = @g.merge_requests(@project.gpid).select{|request| request.state == "merged"} + when "3" + @requests = @g.merge_requests(@project.gpid).select{|request| request.state == "closed"} end @requests_opened_count = @requests.count - @requests_merged_count = params[:type] ? @requests.count : @g.merge_requests(@project.gpid).select{|request| request.state == "merged"}.count + @requests_merged_count = @g.merge_requests(@project.gpid).select{|request| request.state == "merged"}.count + @requests_closed_count = @g.merge_requests(@project.gpid).select{|request| request.state == "closed"}.count + + @limit = 10 + @is_remote = true + @count = type_count(type, @requests_opened_count, @requests_merged_count, @requests_closed_count) + @pages = Paginator.new @count, @limit, params['page'] || 1 + @offset ||= @pages.offset + @requests = paginateHelper @requests, 10 respond_to do |format| format.html format.js @@ -84,6 +95,15 @@ class PullRequestsController < ApplicationController @commits_count = @commits.count @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes) @changes_count = @changes.count + @comments = @g.merge_request_comments(@project.gpid, params[:id]).reverse + @comments_count = @comments.count + + @limit = 10 + @is_remote = true + @count = @comments_count + @pages = Paginator.new @count, @limit, params['page'] || 1 + @offset ||= @pages.offset + @comments = paginateHelper @comments, 10 end # Accept a merge request. @@ -99,6 +119,7 @@ class PullRequestsController < ApplicationController def accept_pull_request begin status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid) + PullRequest.create(:pull_request_id => status.id, :user_id => User.current.id, :gpid => status.project_id) respond_to do |format| format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)} end @@ -107,16 +128,110 @@ class PullRequestsController < ApplicationController end end - # 获取某次请求的提交次数 + # Updates a merge request. + # + # @example + # Gitlab.update_merge_request(5, 42, :title => 'New title') + # + # @param [Integer] project The ID of a project. + # @param [Integer] id The ID of a merge request. + # @param [Hash] options A customizable set of options. + # @option options [String] :title The title of a merge request. + # @option options [String] :source_branch The source branch name. + # @option options [String] :target_branch The target branch name. + # @option options [Integer] :assignee_id The ID of a user to assign merge request. + # @option options [String] :state_event New state (close|reopen|merge). + # @return [Gitlab::ObjectifiedHash] Information about updated merge request. + def update_pull_request + begin + @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) + respond_to do |format| + format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)} + end + rescue Exception => e + @message = e.message + end + end + + # Creates a merge request. + # + # @example + # Gitlab.create_merge_request(5, 'New merge request', + # :source_branch => 'source_branch', :target_branch => 'target_branch') + # Gitlab.create_merge_request(5, 'New merge request', + # :source_branch => 'source_branch', :target_branch => 'target_branch', :assignee_id => 42) + def create_pull_request_comment + content = params[:pull_request_comment] + begin + @comments = @g.create_merge_request_comment(@project.gpid, params[:id], content, User.current.gid) + respond_to do |format| + format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)} + end + rescue Exception => e + @message = e.message + end + end + + # Gets the comments on a merge request. + # + # @example + # Gitlab.merge_request_comments(5, 1) + def pull_request_comments + begin + @comments = @g.merge_request_comments(@project.gpid, params[:id]).reverse + @comments_count = @comments.count + + @limit = 10 + @is_remote = true + @count = @comments_count + @pages = Paginator.new @count, @limit, params['page'] || 1 + @offset ||= @pages.offset + @comments = paginateHelper @comments, 10 + rescue Exception => e + @message = e.message + end + end + + # Get a list of merge request commits. + # Parameters: + # id (required) - The ID of a project + # merge_request_id (required) - The ID of MR def pull_request_commits - @type = parms[:type] - @commits = @g.merge_request_commits(@project.gpid, params[:id].to_i) + begin + @type = params[:type] + @commits = @g.merge_request_commits(@project.gpid, params[:id]) + @commits_count = @commits.count + + @limit = 10 + @is_remote = true + @count = @commits_count + @pages = Paginator.new @count, @limit, params['page'] || 1 + @offset ||= @pages.offset + @commits = paginateHelper @commits, 10 + rescue Exception => e + @message = e.message + end end - # 获取某次请求的改动 + # Shows information about the merge request including its files and changes. With GitLab 8.2 the return fields upvotes and downvotes are deprecated and always return 0. + # Parameters: + # id (required) - The ID of a project + # merge_request_id (required) - The ID of MR def pull_request_changes - @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes) - @changes_count = @changes.count + begin + @type = params[:type] + @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes) + @changes_count = @changes.count + + @limit = 10 + @is_remote = true + @count = @changes_count + @pages = Paginator.new @count, @limit, params['page'] || 1 + @offset ||= @pages.offset + @changes = paginateHelper @changes, 10 + rescue Exception => e + @message = e.message + end end private diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index c9873ade4..a0b275dc7 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -17,6 +17,7 @@ class QualityAnalysisController < ApplicationController # params 说明:{identifier:版本库名} def create + logger.info("11111111111111111111111111111") begin user_name = User.find(params[:user_id]).try(:login) identifier = params[:identifier] @@ -32,12 +33,13 @@ class QualityAnalysisController < ApplicationController projects_date = open(@sonar_address + "/api/projects/index").read arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] quality_an = QualityAnalysis.where(:sonar_name => sonar_name).first - if @client.job.exists?(job_name) && QualityAnalysis.where(:sonar_name => sonar_name).select{|qa| arr.include?(qa.sonar_name)}.blank? - aa = @client.job.delete("#{job_name}") + if @client_jenkins.job.exists?(job_name) && QualityAnalysis.where(:sonar_name => sonar_name).select{|qa| arr.include?(qa.sonar_name)}.blank? + aa = @client_jenkins.job.delete("#{job_name}") quality_an.delete unless quality_an.blank? end + # Checks if the given job exists in Jenkins. - # unless @client.job.exists?(job_name) + unless @client_jenkins.job.exists?(job_name) @g = Gitlab.client branch = params[:branch] language = swith_language_type(params[:language]) @@ -59,20 +61,20 @@ class QualityAnalysisController < ApplicationController @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties # jenkins job创建 - jenkins_job = @client.job.create("#{job_name}", @doc.to_xml) + jenkins_job = @client_jenkins.job.create("#{job_name}", @doc.to_xml) logger.info("Jenkins status of create ==> #{jenkins_job}") # 将地址作为hook值添加到gitlab @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}") # job创建完成后自动运行job,如果运行成功则返回‘200’ - code = @client.job.build("#{job_name}") + code = @client_jenkins.job.build("#{job_name}") logger.error("build result ==> #{code}") # 判断调用sonar分析是否成功 # 等待启动时间处理, 最长时间为30分钟 for i in 0..360 do sleep(5) - @current_build_status = @client.job.get_current_build_status("#{job_name}") + @current_build_status = @client_jenkins.job.get_current_build_status("#{job_name}") if (@current_build_status == "success" || @current_build_status == "failure") break if i == 360 @@ -86,7 +88,7 @@ class QualityAnalysisController < ApplicationController sleep(10) # 获取sonar output结果 - console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] + console_build = @client_jenkins.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] logger.info("@current_build_status is ==> #{@current_build_status}") # 两种情况需要删除job: @@ -94,14 +96,14 @@ class QualityAnalysisController < ApplicationController # 2/creat和build成功,调用sonar启动失败则删除job # 错误信息存储需存到Trustie数据库,否则一旦job删除则无法获取这些信息 if jenkins_job == '200' && code != '201' - @client.job.delete("#{job_name}") + @client_jenkins.job.delete("#{job_name}") else if @current_build_status == "failure" reg_console = /Exception:.*?\r/.match(console_build) output = reg_console[0].gsub("\r", "") unless reg_console.nil? se = SonarError.where(:jenkins_job_name => job_name).first se.nil? ? SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => output) : se.update_column(:output, output) - @client.job.delete("#{job_name}") + @client_jenkins.job.delete("#{job_name}") elsif @current_build_status == "success" if quality_an.blank? QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, @@ -111,17 +113,24 @@ class QualityAnalysisController < ApplicationController end end end - # end + + respond_to do |format| + if @current_build_status == "success" + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)} + elsif @current_build_status == "failure" + format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name)} + end + end + end rescue => e @message = e.message - end - respond_to do |format| - if @current_build_status == "success" - format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)} - elsif @current_build_status == "failure" - format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name)} + logger.error("######################====>#{e.message}") + respond_to do |format| + format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name, :message => @message)} + # format.html{redirect_to :controller => 'repositories', :action => 'show', :id => @project, :repository_id => identifier} end end + end def error_list @@ -159,9 +168,9 @@ class QualityAnalysisController < ApplicationController rep_id = Repository.where(:project_id => @project.id, :identifier => qa.rep_identifier).first.try(:id) job_name = "#{qa.author_login}-#{rep_id}" logger.info("result: job_name ###################==>#{job_name}") - logger.info("result: @client.job ###################==>#{@client.job}") + logger.info("result: @client_jenkins.job ###################==>#{@client_jenkins.job}") - d_job = @client.job.delete(job_name) + d_job = @client_jenkins.job.delete(job_name) logger.info("result: delete job ###################==>#{d_job}") qa.delete respond_to do |format| @@ -198,7 +207,7 @@ class QualityAnalysisController < ApplicationController @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties # update成功则返回 ‘200’ - jenkins_job = @client.job.update("#{job_name}", @doc.to_xml) + jenkins_job = @client_jenkins.job.update("#{job_name}", @doc.to_xml) # 数据更新到Trustie数据 if jenkins_job == '200' logger.info("quality_ananlysis will be updated: ==> #{jenkins_job}") @@ -278,9 +287,10 @@ class QualityAnalysisController < ApplicationController @jenkins_address = Redmine::Configuration['jenkins_address'] jenkins_username = Redmine::Configuration['jenkins_username'] jenkins_password = Redmine::Configuration['jenkins_password'] - + logger.info("22222222222222222222222222222222") # connect jenkins - @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => jenkins_username, :password => jenkins_password) + @client_jenkins = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => jenkins_username, :password => jenkins_password) + logger.info("333333333333333333333333333333") rescue => e logger.error("failed to connect Jenkins ==> #{e}") end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 65b4a15d6..a79890870 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -386,9 +386,9 @@ update project_score.update_column(:changeset_num, @changesets_all_count) end - # unless @changesets_latest_coimmit.blank? - # update_commits_date(@project, @changesets_latest_coimmit) - # end + unless @changesets_latest_coimmit.blank? + update_commits_date(@project, @changesets_latest_coimmit) + end @creator = @project.owner.to_s gitlab_address = Redmine::Configuration['gitlab_address'] diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index adfcd6263..722845ef7 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -597,6 +597,7 @@ class StudentWorkController < ApplicationController student_work.description = params[:student_work][:description] student_work.homework_common_id = @homework.id student_work.user_id = User.current.id + student_work.commit_time = Time.now student_work.save_attachments(params[:attachments]) render_attachment_warning_if_needed(student_work) if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 @@ -791,7 +792,7 @@ class StudentWorkController < ApplicationController end end elsif @homework.homework_type == 1 - @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0) + @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil) end @student_work = StudentWork.new respond_to do |format| @@ -826,7 +827,7 @@ class StudentWorkController < ApplicationController @new_score.user_id = User.current.id @new_score.student_work_id = @work.id if @is_teacher && @work.work_status == 0 - @work.update_column('work_status', 1) + @work.update_attributes(:work_status => 1, :commit_time => Time.now) end if User.current.admin? @new_score.reviewer_role = 1 @@ -867,6 +868,7 @@ class StudentWorkController < ApplicationController update_org_activity(@homework.class,@homework.id) if @work.save @work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => @work.id).first + @count = @homework.student_works.has_committed.count respond_to do |format| format.js end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 932617671..e929153ad 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -42,7 +42,7 @@ class UsersController < ApplicationController :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, - :my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks] + :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -353,14 +353,14 @@ class UsersController < ApplicationController def dealwith_apply_request @msg = CourseMessage.find(params[:msg_id]) #CourseMessage content存的是role 7教辅 9 教师 + apply_user = User.find(@msg.course_message_id) + ids = @msg.content.split(",") # [@msg.content] msg content保存的是申请的职位角色 + integer_ids = [] + ids.each do |role_id| + integer_ids << role_id.to_i + end case params[:agree] when 'Y' - apply_user = User.find(@msg.course_message_id) - ids = @msg.content.split(",") # [@msg.content] msg content保存的是申请的职位角色 - integer_ids = [] - ids.each do |role_id| - integer_ids << role_id.to_i - end if apply_user.member_of_course?(Course.find(@msg.course_id)) #将角色改为老师或者教辅 member = Course.find(@msg.course_id).members.where(:user_id=>apply_user.id).all[0] @@ -383,11 +383,32 @@ class UsersController < ApplicationController Course.find(@msg.course_id).members << members CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) @msg.update_attributes(:status=>1,:viewed=>1) + + if integer_ids.include?(9) + cs = CoursesService.new + c = Course.find(@msg.course_id) + cs.send_wechat_join_class_notice apply_user,c,9,0 + else + cs = CoursesService.new + c = Course.find(@msg.course_id) + cs.send_wechat_join_class_notice apply_user,c,7,0 + end end when 'N' CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>2) @msg.update_attributes(:status=>2,:viewed=>1) + + if integer_ids.include?(9) + cs = CoursesService.new + c = Course.find(@msg.course_id) + cs.send_wechat_join_class_notice apply_user,c,9,1 + else + cs = CoursesService.new + c = Course.find(@msg.course_id) + cs.send_wechat_join_class_notice apply_user,c,7,1 + end + end respond_to do |format| format.js @@ -599,7 +620,7 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") #我的题库 courses = @user.courses.where("is_delete = 1") course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}") + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids}").order("#{@order} #{@b_sort}") elsif params[:type] == "2" #公共题库 visible_course = Course.where("is_delete = 0") visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" @@ -1004,6 +1025,7 @@ class UsersController < ApplicationController student_work.work_status = 1 end + student_work.commit_time = Time.now student_work.save send_message_to_teacher(student_work) homework.update_column(:updated_at, Time.now) @@ -1460,6 +1482,7 @@ class UsersController < ApplicationController def user_projects4show @page = params[:page].to_i + 1 @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10).offset(@page * 10) + @all_count = @user.projects.visible.count end def user_course_activities @@ -1533,7 +1556,7 @@ class UsersController < ApplicationController stu_courses = @user.courses.visible.not_deleted.select{|course| @user.has_student_role(course)} stu_course_ids = stu_courses.empty? ? "(-1)" : "(" + stu_courses.map{|course| course.id}.join(',') + ")" @receive_homeworks = HomeworkCommon.where("course_id in #{stu_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc").limit(5) - if (@manage_homeworks.empty? && @receive_homeworks.empty?) || (@receive_homeworks.empty?) || (!@manage_homeworks.empty? && !@receive_homeworks.empty? && @manage_homeworks.first.publish_time > @receive_homeworks.first.publish_time) + if (@manage_homeworks.empty? && @receive_homeworks.empty?) || (@receive_homeworks.empty?) || (!@manage_homeworks.empty? && !@receive_homeworks.empty? && @manage_homeworks.first.created_at > @receive_homeworks.first.created_at) @manage_pre = true else @manage_pre = false @@ -3417,7 +3440,22 @@ class UsersController < ApplicationController end def user_projectlist - @order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + @order, @c_sort, @type, @list_type = 1, 2, 1, 1 + #limit = 5 + + @my_projects = @user.projects.visible.where("projects.user_id = #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_projects_count = @my_projects.count + + @my_joined_projects = @user.projects.visible.where("projects.user_id != #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_joined_projects_count = @my_joined_projects.count + respond_to do |format| + format.html {render :layout => 'new_base_user'} + end + end + + def sort_project_list + @order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1 + #limit = 5 #确定 sort_type if @order.to_i == @type.to_i @@ -3426,11 +3464,16 @@ class UsersController < ApplicationController @c_sort = 2 end - sort_name = "updated_at" + sort_name = "updatetime" sort_type = @c_sort == 1 ? "asc" : "desc" #@projects = @user.projects.visible.order("#{sort_name} #{sort_type}") - @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name} ").order("#{sort_name} #{sort_type}") + if @list_type.to_i == 1 + @projects = @user.projects.visible.where("projects.user_id = #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + else + @projects = @user.projects.visible.where("projects.user_id != #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + end + @projects_count = @projects.count #根据 问题+资源数排序 @project.project_score.issue_num @project.project_score.attach_num if @order.to_i == 2 @@ -3447,18 +3490,8 @@ class UsersController < ApplicationController @type = 1 end - #分页 - @limit = 10 - @is_remote = true - @atta_count = @projects.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - @projects = paginateHelper @projects,@limit - @is_project = 1 - respond_to do |format| format.js - format.html {render :layout => 'new_base_user'} end end diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index c5ef8c24e..cfa5f4414 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -137,7 +137,7 @@ class WechatsController < ActionController::Base on :fallback, respond: 'fallback message' on :click, with: 'FEEDBACK' do |request, key| - request.reply.text "如有反馈问题,请直接切换至输入框,发微信给我们即可" + request.reply.text "如有问题反馈,请您:\n1、直接切换至输入框,发微信给我们。\n2、加入QQ群:173184401,我们直接互动。\n欢迎大家积极反馈,谢谢啦!" end on :click, with: 'MY_NEWS' do |request, key| @@ -252,13 +252,16 @@ class WechatsController < ActionController::Base end def sendBind(request) + tmpurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=login&connect_redirect=1#wechat_redirect" + logger.info "tmpurl!!!!!!!!!!!!!!" + logger.info tmpurl news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "欢迎使用Trustie创新实践服务平台! 在这里您可以随时了解您的课程和项目动态,随时点赞和回复。 我们将会与微信不断结合,为您提供更有价值的服务。 您还未绑定确实的用户,请先绑定,谢谢!" } } request.reply.news(news) do |article, n, index| # article is return object - url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=login#wechat_redirect" + url = tmpurl pic_url = "#{ROOT_URL}/images/weixin_pic.jpg" article.item title: "#{n[:title]}", description: n[:content], @@ -284,7 +287,7 @@ class WechatsController < ActionController::Base end news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!', - content: "课程名称:#{course.name}\n班级名称:#{course.name}\n任课老师:#{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} } + content: "课程名称:#{course.syllabus.title}\n班级名称:#{course.name}\n任课老师:#{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} } return request.reply.news(news) do |article, n, index| # article is return object url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities#/class?id='+course.id.to_s}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect" pic_url = "#{ROOT_URL}/images/wechat/class.jpg" @@ -314,7 +317,7 @@ class WechatsController < ActionController::Base creator = User.find(project.user_id) news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入项目,开始研发吧!', - content: "项目名称:#{project.name}\n发起人:#{creator.name}\n进入项目,和小伙伴轻松的研发吧!"} } + content: "项目名称:#{project.name}\n发起人:#{creator.show_name}\n进入项目,和小伙伴轻松的研发吧!"} } return request.reply.news(news) do |article, n, index| # article is return object url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities#/project?id='+project.id.to_s}&response_type=code&scope=snsapi_base&state=myproject#wechat_redirect" pic_url = "#{ROOT_URL}/images/wechat/project.jpg" @@ -333,10 +336,12 @@ class WechatsController < ActionController::Base code = params[:code] || session[:wechat_code] openid = get_openid_from_code(code) - raise "无法获取到微信openid" unless openid + # raise "无法获取到微信openid" unless openid + + raise "请在微信中关注Trustie创新实践平台后再打开本页面" unless openid uw = UserWechat.where(openid: openid).first - raise "还未绑定trustie帐户" unless uw + raise "还未绑定trustie帐户" unless (uw && uw.bindtype == 0) logger.debug "get_bind ============= #{uw}" user = uw.user @@ -349,13 +354,25 @@ class WechatsController < ActionController::Base end end + def is_bind + begin + code = params[:code] || session[:wechat_code] + open_id = get_openid_from_code(code) + raise "还未绑定trustie帐户" unless user_binded?(open_id) + render :json => {status: 0} + rescue Exception=>e + render :json => {status: -1, message: e.message} + end + end + def bind begin code = params[:code] || session[:wechat_code] openid = get_openid_from_code(code) - raise "无法获取到openid,请在微信中打开本页面" unless openid + # raise "无法获取到openid,请在微信中打开本页面" unless openid + raise "请在微信中关注Trustie创新实践平台后再打开本页面" unless openid raise "此微信号已绑定用户,不能重复绑定" if user_binded?(openid) user, last_login_on = User.try_to_login(params[:username], params[:password]) @@ -369,7 +386,7 @@ class WechatsController < ActionController::Base user: user ) ws = WechatService.new - ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台!", user.login, format_time(Time.now)) + ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台!", user.show_name+"("+user.login+")", format_time(Time.now)) render :json => {status:0, msg: "绑定成功"} rescue Exception=>e render :json => {status: -1, msg: e.message} @@ -398,8 +415,16 @@ class WechatsController < ActionController::Base unless open_id render 'wechats/open_wechat', layout: nil and return end + + logger.info "user_activities!!!!!!!!!!!!!!" + logger.info params + + #保证下面的redirect_to "/wechat/user_activities##{@path}?id=...不会往下走 + if params[:state] == nil + return + end - unless user_binded?(open_id) + unless (user_binded?(open_id) || params[:state] == "invite_code" || params[:state] == "project_invite_code" || params[:state] == "blog_comment" || params[:state] == "course_notice" || params[:state] == "project_discussion" || params[:state] == "course_discussion" || params[:state] == "homework" || params[:state] == "issues" || params[:state] == "journal_for_message") @path = '/login' else if params[:state] == 'myclass' @@ -410,7 +435,14 @@ class WechatsController < ActionController::Base session[:wechat_openid] = open_id if params[:code] - redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return + if params[:userid] + redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}&userid=#{params[:userid]}" and return + elsif params[:id] + redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return + else + redirect_to "/wechat/user_activities##{@path}" and return + end + # redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return end end render 'wechats/user_activities', layout: nil @@ -421,10 +453,19 @@ class WechatsController < ActionController::Base def get_openid_from_code(code) return 'oCnvgvz8R7QheXE-R9Kkr39j8Ndg' if code =='only-for-test' openid = session[:wechat_openid] - unless openid if code - openid = wechat.web_access_token(code)["openid"] + #不能联系调两次web_access_token 否则会提示请在微信客户端打开次链接 + info = wechat.web_access_token(code) + openid =info["openid"] + access_token =info["access_token"] + if access_token + session[:access_token] = access_token + end + refresh_token = info["refresh_token"] + if refresh_token + session[:refresh_token] = refresh_token + end end end @@ -437,6 +478,11 @@ class WechatsController < ActionController::Base def user_binded?(openid) uw = UserWechat.where(openid: openid).first + if uw && uw.bindtype == 0 + uw + else + nil + end end def current_url diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 942016976..0c0e0919e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2172,7 +2172,7 @@ module ApplicationHelper candown = User.current.member_of_org?(org) || ((attachment.is_public == 1 || attachment.get_status_by_attach(User.current.id) == 2) && org.allow_guest_download == true) elsif attachment.container.is_a?(OrgDocumentComment) org = attachment.container.organization - candown = User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1) + candown = org.allow_guest_download || User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1) elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && attachment.container.board.course course = attachment.container.board.course @@ -2738,7 +2738,7 @@ module ApplicationHelper link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red' end else - if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 #匿评作业,且作业状态不是在开启匿评之前 + if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前 link_to "作品匿评", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品" elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "匿评已结束" @@ -2841,7 +2841,7 @@ module ApplicationHelper #获取当前作业的提交截止时间/互评截止时间 def cur_homework_end_time homework str = "" - if homework.anonymous_comment == 0 && homework.end_time < Date.today && homework.homework_detail_manual + if homework.anonymous_comment == 0 && homework.end_time && homework.end_time < Date.today && homework.homework_detail_manual str = "互评截止:#{format_date homework.homework_detail_manual.evaluation_end}" else str = "提交截止:#{homework.end_time ? (format_date homework.end_time) : '       --       '}" @@ -3436,3 +3436,9 @@ def course_syllabus_option user = User.current end type end + +# 获取项目动态更新时间 +def get_forge_act_message(act, type) + forge_act = ForgeActivity.where(:forge_act_id => act.id, :forge_act_type => type).first + format_time(forge_act.nil? ? act.created_on : forge_act.try(:updated_at)) +end diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index 048d92458..48b5f068b 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -18,12 +18,6 @@ module OrganizationsHelper s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" ) end - # 获取项目动态更新时间 - def get_forge_act_message(act, type) - forge_act = ForgeActivity.where(:forge_act_id => act.id, :forge_act_type => type).first - format_time(forge_act.nil? ? act.created_on : forge_act.try(:updated_at)) - end - def get_default_name field case field.name when 'activity' then diff --git a/app/helpers/pull_requests_helper.rb b/app/helpers/pull_requests_helper.rb index 82d4edc0f..07b022358 100644 --- a/app/helpers/pull_requests_helper.rb +++ b/app/helpers/pull_requests_helper.rb @@ -14,4 +14,37 @@ module PullRequestsHelper User.find(user_id).try(:login) end + # 获取接受PullRequest用户的信息 + def accept_user pull_request_id + PullRequest.where(:pull_request_id => pull_request_id).first + end + + def get_state state + case state + when "open","reopened" + l(:label_state_open) + when "closed" + l(:label_state_closed) + when "merged" + l(:label_state_merged) + end + end + + def type_count type, requests_opened_count, requests_merged_count, requests_closed_count + case type + when nil, "1" + requests_opened_count + when "2" + requests_merged_count + when "3" + requests_closed_count + end + end + + # 判断是否允许创建Pull Request + # 如果分支相同,并且项目相同则提示 + def judge_pr_allow + + end + end diff --git a/app/helpers/quality_analysis_helper.rb b/app/helpers/quality_analysis_helper.rb index 5940dd255..f7dbf3469 100644 --- a/app/helpers/quality_analysis_helper.rb +++ b/app/helpers/quality_analysis_helper.rb @@ -1,23 +1,33 @@ # encoding: utf-8 module QualityAnalysisHelper + def sonar_time sonar_name + sonar = open(@sonar_address + "/api/resources/index?resource=#{sonar_name}&depth=0").read + sonar =JSON.parse(sonar).first['date'] + end + def sqale_rating_status val arr = [] if val <= 5 arr << "很好" arr << "b_green2" + arr << "A" elsif val. > 5 && val <= 10 arr << "较好" arr << "b_slow_yellow" + arr << "B" elsif val > 10 && val <= 20 arr << "中等" arr << "b_yellow" + arr << "C" elsif val > 20 && val <= 50 arr << "较差" arr << "b_slow_red" + arr << "D" elsif val > 20 arr << "很差" arr << "b_red" + arr << "E" end end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index ef637d3ee..bc5e8ee57 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -47,9 +47,9 @@ module RepositoriesHelper end # 获取文件目录的最新动态 - def get_trees_last_changes(project_id, rev, ent_name, g) + def get_trees_last_changes(gpid, rev, ent_name, g) begin - tree_changes = g.rep_last_changes(project_id, :rev => rev, :path => ent_name) + tree_changes = g.rep_last_changes(gpid, :rev => rev, :path => ent_name) rescue Exception => e puts e end diff --git a/app/models/course.rb b/app/models/course.rb index 561a031ae..659f9fcec 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -80,6 +80,7 @@ class Course < ActiveRecord::Base after_update :update_files_public,:update_course_ealasticsearch_index after_create :create_board_sync, :act_as_course_activity, :act_as_course_message,:create_course_ealasticsearch_index before_destroy :delete_all_members,:delete_course_ealasticsearch_index + after_save :log_infor safe_attributes 'extra', 'time', @@ -504,6 +505,10 @@ class Course < ActiveRecord::Base ticket end + def log_infor + Rails.logger.info "##########################################################course's syllabus_id is #{self.syllabus_id}." + end + end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 86aab8260..a901e6338 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -77,7 +77,7 @@ class HomeworkCommon < ActiveRecord::Base count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count if count == 0 ws = WechatService.new - ws.homework_message_notice(m.user_id, "homework", self.id, "#{m.user.show_name},#{l(:label_new_homework_template)}:", self.course.name, "新作业:"+ self.name.html_safe, "作业内容请点击“详情”查看。") + ws.homework_message_notice(m.user_id, "homework", self.id, "#{m.user.show_name},#{l(:label_new_homework_template)}", self.course.name, "新作业:"+ self.name.html_safe, "作业内容请点击“详情”查看。") end # end end diff --git a/app/models/news.rb b/app/models/news.rb index 54f6fce08..cd7156cca 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -173,7 +173,7 @@ class News < ActiveRecord::Base count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count if count == 0 ws = WechatService.new - content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200 + content = self.title ws.class_notice m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.course.name, self.author.show_name, format_time(self.created_on), content, "点击查看通知详情" end end diff --git a/app/models/project.rb b/app/models/project.rb index 0751c902f..0d297bb3c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1254,12 +1254,14 @@ class Project < ActiveRecord::Base def create_project_ealasticsearch_index + return if Rails.env.development? if self.is_public self.__elasticsearch__.index_document end end def update_project_ealasticsearch_index + return if Rails.env.development? if self.is_public #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 begin self.__elasticsearch__.update_document @@ -1276,6 +1278,7 @@ class Project < ActiveRecord::Base end def delete_project_ealasticsearch_index + return if Rails.env.development? begin self.__elasticsearch__.delete_document rescue => e diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb new file mode 100644 index 000000000..f40397cf0 --- /dev/null +++ b/app/models/pull_request.rb @@ -0,0 +1,4 @@ +class PullRequest < ActiveRecord::Base + attr_accessible :gpid, :pull_request_id, :user_id + validates_uniqueness_of :pull_request_id +end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 3ba3ee2b2..09ef15583 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -1,6 +1,6 @@ #学生提交作品表 class StudentWork < ActiveRecord::Base - attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test, :simi_id, :simi_value, :work_status + attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time belongs_to :homework_common belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index 57663f3eb..b863c1f70 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -228,7 +228,7 @@ class User < Principal # Prevents unauthorized assignments attr_protected :login, :admin, :password, :password_confirmation, :hashed_password - LOGIN_LENGTH_LIMIT = 25 + LOGIN_LENGTH_LIMIT = 30 MAIL_LENGTH_LIMIT = 60 validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } diff --git a/app/models/user_wechat.rb b/app/models/user_wechat.rb index 49053dbf0..c63411ab3 100644 --- a/app/models/user_wechat.rb +++ b/app/models/user_wechat.rb @@ -1,6 +1,27 @@ class UserWechat < ActiveRecord::Base attr_accessible :subscribe, :openid, :nickname, :sex, :language, :city, :province, :country, - :headimgurl, :subscribe_time, :unionid, :remark, :groupid, :user, :user_id + :headimgurl, :subscribe_time, :unionid, :remark, :groupid, :user, :user_id, :bindtype belongs_to :user + + def real? + bindtype == 0 + end + + def migrate_user(u) + self.bindtype = 0 + old_user = user.id + self.user = u + self.save + + ## 主要是将comment 迁移 + User.delete(old_user) + + JournalsForMessage.where(user_id: old_user).update_all(user_id: u.id) + Journal.where(user_id: old_user).update_all(user_id: u.id) + Comment.where(author_id: old_user).update_all(author_id: u.id) + Message.where(author_id: old_user).update_all(author_id: u.id) + BlogComment.where(author_id: old_user).update_all(author_id: u.id) + UserActivity.where(user_id: old_user).update_all(user_id: u.id) + end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index c6854f3dd..7d574bada 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -97,7 +97,7 @@ class CoursesService end users = [] @members.each do |m| - img_url = url_to_avatar(m.user) + img_url = "/images/"+url_to_avatar(m.user) gender = m.user.user_extensions.gender.nil? ? 0 : m.user.user_extensions.gender work_unit = get_user_work_unit m.user location = get_user_location m.user @@ -108,14 +108,14 @@ class CoursesService end #双重身份 学生列表中不显示 - unless (params[:role] == '2' && role_ids.length >= 2) + # unless (params[:role] == '2' && role_ids.length >= 2) users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, :work_unit => work_unit, :mail => m.user.mail, :location => location, role_name: m.roles.first.name, name: m.user.show_name, roles_id: role_ids.include?(7) ? 7 : (role_ids.include?(9) ? 9 : 10 ), :brief_introduction => m.user.user_extensions.brief_introduction,:realname=>m.user.realname} - end + # end end users @@ -223,16 +223,20 @@ class CoursesService end if integer_ids.include?(9) message = "您已同意教师"+apply_user.show_name+",加入班级" + send_wechat_join_class_notice apply_user,c,9,0 else message = "您已同意助教"+apply_user.show_name+",加入班级" + send_wechat_join_class_notice apply_user,c,7,0 end else CourseMessage.create(:user_id => apply_user.id, :course_id => c.id, :viewed => false,:content=> messages.content,:course_message_id=>current_user.id,:course_message_type=>'CourseRequestDealResult',:status=>2) messages.update_attributes(:status=>2,:viewed=>1) if integer_ids.include?(9) message = "您已拒绝教师"+apply_user.show_name+",加入班级" + send_wechat_join_class_notice apply_user,c,9,1 else message = "您已拒绝助教"+apply_user.show_name+",加入班级" + send_wechat_join_class_notice apply_user,c,7,1 end end status = 0 @@ -528,6 +532,33 @@ class CoursesService {:state => @state,:course => course} end + #加入班级结果 + def send_wechat_join_class_notice user,course,role_id,result + count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count + if count == 0 + ws = WechatService.new + + role_name = role_id == 7 ? "助教" : role_id == 9 ? "教师" : "学生" + result_name = result == 0 ? "通过" : "被拒绝" + content = "您以"+role_name+"身份加入班级的申请已"+result_name+"。" + + if result == 0 + title = "恭喜您加入班级成功。" + remark = "点击查看班级详情。" + uid = 0 + type = "class" + else + title = "很遗憾您未能成功加入班级。" + remark = "点击查看申请详情。" + uid = user.id + type = "review_class_member" + end + ws = WechatService.new + ws.class_notice user.id, type, course.id, title, course.name, user.show_name, format_time(Time.now), content, remark,uid + + end + end + #多个角色加入课程 def join_course_roles params,current_user course = Course.find_by_invite_code(params[:invite_code]) if params[:invite_code] @@ -587,6 +618,7 @@ class CoursesService course.members << members StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) @state = 0 + send_wechat_join_class_notice current_user,course,10,0 else is_stu = false if role_ids.include?("10") @@ -595,6 +627,7 @@ class CoursesService course.members << members StudentsForCourse.create(:student_id => current_user.id, :course_id =>course.id) is_stu = true + send_wechat_join_class_notice current_user,course,10,0 end #如果已经发送过消息了,那么就要给个提示 if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = '#{role_str}' and course_message_id = #{current_user.id} and course_id = #{course.id} and status = 0").count != 0 diff --git a/app/services/homework_service.rb b/app/services/homework_service.rb index dd42795b1..04680f76f 100644 --- a/app/services/homework_service.rb +++ b/app/services/homework_service.rb @@ -256,7 +256,7 @@ class HomeworkService jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC") jours.each do |jour| user = jour.user - img_url = url_to_avatar(jour.user) + img_url = "/images/"+url_to_avatar(jour.user) datetime = jour.created_on content = jour.notes end diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb index 1b342c122..56dfaceff 100644 --- a/app/services/projects_service.rb +++ b/app/services/projects_service.rb @@ -117,6 +117,27 @@ class ProjectsService ] end + #加入项目结果 + def send_wechat_join_project_notice user,project,role_id,result + count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Project' and shield_id=#{project.id}").count + if count == 0 + result_name = result == 0 ? "已同意" : "已拒绝" + if result == 0 + title = "恭喜您加入项目成功。" + remark = "点击查看项目详情。" + uid = 0 + type = "project" + else + title = "很遗憾您未能成功加入项目。" + remark = "点击查看申请详情。" + uid = user.id + type = "review_project_member" + end + ws = WechatService.new + ws.join_project_notice user.id, "project", project.id,title, project.name,result_name, remark,uid + end + end + def join_project params,current_user status = -1 project = Project.find_by_invite_code(params[:invite_code]) if params[:invite_code] @@ -128,6 +149,10 @@ class ProjectsService if current_user.member_of?(project) #如果已经是成员 member = project.member_principals.includes(:roles, :principal).where("user_id=?",current_user.id).first status = member.member_roles[0].role_id + + #将之前的申请都改为已拒绝 + applied_messages = AppliedMessage.where(:project_id => project.id, :status => true, :applied_user_id=>current_user.id,:applied_type => "AppliedProject") + applied_messages.update_all(:status=>5) else if params[:invite_code].present? @@ -146,6 +171,11 @@ class ProjectsService project.project_infos << project_info status = 0 + send_wechat_join_project_notice current_user,project,5,0 + + #将之前的申请都改为已拒绝 + applied_messages = AppliedMessage.where(:project_id => project.id, :status => true, :applied_user_id=>current_user.id,:applied_type => "AppliedProject") + applied_messages.update_all(:status=>5) else if !AppliedProject.where(:project_id => project.id, :user_id => current_user.id).first.nil? status = 8 @@ -181,7 +211,7 @@ class ProjectsService user = User.find(m.applied_user_id) if user - img_url = url_to_avatar(user) + img_url = "/images/"+url_to_avatar(user) gender = user.user_extensions.gender.nil? ? 0 : user.user_extensions.gender work_unit = get_user_work_unit user location = get_user_location user @@ -210,7 +240,7 @@ class ProjectsService status = applied_message.status user = User.find(params[:user_id]) if user - img_url = url_to_avatar(user) + img_url = "/images/"+url_to_avatar(user) gender = user.user_extensions.gender.nil? ? 0 : user.user_extensions.gender work_unit = get_user_work_unit user location = get_user_location user @@ -239,7 +269,12 @@ class ProjectsService if apply_message if user.member_of?(project) message = "已经是该项目的成员了" - applied_messages.update_all(:status=>7) + u_member = project.member_principals.includes(:roles, :principal).where("user_id=?",params[:user_id]).first + if u_member.member_roles[0].role_id == 5 + applied_messages.update_all(:status=>5) + else + applied_messages.update_all(:status=>7) + end else applied_project = apply_message.applied ap_role = applied_project.try(:role) @@ -266,6 +301,8 @@ class ProjectsService message = "您已同意"+rolename+user.show_name+",加入项目" + send_wechat_join_project_notice user,project,ap_role,0 + else #拒绝 AppliedMessage.create(:user_id => user.id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 4, @@ -275,6 +312,8 @@ class ProjectsService applied_project.delete message = "您已拒绝"+rolename+user.show_name+",加入项目" + + send_wechat_join_project_notice user,project,ap_role,1 end status = 0 diff --git a/app/services/syllabuses_service.rb b/app/services/syllabuses_service.rb index fcb70653b..f12ae67cc 100644 --- a/app/services/syllabuses_service.rb +++ b/app/services/syllabuses_service.rb @@ -36,24 +36,21 @@ class SyllabusesService # courses.each do |c| # other.courses << c[:course] unless c[:course].syllabus # end + result = [] + i = 0 courses = user.courses.not_deleted syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" syllabuses = Syllabus.where("id in #{syllabus_ids} or user_id = #{user.id}").order("updated_at desc") syllabuses.each do |syllabus| - syllabus.courses = courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("time desc") + tmp_courses = courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + result[i] = {:title=>syllabus.title, :id=>syllabus.id , :user_id=>syllabus.user_id,:courses=>tmp_courses } + i = i + 1 end - - # syllabuses.to_a << other - - syllabuses.to_a - #管理权限 can_setting - # syllabuses.each do |s| - # s = judge_can_setting(s,user) - # end - - syllabuses + # syllabuses.to_a + # syllabuses + result end def after_create_course(course, user) @@ -72,7 +69,7 @@ class SyllabusesService if count == 0 ws = WechatService.new title = "恭喜您创建班级成功。" - ws.create_class_notice user.id, "create_course_notice", course.id,title, course.name, user.show_name, 0, "点击查看班级详情。" + ws.create_class_notice user.id, "create_course_notice", course.id,title, course.name, user.show_name, 1, "点击查看班级详情。" end end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index ab1bb2ec4..5789befe5 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -80,7 +80,7 @@ class UsersService #id用户id def show_user(params) @user = User.find(params[:id]) - img_url = url_to_avatar(@user) + img_url = "/images/"+url_to_avatar(@user) gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender work_unit = get_user_work_unit @user location = get_user_location @user @@ -224,7 +224,7 @@ class UsersService membership.sort! {|older, newer| newer.created_on <=> older.created_on } course_list = [] membership.each do |mp| - course_list << {:course => mp.course,:img_url => url_to_avatar(mp.course),:current_user_is_member => current_user.member_of_course?(mp.course),:current_user_is_teacher => is_course_teacher(current_user,mp.course)} + course_list << {:course => mp.course,:img_url => "/images/"+url_to_avatar(mp.course),:current_user_is_member => current_user.member_of_course?(mp.course),:current_user_is_teacher => is_course_teacher(current_user,mp.course)} end course_list end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 9a6351391..3b6cfe930 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -111,11 +111,17 @@ class WechatService end end - def two_keys_template(openid, template_id, type, id, first, key1, key2, remark="") + def two_keys_template(openid, template_id, type, id, first, key1, key2, remark="",uid) + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 + if uid && uid != 0 + tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 + end data = { touser:openid, template_id:template_id, - url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}",#/assets/wechat/app.html#/#{type}/#{id} + url:tmpurl,#/assets/wechat/app.html#/#{type}/#{id} topcolor:"#FF0000", data:{ first: { @@ -140,9 +146,11 @@ class WechatService end def three_keys_template(openid, template_id, type, id, first, key1, key2, key3, remark="",uid) - tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}" + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 if uid && uid != 0 tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 end data = { @@ -177,9 +185,11 @@ class WechatService end def four_keys_template(openid, template_id, type, id, first, key1, key2, key3, key4, remark="",uid) - tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}/#{id}" + # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" + tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 if uid && uid != 0 tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s + # tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3 end data = { @@ -223,7 +233,7 @@ class WechatService data = { touser:uw.openid, template_id:Wechat.config.binding_succ_notice, - url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities", + url:Wechat.config.auto_openid_url_1+Wechat.config.auto_openid_url_2+"activites"+Wechat.config.auto_openid_url_3, topcolor:"#FF0000", data:{ first: { @@ -292,13 +302,26 @@ class WechatService end end + # def join_class_notice(user_id, type, id, first, key1, key2, key3,remark="") + # uw = UserWechat.where(user_id: user_id).first + # unless uw.nil? + # data = three_keys_template uw.openid,Wechat.config.join_class_notice, type, id, first, key1, key2, key3, remark + # begin + # req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + # rescue Exception => e + # Rails.logger.error "[join_class__notice] ===> #{e}" + # end + # Rails.logger.info "send over. #{req}" + # end + # end + def create_class_notice(user_id, type, id, first, key1, key2, key3, remark="") uw = UserWechat.where(user_id: user_id).first unless uw.nil? data = { touser:uw.openid, template_id:Wechat.config.create_class_notice, - url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/class?id="+id.to_s, + url:Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+"class"+Wechat.config.auto_openid_url_3, topcolor:"#FF0000", data:{ first: { @@ -339,7 +362,7 @@ class WechatService data = { touser:uw.openid, template_id:Wechat.config.create_project_notice, - url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/project?id="+id.to_s, + url:Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+"project"+Wechat.config.auto_openid_url_3, topcolor:"#FF0000", data:{ first: { @@ -383,4 +406,19 @@ class WechatService end end + def join_project_notice(user_id, type, id, first, key1, key2,remark="",uid=0) + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = two_keys_template uw.openid,Wechat.config.join_project_notice, type, id, first, key1, key2,remark,uid + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[join_project_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + + + end + end \ No newline at end of file diff --git a/app/views/at/show.json.erb b/app/views/at/show.json.erb index 6e2a244e4..3e49496f9 100644 --- a/app/views/at/show.json.erb +++ b/app/views/at/show.json.erb @@ -1,11 +1,11 @@ [ - <% @users && @users.each_with_index do |person,index| %> - <% if index == 0 %> - {"id":<%=index%>, "userid": "<%=person.id%>", "name": "所有人", "login": "<%=person.name%>", "searchKey": "<%=person.name%>"} - <%= index != @users.size-1 ? ',' : '' %> - <% else %> - {"id":<%=index%>, "userid": <%=person.id%>, "name": "<%=person.show_name%>", "login": "<%=person.login%>", "searchKey": "<%=person.get_at_show_name%>"} - <%= index != @users.size-1 ? ',' : '' %> - <% end %> - <% end %> + <% @users && @users.each_with_index do |person,index| %> + <% if index == 0 %> + {"id":<%=index%>, "userid": "<%=person.id%>", "name": "所有人", "login": "<%=person.name%>", "searchKey": "<%=person.name%>"} + <%= index != @users.size-1 ? ',' : '' %> + <% else %> + {"id":<%=index%>, "userid": "<%=person.id%>", "name": "<%=person.show_name%>", "login": "<%=person.login%>", "searchKey": "<%=person.get_at_show_name%>"} + <%= index != @users.size-1 ? ',' : '' %> + <% end %> + <% end %> ] diff --git a/app/views/exercise/_show_head.html.erb b/app/views/exercise/_show_head.html.erb index cfa814c2e..8a0c182ce 100644 --- a/app/views/exercise/_show_head.html.erb +++ b/app/views/exercise/_show_head.html.erb @@ -11,6 +11,8 @@ 测验时长:<%= exercise.time %>分钟 <% end %> -
<%= exercise.exercise_description.nil? ? "" :exercise.exercise_description.html_safe%>
+
+    <%= exercise.exercise_description.nil? ? "" :exercise.exercise_description.html_safe%>
+  
\ No newline at end of file diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 7724bb861..be7da4732 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -1,19 +1,14 @@ - <% curse_attachments.each do |file| %> - <% if file.is_public? || User.current.member_of_course?(course) || User.current.admin? %> +<% curse_attachments.each do |file| %> + <% if file.is_public? || User.current.member_of_course?(course) || User.current.admin? %>
- <%=render :partial=>'files/resource_detail',:locals => {:file => file} %> + <%=render :partial=>'files/resource_detail',:locals => {:file => file} %>
- <% else %> -
<%= file.filename %>是私有资源
- <% end %> - <% end %> - -<% if curse_attachments.count == 10%> - <% if params[:action] == 'search' %> - <%=link_to "点击展开更多", search_course_files_path({:course_id => course.id,:page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> <% else %> - - <%=link_to "点击展开更多", course_files_path(:course_id => course.id, :page => @page), :id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <%end%> -<% end%> +
<%= file.filename %>是私有资源
+ <% end %> +<% end %> + + diff --git a/app/views/files/_project_list.html.erb b/app/views/files/_project_list.html.erb index 36dc80a18..faf254015 100644 --- a/app/views/files/_project_list.html.erb +++ b/app/views/files/_project_list.html.erb @@ -66,17 +66,10 @@ <% end %> <% end %> -<% if project_attachments.count == 10%> - <% if params[:action] == 'search_project' %> - - - - <%=link_to "点击展开更多", search_project_project_files_path({:project_id => project.id, :page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <%else%> - - <%=link_to "点击展开更多", project_files_path(:project_id => project.id,:page => @page),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <%end%> -<% end%> + + diff --git a/app/views/files/index.js.erb b/app/views/files/index.js.erb index 49e7ac714..982d19329 100644 --- a/app/views/files/index.js.erb +++ b/app/views/files/index.js.erb @@ -1,7 +1,9 @@ <% if @course %> - $("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/course_list',:locals => {course:@course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} )%>"); + $("#resource_list").html("<%= escape_javascript( render :partial => 'files/course_file',:locals => {course:@course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments}) %>"); + $("#pages").html('<%= pagination_links_full @feedback_pages, @feedback_count, :per_page_links => false, :remote => true, :flag => true %>'); <% elsif @project %> - $("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/project_list', :locals => {project:@project, all_attachments:@all_attachments, sort:@sort, order:@order, project_attachments:@obj_attachments})%>"); + $("#resource_list").html("<%= escape_javascript( render :partial => 'files/project_file',:locals => {project:@project, all_attachments:@all_attachments, sort:@sort, order:@order, project_attachments:@obj_attachments}) %>"); + $("#pages").html('<%= pagination_links_full @feedback_pages, @feedback_count, :per_page_links => false, :remote => true, :flag => true %>'); <% elsif @org_subfield %> $("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/org_subfield_list', :locals => {org_subfield:@org_subfield, all_attachments:@all_attachments, sort:@sort, order:@order, org_subfield_attachments:@obj_attachments})%>"); <%end %> \ No newline at end of file diff --git a/app/views/files/search.js.erb b/app/views/files/search.js.erb index fd88b3f9e..011b3bb25 100644 --- a/app/views/files/search.js.erb +++ b/app/views/files/search.js.erb @@ -1,6 +1,3 @@ -<% if (@obj_pages &&( @obj_pages.page > 1)) || (@feedback_pages && (@feedback_pages.page > 1)) %> //搜索的时候有时候是需要加载下一页,有时候是直接替换当前 #course_list。这个根据 page来判定 - $("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/course_list',:locals => {course: @course,all_attachments: @result,sort:@sort,order:@order,curse_attachments:@searched_attach} )%>"); -<% else %> - $("#course_list").html("<%= escape_javascript(render :partial => 'files/course_list',:locals => {course: @course,all_attachments: @result,sort:@sort,order:@order,curse_attachments:@searched_attach})%>"); - $("#attachment_count").html("<%= @result.count%>") -<% end %> \ No newline at end of file + + $("#resource_list").html("<%= escape_javascript( render :partial => 'files/course_file',:locals => {course:@course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} )%>"); + $("#pages").html('<%= pagination_links_full @feedback_pages, @feedback_count, :per_page_links => false, :remote => true, :flag => true %>'); diff --git a/app/views/files/search_project.js.erb b/app/views/files/search_project.js.erb index 69752e0d9..f88438d57 100644 --- a/app/views/files/search_project.js.erb +++ b/app/views/files/search_project.js.erb @@ -1,7 +1,2 @@ -<% if (@obj_pages &&( @obj_pages.page > 1)) || (@feedback_pages && (@feedback_pages.page > 1)) %> //搜索的时候有时候是需要加载下一页,有时候是直接替换当前 #course_list。这个根据 page来判定 - $("#show_more_attachments").replaceWith("<%= escape_javascript( render :partial => 'files/project_list', - :locals => {project: @project, all_attachments:@result, sort:@sort, order:@order, project_attachments:@searched_attach})%>"); -<% else %> - $("#course_list").html("<%= escape_javascript(render :partial => 'files/project_list',:locals => {project:@project, all_attachments:@result, sort:@sort, order:@order,project_attachments:@searched_attach})%>"); - $("#attachment_count").html("<%= @project_attachment_result.count %>") -<% end %> \ No newline at end of file +$("#resource_list").html("<%= escape_javascript( render :partial => 'files/project_file',:locals => {project:@project, all_attachments:@all_attachments, sort:@sort, order:@order, project_attachments:@obj_attachments}) %>"); +$("#pages").html('<%= pagination_links_full @feedback_pages, @feedback_count, :per_page_links => false, :remote => true, :flag => true %>'); diff --git a/app/views/files/search_tag_attachment.js.erb b/app/views/files/search_tag_attachment.js.erb index 3003d8b98..dff75023b 100644 --- a/app/views/files/search_tag_attachment.js.erb +++ b/app/views/files/search_tag_attachment.js.erb @@ -1,8 +1,7 @@ <% if @course %> - $("#course_list").html("<%= escape_javascript(render :partial => 'course_list',:locals => {course: @course,all_attachments: @result,sort:@sort,order:@order,curse_attachments:@searched_attach})%>"); - $("#course_filter_order").html("<%= escape_javascript(render :partial => 'course_file_filter_order', :locals => {course: @course,all_attachments: @result,sort:@sort,order:@order,curse_attachments:@searched_attach, tag_name: @tag_name, q: @q})%>"); - $("#attachment_count").html("<%= @result.count%>") + $("#resource_list").html("<%= escape_javascript( render :partial => 'files/course_file',:locals => {course:@course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} )%>"); + $("#pages").html('<%= pagination_links_full @feedback_pages, @feedback_count, :per_page_links => false, :remote => true, :flag => true %>'); <% else %> - $("#course_list").html("<%= escape_javascript(render :partial => 'project_list',:locals => {project:@project, all_attachments:@result_search_project, sort:@sort, order:@order, project_attachments:@searched_attach}) %>"); - $("#attachment_count").html("<%= @result_search_project.count%>") + $("#resource_list").html("<%= escape_javascript( render :partial => 'files/project_file',:locals => {project:@project, all_attachments:@all_attachments, sort:@sort, order:@order, project_attachments:@obj_attachments}) %>"); + $("#pages").html('<%= pagination_links_full @feedback_pages, @feedback_count, :per_page_links => false, :remote => true, :flag => true %>'); <% end %> diff --git a/app/views/files/subfield_upload_file.js.erb b/app/views/files/subfield_upload_file.js.erb index 340a2890f..96c1659fd 100644 --- a/app/views/files/subfield_upload_file.js.erb +++ b/app/views/files/subfield_upload_file.js.erb @@ -2,5 +2,5 @@ $('#ajax-modal').html('<%= escape_javascript(render :partial => 'files/upload_su showModal('ajax-modal', '513px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before(""); -$('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); +$('#ajax-modal').parent().css("top","30%").css("left","40%").css("border","3px solid #269ac9"); $('#ajax-modal').parent().addClass("popbox_polls"); \ No newline at end of file diff --git a/app/views/layouts/_course_base_info.html.erb b/app/views/layouts/_course_base_info.html.erb index 1c01ecf53..09832b66c 100644 --- a/app/views/layouts/_course_base_info.html.erb +++ b/app/views/layouts/_course_base_info.html.erb @@ -3,6 +3,8 @@ <% student_num = studentCount(@course) %> <% course_file_num = visable_attachemnts_incourse(@course).count %>

+ <%= link_to(@course.teacher.show_name, user_path(@course.teacher), :class => 'sy_cgrey') %> +  >  <% if @course.syllabus %> <%=link_to @course.syllabus.title, syllabus_path(@course.syllabus_id), :class => 'sy_cgrey' %>  >  @@ -17,7 +19,9 @@

diff --git a/app/views/layouts/_forbidden_new_feedback.html.erb b/app/views/layouts/_forbidden_new_feedback.html.erb new file mode 100644 index 000000000..03c9855f9 --- /dev/null +++ b/app/views/layouts/_forbidden_new_feedback.html.erb @@ -0,0 +1,40 @@ +<%= javascript_include_tag "feedback" %> + +
+
+
+ +
+
+ <% get_memo %> + <%= form_for(@new_memo, :url => create_feedback_forum_path(@public_forum)) do |f| %> + <%= f.text_area :subject, :id=>"subject", :class => "opnionText", :placeholder => l(:label_feedback_tips) %> + <%= f.hidden_field :content,:id => 'hidden', :required => true , :value => l(:label_feedback_value) %> + + + <%= l(:label_submit)%> + + <% end %> +
+
+ + <%#= l(:label_technical_support) %> + + + + Trustie师姐师兄答疑群 +
+
+
+
+
+
+ <%= l(:label_submit)%> + +
+
diff --git a/app/views/layouts/_syllabus_base_info.html.erb b/app/views/layouts/_syllabus_base_info.html.erb index 335dc3335..22139b550 100644 --- a/app/views/layouts/_syllabus_base_info.html.erb +++ b/app/views/layouts/_syllabus_base_info.html.erb @@ -5,27 +5,27 @@
diff --git a/public/assets/wechat/course_discussion.html b/public/assets/wechat/course_discussion.html index 9ef7bc429..3d7444c95 100644 --- a/public/assets/wechat/course_discussion.html +++ b/public/assets/wechat/course_discussion.html @@ -5,10 +5,11 @@
+
私有内容,请谨慎传播
@@ -23,20 +24,20 @@
{{discussion.praise_count}}
{{discussion.praise_count}}
-
-
+
{{journal.lasted_comment}}
@@ -47,7 +48,7 @@
点击展开更多楼层
{{reply_bottom.lasted_comment}}
diff --git a/public/assets/wechat/course_notice.html b/public/assets/wechat/course_notice.html index b2771100b..95eeda60b 100644 --- a/public/assets/wechat/course_notice.html +++ b/public/assets/wechat/course_notice.html @@ -4,10 +4,11 @@
+
私有内容,请谨慎传播
@@ -22,20 +23,20 @@
{{news.praise_count}}
{{news.praise_count}}
-
-
+
{{comments.created_on}}
diff --git a/public/assets/wechat/edit_class_member.html b/public/assets/wechat/edit_class_member.html index c20ed5acb..f27ab76cb 100644 --- a/public/assets/wechat/edit_class_member.html +++ b/public/assets/wechat/edit_class_member.html @@ -2,7 +2,7 @@
角色变更
-
{{current_edit_member.user.realname == "" ? current_edit_member.user.name : current_edit_member.user.realname}}
+
{{current_edit_member.user.realname == "" ? current_edit_member.user.name : current_edit_member.user.realname}}
角色
  • diff --git a/public/assets/wechat/edit_project_member.html b/public/assets/wechat/edit_project_member.html index 8677844b7..51294f43e 100644 --- a/public/assets/wechat/edit_project_member.html +++ b/public/assets/wechat/edit_project_member.html @@ -2,7 +2,7 @@
    角色变更
    -
    {{current_edit_member.user.real_name == "" ? current_edit_member.user.name : current_edit_member.user.real_name}}
    +
    {{current_edit_member.user.real_name == "" ? current_edit_member.user.name : current_edit_member.user.real_name}}
    角色
    • diff --git a/public/assets/wechat/homework_detail.html b/public/assets/wechat/homework_detail.html index 599774dfc..77aa0a48d 100644 --- a/public/assets/wechat/homework_detail.html +++ b/public/assets/wechat/homework_detail.html @@ -4,10 +4,11 @@
      +
      私有内容,请谨慎传播
      @@ -27,20 +28,20 @@
      {{homework.praise_count}}
      {{homework.praise_count}}
      - -
      +
      {{journal.lasted_comment}}
      @@ -51,7 +52,7 @@
      点击展开更多楼层
      {{reply_bottom.lasted_comment}}
      @@ -73,7 +74,7 @@
      - +
      diff --git a/public/assets/wechat/invite_code.html b/public/assets/wechat/invite_code.html index a1b225fc9..3aaa00bbe 100644 --- a/public/assets/wechat/invite_code.html +++ b/public/assets/wechat/invite_code.html @@ -11,6 +11,8 @@

      + 3.通过“加入班级”菜单输入邀请码加入班级(长按邀请码可以复制哦~)
      + 4.扫码默认以学生身份加入班级 +
      \ No newline at end of file diff --git a/public/assets/wechat/issue_detail.html b/public/assets/wechat/issue_detail.html index 852103b81..14df1cfb1 100644 --- a/public/assets/wechat/issue_detail.html +++ b/public/assets/wechat/issue_detail.html @@ -4,11 +4,12 @@
      +
      私有内容,请谨慎传播
      @@ -28,20 +29,20 @@
      {{issue.praise_count}}
      {{issue.praise_count}}
      -
      -
      +
      {{journal.created_on}}
      diff --git a/public/assets/wechat/join_project.html b/public/assets/wechat/join_project.html index c2c0ec993..61be93cfd 100644 --- a/public/assets/wechat/join_project.html +++ b/public/assets/wechat/join_project.html @@ -9,6 +9,13 @@
    +
    + 提示 +
      +
    • 管理人员、开发人员角色需要项目管理员审批
    • +
    • 报告人员角色无需管理员审批
    • +
    +
    取消 确定 diff --git a/public/assets/wechat/jour_message_detail.html b/public/assets/wechat/jour_message_detail.html index 78760da71..b94bca8b2 100644 --- a/public/assets/wechat/jour_message_detail.html +++ b/public/assets/wechat/jour_message_detail.html @@ -3,11 +3,12 @@
    +
    私有内容,请谨慎传播
    @@ -22,21 +23,21 @@
    {{message.praise_count}}
    {{message.praise_count}}
    -
    -
    +
    {{journal.lasted_comment}}
    @@ -46,7 +47,7 @@
    点击展开更多楼层
    {{reply_bottom.lasted_comment}}
    diff --git a/public/assets/wechat/login.html b/public/assets/wechat/login.html index 61c9b9de3..05d844ca8 100644 --- a/public/assets/wechat/login.html +++ b/public/assets/wechat/login.html @@ -17,7 +17,7 @@
    - +
    diff --git a/public/assets/wechat/login_tip.html b/public/assets/wechat/login_tip.html new file mode 100644 index 000000000..82bb6d906 --- /dev/null +++ b/public/assets/wechat/login_tip.html @@ -0,0 +1,13 @@ +
    +
    + +
    提示
    +
    +
      +
    • 您的回复内容已提交
    • +
    • 想要实时接收动态、加入社区?
      长按二维码,关注公众号
    • +
    • +
    +
    +
    + diff --git a/public/assets/wechat/project.html b/public/assets/wechat/project.html index 0ea8a3117..733f0899d 100644 --- a/public/assets/wechat/project.html +++ b/public/assets/wechat/project.html @@ -15,8 +15,7 @@
    @@ -54,8 +53,7 @@
    @@ -88,7 +86,7 @@
    - +
    @@ -110,30 +108,30 @@
    管理人员({{project_master_members.length}})
    - {{master.user.real_name == "" ? master.user.name : master.user.real_name }} + {{master.user.real_name == "" ? master.user.name : master.user.real_name }}
    - {{user.real_name == "" ? user.name : user.real_name }} + {{user.real_name == "" ? user.name : user.real_name }} 待审批 ▶
    开发人员({{project_develop_members.length}})
    - {{develop.user.real_name == "" ? develop.user.name : develop.user.real_name}} + {{develop.user.real_name == "" ? develop.user.name : develop.user.real_name}}
    - {{user.real_name == "" ? user.name : user.real_name}} + {{user.real_name == "" ? user.name : user.real_name}} 待审批 ▶
    报告人员({{project_report_members.length}})
    - {{report.user.real_name == "" ? report.user.name : report.user.real_name}} + {{report.user.real_name == "" ? report.user.name : report.user.real_name}}
    diff --git a/public/assets/wechat/project_discussion.html b/public/assets/wechat/project_discussion.html index cc3d4b1c8..fef0a2f6e 100644 --- a/public/assets/wechat/project_discussion.html +++ b/public/assets/wechat/project_discussion.html @@ -4,10 +4,11 @@
    +
    私有内容,请谨慎传播
    @@ -23,7 +24,7 @@
    {{discussion.praise_count}}
    {{discussion.praise_count}}
    -
    + @@ -31,13 +32,13 @@
    -
    +
    {{journal.lasted_comment}}
    @@ -47,7 +48,7 @@
    点击展开更多楼层
    {{reply_bottom.lasted_comment}}
    diff --git a/public/assets/wechat/project_invite_code.html b/public/assets/wechat/project_invite_code.html index a17b8fe85..7685d7aef 100644 --- a/public/assets/wechat/project_invite_code.html +++ b/public/assets/wechat/project_invite_code.html @@ -11,6 +11,8 @@

    + 3.通过“加入项目”菜单输入邀请码加入项目(长按邀请码可以复制哦~)
    + 4.扫码默认以报告人员身份加入项目 +
    \ No newline at end of file diff --git a/public/assets/wechat/project_list.html b/public/assets/wechat/project_list.html index 1d385dabf..d9313b6a7 100644 --- a/public/assets/wechat/project_list.html +++ b/public/assets/wechat/project_list.html @@ -7,7 +7,7 @@
    - > + > {{project.member_count}}人
    @@ -20,7 +20,7 @@
    - > + > {{project.member_count}}人
    diff --git a/public/assets/wechat/reg.html b/public/assets/wechat/reg.html index 26a17931f..f42108202 100644 --- a/public/assets/wechat/reg.html +++ b/public/assets/wechat/reg.html @@ -27,9 +27,10 @@
    diff --git a/public/assets/wechat/review_class_member.html b/public/assets/wechat/review_class_member.html index 06ce99018..e066c48f0 100644 --- a/public/assets/wechat/review_class_member.html +++ b/public/assets/wechat/review_class_member.html @@ -3,7 +3,7 @@
    {{current_course.name}}
    -
    {{current_review_member.realname == "" ? current_review_member.name : current_review_member.realname}}
    +
    {{current_review_member.realname == "" ? current_review_member.name : current_review_member.realname}}
    角色
    • diff --git a/public/assets/wechat/review_project_member.html b/public/assets/wechat/review_project_member.html index d50a04fa4..bcbbb50b6 100644 --- a/public/assets/wechat/review_project_member.html +++ b/public/assets/wechat/review_project_member.html @@ -3,7 +3,7 @@
      {{current_project.name}}
      -
      {{current_review_member.realname == "" ? current_review_member.name : current_review_member.realname}}
      +
      {{current_review_member.realname == "" ? current_review_member.name : current_review_member.realname}}
      角色
      • diff --git a/public/images/wechat/trustie_QR.jpg b/public/images/wechat/trustie_QR.jpg new file mode 100644 index 000000000..2b0c38f8b Binary files /dev/null and b/public/images/wechat/trustie_QR.jpg differ diff --git a/public/images/wechat/wx_logo.jpg b/public/images/wechat/wx_logo.jpg new file mode 100644 index 000000000..8faeef27a Binary files /dev/null and b/public/images/wechat/wx_logo.jpg differ diff --git a/public/javascripts/application.js b/public/javascripts/application.js index cfeb4b341..504fea3cb 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1495,12 +1495,12 @@ function pop_up_box(value,tWidth,tTop,tLeft){ // 公共弹框样式 function pop_box_new(value, Width, Height){ w = ($(window).width() - Width)/2; - h = ($(window).height() - Height)/2 - 100; + h = ($(window).height() - Height)/2; $("#ajax-modal").html(value); showModal('ajax-modal', Width + 'px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').parent().css({"top": h+"px","left": w+"px","padding":"0","border":"none","position":"fixed"}); - $('#ajax-modal').css({"padding":"0"}); + $('#ajax-modal').css({"padding":"0","overflow":"hidden"}); $('#ajax-modal').parent().attr("id","popupWrap"); //拖拽 @@ -1552,7 +1552,10 @@ function pop_box_new(value, Width, Height){ document.onmousemove = null; } - new Drag("popupWrap"); + $(".sy_popup_con").mousedown(function(event){ + event.stopPropagation(); + new Drag("popupWrap"); + }); } // 公共提示弹框样式 diff --git a/public/javascripts/new_user.js b/public/javascripts/new_user.js index 8db3fbc20..1013dd749 100644 --- a/public/javascripts/new_user.js +++ b/public/javascripts/new_user.js @@ -38,7 +38,6 @@ function edit_user_introduction(url){ function show_more_course(url){ $.get( url, - { page: $("#course_page_num").val() }, function (data) { } ); @@ -48,7 +47,6 @@ function show_more_course(url){ function show_more_project(url){ $.get( url, - { page: $("#project_page_num").val() }, function (data) { } diff --git a/public/javascripts/syllabus.js b/public/javascripts/syllabus.js index 24b997496..0319bd4d1 100644 --- a/public/javascripts/syllabus.js +++ b/public/javascripts/syllabus.js @@ -2,7 +2,6 @@ function show_more_course(url){ $.get( url, - { page: $("#course_page_num").val() }, function (data) { } ); diff --git a/public/javascripts/wechat/controllers/activity.js b/public/javascripts/wechat/controllers/activity.js index 7066da4d9..e646da5b9 100644 --- a/public/javascripts/wechat/controllers/activity.js +++ b/public/javascripts/wechat/controllers/activity.js @@ -2,6 +2,10 @@ app.controller('ActivityController', ['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common','alertService', function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common, alertService){ + +// common.checkLogin(); + + $scope.replaceUrl = function(url){ return url; }; @@ -142,7 +146,7 @@ app.controller('ActivityController', rms.save("activities",$scope.activities); rms.save("course_activities",$scope.course_activities); rms.save("project_activities",$scope.project_activities); - $location.path('/'+type+'/'+act_id); + $location.path("/"+type).search({id: act_id}); }; $scope.addPraise = function(act){ diff --git a/public/javascripts/wechat/controllers/blog.js b/public/javascripts/wechat/controllers/blog.js index 5fb61151d..21c1cf345 100644 --- a/public/javascripts/wechat/controllers/blog.js +++ b/public/javascripts/wechat/controllers/blog.js @@ -7,6 +7,7 @@ app.controller('BlogController', scope: $scope, type: 'blog_comments', replyType: 'BlogComment', + urlName: 'blog_comment', loadCallback: function(data){ console.log(data.data); diff --git a/public/javascripts/wechat/controllers/class.js b/public/javascripts/wechat/controllers/class.js index 04807b2dd..d372f6826 100644 --- a/public/javascripts/wechat/controllers/class.js +++ b/public/javascripts/wechat/controllers/class.js @@ -1,181 +1,185 @@ -app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams','alertService','rms', function($scope, config, $http, auth, $location, $routeParams,alertService,rms){ - - var vm = $scope; - var courseid = $routeParams.id; - var tag = $routeParams.tag; - - - var getUsers = function(){ - if(vm.teachers.length<=0){ - $http.get(config.apiUrl + 'courses/teachers?token='+auth.token()+'&course_id='+courseid).then( - function(response) { - console.log(response.data); - vm.teachers = response.data.data; - } - ) - } - - if(vm.course.is_creator){ - if(vm.reviewers.length<=0){ - $http.get(config.apiUrl + 'courses/reviewers?token='+auth.token()+'&course_id='+courseid).then( - function(response) { - console.log(response.data); - vm.reviewers = response.data.data; - } - ) - } - } - - if(vm.students.length<=0){ - $http.get(config.apiUrl + 'courses/students?token='+auth.token()+'&course_id='+courseid).then( - function(response) { - console.log(response.data); - vm.students = response.data.data; - } - ) - } - } - - var getResources = function(){ - if(vm.resources.length<=0){ - $http.post(config.apiUrl + "courses/"+courseid+"/attachments", - {token: auth.token(), name: ''} - ).then(function(response){ - vm.resources = response.data.data; - vm.resources_tag = true; - }); - } - } - - var getHomeworks = function(){ - if(vm.homeworks.length <=0){ - $http.get(config.apiUrl + "courses/homeworks/"+courseid+"?token="+auth.token()).then(function(response){ - vm.homeworks = response.data.data; - console.log(response.data); - vm.homeworks_tag = true; - }); - } - } - - var getExercises = function(){ - if(vm.exercises.length <=0){ - $http.get(config.apiUrl + "courses/"+courseid+"/exercises?token="+auth.token()).then(function(response){ - vm.exercises = response.data.data; - console.log(response.data); - vm.exercises_tag = true; - }); - } - } - - - vm.isTeacher = false; - vm.currentTab = 1; - vm.tab = function(index){ - vm.currentTab = index; - vm.searchText = ''; - - vm.showClassMate = false; - vm.showResources = false; - vm.showHomework = false; - vm.showTestcase = false; - vm.resources_tag = false; - vm.homeworks_tag = false; - vm.exercises_tag = false; - - if(vm.isTeacher){ - if(index == 1){ //课件 - getResources(); - vm.showResources = true; - } else if(index==2){ //作业 - getHomeworks(); - vm.showHomework = true; - } else if(index==3){ //小测验 - getExercises(); - vm.showTestcase = true; - } else if(index==4){ //学生管理 - getUsers(); - vm.showClassMate = true; - } - - } else { - if(index == 2){ - getUsers(); - vm.showClassMate = true; - } else if(index==1){ - getResources(); - vm.showResources = true; - } - } - } - - vm.course = {}; - vm.students = []; - vm.teachers = []; - vm.reviewers = []; //待审批 - vm.resources = []; - vm.homeworks = []; - vm.exercises = []; - - //发送类别 1课件 2作业 3测验 - vm.myresource_sendIndex = rms.get('myresource_sendIndex') || 1; - - vm.alertService = alertService.create(); - - vm.invite = function(){ - $location.path("/invite_code").search({id: courseid}); - }; - - vm.sendFile = function(r,index){ - vm.myresource_sendIndex = index; - rms.save('myresource_sendIndex',index); - $location.path("/send_class_list").search({id: r.id}); - } - - $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then( - function(response) { - console.log(response.data); - - if (response.data.status == 0){ - vm.course = response.data.data; - resetMenu(vm.course.current_user_is_teacher); - if(tag){ - vm.tab(4); - tag = null; - } - else{ - vm.tab(1); - } - } - else{ - vm.alertService.showMessage('提示', response.data.message); - } - - } - ); - - - var resetMenu = function(is_teacher){ - vm.isTeacher = is_teacher; - if(is_teacher){ - vm.menus = ["课件", "作业", "测验", "成员管理"]; - } else { - vm.menus = ['课件', "我的同学"]; - } - - } - - vm.onSetting = function(user){ - rms.save('current_edit_member', user); - $location.path("/edit_class_member").search({id: courseid,user_id: user.id}); - }; - - vm.review = function(user){ - rms.save('current_review_member', user); - rms.save('current_course', vm.course); - - $location.path("/review_class_member").search({id: courseid,user_id: user.id}); - } - - - +app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams','alertService','rms','common', function($scope, config, $http, auth, $location, $routeParams,alertService,rms,common){ +// common.checkLogin(); + + var vm = $scope; + var courseid = $routeParams.id; + var tag = $routeParams.tag; + + + var getUsers = function(){ + if(vm.teachers.length<=0){ + $http.get(config.apiUrl + 'courses/teachers?token='+auth.token()+'&course_id='+courseid).then( + function(response) { + console.log(response.data); + vm.teachers = response.data.data; + } + ) + } + + if(vm.course.is_creator){ + if(vm.reviewers.length<=0){ + $http.get(config.apiUrl + 'courses/reviewers?token='+auth.token()+'&course_id='+courseid).then( + function(response) { + console.log(response.data); + vm.reviewers = response.data.data; + } + ) + } + } + + if(vm.students.length<=0){ + $http.get(config.apiUrl + 'courses/students?token='+auth.token()+'&course_id='+courseid).then( + function(response) { + console.log(response.data); + vm.students = response.data.data; + } + ) + } + } + + var getResources = function(){ + if(vm.resources.length<=0){ + $http.post(config.apiUrl + "courses/"+courseid+"/attachments", + {token: auth.token(), name: ''} + ).then(function(response){ + vm.resources = response.data.data; + vm.resources_tag = true; + }); + } + } + + var getHomeworks = function(){ + if(vm.homeworks.length <=0){ + $http.get(config.apiUrl + "courses/homeworks/"+courseid+"?token="+auth.token()).then(function(response){ + vm.homeworks = response.data.data; + console.log(response.data); + vm.homeworks_tag = true; + }); + } + } + + var getExercises = function(){ + if(vm.exercises.length <=0){ + $http.get(config.apiUrl + "courses/"+courseid+"/exercises?token="+auth.token()).then(function(response){ + vm.exercises = response.data.data; + console.log(response.data); + vm.exercises_tag = true; + }); + } + } + + + vm.isTeacher = false; + vm.currentTab = 1; + vm.tab = function(index){ + vm.currentTab = index; + vm.searchText = ''; + + vm.showClassMate = false; + vm.showResources = false; + vm.showHomework = false; + vm.showTestcase = false; + vm.resources_tag = false; + vm.homeworks_tag = false; + vm.exercises_tag = false; + + if(vm.isTeacher){ + if(index == 1){ //课件 + getResources(); + vm.showResources = true; + } else if(index==2){ //作业 + getHomeworks(); + vm.showHomework = true; + } else if(index==3){ //小测验 + getExercises(); + vm.showTestcase = true; + } else if(index==4){ //学生管理 + getUsers(); + vm.showClassMate = true; + } + + } else { + if(index == 2){ + getUsers(); + vm.showClassMate = true; + } else if(index==1){ + getResources(); + vm.showResources = true; + } + } + rms.save("tab_num",index); + } + + vm.tabRecord = rms.get('tab_num') || 1; + + vm.course = {}; + vm.students = []; + vm.teachers = []; + vm.reviewers = []; //待审批 + vm.resources = []; + vm.homeworks = []; + vm.exercises = []; + + //发送类别 1课件 2作业 3测验 + vm.myresource_sendIndex = rms.get('myresource_sendIndex') || 1; + + vm.alertService = alertService.create(); + + vm.invite = function(){ + $location.path("/invite_code").search({id: courseid}); + }; + + vm.sendFile = function(r,index){ + vm.myresource_sendIndex = index; + rms.save('myresource_sendIndex',index); + $location.path("/send_class_list").search({id: r.id}); + } + + $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then( + function(response) { + console.log(response.data); + + if (response.data.status == 0){ + vm.course = response.data.data; + resetMenu(vm.course.current_user_is_teacher,vm.tabRecord); + if(tag){ + vm.tab(4); + tag = null; + } + else{ + vm.tab(vm.tabRecord); + } + } + else{ + vm.alertService.showMessage('提示', response.data.message); + } + + } + ); + + + var resetMenu = function(is_teacher){ + vm.isTeacher = is_teacher; + if(is_teacher){ + vm.menus = ["课件", "作业", "测验", "成员管理"]; + } else { + vm.menus = ['课件', "我的同学"]; + } + + } + + vm.onSetting = function(user){ + rms.save('current_edit_member', user); + $location.path("/edit_class_member").search({id: courseid,user_id: user.id}); + }; + + vm.review = function(user){ + rms.save('current_review_member', user); + rms.save('current_course', vm.course); + + $location.path("/review_class_member").search({id: courseid,user_id: user.id}); + } + + + }]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/class_list.js b/public/javascripts/wechat/controllers/class_list.js index 48e778f9d..cc5250970 100644 --- a/public/javascripts/wechat/controllers/class_list.js +++ b/public/javascripts/wechat/controllers/class_list.js @@ -3,8 +3,10 @@ */ -app.controller('ClassListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms', - function ($scope, config, auth, $http, $location, alertService,rms) { +app.controller('ClassListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms','common', + function ($scope, config, auth, $http, $location, alertService,rms,common) { +// common.checkLogin(); + var vm = $scope; vm.syllabuses = rms.get('syllabuses') || []; diff --git a/public/javascripts/wechat/controllers/course_notice.js b/public/javascripts/wechat/controllers/course_notice.js index 77d2e6ab0..9f9ba83d6 100644 --- a/public/javascripts/wechat/controllers/course_notice.js +++ b/public/javascripts/wechat/controllers/course_notice.js @@ -6,8 +6,10 @@ app.controller('CourseNoticeController', ['$scope', '$http', '$routeParams', 'au scope: $scope, type: 'newss', replyType: 'News', + urlName: 'course_notice', loadCallback: function(data){ $scope.news = data.data; + $scope.is_public = data.is_public; }, replyCallback: function(){ } diff --git a/public/javascripts/wechat/controllers/discussion.js b/public/javascripts/wechat/controllers/discussion.js index 60bfb3ee3..21e842d0f 100644 --- a/public/javascripts/wechat/controllers/discussion.js +++ b/public/javascripts/wechat/controllers/discussion.js @@ -5,6 +5,7 @@ app.controller('DiscussionController', ['$scope', '$http', '$routeParams', 'auth scope: $scope, type: 'messages', replyType: 'Message', + urlName: 'discussion', loadCallback: function(data){ console.log(data.data); @@ -16,6 +17,7 @@ app.controller('DiscussionController', ['$scope', '$http', '$routeParams', 'auth if (page == 0){ $scope.discussion = data.data; $scope.page = 0; + $scope.is_public = data.is_public; } else{ $scope.discussion.all_children = $scope.discussion.all_children.concat(data.data.all_children); diff --git a/public/javascripts/wechat/controllers/edit_class.js b/public/javascripts/wechat/controllers/edit_class.js index 0a09ce1e3..d61c25353 100644 --- a/public/javascripts/wechat/controllers/edit_class.js +++ b/public/javascripts/wechat/controllers/edit_class.js @@ -1,6 +1,8 @@ -app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){ +app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){ +// common.checkLogin(); + var vm = $scope; vm.syllabus = rms.get('current_edit_syllobus'); diff --git a/public/javascripts/wechat/controllers/edit_class_member.js b/public/javascripts/wechat/controllers/edit_class_member.js index b3c28ea0b..e00e36f20 100644 --- a/public/javascripts/wechat/controllers/edit_class_member.js +++ b/public/javascripts/wechat/controllers/edit_class_member.js @@ -1,6 +1,8 @@ -app.controller('EditClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){ +app.controller('EditClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){ +// common.checkLogin(); + var vm = $scope; // vm.current_edit_member = rms.get('current_edit_member'); diff --git a/public/javascripts/wechat/controllers/edit_project_member.js b/public/javascripts/wechat/controllers/edit_project_member.js index 3fd24f04e..511db35bb 100644 --- a/public/javascripts/wechat/controllers/edit_project_member.js +++ b/public/javascripts/wechat/controllers/edit_project_member.js @@ -1,6 +1,8 @@ -app.controller('EditProjectMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){ +app.controller('EditProjectMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){ +// common.checkLogin(); + var vm = $scope; // vm.current_edit_member = rms.get('current_edit_member'); diff --git a/public/javascripts/wechat/controllers/homework.js b/public/javascripts/wechat/controllers/homework.js index 2898fc27f..f61f2be1d 100644 --- a/public/javascripts/wechat/controllers/homework.js +++ b/public/javascripts/wechat/controllers/homework.js @@ -5,6 +5,7 @@ app.controller('HomeworkController', ['$scope', '$http', '$routeParams', 'auth', scope: $scope, type: 'whomeworks', replyType: 'HomeworkCommon', + urlName: 'homework', loadCallback: function(data){ console.log(data.data); @@ -16,6 +17,7 @@ app.controller('HomeworkController', ['$scope', '$http', '$routeParams', 'auth', if (page == 0){ $scope.homework = data.data; $scope.page = 0; + $scope.is_public = data.is_public; } else{ $scope.homework.all_children = $scope.homework.all_children.concat(data.data.all_children); diff --git a/public/javascripts/wechat/controllers/invite_code.js b/public/javascripts/wechat/controllers/invite_code.js index db8b99ae7..50c14c0c3 100644 --- a/public/javascripts/wechat/controllers/invite_code.js +++ b/public/javascripts/wechat/controllers/invite_code.js @@ -13,9 +13,12 @@ app.controller('InviteCodeController', ['$scope','$http', '$routeParams','config console.log(response.data); vm.course = response.data.data; - var desc = "班级邀请:"+vm.course.name+" 班级"; + var desc = "您的好友邀请您加入班级:【"+vm.course.name+"】,和小伙伴一起踏上便捷的学习之旅吧!"; + var link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid+ + "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+vm.course.id+ + "&response_type=code&scope=snsapi_base&state=invite_code&connect_redirect=1#wechat_redirect"; - common.wxConfig("",desc,""); + common.wxConfig("",desc,"",link); // wx.ready(function(){ // wx.onMenuShareTimeline({ diff --git a/public/javascripts/wechat/controllers/issue.js b/public/javascripts/wechat/controllers/issue.js index ae0cc4450..131fab6f6 100644 --- a/public/javascripts/wechat/controllers/issue.js +++ b/public/javascripts/wechat/controllers/issue.js @@ -5,9 +5,11 @@ app.controller('IssueController', ['$scope', '$http', '$routeParams', 'auth', 'c scope: $scope, type: 'issues', replyType: 'Issue', + urlName: 'issues', loadCallback: function(data){ console.log(data); $scope.issue = data.data; + $scope.is_public = data.is_public; }, replyCallback: function(){ } diff --git a/public/javascripts/wechat/controllers/join_class.js b/public/javascripts/wechat/controllers/join_class.js index 3f1a28387..1a9710bc1 100644 --- a/public/javascripts/wechat/controllers/join_class.js +++ b/public/javascripts/wechat/controllers/join_class.js @@ -1,6 +1,8 @@ -app.controller('JoinClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx){ +app.controller('JoinClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx,common){ +// common.checkLogin(); + var vm = $scope; // vm.current_edit_member = rms.get('current_edit_member'); diff --git a/public/javascripts/wechat/controllers/join_project.js b/public/javascripts/wechat/controllers/join_project.js index f27c535c5..d942e8859 100644 --- a/public/javascripts/wechat/controllers/join_project.js +++ b/public/javascripts/wechat/controllers/join_project.js @@ -1,6 +1,8 @@ -app.controller('JoinProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx){ +app.controller('JoinProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx,common){ +// common.checkLogin(); + var vm = $scope; // vm.current_edit_member = rms.get('current_edit_member'); diff --git a/public/javascripts/wechat/controllers/journals.js b/public/javascripts/wechat/controllers/journals.js index 23f3b908b..0570e695f 100644 --- a/public/javascripts/wechat/controllers/journals.js +++ b/public/javascripts/wechat/controllers/journals.js @@ -4,6 +4,7 @@ app.controller('JournalsController', ['$scope', '$http', '$routeParams', 'auth', scope: $scope, type: 'journal_for_messages', replyType: 'JournalsForMessage', + urlName: 'journal_for_message', loadCallback: function(data){ console.log(data.data); @@ -15,6 +16,7 @@ app.controller('JournalsController', ['$scope', '$http', '$routeParams', 'auth', if (page == 0){ $scope.message = data.data; $scope.page = 0; + $scope.is_public = data.is_public; } else{ $scope.message.all_children = $scope.message.all_children.concat(data.data.all_children); diff --git a/public/javascripts/wechat/controllers/login.js b/public/javascripts/wechat/controllers/login.js index f8e87a93f..ea86a71a2 100644 --- a/public/javascripts/wechat/controllers/login.js +++ b/public/javascripts/wechat/controllers/login.js @@ -1,6 +1,8 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams', 'alertService', 'config','auth','session','wx', function ($scope, $http, $location, $routeParams, alertService, config, auth,session, wx) { + var tag = $routeParams.tag; + // 登录页不用显示菜音 wx.ready(function(){ wx.hideOptionMenu(); @@ -39,7 +41,13 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams vm.loginFailed = (response.data.status != 0); if (!$scope.loginFailed) { //绑定成功 vm.alertService.showMessage('提示', response.data.message, function(){ - wx.closeWindow(); + if(tag){ + window.history.back(); + tag = null; + } + else{ + wx.closeWindow(); + } }); } else { vm.alertService.showMessage('出错了', response.data.message); diff --git a/public/javascripts/wechat/controllers/login_tip..js b/public/javascripts/wechat/controllers/login_tip..js new file mode 100644 index 000000000..a719abf79 --- /dev/null +++ b/public/javascripts/wechat/controllers/login_tip..js @@ -0,0 +1,7 @@ +app.controller('LoginTipController', ['$scope', '$http', '$location', 'alertService','$location', + function ($scope, $http, $location, alertService, $location) { + $scope.bindWx = function(){ + $location.path("/login").search({tag:1}); + }; + + }]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/myresource.js b/public/javascripts/wechat/controllers/myresource.js index b5489c065..089b63dfc 100644 --- a/public/javascripts/wechat/controllers/myresource.js +++ b/public/javascripts/wechat/controllers/myresource.js @@ -1,4 +1,6 @@ -app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$location', 'rms', function($scope, $http, auth, config, $location,rms){ +app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$location', 'rms','common', function($scope, $http, auth, config, $location,rms,common){ +// common.checkLogin(); + var vm = $scope; // vm.menus = ['课件', '作业', '测验']; vm.menus = ['课件', '作业']; diff --git a/public/javascripts/wechat/controllers/new_class.js b/public/javascripts/wechat/controllers/new_class.js index 5e9f339a1..54bc396b6 100644 --- a/public/javascripts/wechat/controllers/new_class.js +++ b/public/javascripts/wechat/controllers/new_class.js @@ -1,6 +1,8 @@ -app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms', function($scope, $http, auth, config, alertService, $location,rms){ +app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms','common', function($scope, $http, auth, config, alertService, $location,rms,common){ +// common.checkLogin(); + var vm = $scope; vm.alertService = alertService.create(); diff --git a/public/javascripts/wechat/controllers/new_project.js b/public/javascripts/wechat/controllers/new_project.js index 6eb6a1caa..03a1b451f 100644 --- a/public/javascripts/wechat/controllers/new_project.js +++ b/public/javascripts/wechat/controllers/new_project.js @@ -1,6 +1,8 @@ -app.controller('NewProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms', function($scope, $http, auth, config, alertService, $location,rms){ +app.controller('NewProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms','common', function($scope, $http, auth, config, alertService, $location,rms,common){ +// common.checkLogin(); + var vm = $scope; vm.alertService = alertService.create(); diff --git a/public/javascripts/wechat/controllers/project.js b/public/javascripts/wechat/controllers/project.js index f4a3b5c5c..08987e491 100644 --- a/public/javascripts/wechat/controllers/project.js +++ b/public/javascripts/wechat/controllers/project.js @@ -1,4 +1,6 @@ app.controller('ProjectController', ['$scope', 'config','$http','$timeout', 'auth','$location','$routeParams','alertService','rms','common', function($scope, config, $http,$timeout, auth, $location, $routeParams,alertService,rms,common){ +// common.checkLogin(); + $scope.replaceUrl = function(url){ return url; }; @@ -115,7 +117,8 @@ app.controller('ProjectController', ['$scope', 'config','$http','$timeout', 'aut rms.save("project_activities",vm.project_activities); rms.save('project_has_more', vm.project_has_more); rms.save("project",vm.project); - $location.path('/'+type+'/'+act_id); +// $location.path('/'+type+'/'+act_id); + $location.path("/"+type).search({id: act_id}); }; //切换 按钮 diff --git a/public/javascripts/wechat/controllers/project_invite_code.js b/public/javascripts/wechat/controllers/project_invite_code.js index dea2e9d64..a68bf430b 100644 --- a/public/javascripts/wechat/controllers/project_invite_code.js +++ b/public/javascripts/wechat/controllers/project_invite_code.js @@ -13,9 +13,12 @@ app.controller('ProjectInviteCodeController', ['$scope','$http', '$routeParams', console.log(response.data); vm.project = response.data.data; - var desc = "项目邀请:"+vm.project.name+" 项目"; + var desc = "您的好友邀请您加入项目:【"+vm.project.name+"】,和小伙伴一起踏上便捷的研发之旅吧!"; + var link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid+ + "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+vm.project.id+ + "&response_type=code&scope=snsapi_base&state=project_invite_code&connect_redirect=1#wechat_redirect"; - common.wxConfig("",desc,""); + common.wxConfig("",desc,"",link); // wx.ready(function(){ // wx.onMenuShareTimeline({ diff --git a/public/javascripts/wechat/controllers/project_list.js b/public/javascripts/wechat/controllers/project_list.js index 6ff7495e4..e716de0a9 100644 --- a/public/javascripts/wechat/controllers/project_list.js +++ b/public/javascripts/wechat/controllers/project_list.js @@ -3,8 +3,10 @@ */ -app.controller('ProjectListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms', - function ($scope, config, auth, $http, $location, alertService,rms) { +app.controller('ProjectListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms','common', + function ($scope, config, auth, $http, $location, alertService,rms,common) { +// common.checkLogin(); + var vm = $scope; // vm.projects = rms.get('projects') || []; vm.projects = []; diff --git a/public/javascripts/wechat/controllers/reg.js b/public/javascripts/wechat/controllers/reg.js index 9600e9dbf..1247cd931 100644 --- a/public/javascripts/wechat/controllers/reg.js +++ b/public/javascripts/wechat/controllers/reg.js @@ -1,5 +1,5 @@ -app.controller('RegController', ['$scope', '$http', '$location', 'alertService','$location', - function ($scope, $http, $location, alertService, $location) { +app.controller('RegController', ['$scope', '$http', '$location', 'alertService','$location','wx', + function ($scope, $http, $location, alertService, $location,wx) { var vm = $scope; vm.errDialog = alertService.create(); @@ -35,7 +35,8 @@ app.controller('RegController', ['$scope', '$http', '$location', 'alertService', } else { vm.successDialog.showMessage("提示","注册且绑定微信成功", function(){ // $location.path("/activities"); - window.WeixinJSBridge.call('closeWindow'); +// window.WeixinJSBridge.call('closeWindow'); + wx.closeWindow(); }); } }, function (response) { diff --git a/public/javascripts/wechat/controllers/review_class_member.js b/public/javascripts/wechat/controllers/review_class_member.js index 44704c32d..aee8d683a 100644 --- a/public/javascripts/wechat/controllers/review_class_member.js +++ b/public/javascripts/wechat/controllers/review_class_member.js @@ -1,6 +1,8 @@ -app.controller('ReviewClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){ +app.controller('ReviewClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){ +// common.checkLogin(); + var vm = $scope; // vm.current_edit_member = rms.get('current_edit_member'); @@ -78,6 +80,11 @@ app.controller('ReviewClassMemberController', ['$scope', '$http', 'auth', 'confi }; vm.goClassMemberList = function(){ - $location.path("/class").search({id: course_id,tag: 1}); + if(vm.current_course.is_member){ + $location.path("/class").search({id: course_id,tag: 1}); + } + else{ + $location.path("/class_list"); + } }; }] ); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/review_project_member.js b/public/javascripts/wechat/controllers/review_project_member.js index 2428c09d0..5c652050f 100644 --- a/public/javascripts/wechat/controllers/review_project_member.js +++ b/public/javascripts/wechat/controllers/review_project_member.js @@ -1,6 +1,8 @@ -app.controller('ReviewProjectMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){ +app.controller('ReviewProjectMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){ +// common.checkLogin(); + var vm = $scope; // vm.current_edit_member = rms.get('current_edit_member'); @@ -90,6 +92,11 @@ app.controller('ReviewProjectMemberController', ['$scope', '$http', 'auth', 'con rms.save("review_master_members",[]); rms.save("review_develop_members",[]); rms.save("tab_num",null); - $location.path("/project").search({id: project_id,tag: 1}); + if(vm.current_project.is_member){ + $location.path("/project").search({id: project_id,tag: 1}); + } + else{ + $location.path("/project_list") + } }; }] ); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/send_class_list.js b/public/javascripts/wechat/controllers/send_class_list.js index bc81cfc08..ead0860f5 100644 --- a/public/javascripts/wechat/controllers/send_class_list.js +++ b/public/javascripts/wechat/controllers/send_class_list.js @@ -1,4 +1,6 @@ -app.controller('SendClassListController', ['$scope', '$http','$routeParams', 'config','auth','alertService', 'rms', function($scope, $http, $routeParams, config, auth, alertService,rms){ +app.controller('SendClassListController', ['$scope', '$http','$routeParams', 'config','auth','alertService', 'rms','common', function($scope, $http, $routeParams, config, auth, alertService,rms,common){ +// common.checkLogin(); + var vm = $scope; var send_id = $routeParams.id; diff --git a/public/javascripts/wechat/directives/at_delete_link.js b/public/javascripts/wechat/directives/at_delete_link.js new file mode 100644 index 000000000..15190c327 --- /dev/null +++ b/public/javascripts/wechat/directives/at_delete_link.js @@ -0,0 +1,17 @@ +/** + * Created by ttang on 2016/8/10. + */ +app.directive('atDeleteLink',["$timeout",function(timer){ + return{ + restrict: 'A', + scope: {}, + link: function(scope, element){ + timer(function(){ + $(".at a").each(function(){ + var atText = $(this).text(); + $(this).parent().html(atText); + }); + }) + } + } +}]); diff --git a/public/javascripts/wechat/directives/form_validate.js b/public/javascripts/wechat/directives/form_validate.js index 553560c56..7b5657428 100644 --- a/public/javascripts/wechat/directives/form_validate.js +++ b/public/javascripts/wechat/directives/form_validate.js @@ -7,4 +7,18 @@ app.directive('pwdconfirm', function(){ } } } +}); + +app.directive('unconfirm', function(){ + return { + require: 'ngModel', + link: function(scope, elm, attrs, ctrl){ + ctrl.$validators.unconfirm = function(modelValue, viewValue) { + if(viewValue == ""){ + return true; + } + return (/^[a-zA-Z\d]\w{0,23}[a-zA-Z\d]{0,1}$/.test(viewValue)); + } + } + } }); \ No newline at end of file diff --git a/public/javascripts/wechat/directives/input_focus.js b/public/javascripts/wechat/directives/input_focus.js new file mode 100644 index 000000000..38cc01ec9 --- /dev/null +++ b/public/javascripts/wechat/directives/input_focus.js @@ -0,0 +1,14 @@ +/** + * Created by ttang on 2016/8/10. + */ +app.directive('inputFocus',function(){ + return{ + restrict: 'A', + scope: {}, + link: function(scope, element){ + element.on('click',function(){ + $("#postInput1").focus(); + }); + } + } +}); \ No newline at end of file diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index 7ac0a3bdb..1c40c9c10 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -1,394 +1,466 @@ -app.factory('alertService', function(){ - function Alert(){ - this.title = null; - this.message = null; - this.visible = null; - this.cb = null; - this.invite = ""; - } - - Alert.prototype.showMessage = function(title, msg, cb){ - this.message = msg; - this.title = title; - this.visible = true; - this.cb = cb; - this.invite = ""; - } - - Alert.prototype.dismiss = function(){ - this.message = null; - this.title = null; - this.visible = false; - this.invite = ""; - if(this.cb) {this.cb();} - } - - return { - create: function(){ - return new Alert(); - } - } -}); - -app.factory('wx', ['$window', function($window){ - var wechat = $window.wx; - return wechat; -}]); - -app.factory('auth', ['$http','$routeParams', '$q', 'session', 'config',function($http,$routeParams, $q, session,config){ - //是否已经绑定 - var isBind = function(){ - var defer = $q.defer(); - - var token = getToken(); - if(token && token.length>10){ - defer.resolve(token); - } else { - var code = window.g_code || $routeParams.code || session.get("code"); - $http.post( - '/wechat/get_bind', - {} ///不用传code了,都由服务器来处理 - ).then(function(response){ - if(response.data.status!=0){ - defer.reject(response.data.message); - }else { - session.save("token", response.data.token); - defer.resolve(response.data.token); - } - }).catch(function(e){ - defer.reject(e); - }); - } - - return defer.promise; - } - - var getToken = function(){ - return 'token';//session.get("token"); - } - return {get_bind: isBind, token: getToken}; -}]); - -app.factory("session", function(){ - return { - save: function(key,value){ - sessionStorage.setItem(key,value); - }, - get: function(key){ - return sessionStorage.getItem(key); - } - } -}); - -app.factory('rms', function(){ - var _saveStorage = {}; - var save = function(key, value){ - _saveStorage[key] = value; - }; - - var get = function(key){ - return _saveStorage[key]; - }; - - return {save: save, get: get}; -}); - -app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx', function($http, auth, $routeParams,rms,config,wx){ - var addCommonReply = function(id, type, data, cb){ - - if(!data.comment || data.comment.length<=0){ - return; - } - - var temp = data.comment.replace(/\n/g,'
        '); - - var userInfo = { - type: type, - content: temp, - token: auth.token() - }; - //回复按钮禁用 - data.disabled = true; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+id, - data: userInfo - }).then(function successCallback(response) { - //alert("提交成功"); - //数据提交完成,回复按钮启用 - data.disabled = false; - if(typeof cb === 'function'){ - cb(); - } - - //保证内外回复数一致 - activities = rms.get("activities") || []; - course_activities = rms.get("course_activities") || []; - project_activities = rms.get("project_activities") || []; - for(var i in activities){ - if(activities[i].act_id == id){ - activities[i].reply_count += 1; - break; - } - } - for(var i in course_activities){ - if(course_activities[i].act_id == id){ - course_activities[i].reply_count += 1; - break; - } - } - for(var i in project_activities){ - if(project_activities[i].act_id == id){ - project_activities[i].reply_count += 1; - break; - } - } - rms.save("activities",activities); - rms.save("course_activities",course_activities); - rms.save("project_activities",project_activities); - - }, function errorCallback(response) { - }); - }; - -// var loadCommonData = function(id, type,replytype,page){ -// return $http({ -// method: 'GET', -// url: apiUrl+ type + "/" + id+"?token="+auth.token(), -// }) -// }; - - var loadCommonData = function(id, type,replytype,page){ - return $http({ - method: 'POST', - url: apiUrl+ type + "/" + id, - dataType: 'jsonp', - data:{token:auth.token(),type:replytype,page:page} - }) - }; - - var addCommonPraise = function(act){ -// act.praise_count += 1; -// act.has_praise = true; - - $http({ - method: 'POST', - url: apiUrl + "praise/" + act.act_id, - data:{token:auth.token(),type:act.act_type} - }).then(function successCallback(response) { - console.log(response.data); - }, function errorCallback(response) { - }); - - }; - - var decreaseCommonPraise = function(act){ -// act.praise_count -= 1; -// act.has_praise = false; - $http({ - method: 'POST', - url: apiUrl + "praise/" + act.act_id, - data:{token:auth.token(),type:act.act_type} - }).then(function successCallback(response) { - console.log(response.data); - }, function errorCallback(response) { - }); - }; - - var init = function(args){ - args.scope.formData = {comment: ''}; - var loadData = function(id,replytype,page){ - loadCommonData(id, args.type,replytype,page).then(function successCallback(response) { - console.log(response.data); - //--------------分享内容定制------------- - var tmptile = "分享动态"; - var imgUrl = ""; - - if(response.data.data.title){ - tmptile = response.data.data.title; - } - - var tmpname = "匿名用户"; - - if(response.data.data.user){ - tmpname = response.data.data.user.realname; - imgUrl = window.g_localhost+response.data.data.user.img_url; - } - - if(response.data.data.author){ - tmpname = response.data.data.author.realname; - imgUrl = window.g_localhost+response.data.data.author.img_url; - } - - var desc = "" - if(response.data.data.content){ - desc = response.data.data.content.replace(/<[^>]+>/g,"").replace(/\s*/g,"").replace(/ /g,""); - } - - if(response.data.data.description){ - desc = response.data.data.description.replace(/<[^>]+>/g,"").replace(/\s*/g,"").replace(/ /g,""); - } - - if(desc.length > 30){ - desc = desc.substring(0,30)+"..."; - } - - var title = tmpname+":"+tmptile; - console.log("desc = "+desc); - console.log("imgUrl= "+imgUrl); - - wxConfig(title,desc,imgUrl); - - //--------------分享内容定制------------- - args.loadCallback(response.data); - }, function errorCallback(response) { - }); - }; - - loadData(args.id,0,0); - args.scope.addReply = function(data){ - console.log(data.comment); - addCommonReply(args.id, args.replyType, data, function(){ - args.scope.formData = {comment: ''}; - loadData(args.id,0,0); - if(typeof args.replyCallback === 'function'){ - args.replyCallback(); - } - }); - }; - -// 动态详情界面点赞与动态界面的数据要同步 保证进入详情点赞后出来显示一致 - args.scope.addPraise = function(act){ - activities = rms.get("activities") || []; - course_activities = rms.get("course_activities") || []; - project_activities = rms.get("project_activities") || []; - for(var i in activities){ - if(activities[i].act_id == act.act_id){ - activities[i].praise_count += 1; - activities[i].has_praise = true; - break; - } - } - for(var i in course_activities){ - if(course_activities[i].act_id == act.act_id){ - course_activities[i].praise_count += 1; - course_activities[i].has_praise = true; - break; - } - } - for(var i in project_activities){ - if(project_activities[i].act_id == act.act_id){ - project_activities[i].praise_count += 1; - project_activities[i].has_praise = true; - break; - } - } - rms.save("activities",activities); - rms.save("course_activities",course_activities); - rms.save("project_activities",project_activities); - - act.praise_count += 1; - act.has_praise = true; - addCommonPraise(act); - }; - - args.scope.decreasePraise = function(act){ - activities = rms.get("activities") || []; - course_activities = rms.get("course_activities") || []; - project_activities = rms.get("project_activities") || []; - for(var i in activities){ - if(activities[i].act_id == act.act_id){ - activities[i].praise_count -= 1; - activities[i].has_praise = false; - break; - } - } - for(var i in course_activities){ - if(course_activities[i].act_id == act.act_id){ - course_activities[i].praise_count -= 1; - course_activities[i].has_praise = false; - break; - } - } - for(var i in project_activities){ - if(project_activities[i].act_id == act.act_id){ - project_activities[i].praise_count -= 1; - project_activities[i].has_praise = false; - break; - } - } - rms.save("activities",activities); - rms.save("course_activities",course_activities); - rms.save("project_activities",project_activities); - - act.praise_count -= 1; - act.has_praise = false; - decreaseCommonPraise(act); - }; - - args.scope.showMoreReply = function(replytype,data){ - if(!data.page){ - data.page = 1; - } - else{ - data.page = data.page + 1; - } - - loadCommonData(data.id, args.type,replytype,data.page).then(function successCallback(response) { - args.loadCallback(response.data); - }, function errorCallback(response) { - }); - }; - - args.scope.commentreply_path = config.rootPath+ 'templates/comment_reply.html'; - - }; - - var wxConfig = function(title,desc,imgUrl){ - - if(title == null || title == ""){ - title = 'Trustie创新实践平台'; - } - - if(desc == null || desc == ""){ - desc = 'Trustie创新实践平台'; - } - - if(imgUrl == null || imgUrl == ""){ - imgUrl = 'http://www.trustie.net/images/logo2.png'; - } - - wx.ready(function(){ - wx.onMenuShareTimeline({ - title: title, // 分享标题 -// link: 'http://www.trustie.net/', // 分享链接 - imgUrl: imgUrl, // 分享图标 - success: function () { - console.log("share successed."); - }, - cancel: function () { - console.log("share canceled."); - } - }); - - wx.onMenuShareAppMessage({ - title: title, // 分享标题 - desc: desc, // 分享描述 -// link: '', // 分享链接 -// imgUrl: '', // 分享图标 - imgUrl: imgUrl, // 分享图标 -// type: '', // 分享类型,music、video或link,不填默认为link -// dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 - success: function () { - // 用户确认分享后执行的回调函数 - }, - cancel: function () { - // 用户取消分享后执行的回调函数 - } - }); - }); - }; - - return {init: init, addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise, wxConfig: wxConfig}; -}]); +app.factory('alertService', function(){ + function Alert(){ + this.title = null; + this.message = null; + this.visible = null; + this.cb = null; + this.invite = ""; + } + + Alert.prototype.showMessage = function(title, msg, cb){ + this.message = msg; + this.title = title; + this.visible = true; + this.cb = cb; + this.invite = ""; + } + + Alert.prototype.dismiss = function(){ + this.message = null; + this.title = null; + this.visible = false; + this.invite = ""; + if(this.cb) {this.cb();} + } + + return { + create: function(){ + return new Alert(); + } + } +}); + +app.factory('wx', ['$window', function($window){ + var wechat = $window.wx; + return wechat; +}]); + +app.factory('auth', ['$http','$routeParams', '$q', 'session', 'config',function($http,$routeParams, $q, session,config){ + //是否已经绑定 + var isBind = function(){ + var defer = $q.defer(); + + var token = getToken(); + if(token && token.length>10){ + defer.resolve(token); + } else { + var code = window.g_code || $routeParams.code || session.get("code"); + $http.post( + '/wechat/get_bind', + {} ///不用传code了,都由服务器来处理 + ).then(function(response){ + if(response.data.status!=0){ + defer.reject(response.data.message); + }else { + session.save("token", response.data.token); + defer.resolve(response.data.token); + } + }).catch(function(e){ + defer.reject(e); + }); + } + + return defer.promise; + } + + var getToken = function(){ + return 'token';//session.get("token"); + } + return {get_bind: isBind, token: getToken}; +}]); + +app.factory("session", function(){ + return { + save: function(key,value){ + sessionStorage.setItem(key,value); + }, + get: function(key){ + return sessionStorage.getItem(key); + } + } +}); + +app.factory('rms', function(){ + var _saveStorage = {}; + var save = function(key, value){ + _saveStorage[key] = value; + }; + + var get = function(key){ + return _saveStorage[key]; + }; + + return {save: save, get: get}; +}); + +app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$location', function($http, auth, $routeParams,rms,config,wx,$location){ + var addCommonReply = function(id, type, data,args, cb){ + //先判断有没有绑定 +// $http.post( +// '/wechat/is_bind', +// {} ///不用传code了,都由服务器来处理 +// ).then(function(response){ +// console.log(response.data); +// if(response.data.status != 0){ +// $location.path("/login_tip"); +// } +// }); + + if(!data.comment || data.comment.length<=0){ + return; + } + + var temp = data.comment.replace(/\n/g,'
        '); + + var userInfo = { + type: type, + content: temp, + token: auth.token() + }; + //回复按钮禁用 + data.disabled = true; + + $http({ + method: 'POST', + url: apiUrl+ "new_comment/"+id, + data: userInfo + }).then(function successCallback(response) { + //alert("提交成功"); + //数据提交完成,回复按钮启用 + console.log(response); + if(response.data.status == -1){ + console.log("回复失败!"); + data.comment = ""; + if(response.data.tip == 0){ + args.scope.replytip = "您不是该私有班级成员,不能回复"; + } + else{ + args.scope.replytip = "您不是该私有项目成员,不能回复"; + } + return; + } + + data.disabled = false; + if(typeof cb === 'function'){ + cb(response.data.subscribe); + } + + //保证内外回复数一致 + activities = rms.get("activities") || []; + course_activities = rms.get("course_activities") || []; + project_activities = rms.get("project_activities") || []; + for(var i in activities){ + if(activities[i].act_id == id){ + activities[i].reply_count += 1; + break; + } + } + for(var i in course_activities){ + if(course_activities[i].act_id == id){ + course_activities[i].reply_count += 1; + break; + } + } + for(var i in project_activities){ + if(project_activities[i].act_id == id){ + project_activities[i].reply_count += 1; + break; + } + } + rms.save("activities",activities); + rms.save("course_activities",course_activities); + rms.save("project_activities",project_activities); + + }, function errorCallback(response) { + }); + }; + +// var loadCommonData = function(id, type,replytype,page){ +// return $http({ +// method: 'GET', +// url: apiUrl+ type + "/" + id+"?token="+auth.token(), +// }) +// }; + + var loadCommonData = function(id, type,replytype,page){ + return $http({ + method: 'POST', + url: apiUrl+ type + "/" + id, + dataType: 'jsonp', + data:{token:auth.token(),type:replytype,page:page} + }) + }; + + var addCommonPraise = function(act){ +// act.praise_count += 1; +// act.has_praise = true; + + $http({ + method: 'POST', + url: apiUrl + "praise/" + act.act_id, + data:{token:auth.token(),type:act.act_type} + }).then(function successCallback(response) { + console.log(response.data); + }, function errorCallback(response) { + }); + + }; + + var decreaseCommonPraise = function(act){ +// act.praise_count -= 1; +// act.has_praise = false; + $http({ + method: 'POST', + url: apiUrl + "praise/" + act.act_id, + data:{token:auth.token(),type:act.act_type} + }).then(function successCallback(response) { + console.log(response.data); + }, function errorCallback(response) { + }); + }; + + var init = function(args){ + args.scope.replytip = "输入回复内容~"; + args.scope.formData = {comment: ''}; + var loadData = function(id,replytype,page){ + loadCommonData(id, args.type,replytype,page).then(function successCallback(response) { + console.log(response.data); + //--------------分享内容定制------------- + var tmptile = "分享动态"; + var imgUrl = ""; + + if(response.data.data.title){ + tmptile = response.data.data.title; + } + + var tmpname = "匿名用户"; + + if(response.data.data.user){ + tmpname = response.data.data.user.realname; + imgUrl = window.g_localhost+response.data.data.user.img_url; + } + + if(response.data.data.author){ + tmpname = response.data.data.author.realname; + imgUrl = window.g_localhost+response.data.data.author.img_url; + } + + var desc = "" + if(response.data.data.content){ + desc = response.data.data.content.replace(/<[^>]+>/g,"").replace(/\s*/g,"").replace(/ /g,""); + } + + if(response.data.data.description){ + desc = response.data.data.description.replace(/<[^>]+>/g,"").replace(/\s*/g,"").replace(/ /g,""); + } + + if(desc.length > 30){ + desc = desc.substring(0,30)+"..."; + } + + var title = tmpname+":"+tmptile; + console.log("desc = "+desc); + console.log("imgUrl= "+imgUrl); + + var link = ""; + + if(args.urlName == "discussion"){ + var urlName = response.data.type_name + "_discussion"; + link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid + + "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+response.data.data.act_id+ + "&response_type=code&scope=snsapi_userinfo&state="+urlName+"&connect_redirect=1#wechat_redirect"; + } + else{ + link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid + + "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+response.data.data.act_id+ + "&response_type=code&scope=snsapi_userinfo&state="+args.urlName+"&connect_redirect=1#wechat_redirect"; + } + +// if(args.urlName == "discussion"){ +// var urlName = response.data.type_name + "_discussion"; +// link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d" + +// "&redirect_uri=https://test.forge.trustie.net/wechat/user_activities?id="+response.data.data.act_id+ +// "&response_type=code&scope=snsapi_base&state="+urlName+"&connect_redirect=1#wechat_redirect"; +// } +// else{ +// link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d" + +// "&redirect_uri=https://test.forge.trustie.net/wechat/user_activities?id="+response.data.data.act_id+ +// "&response_type=code&scope=snsapi_base&state="+args.urlName+"&connect_redirect=1#wechat_redirect"; +// } + + console.log("link= "+link); + + wxConfig(title,desc,imgUrl,link); + + //--------------分享内容定制------------- + args.loadCallback(response.data); + }, function errorCallback(response) { + }); + }; + + loadData(args.id,0,0); + args.scope.addReply = function(data){ + console.log(data.comment); + addCommonReply(args.id, args.replyType, data,args, function(subscribe){ + args.scope.formData = {comment: ''}; + if(subscribe == 0){ + $location.path("/login_tip"); + return; + } + else{ + loadData(args.id,0,0); + } + + if(typeof args.replyCallback === 'function'){ + args.replyCallback(); + } + }); + }; + +// 动态详情界面点赞与动态界面的数据要同步 保证进入详情点赞后出来显示一致 + args.scope.addPraise = function(act){ + activities = rms.get("activities") || []; + course_activities = rms.get("course_activities") || []; + project_activities = rms.get("project_activities") || []; + for(var i in activities){ + if(activities[i].act_id == act.act_id){ + activities[i].praise_count += 1; + activities[i].has_praise = true; + break; + } + } + for(var i in course_activities){ + if(course_activities[i].act_id == act.act_id){ + course_activities[i].praise_count += 1; + course_activities[i].has_praise = true; + break; + } + } + for(var i in project_activities){ + if(project_activities[i].act_id == act.act_id){ + project_activities[i].praise_count += 1; + project_activities[i].has_praise = true; + break; + } + } + rms.save("activities",activities); + rms.save("course_activities",course_activities); + rms.save("project_activities",project_activities); + + act.praise_count += 1; + act.has_praise = true; + addCommonPraise(act); + }; + + args.scope.decreasePraise = function(act){ + activities = rms.get("activities") || []; + course_activities = rms.get("course_activities") || []; + project_activities = rms.get("project_activities") || []; + for(var i in activities){ + if(activities[i].act_id == act.act_id){ + activities[i].praise_count -= 1; + activities[i].has_praise = false; + break; + } + } + for(var i in course_activities){ + if(course_activities[i].act_id == act.act_id){ + course_activities[i].praise_count -= 1; + course_activities[i].has_praise = false; + break; + } + } + for(var i in project_activities){ + if(project_activities[i].act_id == act.act_id){ + project_activities[i].praise_count -= 1; + project_activities[i].has_praise = false; + break; + } + } + rms.save("activities",activities); + rms.save("course_activities",course_activities); + rms.save("project_activities",project_activities); + + act.praise_count -= 1; + act.has_praise = false; + decreaseCommonPraise(act); + }; + + args.scope.showMoreReply = function(replytype,data){ + if(!data.page){ + data.page = 1; + } + else{ + data.page = data.page + 1; + } + + loadCommonData(data.id, args.type,replytype,data.page).then(function successCallback(response) { + args.loadCallback(response.data); + }, function errorCallback(response) { + }); + }; + + args.scope.commentreply_path = config.rootPath+ 'templates/comment_reply.html'; + + }; + + var wxConfig = function(title,desc,imgUrl,link){ + + if(title == null || title == ""){ + title = 'Trustie创新实践平台'; + } + + if(desc == null || desc == ""){ + desc = 'Trustie创新实践平台'; + } + + if(imgUrl == null || imgUrl == ""){ + imgUrl = window.g_localhost+'/images/wechat/wx_logo.jpg'; + } + + wx.ready(function(){ + wx.onMenuShareTimeline({ + title: title, // 分享标题 + link: link, // 分享链接 + imgUrl: imgUrl, // 分享图标 + success: function () { + console.log("share successed."); + }, + cancel: function () { + console.log("share canceled."); + } + }); + + wx.onMenuShareAppMessage({ + title: title, // 分享标题 + desc: desc, // 分享描述 + link: link, // 分享链接 +// imgUrl: '', // 分享图标 + imgUrl: imgUrl, // 分享图标 +// type: '', // 分享类型,music、video或link,不填默认为link +// dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 + success: function () { + // 用户确认分享后执行的回调函数 + }, + cancel: function () { + // 用户取消分享后执行的回调函数 + } + }); + }); + }; + + var checkLogin = function(){ + $http.post( + '/wechat/is_bind', + {} ///不用传code了,都由服务器来处理 + ).then(function(response){ + console.log(response.data); + if(response.data.status != 0){ + $location.path("/login"); + return; + } + }); + }; + + return {init: init, addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise, wxConfig: wxConfig, checkLogin: checkLogin}; +}]); diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js index 70d1491f4..7311c66c1 100644 --- a/public/javascripts/wechat/others/routes.js +++ b/public/javascripts/wechat/others/routes.js @@ -23,13 +23,13 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func controller: 'RegController' }) .when('/activites', makeRoute('activities.html', 'ActivityController')) - .when('/issues/:id', makeRoute('issue_detail.html', 'IssueController')) - .when('/project_discussion/:id', makeRoute('project_discussion.html', 'DiscussionController')) - .when('/homework/:id', makeRoute('homework_detail.html', 'HomeworkController')) - .when('/course_notice/:id', makeRoute('course_notice.html', 'CourseNoticeController')) - .when('/course_discussion/:id', makeRoute('course_discussion.html', 'DiscussionController')) - .when('/journal_for_message/:id', makeRoute('jour_message_detail.html', 'JournalsController')) - .when('/blog_comment/:id', makeRoute('blog_detail.html', 'BlogController')) + .when('/issues', makeRoute('issue_detail.html', 'IssueController')) + .when('/project_discussion', makeRoute('project_discussion.html', 'DiscussionController')) + .when('/homework', makeRoute('homework_detail.html', 'HomeworkController')) + .when('/course_notice', makeRoute('course_notice.html', 'CourseNoticeController')) + .when('/course_discussion', makeRoute('course_discussion.html', 'DiscussionController')) + .when('/journal_for_message', makeRoute('jour_message_detail.html', 'JournalsController')) + .when('/blog_comment', makeRoute('blog_detail.html', 'BlogController')) .when('/class', makeRoute('class.html', 'ClassController')) .when('/new_class', makeRoute('new_class.html', 'NewClassController')) .when('/edit_class', makeRoute('edit_class.html', 'EditClassController')) @@ -47,6 +47,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func .when('/project_invite_code', {templateUrl: rootPath + 'project_invite_code.html', controller: 'ProjectInviteCodeController'}) .when('/join_project', makeRoute('join_project.html', 'JoinProjectController')) .when('/review_project_member', makeRoute('review_project_member.html', 'ReviewProjectMemberController')) + .when('/login_tip', makeRoute('login_tip.html', 'LoginTipController')) .otherwise({ redirectTo: '/activites' }); diff --git a/public/stylesheets/css/common.css b/public/stylesheets/css/common.css index f704a3f0d..fbce13354 100644 --- a/public/stylesheets/css/common.css +++ b/public/stylesheets/css/common.css @@ -4,7 +4,7 @@ body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{ margin:0; padding:0;} body,table,input,textarea,select,button { font-family: "微软雅黑","宋体"; font-size:12px;line-height:1.5; background:#eaebec;} div,img,tr,td,table{ border:0;} -table,tr,td{border:0;cellspacing:0; cellpadding:0;} +table,tr,td{border:0;} ol,ul,li{ list-style-type:none} blockquote { border:1px solid #d4d4d4; diff --git a/public/stylesheets/css/project.css b/public/stylesheets/css/project.css index 4c4019593..1c7563a58 100644 --- a/public/stylesheets/css/project.css +++ b/public/stylesheets/css/project.css @@ -160,9 +160,9 @@ div.thumbnails div {background:#fff;display:inline-block;margin-right:2px;} .repos_files ul:hover{ background:#ffffdd;} .repos_t_c li{ text-align:center;} .pic_stats{display:block; background:url(/images/public_icon.png) 0px -548px no-repeat; width:20px; height:15px;} -.tree-age{width:10%; text-align:right;} +.tree-age{width:15%; text-align:right;} .tree-author{width:10%; text-align:left;} -.tree-comments{width:40%; text-align:left;} +.tree-comments{width:35%; text-align:left;} /* 里程碑 */ .roadmap_box{ background:#f8f8f8; width:648px; padding:10px; margin-top:5px; border:1px solid #ddd; color:#555;} @@ -372,7 +372,7 @@ tr.entry td.filename_no_report { width: 40%; } tr.entry td.size { text-align: right; font-size: 90%; } tr.entry td.revision, tr.entry td.author { text-align: center; } tr.entry td.age { text-align: right; } -tr.entry.file td.filename a { margin-center: 16px; } +tr.entry.file td.filename a { } tr.entry.file td.filename_no_report a { margin-left: 16px; } tr span.expander {background-image: url(/images/bullet_toggle_plus.png); padding-left: 8px; margin-left: 0; cursor: pointer;} @@ -511,8 +511,9 @@ a:hover.upload_btn_grey{background:#8a8a8a;} .analysis-result-name {width:200px;} .analysis-result-version {width:90px; text-align:right;} .analysis-result-loc {width:60px; text-align:right;} -.analysis-result-debt {width:160px; text-align:right;} +.analysis-result-debt {width:80px; text-align:right;} .analysis-result-time {width:150px; text-align:right;} +.analysis-result-edit {width:80px; text-align:right;} .analysis-name-icon {background:url(/images/code-analysis-icon.png) -2px -148px no-repeat; width:16px; height:16px; display:inline-block; vertical-align:middle;} @@ -523,7 +524,7 @@ a:hover.upload_btn_grey{background:#8a8a8a;} .project-merge-banner li a {padding:14px; font-size:14px; color:#555; display:inline-block;} .project-number-dot {display:inline-block; min-width:10px; padding:3px 5px; font-size:12px; color:#888; line-height:1; vertical-align:middle; white-space:nowrap; text-align:center; background-color:#eee; border-radius:10px; margin-left:5px;} .project-merge-content {} -.project-merge-content li {padding:10px; margin:0 -10px; background-color:#f9f9f9; border-bottom:1px solid #e5e5e5;} +.project-merge-content>li {padding:10px; margin:0 -10px; background-color:#f9f9f9; border-bottom:1px solid #e5e5e5;} .no-merge-content {padding:10px 15px; color:#888;} .new-merge-request {border-bottom:1px solid #ddd; padding-bottom:10px;} .new-merge-wrap {font-size:13px; color:#484848; border-bottom:1px solid #ddd; padding:10px 0;} @@ -540,4 +541,42 @@ a:hover.upload_btn_grey{background:#8a8a8a;} .merge-commit-code {width:150px; float:left; text-align:right;} .merge-show {margin:-10px -10px 0 -10px; padding:10px; line-height:36px; border-bottom:1px solid #ddd;} .open-status {color:#fff; padding:0 16px; background-color:#3b94d6; border-radius:2px; display:inline-block;} -.merge-commit-option {padding:12px; border:1px solid #ddd; background-color:#f9f9f9; border-radius:2px;} \ No newline at end of file +.merge-commit-option {padding:12px; border:1px solid #ddd; background-color:#f9f9f9; border-radius:2px;} +.merge-discussion-content {font-size:13px; color: #484848; margin:0 -10px; padding:10px; border-bottom:1px solid #ddd;} +.merge-discussion-detail {font-size:13px; line-height:1.5em; color:#484848; margin-top:10px;} +.merge-discussion-automatic {background-color:#fdfdfd;} +.merge-discussion-input {margin:0 -10px; padding:10px; background-color:#f8f8f8;} +.merge-discussion-input textarea {width:720px; height:80px; font-size:13px; line-height:16px; color:#484848; padding:5px;} + +/*新版项目列表新增*/ +.new_project_title{ font-size:16px; color:#333; max-width:560px; font-weight:normal;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; } +.icons_project_list{ width:8px; height:8px; border:2px solid #fff; background:#3b94d6;-webkit-border-radius:50px;-moz-border-radius:50px;-o-border-radius:50px;border-radius:50px;-webkit-box-shadow: 0px 2px 5px rgba(146, 153, 169, 0.5);-moz-box-shadow: 0px 2px 5px rgba(146, 153, 169, 0.5);box-shadow: 0px 2px 5px rgba(146, 153, 169, 0.5); } +.new_projectlist_more{ text-align:center;} +.new_projectlist_more a:hover{ color:#3b94d6;} +/*新版项目引用的新版课程大纲中的公共样式*/ +.icons_tishi{ + width: 110px; + height: 110px; + margin: 135px auto 20px; +} +.sy_tab_con_p{ + font-size: 16px; + text-align: center; + margin-bottom:100px; + color:#888; +} +a.sy_btn_green{ + display:inline-block; + color: #fff; + background: #60b25e; + text-align: center; + font-size: 12px; + padding:0 15px; + height: 30px; + line-height: 30px; + -webkit-border-radius:3px; + -moz-border-radius:3px; + -o-border-radius:3px; + border-radius:3px; +} +a:hover.sy_btn_green{ background: #51a74f;} \ No newline at end of file diff --git a/public/stylesheets/css/structure.css b/public/stylesheets/css/structure.css index 44b1165c6..1d2c106e2 100644 --- a/public/stylesheets/css/structure.css +++ b/public/stylesheets/css/structure.css @@ -1,5 +1,3 @@ -/*将header.css文件和public.css,new_user.css中的内容统一*/ - @charset "utf-8"; /* CSS Document */ @@ -34,7 +32,7 @@ a:hover.search_btn{ background: #0fa9bb;} a.parent {background: url(/images/arrowList.png) -30px 3px no-repeat; width:95px; padding-right:50px;} a.parent:hover {background: url(/images/arrowList.png) -30px -14px no-repeat; width:95px; padding-right:50px; color:#fe7d68;} a.linkToOrange:hover {color:#fe7d68;} -#userInfo ul li {positon: relative;} +#userInfo ul li {position: relative;} #userInfo ul li ul {display:none;} #userInfo ul li:hover ul {display:block; position:absolute;} #userInfo ul li:hover ul li ul {display:none;} @@ -383,7 +381,7 @@ ul.subNavArrow:hover li ul {display:block;} .currentDd{color:#0781b4;} .currentDt{background-color:#fff;} .navContent{display: none;border-bottom:solid 1px #e5e3da; } -.navContent li a{display:block;width:240px;heigh:28px;text-align:center;font-size:12px;line-height:28px;color:#333} +.navContent li a{display:block;width:240px;height:28px;text-align:center;font-size:12px;line-height:28px;color:#333} .navContent li a:hover{color:#fff;background-color:#b3e0ee} a.subnav_num{ font-weight:normal; color:#ff7143; font-size:12px;} a.subnav_green{ background:#28be6c; color:#fff; font-size:12px; font-weight:normal;height:18px; padding:0px 5px; padding-top:2px; display:block; margin-top:2px; margin-bottom:5px; float:right; margin-right:5px;line-height:1.4 !important;} @@ -474,6 +472,7 @@ a.f_grey:hover {color:#000000;} .shadowbox_news_list{ max-height:400px; overflow:hidden;} .shadowbox_news_list a{ color:#999;} .shadowbox_news_list li{ height:40px; border-bottom:1px dashed #ebebeb; line-height:40px;overflow:hidden; white-space: nowrap; text-overflow:ellipsis; padding:0 10px;} +.shadowbox_news_list li:last-child {border-bottom:none;} .shadowbox_news_list li:hover{ background-color:#eee;} span.shadowbox_news_user{ color:#3b94d6;} a.shadowbox_news_all{ display:block; width:305px; height:40px; line-height:40px; color:#3b94d6; text-align:center;border-top:1px solid #eee;} diff --git a/public/stylesheets/sy_public.css b/public/stylesheets/sy_public.css index e1d3eaf38..deeb36c15 100644 --- a/public/stylesheets/sy_public.css +++ b/public/stylesheets/sy_public.css @@ -234,7 +234,7 @@ a.sy_icons_close{ .hw_popup_top a.hw_icons_close{display:block;width:26px; height:26px;background: url(../images/hw/icons_hw.png) 0 -95px no-repeat; transition: all 0s linear;} .hw_popup_top a:hover.hw_icons_close{background: url(../images/hw/icons_hw.png) -41px -95px no-repeat; } .hw_popup_con{ width:770px; max-height:770px; margin:0 auto;} -.hw_popup_txt{width:770px; max-height:700px; margin:15px auto;overflow:auto;} +.hw_popup_txt{width:770px; max-height:680px; margin:15px auto;overflow:auto;} /* 题库发送弹框 */ .hw_sendpopup_box{ width:460px;background:#fff;padding-bottom:15px;-webkit-border-radius:5px;-moz-border-radius:5px;-o-border-radius:5px;border-radius:5px;-webkit-box-shadow: 0px 0px 8px rgba(146, 153, 169, 0.5);-moz-box-shadow: 0px 0px 8px rgba(146, 153, 169, 0.5);box-shadow: 0px 0px 8px rgba(146, 153, 169, 0.5);} .hw_sendpopup_top{background:#3b94d6;height:40px;-webkit-border-radius: 5px 5px 0px 0px;-o-border-radius: 5px 5px 0px 0px;border-radius: 5px 5px 0px 0px;} diff --git a/public/stylesheets/syllabus.css b/public/stylesheets/syllabus.css index 703c68c61..9e6a9817d 100644 --- a/public/stylesheets/syllabus.css +++ b/public/stylesheets/syllabus.css @@ -324,9 +324,10 @@ a.sy_class_option:hover { height:110px; } .sy_class_id{ - width:110px; - height:80px; - background:#f1f1f1; + width:108px; + height:78px; + border:1px solid #f1f1f1; + background:#fff; text-align:center; padding-top:30px; } diff --git a/public/stylesheets/weui/weixin.css b/public/stylesheets/weui/weixin.css index 8eabdd420..7375fc80c 100644 --- a/public/stylesheets/weui/weixin.css +++ b/public/stylesheets/weui/weixin.css @@ -87,6 +87,7 @@ a.underline {text-decoration:underline;} .btn-disabled {background-color:#ccc !important;} .btn2 {width:145px; height:35px; color:#fff; font-size:15px; line-height:35px; text-align:center; vertical-align:middle; margin:18px auto 20px auto; border-radius:50px; display:block;} .btn3 {width:145px; height:35px; color:#fff; font-size:15px; line-height:35px; text-align:center; vertical-align:middle; border-radius:50px; display:block;} +.btn4 {width:150px; height:40px; line-height:40px; vertical-align:middle; text-align:center; color:#fff; display:inline-block; border-radius:5px;} .fixed-bottom-btn {position:fixed; bottom:5px; left:50%; transform:translate(-50%,0);} /*tab*/ @@ -178,7 +179,7 @@ a.underline {text-decoration:underline;} .invitation-code-wrap {text-align:center; font-size:18px; color:#3b3b3b; padding:16px;} .share-code-wrap {width:100%; background-color:#efeff4;} .share-code-btn, .finish-btn {width:145px; height:35px; color:#fff; font-size:15px; line-height:35px; text-align:center; vertical-align:middle; background-color:#ff7239; margin:18px auto 20px auto; border-radius:50px; display:block;} -.share-code-instruction {max-width:228px; font-size:12px; color:#666; line-height:20px; margin:0 auto;} +.share-code-instruction {max-width:228px; font-size:12px; color:#666; line-height:20px; margin:20px auto 30px;} /*20160613班级详情*/ .class-detail-name, .blue-title {width:100%; height:45px; line-height:45px; vertical-align:middle; background-color:#3b94d6; color:#fff; font-size:18px; text-align:center;} @@ -216,9 +217,10 @@ a.underline {text-decoration:underline;} .border-bottom-none {border-bottom:none !important;} .border-top-none {border-top:none !important;} .students-amount {height:14px; line-height:14px; vertical-align:middle; padding:2px 5px; background-color:#e6e6e6; border-radius:10px;} +.amount-arrow {height:14px; line-height:14px; vertical-align:middle; margin-top:12px;} .new-class-btn {font-size:15px; color:#fff; background-color:#3b94d6; padding:10px 40px; border-radius:20px; display:inline-block; margin:0 auto;} .join-class-btn {font-size:15px; color:#444; background-color:#ccc; padding:10px 40px; border-radius:20px; display:inline-block; margin:0 auto;} -.new-class-input {width:60%; color:#555; height:16px; line-height:16px; vertical-align:middle; border:none; outline:none; padding:8px 0;} +.new-class-input {width:60%; color:#555; height:16px; line-height:16px; border:none; outline:none; padding:11px 0;} .class-list-setting {position:absolute; top:11px; right:10px;} .class-setting-wrap {width:38px; height:38px; position:absolute; top:0; right:0;} @@ -230,8 +232,7 @@ a.underline {text-decoration:underline;} .login-box{display:inline-block; width:14px; height:14px; line-height:14px; text-align:center; vertical-align:middle; border:1px solid #ccc; background:#fff; border-radius:3px; color:#fff; cursor:pointer;} .login-box.checked{background:#63c360; border:1px solid #63c360;} .login-box.checked:after{content:url(/images/wechat/checked.png);} -.forget-psw-wrap {width:60px; margin:0 auto;} -.forget-psw {position:fixed; bottom:10px;} +.forget-psw-wrap {width:60px; margin:30px auto;} /*二级回复*/ .mult-reply-container{ border:solid 1px #f3ddb3; background:#fffef4; padding:4px;color:#999;} @@ -247,4 +248,13 @@ a.underline {text-decoration:underline;} /*新建说明*/ .new-tip {line-height:2;} -.new-tip li {position:relative; padding-left:10px;} \ No newline at end of file +.new-tip li {position:relative; padding-left:10px;} + +/*20160810绑定说明*/ +.ac-wrap {text-align:center;} +.ac-content {display:inline-block; line-height:2;} +.ac-content li {position:relative; text-align:left; padding-left:5px;} + +/*发布帖子,通知*/ +.full-width-wrap {padding:5px 15px; background-color:#fff; border-top:1px solid #ddd; border-bottom:1px solid #ddd;} +.full-width-textarea {width:100%; height:180px; line-height:18px; max-height:180px; border:none; resize:none; font-size:13px; color:#555;} \ No newline at end of file diff --git a/spec/factories/pull_requests.rb b/spec/factories/pull_requests.rb new file mode 100644 index 000000000..51a2b94a1 --- /dev/null +++ b/spec/factories/pull_requests.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :pull_request do + pull_request_id 1 +gpid 1 +user_id 1 + end + +end diff --git a/spec/models/pull_request_spec.rb b/spec/models/pull_request_spec.rb new file mode 100644 index 000000000..d7e798e9a --- /dev/null +++ b/spec/models/pull_request_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe PullRequest, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end