diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 30dca1c2..ab8df148 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -57,7 +57,7 @@ class MemosController < ApplicationController pre_count = REPLIES_PER_PAGE @memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示 - @memo.update_attribute(:viewed_count, @memo.viewed_count.to_i + 1) + @memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1)) page = params[:page] if params[:r] && page.nil? @@ -95,11 +95,12 @@ class MemosController < ApplicationController def update respond_to do |format| - if( @memo.update_attribute(:subject, params[:memo][:subject]) && - @memo.update_attribute(:content, params[:memo][:content]) && - @memo.update_attribute(:sticky, params[:memo][:sticky]) && - @memo.update_attribute(:lock, params[:memo][:lock])) + if( @memo.update_column(:subject, params[:memo][:subject]) && + @memo.update_column(:content, params[:memo][:content]) && + @memo.update_column(:sticky, params[:memo][:sticky]) && + @memo.update_column(:lock, params[:memo][:lock])) @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads])) + # @memo.root.update_attribute(:updated_at, @memo.updated_at) format.html {redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}"} else format.html { render action: "edit" } diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index afa602d6..1baf5d62 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/controllers/words_controller.rb b/app/controllers/words_controller.rb index 7c05c5af..ce4523b2 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -73,10 +73,8 @@ class WordsController < ApplicationController end def destroy - if User.current.admin? || User.current.id == @user.id - JournalsForMessage.delete_message(params[:object_id]) - end - @jours = @user.journals_for_messages.reverse + @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) + @jours = @user.journals_for_messages.where('m_parent_id IS NULL').reverse @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index f862ce30..fc19ccaa 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -75,13 +75,13 @@ module WelcomeHelper str = ' '.html_safe case event.event_type when 'news' , 'issue', 'message' , 'bid' , 'wiki-page' , 'document' - str << content_tag("span", "发表了") << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url) + str << content_tag("span", "发表了") << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url, :target => "_blank" ) when 'reply' ,'Reply', 'Memo' - str << content_tag("span", "发表了") << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(truncate(strip_tags(event.event_description), length: 30, omission:'...'), event.event_url) + str << content_tag("span", "发表了") << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(truncate(strip_tags(event.event_description), length: 30, omission:'...'), event.event_url, :target => "_blank" ) when 'attachment' str << content_tag('span', '上传了') << content_tag('span', find_all_event_type(event)) << ': '.html_safe << link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url) << link_to((' ['.html_safe+l(:label_downloads_list).to_s << ']'), project_files_path(event.container)) else - str << content_tag("span", "更新了") << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url) + str << content_tag("span", "更新了") << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url, :target => "_blank" ) end str rescue Exception => e @@ -92,9 +92,9 @@ module WelcomeHelper str = "回复(" case event.event_type when "issue" - str << link_to(cal_issues_count(event), issue_path(event)) << ")" + str << link_to(cal_issues_count(event), issue_path(event), :target => "_blank" ) << ")" when "Memo" - str << link_to(cal_memos_count(event), forum_memo_path(event.forum_id,event.id)) << ")" + str << link_to(cal_memos_count(event), forum_memo_path(event.forum_id,event.id), :target => "_blank" ) << ")" else str = "" end @@ -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 @@ -135,7 +146,7 @@ module WelcomeHelper # } # user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )") activity = Redmine::Activity::Fetcher.new(nil) - activity.scope_select{|t| ['changesets'].include?(t) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' } + activity.scope_select{|t| ['changesets', 'documents'].include?(t) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' } activity.events_welcome(nil, nil, {:limit => limit, :types => 'welcome'}) end diff --git a/app/models/forum.rb b/app/models/forum.rb index 3d4c3830..aa7f16cd 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/journals_for_message.rb b/app/models/journals_for_message.rb index e00564f1..e83018be 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -20,7 +20,6 @@ class JournalsForMessage < ActiveRecord::Base belongs_to :at_user, :class_name => "User", :foreign_key => 'reply_id' has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy - has_many :reply_for_journals, :dependent => :destroy validates :notes, presence: true after_create :act_as_activity #huang @@ -30,7 +29,8 @@ class JournalsForMessage < ActiveRecord::Base # default_scope { where('m_parent_id IS NULL') } def self.delete_message(message_id) - self.delete_all "id = #{message_id}" + self.find(message_id).destroy + # self.destroy_all "id = #{message_id}" end def reference_user diff --git a/app/models/memo.rb b/app/models/memo.rb index 6841cc0f..31b412a4 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'}, @@ -64,6 +65,7 @@ class Memo < ActiveRecord::Base def reset_counters! if parent && parent.id Memo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id}) + parent.update_attribute(:updated_at, Time.now) end forum.reset_counters! end diff --git a/app/models/message.rb b/app/models/message.rb index b9f71b0a..2421a7d4 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'}, diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 8388b6ae..47662f25 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -2,7 +2,7 @@