From f05d2131bd9d4955dd3a08cfb351664936e64e17 Mon Sep 17 00:00:00 2001 From: yanxd Date: Wed, 25 Dec 2013 15:40:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E7=95=99=E8=A8=80=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/words_controller.rb | 28 +++++--- app/helpers/words_helper.rb | 102 +++++++++++++++------------- app/models/journals_for_message.rb | 13 ++-- app/models/user.rb | 10 ++- 4 files changed, 89 insertions(+), 64 deletions(-) diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index ee4e24ac7..0f11cc5e3 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 #####leave message fq class WordsController < ApplicationController @@ -40,23 +41,30 @@ class WordsController < ApplicationController end def create_reply - find_user @params = params parent_id = params[:reference_id] author_id = User.current.id reply_user_id = params[:reference_user_id] - # reply_id = nil # 暂时不实现 + reply_id = nil # 暂时不实现 content = params[:user_notes] - @params.merge({flag:'====', parent_id: parent_id, author_id: author_id, reply_user_id: reply_user_id, content: content}) - JournalsForMessage.new( :user_id => author_id, - :m_parent_id => parent_id, - :reply_id => reply_user_id, - :notes => content, - :is_readed => false - ) + @params.merge!({flag:'====', parent_id: parent_id, author_id: author_id, reply_user_id: reply_user_id, content: content}) + options = {:user_id => author_id, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + jfm = User.current.add_jour(nil, nil, nil, options) respond_to do |format| - format.html {render 'test/index'} + format.html { + if jfm.errors.empty? + flash.notice = l(:label_feedback_success) + else + flash.errors = l(:label_feedback_fail) + end + render 'test/index' + } format.js end end diff --git a/app/helpers/words_helper.rb b/app/helpers/words_helper.rb index 167c78e2c..fb9d3264f 100644 --- a/app/helpers/words_helper.rb +++ b/app/helpers/words_helper.rb @@ -1,47 +1,57 @@ -########fq -module WordsHelper - def message_list(object, state, user) - unless state - if object.size > 5 - object = object[-5, 5] - end - end - object = object.reverse - remove_allowed = (User.current.id == object.first.user_id) - content = ''.html_safe - lis = object.each do |t_object| - s = ''.html_safe - s << link_to(t_object.indice, {}, :class => "journal-link") - s << avatar(t_object.user, :size => "16").to_s - s << link_to_user(t_object.user, :class => 'user') - time = time_tag(t_object.created_at) - s << l(:field_add, :time => time).html_safe - if !t_object.notes.blank? - s << link_to(image_tag('comment.png'), - {:controller => 'words', :action => 'new', :id => user, :journal_id => t_object}, - :remote => true, - :method => 'post', - :title => l(:button_quote)) - if remove_allowed || t_object.jour_id == User.current.id - url = {:controller => 'words', - :action => 'destroy', - :object_id => t_object, - :user_id => user} - s << ' ' - s << link_to(image_tag('delete.png'), url, - :remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete)) - end - end - #time = '更新于' + time_tag(t_object.created_at) + '之前' - - - # s << content_tag('div', time) - - content << content_tag('li', s, :class => "user-#{t_object.jour_id}") - content << textilizable(t_object.notes) - end - # content.present? ? content_tag('ul', content, :class => 'watchers') : content - content - end -end +########fq +module WordsHelper + def message_list(object, state, user) + unless state + if object.size > 5 + object = object[-5, 5] + end + end + object = object.reverse + remove_allowed = (User.current.id == object.first.user_id) + content = ''.html_safe + lis = object.each do |t_object| + s = ''.html_safe + s << link_to(t_object.indice, {}, :class => "journal-link") + s << avatar(t_object.user, :size => "16").to_s + s << link_to_user(t_object.user, :class => 'user') + time = time_tag(t_object.created_at) + s << l(:field_add, :time => time).html_safe + if !t_object.notes.blank? + s << link_to(image_tag('comment.png'), + {:controller => 'words', :action => 'new', :id => user, :journal_id => t_object}, + :remote => true, + :method => 'post', + :title => l(:button_quote)) + if remove_allowed || t_object.jour_id == User.current.id + url = {:controller => 'words', + :action => 'destroy', + :object_id => t_object, + :user_id => user} + s << ' ' + s << link_to(image_tag('delete.png'), url, + :remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete)) + end + end + #time = '更新于' + time_tag(t_object.created_at) + '之前' + + + # s << content_tag('div', time) + + content << content_tag('li', s, :class => "user-#{t_object.jour_id}") + content << textilizable(t_object.notes) + end + # content.present? ? content_tag('ul', content, :class => 'watchers') : content + content + end + + def fetch_user_leaveWord_reply leaveWordObj + if leaveWordObj.kind_of? JournalsForMessage + leaveWordObj.children + elsif leaveWordObj.kind_of? Fixnum + JournalsForMessage.find(leaveWordObj).children + else + [] + end + end +end \ No newline at end of file diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 1c28b815e..2c5b40c74 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -1,6 +1,6 @@ # fq # 数据库字段中带有m前缀和is_readed是二次开发添加,之前的字段基本复用 -# 注意reply_id 是提到人的id,不是留言id, Base中叫做ator +# 注意reply_id 是提到人的id,不是留言id, Base中叫做 at_user class JournalsForMessage < ActiveRecord::Base include Redmine::SafeAttributes safe_attributes "jour_type", # 留言所属类型 @@ -17,7 +17,7 @@ class JournalsForMessage < ActiveRecord::Base belongs_to :jour, :polymorphic => true belongs_to :user - belongs_to :ator, :class_name => "User", :foreign_key => 'reply_id' + 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 @@ -50,10 +50,11 @@ class JournalsForMessage < ActiveRecord::Base end def reset_counters! - self.class.reset_counters!(id) + self.class.reset_counters!(self) end - def self.reset_counters! journals_for_messages_id - jfm_id = journals_for_messages_id.to_i - update_all("m_reply_count = (SELECT COUNT(*) FROM #{JournalsForMssages.table_name} WHERE m_parent_id = #{jfm_id} )", ["id = ?", jfm_id]) + def self.reset_counters! journals_for_messages + # jfm_id = journals_for_messages.id.to_i + count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} ) + update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id]) end end diff --git a/app/models/user.rb b/app/models/user.rb index a0bca8040..3ee601b6a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -164,8 +164,14 @@ class User < Principal ###添加留言 fq - def add_jour(user, notes, reference_user_id = 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true) + def add_jour(user, notes, reference_user_id = 0, options = {}) + if options.count == 0 + self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true) + else + jfm = self.journals_for_messages.build(options) + jfm.save + jfm + end end # 判断用户是否加入了竞赛中 fq