应用页面列表排序(按时间排序已好,另一种排序暂未定)

This commit is contained in:
wanglinchun 2014-04-29 18:21:07 +08:00
parent 0eb81a24af
commit 3da6d5cd37
3 changed files with 64 additions and 24 deletions

View File

@ -13,9 +13,25 @@ class SoftapplicationsController < ApplicationController
@softapplication_count = @softapplications.count @softapplication_count = @softapplications.count
@softapplication_pages = Paginator.new @softapplication_count, @limit, params['page'] @softapplication_pages = Paginator.new @softapplication_count, @limit, params['page']
@offset ||= @softapplication_pages.offset @offset ||= @softapplication_pages.offset
@softapplications = @softapplications[@offset,@limit]
#new added end
#@softapplications = @softapplications[@offset,@limit] #@softapplications = @softapplications[@offset,@limit]
#new added end
#new added sort
if params[:softapplication_sort_type].present?
case params[:softapplication_sort_type]
when '0'
@softapplications = @softapplications[@offset, @limit]
@s_state = 0
when '1'
@softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit]
@s_state = 1
end
else
@softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit]
@s_state = 1
end
#new added end
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.json { render json: @softapplications } format.json { render json: @softapplications }

View File

@ -1,2 +1,18 @@
module SoftapplicationsHelper module SoftapplicationsHelper
def sort_softapplication(state)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'softapplications', action: 'index' ,:softapplication_sort_type => '1'}))
content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'softapplications', action: 'index' ,:softapplication_sort_type => '0'}, :class=>"selected"), :class=>"selected")
when 1
content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'softapplications', action: 'index' ,:softapplication_sort_type => '1'}, :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'softapplications', action: 'index' ,:softapplication_sort_type => '0'}))
end
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
end end

View File

@ -36,28 +36,36 @@
<%=render :partial => 'layouts/base_softapplication_index_top_content'%> <%=render :partial => 'layouts/base_softapplication_index_top_content'%>
<div width="95%" border="0" style="padding-left: 10px; padding-top: 10px;"> <% if @softapplications.size > 0%>
<% @softapplications.each do |softapplication| %> <%= sort_softapplication(@s_state)%>
<div>
<span style="font-size: 15px; margin-right: 10px;"><strong><%= link_to softapplication.name, softapplication, :target => "_blank" %></strong></span> <div width="95%" border="0" style="padding-left: 10px; padding-top: 10px;">
<span><%= rating_for softapplication, :static => true, dimension: :quality, class: 'rateable div_inline' %></span> <% @softapplications.each do |softapplication| %>
<div>
</div> <span style="font-size: 15px; margin-right: 10px;"><strong><%= link_to softapplication.name, softapplication, :target => "_blank" %></strong></span>
<div class="avatar-4"; style="float: left; margin-top: 7px "><%= image_tag('/images/app1.png')%></div> <span><%= rating_for softapplication, :static => true, dimension: :quality, class: 'rateable div_inline' %></span>
<div style="float: left; width: 600px; padding-top: 6px; margin-left: 8px"><%= softapplication.description.truncate(95, omission: '...') %></div>
<div style="float: left; width: 200px; margin-left: 70px; margin-top: -3px; line-height: 0.5em"> </div>
<p>所属竞赛:<%#= contest ? link_to(contest.name, show_softapplication_contest_path()) : '尚未加入竞赛'%></p> <div class="avatar-4"; style="float: left; margin-top: 7px "><%= image_tag('/images/app1.png')%></div>
<p>所属类别:<%= softapplication.app_type_name %></p> <div style="float: left; width: 600px; padding-top: 6px; margin-left: 8px"><%= softapplication.description.truncate(95, omission: '...') %></div>
<p>系统支持:<%= softapplication.android_min_version_available %></p> <div style="float: left; width: 200px; margin-left: 70px; margin-top: -3px; line-height: 0.5em">
</div> <p>所属竞赛:<%#= contest ? link_to(contest.name, show_softapplication_contest_path()) : '尚未加入竞赛'%></p>
<div style="padding-left: 53px"> <p>所属类别:<%= softapplication.app_type_name %></p>
<span>开发人员:<%= softapplication.application_developers %></span> <p>系统支持:<%= softapplication.android_min_version_available %></p>
<span style="padding-left: 50px">发布时间:<%=format_time softapplication.created_at %></span> </div>
</div> <div style="padding-left: 53px">
<div style="border-left: 1px solid #d9d8d8; border-bottom: 1px solid #d9d8d8; margin-left: 50px; padding-bottom: 10px; margin-bottom: 20px; width: 66%"></div> <span>开发人员:<%= softapplication.application_developers %></span>
<div class="underline-contests_one" style="margin-top: -7px"></div> <span style="padding-left: 50px">发布时间:<%=format_time softapplication.created_at %></span>
<% end %> </div>
</div> <div style="border-left: 1px solid #d9d8d8; border-bottom: 1px solid #d9d8d8; margin-left: 50px; padding-bottom: 10px; margin-bottom: 20px; width: 66%"></div>
<div class="underline-contests_one" style="margin-top: -7px"></div>
<% end %>
</div>
<% else %>
<%= render :partial => "layouts/no_content"%>
<% end %>
<div class="pagination"><%= pagination_links_full @softapplication_pages, @softapplication_count, :per_page_links => false %></div> <div class="pagination"><%= pagination_links_full @softapplication_pages, @softapplication_count, :per_page_links => false %></div>