From f3ce91869949c2d3d82f89ccc5b1b6b0f02807d0 Mon Sep 17 00:00:00 2001 From: nieguanghui Date: Tue, 24 Dec 2013 16:42:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=99=E8=A8=80=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/words_controller.rb | 38 +++++ app/models/journals_for_message.rb | 3 +- app/models/reply_for_journal.rb | 4 + app/models/user.rb | 7 +- app/views/layouts/base_users.html.erb | 10 -- app/views/words/_message.html.erb | 19 ++- app/views/words/_new_respond.html.erb | 8 + app/views/words/new.js.erb | 1 + config/routes.rb | 1 + ...sing_attribute_to_journals_for_messages.rb | 8 + db/schema.rb | 143 +++++++++++++----- 11 files changed, 181 insertions(+), 61 deletions(-) create mode 100644 app/models/reply_for_journal.rb create mode 100644 app/views/words/_new_respond.html.erb create mode 100644 db/migrate/20131224021723_add_missing_attribute_to_journals_for_messages.rb diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 113adecc5..7198fc5ac 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -39,6 +39,44 @@ class WordsController < ApplicationController end end + def create_reply + if params[:new_form][:user_message].size>0 + unless params[:user_id].nil? + if params[:reference_content] + message = params[:new_form][:user_message] + "\n" + params[:reference_content] + else + message = params[:new_form][:user_message] + end + refer_user_id = params[:new_form][:reference_user_id].to_i + + # @user.add_jour(User.current, message, params[:object_id]) + @user.add_reply(params[:object_id], @user.current, message) + unless refer_user_id == 0 || refer_user_id == User.current.id + User.find(refer_user_id).add_jour(User.current, message, refer_user_id) + end + @user.count_new_jour + # if a_message.size > 5 + # @message = a_message[-5, 5] + # else + # @message = a_message + # end + # @message_count = a_message.count + end + end + @jours = @user.journals_for_messages.reverse + @limit = 10 + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] + + respond_to do |format| + # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} + format.js + #format.api { render_api_ok } + end + end + def destroy if User.current.admin? || User.current.id == @user.id JournalsForMessage.delete_message(params[:object_id]) diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index bb03ad121..e4e9164d6 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -6,6 +6,7 @@ class JournalsForMessage < ActiveRecord::Base belongs_to :jour, :polymorphic => true belongs_to :user has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy + has_many :reply_for_journals, :dependent => :destroy after_create :act_as_activity #huang def self.delete_message(message_id) @@ -24,7 +25,7 @@ class JournalsForMessage < ActiveRecord::Base def act_as_activity if self.jour_type == 'Principal' - unless self.user_id == self.jour.id && self.user_id != self.reply_id && self.reply_id !=0 + unless self.user_id == self.jour.id && self.user_id != self.reply_id && self.reply_id != 0 self.acts << Activity.new(:user_id => self.user_id) end end diff --git a/app/models/reply_for_journal.rb b/app/models/reply_for_journal.rb new file mode 100644 index 000000000..0ea6a04c7 --- /dev/null +++ b/app/models/reply_for_journal.rb @@ -0,0 +1,4 @@ +class ReplyForJournal < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :journals_for_messages +end diff --git a/app/models/user.rb b/app/models/user.rb index 6b1ee3d1b..a0bca8040 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -204,7 +204,12 @@ class User < Principal def count_new_jour count = self.new_jours.count end - + + #added by nie + def count_new_journal_reply + count = self.journal_reply.count + end + def set_mail_notification ##add byxianbo thread=Thread.new do diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index 33b296bfb..e829aec08 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -67,14 +67,10 @@ -
<%= link_to l(:label_user_watcher)+"("+User.watched_by(@user.id).count.to_s+")" ,:controller=>"users", :action=>"user_watchlist"%>   - <%= link_to l(:label_x_user_fans, :count => User.current.watcher_users(User.current.id).count)+"("+@user.watcher_users(@user.id).count.to_s+")", :controller=>"users", :action=>"user_fanslist" %>  - <%= link_to l(:label_requirement_focus)+"("+Bid.watched_by(@user).where('reward_type = ?', 1).count.to_s+")" ,:controller=>"users", :action=>"watch_bids"%>   - <% if @user.id == User.current.id %>

@@ -89,9 +85,7 @@