Skip to content

Commit

Permalink
Fixed calendar, added pry as console
Browse files Browse the repository at this point in the history
  • Loading branch information
abangratz committed Aug 1, 2011
1 parent 17cd958 commit f14cc24
Show file tree
Hide file tree
Showing 12 changed files with 2,130 additions and 7,508 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ gem 'dm-timestamps', DM_VERSION
gem 'dm-observer', DM_VERSION
gem 'dm-is-list', DM_VERSION
gem 'dm-rails', DM_VERSION
gem 'dm-zone-types'
gem 'dm-devise', :git => 'git://github.com/jm81/dm-devise.git'
gem 'dm-paperclip', :git => 'git://github.com/abangratz/dm-paperclip.git'

Expand All @@ -36,6 +37,9 @@ gem 'will_paginate', '~> 3.0.pre2'
gem 'bb-ruby'
gem 'andand'

group :development, :test do
gem 'pry'
end

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
Expand Down
17 changes: 16 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ GEM
net-scp (>= 1.0.0)
net-sftp
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh
net-ssh (>= 2.0.14)
net-ssh-gateway
net-ssh-gateway (>= 1.0.0)
coderay (0.9.8)
data_objects (0.10.3)
addressable (~> 2.1)
datamapper (1.1.0)
Expand Down Expand Up @@ -129,6 +130,10 @@ GEM
uuidtools (~> 2.1.2)
dm-validations (1.1.0)
dm-core (~> 1.1.0)
dm-zone-types (0.3)
activesupport (>= 3.0.0.beta3)
dm-core
tzinfo
do_postgres (0.10.3)
data_objects (= 0.10.3)
erubis (2.6.6)
Expand All @@ -154,6 +159,8 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.6.0)
ruby_parser (>= 2.0.5)
mime-types (1.16)
mocha (0.9.12)
net-scp (1.0.4)
Expand All @@ -167,6 +174,11 @@ GEM
orm_adapter (0.0.4)
pg (0.10.1)
polyglot (0.3.1)
pry (0.9.3)
coderay (>= 0.9.8)
method_source (>= 0.6.0)
ruby_parser (>= 2.0.5)
slop (~> 1.9.0)
rack (1.2.2)
rack-mount (0.6.14)
rack (>= 1.0.0)
Expand All @@ -190,6 +202,7 @@ GEM
ruby_parser (2.0.6)
sexp_processor (~> 3.0)
sexp_processor (3.0.5)
slop (1.9.1)
stringex (1.2.1)
sugar-high (0.2.12)
mocha (~> 0.9.8)
Expand Down Expand Up @@ -228,12 +241,14 @@ DEPENDENCIES
dm-transactions (~> 1.1.0)
dm-types (~> 1.1.0)
dm-validations (~> 1.1.0)
dm-zone-types
haml
haml-rails
hpricot
jquery-rails
nokogiri
pg
pry
rails (= 3.0.5)
ruby_parser
unicorn
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/calendar_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CalendarEventsController < ApplicationController
def index
if params[:start] && params[:end]
the_range = Time.at(params[:start].to_i)..Time.at(params[:end].to_i)
@calendar_events = CalendarEvent.all(:start => the_range)
@calendar_events = CalendarEvent.all(:utc_start.gte => the_range.first, :utc_start.lte => the_range.last)
else
@calendar_events = CalendarEvent.all
end
Expand Down Expand Up @@ -48,8 +48,9 @@ def edit
# POST /calendar_events
# POST /calendar_events.xml
def create
params[:calendar_event][:start] = params[:start_date] + ' ' + params[:start_time]
params[:calendar_event][:end] = params[:end_date] + ' ' + params[:end_time]
params[:calendar_event][:start] = Time.zone.parse(params[:start_date] + ' ' + params[:start_time] )
params[:calendar_event][:end] = Time.zone.parse(params[:end_date] + ' ' + params[:end_time] )
logger.debug params
@calendar_event = CalendarEvent.new(params[:calendar_event])
@calendar_event.user = current_user

Expand All @@ -75,8 +76,6 @@ def update
params[:calendar_event][:end] = params[:end_date] + ' ' + params[:end_time]
end

params[:calendar_event][:start] = Time.zone.parse(params[:calendar_event][:start]).to_s
params[:calendar_event][:end] = Time.zone.parse(params[:calendar_event][:end]).to_s

logger.debug(params)
respond_to do |format|
Expand Down
40 changes: 29 additions & 11 deletions app/models/calendar_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class CalendarEvent

property :id, Serial

property :title, String, :required => true, :length => 10..50
property :location, String, :required => true, :length => 5..50
property :title, String, :required => true#, :length => 10..50
property :location, String, :required => true#, :length => 5..50
property :comment, Text
property :start, DateTime
property :end, DateTime
property :utc_start, ZonedTime, :required => true
property :utc_end, ZonedTime, :required => true
property :public, Boolean
property :max, Integer
property :overcommit, Integer
Expand All @@ -21,18 +21,36 @@ class CalendarEvent
belongs_to :user
has n, :subscriptions

validates_length_of :comment, :min => 15
#validates_length_of :comment, :min => 15

def start
super.in_time_zone.to_datetime
def allDay
false
end

def end
super.in_time_zone.to_datetime
def start=(time)
self.utc_start = case time
when ::String
DateTime.parse(time).utc
else
time.utc
end
end

def allDay
false
def end=(time)
self.utc_end = case time
when ::String
DateTime.parse(time).utc
else
time.utc
end
end

def start
self.utc_start.in_time_zone
end

def end
self.utc_end.in_time_zone
end

def to_json(options)
Expand Down
3 changes: 3 additions & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
# Load the rails application
require File.expand_path('../application', __FILE__)


# Initialize the rails application
Cf::Application.initialize!
13 changes: 13 additions & 0 deletions config/initializers/pry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
begin
require 'pry'
module Rails
class Console
class IRB
def self.start
Pry.start
end
end
end
end
rescue LoadError
end
8 changes: 4 additions & 4 deletions public/javascripts/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $(document).ready(function(){
allDaySlot: false,
defaultView: 'agendaWeek',
firstHour: 15,
//ignoreTimezone: false,
ignoreTimezone: true,
theme: true,
header: {
left: 'prev,next today',
Expand All @@ -72,7 +72,7 @@ $(document).ready(function(){
minWidth: 650,
minHeight: 500,
autoOpen: false,
}).load('/calendar_events/new', "event[start]=" + escape(startDate.format('isoDateTime')) + "&event[end]=" + escape(endDate.format('isoDateTime')), function() {
}).load('/calendar_events/new', "event[start]=" + escape(startDate.format('yyyy-mm-dd HH:MM:ss')) + "&event[end]=" + escape(endDate.format('yyyy-mm-dd HH:MM:ss')), function() {
btn = form.find(':submit');
var txt = btn.val();
btn.remove();
Expand Down Expand Up @@ -158,7 +158,7 @@ $(document).ready(function(){
$.ajax({
type: 'PUT',
url: '/calendar_events/' + event.id,
data: {"calendar_event": {"id" : event.id, "start": event.start.format('yyyy-mm-dd HH:MM:ss'), "end": event.end.format('yyyy-mm-dd HH:MM:ss')}},
data: {"calendar_event": {"id" : event.id, "start": event.start.format('isoDateTime'), "end": event.end.format('isoDateTime')}},
dataType: 'json',
error: function(xhr) {
}
Expand All @@ -169,7 +169,7 @@ $(document).ready(function(){
$.ajax({
type: 'PUT',
url: '/calendar_events/' + event.id,
data: {"calendar_event": {"id" : event.id, "start": event.start.format('yyyy-mm-dd HH:MM:ss'), "end": event.end.format('yyyy-mm-dd HH:MM:ss')}},
data: {"calendar_event": {"id" : event.id, "start": event.start.format('isoDateTime'), "end": event.end.format('isoDateTime')}},
dataType: 'json',
error: function(xhr) {
}
Expand Down
Loading

0 comments on commit f14cc24

Please sign in to comment.