Conflicts: app/controllers/admin_controller.rb config/routes.rb lib/redmine.rbcxt_course
commit
7481d96166
@ -0,0 +1 @@
|
|||||||
|
{"access_token":"bFlabz0uBcoIBfWL7nBJkgpl26aOWDy-dyCOvH_MjUo_hMOOKG83WV1cCL1MG6H-AE-6eMI0iyLoOoAMv9Y3pFFsLYD-GAGr3UH9fT8OqeHMDlFhXyRTvHv9l2QPHGpcARUcCGANEH","expires_in":7200,"got_token_at":1462934760}
|
@ -0,0 +1,63 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Activities< Grape::API
|
||||||
|
resources :activities do
|
||||||
|
|
||||||
|
desc "get user activities"
|
||||||
|
|
||||||
|
params do
|
||||||
|
requires :page, type: Integer
|
||||||
|
requires :openid, type: String
|
||||||
|
end
|
||||||
|
post do
|
||||||
|
user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
=begin
|
||||||
|
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
|
||||||
|
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
|
||||||
|
page = params[:page] ? params[:page] : 0
|
||||||
|
user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
|
||||||
|
user_course_ids = (user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
|
||||||
|
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||||
|
project_types = "('Message','Issue','ProjectCreateInfo')"
|
||||||
|
principal_types = "JournalsForMessage"
|
||||||
|
|
||||||
|
blog_ids = "("+user.blog.id.to_s+","+((User.watched_by(user.id).count == 0 )? '0' :User.watched_by(user.id).map{|u| u.blog.id}.join(','))+")"
|
||||||
|
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
|
||||||
|
|
||||||
|
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
|
||||||
|
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
|
||||||
|
page = params[:page] ? params[:page] : 0
|
||||||
|
user_project_ids = (user.projects.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.map{|project| project.id}-shield_project_ids).join(",") + ")"
|
||||||
|
user_course_ids = (user.courses.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.map{|course| course.id}-shield_course_ids).join(",") + ")"
|
||||||
|
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||||
|
project_types = "('Message','Issue','ProjectCreateInfo')"
|
||||||
|
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}").map { |blog| blog.id}.join(",")
|
||||||
|
blog_ids = "(" + watched_user_blog_ids + ")"
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,19 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class BlogComments< Grape::API
|
||||||
|
resources :blog_comments do
|
||||||
|
|
||||||
|
desc "get special topic"
|
||||||
|
get ':id' do
|
||||||
|
user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
blog = BlogComment.find params[:id]
|
||||||
|
present :data, blog, with: Mobile::Entities::BlogComment,user: user
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Issues< Grape::API
|
||||||
|
resources :issues do
|
||||||
|
include IssuesHelper
|
||||||
|
|
||||||
|
desc "get special issuse"
|
||||||
|
get ':id' do
|
||||||
|
user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
issue = Issue.find params[:id]
|
||||||
|
present :data, issue, with: Mobile::Entities::Issue,user: user
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,18 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class JournalForMessages< Grape::API
|
||||||
|
resources :journal_for_messages do
|
||||||
|
|
||||||
|
desc "get special journal"
|
||||||
|
get ':id' do
|
||||||
|
user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
jour = JournalsForMessage.find params[:id]
|
||||||
|
present :data, jour, with: Mobile::Entities::Jours,user: user
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,18 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Messages< Grape::API
|
||||||
|
resources :messages do
|
||||||
|
|
||||||
|
desc "get special topic"
|
||||||
|
get ':id' do
|
||||||
|
user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
message = Message.find params[:id]
|
||||||
|
present :data, message, with: Mobile::Entities::Message,user: user
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,105 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class NewComment< Grape::API
|
||||||
|
include ApplicationHelper
|
||||||
|
include ApiHelper
|
||||||
|
resources :new_comment do
|
||||||
|
|
||||||
|
desc "add a new comment"
|
||||||
|
params do
|
||||||
|
requires :type, type: String
|
||||||
|
requires :content, type: String
|
||||||
|
requires :openid, type: String
|
||||||
|
end
|
||||||
|
post ':id' do
|
||||||
|
type = params[:type]
|
||||||
|
result = 1
|
||||||
|
current_user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
if params[:content]!="" && current_user
|
||||||
|
case type
|
||||||
|
when "HomeworkCommon"
|
||||||
|
homework_common = HomeworkCommon.find(params[:id])
|
||||||
|
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
|
||||||
|
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
|
||||||
|
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
|
||||||
|
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
|
||||||
|
end
|
||||||
|
when 'BlogComment'
|
||||||
|
blog = BlogComment.find(params[:id]).root
|
||||||
|
blogComment = BlogComment.new
|
||||||
|
blogComment.author = current_user
|
||||||
|
blogComment.blog = blog.blog
|
||||||
|
blogComment.content = params[:content]
|
||||||
|
blogComment.title = "RE: #{blog.title}"
|
||||||
|
if blog.children << blogComment
|
||||||
|
result = 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if result == 2
|
||||||
|
update_course_activity_api(type,params[:id])
|
||||||
|
update_user_activity_api(type,params[:id])
|
||||||
|
update_org_activity_api(type,params[:id])
|
||||||
|
update_forge_activity_api(type,params[:id])
|
||||||
|
update_principal_activity_api(type,params[:id])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
result = 3
|
||||||
|
end
|
||||||
|
present :result, result
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,18 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Newss< Grape::API
|
||||||
|
resources :newss do
|
||||||
|
|
||||||
|
desc "get special news"
|
||||||
|
get ':id' do
|
||||||
|
user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
news = News.find params[:id]
|
||||||
|
present :data, news, with: Mobile::Entities::News,user: user
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,41 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Praise< Grape::API
|
||||||
|
include ApiHelper
|
||||||
|
resources :praise do
|
||||||
|
desc "praise an activity"
|
||||||
|
|
||||||
|
params do
|
||||||
|
requires :type, type: String
|
||||||
|
requires :openid, type: String
|
||||||
|
end
|
||||||
|
post ':id' do
|
||||||
|
obj_id = params[:id]
|
||||||
|
obj_type = params[:type]
|
||||||
|
user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first
|
||||||
|
if pts.blank?
|
||||||
|
praise_or_cancel(obj_type,obj_id,user,1)
|
||||||
|
obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
|
||||||
|
num = get_activity_praise_num(obj) if !obj.blank?
|
||||||
|
else
|
||||||
|
pts.destroy if !pts.blank?
|
||||||
|
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除
|
||||||
|
ptc = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
|
||||||
|
ptc.praise_minus(1) if !ptc.blank?
|
||||||
|
if ptc.praise_num == 0
|
||||||
|
ptc.delete
|
||||||
|
end
|
||||||
|
obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
|
||||||
|
num = !obj.blank? ? get_activity_praise_num(obj) : 0
|
||||||
|
end
|
||||||
|
|
||||||
|
present :data, num
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,18 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Whomeworks< Grape::API
|
||||||
|
resources :whomeworks do
|
||||||
|
|
||||||
|
desc "get one homework"
|
||||||
|
get ':id' do
|
||||||
|
user = UserWechat.find_by_openid(params[:openid]).user
|
||||||
|
homework = HomeworkCommon.find params[:id]
|
||||||
|
present :data, homework, with: Mobile::Entities::Whomework,user: user
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,146 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
module Mobile
|
||||||
|
module Entities
|
||||||
|
class Activity <Grape::Entity
|
||||||
|
include ApplicationHelper
|
||||||
|
include ApiHelper
|
||||||
|
def self.act_expose(f)
|
||||||
|
expose f do |ac,opt|
|
||||||
|
if ac.is_a?(Hash) && ac.key?(f)
|
||||||
|
ac[f]
|
||||||
|
elsif ac.is_a?(::UserActivity)
|
||||||
|
if ac.respond_to?(f)
|
||||||
|
ac.send(f)
|
||||||
|
else
|
||||||
|
case f
|
||||||
|
when :user_act
|
||||||
|
if ac.act_type == "ProjectCreateInfo"
|
||||||
|
ac unless ac.nil?
|
||||||
|
else
|
||||||
|
ac.act unless ac.nil? || ac.act.nil?
|
||||||
|
end
|
||||||
|
when :reply_count
|
||||||
|
if ac.act_type == "HomeworkCommon"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : ac.act.journals_for_messages.count
|
||||||
|
elsif ac.act_type == "News"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : ac.act.comments.count
|
||||||
|
elsif ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : ac.act.children.count
|
||||||
|
elsif ac.act_type == "Issue"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : ac.act.journals.where("notes is not null and notes != ''").count
|
||||||
|
end
|
||||||
|
when :subject
|
||||||
|
if ac.act_type == "HomeworkCommon"
|
||||||
|
ac.act.name unless ac.nil? || ac.act.nil?
|
||||||
|
elsif ac.act_type == "News" || ac.act_type == "BlogComment"
|
||||||
|
ac.act.title unless ac.nil? || ac.act.nil?
|
||||||
|
elsif ac.act_type == "Message" || ac.act_type == "Issue"
|
||||||
|
ac.act.subject unless ac.nil? || ac.act.nil?
|
||||||
|
elsif ac.act_type == "JournalsForMessage"
|
||||||
|
ac.act.private == 0 ? "留言" : "私信" unless ac.nil? || ac.act.nil?
|
||||||
|
end
|
||||||
|
when :description
|
||||||
|
if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News"
|
||||||
|
ac.act.description unless ac.nil? || ac.act.nil?
|
||||||
|
elsif ac.act_type == "Message" || ac.act_type == "BlogComment"
|
||||||
|
ac.act.content unless ac.nil? || ac.act.nil?
|
||||||
|
elsif ac.act_type == "JournalsForMessage"
|
||||||
|
ac.act.notes unless ac.nil? || ac.act.nil?
|
||||||
|
end
|
||||||
|
when :latest_update
|
||||||
|
time_from_now ac.updated_at unless ac.nil?
|
||||||
|
when :praise_count
|
||||||
|
if ac.act_type == "HomeworkCommon" || ac.act_type == "News" || ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage" || ac.act_type == "Issue"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : get_activity_praise_num(ac.act)
|
||||||
|
end
|
||||||
|
#when :homework_common_detail_manual
|
||||||
|
# if ac.act_type == "HomeworkCommon"
|
||||||
|
# ac.act.homework_detail_manual unless ac.nil? || ac.act.nil? || ac.act.homework_detail_manual.nil?
|
||||||
|
# end
|
||||||
|
when :course_project_name
|
||||||
|
if ac.container_type == "Course"
|
||||||
|
name = (get_course(ac.container_id)).name
|
||||||
|
name
|
||||||
|
elsif ac.container_type == "Project"
|
||||||
|
name = (get_project(ac.container_id)).name
|
||||||
|
name
|
||||||
|
elsif ac.container_type == "Blog"
|
||||||
|
"发表博客"
|
||||||
|
end
|
||||||
|
when :activity_type_name
|
||||||
|
if ac.container_type == "Course"
|
||||||
|
case ac.act_type
|
||||||
|
when "HomeworkCommon"
|
||||||
|
"课程作业"
|
||||||
|
when "News"
|
||||||
|
"课程通知"
|
||||||
|
when "Message"
|
||||||
|
"课程问答区"
|
||||||
|
when "Poll"
|
||||||
|
"课程问卷"
|
||||||
|
when "Course"
|
||||||
|
"课程"
|
||||||
|
end
|
||||||
|
elsif ac.container_type == "Project"
|
||||||
|
case ac.act_type
|
||||||
|
when "Issue"
|
||||||
|
"项目缺陷"
|
||||||
|
when "Message"
|
||||||
|
"项目讨论区"
|
||||||
|
when "ProjectCreateInfo"
|
||||||
|
"项目"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :act_type #缺陷/作业/讨论区/留言等类型
|
||||||
|
expose :act_id
|
||||||
|
expose :container_type #课程/项目/博客/个人
|
||||||
|
expose :author, using: Mobile::Entities::User do |a, opt| #用户信息
|
||||||
|
if a.is_a? ::UserActivity
|
||||||
|
if a.act_type == "ProjectCreateInfo"
|
||||||
|
get_user(get_project(a.act_id).user_id)
|
||||||
|
elsif !a.act.nil?
|
||||||
|
if a.act_type == 'Issue' || a.act_type == 'News' || a.act_type == 'Message' || a.act_type == 'BlogComment'
|
||||||
|
a.act.author
|
||||||
|
elsif a.act_type == 'HomeworkCommon' || a.act_type == 'Poll' || a.act_type == 'JournalsForMessage'
|
||||||
|
a.act.user
|
||||||
|
elsif a.act_type == 'Course'
|
||||||
|
a.act.teacher
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :homework_common_detail , using: Mobile::Entities::Whomework do |a, opt| #作业相关信息
|
||||||
|
if a.act_type == "HomeworkCommon"
|
||||||
|
a.act
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :issue_detail, using: Mobile::Entities::Issue do |a, opt| #缺陷信息
|
||||||
|
if a.act_type == "Issue"
|
||||||
|
a.act
|
||||||
|
end
|
||||||
|
end
|
||||||
|
act_expose :reply_count #回复数
|
||||||
|
act_expose :praise_count #点赞数
|
||||||
|
#act_expose :user_act #某个动态
|
||||||
|
act_expose :subject #标题
|
||||||
|
act_expose :description #描述
|
||||||
|
act_expose :latest_update #最新更新时间
|
||||||
|
act_expose :course_project_name #课程/项目名字
|
||||||
|
act_expose :activity_type_name #课程问答区/项目缺陷等
|
||||||
|
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||||
|
if instance.act_type == "HomeworkCommon" || instance.act_type == "News" || instance.act_type == "Message" || instance.act_type == "BlogComment" || instance.act_type == "JournalsForMessage" || instance.act_type == "Issue"
|
||||||
|
has_praise = false
|
||||||
|
current_user = options[:user]
|
||||||
|
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id)
|
||||||
|
has_praise = obj.empty? ? false : true
|
||||||
|
has_praise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,65 @@
|
|||||||
|
module Mobile
|
||||||
|
module Entities
|
||||||
|
class BlogComment < Grape::Entity
|
||||||
|
include ApplicationHelper
|
||||||
|
include ApiHelper
|
||||||
|
def self.blog_comment_expose(f)
|
||||||
|
expose f do |u,opt|
|
||||||
|
if u.is_a?(Hash) && u.key?(f)
|
||||||
|
u[f]
|
||||||
|
elsif u.is_a?(::BlogComment)
|
||||||
|
if u.respond_to?(f)
|
||||||
|
if f == :created_at
|
||||||
|
format_time( u.send(f))
|
||||||
|
else
|
||||||
|
u.send(f)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
case f
|
||||||
|
when :praise_count
|
||||||
|
get_activity_praise_num(u)
|
||||||
|
when :lasted_comment
|
||||||
|
time_from_now(u.created_at)
|
||||||
|
when :act_type
|
||||||
|
'BlogComment'
|
||||||
|
when :act_id
|
||||||
|
u.id
|
||||||
|
when :comment_count
|
||||||
|
u.children.count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||||
|
if c.is_a?(::BlogComment)
|
||||||
|
c.author
|
||||||
|
end
|
||||||
|
end
|
||||||
|
blog_comment_expose :act_type
|
||||||
|
blog_comment_expose :act_id
|
||||||
|
blog_comment_expose :blog_id
|
||||||
|
blog_comment_expose :title
|
||||||
|
blog_comment_expose :content
|
||||||
|
blog_comment_expose :comment_count
|
||||||
|
blog_comment_expose :created_at
|
||||||
|
blog_comment_expose :lasted_comment
|
||||||
|
blog_comment_expose :id
|
||||||
|
blog_comment_expose :praise_count
|
||||||
|
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
|
||||||
|
if c.is_a? (::BlogComment)
|
||||||
|
c.children.reverse
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :has_praise, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||||
|
has_praise = false
|
||||||
|
current_user = options[:user]
|
||||||
|
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||||
|
has_praise = obj.empty? ? false : true
|
||||||
|
has_praise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,67 @@
|
|||||||
|
module Mobile
|
||||||
|
module Entities
|
||||||
|
class Issue <Grape::Entity
|
||||||
|
include ApiHelper
|
||||||
|
include Redmine::I18n
|
||||||
|
def self.issue_expose(f)
|
||||||
|
expose f do |issue, opt|
|
||||||
|
if issue.is_a?(Hash) && issue.key?(f)
|
||||||
|
issue[f]
|
||||||
|
elsif issue.is_a?(::Issue)
|
||||||
|
if issue.respond_to?(f)
|
||||||
|
if f == :created_on
|
||||||
|
format_time(issue.send(f))
|
||||||
|
else
|
||||||
|
issue.send(f)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
case f
|
||||||
|
when :issue_priority
|
||||||
|
get_issue_priority_api issue.priority_id
|
||||||
|
when :issue_assigned_to
|
||||||
|
(get_user(issue.assigned_to_id)).login
|
||||||
|
when :issue_status
|
||||||
|
IssueStatus.find(issue.status_id).name
|
||||||
|
when :journals_count
|
||||||
|
issue.journals.where("notes is not null and notes != ''").count
|
||||||
|
when :project_name
|
||||||
|
issue.project.name
|
||||||
|
when :praise_count
|
||||||
|
get_activity_praise_num(issue)
|
||||||
|
when :act_type
|
||||||
|
'Issue'
|
||||||
|
when :act_id
|
||||||
|
issue.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :subject
|
||||||
|
expose :description
|
||||||
|
expose :author, using: Mobile::Entities::User
|
||||||
|
expose :done_ratio
|
||||||
|
issue_expose :act_type
|
||||||
|
issue_expose :act_id
|
||||||
|
issue_expose :created_on
|
||||||
|
issue_expose :issue_priority
|
||||||
|
issue_expose :issue_assigned_to
|
||||||
|
issue_expose :issue_status
|
||||||
|
issue_expose :journals_count
|
||||||
|
issue_expose :project_name
|
||||||
|
issue_expose :praise_count
|
||||||
|
expose :issue_journals, using: Mobile::Entities::Journal do |f, opt|
|
||||||
|
if f.is_a?(::Issue)
|
||||||
|
f.journals.where("notes is not null and notes != ''").reverse
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||||
|
has_praise = false
|
||||||
|
current_user = options[:user]
|
||||||
|
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||||
|
has_praise = obj.empty? ? false : true
|
||||||
|
has_praise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,44 @@
|
|||||||
|
module Mobile
|
||||||
|
module Entities
|
||||||
|
class Journal <Grape::Entity
|
||||||
|
include Redmine::I18n
|
||||||
|
=begin
|
||||||
|
include Redmine::I18n
|
||||||
|
include ApplicationHelper
|
||||||
|
include ApiHelper
|
||||||
|
include IssuesHelper
|
||||||
|
include ActionView::Helpers::TagHelper
|
||||||
|
include ActionView::Helpers::UrlHelper
|
||||||
|
=end
|
||||||
|
def self.journal_expose(f)
|
||||||
|
expose f do |journal, opt|
|
||||||
|
if journal.is_a?(Hash) && journal.key?(f)
|
||||||
|
journal[f]
|
||||||
|
elsif journal.is_a?(::Journal)
|
||||||
|
if journal.respond_to?(f)
|
||||||
|
if f == :created_on
|
||||||
|
time_from_now(journal.send(f))
|
||||||
|
else
|
||||||
|
journal.send(f)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
case f
|
||||||
|
when :detail_journal
|
||||||
|
if journal.details.any?
|
||||||
|
details_to_strings(journal.details)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
expose :notes
|
||||||
|
journal_expose :created_on
|
||||||
|
expose :user,using: Mobile::Entities::User do |f, opt|
|
||||||
|
f.user
|
||||||
|
end
|
||||||
|
#journal_expose :detail_journal
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,85 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
module Mobile
|
||||||
|
module Entities
|
||||||
|
class Whomework <Grape::Entity
|
||||||
|
include ApiHelper
|
||||||
|
include ApplicationHelper
|
||||||
|
include Redmine::I18n
|
||||||
|
def self.whomework_expose(f)
|
||||||
|
expose f do |wh, opt|
|
||||||
|
if wh.is_a?(Hash) && wh.key?(f)
|
||||||
|
wh[f]
|
||||||
|
elsif wh.is_a?(::HomeworkCommon)
|
||||||
|
if wh.respond_to?(f)
|
||||||
|
if f == :created_at
|
||||||
|
format_time(wh.send(f))
|
||||||
|
else
|
||||||
|
wh.send(f)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
case f
|
||||||
|
when :absence_penalty
|
||||||
|
wh.nil? || wh.homework_detail_manual.nil? ? 0 : wh.homework_detail_manual.absence_penalty
|
||||||
|
when :evaluation_start
|
||||||
|
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_start, 0)
|
||||||
|
when :evaluation_end
|
||||||
|
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1)
|
||||||
|
when :praise_count
|
||||||
|
get_activity_praise_num(wh)
|
||||||
|
when :whomework_journal_count
|
||||||
|
wh.journals_for_messages.count
|
||||||
|
when :course_name
|
||||||
|
wh.course.name
|
||||||
|
when :act_type
|
||||||
|
'HomeworkCommon'
|
||||||
|
when :act_id
|
||||||
|
wh.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
expose :author, using: Mobile::Entities::User do |w, opt|
|
||||||
|
if w.is_a?(::HomeworkCommon)
|
||||||
|
w.user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :current_user, using: Mobile::Entities::User do |w, opt|
|
||||||
|
current_user
|
||||||
|
end
|
||||||
|
expose :name
|
||||||
|
expose :description
|
||||||
|
expose :publish_time
|
||||||
|
expose :end_time
|
||||||
|
expose :homework_type
|
||||||
|
expose :late_penalty
|
||||||
|
expose :course_id
|
||||||
|
expose :anonymous_comment
|
||||||
|
expose :quotes
|
||||||
|
expose :is_open
|
||||||
|
whomework_expose :act_type
|
||||||
|
whomework_expose :act_id
|
||||||
|
whomework_expose :course_name
|
||||||
|
whomework_expose :created_at
|
||||||
|
whomework_expose :absence_penalty
|
||||||
|
whomework_expose :evaluation_start
|
||||||
|
whomework_expose :evaluation_end
|
||||||
|
whomework_expose :praise_count
|
||||||
|
whomework_expose :whomework_journal_count
|
||||||
|
expose :journals_for_messages, using: Mobile::Entities::Jours do |f, opt|
|
||||||
|
#f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages)
|
||||||
|
if f.is_a?(::HomeworkCommon)
|
||||||
|
f.journals_for_messages.reverse
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||||
|
has_praise = false
|
||||||
|
current_user = options[:user]
|
||||||
|
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||||
|
has_praise = obj.empty? ? false : true
|
||||||
|
has_praise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the ShieldWechatMessages controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the sub_document_comments controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the sub_domains controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
@ -0,0 +1,36 @@
|
|||||||
|
class ShieldWechatMessagesController < ApplicationController
|
||||||
|
def create
|
||||||
|
if params[:user_id]
|
||||||
|
@user = User.find params[:user_id]
|
||||||
|
if params[:project_id]
|
||||||
|
ShieldWechatMessage.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
|
||||||
|
#@cp = 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(5)
|
||||||
|
elsif params[:course_id]
|
||||||
|
ShieldWechatMessage.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
|
||||||
|
#@cp = 0
|
||||||
|
#@courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_messages
|
||||||
|
if params[:user_id]
|
||||||
|
@user = User.find params[:user_id]
|
||||||
|
if params[:project_id]
|
||||||
|
ShieldWechatMessage.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act|
|
||||||
|
act.destroy
|
||||||
|
end
|
||||||
|
#@cp = 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(5)
|
||||||
|
# ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
|
||||||
|
elsif params[:course_id]
|
||||||
|
ShieldWechatMessage.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act|
|
||||||
|
act.destroy
|
||||||
|
end
|
||||||
|
#@cp = 0
|
||||||
|
#@courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,71 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
require 'base64'
|
||||||
|
require 'json'
|
||||||
|
require 'openssl'
|
||||||
|
|
||||||
|
## 单点登录 <=> 北斗
|
||||||
|
class SsosController < ApplicationController
|
||||||
|
|
||||||
|
skip_before_filter :check_if_login_required
|
||||||
|
layout false
|
||||||
|
|
||||||
|
def show
|
||||||
|
begin
|
||||||
|
# suRh2nFEJd0Ai_TFbqZ-1yQXnGfIB-YD_f4KTA3O4dQGSBMiXfOMt-0mzizgXekWTjHKfn62nJ60iHM3_eY_KS0Qn8SF8vANfa46GhzZRt4T0iC5ZOSs4cWeK43OU0RoekQLZZAo5OyOVibxabmiPGzEFCnVVtdmRk9d7X_B0Is=
|
||||||
|
@auth = params[:auth]
|
||||||
|
@options = parse(params[:auth])
|
||||||
|
|
||||||
|
if params[:login].present?
|
||||||
|
@options["name"] = params[:login]
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.debug @options
|
||||||
|
## 认证
|
||||||
|
sso = login(@options)
|
||||||
|
|
||||||
|
## 加入组织
|
||||||
|
@organization = Organization.find(82)
|
||||||
|
unless @organization.org_members.exists?(user_id: sso.user_id)
|
||||||
|
member = OrgMember.new(:user_id => sso.user_id)
|
||||||
|
@organization.org_members << member
|
||||||
|
end
|
||||||
|
|
||||||
|
## 选择性跳转
|
||||||
|
redirect_to @organization
|
||||||
|
rescue => e
|
||||||
|
logger.error e
|
||||||
|
if e.message == "exist user"
|
||||||
|
render 'ssos/show', :layout => false
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
## 改用户名
|
||||||
|
def create
|
||||||
|
show and return
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def base64_safe(content)
|
||||||
|
content = content.gsub('-', '+')
|
||||||
|
content.gsub('_', '/')
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse(auth)
|
||||||
|
crypted_str = Base64.decode64(base64_safe(auth))
|
||||||
|
pkey = OpenSSL::PKey::RSA.new(File.new(File.join(Rails.root,"config/private.key")))
|
||||||
|
content = pkey.private_decrypt(crypted_str,OpenSSL::PKey::RSA::PKCS1_PADDING)
|
||||||
|
# content = pkey.private_decrypt(crypted_str)
|
||||||
|
ActiveSupport::JSON.decode(content)
|
||||||
|
end
|
||||||
|
|
||||||
|
def login(opt)
|
||||||
|
sso = Sso.sync_user(opt)
|
||||||
|
start_user_session(sso.user)
|
||||||
|
sso
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,63 @@
|
|||||||
|
class SubDomainsController < ApplicationController
|
||||||
|
layout 'base_org'
|
||||||
|
before_filter :find_org_subfield_and_subdomain, :only => [:show, :index, :domain_update_priority, :destroy, :update, :hide_sub_domain, :show_sub_domain]
|
||||||
|
|
||||||
|
def new
|
||||||
|
@subdomain = SubDomain.new
|
||||||
|
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||||
|
@organization = @org_subfield.organization
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0
|
||||||
|
@res = true
|
||||||
|
@subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||||
|
@organization = @subfield.organization
|
||||||
|
@subdomain = SubDomain.create(:name => params[:name], :org_subfield_id => params[:org_subfield_id], :priority => @subfield.sub_domains.blank? ? 1 : @subfield.sub_domains.order("priority").last.priority + 1)
|
||||||
|
@subdomain.update_column(:field_type, params[:field_type])
|
||||||
|
else
|
||||||
|
@res = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@subdomain.update_column(:name, params[:name])
|
||||||
|
end
|
||||||
|
|
||||||
|
def domain_update_priority
|
||||||
|
@subdomain.update_attribute(:priority, params[:priority].to_i)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@subdomain.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
render_404
|
||||||
|
# @subfield_content = @organization.org_subfields.order("priority")
|
||||||
|
# render layout: @organization.switch_type ? 'base_sub_domain' : 'base_org'
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def hide_sub_domain
|
||||||
|
@subdomain.update_attribute(:hide, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_sub_domain
|
||||||
|
@subdomain.update_attribute(:hide, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_org_subfield_and_subdomain
|
||||||
|
@subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||||
|
@subdomain = SubDomain.find(params[:id])
|
||||||
|
@organization = @subfield.organization
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
# source_subdomain not found
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,237 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
class WechatsController < ActionController::Base
|
||||||
|
wechat_responder
|
||||||
|
|
||||||
|
include ApplicationHelper
|
||||||
|
|
||||||
|
# default text responder when no other match
|
||||||
|
on :text do |request, content|
|
||||||
|
request.reply.text "您的意见已收到" # Just echo
|
||||||
|
end
|
||||||
|
|
||||||
|
# When receive 'help', will trigger this responder
|
||||||
|
on :text, with: 'help' do |request|
|
||||||
|
request.reply.text 'help content'
|
||||||
|
end
|
||||||
|
|
||||||
|
# When receive '<n>news', will match and will got count as <n> as parameter
|
||||||
|
on :text, with: /^(\d+) news$/ do |request, count|
|
||||||
|
# Wechat article can only contain max 10 items, large than 10 will dropped.
|
||||||
|
news = (1..count.to_i).each_with_object([]) { |n, memo| memo << { title: 'News title', content: "No. #{n} news content" } }
|
||||||
|
request.reply.news(news) do |article, n, index| # article is return object
|
||||||
|
article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: 'http://www.baidu.com/img/bdlogo.gif', url: 'http://www.baidu.com/'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
on :event, with: 'subscribe' do |request|
|
||||||
|
default_msg(request)
|
||||||
|
end
|
||||||
|
|
||||||
|
# When unsubscribe user scan qrcode qrscene_xxxxxx to subscribe in public account
|
||||||
|
# notice user will subscribe public account at same time, so wechat won't trigger subscribe event any more
|
||||||
|
on :scan, with: 'qrscene_xxxxxx' do |request, ticket|
|
||||||
|
request.reply.text "Unsubscribe user #{request[:FromUserName]} Ticket #{ticket}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# When subscribe user scan scene_id in public account
|
||||||
|
on :scan, with: 'scene_id' do |request, ticket|
|
||||||
|
request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# When no any on :scan responder can match subscribe user scaned scene_id
|
||||||
|
on :event, with: 'scan' do |request|
|
||||||
|
if request[:EventKey].present?
|
||||||
|
request.reply.text "event scan got EventKey #{request[:EventKey]} Ticket #{request[:Ticket]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# When enterprise user press menu BINDING_QR_CODE and success to scan bar code
|
||||||
|
on :scan, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type|
|
||||||
|
request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Except QR code, wechat can also scan CODE_39 bar code in enterprise account
|
||||||
|
on :scan, with: 'BINDING_BARCODE' do |message, scan_result|
|
||||||
|
if scan_result.start_with? 'CODE_39,'
|
||||||
|
message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# When user click the menu button
|
||||||
|
on :click, with: 'BOOK_LUNCH' do |request, key|
|
||||||
|
request.reply.text "User: #{request[:FromUserName]} click #{key}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# When user view URL in the menu button
|
||||||
|
on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view|
|
||||||
|
request.reply.text "#{request[:FromUserName]} view #{view}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# When user sent the imsage
|
||||||
|
on :image do |request|
|
||||||
|
request.reply.image(request[:MediaId]) # Echo the sent image to user
|
||||||
|
end
|
||||||
|
|
||||||
|
# When user sent the voice
|
||||||
|
on :voice do |request|
|
||||||
|
request.reply.voice(request[:MediaId]) # Echo the sent voice to user
|
||||||
|
end
|
||||||
|
|
||||||
|
# When user sent the video
|
||||||
|
on :video do |request|
|
||||||
|
nickname = wechat.user(request[:FromUserName])['nickname'] # Call wechat api to get sender nickname
|
||||||
|
request.reply.video(request[:MediaId], title: 'Echo', description: "Got #{nickname} sent video") # Echo the sent video to user
|
||||||
|
end
|
||||||
|
|
||||||
|
# When user sent location
|
||||||
|
on :location do |request|
|
||||||
|
request.reply.text("Latitude: #{message[:Latitude]} Longitude: #{message[:Longitude]} Precision: #{message[:Precision]}")
|
||||||
|
end
|
||||||
|
|
||||||
|
on :event, with: 'unsubscribe' do |request|
|
||||||
|
request.reply.success # user can not receive this message
|
||||||
|
end
|
||||||
|
|
||||||
|
# When user enter the app / agent app
|
||||||
|
on :event, with: 'enter_agent' do |request|
|
||||||
|
request.reply.text "#{request[:FromUserName]} enter agent app now"
|
||||||
|
end
|
||||||
|
|
||||||
|
# When batch job create/update user (incremental) finished.
|
||||||
|
on :batch_job, with: 'sync_user' do |request, batch_job|
|
||||||
|
request.reply.text "sync_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# When batch job replace user (full sync) finished.
|
||||||
|
on :batch_job, with: 'replace_user' do |request, batch_job|
|
||||||
|
request.reply.text "replace_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# When batch job invent user finished.
|
||||||
|
on :batch_job, with: 'invite_user' do |request, batch_job|
|
||||||
|
request.reply.text "invite_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# When batch job replace department (full sync) finished.
|
||||||
|
on :batch_job, with: 'replace_party' do |request, batch_job|
|
||||||
|
request.reply.text "replace_party job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Any not match above will fail to below
|
||||||
|
on :fallback, respond: 'fallback message'
|
||||||
|
|
||||||
|
on :click, with: 'FEEDBACK' do |request, key|
|
||||||
|
request.reply.text "如有反馈问题,请直接切入至输入框,发微信给我们即可"
|
||||||
|
end
|
||||||
|
|
||||||
|
on :click, with: 'MY_NEWS' do |request, key|
|
||||||
|
default_msg(request)
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_msg(request)
|
||||||
|
uw = user_binded?(request[:FromUserName])
|
||||||
|
if uw && uw.user
|
||||||
|
request.reply.text "欢迎回来, #{uw.user.show_name}"
|
||||||
|
else
|
||||||
|
request.reply.text "欢迎关注Trustie创新实践社区"
|
||||||
|
sendBind(request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def sendBind(request)
|
||||||
|
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "您还未绑定确实的用户,请先绑定." } }
|
||||||
|
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=#{login_wechat_url}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
|
||||||
|
article.item title: "#{n[:title]}",
|
||||||
|
description: n[:content],
|
||||||
|
pic_url: 'https://www.trustie.net/images/trustie_logo2.png',
|
||||||
|
url: url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def get_open_id
|
||||||
|
begin
|
||||||
|
raise "非法操作, code不存在" unless params[:code]
|
||||||
|
openid = get_openid_from_code(params[:code])
|
||||||
|
raise "无法获取到openid" unless openid
|
||||||
|
render :json => {status:0, openid: openid}
|
||||||
|
rescue Exception=>e
|
||||||
|
render :json => {status: -1, msg: e.message}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def bind
|
||||||
|
begin
|
||||||
|
raise "非法操作, code不存在" unless params[:code]
|
||||||
|
openid = get_openid_from_code(params[:code])
|
||||||
|
raise "无法获取到openid" unless openid
|
||||||
|
raise "此微信号已绑定用户, 不能得复绑定" if user_binded?(openid)
|
||||||
|
|
||||||
|
user, last_login_on = User.try_to_login(params[:username], params[:password])
|
||||||
|
raise "用户名或密码错误,请重新登录" unless user
|
||||||
|
#补全用户信息
|
||||||
|
|
||||||
|
raise "此用户已经绑定了公众号" if user.user_wechat
|
||||||
|
|
||||||
|
UserWechat.create!(
|
||||||
|
openid: openid,
|
||||||
|
user: user
|
||||||
|
)
|
||||||
|
request.reply.text "欢迎加入Trustie创新实践社区"
|
||||||
|
render :json => {status:0, msg: "绑定成功"}
|
||||||
|
rescue Exception=>e
|
||||||
|
render :json => {status: -1, msg: e.message}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def login
|
||||||
|
@code = params[:code] #TODO 安全性
|
||||||
|
render 'wechats/login', layout: 'base_wechat'
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def get_openid_from_code(code)
|
||||||
|
url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{Wechat.config.appid}&secret=#{Wechat.config.secret}&code=#{code}&grant_type=authorization_code"
|
||||||
|
logger.debug url
|
||||||
|
body = URI.parse(url).read
|
||||||
|
logger.debug body
|
||||||
|
JSON.parse(body)["openid"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_binded?(openid)
|
||||||
|
uw = UserWechat.where(openid: openid).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_activity(user)
|
||||||
|
@user = user
|
||||||
|
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
|
||||||
|
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
|
||||||
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||||
|
user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
|
||||||
|
user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
|
||||||
|
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||||
|
project_types = "('Message','Issue','ProjectCreateInfo')"
|
||||||
|
principal_types = "JournalsForMessage"
|
||||||
|
|
||||||
|
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
|
||||||
|
@user_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').limit(10).offset(@page * 10)
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_activity(user_activity)
|
||||||
|
act= user_activity.act
|
||||||
|
case user_activity.container_type.to_s
|
||||||
|
when 'Course'
|
||||||
|
when 'Project'
|
||||||
|
case user_activity.act_type.to_s
|
||||||
|
when 'Issue'
|
||||||
|
[act.project.name.to_s+" | 项目问题", act.subject.to_s, url_to_avatar(act.author),"http://wechat.trustie.net/app.html#/issue/#{act.id}"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,2 @@
|
|||||||
|
module ShieldWechatMessagesHelper
|
||||||
|
end
|
@ -0,0 +1,2 @@
|
|||||||
|
module SubDocumentCommentsHelper
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
module SubDomainsHelper
|
||||||
|
include OrganizationsHelper
|
||||||
|
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
class CodeTests < ActiveRecord::Base
|
||||||
|
attr_accessible :homework_id, :language, :status, :time_used, :wait_time, :student_work_id
|
||||||
|
end
|
@ -0,0 +1,4 @@
|
|||||||
|
class RepStatics < ActiveRecord::Base
|
||||||
|
belongs_to :project
|
||||||
|
attr_accessible :add, :commits_num, :del, :email, :project_id, :uname, :changeset
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
class ShieldWechatMessage < ActiveRecord::Base
|
||||||
|
attr_accessible :container_id, :container_type, :shield_id, :shield_type
|
||||||
|
end
|
@ -0,0 +1,56 @@
|
|||||||
|
class Sso < ActiveRecord::Base
|
||||||
|
belongs_to :user
|
||||||
|
attr_accessible :email, :name, :openid, :password, :school, :sex, :user, :user_id
|
||||||
|
|
||||||
|
validates :user_id, :user, :email, :openid, :presence => true
|
||||||
|
|
||||||
|
def self.sync_user(opt)
|
||||||
|
sso = Sso.where(openid: opt["openid"]).first
|
||||||
|
return sso if sso
|
||||||
|
|
||||||
|
sso = Sso.new
|
||||||
|
sso.name = opt["name"]
|
||||||
|
sso.openid = opt["openid"]
|
||||||
|
sso.email = opt["email"]
|
||||||
|
sso.password = opt["password"]
|
||||||
|
sso.school = opt["school"]
|
||||||
|
sso.sex = opt["sex"]
|
||||||
|
|
||||||
|
|
||||||
|
# 查邮箱
|
||||||
|
user = User.where(mail: opt["email"]).first
|
||||||
|
|
||||||
|
unless user
|
||||||
|
# 查用户名
|
||||||
|
|
||||||
|
user = User.where(login: opt["name"]).first
|
||||||
|
if user
|
||||||
|
# 跳到修改用户名
|
||||||
|
raise "exist user"
|
||||||
|
end
|
||||||
|
|
||||||
|
password = opt["password"]
|
||||||
|
if password.size < 8
|
||||||
|
password = random_pwd
|
||||||
|
end
|
||||||
|
us = UsersService.new
|
||||||
|
user = us.register(login: opt["name"], mail: opt["email"],
|
||||||
|
password: password,
|
||||||
|
:should_confirmation_password => false)
|
||||||
|
if user.new_record?
|
||||||
|
raise user.errors.full_messages.first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sso.user = user
|
||||||
|
sso.save!
|
||||||
|
return sso
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
def self.random_pwd
|
||||||
|
('a'..'z').to_a.shuffle[0..7].join
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,33 @@
|
|||||||
|
class SubDocumentComment < ActiveRecord::Base
|
||||||
|
attr_accessible :content, :creator_id, :locked, :org_subfield_id, :parent_id, :reply_id, :sticky, :sub_domain_id, :title
|
||||||
|
|
||||||
|
include Redmine::SafeAttributes
|
||||||
|
include ApplicationHelper
|
||||||
|
belongs_to :sub_domain
|
||||||
|
belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
|
||||||
|
acts_as_tree :order => "#{SubDocumentComment.table_name}.sticky asc, #{SubDocumentComment.table_name}.created_at desc"
|
||||||
|
acts_as_attachable
|
||||||
|
has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy
|
||||||
|
after_create :document_save_as_sub_activity
|
||||||
|
after_update :update_activity
|
||||||
|
validates_presence_of :content
|
||||||
|
|
||||||
|
#动态的更新
|
||||||
|
private
|
||||||
|
def update_activity
|
||||||
|
org_activity = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", id).first
|
||||||
|
if org_activity
|
||||||
|
org_activity.updated_at = Time.now
|
||||||
|
org_activity.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def document_save_as_sub_activity
|
||||||
|
if(self.parent().nil?)
|
||||||
|
self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.sub_domain.id, :container_type => 'SubDomain')
|
||||||
|
else
|
||||||
|
act = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", self.root.id).first
|
||||||
|
act.update_attributes(:updated_at => self.updated_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
class SubDomain < ActiveRecord::Base
|
||||||
|
attr_accessible :field_type, :hide, :name, :org_subfield_id, :priority, :status
|
||||||
|
belongs_to :org_subfield, :foreign_key => :org_subfield_id
|
||||||
|
has_many :sub_document_comments, :dependent => :destroy
|
||||||
|
end
|
@ -0,0 +1,6 @@
|
|||||||
|
class UserWechat < ActiveRecord::Base
|
||||||
|
attr_accessible :subscribe, :openid, :nickname, :sex, :language, :city, :province, :country,
|
||||||
|
:headimgurl, :subscribe_time, :unionid, :remark, :groupid, :user, :user_id
|
||||||
|
|
||||||
|
belongs_to :user
|
||||||
|
end
|
@ -0,0 +1,117 @@
|
|||||||
|
#encoding: utf-8
|
||||||
|
class WechatService
|
||||||
|
|
||||||
|
def template_data(openid, template_id, type, id, first, key1, key2, key3, remark="")
|
||||||
|
data = {
|
||||||
|
touser:openid,
|
||||||
|
template_id:template_id,
|
||||||
|
url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect",
|
||||||
|
topcolor:"#FF0000",
|
||||||
|
data:{
|
||||||
|
first: {
|
||||||
|
value:first,
|
||||||
|
color:"#707070"
|
||||||
|
},
|
||||||
|
keyword1:{
|
||||||
|
value:key1,
|
||||||
|
color:"#707070"
|
||||||
|
},
|
||||||
|
keyword2:{
|
||||||
|
value:key2,
|
||||||
|
color:"#707070"
|
||||||
|
},
|
||||||
|
keyword3:{
|
||||||
|
value:key3,
|
||||||
|
color:"#707070"
|
||||||
|
},
|
||||||
|
remark:{
|
||||||
|
value:remark,
|
||||||
|
color:"#707070"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data
|
||||||
|
end
|
||||||
|
|
||||||
|
def homework_template(user_id, type, id, first, key1, key2, key3, remark="")
|
||||||
|
uw = UserWechat.where(user_id: user_id).first
|
||||||
|
unless uw.nil?
|
||||||
|
data = template_data uw.openid,"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI", 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 "[homework] ===> #{e}"
|
||||||
|
end
|
||||||
|
Rails.logger.info "send over. #{req}"
|
||||||
|
end
|
||||||
|
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
|
||||||
|
end
|
||||||
|
|
||||||
|
def topic_publish_template(user_id, type, id, first, key1, key2, key3, remark="")
|
||||||
|
uw = UserWechat.where(user_id: user_id).first
|
||||||
|
unless uw.nil?
|
||||||
|
data = template_data uw.openid,"oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ", type, id,first, key1, key2, key3, remark
|
||||||
|
Rails.logger.info "start send template message: #{data}"
|
||||||
|
begin
|
||||||
|
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||||
|
rescue Exception => e
|
||||||
|
Rails.logger.error "[topic_publish] ===> #{e}"
|
||||||
|
end
|
||||||
|
Rails.logger.info "send over. #{req}"
|
||||||
|
end
|
||||||
|
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
|
||||||
|
end
|
||||||
|
|
||||||
|
def comment_template(user_id,type, id, first, key1, key2, key3, remark="")
|
||||||
|
uw = UserWechat.where(user_id: user_id).first
|
||||||
|
unless uw.nil?
|
||||||
|
data = template_data uw.openid,"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",type, id,first, key1, key2, key3, remark
|
||||||
|
Rails.logger.info "start send template message: #{data}"
|
||||||
|
begin
|
||||||
|
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||||
|
rescue Exception => e
|
||||||
|
Rails.logger.error "[comment] ===> #{e}"
|
||||||
|
end
|
||||||
|
Rails.logger.info "send over. #{req}"
|
||||||
|
end
|
||||||
|
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_update_template(user_id, type, id, first, key1, key2, remark="")
|
||||||
|
uw = UserWechat.where(user_id: user_id).first
|
||||||
|
unless uw.nil?
|
||||||
|
data = {
|
||||||
|
touser:uw.openid,
|
||||||
|
template_id:"YTyNPZnQD8uZFBFq-Q6cCOWaq5LA9vL6RFlF2JuD5Cg",
|
||||||
|
url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect",
|
||||||
|
topcolor:"#FF0000",
|
||||||
|
data:{
|
||||||
|
first: {
|
||||||
|
value:first,
|
||||||
|
color:"#707070"
|
||||||
|
},
|
||||||
|
keyword1:{
|
||||||
|
value:key1,
|
||||||
|
color:"#707070"
|
||||||
|
},
|
||||||
|
keyword2:{
|
||||||
|
value:key2,
|
||||||
|
color:"#707070"
|
||||||
|
},
|
||||||
|
remark:{
|
||||||
|
value:remark,
|
||||||
|
color:"#707070"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rails.logger.info "start send template message: #{data}"
|
||||||
|
begin
|
||||||
|
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||||
|
rescue Exception => e
|
||||||
|
Rails.logger.error "[message_update] ===> #{e}"
|
||||||
|
end
|
||||||
|
Rails.logger.info "send over. #{req}"
|
||||||
|
end
|
||||||
|
Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect"
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,99 @@
|
|||||||
|
<h3>
|
||||||
|
<%=l(:label_code_work_tests)%>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="autoscroll">
|
||||||
|
<table class="list" style="width: 100%;table-layout: fixed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="width: 50px;">
|
||||||
|
<span style="float:left; margin-left:20px;">作业id</span>
|
||||||
|
</th>
|
||||||
|
<th style="width: 50px;">
|
||||||
|
<span style="float:left; margin-left:20px;">作品id</span>
|
||||||
|
</th>
|
||||||
|
<th style="width: 60px;">
|
||||||
|
用户等待时间
|
||||||
|
</th>
|
||||||
|
<th style="width: 50px;">
|
||||||
|
<span style="float:left; margin-left:20px;">语言</span>
|
||||||
|
</th>
|
||||||
|
<th style="width: 100px;">
|
||||||
|
测试完成时间
|
||||||
|
</th>
|
||||||
|
<th style="width: 60px;">
|
||||||
|
<span style="float:left; margin-left:20px;">答题状态</span>
|
||||||
|
</th>
|
||||||
|
<th style="width: 50px;">
|
||||||
|
<span style="float:left; margin-left:20px;">耗时</span>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @code_work_tests.each do |test| %>
|
||||||
|
<% if test['homework_id'] != nil %>
|
||||||
|
<tr class="<%= cycle("odd", "even") %>">
|
||||||
|
<td style="text-align: center; " title='<%=test['homework_id']%>'>
|
||||||
|
<% if test['link_hwork'] %>
|
||||||
|
<%=link_to(test['homework_id'], student_work_index_path(:homework => test['homework_id']))%>
|
||||||
|
<% else %>
|
||||||
|
<%= test['homework_id'] %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td style="text-align: center; " title='<%=test['student_work_id']%>'>
|
||||||
|
<% if test['link_swork'] && test['link_hwork'] %>
|
||||||
|
<% if !test['is_test'] %>
|
||||||
|
<%=link_to(test['student_work_id'], student_work_index_path(:homework => test['homework_id'],:student_work_id=>test['student_work_id']))%>
|
||||||
|
<% else %>
|
||||||
|
<%=link_to(test['student_work_id'], new_user_commit_homework_users_path(homework_id: test['homework_id'], is_test: true))%>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= test['student_work_id'] %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td style="text-align: center;">
|
||||||
|
<% if test.wait_time != 0 %>
|
||||||
|
<%=test.wait_time.to_s+"毫秒" %>
|
||||||
|
<% else %>
|
||||||
|
<%="未记录"%>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td align="center">
|
||||||
|
<%=%W(C C++ Python Java).at(test['language'].to_i - 1)%>
|
||||||
|
</td>
|
||||||
|
<td align="center">
|
||||||
|
<%=Time.parse(test.created_at.to_s).strftime("%Y-%m-%d %H:%M:%S")%>
|
||||||
|
</td>
|
||||||
|
<td align="center">
|
||||||
|
<% if test.status == 0 %>
|
||||||
|
<%= "答题正确" %>
|
||||||
|
<% elsif test.status == -2 %>
|
||||||
|
<%= "编译错误" %>
|
||||||
|
<% elsif test.status == 2 %>
|
||||||
|
<%= "代码超时" %>
|
||||||
|
<% elsif test.status == -3 %>
|
||||||
|
<%= "请求超时" %>
|
||||||
|
<% else %>
|
||||||
|
<%= "答题错误" %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td class="center">
|
||||||
|
<% if test.time_used > 0 %>
|
||||||
|
<%=test.time_used.to_s+"毫秒"%>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pagination">
|
||||||
|
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% html_title(l(:label_code_work_tests)) -%>
|
@ -0,0 +1 @@
|
|||||||
|
$("#blog-list").replaceWith('<%= escape_javascript( render :partial => 'blogs/article', :locals => {:topics => @topics} ) %>');
|
@ -1,5 +1,5 @@
|
|||||||
<% if @course %>
|
<% if @course %>
|
||||||
$("#show_more_course_topic").replaceWith("<%= escape_javascript( render :partial => 'boards/course_show_detail',:locals => {:topics => @topics, :page => @page} )%>");
|
$("#course-boardlist").replaceWith('<%= escape_javascript( render :partial => 'users/course_boardlist', :locals => {:topics => @topics, :is_course => 1, :is_board=>1}) %>');
|
||||||
<% else %>
|
<% else %>
|
||||||
$("#show_more_project_topic").replaceWith("<%= escape_javascript( render :partial => 'boards/project_show_detail',:locals => {:topics => @topics, :page => @page} )%>");
|
$("#project-boardlist").replaceWith('<%= escape_javascript( render :partial => 'users/project_boardlist', :locals => {:topics => @topics, :is_course => 1, :is_board=>1}) %>');
|
||||||
<% end %>
|
<% end %>
|
@ -0,0 +1,100 @@
|
|||||||
|
<div class="blue-border-box">
|
||||||
|
<div class="box-con">
|
||||||
|
<h4 id = "compare-tips-1"></h4>
|
||||||
|
<div class="box-con-a">
|
||||||
|
<a href="javascript:void(0);" class="Blue-btn fl " onclick = "compare_code_btn(<%=homework.id%>,<%=courseid%>)">重新查重</a>
|
||||||
|
<a href="javascript:void(0);" class="Blue-btn fl " onclick = "see_last_compare_code(<%=courseid%>,<%=homework.id%>)">查看结果</a>
|
||||||
|
</div>
|
||||||
|
<div class="cl"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
//请求重新查重
|
||||||
|
function compare_code_btn(homeworkid,courseid)
|
||||||
|
{
|
||||||
|
hideModal($(".blue-border-box"));
|
||||||
|
test_repeat(homeworkid,courseid);
|
||||||
|
|
||||||
|
}
|
||||||
|
//查看结果
|
||||||
|
function see_last_compare_code(courseid,homeworkid)
|
||||||
|
{
|
||||||
|
hideModal($(".blue-border-box"));
|
||||||
|
var rootpath = getRootPath();
|
||||||
|
var code_repeatpath = rootpath+"/courses/"+courseid+"/code_repeat?homework="+homeworkid;
|
||||||
|
//新打开页面
|
||||||
|
window.open(code_repeatpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var test_repeat = function(homeworkid,courseid){
|
||||||
|
$.post(
|
||||||
|
'/student_work/code_repeattest',
|
||||||
|
{homework: homeworkid},
|
||||||
|
function(data,status){
|
||||||
|
console.log("result = ");
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (data.status == 0) {
|
||||||
|
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"查重完成,是否立即查看结果?",:status=>1, :homework=> homework,:courseid=> courseid})%>');
|
||||||
|
showModal('ajax-modal', '580px');
|
||||||
|
$('#ajax-modal').siblings().remove();
|
||||||
|
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 565px; margin-top:-10px;' class='resourceClose'></a>");
|
||||||
|
//$('#ajax-modal').parent().css("top","40%").css("left","50%");
|
||||||
|
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("padding-top","10px").css("position","fixed");
|
||||||
|
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||||
|
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||||
|
|
||||||
|
function closeModal(){
|
||||||
|
hideModal($(".blue-border-box"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (data.status == -1){
|
||||||
|
// confirm("对不起只支持java/c/c++的代码查重!");
|
||||||
|
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起目前只支持java/c/c++的代码查重!",:status=>0, :homework=> homework,:courseid=> courseid})%>');
|
||||||
|
showModal('ajax-modal', '580px');
|
||||||
|
$('#ajax-modal').siblings().remove();
|
||||||
|
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 565px; margin-top:-10px;' class='resourceClose'></a>");
|
||||||
|
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("padding-top","10px").css("position","fixed");
|
||||||
|
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||||
|
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||||
|
|
||||||
|
function closeModal(){
|
||||||
|
hideModal($(".blue-border-box"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (data.status == -2){
|
||||||
|
// confirm("对不起该作业的作品过少不能查重!");
|
||||||
|
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起该作业的作品过少不能查重!",:status=>0, :homework=> homework,:courseid=> courseid})%>');
|
||||||
|
showModal('ajax-modal', '580px');
|
||||||
|
$('#ajax-modal').siblings().remove();
|
||||||
|
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 565px; margin-top:-10px;' class='resourceClose'></a>");
|
||||||
|
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("padding-top","10px").css("position","fixed");
|
||||||
|
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||||
|
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||||
|
|
||||||
|
function closeModal(){
|
||||||
|
hideModal($(".blue-border-box"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
).fail(function(xhr, status){
|
||||||
|
// confirm("对不起,服务器繁忙请稍后再试!");
|
||||||
|
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/compare_code_tips_2',:locals => {:des=>"对不起,服务器繁忙请稍后再试!",:status=>0, :homework=> homework,:courseid=> courseid})%>');
|
||||||
|
showModal('ajax-modal', '580px');
|
||||||
|
$('#ajax-modal').siblings().remove();
|
||||||
|
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal();' style='margin-left: 565px; margin-top:-10px;' class='resourceClose'></a>");
|
||||||
|
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("padding-top","10px").css("position","fixed");
|
||||||
|
$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||||
|
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||||
|
|
||||||
|
function closeModal(){
|
||||||
|
hideModal($(".blue-border-box"));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,22 @@
|
|||||||
|
<div class="blue-border-box">
|
||||||
|
<div class="box-con">
|
||||||
|
<h4><%=des%></h4>
|
||||||
|
<div class="box-con-a">
|
||||||
|
<a href="javascript:void(0);" class="Blue-btn " style="width:67px; margin:25px auto 0px auto;" onclick = "yes_btn(<%=status%>,<%=courseid%>,<%=homework.id%>)">确定</a>
|
||||||
|
</div>
|
||||||
|
<div class="cl"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function yes_btn(status,courseid,homeworkid)
|
||||||
|
{
|
||||||
|
hideModal($(".blue-border-box"));
|
||||||
|
if(status == 1) {
|
||||||
|
var rootpath = getRootPath();
|
||||||
|
var code_repeatpath = rootpath+"/courses/"+courseid+"/code_repeat?homework="+homeworkid;
|
||||||
|
window.open(code_repeatpath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
<% content_for :header_tags do %>
|
||||||
|
<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %>
|
||||||
|
<%= stylesheet_link_tag "/assets/codemirror/codemirror" %>
|
||||||
|
<%= stylesheet_link_tag "/assets/codemirror/merge" %>
|
||||||
|
<%= javascript_include_tag "https://cdnjs.cloudflare.com/ajax/libs/diff_match_patch/20121119/diff_match_patch.js"%>
|
||||||
|
<%= javascript_include_tag "/assets/codemirror/merge" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h3 style="float:left; width:47%; text-align:center;"><%=src_name%></h3>
|
||||||
|
<% if @simi_value.to_i >= 90 %>
|
||||||
|
<h6 style="color:red;float:left; width:6%; text-align:center;">相似度<%=@simi_value.to_i%>%</h3>
|
||||||
|
<% else %>
|
||||||
|
<h6 style="float:left; width:6%; text-align:center;">相似度<%=@simi_value.to_i%>%</h3>
|
||||||
|
<% end %>
|
||||||
|
<h3 style="float:left; width:47%; text-align:center;"><%=dst_name%></h3><div class="cl"></div>
|
||||||
|
<pre id = "program-src_1" style = "display: none" ><%= src_code if src_code%></pre>
|
||||||
|
<pre id = "program-src_2" style = "display: none" ><%= dst_code if dst_code%></pre>
|
||||||
|
<div class = "program-compare-code" id=program-compare-code></div>
|
||||||
|
</article>
|
@ -1 +1,2 @@
|
|||||||
$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>");
|
$("#st_groups").html("<%= escape_javascript( render :partial => 'new_groups_name', locals: {:course_groups => @course_groups})%>");
|
||||||
|
$("#member_content").html("<%= escape_javascript( render :partial => 'new_member_list', :locals => {:members => @members})%>");
|
@ -0,0 +1,81 @@
|
|||||||
|
<div class="conbox">
|
||||||
|
<h2 class="conbox-h2">查重结果</h2>
|
||||||
|
<div class="chabox">
|
||||||
|
<ul class="chabox-header">
|
||||||
|
<li class="chabox-w-500" style = "width:437px" >被查作品</li>
|
||||||
|
<li class="chabox-w-500" style = "width:561px" >疑被抄袭作品</li>
|
||||||
|
<div class="cl"></div>
|
||||||
|
</ul>
|
||||||
|
<ul class="chabox-top">
|
||||||
|
<li class="chabox-w-40 " >序号</li>
|
||||||
|
<li class="chabox-w-401" >作品名称</li>
|
||||||
|
<li>姓名</li>
|
||||||
|
<li>学号 </li>
|
||||||
|
<li class="chabox-r-line">时间 </li>
|
||||||
|
<li class="chabox-w-401">作品名称</li>
|
||||||
|
<li>姓名</li>
|
||||||
|
<li>学号 </li>
|
||||||
|
<li class="chabox-r-line">时间 </li>
|
||||||
|
<li >相似度 </li>
|
||||||
|
<li >对比 </li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<%if @homework.homework_type == 2 %>
|
||||||
|
<% @student_works.each_with_index do |student_work,index|%>
|
||||||
|
<ul class="chabox-con" id = "chabox-con-<%=student_work.id%>" >
|
||||||
|
<li class="chabox-w-40 chabox-txt-left" ><%=index+1%></li>
|
||||||
|
<% student_work_name = student_work.name.nil? || student_work.name.empty? ? student_work.user.show_name + '的作品' : student_work.name%>
|
||||||
|
<li class="chabox-w-401 chabox-txt-left" style =" text-align:left; text-indent:1em; " ><%=student_work_name%></li>
|
||||||
|
<li><%=student_work.user.show_name%></li>
|
||||||
|
<li><%= student_work.user.user_extensions.nil? ? "--" : student_work.user.user_extensions.student_id%> </li>
|
||||||
|
<li class="chabox-r-line"><%= Time.parse(format_time(student_work.created_at)).strftime("%m-%d %H:%M")%></li>
|
||||||
|
<% if student_work.simi_id.to_i > 0 && @works_hash[student_work.simi_id.to_i] %>
|
||||||
|
<% simi_student_work = @works_hash[student_work.simi_id.to_i] %>
|
||||||
|
<% simi_student_work_name = simi_student_work.name.nil? || simi_student_work.name.empty? ? simi_student_work.user.show_name + '的作品' : simi_student_work.name%>
|
||||||
|
<li class="chabox-w-401 chabox-txt-left" style =" text-align:left; text-indent:1em; " ><%=simi_student_work_name%></li>
|
||||||
|
<li><%=simi_student_work.user.show_name%></li>
|
||||||
|
<li><%= simi_student_work.user.user_extensions.nil? ? "--" : simi_student_work.user.user_extensions.student_id%></li>
|
||||||
|
<li class="chabox-r-line"><%= Time.parse(format_time(simi_student_work.created_at)).strftime("%m-%d %H:%M")%></li>
|
||||||
|
<% if student_work.simi_value.to_i >= 90 %>
|
||||||
|
<li style = "color:red" ><%=student_work.simi_value.to_i%>%</li>
|
||||||
|
<% else %>
|
||||||
|
<li ><%=student_work.simi_value.to_i%>%</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<!--@works_hash[student_work.id].description -->
|
||||||
|
<!--<li ><a href="javascript:void(0);" target="_blank" class="cha-btn" onclick = "show_code_compare()">查看</a>-->
|
||||||
|
<li >
|
||||||
|
<%= link_to("查看", show_comparecode_course_path(:homework_id => @homework.id,:src_id => student_work.id,:dst_id => student_work.simi_id.to_i),:class => "cha-btn",:remote => true ) %>
|
||||||
|
</li>
|
||||||
|
<%else%>
|
||||||
|
<li class="chabox-w-401">--</li>
|
||||||
|
<li>--</li>
|
||||||
|
<li>--</li>
|
||||||
|
<li class="chabox-r-line">--</li>
|
||||||
|
<li >--</li>
|
||||||
|
<li > </li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<%end%>
|
||||||
|
<%end%>
|
||||||
|
</div>
|
||||||
|
<div class="cl"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function show_code_compare() {
|
||||||
|
|
||||||
|
// $("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/show_compare_code' ,:locals => {:src_code=> 1,:src_name=> 2,:dst_name=> 3, :dst_code=> 4,:language=> 5,})%>');
|
||||||
|
// showModal('ajax-modal', '950px');
|
||||||
|
// $('#ajax-modal').siblings().remove();
|
||||||
|
// $('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 935px;' class='resourceClose'></a>");
|
||||||
|
// $('#ajax-modal').parent().css("top", "20%").css("left", "26.5%").css("position", "absolute");
|
||||||
|
// $('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||||
|
// $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px");
|
||||||
|
//
|
||||||
|
// function closeModal() {
|
||||||
|
// hideModal($(".contrast-box"));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
@ -0,0 +1,101 @@
|
|||||||
|
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/show_compare_code' ,:locals => {:src_code=> @src_code,:src_name=> @src_username,:dst_name=> @dst_username, :dst_code=> @dst_code, :simivalue=> @simi_value })%>');
|
||||||
|
showModal('ajax-modal', '1250px');
|
||||||
|
$('#ajax-modal').siblings().remove();
|
||||||
|
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 1235px; margin-top:-18px;' class='resourceClose'></a>");
|
||||||
|
$('#ajax-modal').parent().css("top","30%").css("left","20%").css("padding-top","20px").css("position","fixed");
|
||||||
|
//$('#ajax-modal').parent().addClass("resourceUploadPopup");
|
||||||
|
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
|
||||||
|
|
||||||
|
function closeModal(){
|
||||||
|
hideModal($(".program-compare-code"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var program_name = "text/x-csrc";
|
||||||
|
var language = <%= @homework.language.to_i %>;
|
||||||
|
if (language == 1) {
|
||||||
|
program_name = 'text/x-csrc';
|
||||||
|
} else if(language==2){
|
||||||
|
program_name = 'text/x-c++src';
|
||||||
|
}else if(language==3){
|
||||||
|
program_name = 'text/x-cython';
|
||||||
|
} else if(language==4){
|
||||||
|
program_name = 'text/x-java';
|
||||||
|
}
|
||||||
|
//
|
||||||
|
//var editor_1 = CodeMirror(document.getElementById("program-code_1"), {
|
||||||
|
// mode: {name: program_name,
|
||||||
|
// version: 2,
|
||||||
|
// singleLineStringErrors: false},
|
||||||
|
// lineNumbers: true,
|
||||||
|
// indentUnit: 2,
|
||||||
|
// matchBrackets: true,
|
||||||
|
// readOnly: true,
|
||||||
|
// value: $("#program-src_1").text()
|
||||||
|
// }
|
||||||
|
//);
|
||||||
|
//
|
||||||
|
//var editor_2 = CodeMirror(document.getElementById("program-code_2"), {
|
||||||
|
// mode: {name: program_name,
|
||||||
|
// version: 2,
|
||||||
|
// singleLineStringErrors: false},
|
||||||
|
// lineNumbers: true,
|
||||||
|
// indentUnit: 2,
|
||||||
|
// matchBrackets: true,
|
||||||
|
// readOnly: true,
|
||||||
|
// value: $("#program-src_2").text()
|
||||||
|
// }
|
||||||
|
//);
|
||||||
|
|
||||||
|
var value, orig1, orig2, dv, panes = 2, highlight = true, connect = null, collapse = false;
|
||||||
|
function initUI() {
|
||||||
|
if (value == null) return;
|
||||||
|
var target = document.getElementById("program-compare-code");
|
||||||
|
target.innerHTML = "";
|
||||||
|
dv = CodeMirror.MergeView(target, {
|
||||||
|
value: value,
|
||||||
|
origLeft: panes == 3 ? orig1 : null,
|
||||||
|
orig: orig2,
|
||||||
|
lineNumbers: true,
|
||||||
|
mode: program_name,
|
||||||
|
highlightDifferences: highlight,
|
||||||
|
connect: connect,
|
||||||
|
collapseIdentical: collapse
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleDifferences() {
|
||||||
|
dv.setShowDifferences(highlight = !highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
value = $("#program-src_1").text();
|
||||||
|
orig1 = $("#program-src_1").text();
|
||||||
|
orig2 = $("#program-src_2").text();
|
||||||
|
initUI();
|
||||||
|
|
||||||
|
|
||||||
|
function mergeViewHeight(mergeView) {
|
||||||
|
function editorHeight(editor) {
|
||||||
|
if (!editor) return 0;
|
||||||
|
return editor.getScrollInfo().height;
|
||||||
|
}
|
||||||
|
return Math.max(editorHeight(mergeView.leftOriginal()),
|
||||||
|
editorHeight(mergeView.editor()),
|
||||||
|
editorHeight(mergeView.rightOriginal()));
|
||||||
|
}
|
||||||
|
|
||||||
|
function resize(mergeView) {
|
||||||
|
var height = mergeViewHeight(mergeView);
|
||||||
|
for(;;) {
|
||||||
|
if (mergeView.leftOriginal())
|
||||||
|
mergeView.leftOriginal().setSize(null, height);
|
||||||
|
mergeView.editor().setSize(null, height);
|
||||||
|
if (mergeView.rightOriginal())
|
||||||
|
mergeView.rightOriginal().setSize(null, height);
|
||||||
|
|
||||||
|
var newHeight = mergeViewHeight(mergeView);
|
||||||
|
if (newHeight >= height) break;
|
||||||
|
else height = newHeight;
|
||||||
|
}
|
||||||
|
mergeView.wrap.style.height = height + "px";
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue