NEW: Pictures per Site Feature + Pagination + improved SQL query

This commit is contained in:
HausdorffHimself
2013-09-12 00:58:33 +02:00
parent 3e8950ba64
commit 77ee994edb
4 changed files with 68 additions and 20 deletions

View File

@@ -18,9 +18,21 @@ class GalleriesController < ApplicationController
# GET /galleries/1.json
def show
@gallery = Gallery.find(params[:id])
@pppage_array = [ 5 , 50 , 100 ] #defines number & size of picture chunks
@pppage = 0 #starting index of pppage_array
if params[:pppage].to_i <= 2 && params[:pppage].to_i >= 0
@pppage = params[:pppage].to_i
end
@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))
@pages = (Foto.where(:gallery_id => params[:id]).count/5)+1
@toolbar_elements << {:hicon=>'icon-plus', :text=> "NewFoto", :path=>new_gallery_foto_path(@gallery)}
@toolbar_elements << {:hicon=>'icon-pencil', :text => I18n.t('common.edit'), :path=>edit_gallery_path(@gallery)}
@toolbar_elements << {:text=>"Back", :path=>galleries_path()}
respond_to do |format|
format.html # show.html.erb
format.json { render json: @gallery }

View File

@@ -11,8 +11,35 @@
<p>
<%= @gallery.desc %>
</p>
</br>
<div class="fluid-row">
<div class="span9"> <!-- pagination-->
<div class="pagination pull_left">
<ul>
<li><a href="<%= gallery_path @gallery, {:pppage => @pppage, :page => (@page==1 ? @page : @page-1)} %>"><%=I18n.t('fotos.prev')%></a></li>
<% for i in 1..@pages do %>
<li><a href="<%= gallery_path @gallery, {:pppage => @pppage, :page => i} %>"><%=i%></a></li>
<% end %>
<li><a href="<%= gallery_path @gallery, {:pppage => @pppage, :page => (@page==@pages ? @page : @page+1)} %>"><%=I18n.t('fotos.next')%></a></li>
</ul>
</div>
</div>
<div class="span3"> <!-- size selector -->
<div class="pull-right" style="margin-top:20px">
<div class="btn-group" data-toggle="buttons-radio">
<button class="btn" disabled><%=I18n.t('fotos.pictures_per_site')%></button>
<% for i in 0..@pppage_array.size-1 %>
<a class="btn" href="<%= gallery_path @gallery, {:pppage => i} %>"><%=@pppage_array[i]%></a>
<% end %>
</div>
</div>
</div>
</div>
<div style="clear:both"></div>
<div class="fluid-row" style="margin-bottom:20px">
<!-- modal-gallery is the modal dialog used for the image gallery -->
<div id="modal-gallery" class="modal hide fade modal-gallery modal-fullscreen modal-loading" tabindex="-1">
<div class="modal-header">
@@ -21,15 +48,15 @@
</div>
<div class="modal-body"><div class="modal-image"></div></div>
<div class="modal-footer">
<a class="btn btn-primary modal-next">Next <i class="icon-arrow-right icon-white"></i></a>
<a class="btn btn-info modal-prev"><i class="icon-arrow-left icon-white"></i> Previous</a>
<a class="btn btn-success modal-play modal-slideshow" data-slideshow="5000"><i class="icon-play icon-white"></i> Slideshow</a>
<a class="btn btn-info modal-prev"><i class="icon-arrow-left icon-white"></i></a>
<a class="btn btn-primary modal-next"><i class="icon-arrow-right icon-white"></i></a>
<a class="btn btn-success modal-play modal-slideshow" data-slideshow="5000"><i class="icon-play icon-white"></i> <%=I18n.t('fotos.slideshow')%></a>
<a class="btn modal-download" target="_blank"><i class="icon-download"></i> Download</a>
</div>
</div>
<div id="gallery" data-toggle="modal-gallery" data-target="#modal-gallery">
<% @gallery.fotos.each do |f| %>
<% @fotos.each do |f| %>
<a href="<%= f.datei.resized.url%>" title="<%=f.title%>" data-gallery="gallery">
<%=image_tag(f.datei.thumb.url,{:class=>"img-polaroid"}) %></a>
@@ -37,7 +64,8 @@
<% end %>
</div>
</br>
</div>
<%= render 'layouts/pretty_toolbar' %>

View File

@@ -3,3 +3,7 @@ de:
galleries: "Bildergalerien"
new-gallery: "neue Galerie"
bilder: "Bilder"
prev: "Vorherige"
next: "Nächste"
slideshow: "Diaschau"
pictures_per_site: "Bilder pro Seite"

View File

@@ -3,3 +3,7 @@ en:
galleries: "Picture Gallery"
new-gallery: "new gallery"
bilder: "pictures"
prev: "Previous"
next: "Next"
slideshow: "Slideshow"
pictures_per_site: "Pictures per site"