From 8b9eabd0275f71e86a7d3a1e19e191e53684317b Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 2 Sep 2015 18:35:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=93=E5=8D=B0=E6=94=B6=E6=8D=AE=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 22 ++++++++++--------- app/views/users/user_messages.html.erb | 5 +++++ db/migrate/20150829024549_course_messages.rb | 1 + .../20150829081822_update_message_time.rb | 1 + ...0150829130302_update_forge_message_time.rb | 1 + ...20150901004812_update_memo_message_time.rb | 1 + 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1fac6737b..5bd124fb9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -106,16 +106,18 @@ 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 + if params[:viewed] == "all" + 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 + end # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count case params[:type] when nil diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index 33c51760c..31fd7a6bd 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -29,6 +29,11 @@
+<% if params[:type].nil? %> +
+ 有 <%= User.current.count_new_message %> 封未读<%= link_to "全部设为已读", user_message_path(User.current, :viewed => 'all') %> +
+<% end %> <% if @message_alls.count >0 %> <%# 课程消息 %> <% unless @message_alls.nil? %> diff --git a/db/migrate/20150829024549_course_messages.rb b/db/migrate/20150829024549_course_messages.rb index 666ccdaeb..34f4e9ef2 100644 --- a/db/migrate/20150829024549_course_messages.rb +++ b/db/migrate/20150829024549_course_messages.rb @@ -3,6 +3,7 @@ class CourseMessages < ActiveRecord::Migration def up Course.all.each do |course| transaction do + put course.id course.course_messages << CourseMessage.new(:user_id => course.tea_id,:course_id => course.id) # 作业 course.homework_commons.each do |homework_common| diff --git a/db/migrate/20150829081822_update_message_time.rb b/db/migrate/20150829081822_update_message_time.rb index fe670e9b8..09e42b6d1 100644 --- a/db/migrate/20150829081822_update_message_time.rb +++ b/db/migrate/20150829081822_update_message_time.rb @@ -11,6 +11,7 @@ class UpdateMessageTime < ActiveRecord::Migration cmessage.created_at = cmessage.course_message.created_on end cmessage.save + puts cmessage.id course_all_message = MessageAll.where("message_type = '#{cmessage.class.to_s}' and message_id = '#{cmessage.id}'").first course_all_message.created_at = cmessage.created_at diff --git a/db/migrate/20150829130302_update_forge_message_time.rb b/db/migrate/20150829130302_update_forge_message_time.rb index 70811c307..295cafea6 100644 --- a/db/migrate/20150829130302_update_forge_message_time.rb +++ b/db/migrate/20150829130302_update_forge_message_time.rb @@ -11,6 +11,7 @@ class UpdateForgeMessageTime < ActiveRecord::Migration fmessage.created_at = fmessage.forge_message.created_on end fmessage.save + puts fmessage.id forge_all_message = MessageAll.where("message_type = '#{fmessage.class.to_s}' and message_id = '#{fmessage.id}'").first forge_all_message.created_at = fmessage.created_at diff --git a/db/migrate/20150901004812_update_memo_message_time.rb b/db/migrate/20150901004812_update_memo_message_time.rb index e512282a0..80ae557fc 100644 --- a/db/migrate/20150901004812_update_memo_message_time.rb +++ b/db/migrate/20150901004812_update_memo_message_time.rb @@ -11,6 +11,7 @@ class UpdateMemoMessageTime < ActiveRecord::Migration memo_message.created_at = memo_message.memo.created_on end memo_message.save + puts memo_message.id memo_messages = MessageAll.where("message_type = '#{memo_message.class.to_s}' and message_id = '#{memo_message.id}'").first memo_messages.created_at = memo_message.created_at