diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index ba7b6284d..53090121e 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -96,38 +96,74 @@ class ForumsController < ApplicationController end def index - @offset, @limit = api_offset_and_limit({:limit => 10}) - @forums = Memo.all - + order = "" + @order_str = "" if(params[:reorder_complex]) - @type="reorder_complex" - @str=params[:reorder_complex] - @forums_all = Forum.reorder("topic_count #{params[:reorder_complex]},updated_at #{params[:reorder_complex]}") + order = " last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}" + @order_str = "reorder_complex="+params[:reorder_complex] elsif(params[:reorder_popu]) - @type="reorder_popu" - @str=params[:reorder_popu] - @forums_all = Forum.reorder("topic_count #{params[:reorder_popu]}") + order = "replies_count #{params[:reorder_popu]}" + @order_str = "reorder_popu="+params[:reorder_popu] elsif(params[:reorder_time]) - @type="reorder_time" - @str=params[:reorder_time] - @forums_all = Forum.reorder("updated_at #{params[:reorder_time]}") + order = "#{Memo.table_name}.updated_at #{params[:reorder_time]}" + @order_str = "reorder_time="+params[:reorder_time] else - params[:reorder_complex] = "desc" - @type="reorder_complex" - @str=params[:reorder_complex] - @forums_all = Forum.reorder("topic_count desc,updated_at desc") + order = "#{Memo.table_name}.updated_at desc" + @order_str = "reorder_time=desc" end - @forums_count = @forums_all.count - @forums_pages = Paginator.new @forums_count, @limit, params['page'] - - @offset ||= @forums_pages.offset - @forums = @forums_all.offset(@offset).limit(@limit).all - #@forums = Forum.all + @memo = Memo.new(:forum => @forum) + @topic_count = Memo.count + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @memos = Memo.includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + reorder(order). + preload(:author, {:last_reply => :author}). + all + @forums = Forum.includes(:memos).preload(:topics) + @my_topic_count = Memo.where("author_id = #{User.current.id} and parent_id is null").count + @my_replies_count = Memo.where("author_id = #{User.current.id} and parent_id is not null").count + @errors = params[:errors] respond_to do |format| - format.html{render :layout => 'base_new_forum'} format.js - format.json { render json: @forums } + format.html { + render :layout => 'base_new_forum' + }# show.html.erb + format.json { render json: @forum } end + + # @offset, @limit = api_offset_and_limit({:limit => 10}) + # @forums = Memo.all + # + # if(params[:reorder_complex]) + # @type="reorder_complex" + # @str=params[:reorder_complex] + # @forums_all = Forum.reorder("topic_count #{params[:reorder_complex]},updated_at #{params[:reorder_complex]}") + # elsif(params[:reorder_popu]) + # @type="reorder_popu" + # @str=params[:reorder_popu] + # @forums_all = Forum.reorder("topic_count #{params[:reorder_popu]}") + # elsif(params[:reorder_time]) + # @type="reorder_time" + # @str=params[:reorder_time] + # @forums_all = Forum.reorder("updated_at #{params[:reorder_time]}") + # else + # params[:reorder_complex] = "desc" + # @type="reorder_complex" + # @str=params[:reorder_complex] + # @forums_all = Forum.reorder("topic_count desc,updated_at desc") + # end + # @forums_count = @forums_all.count + # @forums_pages = Paginator.new @forums_count, @limit, params['page'] + # + # @offset ||= @forums_pages.offset + # @forums = @forums_all.offset(@offset).limit(@limit).all + # #@forums = Forum.all + # respond_to do |format| + # format.html{render :layout => 'base_new_forum'} + # format.js + # format.json { render json: @forums } + # end end # GET /forums/1 @@ -161,7 +197,7 @@ class ForumsController < ApplicationController reorder(order). preload(:author, {:last_reply => :author}). all - @memos + @forums = Forum.includes(:memos).preload(:topics) @my_topic_count = Memo.where("author_id = #{User.current.id} and parent_id is null").count @my_replies_count = Memo.where("author_id = #{User.current.id} and parent_id is not null").count @errors = params[:errors] @@ -200,18 +236,17 @@ class ForumsController < ApplicationController # Author lizanle # Description after save后需要进行资源记录的更新 # owner_type = 2 对应的是 forum - @save_flag=true + @save_flag = true if params[:asset_id] ids = params[:asset_id].split(',') - update_kindeditor_assets_owner ids ,@forum.id,OwnerTypeHelper::FORUM + update_kindeditor_assets_owner ids, @forum.id, OwnerTypeHelper::FORUM end #end respond_to do |format| - format.js + format.js{ redirect_to forums_path, notice: l(:label_forum_create_succ)} format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } format.json { render json: @forum, status: :created, location: @forum } end - else @save_flag=false respond_to do |format| diff --git a/app/views/forums/_new.html.erb b/app/views/forums/_new.html.erb index d195168f6..2feb28eb6 100644 --- a/app/views/forums/_new.html.erb +++ b/app/views/forums/_new.html.erb @@ -5,21 +5,30 @@