rerouting. deizzzzign

This commit is contained in:
Espen Antonsen 2009-06-11 13:05:09 +02:00
parent 6ef0ac7424
commit 6509900227
19 changed files with 331 additions and 120 deletions

View file

@ -27,7 +27,7 @@ class AlbumsController < ApplicationController
end
def show
@album = Album.find( params[:id])
@album = Album.find_by_title( params[:id])
respond_to do |format|
format.html
format.json { render :json => @album }

View file

@ -11,7 +11,7 @@ class CollectionsController < ApplicationController
end
def show
@collection = Collection.find( params[:id])
@collection = Collection.find_by_title( params[:id] )
respond_to do |format|
format.html
format.json { render :json => @collection }

View file

@ -4,13 +4,13 @@ class PhotosController < ApplicationController
def index
if params[:tag_id]
@photos = Tag.find_by_title( params[:tag_id] ).photos
@photos = Tag.find_by_title( params[:tag_id] ).photos.find(:all, :order => "Photos.Id ASC")
elsif params[:album_id]
@photos = Album.find( params[:album_id]).photos.find(:all)
@photos = Album.find_by_title( params[:album_id]).photos.find(:all, :order => "Photos.Id ASC")
elsif params[:q]
@photos = Photo.find(:all, :limit => 20, :conditions => [ "Photos.description LIKE :q OR Photos.title LIKE :q OR Photos.Id IN ( SELECT Photo_Id FROM Photo_Tags LEFT OUTER JOIN Tags ON Photo_Tags.Tag_Id = Tags.Id WHERE Tags.Title LIKE :q) ", { :q => '%' + params[:q] + '%' } ], :include => :album )
@photos = Photo.find(:all, :limit => 20, :conditions => [ "Photos.description LIKE :q OR Photos.title LIKE :q OR Photos.Id IN ( SELECT Photo_Id FROM Photo_Tags LEFT OUTER JOIN Tags ON Photo_Tags.Tag_Id = Tags.Id WHERE Tags.Title LIKE :q) ", { :q => '%' + params[:q] + '%' } ], :include => :album, :order => "Photos.Id ASC" )
else
@photos = Photo.find(:all)
@photos = Photo.find(:all, :order => "Photos.Id ASC")
end
respond_to do |format|
format.html
@ -21,7 +21,7 @@ class PhotosController < ApplicationController
def untouched
if params[:album_id]
@album = Album.find( params[:album_id])
@album = Album.find_by_title( params[:album_id])
@photos = @album.photos.untouched
else
@photos = Photo.untouched()
@ -34,7 +34,12 @@ class PhotosController < ApplicationController
end
def show
@photo = Photo.find( params[:id])
@photo = Photo.find( params[:id] )
previous_rs = Photo.previous( @photo.id, @photo.album )
@previous = previous_rs.first if !previous_rs.empty?
next_rs = Photo.next( @photo.id, @photo.album )
puts next_rs.inspect
@next = next_rs.first if !next_rs.empty?
respond_to do |format|
format.html
format.json { render :json => @photo }
@ -47,7 +52,7 @@ class PhotosController < ApplicationController
end
def upload
@album = Album.find( params[:album_id])
@album = Album.find_by_title( params[:album_id])
end
def create

View file

@ -1,4 +1,25 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def breadcrumbs(sep = "/", include_home = true)
levels = request.path.split('?')[0].split('/')
levels.delete_at(0)
#links = "You are here: "
links = content_tag('a', "HOME", :href => "/") if include_home
nocrumb = ["collections", "albums", "photos", "tags"]
levels.each_with_index do |level, index|
level = level.gsub(/[0-9]+-/,"") if levels[index-1] == "photos"
level = level.gsub("-", " ")
if index+1 == levels.length
links += " #{sep} #{level.upcase}" unless nocrumb.include?(level)
else
links += " #{sep} #{content_tag('a', level.upcase, :href => '/'+levels[0..index].join('/'))}" unless nocrumb.include?(level)
end
end
content_tag("div", content_tag("p", links ), :id => "breadcrumb")
end
end

View file

@ -14,6 +14,10 @@ class Album < ActiveRecord::Base
named_scope :untouched, :conditions => "Albums.Id IN ( SELECT DISTINCT Photos.Album_Id FROM Photos WHERE Photos.description IS NULL AND Photos.Id NOT IN ( SELECT Photo_ID FROM Photo_Tags) )"
def to_param
title.gsub(/[^a-z0-9]+/i, '-')
end
def ensure_path

View file

@ -2,4 +2,8 @@ class Collection < ActiveRecord::Base
has_many :collection_albums
has_many :albums, :through => :collection_albums
end
def to_param
title.gsub(/[^a-z0-9]+/i, '-')
end
end

View file

@ -18,6 +18,12 @@ class Photo < ActiveRecord::Base
#attr_protected :path
named_scope :untouched, :conditions => "Photos.description IS NULL AND Photos.Id NOT IN ( SELECT Photo_ID FROM Photo_Tags)", :include => :album
named_scope :previous, lambda { |p,a| { :conditions => ["id < :id AND Album_Id = :album ", { :id => p, :album => a } ], :limit => 1, :order => "Id DESC"} }
named_scope :next, lambda { |p,a| { :conditions => ["id > :id AND Album_Id = :album ", { :id => p, :album => a } ], :limit => 1, :order => "Id ASC"} }
def to_param
id.to_s + '-' + title.gsub(/[^a-z0-9]+/i, '-')
end
def path_original_public
return APP_CONFIG[:photos_path_public] + self.path

View file

@ -11,10 +11,8 @@ class Tag < ActiveRecord::Base
end
def to_param
#{ }"#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}"
#id.to_s+'-'+name.downcase.gsub(/[^a-z0-9]+/i, '-')
#id.to_s+'-'+name.downcase.gsub(' ', '-')
self.title
#id.to_s+'-'+
title.downcase.gsub(/[^a-z0-9]+/i, '-')
end
protected

View file

@ -1,5 +1 @@
<p><%= link_to album.title, album %>
<div id="photos">
<%= render :partial => album.photos.find(:all, :limit => 2) %>
</div>
</p>
<p><%= render :partial => "photos/thumb", :locals => {:photo => album.photos.find(:first) } %></p>

View file

@ -1,7 +1,17 @@
<h1><%= @album.title %></h1>
<% for photo in @album.photos %>
<%= link_to image_tag( photo.path_modified_public("album") ), photo %>
<% end %>
<h2><%= @album.title %></h2>
<div id="multipleimages">
<table>
<% count = 0.0 %>
<% for photo in @album.photos.find(:all, :order => "Id ASC") %>
<% count += 1%>
<% if count == 1 || ( (count-1) / 4.0 == ( (count-1) / 4.0).to_i ) %><tr><% end %>
<td><%= link_to image_tag( photo.path_modified_public("album") ), [@album.collections.first, @album, photo] %></td>
<% if count / 4.0 == (count / 4.0).to_i %></tr><% end %>
<% end %>
</table>
</div>
<p><%= @album.description %></p>
<% if has_permission?("see_album_note") %>
<p><%= @album.note %></p>

View file

@ -1,5 +1,9 @@
<h1>Collections</h1>
<h2>Collections</h2>
<div id="multipleimages">
<% for collection in @collections %>
<%= link_to collection.title, collection %>
<%= render :partial => collection.albums %>
<% end %>
<div class="thumb">
<h3><%= link_to collection.title, collection %></h3>
<%= render :partial => collection.albums.find(:first) %>
</div>
<% end %>
</div>

View file

@ -1,8 +1,21 @@
<h1><%= h @collection.title %></h1>
<h2><%= h @collection.title %></h2>
<p><%= h @collection.description %></p>
<%= render :partial => @collection.albums %>
<% for album in @collection.albums %>
<div class="row">
<div class="title">
<%= render :partial => "photos/thumb", :locals => {:photo => album.photos.first } %>
<p><%= link_to album.title, collection_album_path(@collection, album) %></p>
</div>
<div class="image">
<%= render :partial => "photos/thumb", :collection => album.photos.find(:all, :limit => 5, :offset => 1), :as => :photo %>
</div>
</div>
<% end %>
<div style="clear:both;">
<% if has_role?("admin") %>
<br /><%= link_to "Update collection", edit_collection_path(@collection) %>
<% end %>
<br /><%= link_to "All collections", collections_path %>
<br /><%= link_to "All collections", collections_path %>
</div>

View file

@ -1,16 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Gallery admin</title>
</head>
<body>
<%= yield%>
</body>
</html>

View file

@ -1,19 +1,38 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ImageGallery</title>
<%= yield :head %>
<%= stylesheet_link_tag 'application' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
<div id="container">
<div id="header">
<p class="links">
<%= breadcrumbs %>
</p>
<h1>ImageGallery</h1>
<form action="/photos" method="get" id="search">
<input type="text" name="q" class="textfie.d"/>
<input type="submit" value="S&oslash;k" class="button" />
</form>
<hr class="seperator" />
</div>
<div id="content">
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</div>
<div id="footer">
<hr class="seperator" />
&copy; Gallery without a name.
</div>
</div>
<%= javascript_include_tag 'jquery-1.3.2.js', 'application' %>
<%= yield :javascript %>

View file

@ -1,4 +0,0 @@
<li>
<a href="<%= photo.path_modified_public("large") %>" title="<%= photo.title %>">
<%= image_tag photo.path_modified_public("album"), { :id => 'thumb_' + photo.id.to_s } %></a>
</li>

View file

@ -1 +1 @@
<%= image_tag photo.public_path_modified("thumb") %>
<%= link_to ( image_tag photo.path_modified_public("album"), { :id => 'thumb_' + photo.id.to_s } ), photo_path(photo) %>

View file

@ -1,5 +1,21 @@
<h1><%= @photo.title%></h1>
<%= image_tag @photo.path_modified_public("large") %>
<div id="fullimage">
<div id="navigation">
<p class="links">
<% unless @previous.nil?%>
<%= link_to "Previous", [ @photo.album.collections.first, @photo.album, @previous] %>
<% unless @next.nil? %>
|
<% end %>
<% end %>
<% unless @next.nil? %>
<%= link_to "Next", [ @photo.album.collections.first, @photo.album, @next] %>
<% end %>
</p>
</div>
<p><%= image_tag @photo.path_modified_public("large") %></p>
</div>
<br/>
Tagged with: <%= @photo.tag_list %>

View file

@ -4,16 +4,21 @@ ActionController::Routing::Routes.draw do |map|
map.authenticate "authenticate", :controller => "user_sessions", :action => "create"
map.logout "logout", :controller => "user_sessions", :action => "destroy"
map.resources :photos,
:collection => { :untouched => :get, :edit_multiple => :post, :update_multiple => :put, :upload => :get }
map.resources :albums, :collection => { :untouched => :get} do |album|
album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get }, :shallow => true
map.resources :photos, :collection => { :untouched => :get, :edit_multiple => :post, :update_multiple => :put, :upload => :get }
map.resources :albums, :collection => { :untouched => :get, } do |album|
album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get }
end
map.resources :collections
map.resources :collections do |collection|
collection.resources :albums do |album|
album.resources :photos
#album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get }
end
end
map.resources :tags, :has_many => [ :photos, :albums ], :shallow => true
map.resources :users, :controller => "admin/users"
map.root :controller => "collections"
end
end

View file

@ -1,64 +1,194 @@
.galleria_container {
margin:0 auto;
text-align: center;
}
/* @group Reset */
#thumbstrip {
/* required settings */
position:relative;
overflow:hidden;
width: 602px;
height: 85px;
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {margin:0;padding:0;border:0;font-weight:inherit;font-style:inherit;font-size:100%;font-family:inherit;vertical-align:baseline;}
body {line-height:1.5;}
table {border-collapse:separate;border-spacing:0;}
caption, th, td {text-align:left;font-weight:normal;}
table, td, th {vertical-align:middle;}
blockquote:before, blockquote:after, q:before, q:after {content:"";}
blockquote, q {quotes:"" "";}
a img {border:none;}
/* @end */
/* @group Typography */
body {font-size:75%;color:#222;background:#fff;font-family:"Helvetica Neue", Arial, Helvetica, sans-serif;}
h1, h2, h3, h4, h5, h6 {font-weight:normal;}
h1 {font-size:3em;line-height:1;margin-bottom:0.5em;}
h2 {font-size:2em;margin-bottom:0.75em;}
h3 {font-size:1.5em;line-height:1;margin-bottom:1em;}
h4 {font-size:1.2em;line-height:1.25;margin-bottom:1.25em;}
h5 {font-size:1em;font-weight:bold;margin-bottom:1.5em;}
h6 {font-size:1em;font-weight:bold;}
h1 img, h2 img, h3 img, h4 img, h5 img, h6 img {margin:0;}
p {margin:0 0 1.5em;}
p img.left {float:left;margin:1.5em 1.5em 1.5em 0;padding:0;}
p img.right {float:right;margin:1.5em 0 1.5em 1.5em;}
a:focus, a:hover {color:#000;}
a {color:#009;text-decoration:underline;}
blockquote {margin:1.5em;color:#666;font-style:italic;}
strong {font-weight:bold;}
em, dfn {font-style:italic;}
dfn {font-weight:bold;}
sup, sub {line-height:0;}
abbr, acronym {border-bottom:1px dotted #666;}
address {margin:0 0 1.5em;font-style:italic;}
del {color:#666;}
pre {margin:1.5em 0;white-space:pre;}
pre, code, tt {font:1em 'andale mono', 'lucida console', monospace;line-height:1.5;}
li ul, li ol {margin:0 1.5em;}
ul, ol {margin:0 1.5em 1.5em 1.5em;}
ul {list-style-type:disc;}
ol {list-style-type:decimal;}
dl {margin:0 0 1.5em 0;}
dl dt {font-weight:bold;}
dd {margin-left:1.5em;}
table {margin-bottom:1.4em;width:100%;}
th {font-weight:bold;}
thead th {background:#c3d9ff;}
th, td, caption {padding:4px 10px 4px 5px;}
tr.even td {background:#e5ecf9;}
tfoot {font-style:italic;}
caption {background:#eee;}
.small {font-size:.8em;margin-bottom:1.875em;line-height:1.875em;}
.large {font-size:1.2em;line-height:2.5em;margin-bottom:1.25em;}
.hide {display:none;}
.quiet {color:#666;}
.loud {color:#000;}
.highlight {background:#ff0;}
.added {background:#060;color:#fff;}
.removed {background:#900;color:#fff;}
.first {margin-left:0;padding-left:0;}
.last {margin-right:0;padding-right:0;}
.top {margin-top:0;padding-top:0;}
.bottom {margin-bottom:0;padding-bottom:0;}
/* @end */
#container {
width: 950px;
margin: 0 auto;
padding: 0;
background-color: #000000;
}
#thumbstrip ul {
/* this cannot be too large */
width:20000em;
position:absolute;
list-style-type: none;
margin: 0;
padding: 0;
}
/*
a single item. must be floated on horizontal scrolling
typically this element is the one that *you* will style
the most.
*/
LABEL.big {
font-weight: bold;
div#header h1 {
text-transform: uppercase;
font-weight: bold;
letter-spacing: 10px;
margin: 10px 0 0 0;
float: left;
}
INPUT.big {
font-size: 22px;
div#header {
padding: 10px 0;
}
#thumbstrip ul li {
float:left;
background: black;
padding: 5px;
margin: 0;
cursor: pointer;
div#content {
clear: both;
}
#photo_large img {
div#footer {
clear: both;
}
form#search {
margin: 5px 0;
padding: 5px 10px;
float: right;
}
form#search input {
padding: 5px 5px 5px;
font-size: 13px;
}
form#search input.textfield {
width: 400px;
border: 1px solid black;
}
SPAN.tagMatches {
margin-left: 10px;
p.links {
margin: 5px 0;
text-transform: uppercase;
}
p.links a {
text-decoration: none;
}
p.links a:hover {
text-decoration: underline;
}
hr.seperator {
clear: both;
border: none;
background-color: #ddd;
height: 1px;
}
div.thumb {
background-color: #eee;
float: left;
padding: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
div.thumb h3 {
text-transform: uppercase;
font-weight: bold;
font-size: 13px;
}
div.thumb h3 a {
color: black;
text-decoration: none;
}
div.thumb h3 a:hover {
border-bottom: 1px solid #999;}
div.thumb img {
width: 200px;
height: 200px;
}
div.thumb p {
text-align: center;
margin: 0;
}
.row {
clear: both;
padding-bottom: 40px;
}
SPAN.tagMatches SPAN {
padding: 2px;
margin-right: 4px;
background-color: #0000AB;
color: #fff;
cursor: pointer;
img {
}
.row div.image {
margin: 10px 0 0;
float: left;
}
.row div.image img {
margin: 0 0 0 10px;
}
div.title {
margin: 10px 0 0;
border-right: 1px solid #bbb;
display: block;
float: left;
width: 240px;
}
.row div.title img, .row div.image img {
width: 100px;
height: 100px;
}
div.title img {
float: right;
padding-right: 10px;
width: 100px;
}
div.title p {
font-weight: bold;
font-size: 18px;
}
div#header h1 p {
display: inline;
font-size: 12px;
letter-spacing: normal;
font-weight: normal;
}
td {
vertical-align: bottom;
}