diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 72301754d..53fb21b8c 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -68,7 +68,7 @@ class BoardsController < ApplicationController end def show - #更新对应的forge_messages表的viewed字段 + # 璁ㄨ鍖烘秷鎭姸鎬佹洿鏂帮紙宸茶鍜屾湭璇伙級 if @project query_forge_messages = @board.messages query_forge_messages.each do |query_forge_message| diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index c73e6bc93..b3624b14d 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -119,12 +119,14 @@ class IssuesController < ApplicationController end # 缂洪櫡鐘舵佹洿鏂 query_journals = @issue.journals - if User.current.id == @issue.author_id query_journals.each do |query_journal| - query_journal.forge_messages.update_all(:viewed => true) + query_journal.forge_messages.each do |f| + if User.current.id == f.user_id + f.update_attributes(:viewed => true) + end + end end - end - # + # end @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all @journals.each_with_index {|j,i| j.indice = i+1} @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 11d1d6e18..27e0d472f 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -115,10 +115,24 @@ class MemosController < ApplicationController REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE) def show - #鏇存柊璐村惂甯栧瓙鐣欒█瀵瑰簲鐨刴emo_messages鐨剉iewed瀛楁 + # 鏇存柊璐村惂甯栧瓙鐣欒█瀵瑰簲鐨刴emo_messages鐨剉iewed瀛楁 + unless @memo.children.blank? + @memo.children.each do |child| + child.memo_messages.each do |memo_message| + if User.current.id == memo_message.user_id + memo_message.update_attributes(:viewed => true) + end + end + end + end query_memo_messages = @memo.memo_messages - pre_count = REPLIES_PER_PAGE + query_memo_messages.each do |query_memo_message| + if User.current.id == query_memo_message.user_id + query_memo_message.update_attributes(:viewed => true) + end + end + pre_count = REPLIES_PER_PAGE @memo = @memo.root # 鍙栧嚭妤间富锛岄槻姝㈣緭鍏ュ笘瀛恑d璁╁洖澶嶄綔涓轰富璐存樉绀 @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1)) diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index d445fc77c..d5c248f77 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -99,30 +99,32 @@ class NewsController < ApplicationController end def show - #鏇存柊news瀵瑰簲鐨刦orge_messages鐨剉iewed瀛楁 - query_forge_news = @news.forge_messages - query_forge_news.each do |query| - if User.current.id == query.user_id - query.update_attributes(:viewed => true) - end + # 鏇存柊news瀵瑰簲鐨刦orge_messages鐨勬秷鎭痸iewed瀛楁 + if @project + query_message_news = @news.forge_messages + else + query_message_news = @news.course_messages end - #鏇存柊news瀵瑰簲鐨刢ourse_messages鐨剉iewed瀛楁 - query_course_news = @news.course_messages - query_course_news.each do |query| - if User.current.id == query.user_id - query.update_attributes(:viewed => true) - end + query_message_news.each do |query| + if User.current.id == query.user_id + query.update_attributes(:viewed => true) + end end - #鏇存柊椤圭洰鏂伴椈鐨勮瘎闃呯殑viewed瀛楁 - current_forge_comments = @news.comments - current_forge_comments.each do |current_forge_comment| - query_forge_comment = current_forge_comment.forge_messages - query_forge_comment.each do |query| + # 鏇存柊椤圭洰鏂伴椈鐨勮瘎闃呯殑娑堟伅viewed瀛楁 + current_message_comments = @news.comments + current_message_comments.each do |current_message_comment| + if @project + query_message_comment = current_message_comment.forge_messages + else + query_message_comment = current_message_comment.course_messages + end + query_message_comment.each do |query| if User.current.id == query.user_id query.update_attributes(:viewed => true) end end end + # end cs = CoursesService.new result = cs.show_course_news params,User.current diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 1bbcf9bb4..a8f2a11f1 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -28,6 +28,7 @@ class PollController < ApplicationController render_403 return end + # 闂嵎娑堟伅鐘舵佹洿鏂 query_course_poll = @poll.course_messages query_course_poll.each do |query| if User.current.id == query.user_id diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ea4dc25a3..1fac6737b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -106,16 +106,16 @@ class UsersController < ApplicationController return end # 褰撳墠鐢ㄦ埛鏌ョ湅娑堟伅锛屽垯璁剧疆娑堟伅涓哄凡璇 - course_querys = @user.course_messages - forge_querys = @user.forge_messages - user_querys = @user.user_feedback_messages - forum_querys = @user.memo_messages - if User.current.id == @user.id - course_querys.update_all(:viewed => true) - forge_querys.update_all(:viewed => true) - user_querys.update_all(:viewed => true) - forum_querys.update_all(:viewed => true) - end + # course_querys = @user.course_messages + # forge_querys = @user.forge_messages + # user_querys = @user.user_feedback_messages + # forum_querys = @user.memo_messages + # if User.current.id == @user.id + # course_querys.update_all(:viewed => true) + # forge_querys.update_all(:viewed => true) + # user_querys.update_all(:viewed => true) + # forum_querys.update_all(:viewed => true) + # end # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count case params[:type] when nil @@ -126,46 +126,41 @@ class UsersController < ApplicationController end when 'homework' @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc") - @message_alls_count = @message_alls.count when 'course_message' @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc") - @message_alls_count = @message_alls.count - when 'forge_message' - @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user).order("created_at desc") - @message_alls_count = @message_alls.count + # when 'forge_message' + # @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user).order("created_at desc") + # @message_alls_count = @message_alls.count when 'course_news' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "News", @user).order("created_at desc") - @message_alls_count = @message_alls.count + # 璇剧▼閫氱煡鍖呭惈鍙戝竷鐨勯氱煡鍜屽洖澶嶇殑閫氱煡 + @message_alls = CourseMessage.where("course_message_type =? or course_message_type =?", "News", "Comment").where("user_id =?", @user).order("created_at desc") #@user_course_messages_count = @user_course_messages.count - when 'forge_news' - @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "News", @user).order("created_at desc") - @message_alls_count = @message_alls.count - when 'course_news_reply' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Comment", @user).order("created_at desc") - when 'forge_news_reply' - @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Comment", @user).order("created_at desc") - @message_alls_count = @message_alls.count - when 'poll' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc") - @message_alls_count = @message_alls.count - when 'works_reviewers' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "StudentWorksScore", @user).order("created_at desc") - @message_alls_count = @message_alls.count - when 'works_reply' - @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "JournalsForMessage", @user).order("created_at desc") - @message_alls_count = @message_alls.count + # when 'forge_news' + # @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "News", @user).order("created_at desc") + # @message_alls_count = @message_alls.count + # when 'course_news_reply' + # @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Comment", @user).order("created_at desc") + # when 'forge_news_reply' + # @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Comment", @user).order("created_at desc") + # @message_alls_count = @message_alls.count + # when 'poll' + # @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc") + # @message_alls_count = @message_alls.count + # when 'works_reviewers' + # @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "StudentWorksScore", @user).order("created_at desc") + # @message_alls_count = @message_alls.count + # when 'works_reply' + # @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "JournalsForMessage", @user).order("created_at desc") + # @message_alls_count = @message_alls.count when 'issue' - @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Issue", @user).order("created_at desc") - @message_alls_count = @message_alls.count - when 'issue_update' # 缂洪櫡鐘舵佹洿鏂般佺暀瑷 - @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Journal", @user).order("created_at desc") - @message_alls_count = @message_alls.count + @message_alls = ForgeMessage.where("forge_message_type =? or forge_message_type =?" , "Issue", "Journal").where("user_id=?", @user).order("created_at desc") + # when 'issue_update' # 缂洪櫡鐘舵佹洿鏂般佺暀瑷 + # @message_alls = ForgeMessage.where("forge_message_type =? and user_id =?", "Journal", @user).order("created_at desc") + # @message_alls_count = @message_alls.count when 'forum' @message_alls = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc") - @message_alls_count = @message_alls.count when 'user_feedback' @message_alls = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "JournalsForMessage", @user).order("created_at desc") - @message_alls_count = @message_alls.count else render_404 return @@ -542,6 +537,15 @@ class UsersController < ApplicationController # modified by fq def user_newfeedback + # 鏇存柊鐢ㄦ埛鐣欒█娑堟伅鐘舵 + @user.journals_for_messages.each do |jour_message| + jour_message.user_feedback_messages.each do |userfeedback_message| + if User.current.id == userfeedback_message.user_id + userfeedback_message.update_attributes(:viewed => true) + end + end + end + # end jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') if User.current == @user jours.update_all(:is_readed => true, :status => false) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fcf28506a..ad9322cbc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -760,7 +760,8 @@ module ApplicationHelper options = args.extract_options! text = distance_of_time_in_words(Time.now, time) if @project - link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => User.current.time_to_date(time)},options.reverse_merge(:title => format_time(time))) + content_tag('acronym', text, options.reverse_merge(:title => format_time(time))) + # link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => User.current.time_to_date(time)},options.reverse_merge(:title => format_time(time))) else content_tag('acronym', text, options.reverse_merge(:title => format_time(time))) end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f7fb9b1aa..47ab30cb1 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -73,7 +73,7 @@ class Attachment < ActiveRecord::Base cattr_accessor :thumbnails_storage_path @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") - before_save :files_to_final_location,:act_as_course_activity + before_save :files_to_final_location,:act_as_course_activity,:act_as_forge_activity after_create :office_conver, :be_user_score,:act_as_forge_activity after_update :office_conver, :be_user_score after_destroy :delete_from_disk,:down_user_score diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 6f775e7a2..c44b1aeee 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -202,24 +202,24 @@ class JournalsForMessage < ActiveRecord::Base # 鐢ㄦ埛鐣欒█娑堟伅閫氱煡 def act_as_user_feedback_message # 涓荤暀瑷 - receivers = [] - if self.reply_id == 0 - if self.user_id != self.jour_id # 杩囨护鑷繁缁欒嚜宸辩殑鐣欒█娑堟伅 - receivers << self.jour - end - else # 鐣欒█鍥炲 - reply_to = User.find(self.reply_id) - if self.user_id != self.reply_id # 娣诲姞鎴戝洖澶嶇殑閭d釜浜 - receivers << reply_to - end - if self.user_id != self.parent.jour_id && self.reply_id != self.parent.jour_id # 缁欎笢瀹跺彂淇℃伅锛屽鏋滃洖澶嶇殑瀵硅薄鏄笢瀹跺垯涓嶅彂 - receivers << self.parent.jour - end - end if self.jour_type == 'Principal' - receivers.each do |r| - self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) + receivers = [] + if self.reply_id == 0 + if self.user_id != self.jour_id # 杩囨护鑷繁缁欒嚜宸辩殑鐣欒█娑堟伅 + receivers << self.jour end + else # 鐣欒█鍥炲 + reply_to = User.find(self.reply_id) + if self.user_id != self.reply_id # 娣诲姞鎴戝洖澶嶇殑閭d釜浜 + receivers << reply_to + end + if self.user_id != self.parent.jour_id && self.reply_id != self.parent.jour_id # 缁欎笢瀹跺彂淇℃伅锛屽鏋滃洖澶嶇殑瀵硅薄鏄笢瀹跺垯涓嶅彂 + receivers << self.parent.jour + end + end + receivers.each do |r| + self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false) + end end end diff --git a/app/models/user_feedback_message.rb b/app/models/user_feedback_message.rb index 1dda157d6..02335b8e2 100644 --- a/app/models/user_feedback_message.rb +++ b/app/models/user_feedback_message.rb @@ -8,7 +8,7 @@ class UserFeedbackMessage < ActiveRecord::Base validates :user_id,presence: true validates :journals_for_message_id,presence: true validates :journals_for_message_type, presence: true - after_create :add_user_message + after_save :add_user_message def add_user_message self.message_alls << MessageAll.new(:user_id => self.user_id) diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index d330857c3..d965c92e7 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -19,9 +19,9 @@ <%# 椤圭洰鐩稿叧娑堟伅 %> - +