From 467eff11ba79b53607845a4278afc1edd2779021 Mon Sep 17 00:00:00 2001 From: Espen Antonsen Date: Sun, 28 Jun 2009 18:02:19 +0200 Subject: [PATCH] see photos by tag. search photos show albums --- app/controllers/albums_controller.rb | 1 + app/controllers/photos_controller.rb | 16 +++++++++++----- app/views/albums/edit.html.erb | 7 +++++-- app/views/albums/index.html.erb | 21 ++++++++++++++++++--- app/views/albums/new.html.erb | 3 +-- app/views/albums/show.html.erb | 3 ++- app/views/photos/_form.html.erb | 3 +++ app/views/photos/edit_multiple.html.erb | 7 ++++--- app/views/photos/index.html.erb | 6 +++++- app/views/photos/untouched.html.erb | 1 + config/database.yml | 2 +- config/routes.rb | 3 +++ 12 files changed, 55 insertions(+), 18 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index ce800c9..ec61d0d 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -19,6 +19,7 @@ class AlbumsController < ApplicationController def untouched @albums = Album.untouched() + @albums.ea respond_to do |format| format.html format.json { render :json => @albums } diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index b49c267..33945e7 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -3,7 +3,9 @@ class PhotosController < ApplicationController before_filter :require_role_admin, :only => [:untouched, :upload, :new, :create, :edit, :update, :destroy] def index - if params[:tag_id] + if params[:tag_id] && params[:album_id] + @photos = Tag.find_by_title( params[:tag_id] ).photos.find(:all, :conditions => ['photos.album_id = :album', {:album => Album.find(params[:album_id] ) } ], :order => "photos.id ASC") + elsif params[:tag_id] @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, :order => "photos.id ASC") @@ -83,7 +85,7 @@ class PhotosController < ApplicationController @photo = Photo.find( params[:id]) @tags = Tag.find(:all).map { |tag| tag.title }.join('\',\'') end - + def edit_multiple if params[:album_id] @album = Album.find( params[:album_id] ) @@ -107,9 +109,13 @@ class PhotosController < ApplicationController @photos = params[:photos][:photo] @photos.each do |photo_item| photo = Photo.find( photo_item[0] ) - photo.title = photo_item[1][:title] - photo.tag_list = photo_item[1][:tags] - photo.save + if photo_item[1][:_delete] == "1" + photo.destroy + else + photo.title = photo_item[1][:title] + photo.tag_list = photo_item[1][:tags] + photo.save + end end flash[:notice] = "Updated photos!" redirect_to photos_path diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb index 5b77cf8..f9c4fc4 100644 --- a/app/views/albums/edit.html.erb +++ b/app/views/albums/edit.html.erb @@ -6,8 +6,11 @@ <%= f.submit "Update" %> <% end %> + +<% content_for :action_links do %> +<% if has_role?("admin") %>
<%= link_to("Delete album", { :action => "destroy", :id => @album }, :confirm => "Are you sure you want to delete this album?", :method => :delete) %> - -
<%= link_to "All albums", albums_path %> \ No newline at end of file +<% end %> +<% end %> diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index 328438d..95cd78b 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -1,4 +1,19 @@ -

Albums

-<%= render :partial => @albums %> +<% for album in @albums %> +
+
+ <%= render :partial => "photos/thumb", :locals => {:photo => album.photos.first } unless album.photos.empty? %> +

<%= link_to album.title, album %>

+
+
+ <%= render :partial => "photos/thumb", :collection => album.photos.find(:all, :limit => 5, :offset => 1), :as => :photo %> +
+
+<% end %> -
<%= link_to "New Album", new_album_path %> \ No newline at end of file +<% content_for :action_links do %> +<%= link_to "Show just the photos tagged with #{params[:q]}", photos_path(:q => params[:q]) if params[:q] %> +<% if has_role?("admin") %> +<%= " | " if params[:q] %> +<%= link_to "New album", new_album_path() %> +<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb index 90116e4..f609ce5 100644 --- a/app/views/albums/new.html.erb +++ b/app/views/albums/new.html.erb @@ -5,5 +5,4 @@ <%= render :partial => "form", :object => f %> <%= f.submit "Create" %> <% end %> - -
<%= link_to "All albums", albums_path %> \ No newline at end of file + \ No newline at end of file diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index 6872f10..97999a3 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -13,7 +13,7 @@

<%= @album.description %>

-

Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, tag_photos_path(tag) ) + " " } unless @album.tags.nil? %>

+

Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, album_tag_photos_path(@album, tag) ) + " " } unless @album.tags.nil? %>

<% if has_role?("admin") %>

<%= @album.address %>

@@ -27,6 +27,7 @@ <%= link_to "PDF", album_path(@album, :format => 'pdf') %> |  <%= link_to "Edit album", edit_album_path(@album) %> |  <%= link_to "Edit all photos", edit_multiple_album_photos_path(@album) %> |  +<%= link_to "Edit untouched photos", untouched_album_photos_path(@album) %> |  <%= link_to "Add photos", upload_album_photos_path(@album) %> <% end %> <% end %> diff --git a/app/views/photos/_form.html.erb b/app/views/photos/_form.html.erb index a990c71..b0cffdb 100644 --- a/app/views/photos/_form.html.erb +++ b/app/views/photos/_form.html.erb @@ -7,5 +7,8 @@
<%= form.label :tag_list %>
<%= form.text_field :tag_list, { :autocomplete => "off", :class => 'tag_list'} %>
+
+<%= form.label :description %>
+<%= form.text_area :description %>

On disk: ~/<%= @photo.path %>

\ No newline at end of file diff --git a/app/views/photos/edit_multiple.html.erb b/app/views/photos/edit_multiple.html.erb index 27505a1..6d445bf 100644 --- a/app/views/photos/edit_multiple.html.erb +++ b/app/views/photos/edit_multiple.html.erb @@ -1,10 +1,11 @@ <% form_for :photos, :url => update_multiple_photos_path, :html => { :method => :put } do |f| %> <% for photo in @photos %>

-<% f.fields_for photo do |p|%> +<% f.fields_for photo, :index => photo.id do |p|%> + <%= p.check_box :_delete %> <%= render :partial => "photos/thumb", :locals => {:photo => photo } %> - <%= p.text_field :title, :index => photo.id %> - <%= p.text_field :tags, :index => photo.id, :value => photo.tag_list %> + <%= p.text_field :title %> + <%= p.text_field :tags, :value => photo.tag_list %> <% end%>

<% end%> diff --git a/app/views/photos/index.html.erb b/app/views/photos/index.html.erb index 1471314..e1cf9d5 100644 --- a/app/views/photos/index.html.erb +++ b/app/views/photos/index.html.erb @@ -1 +1,5 @@ - \ No newline at end of file + + +<% content_for :action_links do %> +<%= link_to "Show albums containing photos tagged with #{params[:q]}", albums_path(:q => params[:q]) if params[:q] %> +<% end %> \ No newline at end of file diff --git a/app/views/photos/untouched.html.erb b/app/views/photos/untouched.html.erb index 2919768..27505a1 100644 --- a/app/views/photos/untouched.html.erb +++ b/app/views/photos/untouched.html.erb @@ -2,6 +2,7 @@ <% for photo in @photos %>

<% f.fields_for photo do |p|%> + <%= render :partial => "photos/thumb", :locals => {:photo => photo } %> <%= p.text_field :title, :index => photo.id %> <%= p.text_field :tags, :index => photo.id, :value => photo.tag_list %> <% end%> diff --git a/config/database.yml b/config/database.yml index 1224ac0..bf3df02 100644 --- a/config/database.yml +++ b/config/database.yml @@ -3,7 +3,7 @@ development: database: gallery_development username: gallery password: changeme -production: +production: adapter: mysql encoding: utf8 username: photogallery diff --git a/config/routes.rb b/config/routes.rb index a24bba9..a3f4d06 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,9 @@ ActionController::Routing::Routes.draw do |map| map.resources :photos, :collection => { :untouched => :get, :edit_multiple => :post, :update_multiple => :put, :upload => :get } map.resources :albums, :collection => { :untouched => :get, } do |album| + album.resources :tags do |tag| + tag.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get } + end album.resources :photos, :collection => { :untouched => :get, :upload => :get, :edit_multiple => :get } end map.resources :collections do |collection|