From 90eedb8e364e1b9a83f1a525ed87ff1c3a1e8478 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Thu, 22 Aug 2013 16:35:07 +0900 Subject: [PATCH] t#31521:fix story pager --- app/controllers/stories_controller.rb | 15 ++++++++++++++- app/models/story.rb | 3 --- app/views/stories/comic.html.erb | 9 +++++++++ spec/models/speech_balloon_spec.rb | 16 ++++++++-------- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 8d1d1e38..ca77f0d6 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -40,7 +40,20 @@ class StoriesController < ApplicationController @stories = Story.play_list(@comic, @author, @offset, @panel_count) respond_to do |format| format.html { - @paginate = Story.play_list_paginate(@comic, @offset, @panel_count) + @prev_offset = if @offset > 0 + if @offset - @panel_count < 0 + 0 + else + @offset - @panel_count + end + else + nil + end + @next_offset = if @offset + @panel_count > cnt + nil + else + @offset + @panel_count + end if @author @new_panels = Panel.mylist(@author, 1, 5) end diff --git a/app/models/story.rb b/app/models/story.rb index ddc52a37..cd67cc3a 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -113,9 +113,6 @@ class Story < ActiveRecord::Base Story.where(self.himlist_where(au)).includes(Story.list_opt).order('stories.updated_at desc').offset((page -1) * page_size).limit(page_size) end - def self.play_list_paginate comic, author, offset = 0, limit = Story.default_panel_size - end - def self.list_paginate page = 1, page_size = self.default_page_size Kaminari.paginate_array(Array.new(Story.where(self.list_where()).includes(Story.list_opt).count, nil)).page(page).per(page_size) end diff --git a/app/views/stories/comic.html.erb b/app/views/stories/comic.html.erb index b0a13ea8..631f6f03 100644 --- a/app/views/stories/comic.html.erb +++ b/app/views/stories/comic.html.erb @@ -13,6 +13,15 @@ <%= render 'footer', :story => story, :author => @author %> <% end %> <%= render 'licensed_pictures', :licensed_pictures => Story.licensed_pictures(@stories) %> + + <% if @prev_offset -%> + <%= link_to h('< @prev_offset, :count => @panel_count}) %> + <% end %> + + <% if @next_offset -%> + <%= link_to h('next>>'), comic_story_path(@comic, {:offset => @next_offset, :count => @panel_count}) %> + <% end %> + <% end %> <% if @comic.own? @author -%>

<%= t('stories.comic.new_panels') -%>

diff --git a/spec/models/speech_balloon_spec.rb b/spec/models/speech_balloon_spec.rb index 47e1afbf..701f1c64 100644 --- a/spec/models/speech_balloon_spec.rb +++ b/spec/models/speech_balloon_spec.rb @@ -295,7 +295,7 @@ describe SpeechBalloon do end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do - @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id + @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100 @speech2 = @sb2.build_speech( FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) ) @@ -304,7 +304,7 @@ describe SpeechBalloon do ) @sb2.boost @sb2.save! - @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id + @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200 @speech3 = @sb3.build_speech( FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) ) @@ -313,7 +313,7 @@ describe SpeechBalloon do ) @sb3.boost @sb3.save! - @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id + @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300 @speech4 = @sb4.build_speech( FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) ) @@ -322,7 +322,7 @@ describe SpeechBalloon do ) @sb4.boost @sb4.save! - @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id + @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400 @speech5 = @sb5.build_speech( FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) ) @@ -419,7 +419,7 @@ describe SpeechBalloon do end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do - @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id + @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100 @speech2 = @sb2.build_speech( FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) ) @@ -428,7 +428,7 @@ describe SpeechBalloon do ) @sb2.boost @sb2.save! - @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id + @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200 @speech3 = @sb3.build_speech( FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) ) @@ -437,7 +437,7 @@ describe SpeechBalloon do ) @sb3.boost @sb3.save! - @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id + @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300 @speech4 = @sb4.build_speech( FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) ) @@ -446,7 +446,7 @@ describe SpeechBalloon do ) @sb4.boost @sb4.save! - @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id + @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400 @speech5 = @sb5.build_speech( FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) ) -- 2.11.0