首页时间排序,可能会引起其他调用event_datetime的问题。待观察

This commit is contained in:
yanxd 2013-12-27 13:54:57 +08:00
parent e12922544a
commit fea1cdff53
5 changed files with 17 additions and 3 deletions

View File

@ -79,6 +79,7 @@ class MessagesController < ApplicationController
@reply.board = @board
@reply.safe_attributes = params[:reply]
@topic.children << @reply
@topic.update_attribute(:updated_on, Time.now)
if !@reply.new_record?
call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
attachments = Attachment.attach_files(@reply, params[:attachments])

View File

@ -102,10 +102,21 @@ module WelcomeHelper
end
def find_new_forum_topics limit=7
Memo.where('memos.parent_id IS NULL').reorder('memos.created_at DESC').limit(limit)
# Memo.where('memos.parent_id IS NULL').reorder('memos.created_at DESC').limit(limit)
# activity = Redmine::Activity::Fetcher.new(nil)
# activity.scope=['memos']
# activity.events_welcome(nil, nil, {:limit => limit})
# resultSet = Memo.where('memos.parent_id IS NULL').includes(:last_reply).order('COALESCE (last_replies_memos.created_at, memos.created_at) DESC').limit(limit)
# resultSet += Message.where('messages.parent_id IS NULL').includes(:last_reply).order('COALESCE (last_replies_messages.created_on, messages.created_on) DESC').limit(limit)
resultSet = Memo.where('parent_id IS NULL').order('updated_at DESC').limit(limit)
resultSet += Message.where('parent_id IS NULL').order('updated_on DESC').limit(limit)
# resultSet = resultSet.to_a
resultSet.sort! {|x,y| y.event_datetime <=> x.event_datetime}
# for i in 0..(resultSet.size-1)
# resultSet[i] = resultSet[i].parent if resultSet[i].parent
# end
resultSet.take(limit)
end
private

View File

@ -1,6 +1,6 @@
class Forum < ActiveRecord::Base
include Redmine::SafeAttributes
has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC"
has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy
has_many :memos, :dependent => :destroy
belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id'
safe_attributes 'name',

View File

@ -17,7 +17,8 @@ class Memo < ActiveRecord::Base
# #:project_key => "#{Forum.table_name}.project_id"
# :date_column => "#{table_name}.created_at"
acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"},
:datetime => :created_at,
:datetime => :updated_at,
# :datetime => :created_at,
:description => :content,
:author => :author,
:type => Proc.new {|o| o.parent_id.nil? ? 'Memo' : 'Reply'},

View File

@ -33,6 +33,7 @@ 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 => :updated_on,
# :datetime => "#{Message.table_name}.created_on",
:group => :parent,
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},