Skip to content

Commit

Permalink
Events index shows local events only! F#@$ yeah! Events controller cr…
Browse files Browse the repository at this point in the history
…eate map can take a zoom level now. Event/show is zoomed in further.
  • Loading branch information
bcaplan committed Mar 17, 2009
1 parent 7eb4bb5 commit e689d71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class EventsController < ApplicationController
# GET /events
# GET /events.xml
def index
@events = Event.sort(params[:page], params[:sorted_by], session[:upcoming])
create_map @ip_location
@events = Event.sort(params[:page], params[:sorted_by], session[:upcoming], @ip_location)
create_map @ip_location, 10

respond_to do |format|
format.html # index.html.erb
Expand All @@ -17,7 +17,7 @@ def index
# GET /events/1.xml
def show
@event = Event.find(params[:id])
create_map @event.location
create_map @event.location, 16

respond_to do |format|
format.html # show.html.erb
Expand Down Expand Up @@ -89,10 +89,10 @@ def destroy

private

def create_map(location)
def create_map(location, zoom = 15)
@map = GMap.new('map')
@map.control_init(:large_map_3d => true,:map_type => true, :scale => true)
@map.center_zoom_init([location[:latitude],location[:longitude]],8)
@map.center_zoom_init([location[:latitude],location[:longitude]],zoom)
@map.add_map_type_init(GMapType::G_PHYSICAL_MAP)
@map.set_map_type_init(GMapType::G_PHYSICAL_MAP)
get_upcoming_markers.each do |marker|
Expand Down
12 changes: 9 additions & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ class Event < ActiveRecord::Base

belongs_to :group
belongs_to :location
acts_as_mappable :through => :location

validates_presence_of :group_id, :location_id, :start_time, :end_time

def self.sort(page, order, upcoming = 'true')
if upcoming == 'true'
SEARCH_RADIUS = 50 # miles

# TODO: Make this less redundant. It would be easier if upcoming could be called after paginate.
def self.sort(page, order, upcoming = 'true', location = nil)
if upcoming == 'true' && !location.nil?
self.upcoming.find_within(SEARCH_RADIUS, :origin => location.to_a.map { |a, b| b }).paginate({ :page => page, :per_page => 10, :order => order, :include => ['group', 'location'] })
elsif upcoming == 'true' && location.nil?
self.upcoming.paginate({ :page => page, :per_page => 10, :order => order, :include => ['group', 'location'] })
else
paginate({ :page => page, :per_page => 10, :order => order, :include => ['group', 'location'] })
self.paginate({ :page => page, :per_page => 10, :order => order, :include => ['group', 'location'] })
end
end

Expand Down

0 comments on commit e689d71

Please sign in to comment.