SHIMADA Koji
null+****@clear*****
Fri Sep 28 02:52:32 JST 2012
SHIMADA Koji 2012-09-28 02:52:32 +0900 (Fri, 28 Sep 2012) New Revision: 7d34dcf4e3a08992e0df9496effa4c7bbf134f64 https://github.com/logaling/logaling-server/commit/7d34dcf4e3a08992e0df9496effa4c7bbf134f64 Merged 71a096d: Merge pull request #20 from logaling/kaminarize Log: Pagination Modified files: app/controllers/search_controller.rb app/controllers/user_glossaries_controller.rb app/helpers/application_helper.rb app/views/search/index.html.haml app/views/user_glossaries/show.html.haml Modified: app/controllers/search_controller.rb (+3 -1) =================================================================== --- app/controllers/search_controller.rb 2012-09-28 02:51:39 +0900 (1329101) +++ app/controllers/search_controller.rb 2012-09-28 02:52:32 +0900 (d91b28b) @@ -3,11 +3,13 @@ class SearchController < ApplicationController @query = params[:query] priority_glossary = signed_in? ? current_user.priority_glossary : nil - @terms = LogalingServer.repository.lookup(@query, priority_glossary).map do |t| + search_results = LogalingServer.repository.lookup(@query, priority_glossary).map do |t| GlossaryEntry.new do |o| o.extend AdditionalInformationAsSearchResults o.attributes = t end end + @per_count = 10 + @terms = Kaminari.paginate_array(search_results).page(params[:page]).per(@per_count) end end Modified: app/controllers/user_glossaries_controller.rb (+1 -0) =================================================================== --- app/controllers/user_glossaries_controller.rb 2012-09-28 02:51:39 +0900 (e6744bb) +++ app/controllers/user_glossaries_controller.rb 2012-09-28 02:52:32 +0900 (6f60487) @@ -7,6 +7,7 @@ class UserGlossariesController < ApplicationController def show @term = GlossaryEntry.new @user_glossary = UserGlossary.find(params[:id]) + @registered_terms = Kaminari.paginate_array(@user_glossary.terms).page(params[:page]) rescue ActiveRecord::RecordNotFound render :file => 'public/404.html', :status => 404, :layout => false end Modified: app/helpers/application_helper.rb (+9 -0) =================================================================== --- app/helpers/application_helper.rb 2012-09-28 02:51:39 +0900 (e70bd50) +++ app/helpers/application_helper.rb 2012-09-28 02:52:32 +0900 (fe43ecc) @@ -14,4 +14,13 @@ module ApplicationHelper def github_project?(glossary_name) glossary_name =~ /^github/ end + + def count_of_starting_position(per_count, current_page) + per_count * (current_page - 1) + 1 + end + + def count_of_end_position(per_count, current_page, page_count) + per_count * (current_page - 1) + page_count + end + end Modified: app/views/search/index.html.haml (+5 -3) =================================================================== --- app/views/search/index.html.haml 2012-09-28 02:51:39 +0900 (b54fcb4) +++ app/views/search/index.html.haml 2012-09-28 02:52:32 +0900 (bf1f17a) @@ -4,13 +4,15 @@ = @title - if****@terms*****? %p - 1- - =****@terms***** + = count_of_starting_position(@per_count, @terms.current_page) + \- + = count_of_end_position(@per_count, @terms.current_page, @terms.count) 件表示 / - =****@terms***** + =****@terms*****_count 件中 -****@terms***** do |term| = render :partial => 'shared/term', :locals => {:term => term} + = paginate @terms - else %p = @query Modified: app/views/user_glossaries/show.html.haml (+2 -1) =================================================================== --- app/views/user_glossaries/show.html.haml 2012-09-28 02:51:39 +0900 (88c4841) +++ app/views/user_glossaries/show.html.haml 2012-09-28 02:52:32 +0900 (ea91990) @@ -8,7 +8,7 @@ = render 'terms/form' %h2 登録されてる用語一覧 - - @user_glossary.terms.each do |term| + - @registered_terms.each do |term| .term .row .span9 @@ -27,3 +27,4 @@ %p.btn-group.actions = link_to raw("<i class=icon-pencil></i>"), edit_user_glossary_term_path(current_user, @user_glossary, term.id), :class => 'btn btn-mini' = link_to raw("<i class=icon-trash></i>"), user_glossary_term_path(current_user, @user_glossary, term.id), method: :delete, :class => 'btn btn-mini' + = paginate @registered_terms -------------- next part -------------- An HTML attachment was scrubbed... Download