Skip to content

Commit

Permalink
Checkin of the latest changes to the event / calendaring system. Events
Browse files Browse the repository at this point in the history
now have timezones, geocoding, all_day_events are handled properly as
far as storage and display in lists and grids, multi day events are
supported / displayed in day, week, month list, month grid formats
correctly, locations support state and country pulldowns to help
normalize event location data for later searching (with 'other state'
support store back into 'state' field), my calendar support with
default to grid view with calendar nav to get to day, week, month
list views.  Group calendar, invite (notify system), and attendee
message by host are not currently supported in this checkin.
have been made visible

git-svn-id: http://code.autistici.org/svn/crabgrass/branches/calendaring@1142 4da624d7-9686-4b4d-bf4a-96ca807925bb
  • Loading branch information
btcdave authored and Seth Walker committed Mar 23, 2008
1 parent dac697e commit d8c4c83
Show file tree
Hide file tree
Showing 37 changed files with 1,060 additions and 293 deletions.
151 changes: 118 additions & 33 deletions app/controllers/my_calendar_controller.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,136 @@
require 'calendar_dates/month_display.rb'
require 'calendar_dates/week.rb'

class MyCalendarController < ApplicationController
before_filter :login_required

helper :date
helper :event_time

layout 'me'
before_filter :login_required

# events / calendar code - most of these actions adapted from
# yossarian's indymedia calendar (with permission)

# greenchange_note: perms and path will have to be adjusted to match
# your system for all the actions below. The datetime logic should
# remain the same, but you will have to reconstruct your options /
# perms / paths for the finding of events I have also had to heavily
# modify the sql builder keywords and filters code to support the
# more complex queries to support multi day event spans this code
# could probably be refactored upon more time for further analysis
# and optimization

# for now, default index to calendar grid view
def index
params[:participate] ||= "interesting"
# by default all the events im watching or attending in the future
options = options_for_me()
path = '/type/event/' + params[:participate] + '/ascending/starts_at/starts/after/now'
@events = find_pages options, path
redirect_to :action => 'calendar_month'
end

def day
params[:participate] ||= "interesting"
# by default all the events im watching or attending in the future
options = options_for_me()
path = '/type/event/' + params[:participate] +'/ascending/starts_at/starts/after/today/before/today'
@events = find_pages options, path
render :action => 'index'
def list_by_day
if params[:date] == nil
@date = Date.today
else
@date = splitdate(params[:date])
end
datestring = @date.to_s

options = options_for_me(:public => true)
@events = Page.find_by_path(build_day_path(datestring,datestring2),options)
end

def list_by_week
if params[:date] == nil
today = Date.today
@date = Week.new(today).first_day_in_week
else
date = splitdate(params[:date])
@date = Week.new(date).first_day_in_week
end
list_one_week(@date)
end

def list_one_week(date)
@date = date
datestring = @date.to_s
datestring2 = (@date + 6).to_s

def week
last_sunday = Time.now - Time.now.wday.days
next_sunday = last_sunday + 7.days
options = options_for_me()
path = event_path + "after/#{last_sunday.to_date}/before/#{next_sunday.to_date}"
@events = find_pages options, path
render :action => 'index'
options = options_for_me(:public => true)
@events = Page.find_by_path(build_complex_path(datestring,datestring2),options)
end

def month
# by default all the events this month
# params[:month] not null shows all the events in the month month
if params[:month].nil?
first_day_month = Time.now - Time.now.mday.days
last_day_month = Time.now.next_month - Time.now.next_month.mday.days
options = options_for_me()
path = event_path + "after/#{first_day_month.to_date}/before/#{last_day_month.to_date}"
def list_by_month
if params[:date] == nil
today = Date.today
year = today.year
month = today.month
else
year = params[:date].split("-")[0].to_i
month = params[:date].split("-")[1].to_i
end
@date = Date.new(year,month)
datestring = @date.to_s
if @date.month < 12 # look for year rollover
datestring2 = (Date.new(@date.year,@date.month+1)).to_s
else
datestring2 = (Date.new(@date.year+1, 1)).to_s
end
@events = find_pages options, path
render :action => 'index'

options = options_for_me(:public => true)
@events = Page.find_by_path(build_complex_path(datestring,datestring2),options)
end

def calendar_month
list_by_month
@month_display = MonthDisplay.new(@date)
end

protected

def splitdate(datestring)
year = datestring.split("-")[0].to_i
month = datestring.split("-")[1].to_i
day = datestring.split("-")[2].to_i
date = Date.new(year, month, day)
date
end

def event_path
"/type/event/#{params[:participate]||'interesting'}/ascending/starts_at/starts/"
# greenchange_note: bypass current bug in sql builder per elijah's
# instructions.. need to revisit these perms for crabgrass trunk

# "/type/event/#{params[:participate]||'interesting'}/ascending/starts_at/starts/"
"/type/event/ascending/starts_at/"
end

# builds simpler case when resolution is one day
def build_day_path(datestring,datestring2)
event_path + "event_starts/event_starts_before/#{datestring.to_date}/event_ends/event_ends_after/#{datestring.to_date}"
end

# greenchange_note: not sure how your system will work below, but there
# are four types of cases to test for and this could probably be refactored
# once there is more time for analysis, this does work though.

# builds complex case when resolution greater than one day and you need
# to detect up to four distinct types of event time intersections with
# the resolution bounds
def build_complex_path(datestring,datestring2)

# event start/end at resolution bounds or within
type1 = "event_starts/event_starts_after/#{datestring.to_date}/event_starts_before/#{datestring2.to_date}/event_ends/event_ends_after/#{datestring.to_date}/event_ends_before/#{datestring2.to_date}/"

# event start/end spanning start of resolution bounds
type2 = "or/event_starts_before/#{datestring.to_date}/event_starts_before/#{datestring2.to_date}/event_ends_after/#{datestring.to_date}/event_ends_before/#{datestring2.to_date}/"

# event start/end spanning end of resolution bounds
type3 = "or/event_starts_after/#{datestring.to_date}/event_starts_before/#{datestring2.to_date}/event_ends_after/#{datestring.to_date}/event_ends_after/#{datestring2.to_date}/"

# event start/end is larger then resolution bounds
type4 = "or/event_starts_before/#{datestring.to_date}/event_starts_before/#{datestring2.to_date}/event_ends_after/#{datestring.to_date}/event_ends_after/#{datestring2.to_date}"

event_path + type1 + type2 + type3 + type4
end

append_before_filter :fetch_user
def fetch_user
@user = current_user
Expand All @@ -58,7 +143,7 @@ def authorized?

def context
me_context('large')
add_context 'inbox'.t, url_for(:controller => 'inbox', :action => 'index')
add_context 'calendar'.t, url_for(:controller => 'my_calendar', :action => 'index')
end


Expand Down
157 changes: 104 additions & 53 deletions app/controllers/tool/event_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'calendar_date_select'
require 'google_map'
require 'google_map_marker'

class Tool::EventController < Tool::BaseController
helper :event_time

append_before_filter :fetch_event
before_filter :login_required, :only => ['create', 'edit', 'new']

#stylesheet 'event'
before_filter :login_required, :only => ['set_event_description', 'create', 'edit', 'new', 'update']

def show
@user_participation= UserParticipation.find(:first, :conditions => {:page_id => @page.id, :user_id => @current_user.id})
Expand All @@ -16,43 +17,93 @@ def show
end
@watchers = UserParticipation.find(:all, :conditions => {:page_id => @page.id, :watch => TRUE})
@attendies = UserParticipation.find(:all, :conditions => {:page_id => @page.id, :attend => TRUE})

end

def edit

end

def update
@page.attributes = params[:page]
@event.attributes = params[:event]
if @page.save and @event.save
return redirect_to(event_url(@page))
else
message :object => @page
# greenchange_note: currently, you aren't able to change a group
# if one has already been set during event creation

if request.post?
@page.attributes = params[:page]
@event.attributes = params[:event]

# greenchange_note: HACK: all day events will be put in as UTC
# noon (note: there is no 'UTC' timezone available, so we are
# going to use 'London' for zero GMT offset as a hack for now)
# so that when viewed in calendars or lists, the events will
# always show up on the appropriate day ie, St. Patrick's day
# should always be on the 17th of March regardless of my frame
# of reference. Also, since we have a programmatic flag to
# identify all day events, this hack can be removed / migrated
# later to any required handling of all day events that might be
# more complex on the fetching side.
if params[:event][:is_all_day] == '1'
@event.time_zone = 'London' # greenchange_note: HACK: see above comment
params[:time_start] = params[:date_start] + " 12:00"
params[:time_end] = params[:date_start] + " 12:00"
else
params[:time_start] = params[:date_start] + " "+ params[:hour_start]
params[:time_end] = params[:date_end] + " " + params[:hour_end]
end

@page.starts_at = TzTime.new(params[:time_start].to_time,TimeZone[@event.time_zone]).utc
@page.ends_at = TzTime.new(params[:time_end].to_time,TimeZone[@event.time_zone]).utc

if @event.state == 'Other'
@event.state = params[:state_other]
end

if @page.save and @event.save
return redirect_to(page_url(@page))
else
message :object => @page
end
end
end


def new
@page_class = Tool::Event
@event = ::Event.new
@event = ::Event.new(:time_zone => current_user.time_zone)
end

def create
@page_class = Tool::Event
@page = create_new_page @page_class
@event = ::Event.new params[:event]

d = params[:date_start].split("/")
params[:date_start] = [d[1], d[0], d[2]].join("/")
params[:time_start] = params[:date_start] + " "+ params[:hour_start]
# greenchange_note: HACK: all day events will be put in as UTC
# noon (note: there is no 'UTC' timezone available, so we are
# going to use 'London' for zero GMT offset as a hack for now)
# so that when viewed in calendars or lists, the events will
# always show up on the appropriate day ie, St. Patrick's day
# should always be on the 17th of March regardless of my frame
# of reference. Also, since we have a programmatic flag to
# identify all day events, this hack can be removed / migrated
# later to any required handling of all day events that might be
# more complex on the fetching side.
if params[:event][:is_all_day] == '1'
@event.time_zone = 'London' # greenchange_note: HACK: see above comment
params[:time_start] = params[:date_start] + " 12:00"
params[:time_end] = params[:date_start] + " 12:00"
else
params[:time_start] = params[:date_start] + " "+ params[:hour_start]
params[:time_end] = params[:date_end] + " " + params[:hour_end]
end

@page.starts_at = TzTime.zone.local_to_utc(params[:time_start].to_time)
@page.starts_at = TzTime.new(params[:time_start].to_time,TimeZone[@event.time_zone]).utc
@page.ends_at = TzTime.new(params[:time_end].to_time,TimeZone[@event.time_zone]).utc

d = params[:date_end].split("/")
params[:date_end] = [d[1], d[0], d[2]].join("/")
if @event.state == 'Other'
@event.state = params[:state_other]
end

# greenchange_note: all events are public right now per green change / seth
@page.public = true

params[:time_end] = params[:date_end] + " " + params[:hour_end]
@page.ends_at = TzTime.zone.local_to_utc(params[:time_end].to_time)
@event = ::Event.new params[:event]
@page.data = @event
if @page.save
add_participants!(@page, params)
Expand All @@ -62,35 +113,35 @@ def create
end
end

def set_event_description
@event.description = params[:value]
@event.save
render :text => @event.description_html
end

def participate
@user_participation = UserParticipation.find(:first, :conditions => {:page_id => @page.id, :user_id => @current_user.id})
if !params[:user_participation_watch].nil?
@user_participation.watch = params[:user_participation_watch]
@user_participation.attend = false
else
if !params[:user_participation_attend].nil?
@user_participation.watch = false
@user_participation.attend = params[:user_participation_attend]
else
@user_participation.watch = false
@user_participation.attend = false
# remove the user participation from the table?
end
end

@user_participation.save

@watchers = UserParticipation.find(:all, :conditions => {:page_id => @page.id, :watch => TRUE})
@attendies = UserParticipation.find(:all, :conditions => {:page_id => @page.id, :attend => TRUE})

end

def set_event_description
@event.description = params[:value]
@event.save
render :text => @event.description_html
end

def participate
@user_participation = UserParticipation.find(:first, :conditions => {:page_id => @page.id, :user_id => @current_user.id})
if !params[:user_participation_watch].nil?
@user_participation.watch = params[:user_participation_watch]
@user_participation.attend = false
else
if !params[:user_participation_attend].nil?
@user_participation.watch = false
@user_participation.attend = params[:user_participation_attend]
else
@user_participation.watch = false
@user_participation.attend = false
# remove the user participation from the table?
end
end

@user_participation.save
@watchers = UserParticipation.find(:all, :conditions => {:page_id => @page.id, :watch => TRUE})
@attendies = UserParticipation.find(:all, :conditions => {:page_id => @page.id, :attend => TRUE})
end
protected

def fetch_event
Expand All @@ -108,7 +159,7 @@ def set_time (time)
end

def authorized?
if params[:action] == 'set_event_description' or params[:action] == 'edit'
if params[:action] == 'set_event_description' or params[:action] == 'edit' or params[:action] == 'update'
return current_user.may?(:admin, @page)
else
return true
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/date_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module DateHelper

def days_of_week
["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
end

end
Loading

0 comments on commit d8c4c83

Please sign in to comment.