Merge branch 'dev_hjq' of http://repository.trustie.net/xianbo/trustie2 into dev_hjq
This commit is contained in:
commit
550b263c2c
|
@ -106,6 +106,7 @@ class UsersController < ApplicationController
|
|||
return
|
||||
end
|
||||
# 记录当前点击按钮的时间
|
||||
# 考虑到用户未退出刷新消息页面
|
||||
if OnclickTime.where("user_id =?", User.current).first.nil?
|
||||
message_new_time = OnclickTime.new
|
||||
message_new_time.user_id = User.current.id
|
||||
|
@ -132,10 +133,19 @@ class UsersController < ApplicationController
|
|||
case params[:type]
|
||||
when nil
|
||||
@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|
|
||||
@message_alls << message_all.message
|
||||
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'
|
||||
@message_alls = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc")
|
||||
when 'course_message'
|
||||
|
|
|
@ -52,6 +52,15 @@ module UsersHelper
|
|||
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)
|
||||
user.valid_notification_options.collect {|o| [l(o.last), o.first]}
|
||||
end
|
||||
|
|
|
@ -1001,8 +1001,11 @@ class User < Principal
|
|||
self.acts << Activity.new(:user_id => self.id)
|
||||
end
|
||||
|
||||
# 注册用户的时候消息默认点击时间为用户创建时间
|
||||
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
|
||||
|
||||
# Removes references that are not handled by associations
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<li class="resourcesSelected"><a href="javascript:void(0);" class="resourcesIcon"></a>
|
||||
<ul class="newsType">
|
||||
<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 => 'course_message'), :class => "resourcesGrey" %></li>
|
||||
|
@ -22,19 +23,21 @@
|
|||
<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>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="resources mt10" id="users_setting">
|
||||
<div>
|
||||
<% if params[:type].nil? %>
|
||||
<div class="newsReadSetting">
|
||||
有 <span class="c_red"><%= User.current.count_new_message %></span> 条未读<a href="javascript:void(0);" class="ml15"><%= link_to "全部设为已读", user_message_path(User.current, :viewed => 'all') %></a>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if @message_alls.count >0 %>
|
||||
<% if params[:type].nil? || params[:type] == "unviewed" %>
|
||||
<div class="newsReadSetting">
|
||||
有 <span class="c_red"><%= unviewed_message(@user) %></span> 条未读
|
||||
<% unless unviewed_message(@user) == 0 %>
|
||||
<a href="javascript:void(0);" class="ml15"><%= link_to "全部设为已读", user_message_path(User.current, :viewed => 'all') %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%# 课程消息 %>
|
||||
<% unless @message_alls.nil? %>
|
||||
<% @message_alls.each do |ma| %>
|
||||
|
|
Loading…
Reference in New Issue