Permalink
Browse files

Adding max and threshold to each event

  • Loading branch information...
1 parent d590b66 commit a01a65d3a5d5295484d26bc1e347ce2cd4867620 @joshe committed Aug 23, 2011
View
@@ -48,7 +48,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- mysql2 (0.2.7)
+ mysql2 (0.2.11)
polyglot (0.3.1)
rack (1.2.3)
rack-mount (0.6.14)
@@ -1,6 +1,7 @@
class EventsController < ApplicationController
before_filter :confirm_logged_in
+ before_filter :populate_max, :only => [:new, :edit]
def index
@events = Event.all
@@ -28,6 +29,24 @@ def show
@event_users = @event.users
@user = User.find(session[:user_id])
@user_is_in = @event_users.include?(@user)
+
+ if @event.threshold > @event_user_count
+ @event_status = "nogo"
+ @event_users_remaining = @event.threshold - @event_user_count
+ if @event_users_remaining == 1
+ @event_users_remaining = "#{@event_users_remaining} person"
+ else
+ @event_users_remaining = "#{@event_users_remaining} people"
+ end
+ elsif @event.max <= @event_user_count
+ if @event.max == 0
+ @event_status = "go"
+ else
+ @event_status = "hitMax"
+ end
+ else
+ @event_status = "go"
+ end
end
def edit
@@ -45,6 +64,17 @@ def update
end
end
+ def populate_max
+ @max = Array.new
+ (0..150).each do |m|
+ if m == 0
+ @max << ["No max", 0]
+ else
+ @max << [m, m]
+ end
+ end
+ end
+
def join
@event = Event.find(params[:id])
@user = User.find(session[:user_id])
View
@@ -3,4 +3,6 @@ class Event < ActiveRecord::Base
has_and_belongs_to_many :users
+ validates :threshold, :presence => true
+ validates :max, :presence => true
end
@@ -1,6 +1,9 @@
-= form_for @event, :as => :event, :url => { :action => "create" } do |e|
- = e.text_field :event_title, :placeholder => "Event title"
- = e.text_field :event_cost, :placeholder => "Cost"
- = e.text_field :event_planner, :placeholder => "Planner"
-
- = submit_tag "Save"
+= e.text_field :event_title, :placeholder => "Event title"
+= e.text_field :event_cost, :placeholder => "Cost"
+= e.text_field :event_planner, :placeholder => "Planner"
+= e.label :threshold
+= e.select :threshold, (1..100).collect { |t| [t, t]}
+= e.label :max
+= e.select :max, @max, html_options = { :class => "max_select"}
+
+= submit_tag "Save"
@@ -1,3 +1,4 @@
%h4 Edit Event
= link_to "back to event page", event_path(@event.id)
-= render "event_fields"
+= form_for @event, :as => :event, :url => { :action => "update" } do |e|
+ = render :partial => "event_fields", :locals => {:e => e}
@@ -1,2 +1,3 @@
%h4 New Event
-= render "event_fields"
+= form_for @event, :as => :event, :url => { :action => "create" } do |e|
+ = render :partial => "event_fields", :locals => {:e => e}
@@ -1,6 +1,13 @@
%h4= @event.event_title
= link_to "< back to all events", events_path
= link_to "edit", edit_event_path
+- if @event_status == "nogo"
+ .eventStatus.nogo= "This event is currently a no go. It still needs #{@event_users_remaining} to join."
+- elsif @event_status == "hitMax"
+ .eventStatus.hitMax= "This event has reached maximum capacity: #{@event.max}"
+- else
+ .eventStatus.go= "This event is on."
+
%p= "Cost: $#{@event.event_cost}"
%p= "Cost per person: $#{@event_cpp}"
%p= "Number of users: #{@event_user_count}"
@@ -0,0 +1,11 @@
+class AddMaxAndThresholdToEvent < ActiveRecord::Migration
+ def self.up
+ add_column :events, :threshold, :integer, :default => 1
+ add_column :events, :max, :integer
+ end
+
+ def self.down
+ remove_column :events, :threshold
+ remove_column :events, :max
+ end
+end
View
@@ -10,14 +10,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110816031629) do
+ActiveRecord::Schema.define(:version => 20110823010039) do
create_table "events", :force => true do |t|
t.string "event_title"
t.float "event_cost"
t.string "event_planner"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "threshold", :default => 1
+ t.integer "max"
end
create_table "events_users", :id => false, :force => true do |t|

0 comments on commit a01a65d

Please sign in to comment.