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

This commit is contained in:
Espen Antonsen 2009-06-30 21:24:06 +02:00
parent fb8d2f4eb0
commit 0fb47748db
15 changed files with 56 additions and 21 deletions

View file

@ -1,7 +1,11 @@
class TagsController < ApplicationController class TagsController < ApplicationController
def index 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| respond_to do |format|
format.html format.html
format.json { render :json => @tags } format.json { render :json => @tags }

View file

@ -14,12 +14,12 @@ module ApplicationHelper
level = level.gsub(/^[0-9]+\-/,"") #if levels[index-1] == "photos" level = level.gsub(/^[0-9]+\-/,"") #if levels[index-1] == "photos"
level = level.gsub("-", " ") level = level.gsub("-", " ")
if index+1 == levels.length if index+1 == levels.length
links += " #{sep} #{level.upcase}" unless nocrumb.include?(level) #links += " #{sep} #{level.upcase}" unless nocrumb.include?(level)
else else
links += " #{sep} #{content_tag('a', level.upcase, :href => '/'+levels[0..index].join('/'))}" unless nocrumb.include?(level) links += " #{sep} #{content_tag('a', level.upcase, :href => '/'+levels[0..index].join('/'))}" unless nocrumb.include?(level)
end end
end end
content_tag("p", links, :id => "breadcrumb") content_tag("div", links, :id => "breadcrumb")
end end
end end

View file

@ -49,6 +49,7 @@ class Album < ActiveRecord::Base
else else
# combine arrays if they have identical tags. # combine arrays if they have identical tags.
# Will remove tags that are only tagged to one photo # Will remove tags that are only tagged to one photo
#tags = tags & photo_tags
tags = tags & photo_tags tags = tags & photo_tags
end end
} }
@ -57,27 +58,34 @@ class Album < ActiveRecord::Base
def tags=(tags) def tags=(tags)
tags = tags.split(" ").sort 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 return if tags == self.tags
# find tags that should be removed from this album - thus remove from all photos in album # 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 # 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.map {|tag|tag if !tags.include?(tag) }.compact
(current_tags - tags).each { |tag| (current_tags - tags).each { |tag|
#puts "remove #{tag}"
self.photos.each {|photo| self.photos.each {|photo|
photo.untag( tag ) photo.untag( tag )
} }
} }
# add universial tags to all photos in album # add universial tags to all photos in album
tags.each do |tag| (tags - current_tags).each do |tag|
#puts "tag photos with #{tag}" if !current_tags.include?( tag )
self.photos.each { |photo| self.photos.each { |photo|
photo.tag( tag ) if !current_tags.include?( tag ) # no need to re-tag photo.tag( tag )
} }
end end
end end
def photo_tags
tags = Array.new
self.photos.each{ |photo|
tags = tags | photo.tags
}
return tags
end
protected protected
private private

View file

@ -92,7 +92,7 @@ class Photo < ActiveRecord::Base
img.thumbnail(210) do |thumb| img.thumbnail(210) do |thumb|
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_preview" + self.extension thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_preview" + self.extension
end 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 thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_single" + self.extension
end end
end end
@ -127,7 +127,7 @@ class Photo < ActiveRecord::Base
self.longitude = photo.GPSLongitude if self.longitude.nil? self.longitude = photo.GPSLongitude if self.longitude.nil?
self.latitude = photo.GPSLatitude if self.latitude.nil? self.latitude = photo.GPSLatitude if self.latitude.nil?
self.title = photo.DocumentName if self.title.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(" ")) self.tag_list = (self.tags.empty? ? "" : self.album.tag_list) + " " + (photo.Keywords.nil? ? "" : photo.Keywords.to_a.map { |tag| tag.gsub(" ", "_") }.join(" "))
end end

View file

@ -16,7 +16,7 @@
<%= form.text_area :note %><br /> <%= form.text_area :note %><br />
<%= form.label :tags %><br /> <%= form.label :tags %><br />
<%= form.text_field :tags, { :autocomplete => "off", :class => 'tag_list'} %><br /> <%= form.text_field :tags, { :autocomplete => "off", :class => 'tag_list', :value => @album.tags.map{|tag|tag.title}.join(" ") } %><br />
<br /> <br />
<% if @album.path? %> <% if @album.path? %>

View file

@ -13,7 +13,11 @@
</div> </div>
<p><%= @album.description %></p> <p><%= @album.description %></p>
<p>Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, album_tag_photos_path(@album, tag) ) + " " } unless @album.tags.nil? %></p> <p>Tagged with:
<% for tag in @album.photo_tags.map{|tag|tag.title}.sort %>
<%= link_to tag, album_tag_photos_path(@album, tag )%>
<% end %>
</p>
<% if has_role?("admin") %> <% if has_role?("admin") %>
<p><%= @album.address %></p> <p><%= @album.address %></p>

View file

@ -10,6 +10,6 @@
<% content_for :action_links do %> <% content_for :action_links do %>
<% if has_role?("admin") %> <% if has_role?("admin") %>
<%= link_to "New collection", new_collection_path %></p> <%= link_to "New collection", new_collection_path %>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -12,7 +12,15 @@
<div id="header"> <div id="header">
<%= breadcrumbs %> <%= breadcrumbs %>
<div id="action_links">
<%= yield :action_links %> <%= yield :action_links %>
<% if current_user %>
Logged in as <%= current_user.name %>
<%= link_to 'Logout', logout_path %>
<% else %>
<%= link_to 'Login', login_path %>
<% end %>
</div>
<h1>ImageGallery</h1> <h1>ImageGallery</h1>
<form action="/photos" method="get" id="search"> <form action="/photos" method="get" id="search">
<input type="text" name="q" class="textfie.d"/> <input type="text" name="q" class="textfie.d"/>

View file

@ -1 +1 @@
<%= link_to (image_tag photo.path_modified_public(defined?(photosize) ? photosize : "album") ), photo_path(photo) %> <%= link_to (image_tag photo.path_modified_public(defined?(photosize) ? photosize : "album") ), [photo.album.collections.first, photo.album, photo] %>

View file

@ -2,4 +2,5 @@
<% content_for :action_links do %> <% content_for :action_links do %>
<%= link_to "Show albums containing photos tagged with #{params[:q]}", albums_path(:q => params[:q]) if params[:q] %> <%= link_to "Show albums containing photos tagged with #{params[:q]}", albums_path(:q => params[:q]) if params[:q] %>
<%= link_to "Show all photos tagged with #{params[:tag_id]}", tag_photos_path(params[:tag_id]) if params[:tag_id] && params[:album_id] %>
<% end %> <% end %>

View file

@ -19,12 +19,12 @@
<p><%= @photo.description %></p> <p><%= @photo.description %></p>
<p>Tagged with: <p>Tagged with:
<% for tag in @photo.tags %> <% for tag in @photo.tags.map{|tag|tag.title}.sort %>
<%= link_to tag.title, tag_photos_path(tag) %> <%= link_to tag, tag_photos_path(tag) %>
<% end %> <% end %>
<% content_for :action_links do %> <% content_for :action_links do %>
<% if has_role?("admin") %> <% if has_role?("admin") %>
<br /><%= link_to "Edit photo", edit_photo_path(@photo) %> <%= link_to "Edit photo", edit_photo_path(@photo) %>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -10,5 +10,3 @@
<% end%> <% end%>
<p><%= f.submit "Submit" %></p> <p><%= f.submit "Submit" %></p>
<% end %> <% end %>
<br /><%= link_to "Back to #{@album.title}", @album %>

View file

@ -1,4 +1,4 @@
<h1>Tags</h1> <h1>Tags</h1>
<% for tag in @tags %> <% for tag in @tags %>
<p><%= link_to tag.title, tag_photos_path(tag) %></p> <%= link_to tag.title, tag_photos_path(tag) %>&nbsp;
<% end %> <% end %>

View file

@ -13,6 +13,7 @@ Rails::Initializer.run do |config|
config.gem 'mime-types', :lib => 'mime/types' config.gem 'mime-types', :lib => 'mime/types'
config.gem "image_science" config.gem "image_science"
config.gem "mini_exiftool" config.gem "mini_exiftool"
# config.gem "inline"
config.load_paths += %W( #{RAILS_ROOT}/app/middleware ) config.load_paths += %W( #{RAILS_ROOT}/app/middleware )

View file

@ -81,6 +81,7 @@ div#header h1 {
letter-spacing: 10px; letter-spacing: 10px;
margin: 10px 0 0 0; margin: 10px 0 0 0;
float: left; float: left;
clear: left;
} }
div#header { div#header {
@ -189,6 +190,16 @@ div#header h1 p {
letter-spacing: normal; letter-spacing: normal;
font-weight: normal; font-weight: normal;
} }
DIV#breadcrumb {
float: left;
}
DIV#action_links {
float: right;
clear: right;
}
td { td {
vertical-align: bottom; vertical-align: bottom;
} }