From 0fb47748db90154f2052747503a1ab51b3e89f11 Mon Sep 17 00:00:00 2001
From: Espen Antonsen
Date: Tue, 30 Jun 2009 21:24:06 +0200
Subject: [PATCH] menu on top. not very nice but works. tags as arrays not
strings. fixed tagging for album. shows all tags for photos in album now
---
app/controllers/tags_controller.rb | 6 +++++-
app/helpers/application_helper.rb | 4 ++--
app/models/album.rb | 18 +++++++++++++-----
app/models/photo.rb | 4 ++--
app/views/albums/_form.html.erb | 2 +-
app/views/albums/show.html.erb | 6 +++++-
app/views/collections/index.html.erb | 2 +-
app/views/layouts/application.html.erb | 8 ++++++++
app/views/photos/_thumb.html.erb | 2 +-
app/views/photos/index.html.erb | 1 +
app/views/photos/show.html.erb | 6 +++---
app/views/photos/untouched.html.erb | 4 +---
app/views/tags/index.html.erb | 2 +-
config/environment.rb | 1 +
public/stylesheets/application.css | 11 +++++++++++
15 files changed, 56 insertions(+), 21 deletions(-)
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index a46d724..d299358 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -1,7 +1,11 @@
class TagsController < ApplicationController
def index
- @tags = Tag.find( :all)
+ if params[:album_id]
+ @tags = Album.find( params[:album_id] ).photo_tags
+ else
+ @tags = Tag.find( :all, :order => 'title')
+ end
respond_to do |format|
format.html
format.json { render :json => @tags }
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index f9fc2d1..6186ac1 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -14,12 +14,12 @@ module ApplicationHelper
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)
+ #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("p", links, :id => "breadcrumb")
+ content_tag("div", links, :id => "breadcrumb")
end
end
diff --git a/app/models/album.rb b/app/models/album.rb
index 12e9d44..dae27e2 100644
--- a/app/models/album.rb
+++ b/app/models/album.rb
@@ -49,6 +49,7 @@ class Album < ActiveRecord::Base
else
# combine arrays if they have identical tags.
# Will remove tags that are only tagged to one photo
+ #tags = tags & photo_tags
tags = tags & photo_tags
end
}
@@ -57,27 +58,34 @@ class Album < ActiveRecord::Base
def tags=(tags)
tags = tags.split(" ").sort
- current_tags = ( self.tags.nil? ? [] : self.tags.split(" ") )
+ current_tags = ( self.tags.nil? ? [] : self.tags.map{|tag|tag.title} )
return if tags == self.tags
# find tags that should be removed from this album - thus remove from all photos in album
# i.e. tags listed in self.tag_list but no in parameter tags
#current_tags.map {|tag|tag if !tags.include?(tag) }.compact
(current_tags - tags).each { |tag|
- #puts "remove #{tag}"
self.photos.each {|photo|
photo.untag( tag )
}
}
# add universial tags to all photos in album
- tags.each do |tag|
- #puts "tag photos with #{tag}" if !current_tags.include?( tag )
+ (tags - current_tags).each do |tag|
self.photos.each { |photo|
- photo.tag( tag ) if !current_tags.include?( tag ) # no need to re-tag
+ photo.tag( tag )
}
end
end
+
+ def photo_tags
+ tags = Array.new
+ self.photos.each{ |photo|
+ tags = tags | photo.tags
+ }
+ return tags
+ end
+
protected
private
diff --git a/app/models/photo.rb b/app/models/photo.rb
index 04c6420..bb8c38d 100644
--- a/app/models/photo.rb
+++ b/app/models/photo.rb
@@ -92,7 +92,7 @@ class Photo < ActiveRecord::Base
img.thumbnail(210) do |thumb|
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_preview" + self.extension
end
- img.thumbnail(950) do |thumb|
+ img.thumbnail(800) do |thumb|
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_single" + self.extension
end
end
@@ -127,7 +127,7 @@ class Photo < ActiveRecord::Base
self.longitude = photo.GPSLongitude if self.longitude.nil?
self.latitude = photo.GPSLatitude if self.latitude.nil?
self.title = photo.DocumentName if self.title.nil?
- self.description = photo.ImageDescription if self.description.nil? || photo.ImageDescription == 'Exif_JPEG_PICTURE'
+ self.description = photo.ImageDescription if self.description.nil? || photo.ImageDescription != 'Exif_JPEG_PICTURE'
self.tag_list = (self.tags.empty? ? "" : self.album.tag_list) + " " + (photo.Keywords.nil? ? "" : photo.Keywords.to_a.map { |tag| tag.gsub(" ", "_") }.join(" "))
end
diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb
index 8cfa749..8d31bd2 100644
--- a/app/views/albums/_form.html.erb
+++ b/app/views/albums/_form.html.erb
@@ -16,7 +16,7 @@
<%= form.text_area :note %>
<%= form.label :tags %>
-<%= form.text_field :tags, { :autocomplete => "off", :class => 'tag_list'} %>
+<%= form.text_field :tags, { :autocomplete => "off", :class => 'tag_list', :value => @album.tags.map{|tag|tag.title}.join(" ") } %>
<% if @album.path? %>
diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb
index 97999a3..121f4de 100644
--- a/app/views/albums/show.html.erb
+++ b/app/views/albums/show.html.erb
@@ -13,7 +13,11 @@
<%= @album.description %>
-Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, album_tag_photos_path(@album, tag) ) + " " } unless @album.tags.nil? %>
+Tagged with:
+<% for tag in @album.photo_tags.map{|tag|tag.title}.sort %>
+<%= link_to tag, album_tag_photos_path(@album, tag )%>
+<% end %>
+
<% if has_role?("admin") %>
<%= @album.address %>
diff --git a/app/views/collections/index.html.erb b/app/views/collections/index.html.erb
index 5b87acf..6c24672 100644
--- a/app/views/collections/index.html.erb
+++ b/app/views/collections/index.html.erb
@@ -10,6 +10,6 @@
<% content_for :action_links do %>
<% if has_role?("admin") %>
-<%= link_to "New collection", new_collection_path %>
+<%= link_to "New collection", new_collection_path %>
<% end %>
<% end %>
\ No newline at end of file
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 3a13867..e4af6f7 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -12,7 +12,15 @@