menu on top. css notice. tags as array

This commit is contained in:
Espen Antonsen 2009-06-16 21:43:03 +02:00
parent 5b227a7774
commit 7e418f9003
14 changed files with 63 additions and 52 deletions

View file

@ -55,14 +55,11 @@ class PhotosController < ApplicationController
end
def create
RAILS_DEFAULT_LOGGER.info('create method')
respond_to do |format|
@photo = Photo.new(params[:photo])
if params[:Filedata]
RAILS_DEFAULT_LOGGER.info('getting file')
@photo.swf_uploaded_data = params[:Filedata]
if @photo.save
RAILS_DEFAULT_LOGGER.info('saved')
format.html { render :text => "FILEID:" + @photo.path_modified_public("album") }
format.xml { render :nothing => true }
else
@ -84,6 +81,7 @@ class PhotosController < ApplicationController
def edit
@photo = Photo.find( params[:id])
@tags = Tag.find(:all).map { |tag| tag.title }.join('\',\'')
end
def edit_multiple

View file

@ -8,7 +8,7 @@ module ApplicationHelper
#links = "You are here: "
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|
level = level.gsub(/^[0-9]+\-/,"") #if levels[index-1] == "photos"

View file

@ -10,7 +10,7 @@ class Album < ActiveRecord::Base
after_create :create_folders
after_destroy :destroy_folders
attr_accessor :tag_list
attr_accessor :tags
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) )"
@ -30,7 +30,7 @@ class Album < ActiveRecord::Base
self.title = File.basename( File.dirname(self.path) ) unless self.title || !self.path
end
def tag_list
def tags
# should maybe cache this to database?
# should maybe return array instead?
@ -52,13 +52,13 @@ class Album < ActiveRecord::Base
tags = tags & photo_tags
end
}
return tags.collect{|tag| tag.title }.sort.join(" ")
return tags
end
def tag_list=(tags)
return if tags.split(" ").sort.join(" ") == self.tag_list
def tags=(tags)
tags = tags.split(" ").sort
return if tags == self.tag_list
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
# i.e. tags listed in self.tag_list but no in parameter tags

View file

@ -10,9 +10,10 @@ class Photo < ActiveRecord::Base
validates_presence_of :title
before_validation :set_title
before_save :ensure_file
before_create :exif_read
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
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"} }
def to_param
id.to_s + '-' + title.gsub(/[^a-z0-9]+/i, '-')
end
def set_title
self.title = File.basename( File.dirname(path) ).gsub( self.extension, "" ) unless self.title
self.id.to_s + '-' + self.title.parameterize
end
def path_original_public
@ -53,9 +50,8 @@ class Photo < ActiveRecord::Base
self.reload
end
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
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.
# From: http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
def swf_uploaded_data=(data)
RAILS_DEFAULT_LOGGER.info('swf_uploaded_data start')
data.content_type = MIME::Types.type_for(data.original_filename)
self.title = 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) }
RAILS_DEFAULT_LOGGER.info('swf_uploaded_data done')
end
def create_thumbnails
RAILS_DEFAULT_LOGGER.info('create thumb')
ImageScience.with_image(APP_CONFIG[:photos_path] + self.path) do |img|
ImageScience.with_image(self.path_original) 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
@ -106,8 +99,7 @@ class Photo < ActiveRecord::Base
end
protected
def extension
return File.extname(self.path_original)
end
@ -122,12 +114,20 @@ class Photo < ActiveRecord::Base
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
photo = MiniExiftool.new(self.path_original)
self.longitude = photo.GPSLongitude if self.longitude.nil?
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.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(" "))
end
@ -143,9 +143,10 @@ class Photo < ActiveRecord::Base
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 + "_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 ) )
File.delete( self.path_original ) if File.exists?( self.path_original )
File.delete( self.path_modified("_collection") ) if File.exists?( self.path_modified("_collection") )
File.delete( self.path_modified("_album") ) if File.exists?( self.path_modified("_album") )
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

View file

@ -12,7 +12,8 @@ class Tag < ActiveRecord::Base
def to_param
#id.to_s+'-'+
title.downcase.gsub(/[^a-z0-9]+/i, '-')
self.title.parameterize
#title.downcase.gsub(/[^a-z0-9]+/i, '-')
end
protected

View file

@ -13,13 +13,19 @@
</div>
<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>
<% end %>
<% content_for :action_links do %>
<% if has_role?("admin") %>
<br /><%= link_to "Update album", edit_album_path(@album) %>
<br /><%= link_to "Update photos", edit_multiple_album_photos_path(@album) %>
<br /><%= link_to "Upload photos", upload_album_photos_path(@album) %>
<%= link_to "Edit album", edit_album_path(@album) %> |&nbsp;
<%= link_to "Edit all photos", edit_multiple_album_photos_path(@album) %> |&nbsp;
<%= link_to "Add photos", upload_album_photos_path(@album) %>
<% end %>
<% end %>
<br /><%= link_to "All albums", albums_path %>

View file

@ -8,6 +8,8 @@
<% end %>
</div>
<% content_for :action_links do %>
<% 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 %>

View file

@ -13,10 +13,9 @@
</div>
<% end %>
<div style="clear:both;">
<% content_for :action_links do %>
<% if has_role?("admin") %>
<br /><%= link_to "Update collection", edit_collection_path(@collection) %>
<br /><%= link_to "New album", new_collection_album_path(@collection) %>
<%= link_to "Edit collection", edit_collection_path(@collection) %> |
<%= link_to "New album", new_collection_album_path(@collection) %>
<% end %>
<br /><%= link_to "All collections", collections_path %>
</div>
<% end %>

View file

@ -12,6 +12,7 @@
<div id="header">
<%= breadcrumbs %>
<%= yield :action_links %>
<h1>ImageGallery</h1>
<form action="/photos" method="get" id="search">
<input type="text" name="q" class="textfie.d"/>
@ -21,7 +22,7 @@
</div>
<div id="content">
<p style="color: green"><%= flash[:notice] %></p>
<p id="notice"><%= flash[:notice] %></p>
<%= yield %>
</div>

View file

@ -1,7 +1,7 @@
<% 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('\',\'')}'" %>
<%= hidden_field_tag :all_tags, @tags %>
<%= form.label :title %><br />
<%= form.text_field :title %><br />
<br />

View file

@ -1,4 +1,6 @@
<h1>Edit Photo</h1>
<%= image_tag @photo.path_modified_public("preview") %>
<% form_for @photo do |f| %>
<%= f.error_messages %>
@ -6,8 +8,8 @@
<%= f.submit "Update" %>
<% end %>
<%= image_tag @photo.path_modified_public("large") %>
<br /><%= link_to("Delete photo", { :action => "destroy", :id => @photo },
<% content_for :action_links do %>
<%= link_to("Delete photo", { :action => "destroy", :id => @photo },
:confirm => "Are you sure you want to delete this photo?",
:method => :delete) %>
<br /><%= link_to "All albums", albums_path %>
<% end %>

View file

@ -17,12 +17,11 @@
<p><%= image_tag @photo.path_modified_public("single") %></p>
</div>
<br/>
Tagged with: <%= @photo.tag_list %>
<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") %>
<br /><%= link_to "Update photo details", edit_photo_path(@photo) %>
<br /><%= link_to "Edit photo", edit_photo_path(@photo) %>
<% end %>
<br /><%= link_to "Back to #{@photo.album.title}", @photo.album %>
<br /><%= link_to "All albums", albums_path %>
<% end %>

View file

@ -51,7 +51,6 @@ module ScanFiles
img.resize!(cols, rows)
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 )
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|

View file

@ -191,4 +191,7 @@ div#header h1 p {
}
td {
vertical-align: bottom;
}
p#notice {
color: green;
}