tagging works
This commit is contained in:
parent
91a3662a19
commit
8bd5668d57
8 changed files with 65 additions and 51 deletions
|
@ -24,7 +24,8 @@ class Album < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def tag_list
|
||||
# should maybe cache this to databse?
|
||||
# should maybe cache this to database?
|
||||
# should maybe return array instead?
|
||||
|
||||
tags = Array.new
|
||||
self.photos.map{ |photo|
|
||||
|
@ -49,7 +50,7 @@ class Album < ActiveRecord::Base
|
|||
|
||||
def tag_list=(tags)
|
||||
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(" ")
|
||||
|
||||
# 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
|
||||
#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
|
||||
|
|
|
@ -54,7 +54,7 @@ class Photo < ActiveRecord::Base
|
|||
def tag_list=(tags)
|
||||
ts = Array.new
|
||||
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
|
||||
self.tags = ts
|
||||
end
|
||||
|
@ -118,7 +118,7 @@ class Photo < ActiveRecord::Base
|
|||
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?
|
||||
self.tag_list = (self.tags.empty? ? "" : self.album.tag_list) + " " + (photo.Keywords.map { |tag| tag.gsub(" ", "_") }.join(" ") if !photo.Keywords.nil?)
|
||||
end
|
||||
|
||||
def exif_write
|
||||
|
@ -130,12 +130,12 @@ class Photo < ActiveRecord::Base
|
|||
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 )
|
||||
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 + "_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[: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 + "_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 + "_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 ) )
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,9 @@ class Tag < ActiveRecord::Base
|
|||
has_many :photos, :through => :photo_tags
|
||||
|
||||
validates_uniqueness_of :title
|
||||
|
||||
|
||||
before_validation :downcase_title
|
||||
|
||||
def self.tag_list
|
||||
return self.find(:all).map { |tag| tag.title }.join('\',\'')
|
||||
end
|
||||
|
@ -15,4 +17,10 @@ class Tag < ActiveRecord::Base
|
|||
self.title
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def downcase_title
|
||||
self.title.downcase! if attribute_present?("title")
|
||||
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.text_field :title, {:class => 'big'} %><br />
|
||||
<%= form.label :description %><br />
|
||||
|
@ -10,7 +16,7 @@
|
|||
<%= form.text_area :note %><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 />
|
||||
<% 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 %>
|
||||
<script type="text/javascript" src="/javascripts/swfupload/swfupload.js"></script>
|
||||
<% end %>
|
||||
|
|
|
@ -7,8 +7,8 @@ $(document).ready(function() {
|
|||
uploader:'/javascripts/jquery.uploadify-v1.6.2.mit/uploader.swf',
|
||||
script:'<%= photos_path %>',
|
||||
scriptData: {
|
||||
'<%= get_session_key %>' : '<%= u cookies[get_session_key] %>',
|
||||
'<%= request_forgery_protection_token %>' : '<%= u form_authenticity_token %>',
|
||||
'<%= get_session_key %>' : encodeURIComponent('<%= u cookies[get_session_key] %>'),
|
||||
'<%= request_forgery_protection_token %>' : encodeURIComponent('<%= u form_authenticity_token %>'),
|
||||
'photo[album_id]' : "<%= @album.id %>"
|
||||
},
|
||||
cancelImg:'/javascripts/jquery.uploadify-v1.6.2.mit/cancel.png',
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
<%= form.text_field :title %><br />
|
||||
<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/>
|
||||
<p>On disk: ~/<%= @photo.path %></p>
|
|
@ -1,43 +1,10 @@
|
|||
jQuery(function($) {
|
||||
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')
|
||||
}
|
||||
}
|
||||
if ( $('#photo_tag_list').length ) {
|
||||
$('#photo_tag_list').tagSuggest({
|
||||
|
||||
if ( $('.tag_list').length ) {
|
||||
$('.tag_list').tagSuggest({
|
||||
tags: $('#all_tags').val().split('\'')
|
||||
})
|
||||
}
|
||||
|
||||
if ( $('FORM #upload').length ) {
|
||||
}
|
||||
|
||||
//$('div.scrollable').scrollable().click( $('#gallery ul').children().index( $('#gallery li.active') ) )
|
||||
});
|
Loading…
Reference in a new issue