From fea1cdff53d1331c233ed6909aaaa62abac34cd7 Mon Sep 17 00:00:00 2001 From: yanxd Date: Fri, 27 Dec 2013 13:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=97=B6=E9=97=B4=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=EF=BC=8C=E5=8F=AF=E8=83=BD=E4=BC=9A=E5=BC=95=E8=B5=B7?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E8=B0=83=E7=94=A8event=5Fdatetime=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82=E5=BE=85=E8=A7=82=E5=AF=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 1 + app/helpers/welcome_helper.rb | 13 ++++++++++++- app/models/forum.rb | 2 +- app/models/memo.rb | 3 ++- app/models/message.rb | 1 + 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index afa602d61..1baf5d62c 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -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]) diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index cce439d79..fc19ccaa0 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -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 diff --git a/app/models/forum.rb b/app/models/forum.rb index 3d4c3830d..aa7f16cd3 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -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', diff --git a/app/models/memo.rb b/app/models/memo.rb index 6841cc0fd..9b36cb726 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -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'}, diff --git a/app/models/message.rb b/app/models/message.rb index b9f71b0ab..2421a7d4f 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -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'},