tagging works
parent
91a3662a19
commit
8bd5668d57
|
@ -24,7 +24,8 @@ class Album < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list
|
def tag_list
|
||||||
# should maybe cache this to databse?
|
# should maybe cache this to database?
|
||||||
|
# should maybe return array instead?
|
||||||
|
|
||||||
tags = Array.new
|
tags = Array.new
|
||||||
self.photos.map{ |photo|
|
self.photos.map{ |photo|
|
||||||
|
@ -49,7 +50,7 @@ class Album < ActiveRecord::Base
|
||||||
|
|
||||||
def tag_list=(tags)
|
def tag_list=(tags)
|
||||||
return if tags.split(" ").sort.join(" ") == self.tag_list
|
return if tags.split(" ").sort.join(" ") == self.tag_list
|
||||||
current_tags = self.tag_list.split(" ")
|
current_tags = ( self.tag_list.nil? ? [] : self.tag_list.split(" ") )
|
||||||
tags = tags.split(" ")
|
tags = tags.split(" ")
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -81,7 +82,7 @@ class Album < ActiveRecord::Base
|
||||||
|
|
||||||
def destroy_directory
|
def destroy_directory
|
||||||
#puts "DELETE DIRECTORY " + APP_CONFIG[:photos_path] + self.path
|
#puts "DELETE DIRECTORY " + APP_CONFIG[:photos_path] + self.path
|
||||||
#Dir.delete( APP_CONFIG[:photos_path] + self.path + "/" ) if File.exists?( APP_CONFIG[:photos_path] + self.path )
|
Dir.delete( APP_CONFIG[:thumbs_path] + self.path ) if File.exists?( APP_CONFIG[:thumbs_path] + self.path )
|
||||||
#Dir.delete( APP_CONFIG[:thumbs_path] + self.path ) if File.exists?( APP_CONFIG[:thumbs_path] + self.path )
|
Dir.delete( APP_CONFIG[:photos_path] + self.path + "/" ) if File.exists?( APP_CONFIG[:photos_path] + self.path )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Photo < ActiveRecord::Base
|
||||||
def tag_list=(tags)
|
def tag_list=(tags)
|
||||||
ts = Array.new
|
ts = Array.new
|
||||||
tags.split(" ").each do |tag|
|
tags.split(" ").each do |tag|
|
||||||
ts.push( Tag.find_or_create_by_title( :title => tag) )
|
ts.push( Tag.find_or_create_by_title( :title => tag.downcase) )
|
||||||
end
|
end
|
||||||
self.tags = ts
|
self.tags = ts
|
||||||
end
|
end
|
||||||
|
@ -118,7 +118,7 @@ class Photo < ActiveRecord::Base
|
||||||
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?
|
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?
|
self.tag_list = (self.tags.empty? ? "" : self.album.tag_list) + " " + (photo.Keywords.map { |tag| tag.gsub(" ", "_") }.join(" ") if !photo.Keywords.nil?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def exif_write
|
def exif_write
|
||||||
|
@ -130,12 +130,12 @@ class Photo < ActiveRecord::Base
|
||||||
photo.Keywords = self.tags
|
photo.Keywords = self.tags
|
||||||
photo.save
|
photo.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_file
|
def destroy_file
|
||||||
#puts "DELETE THUMBS OF " + APP_CONFIG[:photos_path] + self.path
|
#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 )
|
File.delete( APP_CONFIG[:photos_path] + self.path ) if File.exists?( APP_CONFIG[:photos_path] + self.path )
|
||||||
File.delete( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_thumb" + File.extname( APP_CONFIG[:photos_path] + self.path ) ) if File.exists?( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_small" + File.extname( APP_CONFIG[:photos_path] + self.path ) )
|
File.delete( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_thumb" + File.extname( APP_CONFIG[:photos_path] + self.path ) ) if File.exists?( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_thumb" + File.extname( APP_CONFIG[:photos_path] + self.path ) )
|
||||||
File.delete( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_album" + File.extname( APP_CONFIG[:photos_path] + self.path ) ) if File.exists?( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_small" + File.extname( APP_CONFIG[:photos_path] + self.path ) )
|
File.delete( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_album" + File.extname( APP_CONFIG[:photos_path] + self.path ) ) if File.exists?( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_album" + File.extname( APP_CONFIG[:photos_path] + self.path ) )
|
||||||
File.delete( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_large" + File.extname( APP_CONFIG[:photos_path] + self.path ) ) if File.exists?( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_large" + File.extname( APP_CONFIG[:photos_path] + self.path ) )
|
File.delete( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_large" + File.extname( APP_CONFIG[:photos_path] + self.path ) ) if File.exists?( APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_large" + File.extname( APP_CONFIG[:photos_path] + self.path ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,9 @@ class Tag < ActiveRecord::Base
|
||||||
has_many :photos, :through => :photo_tags
|
has_many :photos, :through => :photo_tags
|
||||||
|
|
||||||
validates_uniqueness_of :title
|
validates_uniqueness_of :title
|
||||||
|
|
||||||
|
before_validation :downcase_title
|
||||||
|
|
||||||
def self.tag_list
|
def self.tag_list
|
||||||
return self.find(:all).map { |tag| tag.title }.join('\',\'')
|
return self.find(:all).map { |tag| tag.title }.join('\',\'')
|
||||||
end
|
end
|
||||||
|
@ -15,4 +17,10 @@ class Tag < ActiveRecord::Base
|
||||||
self.title
|
self.title
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def downcase_title
|
||||||
|
self.title.downcase! if attribute_present?("title")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
<% content_for :javascript do %>
|
||||||
|
<script src="/javascripts/tag/tag.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= hidden_field_tag :all_tags, "'#{Tag.find(:all).map { |tag| tag.title }.join('\',\'')}'" %>
|
||||||
|
|
||||||
<%= form.label :title, :Title, {:class => 'big'} %><br />
|
<%= form.label :title, :Title, {:class => 'big'} %><br />
|
||||||
<%= form.text_field :title, {:class => 'big'} %><br />
|
<%= form.text_field :title, {:class => 'big'} %><br />
|
||||||
<%= form.label :description %><br />
|
<%= form.label :description %><br />
|
||||||
|
@ -10,7 +16,7 @@
|
||||||
<%= form.text_area :note %><br />
|
<%= form.text_area :note %><br />
|
||||||
|
|
||||||
<%= form.label :tag_list %><br />
|
<%= form.label :tag_list %><br />
|
||||||
<%= form.text_field :tag_list, { :autocomplete => "off"} %><br />
|
<%= form.text_field :tag_list, { :autocomplete => "off", :class => 'tag_list'} %><br />
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<% if @album.path? %>
|
<% if @album.path? %>
|
||||||
|
|
|
@ -1,3 +1,35 @@
|
||||||
|
if ( $('ul.gallery').length ) {
|
||||||
|
$('ul.gallery').galleria( {
|
||||||
|
clickNext : true,
|
||||||
|
insert: "#photo_large",
|
||||||
|
onImage: function ( image, caption, thumb ) {
|
||||||
|
image.css('display','none').fadeIn()
|
||||||
|
|
||||||
|
thumb.parents('li').siblings().children('img.selected').fadeTo(500,0.3)
|
||||||
|
thumb.fadeTo('fast',1).addClass('selected')
|
||||||
|
$( '#photo_metadata' ).html( '<a href=\'/photos/' + thumb.attr('id').replace('thumb_', '') + '/edit\'>Update photo details</a>' )
|
||||||
|
|
||||||
|
var scrollable = $("#thumbstrip").scrollable()
|
||||||
|
scrollable.seekTo( thumb.parents('ul').children().index( thumb.parents('li') ) )
|
||||||
|
},
|
||||||
|
onThumb: function ( thumb) {
|
||||||
|
thumb.css({display:'none',opacity: (thumb.parents('li').is('.active') ? '1' : '0.3') }).fadeIn(1500)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $('#thumbstrip').length ) {
|
||||||
|
$('#thumbstrip').scrollable( {
|
||||||
|
items : '#thumbs',
|
||||||
|
clickable: true,
|
||||||
|
keyboard : false
|
||||||
|
})
|
||||||
|
if ( $('#thumbs li.active').length == 0 ){
|
||||||
|
//$('div.scrollable').scrollable().click(0)
|
||||||
|
$('#thumbs li:first').addClass('active')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
<% content_for :javascript do %>
|
<% content_for :javascript do %>
|
||||||
<script type="text/javascript" src="/javascripts/swfupload/swfupload.js"></script>
|
<script type="text/javascript" src="/javascripts/swfupload/swfupload.js"></script>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -7,8 +7,8 @@ $(document).ready(function() {
|
||||||
uploader:'/javascripts/jquery.uploadify-v1.6.2.mit/uploader.swf',
|
uploader:'/javascripts/jquery.uploadify-v1.6.2.mit/uploader.swf',
|
||||||
script:'<%= photos_path %>',
|
script:'<%= photos_path %>',
|
||||||
scriptData: {
|
scriptData: {
|
||||||
'<%= get_session_key %>' : '<%= u cookies[get_session_key] %>',
|
'<%= get_session_key %>' : encodeURIComponent('<%= u cookies[get_session_key] %>'),
|
||||||
'<%= request_forgery_protection_token %>' : '<%= u form_authenticity_token %>',
|
'<%= request_forgery_protection_token %>' : encodeURIComponent('<%= u form_authenticity_token %>'),
|
||||||
'photo[album_id]' : "<%= @album.id %>"
|
'photo[album_id]' : "<%= @album.id %>"
|
||||||
},
|
},
|
||||||
cancelImg:'/javascripts/jquery.uploadify-v1.6.2.mit/cancel.png',
|
cancelImg:'/javascripts/jquery.uploadify-v1.6.2.mit/cancel.png',
|
||||||
|
|
|
@ -6,6 +6,6 @@
|
||||||
<%= form.text_field :title %><br />
|
<%= form.text_field :title %><br />
|
||||||
<br />
|
<br />
|
||||||
<%= form.label :tag_list %><br />
|
<%= form.label :tag_list %><br />
|
||||||
<%= form.text_field :tag_list, { :autocomplete => "off"} %><br />
|
<%= form.text_field :tag_list, { :autocomplete => "off", :class => 'tag_list'} %><br />
|
||||||
<br/>
|
<br/>
|
||||||
<p>On disk: ~/<%= @photo.path %></p>
|
<p>On disk: ~/<%= @photo.path %></p>
|
|
@ -1,43 +1,10 @@
|
||||||
jQuery(function($) {
|
jQuery(function($) {
|
||||||
if ( $('ul.gallery').length ) {
|
|
||||||
$('ul.gallery').galleria( {
|
if ( $('.tag_list').length ) {
|
||||||
clickNext : true,
|
$('.tag_list').tagSuggest({
|
||||||
insert: "#photo_large",
|
|
||||||
onImage: function ( image, caption, thumb ) {
|
|
||||||
image.css('display','none').fadeIn()
|
|
||||||
|
|
||||||
thumb.parents('li').siblings().children('img.selected').fadeTo(500,0.3)
|
|
||||||
thumb.fadeTo('fast',1).addClass('selected')
|
|
||||||
$( '#photo_metadata' ).html( '<a href=\'/photos/' + thumb.attr('id').replace('thumb_', '') + '/edit\'>Update photo details</a>' )
|
|
||||||
|
|
||||||
var scrollable = $("#thumbstrip").scrollable()
|
|
||||||
scrollable.seekTo( thumb.parents('ul').children().index( thumb.parents('li') ) )
|
|
||||||
},
|
|
||||||
onThumb: function ( thumb) {
|
|
||||||
thumb.css({display:'none',opacity: (thumb.parents('li').is('.active') ? '1' : '0.3') }).fadeIn(1500)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $('#thumbstrip').length ) {
|
|
||||||
$('#thumbstrip').scrollable( {
|
|
||||||
items : '#thumbs',
|
|
||||||
clickable: true,
|
|
||||||
keyboard : false
|
|
||||||
})
|
|
||||||
if ( $('#thumbs li.active').length == 0 ){
|
|
||||||
//$('div.scrollable').scrollable().click(0)
|
|
||||||
$('#thumbs li:first').addClass('active')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( $('#photo_tag_list').length ) {
|
|
||||||
$('#photo_tag_list').tagSuggest({
|
|
||||||
tags: $('#all_tags').val().split('\'')
|
tags: $('#all_tags').val().split('\'')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $('FORM #upload').length ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//$('div.scrollable').scrollable().click( $('#gallery ul').children().index( $('#gallery li.active') ) )
|
//$('div.scrollable').scrollable().click( $('#gallery ul').children().index( $('#gallery li.active') ) )
|
||||||
});
|
});
|
Loading…
Reference in New Issue