parent
c2650e6359
commit
0064aa4278
|
@ -112,10 +112,17 @@ class UsersController < ApplicationController
|
|||
case params[:type]
|
||||
when nil
|
||||
@message_alls = []
|
||||
messages = MessageAll.where("user_id =?" ,@user).order("created_at desc")
|
||||
system_message_types = MessageAll.where("message_type =?", "SystemMessage")
|
||||
messages = MessageAll.where("user_id =? and message_type !=?" ,@user, "SystemMessage")
|
||||
messages.each do |message_all|
|
||||
@message_alls << message_all.message
|
||||
end
|
||||
# 系统消息需要给每个人发送,之所以这样做,可以避免遍历系统所有用户
|
||||
system_message_types.each do |system_message_type|
|
||||
@message_alls << system_message_type.message
|
||||
end
|
||||
# 取出所有符合条件的按照创建时间排序
|
||||
@message_alls = @message_alls.sort {|a,b| b.created_at <=> a.created_at}
|
||||
when 'unviewed'
|
||||
@message_alls = []
|
||||
messages = MessageAll.where("user_id =?", @user).order("created_at desc")
|
||||
|
@ -187,12 +194,8 @@ class UsersController < ApplicationController
|
|||
message_new_time.onclick_time = Time.now
|
||||
message_new_time.save
|
||||
else
|
||||
# 24小时内显示
|
||||
contrast_time = Time.now - 86400
|
||||
message_time.update_attributes(:onclick_time => Time.now)
|
||||
end
|
||||
# 24小时内显示系统消息
|
||||
@user_system_messages = SystemMessage.where("created_at >?", contrast_time).order("created_at desc")
|
||||
end
|
||||
|
||||
# 消息设置为已读
|
||||
|
|
|
@ -5,4 +5,15 @@ class SystemMessage < ActiveRecord::Base
|
|||
validates :subject, presence: true
|
||||
# validates :description, presence: true
|
||||
validates_length_of :description, maximum: 10000
|
||||
|
||||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
||||
|
||||
# 系统消息放置总消息列表
|
||||
after_create :add_system_message
|
||||
|
||||
def add_system_message
|
||||
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<% if ma.class == SystemMessage %>
|
||||
<%# @user_system_messages.each do |usm| %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<li class="homepageNewsPortrait fl">
|
||||
<a href="javascript:void(0);"><div class="navHomepageLogo fl"><%= image_tag("/images/logo.png", width: "30px", height: "30px", class: "mt3") %></div></a>
|
||||
</li>
|
||||
<li class="homepageNewsPubType fl">
|
||||
<span class="newsBlue homepageNewsPublisher">Trustie平台</span><span class="homepageNewsType fl">发布新消息:</span>
|
||||
</li>
|
||||
<span style="color: red;float: left">【系统消息】</span>
|
||||
<li class="homepageSystenMessageContent fl">
|
||||
|
||||
<%= link_to ma.subject.blank? ? (ma.content.nil? ? ma.description.html_safe : ma.content.html_safe) : ma.subject, user_system_messages_path(User.current),
|
||||
:id => "content_link_#{ma.id}",
|
||||
:onmouseover =>"message_titile_show($(this),event);",
|
||||
:onmouseout => "message_titile_hide($(this));"
|
||||
%>
|
||||
</li>
|
||||
<div style="display:none;" class="message_title_red system_message_style">
|
||||
<% unless ma.subject.blank? %>
|
||||
<p><strong>标题:</strong><%= ma.subject %></p>
|
||||
<% end %>
|
||||
<% if (!ma.description.blank?) || (!ma.content.blank?) %>
|
||||
<div class="fl"><strong>内容:</strong></div><div class="ml36"><%= ma.description.nil? ? ma.content.html_safe : ma.description.html_safe %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||
</ul>
|
||||
<%# end %>
|
||||
<% end %>
|
|
@ -41,40 +41,13 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%# 系统消息 %>
|
||||
<% if params[:type] != 'system_messages' %>
|
||||
<% @user_system_messages.each do |usm| %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<li class="homepageNewsPortrait fl">
|
||||
<a href="javascript:void(0);"><div class="navHomepageLogo fl"><%= image_tag("/images/logo.png", width: "30px", height: "30px", class: "mt3") %></div></a>
|
||||
</li>
|
||||
<li class="homepageNewsPubType fl">
|
||||
<span class="newsBlue homepageNewsPublisher">Trustie平台</span><span class="homepageNewsType fl">发布新消息:</span>
|
||||
</li>
|
||||
<span style="color: red;float: left">【系统消息】</span>
|
||||
<li class="homepageSystenMessageContent fl">
|
||||
|
||||
<%= link_to usm.subject.blank? ? (usm.content.nil? ? usm.description.html_safe : usm.content.html_safe) : usm.subject, user_system_messages_path(User.current),
|
||||
:id => "content_link_#{usm.id}",
|
||||
:onmouseover =>"message_titile_show($(this),event);",
|
||||
:onmouseout => "message_titile_hide($(this));"
|
||||
%>
|
||||
</li>
|
||||
<div style="display:none;" class="message_title_red system_message_style">
|
||||
<% unless usm.subject.blank? %>
|
||||
<p><strong>标题:</strong><%= usm.subject %></p>
|
||||
<% end %>
|
||||
<% if (!usm.description.blank?) || (!usm.content.blank?) %>
|
||||
<div class="fl"><strong>内容:</strong></div><div class="ml36"><%= usm.description.nil? ? usm.content.html_safe : usm.description.html_safe %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<li class="homepageNewsTime fl"><%= time_tag(usm.created_at).html_safe %> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<!--总消息列表-->
|
||||
<% unless @message_alls.nil? %>
|
||||
<% @message_alls.each do |ma| %>
|
||||
<%# 系统消息 %>
|
||||
<%= render :partial => 'users/user_message_system', :locals => {:ma => ma} %>
|
||||
|
||||
<%# 课程消息 %>
|
||||
<%= render :partial => 'users/user_message_course', :locals => {:ma => ma} %>
|
||||
|
||||
|
|
Loading…
Reference in New Issue