From 3119d9a9aafba1fe1872e215b3b99326f5c2754b Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 29 Jul 2014 17:35:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AB=9E=E8=B5=9B=E4=BD=9C?= =?UTF-8?q?=E5=93=81=E7=9A=84=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softapplications_controller.rb | 30 +++++++++++++++++++ ...softapplication_index_top_content.html.erb | 18 ++++++----- app/views/softapplications/_list.html.erb | 24 +++++++++++++++ app/views/softapplications/index.html.erb | 28 ++--------------- app/views/softapplications/search.js.erb | 2 ++ config/routes.rb | 1 + 6 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 app/views/softapplications/_list.html.erb create mode 100644 app/views/softapplications/search.js.erb diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index 1808a3eaa..89bdce5b7 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -304,6 +304,36 @@ class SoftapplicationsController < ApplicationController end end + def search + @softapplications = Softapplication.where("name like '%#{params[:name]}%'") + + #new added fenyefunction + @limit = 5 + @softapplication_count = @softapplications.count + @softapplication_pages = Paginator.new @softapplication_count, @limit, params['page'] + @offset ||= @softapplication_pages.offset + + #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.js + end + end + private def find_softapplication @softapplication = Softapplication.find_by_id(params[:id]) diff --git a/app/views/layouts/_base_softapplication_index_top_content.html.erb b/app/views/layouts/_base_softapplication_index_top_content.html.erb index 7fa65bec4..db1e5df56 100644 --- a/app/views/layouts/_base_softapplication_index_top_content.html.erb +++ b/app/views/layouts/_base_softapplication_index_top_content.html.erb @@ -4,18 +4,20 @@ <%=l(:label_contest_innovate_community)%> <%= l(:label_user_location) %> : - + - + <%=link_to request.host()+"/softapplications", :controller=>'softapplications', :action=>'index' %> - <%=link_to l(:field_homepage), home_path %> > - <%=link_to l(:label_contest_work), :controller=>'softapplications', :action=>'index' %> + <%=link_to l(:field_homepage), home_path %> > + <%=link_to l(:label_contest_work), :controller=>'softapplications', :action=>'index' %> diff --git a/app/views/softapplications/_list.html.erb b/app/views/softapplications/_list.html.erb new file mode 100644 index 000000000..9ce6e269b --- /dev/null +++ b/app/views/softapplications/_list.html.erb @@ -0,0 +1,24 @@ + + <% @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 = softapplication.contests.first%> +

<%=l(:label_attendingcontestwork_belongs_contest)%>:<%= contest ? link_to(contest.name.truncate(14, omission: '...'), show_attendingcontest_contest_path(contest), title: contest.name.to_s ) : '尚未加入竞赛'%>

+

<%=l(:label_attendingcontestwork_belongs_type)%>:<%= softapplication.app_type_name.truncate(10, omission: '...') %>

+

<%=l(:label_attendingcontestwork_adaptive_system)%>:<%= softapplication.android_min_version_available %>

+
+
+ <%=l(:label_attendingcontestwork_developers)%>:<%= softapplication.application_developers %> + <%=l(:label_attendingcontestwork_release_time)%>:<%=format_time softapplication.created_at %> +
+
+
+ <% end %> + + \ No newline at end of file diff --git a/app/views/softapplications/index.html.erb b/app/views/softapplications/index.html.erb index 5b355f65c..86d805621 100644 --- a/app/views/softapplications/index.html.erb +++ b/app/views/softapplications/index.html.erb @@ -4,36 +4,14 @@ <% 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 = softapplication.contests.first%> -

<%=l(:label_attendingcontestwork_belongs_contest)%>:<%= contest ? link_to(contest.name.truncate(14, omission: '...'), show_attendingcontest_contest_path(contest), title: contest.name.to_s ) : '尚未加入竞赛'%>

-

<%=l(:label_attendingcontestwork_belongs_type)%>:<%= softapplication.app_type_name.truncate(10, omission: '...') %>

-

<%=l(:label_attendingcontestwork_adaptive_system)%>:<%= softapplication.android_min_version_available %>

-
-
- <%=l(:label_attendingcontestwork_developers)%>:<%= softapplication.application_developers %> - <%=l(:label_attendingcontestwork_release_time)%>:<%=format_time softapplication.created_at %> -
-
-
- <% end %> +
+ <%= render :partial => "list" %>
- <% else %> <%= render :partial => "layouts/no_content"%> <% end %> - + <% html_title l(:label_contest_work_list)%> \ No newline at end of file diff --git a/app/views/softapplications/search.js.erb b/app/views/softapplications/search.js.erb new file mode 100644 index 000000000..8b4b8afb2 --- /dev/null +++ b/app/views/softapplications/search.js.erb @@ -0,0 +1,2 @@ + +$('#softapplications_list').html('<%= escape_javascript(render(:partial => 'list' )) %>'); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 948eee4a5..8d55fe300 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -76,6 +76,7 @@ RedmineApp::Application.routes.draw do collection do match 'new_message', via: :get + match 'search', via: [:get, :post] end member do match 'create_message' , via: :post