OSDN Git Service

t#31521:fix story pager
authoryasushiito <yas@pen-chan.jp>
Thu, 22 Aug 2013 07:35:07 +0000 (16:35 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 22 Aug 2013 07:35:07 +0000 (16:35 +0900)
app/controllers/stories_controller.rb
app/models/story.rb
app/views/stories/comic.html.erb
spec/models/speech_balloon_spec.rb

index 8d1d1e3..ca77f0d 100644 (file)
@@ -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
index ddc52a3..cd67cc3 100644 (file)
@@ -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
index b0a13ea..631f6f0 100644 (file)
     <%= render 'footer', :story => story, :author => @author %>
   <% end %>
   <%= render 'licensed_pictures', :licensed_pictures => Story.licensed_pictures(@stories) %>
+
+  <% if @prev_offset -%>
+    <%= link_to h('<<prev'), comic_story_path(@comic, {:offset => @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 -%>
   <h3><%= t('stories.comic.new_panels') -%></h3>
index 47e1afb..701f1c6 100644 (file)
@@ -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)
         )