Refactoring of proposal workflow. Fixes #215

This commit is contained in:
Stella Rouzi 2015-04-16 18:34:41 +03:00
parent 333c5e39bf
commit e6bb168c5e
35 changed files with 491 additions and 192 deletions

View file

@ -52,6 +52,10 @@ class Ability
can [:show, :create], Registration do |registration|
registration.new_record?
end
can [:show, :create], Event do |event|
event.new_record?
end
end
# Abilities for signed in users

View file

@ -3,7 +3,8 @@ class Commercial < ActiveRecord::Base
attr_accessible :commercial_id, :commercial_type
validates :commercial_id, :commercial_type, presence: true
validates :commercial_id, presence: true
validates :commercial_type, presence: true
validates :commercial_type, inclusion: { in: CONFIG['commercial_types'].values }, allow_blank: true
validates :commercial_type, inclusion: { in: CONFIG['commercial_types'].values }
end

View file

@ -911,10 +911,10 @@ class Conference < ActiveRecord::Base
# Creates default EventTypes for this Conference. Used as before_create.
#
def create_event_types
event_types << EventType.create(title: 'Talk', length: 30, color: '#FF0000',
event_types << EventType.create(title: 'Talk', length: 30, color: '#FF0000', description: 'Presentation in lecture format',
minimum_abstract_length: 0,
maximum_abstract_length: 500)
event_types << EventType.create(title: 'Workshop', length: 60, color: '#0000FF',
event_types << EventType.create(title: 'Workshop', length: 60, color: '#0000FF', description: 'Interactive hands-on practice',
minimum_abstract_length: 0,
maximum_abstract_length: 500)
true

View file

@ -26,17 +26,18 @@ class Event < ActiveRecord::Base
accepts_nested_attributes_for :event_users, allow_destroy: true
accepts_nested_attributes_for :users
before_create :generate_guid
validate :abstract_limit
validate :before_end_of_conference, on: :create
validate :name_and_biography_exists
validates :title, presence: true
validates :abstract, presence: true
validates :event_type, presence: true
validates :conference, presence: true
scope :confirmed, -> { where(state: 'confirmed') }
scope :highlighted, -> { where(is_highlight: true) }
state_machine initial: :new do
state :new
@ -212,6 +213,32 @@ class Event < ActiveRecord::Base
result.to_a.to_sentence
end
##
#
# Returns +Hash+
def progress_status
{
registered: self.conference.user_registered?(self.submitter),
commercials: self.commercials.any?,
biography: !self.submitter.biography.blank?,
subtitle: !self.subtitle.blank?,
difficulty_level: !self.difficulty_level.blank?,
title: true,
abstract: true
}.with_indifferent_access
end
##
# Returns the progress of the proposal's set up
#
# ====Returns
# * +Fixnum+ -> Progress in Percent
def calculate_progress
result = self.progress_status
true_items = result.select { |_key, value| value }.length
(true_items / result.length.to_f * 100).round(0).to_s
end
private
def abstract_limit
@ -225,11 +252,6 @@ class Event < ActiveRecord::Base
errors.add(:abstract, "cannot have more than #{max_words} words") if len > max_words
end
def name_and_biography_exists
errors.add(:biography, "cant' be blank") if submitter.biography.blank?
errors.add(:name, " can't be blank") if submitter.name.blank?
end
# TODO: create a module to be mixed into model to perform same operation
# venue.rb has same functionality which can be shared
# TODO: rename guid to UUID as guid is specifically Microsoft term

View file

@ -1,6 +1,6 @@
class EventType < ActiveRecord::Base
attr_accessible :title, :length, :minimum_abstract_length, :maximum_abstract_length, :color,
:conference_id
:conference_id, :description
belongs_to :conference
has_many :events, dependent: :restrict_with_error