diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb new file mode 100644 index 000000000..8c551d0df --- /dev/null +++ b/app/controllers/at_controller.rb @@ -0,0 +1,152 @@ +#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 } if users + end + + private + def find_at_users(type, id) + @logger.info("#{type}, #{id}") + case type + when "Issue" + 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) + when 'HomeworkCommon' + find_homework(id) + when 'Topic' + find_topic(id) + 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_project(id) + 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) + (at_persons || []) + (find_project(message.board.project_id)||[]) + 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) + find_at_users(jounrnal.jour_type, jounrnal.jour_id) + end + + #Poll + def find_poll(id) + end + + #Journal + def find_journal(id) + journal = Journal.find(id) + find_at_users(journal.journalized_type, journal.journalized_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) + blog = BlogComment.find(id).blog + blog.users + end + +end \ No newline at end of file diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 2ec3cac0d..3545a8a22 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -79,6 +79,13 @@ class BoardsController < ApplicationController end end end + + @project.boards.each do |board| + board.messages.each do |m| + User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!} + end + end + elsif @course query_course_messages = @board.messages query_course_messages.each do |query_course_message| diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index a83534ad7..acc174659 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -19,6 +19,14 @@ class HomeworkCommonController < ApplicationController @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] + + #设置at已读 + @homeworks.each do |homework| + homework.journals_for_messages.each do |j| + User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} + end + end + respond_to do |format| format.js format.html diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 2c1f78de8..a132ec295 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -24,7 +24,7 @@ class IssuesController < ApplicationController before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] before_filter :find_project, :only => [:new, :create, :update_form] #before_filter :authorize, :except => [:index, :show] - before_filter :authorize, :except => [:index,:add_journal, :add_journal_in_org] + before_filter :authorize, :except => [:index,:add_journal, :add_journal_in_org,:delete_journal,:reply,:add_reply] before_filter :find_optional_project, :only => [:index] before_filter :check_for_default_issue_status, :only => [:new, :create] @@ -118,6 +118,14 @@ class IssuesController < ApplicationController # 当前用户查看指派给他的缺陷消息,则设置消息为已读 query = ForgeMessage.where("forge_message_type =? and user_id =? and forge_message_id =?", "Issue", User.current, @issue).first query.update_attribute(:viewed, true) unless query.nil? + + # issue 新建的at消息 + User.current.at_messages.unviewed('Issue', @issue.id).each {|x| x.viewed!} + # 回复的at消息 + @issue.journals.each do |j| + User.current.at_messages.unviewed('Journal', j.id).each {|x| x.viewed!} + end + # 缺陷状态更新 query_journals = @issue.journals query_journals.each do |query_journal| @@ -145,24 +153,17 @@ class IssuesController < ApplicationController @project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq - #id name email - #1. issues list persons - #2. project persons - @at_persons = @journals.map(&:user) + @issue.project.users - @at_persons = @at_persons.uniq{|u| u.id}.delete_if{|u| u.id == User.current.id} - @at_persons = nil - - respond_to do |format|`` - format.html { - retrieve_previous_and_next_issue_ids - render :template => 'issues/show', :layout => @project_base_tag#by young - } - format.api - format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } - format.pdf { - pdf = issue_to_pdf(@issue, :journals => @journals) - send_data(pdf, :type => 'application/pdf', :filename => filename_for_content_disposition("#{@project.identifier}-#{@issue.id}.pdf") ) - } + respond_to do |format| + format.html { + retrieve_previous_and_next_issue_ids + render :template => 'issues/show', :layout => @project_base_tag#by young + } + format.api + format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } + format.pdf { + pdf = issue_to_pdf(@issue, :journals => @journals) + send_data(pdf, :type => 'application/pdf', :filename => filename_for_content_disposition("#{@project.identifier}-#{@issue.id}.pdf") ) + } end end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f0b15e8f8..8eb6a6860 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -348,10 +348,6 @@ update # end # end - - - - @changesets = g.commits(@project.gpid, :ref_name => @rev) # @changesets = @repository.latest_changesets(@path, @rev) # @changesets_count = @repository.latest_changesets(@path, @rev).count @@ -378,19 +374,6 @@ update alias_method :browse, :show - #add by hx - def count_commits(project_id , left , right) - count = 0 - (left..right).each do |page| - if $g.commits(project_id,:page => page).count == 0 - break - else - count = count + $g.commits(project_id,:page => page).count - end - end - return count - end - def changes @entry = @repository.entry(@path, @rev) (show_error_not_found; return) unless @entry @@ -400,26 +383,10 @@ update @commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s) #add by hx - if g.commits(@project.gpid , :page=>200).count > 0 - count = 4020 - elsif g.commits(@project.gpid , :page=>25).count==0 - count = count_commits(@project.gpid , 0 , 25) - elsif g.commits(@project.gpid , :page=>50).count ==0 - count = count_commits(@project.gpid , 25 , 50)+ 25 * 20 - elsif g.commits(@project.gpid , :page=>75).count ==0 - count = count_commits(@project.gpid , 50 , 75)+ 50 * 20 - elsif g.commits(@project.gpid , :page=>100).count== 0 - count = count_commits(@project.gpid , 75 , 100) + 75 * 20 - elsif g.commits(@project.gpid , :page=>125).count==0 - count = count_commits(@project.gpid , 100 , 125) + 100 * 20 - elsif g.commits(@project.gpid , :page=>150).count==0 - count = count_commits(@project.gpid , 125 , 150) + 125 * 20 - else - count = count_commits(@project.gpid , 150 ,200) + 150 * 20 - end + rep_count = commit_count(@project) #页面传递必须要str类型,但是Paginator的初始化必须要num类型,需要类型转化 - @commits_count = count + @commits_count = rep_count @commits_pages = Redmine::Pagination::Paginator.new @commits_count,limit,params[:page] @commit = g.commit(@project.gpid,@rev) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ce4c07c55..0650db1cf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -668,6 +668,42 @@ module ApplicationHelper return rep.blank? ? true :false end + # 获取Gitlab版本库提交总数 + def commit_count(project) + g = Gitlab.client + #add by hx + if g.commits(project.gpid , :page=>200).count > 0 + count = 4020 + elsif g.commits(project.gpid , :page=>25).count==0 + count = count_commits(project.gpid , 0 , 25) + elsif g.commits(project.gpid , :page=>50).count ==0 + count = count_commits(project.gpid , 25 , 50)+ 25 * 20 + elsif g.commits(project.gpid , :page=>75).count ==0 + count = count_commits(project.gpid , 50 , 75)+ 50 * 20 + elsif g.commits(project.gpid , :page=>100).count== 0 + count = count_commits(project.gpid , 75 , 100) + 75 * 20 + elsif g.commits(project.gpid , :page=>125).count==0 + count = count_commits(project.gpid , 100 , 125) + 100 * 20 + elsif g.commits(project.gpid , :page=>150).count==0 + count = count_commits(project.gpid , 125 , 150) + 125 * 20 + else + count = count_commits(project.gpid , 150 ,200) + 150 * 20 + end + end + + #add by hx + def count_commits(project_id , left , right) + count = 0 + (left..right).each do |page| + if $g.commits(project_id,:page => page).count == 0 + break + else + count = count + $g.commits(project_id,:page => page).count + end + end + return count + end + # 获取单一gitlab项目 def gitlab_repository(project) rep = Repository.where("project_id =? and type =?", project.id,"Repository::Gitlab" ).first @@ -1716,6 +1752,13 @@ module ApplicationHelper # def javascript_include_tag(*sources) options = sources.last.is_a?(Hash) ? sources.pop : {} + + @sources ||= [] + sources = sources.delete_if do|source| + @sources.include?(source) + end + @sources += sources + if plugin = options.delete(:plugin) sources = sources.map do |source| if plugin @@ -1725,7 +1768,12 @@ module ApplicationHelper end end end - super sources, options + + if sources && !sources.empty? + super(sources, options) + else + '' + end end def content_for(name, content = nil, &block) @@ -2676,19 +2724,8 @@ int main(int argc, char** argv){ end def import_ke(default_opt={}) - opt = {enable_at: true, prettify: false, init_activity: false}.merge default_opt + opt = {enable_at: false, prettify: false, init_activity: false}.merge default_opt ss = '' - if opt[:enable_at] - ss = '" - end ss += javascript_include_tag("/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg') if opt[:enable_at] diff --git a/app/helpers/project_score_helper.rb b/app/helpers/project_score_helper.rb index 104cd16cb..256e35a7a 100644 --- a/app/helpers/project_score_helper.rb +++ b/app/helpers/project_score_helper.rb @@ -22,6 +22,7 @@ module ProjectScoreHelper #代码提交数量 def changesets_num project + # commit_count(project) project.changesets.count end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 2935d018a..963284f7f 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -89,7 +89,8 @@ module UsersHelper forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count user_memo_count = MemoMessage.where("user_id =? and viewed =?", user, 0).count - messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count = user.at_messages.where(viewed: false).count + messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count end def user_mail_notification_options(user) diff --git a/app/models/at_message.rb b/app/models/at_message.rb new file mode 100644 index 000000000..3d20ffafb --- /dev/null +++ b/app/models/at_message.rb @@ -0,0 +1,102 @@ +#coding=utf-8 + +class AtMessage < ActiveRecord::Base + belongs_to :user + belongs_to :sender, class_name: "User", foreign_key: "sender_id" + attr_accessible :at_message, :container, :viewed, :user_id, :sender_id + belongs_to :at_message, polymorphic: true + belongs_to :container, polymorphic: true + + has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy + validates :user_id, :sender_id, :at_message_id, :at_message_type, presence: true + + after_create :add_user_message + + scope :unviewed, ->(type, id){ + where(at_message_type: type, at_message_id:id, viewed: false) + } + + def viewed! + update_attribute :viewed, true + end + + def at_valid? + return true if at_message_type == 'Issue' + return true if 'Journal' == at_message_type + return true if 'JournalsForMessage' == at_message_type + return true if 'Message' == at_message_type + false + end + + def add_user_message + if MessageAll.where(message_type: self.class.name,message_id: self.id).empty? + self.message_alls << MessageAll.new(:user_id => self.user_id) + end + end + + def subject + case at_message_type + when "Issue" + "新建问题: " + at_message.subject + when "Journal" + "问题留言: " + at_message.journalized.subject + when 'Message' + if(at_message.topic?) + "发布新帖: " + else + "回复帖子: " + end + at_message.subject + when 'JournalsForMessage' + "作业: #{at_message.jour.name} 中留言" + else + logger.error "error type: #{at_message_type}" + end + end + + def description + case at_message_type + when "Issue" + at_message.description + when "Journal" + at_message.notes + when 'Message' + at_message.content + when "JournalsForMessage" + at_message.notes + else + logger.error "error type: #{at_message_type}" + end + end + + def author + case at_message_type + when "Issue" + at_message.author + when "Journal" + at_message.user + when 'Message' + at_message.author + when 'JournalsForMessage' + at_message.user + else + logger.error "error type: #{at_message_type}" + end + end + + def url + case at_message_type + when "Issue" + {controller: :issues, action: :show, id: at_message} + when "Journal" + {controller: :issues, action: :show, id: at_message.journalized} + when 'Message' + {controller: :boards, action: :show, project_id: at_message.board.project, id: at_message.board} + when 'JournalsForMessage' + {controller: :homework_common, action: :index, course: at_message.jour.course_id} + else + logger.error "error type: #{at_message_type}" + end + + end + +end diff --git a/app/models/issue.rb b/app/models/issue.rb index edce3310a..5ecb3e36f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -52,6 +52,7 @@ class Issue < ActiveRecord::Base # ForgeMessage虚拟关联(多态) has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy + has_many :at_messages, class_name: 'AtMessage', as: :at_message ,:dependent => :destroy acts_as_nested_set :scope => 'root_id', :dependent => :destroy acts_as_attachable :before_add => :attachment_added, :after_remove => :attachment_removed @@ -82,7 +83,7 @@ class Issue < ActiveRecord::Base attr_reader :current_journal # fq - after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message + after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message after_update :be_user_score after_destroy :down_user_score # after_create :be_user_score @@ -156,6 +157,14 @@ class Issue < ActiveRecord::Base end end + # at 功能添加消息提醒 + def act_as_at_message + users = self.description.scan //m + users && users.flatten.uniq.each do |uid| + self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id) + end + end + # 更新缺陷 #def act_as_forge_message_update # unless self.author_id == self.assigned_to_id diff --git a/app/models/journal.rb b/app/models/journal.rb index 9ffc5d405..638a98006 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -28,10 +28,12 @@ class Journal < ActiveRecord::Base has_one :journal_reply has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy # 被ForgeActivity虚拟关联 - has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy + #has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy 评论不应该算入 # 被ForgeMessage虚拟关联 has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy - # end + + has_many :at_messages, as: :at_message, dependent: :destroy + attr_accessor :indice acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.project_index}#{status}: #{o.issue.subject}" }, @@ -50,7 +52,7 @@ class Journal < ActiveRecord::Base before_create :split_private_notes # fq - after_save :act_as_activity,:be_user_score,:act_as_forge_activity, :act_as_forge_message + after_save :act_as_activity,:be_user_score, :act_as_forge_message, :act_as_at_message # end #after_destroy :down_user_score #before_save :be_user_score @@ -160,14 +162,14 @@ class Journal < ActiveRecord::Base end # end - # Time 2015-02-27 13:30:19 - # Author lizanle - # Description 公共表中需要保存一份该记录 - def act_as_forge_activity - self.forge_acts << ForgeActivity.new(:user_id => self.user_id, - :project_id => self.issue.project.id) - - end + # # Time 2015-02-27 13:30:19 + # # Author lizanle + # # Description 公共表中需要保存一份该记录 + # def act_as_forge_activity + # self.forge_acts << ForgeActivity.new(:user_id => self.user_id, + # :project_id => self.issue.project.id) + # + # end # 缺陷状态更改,消息提醒 def act_as_forge_message @@ -184,6 +186,13 @@ class Journal < ActiveRecord::Base end end + def act_as_at_message + users = self.notes.scan //m + users && users.flatten.uniq.each do |uid| + self.at_messages << AtMessage.new(user_id: uid, sender_id: self.user_id) + end + end + # 更新用户分数 -by zjc def be_user_score #新建了缺陷留言且留言不为空,不为空白 diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 396133c7a..59da817f4 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -64,8 +64,10 @@ class JournalsForMessage < ActiveRecord::Base has_many :course_messages, :class_name => 'CourseMessage',:as =>:course_message ,:dependent => :destroy has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy + has_many :at_messages, as: :at_message, dependent: :destroy + validates :notes, presence: true, if: :is_homework_jour? - after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score + after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_at_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score after_create :reset_counters! after_destroy :reset_counters! after_save :be_user_score @@ -240,6 +242,12 @@ class JournalsForMessage < ActiveRecord::Base end end + def act_as_at_message + users = self.notes.scan //m + users && users.flatten.uniq.each do |uid| + self.at_messages << AtMessage.new(user_id: uid, sender_id: self.user_id) + end + end # 用户留言消息通知 def act_as_user_feedback_message # 主留言 diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 8891e6552..551ddd616 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -395,13 +395,13 @@ class Mailer < ActionMailer::Base user = User.find_by_mail(recipients) @user = user @token = Token.get_token_from_user(user, 'autologin') - @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :token => @token.value) + @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id) # edit - @issue_author_url = url_for(user_activities_url(@author,:token => @token.value)) - @project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id, :token => @token.value) + @issue_author_url = url_for(user_activities_url(@author)) + @project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id) - @user_url = url_for(my_account_url(user,:token => @token.value)) + @user_url = url_for(my_account_url(user)) subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}" @@ -471,7 +471,7 @@ class Mailer < ActionMailer::Base recipients = @project.manager_recipients s = l(:text_applied_project, :id => "##{@user.show_name}", :project => @project.name) @token = Token.get_token_from_user(@user, 'autologin') - @applied_url = url_for(:controller => 'projects', :action => 'settings', :id => @project.id,:tab=>'members', :token => @token.value) + @applied_url = url_for(:controller => 'projects', :action => 'settings', :id => @project.id,:tab=>'members') mail :to => recipients, :subject => s end diff --git a/app/models/message.rb b/app/models/message.rb index d8f62171a..4cdae1f6e 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -38,7 +38,7 @@ class Message < ActiveRecord::Base # 课程/项目 消息 has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy - #end + has_many :at_messages, as: :at_message, dependent: :destroy has_many :ActivityNotifies,:as => :activity, :dependent => :destroy @@ -74,7 +74,7 @@ class Message < ActiveRecord::Base after_update :update_messages_board after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets - after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score + after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score, :act_as_at_message #before_save :be_user_score scope :visible, lambda {|*args| @@ -96,6 +96,10 @@ class Message < ActiveRecord::Base end } + def topic? + parent_id.nil? + end + def visible?(user=User.current) if project !user.nil? && user.allowed_to?(:view_messages, project) @@ -237,6 +241,13 @@ class Message < ActiveRecord::Base end end end + + def act_as_at_message + users = self.content.scan //m + users && users.flatten.uniq.each do |uid| + self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id) + end + end #更新用户分数 -by zjc def be_user_score diff --git a/app/models/user.rb b/app/models/user.rb index 0c8d65481..2714117e9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -161,6 +161,7 @@ class User < Principal has_many :user_feedback_messages has_one :onclick_time has_many :system_messages + has_many :at_messages # 虚拟转换 has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" @@ -400,16 +401,7 @@ class User < Principal end def show_name - name = "" - unless self.user_extensions.nil? - if self.user_extensions.identity == 2 - name = firstname - else - name = lastname+firstname - end - else - name = lastname+firstname - end + name = lastname + firstname name.empty? || name.nil? ? login : name end ## end diff --git a/app/views/at/show.json.erb b/app/views/at/show.json.erb new file mode 100644 index 000000000..5341f251e --- /dev/null +++ b/app/views/at/show.json.erb @@ -0,0 +1,6 @@ +[ + <% @users && @users.each_with_index do |person,index| %> + {"id":<%=index%>, "userid": <%=person.id%>, "name": "<%=person.show_name%>", "login": "<%=person.login%>", "searchKey": "<%=person.get_at_show_name%>"} + <%= index != @users.size-1 ? ',' : '' %> + <% end %> +] diff --git a/app/views/bids/_new_homework_form.html.erb b/app/views/bids/_new_homework_form.html.erb index 5958fccff..815ff27e4 100644 --- a/app/views/bids/_new_homework_form.html.erb +++ b/app/views/bids/_new_homework_form.html.erb @@ -15,10 +15,10 @@ <% if edit_mode %> - <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:owner_id => bid.id,:owner_type =>OwnerTypeHelper::BID,:resizeType => 0 %> + <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:owner_id => bid.id,:owner_type =>OwnerTypeHelper::BID,:resizeType => 0,act_id: @course.id, act_type: @course.class.to_s %> <% else %> <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> - <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:resizeType => 0 %> + <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:resizeType => 0, act_id: @course.id, act_type: @course.class.to_s %> <% end %>
diff --git a/app/views/blog_comments/_edit.html.erb b/app/views/blog_comments/_edit.html.erb index c7065ece4..048402635 100644 --- a/app/views/blog_comments/_edit.html.erb +++ b/app/views/blog_comments/_edit.html.erb @@ -1,5 +1,5 @@ <%= content_for(:header_tags) do %> - <%= import_ke(enable_at: false, prettify: false) %> + <%= import_ke(enable_at: true, prettify: false) %> <%= javascript_include_tag 'blog' %> <% end %> @@ -34,7 +34,9 @@ :class => 'talk_text fl', :input_html => { :id => 'message_content', :class => 'talk_text fl', - :maxlength => 5000 }%> + :maxlength => 5000 }, + act_id: article.id, act_type: article.class.to_s + %>

diff --git a/app/views/blog_comments/_reply_form.html.erb b/app/views/blog_comments/_reply_form.html.erb index 32f4333c2..67642069c 100644 --- a/app/views/blog_comments/_reply_form.html.erb +++ b/app/views/blog_comments/_reply_form.html.erb @@ -1,5 +1,5 @@ <%= content_for(:header_tags) do %> - <%= import_ke(enable_at: false, prettify: false) %> + <%= import_ke(enable_at: true, prettify: false) %> <% end %>
  • @@ -27,7 +27,9 @@ :minHeight=>100, :input_html => { :id => 'message_content', :class => 'talk_text fl', - :maxlength => 5000 }%> + :maxlength => 5000 }, + at_id: article.id, at_type: article.class.to_s + %>

  • diff --git a/app/views/blog_comments/quote.js.erb b/app/views/blog_comments/quote.js.erb index 088b2cf67..cd53707d5 100644 --- a/app/views/blog_comments/quote.js.erb +++ b/app/views/blog_comments/quote.js.erb @@ -3,7 +3,7 @@ if($("#reply_message_<%= @blogComment.id%>").length > 0) { $(function(){ $('#reply_subject').val("<%= raw escape_javascript(@subject) %>"); $('#quote_quote').val("<%= raw escape_javascript(@temp.content.html_safe) %>"); - init_activity_KindEditor_data(<%= @blogComment.id%>,null,"85%"); + init_activity_KindEditor_data(<%= @blogComment.id%>,null,"85%", "<%=@blogComment.class.to_s%>"); }); }else if($("#reply_to_message_<%= @blogComment.id%>").length >0) { $("#reply_to_message_<%= @blogComment.id%>").replaceWith("

    "); diff --git a/app/views/blog_comments/reply.js.erb b/app/views/blog_comments/reply.js.erb index 1cb64b2b5..06adca74d 100644 --- a/app/views/blog_comments/reply.js.erb +++ b/app/views/blog_comments/reply.js.erb @@ -1,7 +1,7 @@ <% if @in_user_center%> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/user_blog', :locals => {:activity => @article,:user_activity_id =>@user_activity_id}) %>"); - init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%"); + init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%", 'UserActivity'); <% else%> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'blogs/article', :locals => {:activity => @article,:user_activity_id =>@user_activity_id}) %>"); -init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%"); +init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%", 'UserActivity'); <% end %> \ No newline at end of file diff --git a/app/views/blog_comments/show.html.erb b/app/views/blog_comments/show.html.erb index e46a7249f..aa984c621 100644 --- a/app/views/blog_comments/show.html.erb +++ b/app/views/blog_comments/show.html.erb @@ -27,7 +27,7 @@ } } $(function() { - init_activity_KindEditor_data(<%= @article.id%>,null,"85%"); + init_activity_KindEditor_data(<%= @article.id%>,null,"85%", '<%=@article.class.to_s%>'); showNormalImage('message_description_<%= @article.id %>'); }); diff --git a/app/views/blogs/_article_list.html.erb b/app/views/blogs/_article_list.html.erb index a91dd8151..f6383c95b 100644 --- a/app/views/blogs/_article_list.html.erb +++ b/app/views/blogs/_article_list.html.erb @@ -74,7 +74,7 @@ } $(function () { - init_activity_KindEditor_data(<%= topic.id%>, null, "87%"); + init_activity_KindEditor_data(<%= topic.id%>, null, "87%", "<%=topic.class.to_s%>"); showNormalImage('activity_description_<%= topic.id %>'); /*var description_images=$("div#activity_description_<%#= topic.id %>").find("img"); if (description_images.length>0) { diff --git a/app/views/boards/_course_new.html.erb b/app/views/boards/_course_new.html.erb index e4cf57ae3..31cdf41eb 100644 --- a/app/views/boards/_course_new.html.erb +++ b/app/views/boards/_course_new.html.erb @@ -1,5 +1,5 @@ <%= content_for(:header_tags) do %> - <%= import_ke(enable_at: false, prettify: false) %> + <%= import_ke(enable_at: true, prettify: false) %> <% end %> <%= error_messages_for 'message' %> @@ -34,7 +34,9 @@ :class => 'talk_text fl', :input_html => { :id => 'message_content', :class => 'talk_text fl', - :maxlength => 5000 }%> + :maxlength => 5000 }, + at_id: topic.id, at_type: topic.class.to_s + %>

    diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index de3b038e6..4dcdb7749 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -31,5 +31,4 @@ <%= render :partial => 'course_new', :locals => {:f => f, :topic => @message, :edit_mode => false, :course => @board.course} %> <% end %> <% end %> - <%= render :partial=> 'course_show_detail',:locals =>{:topics => @topics, :page => 0} %> - + <%= render :partial=> 'course_show_detail',:locals =>{:topics => @topics, :page => 0} %> diff --git a/app/views/boards/_project_show.html.erb b/app/views/boards/_project_show.html.erb index 5f6275e9d..839d587b2 100644 --- a/app/views/boards/_project_show.html.erb +++ b/app/views/boards/_project_show.html.erb @@ -20,7 +20,7 @@ <% end %>
    -