recreate thumbs. css. thumb local for photo
This commit is contained in:
parent
c93ac2ad2c
commit
aa30654071
|
@ -1,6 +1,7 @@
|
||||||
class CollectionsController < ApplicationController
|
class CollectionsController < ApplicationController
|
||||||
|
|
||||||
before_filter :require_role_admin, :only => [:new, :create, :edit, :update, :destroy]
|
before_filter :require_role_admin, :only => [:new, :create, :edit, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@collections = Collection.find(:all)
|
@collections = Collection.find(:all)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -35,11 +36,11 @@ class CollectionsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@collection = Collection.find( params[:id])
|
@collection = Collection.find_by_title( params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@collection = Collection.find( params[:id])
|
@collection = Collection.find_by_title( params[:id])
|
||||||
if @collection.update_attributes(params[:collection])
|
if @collection.update_attributes(params[:collection])
|
||||||
flash[:notice] = "Collection updated!"
|
flash[:notice] = "Collection updated!"
|
||||||
redirect_to @collection
|
redirect_to @collection
|
||||||
|
@ -49,7 +50,7 @@ class CollectionsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@collection = Collection.find( params[:id])
|
@collection = Collection.find_by_title( params[:id])
|
||||||
if @collection.destroy
|
if @collection.destroy
|
||||||
redirect_to collections_path
|
redirect_to collections_path
|
||||||
else
|
else
|
||||||
|
|
|
@ -4,8 +4,9 @@ class Album < ActiveRecord::Base
|
||||||
has_many :collections, :through => :collection_albums
|
has_many :collections, :through => :collection_albums
|
||||||
|
|
||||||
validates_uniqueness_of :path, :message => "Album already exsists on disc"
|
validates_uniqueness_of :path, :message => "Album already exsists on disc"
|
||||||
|
validates_presence_of :title, :message => "can't be blank"
|
||||||
|
|
||||||
before_validation :ensure_path
|
before_validation :ensure_path, :set_title
|
||||||
after_create :create_folders
|
after_create :create_folders
|
||||||
after_destroy :destroy_folders
|
after_destroy :destroy_folders
|
||||||
|
|
||||||
|
@ -21,7 +22,11 @@ class Album < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
||||||
def ensure_path
|
def ensure_path
|
||||||
self.path = self.title if !self.path
|
self.path = self.title unless self.path
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_title
|
||||||
|
self.title = File.basename( File.dirname(self.path) ) unless self.title || !self.path
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list
|
def tag_list
|
||||||
|
@ -77,13 +82,13 @@ class Album < ActiveRecord::Base
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_folders
|
def create_folders
|
||||||
Dir.mkdir( APP_CONFIG[:photos_path] + self.path ) if !File.exists?( APP_CONFIG[:photos_path] + self.path )
|
Dir.mkdir( APP_CONFIG[:photos_path] + self.path ) unless File.exists?( APP_CONFIG[:photos_path] + self.path )
|
||||||
Dir.mkdir( APP_CONFIG[:thumbs_path] + self.path ) if !File.exists?( APP_CONFIG[:photos_path] + self.path )
|
Dir.mkdir( APP_CONFIG[:thumbs_path] + self.path ) unless File.exists?( APP_CONFIG[:thumbs_path] + self.path )
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_folders
|
def destroy_folders
|
||||||
#puts "DELETE DIRECTORY " + APP_CONFIG[:photos_path] + self.path
|
#puts "DELETE DIRECTORY " + 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[:photos_path] + self.path ) if File.exists?( 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 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
class Collection < ActiveRecord::Base
|
class Collection < ActiveRecord::Base
|
||||||
has_many :collection_albums
|
has_many :collection_albums
|
||||||
has_many :albums, :through => :collection_albums
|
has_many :albums, :through => :collection_albums
|
||||||
|
#accepts_nested_attributes_for :albums, :allow_destroy => true
|
||||||
|
attr_accessor :album_list
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
title.gsub(/[^a-z0-9]+/i, '-')
|
title.gsub(/[^a-z0-9]+/i, '-')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def album_list=(albums)
|
||||||
|
self.albums = Album.find(albums)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
|
@ -9,6 +9,7 @@ class Photo < ActiveRecord::Base
|
||||||
validates_uniqueness_of :path, :message => "Photo already exsists on disc"
|
validates_uniqueness_of :path, :message => "Photo already exsists on disc"
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
|
|
||||||
|
before_validation :set_title
|
||||||
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
|
||||||
|
@ -25,6 +26,10 @@ class Photo < ActiveRecord::Base
|
||||||
id.to_s + '-' + title.gsub(/[^a-z0-9]+/i, '-')
|
id.to_s + '-' + title.gsub(/[^a-z0-9]+/i, '-')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_title
|
||||||
|
self.title = File.basename( File.dirname(path) ).gsub( self.extension, "" ) unless self.title
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
@ -79,6 +84,24 @@ class Photo < ActiveRecord::Base
|
||||||
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) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def create_thumbnails
|
||||||
|
ImageScience.with_image(APP_CONFIG[:photos_path] + self.path) do |img|
|
||||||
|
img.cropped_thumbnail(200) do |thumb|
|
||||||
|
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_collection" + self.extension
|
||||||
|
end
|
||||||
|
img.cropped_thumbnail(100) do |thumb|
|
||||||
|
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_album" + self.extension
|
||||||
|
end
|
||||||
|
img.thumbnail(210) do |thumb|
|
||||||
|
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_preview" + self.extension
|
||||||
|
end
|
||||||
|
img.thumbnail(950) do |thumb|
|
||||||
|
thumb.save APP_CONFIG[:thumbs_path] + self.album.path + "/" + self.id.to_s + "_single" + self.extension
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,24 +119,6 @@ class Photo < ActiveRecord::Base
|
||||||
|
|
||||||
private
|
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
|
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?
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<p><%= render :partial => "photos/thumb", :locals => { :photo => album.photos.find(:first) } unless album.photos.empty? %></p>
|
<p><%= render :partial => "photos/thumb", :locals => { :photo => album.photos.find(:first), :photosize => 'collection' } unless album.photos.empty? %></p>
|
|
@ -6,7 +6,7 @@
|
||||||
<% for photo in @album.photos.find(:all, :order => "Id ASC") %>
|
<% for photo in @album.photos.find(:all, :order => "Id ASC") %>
|
||||||
<% count += 1%>
|
<% count += 1%>
|
||||||
<% if count == 1 || ( (count-1) / 4.0 == ( (count-1) / 4.0).to_i ) %><tr><% end %>
|
<% if count == 1 || ( (count-1) / 4.0 == ( (count-1) / 4.0).to_i ) %><tr><% end %>
|
||||||
<td><%= link_to image_tag( photo.path_modified_public("album") ), [@album.collections.first, @album, photo] %></td>
|
<td><%= link_to image_tag( photo.path_modified_public("preview") ), [@album.collections.first, @album, photo] %></td>
|
||||||
<% if count / 4.0 == (count / 4.0).to_i %></tr><% end %>
|
<% if count / 4.0 == (count / 4.0).to_i %></tr><% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -3,4 +3,9 @@
|
||||||
|
|
||||||
<%= form.label :description %><br />
|
<%= form.label :description %><br />
|
||||||
<%= form.text_area :description %><br />
|
<%= form.text_area :description %><br />
|
||||||
|
|
||||||
|
<%= form.label :album %><br />
|
||||||
|
<%= collection_select :collection, :album_list, Album.find(:all), :id, :title, {:selected => @collection.albums.map{|album|album.id} }, {:multiple => true, :rows => 10} %><br />
|
||||||
|
|
||||||
|
|
||||||
<br />
|
<br />
|
|
@ -6,7 +6,7 @@
|
||||||
<%= f.submit "Update" %>
|
<%= f.submit "Update" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<br /><%= link_to("Delete collection", { :action => "destroy", :id => @collection },
|
<br /><%= link_to("Delete this collection", { :action => "destroy", :id => @collection },
|
||||||
:confirm => "Are you sure you want to delete this collection?",
|
:confirm => "Are you sure you want to delete this collection?",
|
||||||
:method => :delete) %>
|
:method => :delete) %>
|
||||||
<br /><%= link_to "All collections", collections_path %>
|
<br /><%= link_to "All collections", collections_path %>
|
|
@ -3,7 +3,11 @@
|
||||||
<% for collection in @collections %>
|
<% for collection in @collections %>
|
||||||
<div class="thumb">
|
<div class="thumb">
|
||||||
<h3><%= link_to collection.title, collection %></h3>
|
<h3><%= link_to collection.title, collection %></h3>
|
||||||
<%= render :partial => collection.albums.find(:first) %>
|
<%= render :partial => collection.albums.find(:first), :locals => {:photosize => 'collection'} %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if has_role?("admin") %>
|
||||||
|
<br /><%= link_to "New collection", new_collection_path %>
|
||||||
|
<% end %>
|
|
@ -4,7 +4,7 @@
|
||||||
<% for album in @collection.albums %>
|
<% for album in @collection.albums %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<%= render :partial => "photos/thumb", :locals => {:photo => album.photos.first } %>
|
<%= render :partial => "photos/thumb", :locals => {:photo => album.photos.first } unless album.photos.empty? %>
|
||||||
<p><%= link_to album.title, collection_album_path(@collection, album) %></p>
|
<p><%= link_to album.title, collection_album_path(@collection, album) %></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="image">
|
<div class="image">
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<%= link_to ( image_tag photo.path_modified_public("album"), { :id => 'thumb_' + photo.id.to_s } ), photo_path(photo) %>
|
<%= link_to (image_tag photo.path_modified_public(defined?(photosize) ? photosize : "album") ), photo_path(photo) %>
|
|
@ -14,7 +14,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p><%= image_tag @photo.path_modified_public("large") %></p>
|
<p><%= image_tag @photo.path_modified_public("single") %></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
10
lib/scan.rb
10
lib/scan.rb
|
@ -18,12 +18,12 @@ module ScanFiles
|
||||||
end
|
end
|
||||||
if album.nil?
|
if album.nil?
|
||||||
puts "New album : " + File.basename( relpath )
|
puts "New album : " + File.basename( relpath )
|
||||||
album = Album.create( :path => relpath, :title => File.basename( File.dirname(path) ) )
|
album = Album.create( :path => relpath )
|
||||||
end
|
end
|
||||||
photo = Photo.find_by_path( relfile )
|
photo = Photo.find_by_path( relfile )
|
||||||
if photo.nil?
|
if photo.nil?
|
||||||
puts " New photo added " + relfile
|
puts " New photo added " + relfile
|
||||||
photo = Photo.create( :album => album, :title => File.basename(path).sub( File.extname(path), '' ) , :path => relfile )
|
photo = Photo.create( :album => album, :path => relfile )
|
||||||
else
|
else
|
||||||
puts " Found photo " + relfile
|
puts " Found photo " + relfile
|
||||||
end
|
end
|
||||||
|
@ -31,6 +31,12 @@ module ScanFiles
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.RecreateThumbnails
|
||||||
|
Photo.find(:all).each {|photo|
|
||||||
|
photo.create_thumbnails()
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def self.CreateThumbnail(photo,image,thumbname,width,height)
|
def self.CreateThumbnail(photo,image,thumbname,width,height)
|
||||||
puts "Create thumb of " + photo.path
|
puts "Create thumb of " + photo.path
|
||||||
thumb = image.first.resize_to_fill( width, height)
|
thumb = image.first.resize_to_fill( width, height)
|
||||||
|
|
|
@ -171,7 +171,7 @@ div.title {
|
||||||
width: 240px;
|
width: 240px;
|
||||||
}
|
}
|
||||||
.row div.title img, .row div.image img {
|
.row div.title img, .row div.image img {
|
||||||
width: 100px;
|
width: 100px;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
}
|
}
|
||||||
div.title img {
|
div.title img {
|
||||||
|
|
Loading…
Reference in a new issue