Merge branch 'adding_surveys' of https://github.com/mdeniz/osem into mdeniz-adding_surveys
This commit is contained in:
commit
1991f53f26
40 changed files with 694 additions and 33 deletions
|
|
@ -94,6 +94,9 @@ class Ability
|
|||
|
||||
# can manage the commercials of their own events
|
||||
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
|
||||
|
||||
# can view and reply a survey
|
||||
can [:show, :reply], Survey, surveyable_type: 'Conference', surveyable_id: user.registrations.pluck(:conference_id)
|
||||
end
|
||||
|
||||
# Abilities for signed in users with roles
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@ class Conference < ActiveRecord::Base
|
|||
has_many :campaigns, dependent: :destroy
|
||||
has_many :commercials, as: :commercialable, dependent: :destroy
|
||||
has_many :subscriptions, dependent: :destroy
|
||||
has_many :surveys, as: :surveyable, dependent: :destroy do
|
||||
def for_registration
|
||||
where(target: targets[:during_registration])
|
||||
end
|
||||
end
|
||||
|
||||
accepts_nested_attributes_for :venue
|
||||
accepts_nested_attributes_for :tickets, allow_destroy: true
|
||||
|
|
|
|||
8
app/models/survey.rb
Normal file
8
app/models/survey.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class Survey < ActiveRecord::Base
|
||||
belongs_to :surveyable, polymorphic: true
|
||||
has_many :survey_questions
|
||||
has_many :survey_submissions
|
||||
|
||||
enum target: [:after_conference, :during_registration]
|
||||
validates :title, presence: true
|
||||
end
|
||||
43
app/models/survey_question.rb
Normal file
43
app/models/survey_question.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
class SurveyQuestion < ActiveRecord::Base
|
||||
belongs_to :survey
|
||||
|
||||
# Order of this list should not be changed without proper action!
|
||||
enum kind: [:boolean, :choice, :string, :text, :datetime, :numeric]
|
||||
|
||||
ICONS = { boolean: 'dot-circle-o', choice: 'check-square-o', string: 'edit', text: 'align-left', datetime: 'clock-o', numeric: 'slack' }
|
||||
|
||||
validates :title, presence: true
|
||||
validates :possible_answers, :max_choices, :min_choices, presence: true, if: "choice?"
|
||||
validates :min_choices, numericality: { greater_than_or_equal_to: 1 }, allow_blank: true
|
||||
validates :max_choices, numericality: { greater_than_or_equal_to: 1 }, allow_blank: true
|
||||
|
||||
validate :max_choices_greater_than_min
|
||||
has_many :survey_replies
|
||||
|
||||
|
||||
def single_choice?
|
||||
choice? && max_choices == 1 && min_choices == 1
|
||||
end
|
||||
|
||||
def multiple_choice?
|
||||
choice? && max_choices > 1
|
||||
end
|
||||
|
||||
def possible_answers=(value)
|
||||
write_attribute(:possible_answers, choice? ? value : nil)
|
||||
end
|
||||
|
||||
def min_choices=(value)
|
||||
write_attribute(:min_choices, choice? ? value : nil)
|
||||
end
|
||||
|
||||
def max_choices=(value)
|
||||
write_attribute(:max_choices, choice? ? value : nil)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def max_choices_greater_than_min
|
||||
errors.add(:max_choices, "Max choices should not be less than min choices") if choice? && max_choices.to_i < min_choices.to_i
|
||||
end
|
||||
end
|
||||
5
app/models/survey_reply.rb
Normal file
5
app/models/survey_reply.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class SurveyReply < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :survey_question
|
||||
serialize :text
|
||||
end
|
||||
7
app/models/survey_submission.rb
Normal file
7
app/models/survey_submission.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class SurveySubmission < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :survey
|
||||
has_many :survey_replies, through: :user
|
||||
|
||||
accepts_nested_attributes_for :survey_replies
|
||||
end
|
||||
|
|
@ -42,6 +42,8 @@ class User < ActiveRecord::Base
|
|||
has_many :votes, dependent: :destroy
|
||||
has_many :voted_events, through: :votes, source: :events
|
||||
has_many :subscriptions, dependent: :destroy
|
||||
has_many :survey_replies
|
||||
has_many :survey_submissions
|
||||
accepts_nested_attributes_for :roles
|
||||
|
||||
scope :admin, -> { where(is_admin: true) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue