hot memo merged board/topic.

This commit is contained in:
yanxd 2013-12-06 11:19:15 +08:00
parent 16fd02abc0
commit d29154cc24
3 changed files with 16 additions and 38 deletions

View File

@ -19,18 +19,6 @@
module WelcomeHelper
# def newbieTopiclist
# find_all_topic_by_board_id
# end
# def newbieTopicStickyList
# find_all_topic_by_board_id 1
# end
# def find_project_by_topic topic
# board = find_board_by_topic(topic)
# find_project_by_board board
# end
def find_all_hot_project
sort_project_by_hot
end
@ -104,25 +92,6 @@ module WelcomeHelper
private
# def search_project
# Project.find_by_identifier "newbie_faq"
# end
# def find_all_topic_by_board_id sticky = 0, limit = 30
# project = search_project
# return [] if(project.nil? or project.boards.nil?)
# board_id = project.boards.first.id
# logger.debug "[WelcomeHelper] ===> find_all_topic_by_board_id=> project.id:#{project.id}, board_id:#{board_id}, sticky:#{sticky}"
# Message.where("board_id = :board_id and sticky=:sticky", :board_id => board_id, :sticky => sticky ).limit(limit)
# end
# def find_board_by_topic topic
# Board.find_by_id(topic.board_id)
# end
# def find_project_by_board board
# Project.find_by_id(board.project_id)
# end
def sort_project_by_hot
sort_project_by_hot_rails 0, 'grade DESC'
end
@ -148,14 +117,12 @@ module WelcomeHelper
# }
# user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )")
activity = Redmine::Activity::Fetcher.new(nil)
logger.debug "[WelcomeHelper] ===> activity::#{activity.event_types}"
activity.events_welcome(nil, nil, {:limit => limit, :types => 'welcome'})
end
#取得论坛数据
def find_hot_forum_topics limit=9
#Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit)
Memo.order('replies_count DESC, created_at DESC').where('parent_id IS NULL').limit(limit)
## 以下语句会内链接自身查询出最后一条回复时间,没有回复的帖子不会显示
# Memo.find_by_sql("
# SELECT memos.*, reply.created_at AS last_reply_date FROM memos AS memos
@ -164,6 +131,13 @@ module WelcomeHelper
# WHERE memos.parent_id IS NULL
# ORDER BY memos.replies_count DESC, memos.created_at DESC
# LIMIT #{limit}")
#Memo.order('replies_count DESC').where('replies_count <> 0').limit(limit)
resultSet = Memo.order('replies_count DESC, created_at DESC').where('parent_id IS NULL').limit(limit)
resultSet += Message.order('replies_count DESC, created_on DESC').where('parent_id IS NULL').limit(limit)
resultSet.sort! {|x,y| (y.replies_count <=> x.replies_count).nonzero? || (y.event_datetime <=> x.event_datetime)}
resultSet.take(limit)
end
def sort_project_by_hot_rails project_type=0, order_by='grade DESC', limit=15

View File

@ -33,13 +33,15 @@ class Message < ActiveRecord::Base
:date_column => "#{table_name}.created_on"
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
:description => :content,
:datetime => :created_on,
:group => :parent,
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
{:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})}
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
:author_key => :author_id
:author_key => :author_id,
:timestamp => :created_on
acts_as_watchable
validates_presence_of :board, :subject, :content

View File

@ -137,13 +137,15 @@
<% find_hot_forum_topics.each do |topic|%>
<li class="message-brief-intro" style="min-height: 25px;">
<div style="display: inline-block; width: 100%;">
<span style="color:gray; display: inline-block; background: url('/images/list-icon.png') no-repeat scroll ;background-position: left center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= link_to topic.subject.truncate(30, omission: '...'), forum_memo_path(topic.forum_id,topic.id), :class => "gray" , :style => "font-size: 10pt !important;"%></span>
<span style="color:gray; display: inline-block; background: url('/images/list-icon.png') no-repeat scroll ;background-position: left center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%= link_to topic.subject.truncate(30, omission: '...'), topic.event_url, :class => "gray" , :style => "font-size: 10pt !important;"%>
</span>
<br>
<span style="margin-left: 20px; color: rgb(172, 174, 177); white-space: nowrap; font-size 9pt !important;;"><%= time_tag_welcome topic.created_at %>前</span>
<span style="margin-left: 20px; color: rgb(172, 174, 177); white-space: nowrap; font-size 9pt !important;;"><%= time_tag_welcome topic.event_datetime %>前</span>
<span style="margin-left: 5px; color: rgb(172, 174, 177) !important; white-space: nowrap;">
由<%= link_to topic.author, user_path(topic.author), :style => "font-size: 9pt !important; color: rgb(17, 102, 173);"%>发表
</span>
<span style="float: right; color: rgb(172, 174, 177); white-space: nowrap; font-size 9pt !important;;">回复(<%= link_to topic.replies_count, forum_memo_path(topic.forum_id,topic.id) %>)</span>
<span style="float: right; color: rgb(172, 174, 177); white-space: nowrap; font-size 9pt !important;;">回复(<%= link_to topic.replies_count, topic.event_url %>)</span>
</div>
</li>
<% end %>