menu on top. css notice. tags as array
This commit is contained in:
parent
5b227a7774
commit
7e418f9003
|
@ -55,14 +55,11 @@ class PhotosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
RAILS_DEFAULT_LOGGER.info('create method')
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@photo = Photo.new(params[:photo])
|
@photo = Photo.new(params[:photo])
|
||||||
if params[:Filedata]
|
if params[:Filedata]
|
||||||
RAILS_DEFAULT_LOGGER.info('getting file')
|
|
||||||
@photo.swf_uploaded_data = params[:Filedata]
|
@photo.swf_uploaded_data = params[:Filedata]
|
||||||
if @photo.save
|
if @photo.save
|
||||||
RAILS_DEFAULT_LOGGER.info('saved')
|
|
||||||
format.html { render :text => "FILEID:" + @photo.path_modified_public("album") }
|
format.html { render :text => "FILEID:" + @photo.path_modified_public("album") }
|
||||||
format.xml { render :nothing => true }
|
format.xml { render :nothing => true }
|
||||||
else
|
else
|
||||||
|
@ -84,6 +81,7 @@ class PhotosController < ApplicationController
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@photo = Photo.find( params[:id])
|
@photo = Photo.find( params[:id])
|
||||||
|
@tags = Tag.find(:all).map { |tag| tag.title }.join('\',\'')
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit_multiple
|
def edit_multiple
|
||||||
|
|
|
@ -8,7 +8,7 @@ module ApplicationHelper
|
||||||
#links = "You are here: "
|
#links = "You are here: "
|
||||||
links = content_tag('a', "HOME", :href => "/") if include_home
|
links = content_tag('a', "HOME", :href => "/") if include_home
|
||||||
|
|
||||||
nocrumb = ["collections", "albums", "photos", "tags"]
|
nocrumb = ["collections", "albums", "photos", "tags", "new", "edit"]
|
||||||
|
|
||||||
levels.each_with_index do |level, index|
|
levels.each_with_index do |level, index|
|
||||||
level = level.gsub(/^[0-9]+\-/,"") #if levels[index-1] == "photos"
|
level = level.gsub(/^[0-9]+\-/,"") #if levels[index-1] == "photos"
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Album < ActiveRecord::Base
|
||||||
after_create :create_folders
|
after_create :create_folders
|
||||||
after_destroy :destroy_folders
|
after_destroy :destroy_folders
|
||||||
|
|
||||||
attr_accessor :tag_list
|
attr_accessor :tags
|
||||||
attr_protected :path
|
attr_protected :path
|
||||||
|
|
||||||
named_scope :untouched, :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) )"
|
named_scope :untouched, :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) )"
|
||||||
|
@ -30,7 +30,7 @@ class Album < ActiveRecord::Base
|
||||||
self.title = File.basename( File.dirname(self.path) ) unless self.title || !self.path
|
self.title = File.basename( File.dirname(self.path) ) unless self.title || !self.path
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list
|
def tags
|
||||||
# should maybe cache this to database?
|
# should maybe cache this to database?
|
||||||
# should maybe return array instead?
|
# should maybe return array instead?
|
||||||
|
|
||||||
|
@ -52,13 +52,13 @@ class Album < ActiveRecord::Base
|
||||||
tags = tags & photo_tags
|
tags = tags & photo_tags
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
return tags.collect{|tag| tag.title }.sort.join(" ")
|
return tags
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list=(tags)
|
def tags=(tags)
|
||||||
return if tags.split(" ").sort.join(" ") == self.tag_list
|
tags = tags.split(" ").sort
|
||||||
|
return if tags == self.tag_list
|
||||||
current_tags = ( self.tag_list.nil? ? [] : 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
|
# 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
|
||||||
|
|
|
@ -10,9 +10,10 @@ class Photo < ActiveRecord::Base
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
|
|
||||||
before_validation :set_title
|
before_validation :set_title
|
||||||
|
before_save :ensure_file
|
||||||
before_create :exif_read
|
before_create :exif_read
|
||||||
after_create :create_thumbnails
|
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_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
|
before_destroy :destroy_file
|
||||||
|
|
||||||
attr_accessor :tag_list
|
attr_accessor :tag_list
|
||||||
|
@ -23,11 +24,7 @@ class Photo < ActiveRecord::Base
|
||||||
named_scope :next, lambda { |p,a| { :conditions => ["id > :id AND Album_Id = :album ", { :id => p, :album => a } ], :limit => 1, :order => "Id ASC"} }
|
named_scope :next, lambda { |p,a| { :conditions => ["id > :id AND Album_Id = :album ", { :id => p, :album => a } ], :limit => 1, :order => "Id ASC"} }
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
id.to_s + '-' + title.gsub(/[^a-z0-9]+/i, '-')
|
self.id.to_s + '-' + self.title.parameterize
|
||||||
end
|
|
||||||
|
|
||||||
def set_title
|
|
||||||
self.title = File.basename( File.dirname(path) ).gsub( self.extension, "" ) unless self.title
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def path_original_public
|
def path_original_public
|
||||||
|
@ -53,9 +50,8 @@ class Photo < ActiveRecord::Base
|
||||||
self.reload
|
self.reload
|
||||||
end
|
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 }.sort.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list=(tags)
|
def tag_list=(tags)
|
||||||
|
@ -78,18 +74,15 @@ class Photo < ActiveRecord::Base
|
||||||
# Thanks to bug in Flash 8 the content type is always set to application/octet-stream.
|
# Thanks to bug in Flash 8 the content type is always set to application/octet-stream.
|
||||||
# From: http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
|
# From: http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
|
||||||
def swf_uploaded_data=(data)
|
def swf_uploaded_data=(data)
|
||||||
RAILS_DEFAULT_LOGGER.info('swf_uploaded_data start')
|
|
||||||
data.content_type = MIME::Types.type_for(data.original_filename)
|
data.content_type = MIME::Types.type_for(data.original_filename)
|
||||||
self.title = data.original_filename
|
self.title = data.original_filename
|
||||||
self.path = self.album.path + "/" + data.original_filename
|
self.path = self.album.path + "/" + data.original_filename
|
||||||
File.open(APP_CONFIG[:photos_path] + self.path, 'wb') { |f| f.write(data.read) }
|
File.open(APP_CONFIG[:photos_path] + self.path, 'wb') { |f| f.write(data.read) }
|
||||||
RAILS_DEFAULT_LOGGER.info('swf_uploaded_data done')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def create_thumbnails
|
def create_thumbnails
|
||||||
RAILS_DEFAULT_LOGGER.info('create thumb')
|
ImageScience.with_image(self.path_original) do |img|
|
||||||
ImageScience.with_image(APP_CONFIG[:photos_path] + self.path) do |img|
|
|
||||||
img.cropped_thumbnail(200) do |thumb|
|
img.cropped_thumbnail(200) do |thumb|
|
||||||
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_collection" + self.extension
|
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_collection" + self.extension
|
||||||
end
|
end
|
||||||
|
@ -106,8 +99,7 @@ class Photo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
||||||
def extension
|
def extension
|
||||||
return File.extname(self.path_original)
|
return File.extname(self.path_original)
|
||||||
end
|
end
|
||||||
|
@ -122,12 +114,20 @@ class Photo < ActiveRecord::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_title
|
||||||
|
self.title = File.basename( self.path ).gsub( self.extension, "" ) unless self.title
|
||||||
|
end
|
||||||
|
|
||||||
|
def ensure_file
|
||||||
|
self.destroy if !File.exists?( APP_CONFIG[:photos_path] + self.path )
|
||||||
|
end
|
||||||
|
|
||||||
def exif_read
|
def exif_read
|
||||||
photo = MiniExiftool.new(self.path_original)
|
photo = MiniExiftool.new(self.path_original)
|
||||||
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?
|
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
|
||||||
|
|
||||||
|
@ -143,9 +143,10 @@ class Photo < ActiveRecord::Base
|
||||||
|
|
||||||
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( self.path_original ) if File.exists?( self.path_original )
|
||||||
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( self.path_modified("_collection") ) if File.exists?( self.path_modified("_collection") )
|
||||||
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( self.path_modified("_album") ) if File.exists?( self.path_modified("_album") )
|
||||||
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( self.path_modified("_single") ) if File.exists?( self.path_modified("_single") )
|
||||||
|
File.delete( self.path_modified("_preview") ) if File.exists?( self.path_modified("_preview") )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,8 @@ class Tag < ActiveRecord::Base
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
#id.to_s+'-'+
|
#id.to_s+'-'+
|
||||||
title.downcase.gsub(/[^a-z0-9]+/i, '-')
|
self.title.parameterize
|
||||||
|
#title.downcase.gsub(/[^a-z0-9]+/i, '-')
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -13,13 +13,19 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><%= @album.description %></p>
|
<p><%= @album.description %></p>
|
||||||
<% if has_permission?("see_album_note") %>
|
<p>Tagged with: <%= @album.tags.map {|tag| (link_to tag.title, tag_photos_path(tag) ) + " " } %></p>
|
||||||
|
|
||||||
|
<% if has_role?("admin") %>
|
||||||
|
<p><%= @album.address %></p>
|
||||||
|
<% end %>
|
||||||
|
<% if has_role?("admin") %>
|
||||||
<p><%= @album.note %></p>
|
<p><%= @album.note %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for :action_links do %>
|
||||||
<% if has_role?("admin") %>
|
<% if has_role?("admin") %>
|
||||||
<br /><%= link_to "Update album", edit_album_path(@album) %>
|
<%= link_to "Edit album", edit_album_path(@album) %> |
|
||||||
<br /><%= link_to "Update photos", edit_multiple_album_photos_path(@album) %>
|
<%= link_to "Edit all photos", edit_multiple_album_photos_path(@album) %> |
|
||||||
<br /><%= link_to "Upload photos", upload_album_photos_path(@album) %>
|
<%= link_to "Add photos", upload_album_photos_path(@album) %>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<br /><%= link_to "All albums", albums_path %>
|
|
|
@ -8,6 +8,8 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% content_for :action_links do %>
|
||||||
<% if has_role?("admin") %>
|
<% if has_role?("admin") %>
|
||||||
<p style="clear:both;"><%= link_to "New collection", new_collection_path %></p>
|
<%= link_to "New collection", new_collection_path %></p>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
|
@ -13,10 +13,9 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div style="clear:both;">
|
<% content_for :action_links do %>
|
||||||
<% if has_role?("admin") %>
|
<% if has_role?("admin") %>
|
||||||
<br /><%= link_to "Update collection", edit_collection_path(@collection) %>
|
<%= link_to "Edit collection", edit_collection_path(@collection) %> |
|
||||||
<br /><%= link_to "New album", new_collection_album_path(@collection) %>
|
<%= link_to "New album", new_collection_album_path(@collection) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<br /><%= link_to "All collections", collections_path %>
|
<% end %>
|
||||||
</div>
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<%= breadcrumbs %>
|
<%= breadcrumbs %>
|
||||||
|
<%= yield :action_links %>
|
||||||
<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"/>
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<p style="color: green"><%= flash[:notice] %></p>
|
<p id="notice"><%= flash[:notice] %></p>
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<% content_for :javascript do %>
|
<% content_for :javascript do %>
|
||||||
<script src="/javascripts/tag/tag.js" type="text/javascript" charset="utf-8"></script>
|
<script src="/javascripts/tag/tag.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= hidden_field_tag :all_tags, "'#{Tag.find(:all).map { |tag| tag.title }.join('\',\'')}'" %>
|
<%= hidden_field_tag :all_tags, @tags %>
|
||||||
<%= form.label :title %><br />
|
<%= form.label :title %><br />
|
||||||
<%= form.text_field :title %><br />
|
<%= form.text_field :title %><br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<h1>Edit Photo</h1>
|
<h1>Edit Photo</h1>
|
||||||
|
|
||||||
|
<%= image_tag @photo.path_modified_public("preview") %>
|
||||||
|
|
||||||
<% form_for @photo do |f| %>
|
<% form_for @photo do |f| %>
|
||||||
<%= f.error_messages %>
|
<%= f.error_messages %>
|
||||||
|
@ -6,8 +8,8 @@
|
||||||
<%= f.submit "Update" %>
|
<%= f.submit "Update" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= image_tag @photo.path_modified_public("large") %>
|
<% content_for :action_links do %>
|
||||||
<br /><%= link_to("Delete photo", { :action => "destroy", :id => @photo },
|
<%= link_to("Delete photo", { :action => "destroy", :id => @photo },
|
||||||
:confirm => "Are you sure you want to delete this photo?",
|
:confirm => "Are you sure you want to delete this photo?",
|
||||||
:method => :delete) %>
|
:method => :delete) %>
|
||||||
<br /><%= link_to "All albums", albums_path %>
|
<% end %>
|
|
@ -17,12 +17,11 @@
|
||||||
<p><%= image_tag @photo.path_modified_public("single") %></p>
|
<p><%= image_tag @photo.path_modified_public("single") %></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br/>
|
|
||||||
Tagged with: <%= @photo.tag_list %>
|
|
||||||
<p><%= @photo.description %></p>
|
<p><%= @photo.description %></p>
|
||||||
|
<p>Tagged with: <%= @photo.tags.map {|tag| (link_to tag.title, tag_photos_path(tag) ) + " " } %></p>
|
||||||
|
|
||||||
|
<% content_for :action_links do %>
|
||||||
<% if has_role?("admin") %>
|
<% if has_role?("admin") %>
|
||||||
<br /><%= link_to "Update photo details", edit_photo_path(@photo) %>
|
<br /><%= link_to "Edit photo", edit_photo_path(@photo) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<br /><%= link_to "Back to #{@photo.album.title}", @photo.album %>
|
<% end %>
|
||||||
<br /><%= link_to "All albums", albums_path %>
|
|
|
@ -51,7 +51,6 @@ module ScanFiles
|
||||||
img.resize!(cols, rows)
|
img.resize!(cols, rows)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
puts "hello"
|
|
||||||
puts "write... " + APP_CONFIG[:thumbs_path] + photo.album.path + "/" + photo.id.to_s + "_" + thumbname + File.extname( APP_CONFIG[:photos_path] + photo.path )
|
puts "write... " + APP_CONFIG[:thumbs_path] + photo.album.path + "/" + photo.id.to_s + "_" + thumbname + File.extname( APP_CONFIG[:photos_path] + photo.path )
|
||||||
thumb.write(APP_CONFIG[:thumbs_path] + photo.album.path + "/" + photo.id.to_s + "_" + thumbname + File.extname( APP_CONFIG[:photos_path] + photo.path ) ) { self.quality = 100 }
|
thumb.write(APP_CONFIG[:thumbs_path] + photo.album.path + "/" + photo.id.to_s + "_" + thumbname + File.extname( APP_CONFIG[:photos_path] + photo.path ) ) { self.quality = 100 }
|
||||||
#image.change_geometry!(MAINSITE_SIZE) { |cols, rows, img|
|
#image.change_geometry!(MAINSITE_SIZE) { |cols, rows, img|
|
||||||
|
|
|
@ -191,4 +191,7 @@ div#header h1 p {
|
||||||
}
|
}
|
||||||
td {
|
td {
|
||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
|
}
|
||||||
|
p#notice {
|
||||||
|
color: green;
|
||||||
}
|
}
|
Loading…
Reference in a new issue