diff --git a/app/controllers/admin/difficulty_levels_controller.rb b/app/controllers/admin/difficulty_levels_controller.rb new file mode 100644 index 00000000..6b500ac1 --- /dev/null +++ b/app/controllers/admin/difficulty_levels_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 5c486b50..89266b71 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -70,6 +70,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 @@ -101,6 +102,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 diff --git a/app/models/conference.rb b/app/models/conference.rb index d1be19fb..28c7a1a0 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -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 diff --git a/app/models/difficulty_level.rb b/app/models/difficulty_level.rb new file mode 100644 index 00000000..6dd526fe --- /dev/null +++ b/app/models/difficulty_level.rb @@ -0,0 +1,8 @@ +class DifficultyLevel < ActiveRecord::Base + attr_accessible :title, :description, :color + + belongs_to :conference + has_many :events + + validates :title, :presence => true +end \ No newline at end of file diff --git a/app/models/event.rb b/app/models/event.rb index b5aafd29..9abc4521 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 diff --git a/app/views/admin/conference/_sidebar.html.haml b/app/views/admin/conference/_sidebar.html.haml index 17c35727..e082fb9f 100644 --- a/app/views/admin/conference/_sidebar.html.haml +++ b/app/views/admin/conference/_sidebar.html.haml @@ -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 diff --git a/app/views/admin/difficulty_levels/_difficulty_level_fields.html.haml b/app/views/admin/difficulty_levels/_difficulty_level_fields.html.haml new file mode 100644 index 00000000..5e8d86ab --- /dev/null +++ b/app/views/admin/difficulty_levels/_difficulty_level_fields.html.haml @@ -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 \ No newline at end of file diff --git a/app/views/admin/difficulty_levels/index.html.haml b/app/views/admin/difficulty_levels/index.html.haml new file mode 100644 index 00000000..c720a402 --- /dev/null +++ b/app/views/admin/difficulty_levels/index.html.haml @@ -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"} \ No newline at end of file diff --git a/app/views/admin/events/_proposal.html.haml b/app/views/admin/events/_proposal.html.haml index 1e931836..0d66c232 100644 --- a/app/views/admin/events/_proposal.html.haml +++ b/app/views/admin/events/_proposal.html.haml @@ -72,6 +72,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 + + %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 diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index e5fd2047..604594ac 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -23,6 +23,8 @@ %b Type %th %b Track + %th + %b Difficulty %th %b State - @events.each do |event| @@ -90,6 +92,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 diff --git a/app/views/proposal/_proposal_form.html.haml b/app/views/proposal/_proposal_form.html.haml index 6159c54a..762ff6ac 100644 --- a/app/views/proposal/_proposal_form.html.haml +++ b/app/views/proposal/_proposal_form.html.haml @@ -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" diff --git a/config/routes.rb b/config/routes.rb index a5451c60..27847b88 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20140212172244_create_difficulty_levels.rb b/db/migrate/20140212172244_create_difficulty_levels.rb new file mode 100644 index 00000000..c4f06239 --- /dev/null +++ b/db/migrate/20140212172244_create_difficulty_levels.rb @@ -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 diff --git a/db/migrate/20140212175251_add_use_difficulty_levels_to_conference.rb b/db/migrate/20140212175251_add_use_difficulty_levels_to_conference.rb new file mode 100644 index 00000000..9fbb503f --- /dev/null +++ b/db/migrate/20140212175251_add_use_difficulty_levels_to_conference.rb @@ -0,0 +1,5 @@ +class AddUseDifficultyLevelsToConference < ActiveRecord::Migration + def change + add_column :conferences, :use_difficulty_levels, :boolean, :default => false + end +end diff --git a/db/migrate/20140213122424_add_difficulty_level_id_to_events.rb b/db/migrate/20140213122424_add_difficulty_level_id_to_events.rb new file mode 100644 index 00000000..56bcecb6 --- /dev/null +++ b/db/migrate/20140213122424_add_difficulty_level_id_to_events.rb @@ -0,0 +1,5 @@ +class AddDifficultyLevelIdToEvents < ActiveRecord::Migration + def change + add_column :events, :difficulty_level_id, :integer + end +end