2015-12-09 09:59:13 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
class AtController < ApplicationController
|
2015-12-14 17:13:57 +08:00
|
|
|
respond_to :json
|
2015-12-09 09:59:13 +08:00
|
|
|
|
|
|
|
def show
|
2015-12-14 17:13:57 +08:00
|
|
|
@logger = Logger.new(Rails.root.join('log', 'at.log').to_s)
|
|
|
|
users = find_at_users(params[:type], params[:id])
|
2015-12-15 09:09:41 +08:00
|
|
|
@users = users
|
2016-01-08 09:41:12 +08:00
|
|
|
@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
|
2016-03-11 18:50:37 +08:00
|
|
|
|
|
|
|
#加上all
|
|
|
|
if @users.size > 0
|
|
|
|
allUser = Struct.new(:id, :name).new
|
|
|
|
allUser.id = @users.map{|u| u.id}.join(",")
|
|
|
|
allUser.name = "all"
|
|
|
|
@users.insert(0, allUser)
|
|
|
|
end
|
|
|
|
@users
|
2015-12-14 17:13:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-01-08 09:41:12 +08:00
|
|
|
def to_pinyin(s)
|
|
|
|
Pinyin.t(s).downcase
|
|
|
|
end
|
|
|
|
|
2015-12-14 17:13:57 +08:00
|
|
|
def find_at_users(type, id)
|
|
|
|
@logger.info("#{type}, #{id}")
|
2015-12-09 09:59:13 +08:00
|
|
|
case type
|
|
|
|
when "Issue"
|
2015-12-14 17:13:57 +08:00
|
|
|
find_issue(id)
|
|
|
|
when 'Project'
|
|
|
|
find_project(id)
|
|
|
|
when 'Course'
|
|
|
|
find_course(id)
|
|
|
|
when 'Activity', 'CourseActivity', 'ForgeActivity','UserActivity', 'OrgActivity','PrincipalActivity'
|
|
|
|
find_activity(id, type)
|
|
|
|
when 'Attachment'
|
|
|
|
find_attachment(id)
|
|
|
|
when 'Message'
|
|
|
|
find_message(id)
|
2015-12-15 09:09:41 +08:00
|
|
|
when 'HomeworkCommon'
|
|
|
|
find_homework(id)
|
2015-12-17 15:14:52 +08:00
|
|
|
when 'Topic'
|
|
|
|
find_topic(id)
|
2016-01-26 18:24:15 +08:00
|
|
|
when 'JournalsForMessage'
|
|
|
|
find_journals_for_message(id)
|
|
|
|
when 'Principal'
|
|
|
|
find_principal(id)
|
2016-07-13 15:20:39 +08:00
|
|
|
when 'BlogComment'
|
|
|
|
find_blog_comment(id)
|
2016-01-26 18:24:15 +08:00
|
|
|
when 'All'
|
|
|
|
nil
|
2015-12-09 09:59:13 +08:00
|
|
|
else
|
2015-12-14 17:13:57 +08:00
|
|
|
nil
|
2015-12-09 09:59:13 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-17 15:14:52 +08:00
|
|
|
def find_topic(id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-12-14 17:13:57 +08:00
|
|
|
def find_issue(id)
|
2015-12-09 09:59:13 +08:00
|
|
|
#1. issues list persons
|
|
|
|
#2. project persons
|
2015-12-14 17:13:57 +08:00
|
|
|
issue = Issue.find(id)
|
|
|
|
journals = issue.journals
|
2015-12-09 09:59:13 +08:00
|
|
|
at_persons = journals.map(&:user) + issue.project.users
|
2015-12-14 17:13:57 +08:00
|
|
|
at_persons.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_project(id)
|
2016-05-20 20:08:46 +08:00
|
|
|
return [] if id.to_i<0
|
2015-12-14 17:13:57 +08:00
|
|
|
at_persons = Project.find(id).users
|
|
|
|
at_persons.delete_if { |u| u.id == User.current.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_course(id)
|
|
|
|
at_persons = Course.find(id).users
|
|
|
|
at_persons.delete_if { |u| u.id == User.current.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_activity(id, type)
|
|
|
|
|
|
|
|
## 基本上是本类型中的 加上所属类型的用户
|
|
|
|
case type
|
|
|
|
when 'Activity'
|
|
|
|
activity = Activity.find(id)
|
|
|
|
(find_at_users(activity.act_type, activity.act_id) ||[]) +
|
|
|
|
(find_at_users(activity.activity_container_type, activity.activity_container_id) || [])
|
|
|
|
when 'CourseActivity'
|
|
|
|
activity = CourseActivity.find(id)
|
|
|
|
(find_at_users(activity.course_act_type, activity.course_act_id) || []) + (find_course(activity.course.id) || [])
|
|
|
|
when 'ForgeActivity'
|
|
|
|
activity = ForgeActivity.find(id)
|
|
|
|
(find_at_users(activity.forge_act_type, activity.forge_act_id) ||[]) +
|
|
|
|
(find_project(activity.project_id) || [])
|
|
|
|
when 'UserActivity'
|
|
|
|
activity = UserActivity.find(id)
|
|
|
|
(find_at_users(activity.act_type, activity.act_id) || []) +
|
|
|
|
(find_at_users(activity.container_type, activity.container_id) || [])
|
|
|
|
when 'OrgActivity'
|
|
|
|
activity = OrgActivity.find(id)
|
|
|
|
(find_at_users(activity.org_act_type, activity.org_act_id) || []) +
|
|
|
|
(find_at_users(activity.container_type, activity.container_id) || [])
|
|
|
|
when 'PrincipalActivity'
|
|
|
|
activity = PrincipalActivity.find(id)
|
|
|
|
find_at_users(activity.principal_act_type, activity.principal_act_id)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#作业应该是关联课程,取课程的用户列表
|
|
|
|
def find_homework(id)
|
|
|
|
homework = HomeworkCommon.find(id)
|
|
|
|
find_course(homework.course_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_attachment(id)
|
|
|
|
attachment = Attachment.find(id)
|
|
|
|
find_at_users(attachment.container_type, attachment.container_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
#Message
|
|
|
|
def find_message(id)
|
|
|
|
message = Message.find(id)
|
|
|
|
at_persons = message.board.messages.map(&:author)
|
2015-12-17 15:14:52 +08:00
|
|
|
(at_persons || []) + (find_project(message.board.project_id)||[])
|
2015-12-14 17:13:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
#News
|
|
|
|
def find_news(id)
|
|
|
|
find_project(News.find(id).project_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
#JournalsForMessage
|
|
|
|
def find_journals_for_message(id)
|
|
|
|
jounrnal = JournalsForMessage.find(id)
|
2016-01-26 18:24:15 +08:00
|
|
|
if jounrnal.jour_type == 'Principal'
|
|
|
|
[jounrnal.user] + (JournalsForMessage.where(m_reply_id: id).map(&:user) || [])
|
|
|
|
else
|
|
|
|
find_at_users(jounrnal.jour_type, jounrnal.jour_id)
|
|
|
|
end
|
2015-12-14 17:13:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
#Poll
|
|
|
|
def find_poll(id)
|
|
|
|
end
|
|
|
|
|
|
|
|
#Journal
|
|
|
|
def find_journal(id)
|
|
|
|
end
|
|
|
|
|
|
|
|
#Document
|
|
|
|
def find_document(id)
|
|
|
|
find_project(Document.find(id).project_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
#ProjectCreateInfo
|
|
|
|
def find_project_create_info(id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
#Principal
|
|
|
|
def find_principal(id)
|
|
|
|
end
|
|
|
|
|
|
|
|
#BlogComment
|
|
|
|
def find_blog_comment(id)
|
2016-07-13 15:20:39 +08:00
|
|
|
blog = BlogComment.find(id)
|
|
|
|
blog.author.watcher_users
|
2015-12-09 09:59:13 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|