You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
5.6 KiB
214 lines
5.6 KiB
6 years ago
|
#coding=utf-8
|
||
|
|
||
|
class AtController < ApplicationController
|
||
|
respond_to :json
|
||
|
|
||
|
def show
|
||
|
@logger = Logger.new(Rails.root.join('log', 'at.log').to_s)
|
||
|
users = find_at_users(params[:type], params[:id])
|
||
|
@users = users
|
||
|
@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.current.logged? && @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
|
||
|
end
|
||
|
|
||
|
private
|
||
|
def to_pinyin(s)
|
||
|
Pinyin.t(s).downcase
|
||
|
end
|
||
|
|
||
|
def find_at_users(type, id)
|
||
|
@logger.info("#{type}, #{id}")
|
||
|
case type
|
||
|
when "Issue"
|
||
|
find_issue(id)
|
||
|
when 'TrainingTask'
|
||
|
find_training_task(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)
|
||
|
when 'HomeworkCommon'
|
||
|
find_homework(id)
|
||
|
when 'GraduationTopic'
|
||
|
find_graduation_topic(id)
|
||
|
when 'GraduationTask'
|
||
|
find_graduation_task(id)
|
||
|
when 'Topic'
|
||
|
find_topic(id)
|
||
|
when 'JournalsForMessage'
|
||
|
find_journals_for_message(id)
|
||
|
when 'Journal'
|
||
|
find_journal(id)
|
||
|
when 'Principal'
|
||
|
find_principal(id)
|
||
|
when 'BlogComment'
|
||
|
find_blog_comment(id)
|
||
|
when 'All'
|
||
|
nil
|
||
|
else
|
||
|
nil
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def find_topic(id)
|
||
|
|
||
|
end
|
||
|
|
||
|
def find_issue(id)
|
||
|
#1. issues list persons
|
||
|
#2. project persons
|
||
|
issue = Issue.find(id)
|
||
|
journals = issue.journals
|
||
|
at_persons = journals.map(&:user) + issue.project.users
|
||
|
at_persons.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }
|
||
|
end
|
||
|
|
||
|
def find_training_task(id)
|
||
|
training_task = TrainingTask.find(id)
|
||
|
journals = training_task.journals
|
||
|
at_persons = journals.map(&:user) + training_task.project.users
|
||
|
at_persons.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }
|
||
|
end
|
||
|
|
||
|
def find_project(id)
|
||
|
return [] if id.to_i<0
|
||
|
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_graduation_topic id
|
||
|
topic = GraduationTopic.find(id)
|
||
|
find_course(topic.course_id)
|
||
|
end
|
||
|
|
||
|
# 毕设任务
|
||
|
def find_graduation_task id
|
||
|
task = GraduationTask.find(id)
|
||
|
find_course(task.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)
|
||
|
if message.board.course_id.nil?
|
||
|
at_persons = message.board.messages.map(&:author)
|
||
|
(at_persons || []) + (find_project(message.board.project_id)||[])
|
||
|
else
|
||
|
type = 'Course'
|
||
|
course_id = message.board.course_id
|
||
|
find_at_users(type, course_id)
|
||
|
end
|
||
|
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)
|
||
|
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
|
||
|
end
|
||
|
|
||
|
#Poll
|
||
|
def find_poll(id)
|
||
|
end
|
||
|
|
||
|
#Journal
|
||
|
def find_journal(id)
|
||
|
journal = Journal.find id
|
||
|
if journal.journalized_type == 'Issue'
|
||
|
issue_id = journal.issue.id
|
||
|
find_at_users(journal.journalized_type, issue_id)
|
||
|
end
|
||
|
|
||
|
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)
|
||
|
blog = BlogComment.find(id)
|
||
|
blog.author.watcher_users
|
||
|
end
|
||
|
|
||
|
end
|