ruby rocks
This commit is contained in:
parent
1ae1716a0b
commit
91a3662a19
|
@ -44,11 +44,11 @@ class Album < ActiveRecord::Base
|
||||||
tags = tags & photo_tags
|
tags = tags & photo_tags
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
return tags.collect{|tag| tag.title }.join(" ")
|
return tags.collect{|tag| tag.title }.sort.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list=(tags)
|
def tag_list=(tags)
|
||||||
return if tags == self.tag_list
|
return if tags.split(" ").sort.join(" ") == self.tag_list
|
||||||
current_tags = self.tag_list.split(" ")
|
current_tags = self.tag_list.split(" ")
|
||||||
tags = tags.split(" ")
|
tags = tags.split(" ")
|
||||||
|
|
||||||
|
@ -58,8 +58,7 @@ class Album < ActiveRecord::Base
|
||||||
(current_tags - tags).each { |tag|
|
(current_tags - tags).each { |tag|
|
||||||
#puts "remove #{tag}"
|
#puts "remove #{tag}"
|
||||||
self.photos.each {|photo|
|
self.photos.each {|photo|
|
||||||
#TODO in photo model
|
photo.untag( tag )
|
||||||
#photo.tag_remove( tag )
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +66,7 @@ class Album < ActiveRecord::Base
|
||||||
tags.each do |tag|
|
tags.each do |tag|
|
||||||
#puts "tag photos with #{tag}" if !current_tags.include?( tag )
|
#puts "tag photos with #{tag}" if !current_tags.include?( tag )
|
||||||
self.photos.each { |photo|
|
self.photos.each { |photo|
|
||||||
#TODO in photo model
|
photo.tag( tag ) if !current_tags.include?( tag ) # no need to re-tag
|
||||||
#photo.tag_with( tag ) if !current_tags.include?( tag ) # no need to re-tag
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,9 +22,6 @@ 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 )
|
self.find(:all, :conditions => "Photos.description IS NULL AND Photos.Id NOT IN ( SELECT Photo_ID FROM Photo_Tags)", :include => :album )
|
||||||
end
|
end
|
||||||
|
|
||||||
def extension
|
|
||||||
return File.extname(self.path_original)
|
|
||||||
end
|
|
||||||
|
|
||||||
def path_original_public
|
def path_original_public
|
||||||
return APP_CONFIG[:photos_path_public] + self.path
|
return APP_CONFIG[:photos_path_public] + self.path
|
||||||
|
@ -34,6 +31,21 @@ class Photo < ActiveRecord::Base
|
||||||
return APP_CONFIG[:thumbs_path_public] + self.album.path + "/" + self.id.to_s + "_" + size + self.extension
|
return APP_CONFIG[:thumbs_path_public] + self.album.path + "/" + self.id.to_s + "_" + size + self.extension
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag(title)
|
||||||
|
return if self.tags.collect{|tag|tag.title}.include?( title )
|
||||||
|
self.photo_tags.create(:tag => Tag.find_or_create_by_title( :title => title) )
|
||||||
|
self.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
def untag(title)
|
||||||
|
return if !self.tags.collect{|tag|tag.title}.include?( title )
|
||||||
|
# perhaps not the best way but it finds the correct PhotoTag and deletes it
|
||||||
|
self.photo_tags.select{|photo_tag|
|
||||||
|
photo_tag.tag.title == title
|
||||||
|
}.each {|photo_tag|photo_tag.destroy}
|
||||||
|
self.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def tag_list
|
def tag_list
|
||||||
return self.tags.find(:all, :order => 'title').collect{ |t| t.title }.join(" ")
|
return self.tags.find(:all, :order => 'title').collect{ |t| t.title }.join(" ")
|
||||||
|
@ -67,6 +79,11 @@ class Photo < ActiveRecord::Base
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
||||||
|
def extension
|
||||||
|
return File.extname(self.path_original)
|
||||||
|
end
|
||||||
|
|
||||||
def path_original
|
def path_original
|
||||||
return APP_CONFIG[:photos_path] + self.path
|
return APP_CONFIG[:photos_path] + self.path
|
||||||
end
|
end
|
||||||
|
@ -75,9 +92,9 @@ class Photo < ActiveRecord::Base
|
||||||
return APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_" + size + self.extension
|
return APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_" + size + self.extension
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
||||||
def create_thumbnails
|
def create_thumbnails
|
||||||
ImageScience.with_image(APP_CONFIG[:photos_path] + self.path) do |img|
|
ImageScience.with_image(APP_CONFIG[:photos_path] + self.path) do |img|
|
||||||
#puts " thumbing it..thumbing it.."
|
#puts " thumbing it..thumbing it.."
|
||||||
|
|
Loading…
Reference in a new issue