Skip to content

Commit

Permalink
added event_calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
thu2004 committed Apr 17, 2010
1 parent 4c104e3 commit 6f0e507
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 20 deletions.
12 changes: 12 additions & 0 deletions app/controllers/member/play_right_bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ def index
@play_rights = PlayRight.find(:all)
end

def test
end

def calendar
@month = params[:month].to_i
@year = params[:year].to_i

@shown_month = Date.civil(@year, @month)

@event_strips = PlayRightBooking.event_strips_for_month(@shown_month)
end

def create
if request.post?
if match_precondition?
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Event < ActiveRecord::Base
has_many :event_participants, :dependent => :destroy
has_many :users, :through => :event_participants
validates_presence_of :name
validates_presence_of :start_date, :end_date, :max_participant
validates_presence_of :start_at, :end_at, :max_participant

def sponsor_name
return sponsor.name if sponsor
Expand Down
18 changes: 16 additions & 2 deletions app/models/play_right_booking.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class PlayRightBooking < ActiveRecord::Base
before_save :update_event_calendar_fields

belongs_to :play_right
belongs_to :user

Expand All @@ -7,8 +9,10 @@ class PlayRightBooking < ActiveRecord::Base

validates_presence_of :num_of_resource
validates_presence_of :booked_on

def validate

has_event_calendar

def validate
return if !self.new_record? # already save. skip futher validation

return if errors.size > 0 # make sure all fields are ok first
Expand All @@ -17,4 +21,14 @@ def validate

errors.add(:booked_on, "fully booked" ) if !play_right.is_free?(booked_on, num_of_resource)
end

def name
"#{play_right.name} - #{user.name}"
end

protected
def update_event_calendar_fields
self.start_at = self.end_at = self.booked_on
self.all_day = true
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/member/application.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>VIFF</title>
<%= stylesheet_link_tag "main", 'formtastic', 'formtastic_changes' , :media => "all" %>
<%= stylesheet_link_tag "main", 'formtastic', 'formtastic_changes', 'event_calendar' , :media => "all" %>
<%= javascript_include_tag :defaults %>
</head>

Expand Down
8 changes: 4 additions & 4 deletions app/views/member/event/index.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<p><%= event.description %></p>
<p>Information finns här <%= event.info_link %>
<ul>
<li>Start datum : <%= event.start_date%></li>
<li>Slut datum : <%= event.end_date %></li>
<li>Start datum : <%= event.start_at%></li>
<li>Slut datum : <%= event.end_at %></li>
<li>Max antal deltagare : <%= event.max_participant %></li>
<li>Antal anmälda deltagare : <%= event.users.size %>
</ul>
Expand Down Expand Up @@ -51,8 +51,8 @@
<p><%= event.description %></p>
<p>Information finns här <%= event.info_link %>
<ul>
<li>Start datum : <%= event.start_date%></li>
<li>Slut datum : <%= event.end_date %></li>
<li>Start datum : <%= event.start_at%></li>
<li>Slut datum : <%= event.end_at %></li>
<li>Max antal deltagare : <%= event.max_participant %></li>
<li>Antal anmälda deltagare : <%= event.users.size %>
</ul>
Expand Down
5 changes: 3 additions & 2 deletions app/views/member/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<%= form.input :name, :label => 'Name' %>
<%= form.input :description, :label => 'Description' %>
<%= form.input :info_link, :label => 'Info link' %>
<%= form.input :start_date, :label => 'Start date' %>
<%= form.input :end_date, :label => 'End date' %>
<%= form.input :start_at, :label => 'Start date' %>
<%= form.input :end_at, :label => 'End date' %>
<%= form.inout :all_day, :label => 'All date'%>
<%= form.input :max_participant, :label => 'Max participant' %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/member/play_right_bookings/calendar.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%=
play_right_booking_calendar
%>
4 changes: 3 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# Set to true in order to use Amazon's Simple Storage Service on your production machine
# instead of the default file system for resources and images
# Make sure to your bucket info is correct in amazon_s3.yml

Refinery.s3_backend = true

config.action_mailer.raise_delivery_errors = true
config.action_mailer.raise_delivery_errors = true

13 changes: 8 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is auto-generated from the current state of the database. Instead of editing this file,
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
#
Expand All @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100407121101) do
ActiveRecord::Schema.define(:version => 20100410201453) do

create_table "event_participants", :force => true do |t|
t.integer "user_id"
Expand All @@ -22,10 +22,11 @@
t.string "name", :limit => 60
t.text "description"
t.string "info_link", :limit => 80
t.datetime "start_date"
t.datetime "end_date"
t.datetime "start_at"
t.datetime "end_at"
t.integer "max_participant"
t.datetime "created_at"
t.boolean "all_day"
end

create_table "images", :force => true do |t|
Expand Down Expand Up @@ -138,6 +139,9 @@
t.text "information"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "start_at"
t.datetime "end_at"
t.boolean "all_day"
end

create_table "play_rights", :force => true do |t|
Expand Down Expand Up @@ -211,7 +215,6 @@
t.datetime "created_at"
end

add_index "slugs", ["name", "scope", "sequence", "sluggable_type"], :name => "index_slugs_on_name_and_sluggable_type_and_scope_and_sequence", :unique => true
add_index "slugs", ["sluggable_id"], :name => "index_slugs_on_sluggable_id"

create_table "user_plugins", :force => true do |t|
Expand Down
4 changes: 2 additions & 2 deletions test/factories/event_factory.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Factory.define :event do |f|
f.sequence(:name) { |n| "event_#{n}"}
f.max_participant 10
f.start_date 5.days.ago.to_s(:db)
f.end_date 1.days.ago.to_s(:db)
f.start_at 5.days.ago.to_s(:db)
f.end_at 1.days.ago.to_s(:db)
end
2 changes: 1 addition & 1 deletion test/unit/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class EventTest < ActiveSupport::TestCase
should_have_many :event_participants
should_have_many :users
should_validate_presence_of :name
should_validate_presence_of :start_date, :end_date, :max_participant
should_validate_presence_of :start_at, :end_at, :max_participant

context 'The factory' do
should 'that create unique post' do
Expand Down
11 changes: 10 additions & 1 deletion test/unit/play_right_booking_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PlayRightBookingTest < ActiveSupport::TestCase
should_validate_presence_of :booked_on

context 'The factory' do
should 'that create unique post' do
should 'that create unique post' do
o1 = Factory(:play_right_booking)
o2 = Factory(:play_right_booking)
assert_equal true, o1.valid?, o1.errors.full_messages
Expand Down Expand Up @@ -43,5 +43,14 @@ class PlayRightBookingTest < ActiveSupport::TestCase
playright.play_right_bookings.create(:booked_on => start_day + 2.days, :num_of_resource => 1)
assert_equal 2, playright.play_right_bookings.today.count
end

should "set event_calendar data correctly" do
o1 = Factory(:play_right).play_right_bookings.new(:booked_on => Date.today, :num_of_resource => 1)
assert_equal true, o1.valid?, o1.errors.full_messages
assert_equal nil, o1.start_at
assert o1.save
assert_not_equal nil, o1.start_at

end

end

0 comments on commit 6f0e507

Please sign in to comment.