From ebb7ed1f1a1000b4265b54fcf6477b0bf5070e41 Mon Sep 17 00:00:00 2001 From: cxt Date: Mon, 12 Oct 2015 17:19:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=8C=BA=E5=8D=95=E4=B8=AA?= =?UTF-8?q?=E5=B8=96=E5=AD=90=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BA=8C=E7=BA=A7?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/boards_controller.rb | 121 ++++++++++--------- app/views/boards/_course_show.html.erb | 28 ++--- app/views/boards/show.html.erb | 17 ++- app/views/boards/show.js.erb | 1 + app/views/messages/_course_show.html.erb | 75 +++++++++--- app/views/messages/_course_show_old.html.erb | 117 ++++++++++++++++++ app/views/messages/_form_course.html.erb | 28 +++-- app/views/messages/_reply_message.html.erb | 34 ++++++ app/views/messages/quote.js.erb | 12 +- config/routes.rb | 7 +- public/stylesheets/courses.css | 5 +- public/stylesheets/new_user.css | 2 +- public/stylesheets/public.css | 2 +- 13 files changed, 331 insertions(+), 118 deletions(-) create mode 100644 app/views/boards/show.js.erb create mode 100644 app/views/messages/_course_show_old.html.erb create mode 100644 app/views/messages/_reply_message.html.erb diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 434ea4470..62f39c04e 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -90,65 +90,66 @@ class BoardsController < ApplicationController end end end + + sort_init 'updated_on', 'desc' + sort_update 'created_on' => "#{Message.table_name}.created_on", + 'replies' => "#{Message.table_name}.replies_count", + 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" + + @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 + 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, #{Message.table_name}.created_on desc"). + limit(limit).offset(@topic_pages).includes(:last_reply). + preload(:author, {:last_reply => :author}).all(); + else + @topics = []; + end + end + + @message = Message.new(:board => @board) + #modify by nwb respond_to do |format| format.js format.html { - sort_init 'updated_on', 'desc' - sort_update 'created_on' => "#{Message.table_name}.created_on", - 'replies' => "#{Message.table_name}.replies_count", - 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" - - @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 - 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 = Paginator.new @topic_count, limit, pageno - @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc"). - limit(limit).offset(@topic_pages.offset).includes(:last_reply). - preload(:author, {:last_reply => :author}).all(); - else - @topics = []; - end - end - - @message = Message.new(:board => @board) - #modify by nwb if @project render :action => 'show', :layout => 'base_projects' elsif @course @@ -158,10 +159,10 @@ class BoardsController < ApplicationController } format.atom { @messages = @board.messages. - reorder('created_on DESC'). - includes(:author, :board). - limit(Setting.feeds_limit.to_i). - all + reorder('created_on DESC'). + includes(:author, :board). + limit(Setting.feeds_limit.to_i). + all if @project render_feed(@messages, :title => "#{@project}: #{@board}") elsif @course diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 1dd8c655a..871aa7e39 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -17,18 +17,9 @@ $("#Container").css("width","1000px"); }); -
-
-
- <% if User.current.language == "zh"%> - <%= h @board.name %> - <% else %> - <%= l(:project_module_boards) %> - <% end %> -
-
- <% @topics.each do |topic| if @topics %> + <% if topics%> + <% topics.each do |topic| %> diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb index a9c0e9101..6005f9258 100644 --- a/app/views/boards/show.html.erb +++ b/app/views/boards/show.html.erb @@ -30,11 +30,20 @@ <%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%#= javascript_include_tag "/assets/kindeditor/kindeditor-min" %> -<% if @project %> + + + <% if @project %> <%= render :partial => 'project_show', locals: {project: @project} %> -<% elsif @course %> - <%= render :partial => 'course_show', locals: {course: @course} %> -<% end %> + <% elsif @course %> +
+
+
+ 课程讨论区 +
+
+ <%= render :partial => 'course_show', :locals => {:topics => @topics, :page => 0} %> +
+ <% end %>