diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 3332f1207..75153c6de 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -96,36 +96,74 @@ class ForumsController < ApplicationController end def index - @offset, @limit = api_offset_and_limit({:limit => 10}) + 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 # index.html.erb 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 @@ -151,24 +189,23 @@ class ForumsController < ApplicationController @order_str = "reorder_time=desc" end @memo = Memo.new(:forum => @forum) - @topic_count = @forum.topics.count + @topic_count = Memo.count @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] - @memos = @forum.topics. - # reorder("#{Memo.table_name}.sticky DESC"). - includes(:last_reply). + @memos = @forum.topics.includes(:last_reply). limit(@topic_pages.per_page). offset(@topic_pages.offset). reorder(order). preload(:author, {:last_reply => :author}). all - @memos - @my_topic_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is null").count - @my_replies_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is not null").count + @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] + # 推荐贴吧 + @forums = Forum.where("id !=?", @forum.id).reorder("topic_count desc,updated_at desc").first(3) respond_to do |format| format.js format.html { - render :layout => 'base_forums' + render :layout => 'base_new_forum' }# show.html.erb format.json { render json: @forum } end @@ -178,9 +215,9 @@ class ForumsController < ApplicationController # GET /forums/new.json def new @forum = Forum.new - respond_to do |format| format.html # new.html.erb + format.js format.json { render json: @forum } end end @@ -200,18 +237,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/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 69a1b829c..fd0ef9865 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -29,30 +29,23 @@ class MemosController < ApplicationController def new @memo = Memo.new - @memo.forum_id = @forum.id - + @my_forums_count = Forum.where(:creator_id => User.current.id).count + @my_memos_count = Memo.where(:author_id => User.current.id).count + @forums = Forum.reorder("topic_count desc,updated_at desc") respond_to do |format| - format.html { - render action: :new ,layout: 'base' - } + format.js + format.html {render layout: 'base_new_forum'} format.json { render json: @memo } end end def create - if params[:quote].nil? @quote = "" else @quote = params[:quote] end - - - #unless params[:quote].nil? - # @quote = params[:quote][:quote] - #end - @memo = Memo.new(params[:memo]) @memo.forum_id = params[:forum_id] @memo.author_id = User.current.id @@ -78,17 +71,14 @@ class MemosController < ApplicationController asset.save end end - #end - format.js - format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } - format.json { render json: @memo, status: :created, location: @memo } + format.js + format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } + format.json { render json: @memo, status: :created, location: @memo } else flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" format.js format.html { redirect_to( forum_path(Forum.find(params[:forum_id]),:errors=>@memo.errors.full_messages[0])) } format.json { render json: @memo.errors, status: :unprocessable_entity } - #end - end end end @@ -148,7 +138,7 @@ class MemosController < ApplicationController respond_to do |format| format.js - format.html {render :layout=> 'base_forums'}#:layout=> 'base_forums', + format.html {render :layout => 'base_new_forum'} format.json { render json: @memo } format.xml { render xml: @memo } end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a69442297..0d9694ac1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,6 +37,16 @@ module ApplicationHelper # super # end + # 公共分页 + def paginator_list objs, objs_count, limit, is_remote + @is_remote = is_remote + @objs_count = objs.count + @obj_pages = Paginator.new @objs_count, limit, params['page'] || 1 + @offset ||= @obj_pages.offset + @objs = paginateHelper @attachments,25 + end + + # 获取竞赛的管理人员 def contest_managers contest contest.contest_members.select{|cm| cm.roles.to_s.include?("ContestManager")} diff --git a/app/views/forums/_file_form.html.erb b/app/views/forums/_file_form.html.erb index 9bbbc9188..cbb53c2cc 100644 --- a/app/views/forums/_file_form.html.erb +++ b/app/views/forums/_file_form.html.erb @@ -47,7 +47,8 @@ <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> <%#= button_tag "文件浏览", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'AnnexBtn fl mt3' %> - 上传附件 + <%= button_tag "上传附件", :id => "upload_attachments", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'sub_btn' %> + <%= file_field_tag 'attachments[dummy][file]', :id => '_file', :class => 'file_selector', diff --git a/app/views/forums/_my_count_message.html.erb b/app/views/forums/_my_count_message.html.erb new file mode 100644 index 000000000..dfb9a5b12 --- /dev/null +++ b/app/views/forums/_my_count_message.html.erb @@ -0,0 +1,16 @@ +