From 5c5d2121937d30d59597953b2e2caef12b13478a Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Fri, 22 Apr 2016 13:52:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/blogs_controller.rb | 34 +++++-- app/views/blogs/_article.html.erb | 118 +++++++++++++---------- app/views/blogs/_article_list.html.erb | 2 +- app/views/blogs/index.js.erb | 1 + app/views/layouts/new_base_user.html.erb | 2 +- public/javascripts/homework.js | 6 ++ public/stylesheets/new_user.css | 21 ++-- 7 files changed, 117 insertions(+), 67 deletions(-) diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index dcdb4846c..8a725dcca 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,24 +1,44 @@ class BlogsController < ApplicationController before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage] before_filter :find_user + include PraiseTreadHelper + def index @article = BlogComment.new - @order, @b_sort = params[:order] || 1, params[:sort] || "desc" - - sort_name = @order == 1 ? "created_on" : "" + @order, @b_sort,@type = params[:order] || 1, params[:sort] || 2, params[:type] || 1 + #确定 sort_type + if @order.to_i == @type.to_i + @b_sort = @b_sort.to_i == 1 ? 2 : 1 + else + @b_sort = 1 + end - @topics = @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.#{sort_name} #{@b_sort}") + sort_name = "updated_on" - #分页 + sort_type = @b_sort == 1 ? "desc" : "asc" - @topics = paginateHelper @topics,10 - @page = (params['page'] || 1).to_i - 1 + @topics = @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.#{sort_name} #{sort_type}") + #根据 赞+回复数排序 + if @order.to_i == 2 + @type = 2 + @b_sort == 1 ? @topics = @topics.sort{|x,y| get_praise_num(y) + (y.parent ? y.parent.children.count : y.children.count) <=> get_praise_num(x) + (x.parent ? x.parent.children.count : x.children.count) } : @topics = @topics.sort{|x,y| get_praise_num(x) + (x.parent ? x.parent.children.count : x.children.count) <=> get_praise_num(y) + (y.parent ? y.parent.children.count : y.children.count) } + else + @type = 1 + end + #分页 + @limit = 10 + @is_remote = true + @atta_count = @topics.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @topics = paginateHelper @topics,@limit respond_to do |format| + format.js format.html {render :layout=>'new_base_user'} end end diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 7b8ccb5d3..4b733c0f9 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -1,56 +1,70 @@ -
- <%= count>0 ? "(#{count})" : "" %> - 回复 - | - <%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %> - 赞 -
-+ <%= count>0 ? "(#{count})" : "" %> + 回复 + | + <%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %> + 赞 +
+