Merge pull request #33 from differentreality/final_difficulty_levels

Add difficulty levels
This commit is contained in:
Henne Vogelsang 2014-03-03 10:40:21 +01:00
commit 4ed72d4967
15 changed files with 119 additions and 3 deletions

View file

@ -0,0 +1,30 @@
class Admin::DifficultyLevelsController < ApplicationController
before_filter :verify_organizer
def index
@conference = Conference.find_all_by_short_title(params[:conference_id]).first
end
def update
if @conference.update_attributes(params[:conference])
if !(@conference.difficulty_levels.count > 0) && @conference.use_difficulty_levels == true
begin
@conference.use_difficulty_levels = false
@conference.save!
flash[:error] = "You cannot enable the usage of difficulty levels without having set any levels."
redirect_to(admin_conference_difficulty_levels_path(:conference_id => @conference.short_title))
rescue ActiveRecord::RecordInvalid
flash[:error] = "Something went wrong. Difficulty Levels update failed."
redirect_to(admin_conference_difficulty_levels_path(:conference_id => @conference.short_title))
end
else
flash[:notice] = "Difficulty Levels were successfully updated."
redirect_to(admin_conference_difficulty_levels_path(:conference_id => @conference.short_title))
end
else
flash[:error] = "Difficulty Levels update failed."
redirect_to(admin_conference_difficulty_levels_path(:conference_id => @conference.short_title))
end
end
end

View file

@ -71,6 +71,7 @@ class Admin::EventsController < ApplicationController
@comments = @event.root_comments
@comment_count = @event.comment_threads.count
@ratings = @event.votes.includes(:person)
@difficulty_levels = @conference.difficulty_levels
end
def edit
@ -102,6 +103,9 @@ class Admin::EventsController < ApplicationController
if params.has_key? :event_type_id
@event.update_attribute(:event_type_id, params[:event_type_id])
end
if params.has_key? :difficulty_level_id
@event.update_attribute(:difficulty_level_id, params[:difficulty_level_id])
end
if @event.update_attributes(params[:event]) && @event.submitter.update_attributes(params[:person])
flash[:notice] = "Successfully updated #{@event.title}."
else

View file

@ -2,7 +2,7 @@ class Conference < ActiveRecord::Base
attr_accessible :title, :short_title, :social_tag, :contact_email, :timezone, :html_export_path,
:start_date, :end_date, :rooms_attributes, :tracks_attributes, :dietary_choices_attributes,
:use_dietary_choices, :use_supporter_levels, :supporter_levels_attributes, :social_events_attributes,
:event_types_attributes, :registration_start_date, :registration_end_date, :logo
:event_types_attributes, :difficulty_levels_attributes, :use_difficulty_levels, :registration_start_date, :registration_end_date, :logo
has_paper_trail
@ -15,6 +15,7 @@ class Conference < ActiveRecord::Base
has_many :events, :dependent => :destroy
has_many :event_types, :dependent => :destroy
has_many :tracks, :dependent => :destroy
has_many :difficulty_levels, :dependent => :destroy
has_many :rooms, :dependent => :destroy
has_many :registrations, :dependent => :destroy
@ -22,6 +23,7 @@ class Conference < ActiveRecord::Base
accepts_nested_attributes_for :rooms, :reject_if => proc {|r| r["name"].blank?}, :allow_destroy => true
accepts_nested_attributes_for :tracks, :reject_if => proc {|r| r["name"].blank?}, :allow_destroy => true
accepts_nested_attributes_for :difficulty_levels, :allow_destroy => true
accepts_nested_attributes_for :social_events, :allow_destroy => true
accepts_nested_attributes_for :venue
accepts_nested_attributes_for :dietary_choices, :allow_destroy => true
@ -41,6 +43,7 @@ class Conference < ActiveRecord::Base
:social_tag
validates_uniqueness_of :short_title
validates_format_of :short_title, :with => /^[a-zA-Z0-9_-]*$/
before_create :generate_guid
before_create :create_venue
before_create :create_email_settings

View file

@ -0,0 +1,8 @@
class DifficultyLevel < ActiveRecord::Base
attr_accessible :title, :description, :color
belongs_to :conference
has_many :events
validates :title, :presence => true
end

View file

@ -1,8 +1,8 @@
class Event < ActiveRecord::Base
include ActiveRecord::Transitions
has_paper_trail
attr_accessible :title, :subtitle, :abstract, :description, :event_type_id, :people_attributes, :person,
:proposal_additional_speakers, :track_id, :video_id, :video_type, :require_registration
attr_accessible :title, :subtitle, :abstract, :description, :event_type_id, :people_attributes, :person, :proposal_additional_speakers, :track_id, :video_id, :video_type, :require_registration, :difficulty_level_id
acts_as_commentable
has_many :event_people, :dependent => :destroy
@ -17,6 +17,7 @@ class Event < ActiveRecord::Base
belongs_to :track
belongs_to :room
belongs_to :difficulty_level
belongs_to :conference
accepts_nested_attributes_for :event_people, :allow_destroy => true
@ -92,6 +93,7 @@ class Event < ActiveRecord::Base
person
end
end
def as_json(options)
json = super(options)
@ -106,6 +108,7 @@ class Event < ActiveRecord::Base
else
json[:track_color] = self.track.color;
end
if self.event_type.nil?
json[:length] = 25
else
@ -114,6 +117,7 @@ class Event < ActiveRecord::Base
json
end
def transition_possible?(transition)
self.class.state_machine.events_for(self.current_state).include?(transition)
end
@ -125,6 +129,7 @@ class Event < ActiveRecord::Base
end
end
end
def process_acceptance(options)
if options[:send_mail] == "true"
Rails.logger.debug "Sending acceptance mail"
@ -156,6 +161,7 @@ class Event < ActiveRecord::Base
end
public_state
end
def abstract_word_count
if self.abstract.nil?
0
@ -163,6 +169,7 @@ class Event < ActiveRecord::Base
self.abstract.split.size
end
end
private
def abstract_limit
@ -184,6 +191,7 @@ class Event < ActiveRecord::Base
errors.add(:person_biography, "must be filled out")
end
end
def generate_guid
begin
guid = SecureRandom.urlsafe_base64

View file

@ -31,6 +31,10 @@
%li.active= link_to "Event Types", "#"
- else
%li= link_to "Event Types", admin_conference_eventtype_list_path(@conference.short_title)
- if activated == "Difficulty Levels"
%li.active= link_to "Difficulty Levels", "#"
- else
%li= link_to "Difficulty Levels", admin_conference_difficulty_levels_path(@conference.short_title)
- if activated == "Social Events"
%li.active= link_to "Social Events", "#"
- else

View file

@ -0,0 +1,6 @@
.nested-fields
= f.inputs do
= f.input :title, :required => true
= f.input :description, :input_html => {:rows => 3, :class => "span6"}
= f.input :color, :input_html => {:size => 6, :type => "color"}
= remove_association_link :difficulty_level, f

View file

@ -0,0 +1,9 @@
.container-fluid
.row-fluid
.span3
= render 'admin/conference/sidebar', :activated => "Difficulty Levels"
.span9
= semantic_form_for(@conference, :url => admin_conference_difficulty_levels_path(@conference.short_title)) do |f|
= f.input :use_difficulty_levels, :label => false
= dynamic_association :difficulty_levels, "Difficulty_Levels", f
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}

View file

@ -71,6 +71,21 @@
- @tracks.each do |track|
%li= link_to track.name, admin_conference_event_path(@conference.short_title, @event, :track_id => track.id) ,
:method => :put, :track_id => track.id
%tr
%td
%b Difficulty
%td
.dropdown
= link_to "#", :class => "dropdown-toggle", :id => "difficulty-dropdown" do
- if @event.difficulty_level.nil?
Difficulty Level
- else
= @event.difficulty_level.title
<b class="caret"></b>
%ul.dropdown-menu
- @difficulty_levels.each do |difficulty|
%li= link_to difficulty.title, admin_conference_event_path(@conference.short_title, @event, :difficulty_level_id => difficulty.id) ,
:method => :put, :difficulty_level_id => difficulty.id
- if !@event.room.nil?
%tr
%td

View file

@ -24,6 +24,8 @@
%b Type
%th
%b Track
%th
%b Difficulty
%th
%b State
- @events.each do |event|
@ -92,6 +94,8 @@
- @tracks.each do |track|
%li= link_to track.name, admin_conference_event_path(@conference.short_title, event, :track_id => track.id) ,
:method => :put, :track_id => track.id
%td
= event.difficulty_level.title if @conference.use_difficulty_levels && event.difficulty_level
%td
- if event.state == "withdrawn"
Withdrawn

View file

@ -15,6 +15,7 @@
%br
- else
= f.input :event_type_id,:as => :select, :collection => @event_types.map {|x| ["#{x.title} - #{show_time(x.length)}", x.id]}, :include_blank => false, :label => "Session Type"
= f.input :difficulty_level, :as => :select, :collection => @conference.difficulty_levels, :include_blank => "(Please select)" if @conference.use_difficulty_levels
= f.input :require_registration
= f.input :abstract, :input_html => {:rows => 5, :class => "span11"},
:required => true, :label => "Session Abstract"

View file

@ -35,6 +35,8 @@ Osem::Application.routes.draw do
post "/cfp" => "callforpapers#create", :as => "cfp_create"
get "/event_types" => "eventtype#show", :as => "eventtype_list"
put "/event_types" => "eventtype#update", :as => "eventtype_update"
put "/difficulty_levels" => "difficulty_levels#update"
resources :difficulty_levels
resources :events do
member do
post :comment

View file

@ -0,0 +1,12 @@
class CreateDifficultyLevels < ActiveRecord::Migration
def change
create_table :difficulty_levels do |t|
t.references :conference
t.string :title
t.text :description
t.string :color, :default => "#ffffff"
t.timestamps
end
end
end

View file

@ -0,0 +1,5 @@
class AddUseDifficultyLevelsToConference < ActiveRecord::Migration
def change
add_column :conferences, :use_difficulty_levels, :boolean, :default => false
end
end

View file

@ -0,0 +1,5 @@
class AddDifficultyLevelIdToEvents < ActiveRecord::Migration
def change
add_column :events, :difficulty_level_id, :integer
end
end