From 6ddf9ff48c99b4a5baeed1b5aa6a1909865d593b Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Sun, 1 Nov 2020 23:26:04 +0100 Subject: [PATCH] Pagination fixed --- app/controllers/packages_controller.rb | 9 +-------- app/views/packages/details.slim | 26 +++++++++----------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 232290f..e5ee532 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -24,14 +24,7 @@ class PackagesController < ApplicationController # first image twice as large. So the first page contains 5 images while # the second and further page contain 6 images. @page = params[:page] - # BUG: having page 1 with 5 and other with 6 items does not compute correctly - @images_per_page = if @page.to_i < 2 - 5 - else - 6 - end - # raise - @screenshots = screenshots_visible_to_user(@package).paginate(page: @page, per_page: @images_per_page) + @screenshots = screenshots_visible_to_user(@package).paginate(page: @page, per_page: 6) end # Show upload form for new images diff --git a/app/views/packages/details.slim b/app/views/packages/details.slim index d973f51..88ee382 100644 --- a/app/views/packages/details.slim +++ b/app/views/packages/details.slim @@ -17,24 +17,16 @@ .grid-x.grid-margin-y.grid-margin-x.align-middle - @screenshots.each_with_index do |screenshot, idx| - / Display the first screenshot as a large image (on the first page only) - - if idx==0 && @page.to_i<2 - .small-12.medium-12.cell - .margin-bottom-3 - = render(partial:'medium_image', locals: {screenshot: screenshot}) + .small-12.medium-6.cell + .margin-bottom-3 + = render(partial:'small_image', locals: {screenshot: screenshot}) - / Display further screenshots as smaller images - - else - .small-12.medium-6.cell - .margin-bottom-3 - = render(partial:'medium_image', locals: {screenshot: screenshot}) - - // Has the unmoderated screenshot been uploaded by the current user? - - if screenshot_uploaded_by_current_user?(screenshot) - span.label.warning - | Uploaded by you - - unless screenshot.approved - | (but not public yet) + // Has the unmoderated screenshot been uploaded by the current user? + - if screenshot_uploaded_by_current_user?(screenshot) + span.label.warning + | Uploaded by you + - unless screenshot.approved + | (but not moderated yet) // Second paginator at the bottom so the user does not have to scroll up again = render(partial: 'packages/paginator', locals: {items: @screenshots})