From 5618fe067a4b02642decb0977c4998e0d0f609ca Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 29 Dec 2015 16:40:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=86=E9=A1=B5=EF=BC=8C?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/boards_controller.rb | 47 +++++-------------- .../boards/_project_show_detail.html.erb | 2 +- app/views/boards/show.js.erb | 6 ++- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 291593fc5..c8518e8a3 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -79,13 +79,12 @@ class BoardsController < ApplicationController end end end - + # 更新@消息为已读 @project.boards.each do |board| board.messages.each do |m| User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!} end end - elsif @course query_course_messages = @board.messages query_course_messages.each do |query_course_message| @@ -106,43 +105,19 @@ class BoardsController < ApplicationController @is_new = params[:is_new] @topic_count = @board ? @board.topics.count : 0 if @project - @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] - #现在发布帖子的时候置顶功能已经没有了。所以取消这个置顶排序 #{Message.table_name}.sticky DESC, - @topics = @board.topics. - reorder("#{Message.table_name}.created_on desc"). - includes(:last_reply). - limit(@topic_pages.per_page). - offset(@topic_pages.offset). - - preload(:author, {:last_reply => :author}). - all + if @board + limit = 10; + @topic_count = @board.topics.count(); + @topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10 + @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc"). + limit(limit).offset(@topic_pages).includes(:last_reply). + preload(:author, {:last_reply => :author}).all(); + else + @topics = []; + end elsif @course - # - # board_topics = @board ? @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc"). - # includes(:last_reply). - # # limit(@topic_pages.per_page). - # # offset(@topic_pages.offset). - # - # preload(:author, {:last_reply => :author}). - # all : [] - # @topics = paginateHelper board_topics,10 if (@board) limit = 10; - #pageno = params[:page]; - #if(pageno == nil || pageno=='') - # dw_topic = nil; - # if( params[:parent_id]!=nil && params[:parent_id]!='' ) - # dw_topic = @board.topics.where(id:params[:parent_id]).first(); - # end - # if( dw_topic != nil ) - # dw_count = @board.topics.where('(sticky>?) or (sticky=? and created_on>?)',dw_topic.sticky,dw_topic.sticky,dw_topic.created_on).count(); - # dw_count = dw_count+1; - # pageno = dw_count%10==0 ? (dw_count/limit) : (dw_count/limit+1) - # end - #end - #if(pageno == nil || pageno=='') - # pageno=1; - #end @topic_count = @board.topics.count(); @topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10 @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc"). diff --git a/app/views/boards/_project_show_detail.html.erb b/app/views/boards/_project_show_detail.html.erb index 6d77452a8..8fb663aff 100644 --- a/app/views/boards/_project_show_detail.html.erb +++ b/app/views/boards/_project_show_detail.html.erb @@ -59,7 +59,7 @@ <% if topics.count == 10 %> - <%= link_to "点击展开更多",boards_topic_path(@board, :course_id => @board.course.id ,:page => page),:id => "show_more_course_topic",:remote => "true",:class => "loadMore mt10 f_grey"%> + <%= link_to "点击展开更多", boards_topic_path(@board, :project_id => @board.project.id ,:page => page), :id => "show_more_project_topic",:remote => "true",:class => "loadMore mt10 f_grey"%> <% end %> <% end%> diff --git a/app/views/boards/show.js.erb b/app/views/boards/show.js.erb index c088abce5..c9208fd2c 100644 --- a/app/views/boards/show.js.erb +++ b/app/views/boards/show.js.erb @@ -1 +1,5 @@ -$("#show_more_course_topic").replaceWith("<%= escape_javascript( render :partial => 'boards/course_show_detail',:locals => {:topics => @topics, :page => @page} )%>"); \ No newline at end of file +<% if @course %> + $("#show_more_course_topic").replaceWith("<%= escape_javascript( render :partial => 'boards/course_show_detail',:locals => {:topics => @topics, :page => @page} )%>"); +<% else %> + $("#show_more_project_topic").replaceWith("<%= escape_javascript( render :partial => 'boards/project_show_detail',:locals => {:topics => @topics, :page => @page} )%>"); +<% end %> \ No newline at end of file