博客列表

This commit is contained in:
yuanke 2016-04-22 13:52:33 +08:00
parent eddea2eabd
commit 5c5d212193
7 changed files with 118 additions and 68 deletions

View File

@ -1,24 +1,44 @@
class BlogsController < ApplicationController class BlogsController < ApplicationController
before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage] before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage]
before_filter :find_user before_filter :find_user
include PraiseTreadHelper
def index def index
@article = BlogComment.new @article = BlogComment.new
@order, @b_sort = params[:order] || 1, params[:sort] || "desc" @order, @b_sort,@type = params[:order] || 1, params[:sort] || 2, params[:type] || 1
sort_name = @order == 1 ? "created_on" : "" #确定 sort_type
if @order.to_i == @type.to_i
@b_sort = @b_sort.to_i == 1 ? 2 : 1
else
@b_sort = 1
end
sort_name = "updated_on"
@topics = @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.#{sort_name} #{@b_sort}") sort_type = @b_sort == 1 ? "desc" : "asc"
@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
@topics = paginateHelper @topics,10 @is_remote = true
@page = (params['page'] || 1).to_i - 1 @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| respond_to do |format|
format.js
format.html {render :layout=>'new_base_user'} format.html {render :layout=>'new_base_user'}
end end
end end

View File

@ -1,17 +1,16 @@
<div class="listbox"> <div class = "cl"> </div>
<div id="blog-list">
<div class="listbox mt10" >
<h2 class="list-h2">博客列表</h2> <h2 class="list-h2">博客列表</h2>
<div class="category"> <div class="category">
<span class="grayTxt ">排序:</span> <span class="grayTxt ">排序:</span>
<%= link_to "时间", {:controller => 'blogs', :action => 'index', :id =>@user, :type => @type, :sort => @b_sort, :order => 1 }, :class => "sortTxt", :remote => true %>
<% if @type.to_i == 1 %>
<%= link_to "时间", user_blog_sort_blog_path(:sort => @score, :order => 1, :search => " "), :class => "sortTxt", :remote => true %> <%= link_to "", {:controller => 'blogs', :action => 'index', :id =>@user, :type => @type, :sort => @b_sort, :order => 1 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% if @order == 1 %>
<%= link_to "", user_blog_sort_blog_path(:sort => @score, :order => 1, :search => " "), :class => "#{@score == 'desc' ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %> <% end %>
<%= link_to "人气", {:controller => 'blogs', :action => 'index', :id =>@user, :type => @type, :sort => @b_sort, :order => 2 }, :class => "sortTxt", :remote => true %>
<%= link_to "人气", user_blog_sort_blog_path(:sort => @score, :order => 2, :search => " "), :class => "sortTxt", :remote => true %> <% if @type.to_i == 2 %>
<% if @order == 2 %> <%= link_to "", {:controller => 'blogs', :action => 'index', :id =>@user, :type => @type, :sort => @b_sort, :order => 2 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<%= link_to "", user_blog_sort_blog_path(:sort => @score, :order => 2, :search => " "), :class => "#{@score == 'desc' ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %> <% end %>
<div class="cl"></div> <div class="cl"></div>
@ -21,13 +20,14 @@
<ul class="list-file"> <ul class="list-file">
<li><span class="item_list fl"></span> <li><span class="item_list fl"></span>
<% if activity.parent_id.nil? %> <!--+"(帖子标题)"--> <% if activity.parent_id.nil? %> <!--+"(帖子标题)"-->
<%= link_to activity.title.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "c_red ml10" %> <%= link_to activity.title.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "list-title fl" %>
<% else %> <% else %>
<%= link_to activity.title.subject.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "c_red ml10"%> <%= link_to activity.title.subject.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "list-title fl"%>
<% end %> <% end %>
<% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %> <% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %>
<span class="c_red ml10">[已设为首页]</span></a> <span class="c_red ml10 fl">[已设为首页]</span>
<% end %> <% end %>
<div class="cl"></div>
</li> </li>
<% count=0 %> <% count=0 %>
<% if activity.parent %> <% if activity.parent %>
@ -49,8 +49,22 @@
<div class="cl"></div> <div class="cl"></div>
</ul> </ul>
<% end %> <% end %>
<div class="pagination"> <div>
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %> <ul class="wlist" id="pages" >
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>
</ul>
<div class="cl"></div>
</div> </div>
</div> </div>
</div> </div>
</div>
<script type="text/javascript">
//如果右边的博客列表比左边的高度低则将右边的高度设为与左边对齐
var leftHeight = $("#LSide").height()-$(".fontGrey5").height()-10;
var rightHeight = $(".homepageRight").height();
if (rightHeight < leftHeight){
var diffHeight = leftHeight - rightHeight;
var blogHeight = $(".listbox").height()+diffHeight;
$(".listbox").css("height",blogHeight);
}
</script>

View File

@ -38,7 +38,7 @@
<div class="homepageRight mt0"> <div class="homepageRight mt0">
<div class="homepageRightBanner"> <div class="homepageRightBanner">
<div class="NewsBannerName"> <div class="f16 fl fontGrey3">
<%= @user.name%>的博客 <%= @user.name%>的博客
</div> </div>
</div> </div>

View File

@ -0,0 +1 @@
$("#blog-list").html('<%= escape_javascript( render :partial => 'blogs/article', :locals => {:topics => @topics} ) %>');

View File

@ -7,7 +7,7 @@
<meta name="keywords" content="issue,bug,tracker" /> <meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %> <%= csrf_meta_tag %>
<%= favicon %> <%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'share','new_user', 'user_leftside','prettify','users','application',:media => 'all' %> <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'share','new_user', 'user_leftside','prettify','users',:media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<%= javascript_heads %> <%= javascript_heads %>
<%= javascript_include_tag "bootstrap","avatars","new_user",'attachments','prettify'%> <%= javascript_include_tag "bootstrap","avatars","new_user",'attachments','prettify'%>

View File

@ -22,6 +22,8 @@ $(function(){
}; };
var test_program = function(cb){ var test_program = function(cb){
$('#test-program-btn').hide()
var homework_id = $('#test-program-btn').attr('data-homework-id'); var homework_id = $('#test-program-btn').attr('data-homework-id');
var student_work_id = $('#test-program-btn').attr('data-student-work-id'); var student_work_id = $('#test-program-btn').attr('data-student-work-id');
var src = $('#program-src').val(); var src = $('#program-src').val();
@ -29,6 +31,7 @@ $(function(){
var is_test = $('input[name=is_test]').val(); var is_test = $('input[name=is_test]').val();
if(!valid_form()){ if(!valid_form()){
$('#test-program-btn').show()
return; return;
} }
/* /*
@ -83,12 +86,14 @@ $(function(){
if (r) { if (r) {
$(".HomeWorkCon form").submit(); $(".HomeWorkCon form").submit();
} }
$('#test-program-btn').show()
return; return;
} }
//2 超时 -2 编译错误 测试结束 //2 超时 -2 编译错误 测试结束
if (data.status == 2 || data.status == -2 || tSeq >= tCount ){ if (data.status == 2 || data.status == -2 || tSeq >= tCount ){
if (typeof cb == 'function') {cb(data); return;} if (typeof cb == 'function') {cb(data); return;}
$('#test-program-btn').show()
return; return;
} }
@ -100,6 +105,7 @@ $(function(){
} else { } else {
alert("对不起,服务器繁忙请稍后再试!"); alert("对不起,服务器繁忙请稍后再试!");
} }
$('#test-program-btn').show()
return; return;
}); });
}; };

View File

@ -1499,18 +1499,19 @@ a:hover.Blue-btn{ background:#3598db; color:#fff;}
.box-con-a{ width:170px; margin:0 auto; margin-top:10px;} .box-con-a{ width:170px; margin:0 auto; margin-top:10px;}
/*博客列表界面样式*/ /*博客列表界面样式*/
a{text-decoration:none}
.listbox{ width:730px; background-color:#fff; border:1px solid #ddd; padding:10px; } .listbox{ width:730px; background-color:#fff; border:1px solid #ddd; padding:10px; }
.bloglistbox{ min-height:690px;} /*.bloglistbox{ min-height:690px;}*/
.list-h2{ font-size:16px; font-weight:bold; color:#000; border-bottom:2px solid #269ac9; padding-bottom:5px;} .list-h2{ font-size:16px; font-weight:bold; color:#000; border-bottom:2px solid #269ac9; padding-bottom:5px;}
.category{ padding:10px 0; border-bottom:1px solid #ddd;} .category{ padding:10px 0; border-bottom:1px solid #ddd;}
.category a,.category span{ float:left; margin-right:5px;} .category a,.category span{ float:left; margin-right:5px;}
.grayTxt{ color:#9093a6;} .grayTxt{ color:#9093a6;}
.sortTxt{ color:#000;} .category a.sortTxt{ color:#9093a6;}
.sortTxt:hover{ color:#28be6c;} .category .sortTxt:hover{ color:#28be6c;}
a.sortupbtn{ background: url(../images/liststyle.png) 0 3px no-repeat; width:12px; height:17px; display:block; margin-right:10px; cursor:pointer;} a.sortupbtn{ background: url(../images/liststyle.png) 0 3px no-repeat; width:12px; height:17px; display:block; margin-right:10px; cursor:pointer;}
a.sortdownbtn{ background: url(../images/liststyle.png) 0 -12px no-repeat; width:12px; height:17px; display:block;cursor:pointer; } a.sortdownbtn{ background: url(../images/liststyle.png) 0 -12px no-repeat; width:12px; height:17px; display:block;margin-right:10px;cursor:pointer; }
.item_list{ display:block; width:5px; height:5px;-webkit-border-radius: 25px;border-radius:25px; background-color:#adadad; margin:10px 10px 0 0;} .item_list{ display:block; width:5px; height:5px;-webkit-border-radius: 25px;border-radius:25px; background-color:#adadad; margin:10px 10px 0 0;}
a.list-title{ font-size:14px; font-weight: bold; color:#000;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; display:block; width:708px;} .list-file a.list-title{ font-size:14px; font-weight: bold; color:#000;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; display:block; max-width:635px;}
a:hover.list-title{ color:#269ac9;} a:hover.list-title{ color:#269ac9;}
.c_red{ font-weight:normal; font-size:12px;} .c_red{ font-weight:normal; font-size:12px;}
.list-file{ padding:10px 0; border-bottom:1px dashed #ddd;} .list-file{ padding:10px 0; border-bottom:1px dashed #ddd;}
@ -1532,3 +1533,11 @@ a:hover.messages-title{ color:#269ac9;}
.massages-content{ width:710px; color:#424242; max-height:65px; overflow:hidden; margin:10px 0;margin-left:15px; line-height:1.9;} .massages-content{ width:710px; color:#424242; max-height:65px; overflow:hidden; margin:10px 0;margin-left:15px; line-height:1.9;}
.red-cir-btn{ background:#e74c3c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;} .red-cir-btn{ background:#e74c3c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;}
.green-cir-btn{ background:#28be6c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;} .green-cir-btn{ background:#28be6c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;}
/****翻页***/
ul.wlist{ float:right; border-bottom:none; height:30px; margin-top:20px; }
ul.wlist li{float: left;}
ul.wlist li a{ border:1px solid #15bccf; padding: 1px 4px 1px 4px; margin-left:3px;}
ul.wlist li a:hover{ background:#15bccf; color:#fff; text-decoration:none;}
/*.wlist_select { background-color:#64bdd9; color:#fff; padding: 1px 5px 0px 5px; margin-left:3px;margin-top: -2px; border:1px solid #64bdd9;}*/
.wlist_select a{background-color: #64bdd9;cursor: default;}