From bfd4ee86eca2c2ddbdefe079883be5c2bc1ce02a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 28 Sep 2017 15:28:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E7=BA=A7=E5=9B=9E=E5=A4=8D=E4=B8=8E?= =?UTF-8?q?=E7=82=B9=E8=B5=9E=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/forums_controller.rb | 11 +- app/controllers/memos_controller.rb | 51 ++- app/views/forums/index.html.erb | 16 +- app/views/memos/_common_reply_box.html.erb | 112 +++++++ app/views/memos/_memo_all_replies.html.erb | 122 +++++--- app/views/memos/create.js.erb | 2 +- app/views/memos/message_replies.js.erb | 9 + app/views/memos/show.html.erb | 295 +++++++++++------- .../praise_tread/_activity_praise.html.erb | 10 +- app/views/praise_tread/_edu_praise.html.erb | 10 +- app/views/praise_tread/praise_minus.js.erb | 2 + app/views/praise_tread/praise_plus.js.erb | 6 +- config/routes.rb | 2 + 13 files changed, 461 insertions(+), 187 deletions(-) create mode 100644 app/views/memos/_common_reply_box.html.erb create mode 100644 app/views/memos/message_replies.js.erb diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index a8d3adb0a..ab17acb3f 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -185,13 +185,10 @@ class ForumsController < ApplicationController end @memo = Memo.new(:forum => @forum) @topic_count = @forum.topics.count - @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] - @memos = @forum.topics.includes(:last_reply). - limit(@topic_pages.per_page). - offset(@topic_pages.offset). - reorder(order). - preload(:author, {:last_reply => :author}). - all + @limit = 20 + @is_remote = true + @topic_pages = Paginator.new @topic_count, @limit, params['page'] || 1 + @memos = paginateHelper @forum.topics.includes(:last_reply).reorder(order).preload(:author, {:last_reply => :author}), @limit @my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and parent_id is null").count @my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and parent_id is not null").count @errors = params[:errors] diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 7f4c1d48e..047d7bd9b 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -1,6 +1,6 @@ class MemosController < ApplicationController default_search_scope :memos - before_filter :find_forum, :only => [:new, :create, :preview, :update] + before_filter :find_forum, :only => [:new, :create, :preview, :update, :reply] before_filter :find_attachments, :only => [:preview] before_filter :find_memo, :except => [:new, :create, :preview] before_filter :authenticate_user_edit, :only => [:edit, :update] @@ -88,6 +88,7 @@ class MemosController < ApplicationController REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE) def show + @user = User.current # 更新贴吧帖子留言对应的memo_messages的viewed字段 unless @memo.children.blank? @memo.children.each do |child| @@ -141,7 +142,7 @@ class MemosController < ApplicationController respond_to do |format| format.js - format.html {render :layout => 'base_new_forum'} + format.html {render :layout => 'base_edu'} format.json { render json: @memo } format.xml { render xml: @memo } end @@ -182,6 +183,52 @@ class MemosController < ApplicationController end end + def reply + if params[:parent_id] + parent = Memo.find params[:memo][:parent_id] + @memo = params[:activity_id].blank? ? parent : Memo.find(params[:activity_id].to_i) + @reply = Memo.new + @reply.author = User.current + @reply.forum_id = parent.forum_id + @reply.content = params[:memo][:content] + @reply.subject = "RE: #{@memo.subject}" + #@reply.reply_id = params[:id] + @reply.root_id = parent.root_id.nil? ? parent.id : parent.root_id + # @reply.reply_id = params[:id] + parent.children << @reply + else + @reply = Memo.new() + @reply.content = params[:content] + @reply.subject = @memo.subject + @reply.author = User.current + @reply.forum_id = @forum.id + #@reply.content = @quote + @reply.content + #@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] + @reply.root_id = @memo.id + @reply.safe_attributes = params[:reply] + @memo.children << @reply + # @reply.reply_id = params[:id] + end + + redirect_to message_replies_forum_memo_path(@memo.forum, @memo) + end + + def message_replies + @replies = Memo.where(:root_id => @memo.id).order("created_at desc") + @reply_count = @replies.count + @replies = get_no_children_comments_all @replies + #@limit_count = @replies.count + #@page = params[:page] ? params[:page].to_i + 1 : 0 + #@limit = 10 + #@replies = @replies[@page * @limit..@page * @limit + 9] + @reply = Message.new() + @user_activity_id = params[:user_activity_id].blank? ? @memo.id : params[:user_activity_id].to_i + respond_to do |format| + format.js + end + + end + def destroy @memo.destroy diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index f8dfd5fd1..dfc448213 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -29,11 +29,13 @@
+
+ <%= image_tag(url_to_avatar(memo.author), :width => 50, :height => 50,:alt=>'用户头像', :class=>"bor-radius-all mt3" ) %>
+
- <%= memo.subject %> + <%= memo.subject %>
<%= memo.content %>
@@ -46,7 +48,7 @@
+ <% if comment.creator_user == User.current %> + 删除 + <% end %> + | + <%= link_to( + '回复'.html_safe, + {:controller => 'users' ,:action => 'reply_to',:reply_id => comment.id, :type => memo.class.to_s, :user_activity_id => memo.id}, + :remote => true, + :method => 'get', + :title => l(:button_reply),:class => "color-grey") %> + | + + <%=render :partial=> "praise_tread/edu_praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + +
+