From 838e504cba92b9ce8b9c68158d4087a7935c121f Mon Sep 17 00:00:00 2001 From: Espen Antonsen Date: Mon, 3 Aug 2009 16:23:51 +0200 Subject: [PATCH] order of album --- README | 5 ++++- app/controllers/albums_controller.rb | 6 +++--- app/models/album.rb | 4 ++-- lib/scan.rb | 1 + 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README b/README index 0241bc4..064a4c5 100644 --- a/README +++ b/README @@ -59,7 +59,10 @@ Ruby Gems The gallery has a web-based upload tool using Flash. Alternatively you can upload files directly by doing this: -Put photos in containing folders(albums) in the specified gallery folder. This format is recommended: +Put photos in containing folders(albums) in the specified gallery folder. +Hierarchy of folders is not fully supported. + +This format is recommended: ./ski weekend in hemsedal/snow.jpg ./ski weekend in hemsedal/afterski.jpg diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 3912457..bdb97b7 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -4,14 +4,14 @@ class AlbumsController < ApplicationController def index if params[:tag_id] - @albums = Album.find(:all, :conditions => [ "id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.id IN ( SELECT photo_id FROM photo_tags WHERE photo_tags.tag_id = :q) )", { :q => Tag.find( params[:tag_id] ).id } ]) + @albums = Album.find(:all, :conditions => [ "id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.id IN ( SELECT photo_id FROM photo_tags WHERE photo_tags.tag_id = :q) )", { :q => Tag.find( params[:tag_id] ).id } ], :order => 'title') elsif params[:q] #search = params[:q] #search = search.split("AND").map{|q|q.strip} #@albums = Album.find(:all, :select => 'DISTINCT albums.id, albums.title', :limit => 20, :conditions => { :tags => {:title => search}}, :joins => 'LEFT OUTER JOIN photos ON albums.id = photos.album_id LEFT OUTER JOIN photo_tags ON photos.id = photo_tags.photo_id LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id', :order => "albums.title ASC" ) - @albums = Album.find(:all, :conditions => [ "id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.description LIKE :q OR photos.title LIKE :q OR photos.id IN ( SELECT photo_id FROM photo_tags LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id WHERE tags.title LIKE :q) )", { :q => '%' + params[:q] + '%' } ]) + @albums = Album.find(:all, :conditions => [ "id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.description LIKE :q OR photos.title LIKE :q OR photos.id IN ( SELECT photo_id FROM photo_tags LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id WHERE tags.title LIKE :q) )", { :q => '%' + params[:q] + '%' } ], :order => 'title') else - @albums = Album.find(:all) + @albums = Album.find(:all, :order => 'title') end respond_to do |format| format.html diff --git a/app/models/album.rb b/app/models/album.rb index 4745912..39da749 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -13,7 +13,7 @@ class Album < ActiveRecord::Base 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) )" + 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) )", :order => 'title' def to_param "#{id}-#{title.parameterize}" @@ -27,7 +27,7 @@ class Album < ActiveRecord::Base end def set_title - self.title = File.basename( File.dirname(self.path) ) unless self.title || !self.path + self.title = File.basename( self.path) unless self.title || !self.path end def tags diff --git a/lib/scan.rb b/lib/scan.rb index cdd70dd..814f033 100644 --- a/lib/scan.rb +++ b/lib/scan.rb @@ -1,5 +1,6 @@ module ScanFiles require "find" + supported_files = ["jpeg", "jpg", "gif", "png"]