完成功能:

1、添加“新的消息”分类
2、新注册用户默认点击时间
This commit is contained in:
huang 2015-09-07 16:08:04 +08:00
parent ecd0056f0a
commit 103d61056d
4 changed files with 27 additions and 5 deletions

View File

@ -106,6 +106,7 @@ class UsersController < ApplicationController
return return
end end
# 记录当前点击按钮的时间 # 记录当前点击按钮的时间
# 考虑到用户未退出刷新消息页面
if OnclickTime.where("user_id =?", User.current).first.nil? if OnclickTime.where("user_id =?", User.current).first.nil?
message_new_time = OnclickTime.new message_new_time = OnclickTime.new
message_new_time.user_id = User.current.id message_new_time.user_id = User.current.id
@ -132,10 +133,19 @@ class UsersController < ApplicationController
case params[:type] case params[:type]
when nil when nil
@message_alls = [] @message_alls = []
messages = MessageAll.where("user_id =?",@user).order("created_at desc") messages = MessageAll.where("user_id =?" ,@user).order("created_at desc")
messages.each do |message_all| messages.each do |message_all|
@message_alls << message_all.message @message_alls << message_all.message
end end
when 'unviewed'
@message_alls = []
messages = MessageAll.where("user_id =?", @user).order("created_at desc")
messages.each do |message_all|
# 在点击或者刷新消息列表后未读的消息存放在数组
if message_all.message.viewed == 0
@message_alls << message_all.message
end
end
when 'homework' when 'homework'
@message_alls = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc") @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc")
when 'course_message' when 'course_message'

View File

@ -52,6 +52,15 @@ module UsersHelper
end end
end end
# 统计未读消息数
def unviewed_message(user)
course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count
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
end
def user_mail_notification_options(user) def user_mail_notification_options(user)
user.valid_notification_options.collect {|o| [l(o.last), o.first]} user.valid_notification_options.collect {|o| [l(o.last), o.first]}
end end

View File

@ -1001,8 +1001,11 @@ class User < Principal
self.acts << Activity.new(:user_id => self.id) self.acts << Activity.new(:user_id => self.id)
end end
# 注册用户的时候消息默认点击时间为用户创建时间
def add_onclick_time def add_onclick_time
self.onclick_time << OnclickTime.new(:user_id => self.id, :onclick_time => self.created_on) if OnclickTime.where("user_id =?" , self.id).first.nil?
OnclickTime.create(:user_id => self.id, :onclick_time => self.created_on)
end
end end
# Removes references that are not handled by associations # Removes references that are not handled by associations

View File

@ -4,6 +4,7 @@
<li class="resourcesSelected"><a href="javascript:void(0);" class="resourcesIcon"></a> <li class="resourcesSelected"><a href="javascript:void(0);" class="resourcesIcon"></a>
<ul class="newsType"> <ul class="newsType">
<li><%= link_to "全部",user_message_path(User.current), :class => "resourcesGrey" %></li> <li><%= link_to "全部",user_message_path(User.current), :class => "resourcesGrey" %></li>
<li><%= link_to "未读消息", user_message_path(User.current, :type => 'unviewed'), :class => "resourcesGrey" %></li>
<%# 课程相关消息 %> <%# 课程相关消息 %>
<li><%= link_to "作业消息", user_message_path(User.current, :type => 'homework'), :class => "resourcesGrey" %></li> <li><%= link_to "作业消息", user_message_path(User.current, :type => 'homework'), :class => "resourcesGrey" %></li>
<li><%= link_to "课程讨论",user_message_path(User.current, :type => 'course_message'), :class => "resourcesGrey" %></li> <li><%= link_to "课程讨论",user_message_path(User.current, :type => 'course_message'), :class => "resourcesGrey" %></li>
@ -22,16 +23,15 @@
<li><%= link_to "贴吧帖子", user_message_path(User.current, :type => 'forum'), :class => "resourcesGrey" %></li> <li><%= link_to "贴吧帖子", user_message_path(User.current, :type => 'forum'), :class => "resourcesGrey" %></li>
<%# 系统贴吧 %> <%# 系统贴吧 %>
<li><%= link_to "用户留言",user_message_path(User.current, :type => 'user_feedback'), :class => "resourcesGrey" %></li> <li><%= link_to "用户留言",user_message_path(User.current, :type => 'user_feedback'), :class => "resourcesGrey" %></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</div> </div>
<div class="resources mt10" id="users_setting"> <div class="resources mt10" id="users_setting">
<div> <div>
<% if params[:type].nil? %> <% if params[:type].nil? || params[:type] == "unviewed" %>
<div class="newsReadSetting"> <div class="newsReadSetting">
有&nbsp;<span class="c_red"><%= User.current.count_new_message %></span>&nbsp;条未读<a href="javascript:void(0);" class="ml15"><%= link_to "全部设为已读", user_message_path(User.current, :viewed => 'all') %></a> 有&nbsp;<span class="c_red"><%= unviewed_message(@user) %></span>&nbsp;条未读<a href="javascript:void(0);" class="ml15"><%= link_to "全部设为已读", user_message_path(User.current, :viewed => 'all') %></a>
</div> </div>
<% end %> <% end %>
<% if @message_alls.count >0 %> <% if @message_alls.count >0 %>