albums now paginate

master
Coleman 2008-06-27 20:28:18 -05:00
parent 0264081c08
commit 448f99644c
7 changed files with 60 additions and 38 deletions

View File

@ -1,6 +1,14 @@
class Albums < Application
def index
@albums = Album.find(:all)
acount = Album.count
@page = params[:page].to_i
per_page = 12
@page_count = (acount.to_f / per_page.to_f).ceil.to_i
@page = 0 if @page >= @page_count
@url_key = :albums
@albums = Album.find(:all, :limit => per_page, :offset => (@page * per_page), :order => 'name ASC')
@tags = Album.popular_tags(30)
display @albums
end

View File

@ -5,6 +5,7 @@ class News < Application
per_page = 5
@page_count = (ncount.to_f / per_page.to_f).ceil.to_i
@page = 0 if @page >= @page_count
@url_key = :news
@page_title = 'Blogging!'
@news = Page.find :all, :limit => per_page, :offset => (@page * per_page), :conditions => [ 'published = ?', true ], :order => 'created_at DESC'
@oldest_date = Page.find(:first, :order => 'created_at ASC').created_at rescue nil

View File

@ -9,7 +9,6 @@ class Pages < Application
def show
@page = Page.find_by_name(params[:id].gsub(/_/, ' '))
if @page.nil?
flash[:error] = "That page does not exist. You can now create it."
redirect url(:new_page, :new_name => params[:id])
else
@comments = @page.comments
@ -23,7 +22,7 @@ class Pages < Application
only_provides :html
@page = Page.new
if params[:new_name]
flash.now[:notice] = 'That page does not exist, but you can create it.'
flash.now[:error] = 'That page does not exist, but you can create it.'
@page.name = params[:new_name].gsub(/_/, ' ')
end
render

View File

@ -9,19 +9,29 @@
<% throw_content :for_stylesheet do -%>
.photo_collection {
word-wrap: break-word;
}
.photo_collection_item {
float: right;
word-wrap: break-word;
width: 170px;
min-height: 140px;
max-height: 200px;
margin: 5px;
margin-top: 15px;
padding: 5px;
text-align: center;
border: 1px solid #BBB;
float: left;
position: relative;
}
.col_1 {
margin-left: 10px;
}
.col_2 {
margin-left: 10px;
}
.col_0 {
margin-left: 10px;
}
<% end -%>
@ -29,12 +39,14 @@
<% if @albums.empty? -%>
<p><em><strong>There were no albums found!</strong></em></p>
<% else -%>
<div class="photo_collection">
<% @albums.each do |album| -%>
<div class="photo_collection_item">
<% @albums.each_with_index do |album, index| -%>
<div class="photo_collection_item col_<%= (index + 1) % 3 -%>">
<p><a href="<%= url(:album, :id => album.name.gsub(/ /, '_')) -%>"><%= album.name -%></a> (<%= album.photos.size -%> photos)</p>
<% if album.album_thumbnail -%><a href="<%= url(:album, :id => album.name.gsub(/ /, '_')) -%>"><img src="<%= thumbnail_photo_url(album.album_thumbnail) -%>" /></a><% end -%>
</div>
<% end -%>
</div>
<br style='clear:both;' />
<%= partial 'shared/pagination_links' %>
<% end -%>

View File

@ -1,4 +1,5 @@
<% throw_content :for_sidebar do -%>
<% if allowed_to?(:create_albums) -%><a href="<%= url(:new_album) -%>"><img src="/images/folder-new.png" alt="Create Album" /> Create An Album</a><br /><% end -%>
<% if allowed_to?(:edit_album) -%><a href="<%= url(:edit_album, :id => @album.name.gsub(/ /, '_')) -%>" rel="nofollow"><img src="/images/document-save.png" /> Edit Album</a><br /><% end %>
<% if allowed_to?(:delete_albums) -%><a href="<%= url(:delete_album, :id => @album.name.gsub(/ /, '_')) -%>" onclick="if(!confirm('Are you sure you want to delete this album?')){return false;}"><img src="/images/edit-delete.png" /> Destroy Album</a><br /><% end %>
<% if allowed_to?(:upload_images) -%><a href="<%= url(:new_photo, :photo => { :album_id => @album.id }) -%>"><img src="/images/emblem-photos.png" /> Upload Image</a><br /><% end %>

View File

@ -26,30 +26,6 @@
<%= partial 'pages/page', :with => [ page ] %>
<% end -%>
<% if @page_count > 0 -%>
<div id="pagination_links">
<% if @page > 0 -%>
<a href="<%= url(:news, :page => 0) -%>"><img src="/images/go-first.png" alt="First Page" /></a> <a href="<%= url(:news, :page => 0) -%>"><img src="/images/go-previous.png" alt="Previous Page" /></a>
<% end -%>
<% if @page_count > 1 -%>
<% (@page - 4).upto(@page - 1) do |i| ; next if i < 0 -%>
<a href="<%= url(:news, :page => i) -%>"><%= i + 1 -%></a>
<% end %>
<%= @page + 1 %>
<% (@page + 1).upto(@page + 4) do |i| ; next if i >= @page_count -%>
<a href="<%= url(:news, :page => i) -%>"><%= i + 1 -%></a>
<% end %>
<% if @page < @page_count - 1 -%>
<a href="<%= url(:news, :page => @page + 1) -%>"><img src="/images/go-next.png" alt="Next Page" /></a> <a href="<%= url(:news, :page => @page_count - 1) -%>"><img src="/images/go-last.png" alt="Last Page" /></a>
<% end -%>
<% end -%>
</div>
<% end -%>
<%= partial 'shared/pagination_links' %>
<% end -%>

View File

@ -0,0 +1,25 @@
<% if @page_count > 0 -%>
<div id="pagination_links">
<% if @page > 0 -%>
<a href="<%= url(@url_key, :page => 0) -%>"><img src="/images/go-first.png" alt="First Page" /></a> <a href="<%= url(@url_key, :page => 0) -%>"><img src="/images/go-previous.png" alt="Previous Page" /></a>
<% end -%>
<% if @page_count > 1 -%>
<% (@page - 5).upto(@page - 1) do |i| ; next if i < 0 -%>
<a href="<%= url(@url_key, :page => i) -%>"><%= i + 1 -%></a>
<% end %>
<%= @page + 1 %>
<% (@page + 1).upto(@page + 5) do |i| ; next if i >= @page_count -%>
<a href="<%= url(@url_key, :page => i) -%>"><%= i + 1 -%></a>
<% end %>
<% if @page < @page_count - 1 -%>
<a href="<%= url(@url_key, :page => @page + 1) -%>"><img src="/images/go-next.png" alt="Next Page" /></a> <a href="<%= url(@url_key, :page => @page_count - 1) -%>"><img src="/images/go-last.png" alt="Last Page" /></a>
<% end -%>
<% end -%>
</div>
<% end -%>