diff --git a/README b/README
index 0d40953..934cb95 100644
--- a/README
+++ b/README
@@ -4,8 +4,10 @@ Made by Espen Antonsen
== Requirements
+Tested with Ruby 1.8.6 and Rails 2.3
+
Software
-- FreeIamge (required for Image Science)
+- FreeImage (required for Image_Science)
- ExifTool (required for Mini_EfixTool)
Ruby Gems
diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb
index b882f3c..5f47405 100644
--- a/app/controllers/albums_controller.rb
+++ b/app/controllers/albums_controller.rb
@@ -9,6 +9,15 @@ class AlbumsController < ApplicationController
format.xml { render :xml => @albums }
end
end
+
+ def untouched
+ @albums = Album.untouched()
+ respond_to do |format|
+ format.html
+ format.json { render :json => @albums }
+ format.xml { render :xml => @albums }
+ end
+ end
def show
@album = Album.find( params[:id])
diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb
new file mode 100644
index 0000000..d5b6ef2
--- /dev/null
+++ b/app/controllers/collections_controller.rb
@@ -0,0 +1,60 @@
+class CollectionsController < ApplicationController
+ before_filter :require_user, :only => [:new, :create, :edit, :update, :delete, :destroy]
+
+ def index
+ @collections = Collection.find(:all)
+ respond_to do |format|
+ format.html
+ format.json { render :json => @collections }
+ format.xml { render :xml => @collections }
+ end
+ end
+
+ def show
+ @collection = Collection.find( params[:id])
+ respond_to do |format|
+ format.html
+ format.json { render :json => @collection }
+ format.xml { render :xml => @collection }
+ format.pdf { render :pdf => @collection.title }
+ end
+ end
+
+ def new
+ @collection = Collection.new
+ end
+
+ def create
+ @collection = Collection.new(params[:collection])
+ if @collection.save
+ flash[:notice] = "Collection created!"
+ redirect_to @collection
+ else
+ render :action => :new
+ end
+ end
+
+ def edit
+ @collection = Collection.find( params[:id])
+ end
+
+ def update
+ @collection = Collection.find( params[:id])
+ if @collection.update_attributes(params[:collection])
+ flash[:notice] = "collection updated!"
+ redirect_to @collection
+ else
+ render :action => :edit
+ end
+ end
+
+ def destroy
+ @collection = Collection.find( params[:id])
+ if @collection.destroy
+ redirect_to collections_path
+ else
+ redirect_to @collection
+ end
+ end
+
+end
diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb
index abf1e64..787db43 100644
--- a/app/controllers/photos_controller.rb
+++ b/app/controllers/photos_controller.rb
@@ -45,10 +45,13 @@ class PhotosController < ApplicationController
@photo = Photo.new(params[:photo])
if params[:Filedata]
@photo.swf_uploaded_data = params[:Filedata]
- @photo.save!
-
- format.html { render :text => "FILEID:" + @photo.public_path_modified("album") }
- format.xml { render :nothing => true }
+ if @photo.save
+ format.html { render :text => "FILEID:" + @photo.path_modified_public("album") }
+ format.xml { render :nothing => true }
+ else
+ format.html { render :text => "ERRORS:" + @photo.errors.full_messages.join(" "), :status => 500 }
+ format.xml { render :xml => @photo.errors, :status => 500 }
+ end
else
if @photo.save
flash[:notice] = 'Created'
diff --git a/app/helpers/collections_helper.rb b/app/helpers/collections_helper.rb
new file mode 100644
index 0000000..3017985
--- /dev/null
+++ b/app/helpers/collections_helper.rb
@@ -0,0 +1,2 @@
+module CollectionsHelper
+end
diff --git a/app/models/album.rb b/app/models/album.rb
index dde9546..92cfaeb 100644
--- a/app/models/album.rb
+++ b/app/models/album.rb
@@ -1,5 +1,7 @@
class Album < ActiveRecord::Base
has_many :photos, :dependent => :destroy
+ has_many :collection_albums
+ has_many :collections, :through => :collection_albums
validates_uniqueness_of :path, :message => "Album already exsists on disc"
@@ -9,45 +11,69 @@ class Album < ActiveRecord::Base
attr_accessor :tag_list
attr_protected :path
+
- protected
+
+ def self.untouched
+ self.find(:all, :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) )" )
+ end
+
def ensure_path
self.path = self.title if !self.path
end
def tag_list
+ # should maybe cache this to databse?
+
tags = Array.new
self.photos.map{ |photo|
if photo.tags.empty?
+ # photo has no tags => no unversial tags for this album
return
else
photo.tags
- end }.each_with_index{ |tag,i|
- puts tag.inspect
- tag.each { |t|
- puts t.title
- puts i
- if i == 0
- tags.push(t.title)
- elsif !tags.include?(t.title)
- tags.delete(t.title)
- end
- }
- }
- return tags.join(" ")
+ end
+ }.each_with_index{ |photo_tags,i|
+ # returns tag collection for each photo
+ if i == 0
+ tags = photo_tags
+ else
+ # combine arrays if they have identical tags.
+ # Will remove tags that are only tagged to one photo
+ tags = tags & photo_tags
+ end
+ }
+ return tags.collect{|tag| tag.title }.join(" ")
end
-
+
def tag_list=(tags)
return if tags == self.tag_list
+ current_tags = self.tag_list.split(" ")
+ tags = tags.split(" ")
- #TODO HERE!
- ts = Array.new
- tags.split(" ").each do |tag|
- ts.push( Tag.find_or_create_by_title( :title => tag) )
+ # 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|
+ #TODO in photo model
+ #photo.tag_remove( tag )
+ }
+ }
+
+ # add universial tags to all photos in album
+ tags.each do |tag|
+ #puts "tag photos with #{tag}" if !current_tags.include?( tag )
+ self.photos.each { |photo|
+ #TODO in photo model
+ #photo.tag_with( tag ) if !current_tags.include?( tag ) # no need to re-tag
+ }
end
- self.tags = ts
- end
+ end
+ protected
+
private
def create_folders
diff --git a/app/models/collection.rb b/app/models/collection.rb
new file mode 100644
index 0000000..a572f2a
--- /dev/null
+++ b/app/models/collection.rb
@@ -0,0 +1,5 @@
+class Collection < ActiveRecord::Base
+ has_many :collection_albums
+ has_many :albums, :through => :collection_albums
+
+end
diff --git a/app/models/collection_album.rb b/app/models/collection_album.rb
new file mode 100644
index 0000000..5010b5e
--- /dev/null
+++ b/app/models/collection_album.rb
@@ -0,0 +1,4 @@
+class CollectionAlbum < ActiveRecord::Base
+ belongs_to :album
+ belongs_to :collection
+end
diff --git a/app/models/photo.rb b/app/models/photo.rb
index 49ce140..f95f380 100644
--- a/app/models/photo.rb
+++ b/app/models/photo.rb
@@ -9,7 +9,9 @@ class Photo < ActiveRecord::Base
validates_uniqueness_of :path, :message => "Photo already exsists on disc"
validates_presence_of :title
- before_create :create_thumbnails, :read_exif
+ before_create :exif_read
+ after_create :create_thumbnails
+ before_update :exif_write # should only write if tags are changed as images can be large and thus ExifTool will take a while to write to the file
before_destroy :destroy_file
attr_accessor :tag_list
@@ -20,20 +22,16 @@ class Photo < ActiveRecord::Base
self.find(:all, :conditions => "Photos.description IS NULL AND Photos.Id NOT IN ( SELECT Photo_ID FROM Photo_Tags)", :include => :album )
end
- def path_original
- return APP_CONFIG[:photos_path] + self.path
+ def extension
+ return File.extname(self.path_original)
end
def path_original_public
return APP_CONFIG[:photos_path_public] + self.path
end
- def path_modified(size)
- return APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_" + size + ".jpg"
- end
-
def path_modified_public(size)
- return APP_CONFIG[:thumbs_path_public] + self.album.path + "/" + self.id.to_s + "_" + size + ".jpg"
+ return APP_CONFIG[:thumbs_path_public] + self.album.path + "/" + self.id.to_s + "_" + size + self.extension
end
@@ -50,40 +48,6 @@ class Photo < ActiveRecord::Base
end
- def create_thumbnails
- ImageScience.with_image(APP_CONFIG[:photos_path] + self.path) do |img|
- #puts " thumbing it..thumbing it.."
- ext = File.extname( APP_CONFIG[:photos_path] + self.path )
-
- img.thumbnail(85) do |thumb|
- thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_thumb" + ext
- end
- img.thumbnail(150) do |thumb|
- thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_album" + ext
- end
- img.thumbnail(800) do |thumb|
- thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_large" + ext
- end
- end
- end
-
- def read_exif
- photo = MiniExiftool.new(self.path_original)
- self.longitude = photo.GPSLongitude
- self.latitude = photo.GPSLatitude
- self.title = photo.DocumentName
- self.description = photo.ImageDescription
- end
-
- def write_exif
- photo = MiniExiftool.new(self.path_original)
- photo.GPSLongitude = self.longitude
- photo.GPSLatitude = self.latitude
- photo.DocumentName = self.title
- photo.ImageDescription = self.description
- photo.save
- end
-
def exif_info
photo = MiniExiftool.new(self.path_original)
photo.tags.sort.each do |tag|
@@ -101,10 +65,55 @@ class Photo < ActiveRecord::Base
File.open(APP_CONFIG[:photos_path] + self.path, "wb") { |f| f.write(data.read) }
end
+ protected
+
+ def path_original
+ return APP_CONFIG[:photos_path] + self.path
+ end
+
+ def path_modified(size)
+ return APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_" + size + self.extension
+ end
+
private
+
+ def create_thumbnails
+ ImageScience.with_image(APP_CONFIG[:photos_path] + self.path) do |img|
+ #puts " thumbing it..thumbing it.."
+ ext = File.extname( APP_CONFIG[:photos_path] + self.path )
+
+ img.thumbnail(85) do |thumb|
+ thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_thumb" + ext
+ end
+ img.thumbnail(150) do |thumb|
+ thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_album" + ext
+ end
+ img.thumbnail(800) do |thumb|
+ thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_large" + ext
+ end
+ end
+ end
+
+ def exif_read
+ photo = MiniExiftool.new(self.path_original)
+ 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?
+ self.tag_list = photo.Keywords.map { |tag| tag.gsub(" ", "_") }.join(" ") if self.tags.empty? && !photo.Keywords.nil?
+ end
-
+ def exif_write
+ photo = MiniExiftool.new(self.path_original)
+ photo.GPSLongitude = self.longitude
+ photo.GPSLatitude = self.latitude
+ photo.DocumentName = self.title
+ photo.ImageDescription = self.description
+ photo.Keywords = self.tags
+ photo.save
+ end
+
def destroy_file
#puts "DELETE THUMBS OF " + APP_CONFIG[:photos_path] + self.path
#File.delete( APP_CONFIG[:photos_path] + self.path ) if File.exists?( APP_CONFIG[:photos_path] + self.path )
diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb
index 2aa6203..a32a88b 100644
--- a/app/views/albums/show.html.erb
+++ b/app/views/albums/show.html.erb
@@ -1,6 +1,7 @@
<% for photo in @album.photos %>
-<%= link_to image_tag( photo.public_path_modified("album") ), photo %>
+<%= link_to image_tag( photo.path_modified_public("album") ), photo %>
<% end %>
<%= link_to "Update album", edit_album_path(@album) %>
+
<%= link_to "Upload photos", upload_album_path(@album) %>
<%= link_to "All albums", albums_path %>
\ No newline at end of file
diff --git a/app/views/albums/untouched.html.erb b/app/views/albums/untouched.html.erb
new file mode 100644
index 0000000..d8c1536
--- /dev/null
+++ b/app/views/albums/untouched.html.erb
@@ -0,0 +1,2 @@
+
<%= @photo.description %>