diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 1aefd62..862d603 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -6,6 +6,9 @@ class AlbumsController < ApplicationController 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 } ]) 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] + '%' } ]) else @albums = Album.find(:all) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 20ef4d7..fce4674 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -10,7 +10,10 @@ class PhotosController < ApplicationController elsif params[:album_id] @photos = Album.find( params[:album_id]).photos.find(:all, :order => "photos.id ASC") elsif params[:q] - @photos = Photo.find(:all, :limit => 20, :conditions => [ "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] + '%' } ], :include => :album, :order => "photos.id ASC" ) + #search = params[:q] + #search = search.split("AND").map{|q|q.strip} + #@photos = Photo.find(:all, :select => 'DISTINCT photos.id, photos.album_id, photos.title, photos.path', :limit => 20, :conditions => { :tags => {:title => search}}, :joins => 'LEFT OUTER JOIN photo_tags ON photos.id = photo_tags.photo_id LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id', :include => [:album], :order => "photos.title ASC" ) + @photos = Photo.find(:all, :limit => 20, :conditions => [ "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 = :t) ", { :q => '%' + params[:q] + '%', :t => params[:q] } ], :include => :album, :order => "photos.id ASC" ) else @photos = Photo.find(:all, :order => "photos.id ASC") end diff --git a/app/models/photo.rb b/app/models/photo.rb index e112ddb..a850c1a 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -23,6 +23,17 @@ class Photo < ActiveRecord::Base named_scope :previous, lambda { |p,a| { :conditions => ["id < :id AND Album_Id = :album ", { :id => p, :album => a } ], :limit => 1, :order => "Id DESC"} } named_scope :next, lambda { |p,a| { :conditions => ["id > :id AND Album_Id = :album ", { :id => p, :album => a } ], :limit => 1, :order => "Id ASC"} } + def self.search(q) + if q + conditions = q.split("AND").each {|var| + + } + find(:all) + else + find(:all) + end + end + def to_param self.id.to_s + '-' + self.title.parameterize end diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb index 4d6492a..cf37bcc 100644 --- a/app/views/albums/_form.html.erb +++ b/app/views/albums/_form.html.erb @@ -3,7 +3,7 @@ <% end %> -
+ <%= hidden_field_tag :all_tags, "'#{Tag.find(:all).map { |tag| tag.title }.join('\',\'')}'" %> <%= hidden_field_tag :collection_id, params[:collection_id] %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index e285e55..426940b 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -5,10 +5,11 @@ jQuery(function($) { tags: $('#all_tags').val().split('\'') }) } - - if ( $('#map_canvas').length ) { - var map, locations_on_map = new Array(); + + var map, locations_on_map = new Array(); + if ( $('#map_canvas').length && $('#album_latitude').val() > '' && $('#album_longitude').val() > '' ) { mapInitialize() + $('#map_canvas').show() } $("#album_address").change( function () { @@ -17,6 +18,11 @@ jQuery(function($) { geocoder.getLatLng( $("#album_address").val() , function(point) { //console.log( point ) if ( point ) { + if (typeof map == "undefined") { + $('#map_canvas').show() + mapInitialize() + } + $('#album_latitude').val( point.lat() ) $('#album_longitude').val( point.lng() ) map.setCenter(new GLatLng( $('#album_latitude').val(), $('#album_longitude').val()), 13); @@ -24,7 +30,9 @@ jQuery(function($) { map.addOverlay(marker); } else - { alert('Unable to find address') } + { + $('#map_canvas').hide() + } } ) } diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index fa2dba1..206dc08 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -191,6 +191,14 @@ div#header h1 p { font-weight: normal; } +DIV#map_canvas { + width: 500px; + height: 300px; + float:right; + border:4px solid black; + display: none; +} + DIV#breadcrumb { float: left; }