diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index e9d21ddc4..c040d2af3 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -13,9 +13,25 @@ class SoftapplicationsController < ApplicationController @softapplication_count = @softapplications.count @softapplication_pages = Paginator.new @softapplication_count, @limit, params['page'] @offset ||= @softapplication_pages.offset - @softapplications = @softapplications[@offset,@limit] - #new added end #@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| format.html # index.html.erb format.json { render json: @softapplications } diff --git a/app/helpers/softapplications_helper.rb b/app/helpers/softapplications_helper.rb index e3cb6410d..fe78e9875 100644 --- a/app/helpers/softapplications_helper.rb +++ b/app/helpers/softapplications_helper.rb @@ -1,2 +1,18 @@ 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 + + diff --git a/app/views/softapplications/index.html.erb b/app/views/softapplications/index.html.erb index de094f1eb..df5ea1921 100644 --- a/app/views/softapplications/index.html.erb +++ b/app/views/softapplications/index.html.erb @@ -36,28 +36,36 @@ <%=render :partial => 'layouts/base_softapplication_index_top_content'%> -
- <% @softapplications.each do |softapplication| %> -
- <%= link_to softapplication.name, softapplication, :target => "_blank" %> - <%= rating_for softapplication, :static => true, dimension: :quality, class: 'rateable div_inline' %> - -
-
<%= image_tag('/images/app1.png')%>
-
<%= softapplication.description.truncate(95, omission: '...') %>
-
-

所属竞赛:<%#= contest ? link_to(contest.name, show_softapplication_contest_path()) : '尚未加入竞赛'%>

-

所属类别:<%= softapplication.app_type_name %>

-

系统支持:<%= softapplication.android_min_version_available %>

-
-
- 开发人员:<%= softapplication.application_developers %> - 发布时间:<%=format_time softapplication.created_at %> -
-
-
- <% end %> -
+<% if @softapplications.size > 0%> + <%= sort_softapplication(@s_state)%> + +
+ <% @softapplications.each do |softapplication| %> +
+ <%= link_to softapplication.name, softapplication, :target => "_blank" %> + <%= rating_for softapplication, :static => true, dimension: :quality, class: 'rateable div_inline' %> + +
+
<%= image_tag('/images/app1.png')%>
+
<%= softapplication.description.truncate(95, omission: '...') %>
+
+

所属竞赛:<%#= contest ? link_to(contest.name, show_softapplication_contest_path()) : '尚未加入竞赛'%>

+

所属类别:<%= softapplication.app_type_name %>

+

系统支持:<%= softapplication.android_min_version_available %>

+
+
+ 开发人员:<%= softapplication.application_developers %> + 发布时间:<%=format_time softapplication.created_at %> +
+
+
+ <% end %> +
+ +<% else %> + <%= render :partial => "layouts/no_content"%> +<% end %> +