Add surveys; custom generated by admins
Available during registration or after conference Co-authored-by: Shyukri <shshyukriev@suse.com> Co-authored-by: Henne <hvogel@opensuse.org> Co-authored-by: Moises <mdeniz@suse.com>
This commit is contained in:
parent
4e742d170f
commit
9f3c0eff5d
43 changed files with 701 additions and 17 deletions
|
|
@ -104,6 +104,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)
|
||||
|
||||
can [:destroy], Openid
|
||||
|
||||
can [:new, :create], Track do |track|
|
||||
|
|
|
|||
|
|
@ -58,6 +58,16 @@ class Conference < ApplicationRecord
|
|||
through: :program,
|
||||
source: :events
|
||||
has_many :event_types, through: :program
|
||||
|
||||
has_many :surveys, as: :surveyable, dependent: :destroy do
|
||||
def for_registration
|
||||
where(target: targets[:during_registration])
|
||||
end
|
||||
|
||||
def after_conference
|
||||
where(target: targets[:after_conference])
|
||||
end
|
||||
end
|
||||
accepts_nested_attributes_for :venue
|
||||
accepts_nested_attributes_for :tickets, allow_destroy: true
|
||||
accepts_nested_attributes_for :sponsorship_levels, allow_destroy: true
|
||||
|
|
@ -1225,3 +1235,4 @@ class Conference < ApplicationRecord
|
|||
result
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/ClassLength
|
||||
|
|
|
|||
13
app/models/survey.rb
Normal file
13
app/models/survey.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
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
|
||||
|
||||
def active?
|
||||
now = Time.now.in_time_zone(surveyable.timezone)
|
||||
now >= start_date && now <= end_date
|
||||
end
|
||||
end
|
||||
42
app/models/survey_question.rb
Normal file
42
app/models/survey_question.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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' }.freeze
|
||||
|
||||
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)
|
||||
self[:possible_answers] = choice? ? value : nil
|
||||
end
|
||||
|
||||
def min_choices=(value)
|
||||
self[:min_choices] = choice? ? value : nil
|
||||
end
|
||||
|
||||
def max_choices=(value)
|
||||
self[: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
|
||||
7
app/models/survey_reply.rb
Normal file
7
app/models/survey_reply.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class SurveyReply < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :survey_question
|
||||
serialize :text
|
||||
|
||||
validates :survey_question_id, uniqueness: { scope: :user_id }
|
||||
end
|
||||
9
app/models/survey_submission.rb
Normal file
9
app/models/survey_submission.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class SurveySubmission < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :survey
|
||||
has_many :survey_replies, through: :user
|
||||
|
||||
validates :user_id, uniqueness: { scope: :survey_id }
|
||||
|
||||
accepts_nested_attributes_for :survey_replies
|
||||
end
|
||||
|
|
@ -74,6 +74,8 @@ class User < ApplicationRecord
|
|||
has_many :booth_requests
|
||||
has_many :booth_requests, dependent: :destroy
|
||||
has_many :booths, through: :booth_requests
|
||||
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