Gallery show enhancements

a) Worked on better pagination, knows now 25, 50, 100  and "all"
b) Viewer always shows ALL pictures, sorted to fit the order of the
pagination
This commit is contained in:
Thomas Blazek
2015-01-16 12:10:02 +01:00
parent a9969a6c72
commit 9c6038d6dd
2 changed files with 27 additions and 13 deletions

View File

@@ -19,19 +19,31 @@ class GalleriesController < ApplicationController
def show def show
@gallery = Gallery.find(params[:id]) @gallery = Gallery.find(params[:id])
@pppage_array = [ 25 , 50 , 100 ] #defines number & size of picture chunks @pppage_array = [ 25 , 50 , 100, "all"] #defines number & size of picture chunks
@pppage = 0 #starting index of pppage_array @pppage = 0 #starting index of pppage_array
if params[:pppage].to_i <= 2 && params[:pppage].to_i >= 0 if !params[:pppage].nil? && params[:pppage].to_i <= 2 && params[:pppage].to_i >= 0
@pppage = params[:pppage].to_i @pppage = params[:pppage].to_i
end end
@page = params[:page].nil? ? 1 : params[:page].to_i @page = params[:page].nil? ? 1 : params[:page].to_i
# @fotos = Foto.where(:gallery_id => params[:id]).limit(@pppage_array[@pppage]).offset(@pppage_array[@pppage]*(@page-1)) # @fotos = Foto.where(:gallery_id => params[:id]).limit(@pppage_array[@pppage]).offset(@pppage_array[@pppage]*(@page-1))
@fotos = Foto.where(:gallery_id => params[:id]) @fotos = Foto.where(:gallery_id => params[:id])
@pages = (Foto.where(:gallery_id => params[:id]).count/(@pppage_array[@pppage])+1) if @pppage_array[@pppage] != "all"
@fotos_p = @fotos.page(@page).per(@pppage_array[@pppage])
@fotos_n = @fotos- @fotos_p
@foto_ind = @fotos.find_index(@fotos_p.first)
@fotos_n = @fotos_n.rotate(@foto_ind)
@pages = (Foto.where(:gallery_id => params[:id]).count/(@pppage_array[@pppage])+1)
else
@fotos_p = @fotos
@fotos_n = []
@pages = 1
end
@showind=[] @showind=[]
@showind.fill(0,@pppage_array[@pppage]){ |i| i+ @pppage_array[@pppage]*(@page-1)} # Hier ausrechnen welche angezeigt werden sollen # Hier ausrechnen welche angezeigt werden sollen
@toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('fotos.new-fotos'), :path=>new_gallery_foto_path(@gallery)} @toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('fotos.new-fotos'), :path=>new_gallery_foto_path(@gallery)}
@toolbar_elements << {:hicon=>'icon-pencil', :text => I18n.t('common.edit'), :path=>edit_gallery_path(@gallery)} @toolbar_elements << {:hicon=>'icon-pencil', :text => I18n.t('common.edit'), :path=>edit_gallery_path(@gallery)}
@toolbar_elements << {:hicon=>'icon-arrow-left', :text=>I18n.t('common.back'), :path=>galleries_path()} @toolbar_elements << {:hicon=>'icon-arrow-left', :text=>I18n.t('common.back'), :path=>galleries_path()}

View File

@@ -36,10 +36,8 @@
</div> </div>
</div> </div>
</div> </div>
<div style="clear:both"></div> <div style="clear:both"></div>
<!-- The Bootstrap Image Gallery lightbox, should be a child element of the document body --> <!-- The Bootstrap Image Gallery lightbox, should be a child element of the document body -->
<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls"> <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls">
<!-- The container for the modal slides --> <!-- The container for the modal slides -->
@@ -74,14 +72,18 @@
</div> </div>
</div> </div>
</div> </div>
<div id="links"> <div id="links">
<% @fotos.each_index do |i| %> <div class="row-fluid">
<% f= @fotos[i] %> <div class="span12">
<% @fotos_p.each do |f| %>
<a href="<%= f.datei.resized.url%>" title="<%=f.title%>" data-gallery> <a href="<%= f.datei.resized.url%>" title="<%=f.title%>" data-gallery>
<%=image_tag(f.datei.thumb.url,{:class=>"img-polaroid img-rounded"}) if @showind.include? i %></a> <%=image_tag(f.datei.thumb.url,{:class=>"img-polaroid img-rounded"}) %></a>
<% end %> <% end %>
<% @fotos_n.each do |f| %>
<a href="<%= f.datei.resized.url%>" title="<%=f.title%>" data-gallery></a>
<% end %>
</div>
</div>
</div> </div>
<%= javascript_include_tag "blueimp-gallery-all" %> <%= javascript_include_tag "blueimp-gallery-all" %>