Pagination fixed

This commit is contained in:
Christoph Haas 2020-11-01 23:26:04 +01:00
parent 3ad1dc605b
commit 6ddf9ff48c
2 changed files with 10 additions and 25 deletions

View file

@ -24,14 +24,7 @@ class PackagesController < ApplicationController
# first image twice as large. So the first page contains 5 images while # first image twice as large. So the first page contains 5 images while
# the second and further page contain 6 images. # the second and further page contain 6 images.
@page = params[:page] @page = params[:page]
# BUG: having page 1 with 5 and other with 6 items does not compute correctly @screenshots = screenshots_visible_to_user(@package).paginate(page: @page, per_page: 6)
@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)
end end
# Show upload form for new images # Show upload form for new images

View file

@ -17,24 +17,16 @@
.grid-x.grid-margin-y.grid-margin-x.align-middle .grid-x.grid-margin-y.grid-margin-x.align-middle
- @screenshots.each_with_index do |screenshot, idx| - @screenshots.each_with_index do |screenshot, idx|
/ Display the first screenshot as a large image (on the first page only) .small-12.medium-6.cell
- if idx==0 && @page.to_i<2 .margin-bottom-3
.small-12.medium-12.cell = render(partial:'small_image', locals: {screenshot: screenshot})
.margin-bottom-3
= render(partial:'medium_image', locals: {screenshot: screenshot})
/ Display further screenshots as smaller images // Has the unmoderated screenshot been uploaded by the current user?
- else - if screenshot_uploaded_by_current_user?(screenshot)
.small-12.medium-6.cell span.label.warning
.margin-bottom-3 | Uploaded by you
= render(partial:'medium_image', locals: {screenshot: screenshot}) - unless screenshot.approved
| (but not moderated 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 public yet)
// Second paginator at the bottom so the user does not have to scroll up again // Second paginator at the bottom so the user does not have to scroll up again
= render(partial: 'packages/paginator', locals: {items: @screenshots}) = render(partial: 'packages/paginator', locals: {items: @screenshots})