mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Add more options for surveys
* Survey period constraints * Add abilities * Enforce required questions * Update survey_submssion updated_at * Do a full match of possible answer and user reply
This commit is contained in:
parent
c278e547ce
commit
683f62a27c
36 changed files with 219 additions and 74 deletions
|
|
@ -93,6 +93,8 @@ linters:
|
||||||
- "app/views/admin/sponsors/index.html.haml"
|
- "app/views/admin/sponsors/index.html.haml"
|
||||||
- "app/views/admin/sponsorship_levels/_form.html.haml"
|
- "app/views/admin/sponsorship_levels/_form.html.haml"
|
||||||
- "app/views/admin/sponsorship_levels/index.html.haml"
|
- "app/views/admin/sponsorship_levels/index.html.haml"
|
||||||
|
- "app/views/admin/surveys/index.html.haml"
|
||||||
|
- "app/views/admin/surveys/show.html.haml"
|
||||||
- "app/views/admin/targets/_form.html.haml"
|
- "app/views/admin/targets/_form.html.haml"
|
||||||
- "app/views/admin/targets/index.html.haml"
|
- "app/views/admin/targets/index.html.haml"
|
||||||
- "app/views/admin/tickets/_form.html.haml"
|
- "app/views/admin/tickets/_form.html.haml"
|
||||||
|
|
@ -161,6 +163,9 @@ linters:
|
||||||
- "app/views/schedules/events.html.haml"
|
- "app/views/schedules/events.html.haml"
|
||||||
- "app/views/schedules/show.html.haml"
|
- "app/views/schedules/show.html.haml"
|
||||||
- "app/views/schedules/show.xml.haml"
|
- "app/views/schedules/show.xml.haml"
|
||||||
|
- "app/views/surveys/*"
|
||||||
|
- "app/views/admin/surveys/*"
|
||||||
|
- "app/views/admin/survey_questions/*.html.haml"
|
||||||
- "app/views/shared/_changelog_actions.haml"
|
- "app/views/shared/_changelog_actions.haml"
|
||||||
- "app/views/shared/_dynamic_association.html.haml"
|
- "app/views/shared/_dynamic_association.html.haml"
|
||||||
- "app/views/shared/_media_item.html.haml"
|
- "app/views/shared/_media_item.html.haml"
|
||||||
|
|
@ -210,6 +215,8 @@ linters:
|
||||||
- "app/views/admin/splashpages/_form.html.haml"
|
- "app/views/admin/splashpages/_form.html.haml"
|
||||||
- "app/views/admin/sponsors/_form.html.haml"
|
- "app/views/admin/sponsors/_form.html.haml"
|
||||||
- "app/views/admin/sponsorship_levels/_form.html.haml"
|
- "app/views/admin/sponsorship_levels/_form.html.haml"
|
||||||
|
- "app/views/admin/survey_questions/*"
|
||||||
|
- "app/views/admin/surveys/*"
|
||||||
- "app/views/admin/tickets/_form.html.haml"
|
- "app/views/admin/tickets/_form.html.haml"
|
||||||
- "app/views/admin/tracks/_form.html.haml"
|
- "app/views/admin/tracks/_form.html.haml"
|
||||||
- "app/views/admin/users/_form.html.haml"
|
- "app/views/admin/users/_form.html.haml"
|
||||||
|
|
@ -447,3 +454,5 @@ linters:
|
||||||
- "app/views/conferences/_gallery.html.haml"
|
- "app/views/conferences/_gallery.html.haml"
|
||||||
- "app/views/layouts/_navigation.html.haml"
|
- "app/views/layouts/_navigation.html.haml"
|
||||||
- "app/views/schedules/events.html.haml"
|
- "app/views/schedules/events.html.haml"
|
||||||
|
- "app/views/admin/survey_questions/*"
|
||||||
|
- "app/views/admin/surveys/*"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Admin
|
module Admin
|
||||||
class SurveyQuestionsController < Admin::BaseController
|
class SurveyQuestionsController < Admin::BaseController
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Admin
|
module Admin
|
||||||
class SurveysController < Admin::BaseController
|
class SurveysController < Admin::BaseController
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
|
|
@ -17,7 +19,7 @@ module Admin
|
||||||
if @survey.save
|
if @survey.save
|
||||||
redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), notice: 'Successfully created survey'
|
redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), notice: 'Successfully created survey'
|
||||||
else
|
else
|
||||||
redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), error: 'Could not create survey.' + @survey.errors.full_messates.to_sentence
|
redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), error: 'Could not create survey.' + @survey.errors.full_messages.to_sentence
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class SurveysController < ApplicationController
|
class SurveysController < ApplicationController
|
||||||
load_resource :conference, find_by: :short_title
|
load_resource :conference, find_by: :short_title
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource except: :reply
|
||||||
|
load_resource only: :reply
|
||||||
|
skip_authorization_check only: :reply
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@surveys = @conference.surveys.select(&:active?)
|
@surveys = @conference.surveys.select(&:active?)
|
||||||
|
|
@ -11,6 +15,11 @@ class SurveysController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def reply
|
def reply
|
||||||
|
unless can? :reply, @survey
|
||||||
|
redirect_to conference_survey_path(@conference, @survey), alert: 'This survey is currently closed'
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
survey_submission = params[:survey_submission]
|
survey_submission = params[:survey_submission]
|
||||||
|
|
||||||
@survey.survey_questions.each do |survey_question|
|
@survey.survey_questions.each do |survey_question|
|
||||||
|
|
@ -22,7 +31,13 @@ class SurveysController < ApplicationController
|
||||||
else
|
else
|
||||||
survey_question.survey_replies.create!(text: reply_text, user: current_user)
|
survey_question.survey_replies.create!(text: reply_text, user: current_user)
|
||||||
end
|
end
|
||||||
@survey.survey_submissions.create!(user: current_user) unless @survey.survey_submissions.find_by(user: current_user)
|
|
||||||
|
user_survey_submission = @survey.survey_submissions.find_by(user: current_user)
|
||||||
|
if user_survey_submission
|
||||||
|
user_survey_submission.update_attributes(updated_at: Time.current)
|
||||||
|
else
|
||||||
|
@survey.survey_submissions.create!(user: current_user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@ class Ability
|
||||||
can [:show, :events], Schedule do |schedule|
|
can [:show, :events], Schedule do |schedule|
|
||||||
schedule.program.schedule_public
|
schedule.program.schedule_public
|
||||||
end
|
end
|
||||||
|
|
||||||
|
can [:index, :show], Survey, surveyable_type: 'Conference'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -104,8 +106,18 @@ class Ability
|
||||||
# can manage the commercials of their own events
|
# can manage the commercials of their own events
|
||||||
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
|
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
|
||||||
|
|
||||||
# can view and reply a survey
|
# can view and reply to a survey
|
||||||
can [:show, :reply], Survey, surveyable_type: 'Conference', surveyable_id: user.registrations.pluck(:conference_id)
|
can [:index, :show, :reply], Survey, surveyable_type: 'Conference'
|
||||||
|
can [:index, :show, :reply], Survey, surveyable_type: 'Registration', surveyable_id: user.registrations.pluck(:conference_id)
|
||||||
|
|
||||||
|
# TODO: this needs to check for more, eg.
|
||||||
|
# if survey target is after_conference, check whether or not the conference is over
|
||||||
|
# if not, do not allow replies.
|
||||||
|
|
||||||
|
# do not allow replies before the start_date or after the end_date of survey
|
||||||
|
cannot :reply, Survey do |survey|
|
||||||
|
survey.start_date > Time.current || survey.end_date < Time.current
|
||||||
|
end
|
||||||
|
|
||||||
can [:destroy], Openid
|
can [:destroy], Openid
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1235,4 +1235,3 @@ class Conference < ApplicationRecord
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/ClassLength
|
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,18 @@ class Event < ApplicationRecord
|
||||||
event_schedules.find_by(schedule_id: selected_schedule_id).try(:start_time)
|
event_schedules.find_by(schedule_id: selected_schedule_id).try(:start_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns true or false, if the event is already over or not
|
||||||
|
#
|
||||||
|
# ====Returns
|
||||||
|
# * +true+ -> If the event is over
|
||||||
|
# * +false+ -> If the event is not over yet
|
||||||
|
def ended?
|
||||||
|
event_schedule = event_schedules.find_by(schedule_id: selected_schedule_id)
|
||||||
|
return false unless event_schedule
|
||||||
|
event_schedule.end_time < Time.current
|
||||||
|
end
|
||||||
|
|
||||||
def conference
|
def conference
|
||||||
program.conference
|
program.conference
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Survey < ActiveRecord::Base
|
class Survey < ActiveRecord::Base
|
||||||
belongs_to :surveyable, polymorphic: true
|
belongs_to :surveyable, polymorphic: true
|
||||||
has_many :survey_questions
|
has_many :survey_questions, dependent: :destroy
|
||||||
has_many :survey_submissions
|
has_many :survey_submissions, dependent: :destroy
|
||||||
|
|
||||||
enum target: [:after_conference, :during_registration]
|
enum target: [:after_conference, :during_registration]
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
|
|
||||||
def active?
|
def active?
|
||||||
|
return false unless start_date && end_date
|
||||||
now = Time.now.in_time_zone(surveyable.timezone)
|
now = Time.now.in_time_zone(surveyable.timezone)
|
||||||
now >= start_date && now <= end_date
|
now >= start_date && now <= end_date
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class SurveyQuestion < ActiveRecord::Base
|
class SurveyQuestion < ActiveRecord::Base
|
||||||
belongs_to :survey
|
belongs_to :survey
|
||||||
has_many :survey_replies
|
has_many :survey_replies, dependent: :destroy
|
||||||
|
|
||||||
# Order of this list should not be changed without proper action!
|
# Order of this list should not be changed without proper action!
|
||||||
enum kind: [:boolean, :choice, :string, :text, :datetime, :numeric]
|
enum kind: [:boolean, :choice, :string, :text, :datetime, :numeric]
|
||||||
|
|
@ -23,15 +25,15 @@ class SurveyQuestion < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def possible_answers=(value)
|
def possible_answers=(value)
|
||||||
self[:possible_answers] = choice? ? value : nil
|
self[:possible_answers] = value if choice?
|
||||||
end
|
end
|
||||||
|
|
||||||
def min_choices=(value)
|
def min_choices=(value)
|
||||||
self[:min_choices] = choice? ? value : nil
|
self[:min_choices] = value if choice?
|
||||||
end
|
end
|
||||||
|
|
||||||
def max_choices=(value)
|
def max_choices=(value)
|
||||||
self[:max_choices] = choice? ? value : nil
|
self[:max_choices] = value if choice?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class SurveyReply < ActiveRecord::Base
|
class SurveyReply < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :survey_question
|
belongs_to :survey_question
|
||||||
serialize :text
|
serialize :text
|
||||||
|
|
||||||
|
validates :user_id, :survey_question_id, presence: true
|
||||||
validates :survey_question_id, uniqueness: { scope: :user_id }
|
validates :survey_question_id, uniqueness: { scope: :user_id }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class SurveySubmission < ActiveRecord::Base
|
class SurveySubmission < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :survey
|
belongs_to :survey
|
||||||
|
|
|
||||||
|
|
@ -61,3 +61,8 @@
|
||||||
= link_to "#{event.comments_count}",
|
= link_to "#{event.comments_count}",
|
||||||
admin_conference_program_event_path(conference_id, event),
|
admin_conference_program_event_path(conference_id, event),
|
||||||
anchor: 'comments-div'
|
anchor: 'comments-div'
|
||||||
|
%td.text-center
|
||||||
|
= link_to new_admin_conference_survey_path(@conference.short_title,
|
||||||
|
survey: { surveyable_type: 'Event', surveyable_id: event.id }),
|
||||||
|
class: 'btn btn-success' do
|
||||||
|
.fa.fa-plus
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= f.input :title
|
= f.input :title
|
||||||
= f.input :mandatory
|
= f.input :mandatory
|
||||||
%div.survey-possible-answers{ class: @survey_question.choice? ? '' : 'hidden'}
|
.survey-possible-answers{ class: @survey_question.choice? ? '' : 'hidden' }
|
||||||
= f.input :possible_answers, hint: 'Comma separated', input_html: { rows: 3 }
|
= f.input :possible_answers, hint: 'Comma separated', input_html: { rows: 3 }
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
|
|
@ -38,16 +38,16 @@
|
||||||
%label
|
%label
|
||||||
Preview:
|
Preview:
|
||||||
.panel.panel-default
|
.panel.panel-default
|
||||||
.panel-body{id: 'survey_question_preview'}
|
.panel-body{ id: 'survey_question_preview' }
|
||||||
%p{id: 'title', style: 'word-wrap: break-word'}
|
%p{ id: 'title', style: 'word-wrap: break-word' }
|
||||||
= @survey_question.title.blank? ? 'What is your answer?' : @survey_question.title
|
= @survey_question.title.blank? ? 'What is your answer?' : @survey_question.title
|
||||||
|
|
||||||
%div.kinds.boolean{ class: @survey_question.boolean? ? '' : 'hidden'}
|
.kinds.boolean{ class: @survey_question.boolean? ? '' : 'hidden' }
|
||||||
%input{type: 'radio', name: 'radio'} Yes
|
%input{ type: 'radio', name: 'radio' } Yes
|
||||||
%br
|
%br
|
||||||
%input{type: 'radio', name: 'radio'} No
|
%input{ type: 'radio', name: 'radio' } No
|
||||||
|
|
||||||
%div.kinds.choice{ id: '', class: @survey_question.choice? ? '' : 'hidden'}
|
.kinds.choice{ class: @survey_question.choice? ? '' : 'hidden' }
|
||||||
- if @survey_question.possible_answers.blank?
|
- if @survey_question.possible_answers.blank?
|
||||||
- if @survey_question.single_choice?
|
- if @survey_question.single_choice?
|
||||||
%input{ type: 'radio', name: 'radio' } Choice 1
|
%input{ type: 'radio', name: 'radio' } Choice 1
|
||||||
|
|
@ -72,21 +72,21 @@
|
||||||
= option
|
= option
|
||||||
%br
|
%br
|
||||||
|
|
||||||
%div.kinds.string{ class: @survey_question.string? ? '' : 'hidden'}
|
.kinds.string{ class: @survey_question.string? ? '' : 'hidden' }
|
||||||
%input.form-control
|
%input.form-control
|
||||||
|
|
||||||
%div.kinds.text{ class: @survey_question.text? ? '' : 'hidden'}
|
.kinds.text{ class: @survey_question.text? ? '' : 'hidden' }
|
||||||
%textarea.form-control{ rows: 4 }
|
%textarea.form-control{ rows: 4 }
|
||||||
|
|
||||||
|
|
||||||
%div.kinds.datetime{ class: @survey_question.datetime? ? '' : 'hidden'}
|
.kinds.datetime{ class: @survey_question.datetime? ? '' : 'hidden' }
|
||||||
.form-group{class: 'datetimepicker'}
|
.form-group{ class: 'datetimepicker' }
|
||||||
.input-group
|
.input-group
|
||||||
.input-group-addon
|
.input-group-addon
|
||||||
%span.fa.fa-calendar
|
%span.fa.fa-calendar
|
||||||
%input.form-control{readonly: 'readonly'}
|
%input.form-control{ readonly: 'readonly' }
|
||||||
|
.kinds.numeric{ class: @survey_question.numeric? ? '' : 'hidden' }
|
||||||
|
|
||||||
%div.kinds.numeric{ class: @survey_question.numeric? ? '' : 'hidden'}
|
|
||||||
%input.form-control{ type: 'number' }
|
%input.form-control{ type: 'number' }
|
||||||
|
|
||||||
= f.submit 'Save', class: 'btn btn-primary'
|
= f.submit 'Save', class: 'btn btn-primary'
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,11 @@
|
||||||
.panel.panel-default
|
.panel.panel-default
|
||||||
.panel-heading
|
.panel-heading
|
||||||
%span.badge
|
= render partial: 'admin/surveys/survey_question_title', locals: { survey_question: survey_question, question_index: question_index }
|
||||||
= question_index
|
|
||||||
= survey_question.title
|
|
||||||
|
|
||||||
- if survey_question.multiple_choice?
|
|
||||||
( Select
|
|
||||||
- if survey_question.min_choices != survey_question.max_choices
|
|
||||||
a minimum of
|
|
||||||
= survey_question.min_choices
|
|
||||||
- if survey_question.min_choices != survey_question.max_choices
|
|
||||||
and a maximum of
|
|
||||||
= survey_question.max_choices
|
|
||||||
choices )
|
|
||||||
- if survey_question.mandatory
|
|
||||||
%span.fa.fa-asterisk.text-danger
|
|
||||||
- if can? :edit, @survey
|
|
||||||
%p.pull-right
|
|
||||||
= link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do
|
|
||||||
%span.fa.fa-edit
|
|
||||||
= link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do
|
|
||||||
%span.fa.fa-times
|
|
||||||
.panel-body
|
.panel-body
|
||||||
- if survey_question.boolean?
|
- if survey_question.boolean?
|
||||||
%input{ type: 'hidden', name: "survey_submission[#{survey_question.id}][]" }
|
%input{ type: 'hidden', name: "survey_submission[#{survey_question.id}][]" }
|
||||||
%label
|
%label
|
||||||
%input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: 'Yes', checked: survey_reply.text == 'Yes' }
|
%input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: 'Yes', checked: survey_reply.text == 'Yes',required: survey_question.mandatory }
|
||||||
Yes
|
Yes
|
||||||
%br
|
%br
|
||||||
%label
|
%label
|
||||||
|
|
@ -39,24 +19,24 @@
|
||||||
- possible_answers.each.with_index(1) do |answer, answer_index|
|
- possible_answers.each.with_index(1) do |answer, answer_index|
|
||||||
- if survey_question.single_choice?
|
- if survey_question.single_choice?
|
||||||
%label
|
%label
|
||||||
%input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: answer, checked: (survey_reply.text.include? answer if survey_reply.text) }
|
%input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: answer, checked: (survey_reply.text == answer if survey_reply.text), required: survey_question.mandatory }
|
||||||
= answer
|
= answer
|
||||||
%br
|
%br
|
||||||
- else
|
- else
|
||||||
%label
|
%label
|
||||||
= check_box_tag "survey_submission[#{survey_question.id}][]", answer, (survey_reply.text.include? answer if survey_reply.text), id: dom_id(survey_reply)
|
= check_box_tag "survey_submission[#{survey_question.id}][]", answer, (survey_reply.text.include? answer if survey_reply.text), id: dom_id(survey_reply), required: survey_question.mandatory
|
||||||
= answer
|
= answer
|
||||||
|
|
||||||
%br
|
%br
|
||||||
- elsif survey_question.string?
|
- elsif survey_question.string?
|
||||||
%input.form-control{ name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }
|
%input.form-control{ name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory }
|
||||||
- elsif survey_question.text?
|
- elsif survey_question.text?
|
||||||
= text_area_tag "survey_submission[#{survey_question.id}][]", survey_reply.text, rows: 4, class: 'form-control'
|
= text_area_tag "survey_submission[#{survey_question.id}][]", survey_reply.text, rows: 4, class: 'form-control', required: survey_question.mandatory
|
||||||
- elsif survey_question.datetime?
|
- elsif survey_question.datetime?
|
||||||
.form-group{ class: 'datetimepicker' }
|
.form-group{ class: 'datetimepicker' }
|
||||||
.input-group
|
.input-group
|
||||||
.input-group-addon
|
.input-group-addon
|
||||||
%span.fa.fa-calendar
|
%span.fa.fa-calendar
|
||||||
%input.form-control{ readonly: 'readonly', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }
|
%input.form-control{ readonly: 'readonly', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory }
|
||||||
- elsif survey_question.numeric?
|
- elsif survey_question.numeric?
|
||||||
%input.form-control{ type: 'number', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }
|
%input.form-control{ type: 'number', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory }
|
||||||
|
|
|
||||||
0
app/views/admin/surveys/_survey_question_body.html.haml
Normal file
0
app/views/admin/surveys/_survey_question_body.html.haml
Normal file
22
app/views/admin/surveys/_survey_question_title.html.haml
Normal file
22
app/views/admin/surveys/_survey_question_title.html.haml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
%span.badge
|
||||||
|
= question_index
|
||||||
|
= survey_question.title
|
||||||
|
|
||||||
|
- if survey_question.multiple_choice?
|
||||||
|
( Select
|
||||||
|
- if survey_question.min_choices != survey_question.max_choices
|
||||||
|
a minimum of
|
||||||
|
= survey_question.min_choices
|
||||||
|
- if survey_question.min_choices != survey_question.max_choices
|
||||||
|
and a maximum of
|
||||||
|
= survey_question.max_choices
|
||||||
|
choices )
|
||||||
|
- if survey_question.mandatory
|
||||||
|
%span.fa.fa-asterisk.text-danger
|
||||||
|
- if can? :edit, @survey
|
||||||
|
%p.pull-right
|
||||||
|
= "(#{survey_question.survey_replies.count} replies)"
|
||||||
|
= link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do
|
||||||
|
%span.fa.fa-edit
|
||||||
|
= link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do
|
||||||
|
%span.fa.fa-times
|
||||||
16
app/views/admin/surveys/_survey_replies.html.haml
Normal file
16
app/views/admin/surveys/_survey_replies.html.haml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
- @survey.survey_questions.each.with_index(1) do |survey_question, question_index|
|
||||||
|
.panel.panel-default
|
||||||
|
.panel-heading{ type: 'button', 'data-toggle': 'collapse', 'data-target': "#question-#{survey_question.id}", 'aria-expanded': 'true', 'aria-controls': 'collapse' }
|
||||||
|
= render partial: 'survey_question_title', locals: { survey_question: survey_question, question_index: question_index }
|
||||||
|
|
||||||
|
.panel-body.collapse{ id: "question-#{survey_question.id}" }
|
||||||
|
- if survey_question.survey_replies.any?
|
||||||
|
%table.table
|
||||||
|
%thead
|
||||||
|
%th User Email
|
||||||
|
%th Reply
|
||||||
|
%tbody
|
||||||
|
- survey_question.survey_replies.reload.each do |reply|
|
||||||
|
%tr
|
||||||
|
%td= reply.user.email
|
||||||
|
%td= reply.text
|
||||||
13
app/views/admin/surveys/_survey_stats.html.haml
Normal file
13
app/views/admin/surveys/_survey_stats.html.haml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
= javascript_include_tag "//www.google.com/jsapi", "chartkick"
|
||||||
|
= javascript_include_tag 'chartkick'
|
||||||
|
|
||||||
|
= bar_chart @survey.survey_questions.map{ |q| [q.title, q.survey_replies.count] }
|
||||||
|
|
||||||
|
- @survey.survey_questions.each.with_index(1) do |survey_question, question_index|
|
||||||
|
.panel.panel-default
|
||||||
|
.panel-heading
|
||||||
|
= render partial: 'survey_question_title', locals: { survey_question: survey_question, question_index: question_index }
|
||||||
|
.panel-body
|
||||||
|
- question_replies = survey_question.survey_replies
|
||||||
|
- if question_replies.any?
|
||||||
|
= pie_chart question_replies.group(:text).count, library: { legend: 'bottom', plotOptions: { pie: { dataLabels: { enabled: false }, showInLegend: true } } }
|
||||||
|
|
@ -14,6 +14,8 @@
|
||||||
%table.table.table-hover.datatable#surveys
|
%table.table.table-hover.datatable#surveys
|
||||||
%thead
|
%thead
|
||||||
%th Title
|
%th Title
|
||||||
|
%th # of questions
|
||||||
|
%th # of submissions
|
||||||
%th When
|
%th When
|
||||||
%th Start Date
|
%th Start Date
|
||||||
%th End Date
|
%th End Date
|
||||||
|
|
@ -23,6 +25,10 @@
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
= link_to survey.title, admin_conference_survey_path(@conference.short_title, survey)
|
= link_to survey.title, admin_conference_survey_path(@conference.short_title, survey)
|
||||||
|
%td
|
||||||
|
= survey.survey_questions.length
|
||||||
|
%td
|
||||||
|
= survey.survey_submissions.length
|
||||||
%td
|
%td
|
||||||
= survey.target
|
= survey.target
|
||||||
%td
|
%td
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,24 @@
|
||||||
= @survey.end_date
|
= @survey.end_date
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= semantic_form_for 'survey_submission', url: '#' do |f|
|
.tabbable
|
||||||
- @survey.survey_questions.each.with_index(1) do |survey_question, question_index|
|
%ul.nav.nav-tabs
|
||||||
.row
|
%li.active
|
||||||
.col-md-12
|
= link_to 'Questions' , '#questions-content', 'data-toggle' => 'tab'
|
||||||
- survey_reply = survey_question.survey_replies.new(survey_question_id: survey_question.id, user_id: current_user.id)
|
%li
|
||||||
= render partial: 'survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply }
|
= link_to 'Replies' , '#replies-content', 'data-toggle' => 'tab'
|
||||||
= link_to 'Add Question', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right'
|
%li
|
||||||
|
= link_to 'Stats' , '#stats-content', 'data-toggle' => 'tab'
|
||||||
|
.tab-content
|
||||||
|
.tab-pane.active#questions-content
|
||||||
|
= semantic_form_for 'survey_submission', url: '#' do |f|
|
||||||
|
- @survey.survey_questions.each.with_index(1) do |survey_question, question_index|
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
- survey_reply = survey_question.survey_replies.new(survey_question_id: survey_question.id, user_id: current_user.id)
|
||||||
|
= render partial: 'survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply }
|
||||||
|
= link_to 'Add Question', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right'
|
||||||
|
.tab-pane#replies-content
|
||||||
|
= render partial: 'survey_replies'
|
||||||
|
.tab-pane#stats-content
|
||||||
|
= render partial: 'survey_stats'
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,19 @@
|
||||||
= @survey.start_date
|
= @survey.start_date
|
||||||
to
|
to
|
||||||
= @survey.end_date
|
= @survey.end_date
|
||||||
|
- unless @survey.active?
|
||||||
|
%label
|
||||||
|
%i.fa.fa-exclamation-circle
|
||||||
|
This survey does not accept replies at this monent.
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= semantic_form_for @survey_submission, url: reply_conference_survey_path(@conference.short_title, @survey) do |f|
|
= semantic_form_for @survey_submission, url: reply_conference_survey_path(@conference.short_title, @survey) do |f|
|
||||||
- @survey.survey_questions.each.with_index(1) do |survey_question, question_index|
|
- @survey.survey_questions.each.with_index(1) do |survey_question, question_index|
|
||||||
.row
|
.row
|
||||||
.col-md-10.col-md-offset-1
|
.col-md-10.col-md-offset-1
|
||||||
- survey_reply = survey_question.survey_replies.find_by(user: current_user) || SurveyReply.new(survey_question_id: survey_question.id, user_id: current_user.id)
|
- survey_reply = survey_question.survey_replies.find_by(user: current_user) || SurveyReply.new(survey_question_id: survey_question.id, user: current_user)
|
||||||
= render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply }
|
= render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply }
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-10.col-md-offset-1
|
.col-md-10.col-md-offset-1
|
||||||
= f.submit 'Submit', class: 'btn btn-primary pull-right'
|
= f.submit 'Submit', class: 'btn btn-primary pull-right', disabled: !(can? :reply, @survey)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CreateSurveys < ActiveRecord::Migration
|
class CreateSurveys < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :surveys do |t|
|
create_table :surveys do |t|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CreateSurveyQuestions < ActiveRecord::Migration
|
class CreateSurveyQuestions < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :survey_questions do |t|
|
create_table :survey_questions do |t|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class AddTargetToSurveys < ActiveRecord::Migration
|
class AddTargetToSurveys < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
add_column :surveys, :target, :integer, default: 0
|
add_column :surveys, :target, :integer, default: 0
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CreateSurveyReplies < ActiveRecord::Migration
|
class CreateSurveyReplies < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :survey_replies do |t|
|
create_table :survey_replies do |t|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CreateSurveySubmissions < ActiveRecord::Migration
|
class CreateSurveySubmissions < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :survey_submissions do |t|
|
create_table :survey_submissions do |t|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ namespace :data do
|
||||||
task surveys: :environment do
|
task surveys: :environment do
|
||||||
conference = create(:full_conference, start_date: Date.current, end_date: Date.current + 1.day)
|
conference = create(:full_conference, start_date: Date.current, end_date: Date.current + 1.day)
|
||||||
survey_after_conference_active = create(:survey, surveyable: conference, target: :after_conference, title: 'Survey about the conference', start_date: conference.start_date - 1.day, end_date: conference.end_date + 5.days, description: 'Survey about the conference. You can already see it.')
|
survey_after_conference_active = create(:survey, surveyable: conference, target: :after_conference, title: 'Survey about the conference', start_date: conference.start_date - 1.day, end_date: conference.end_date + 5.days, description: 'Survey about the conference. You can already see it.')
|
||||||
survey_after_conference_inactive = create(:survey, surveyable: conference, target: :after_conference, title: 'Survey about the conference', start_date: conference.start_date + 1.day, end_date: conference.end_date + 5.days, description: 'Survey abou the conference. Not available yet!')
|
# survey_after_conference_inactive = create(:survey, surveyable: conference, target: :after_conference, title: 'Survey about the conference', start_date: conference.start_date + 1.day, end_date: conference.end_date + 5.days, description: 'Survey abou the conference. Not available yet!')
|
||||||
survey_on_registration = create(:survey, surveyable: conference, target: :during_registration, title: 'Survey during registation', start_date: conference.registration_period.start_date, end_date: conference.registration_period.end_date, description: 'Survey during registration.')
|
# survey_on_registration = create(:survey, surveyable: conference, target: :during_registration, title: 'Survey during registation', start_date: conference.registration_period.start_date, end_date: conference.registration_period.end_date, description: 'Survey during registration.')
|
||||||
|
|
||||||
create(:boolean_non_mandatory, survey: survey_after_conference_active)
|
create(:boolean_non_mandatory, survey: survey_after_conference_active)
|
||||||
create(:boolean_mandatory, survey: survey_after_conference_active)
|
create(:boolean_mandatory, survey: survey_after_conference_active)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe SurveysController do
|
describe SurveysController do
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :survey_question do
|
factory :survey_question do
|
||||||
survey
|
survey
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :survey_reply do
|
factory :survey_reply do
|
||||||
user
|
user
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :survey_submission do
|
factory :survey_submission do
|
||||||
user
|
user
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :survey do
|
factory :survey do
|
||||||
title 'This is my survey'
|
title 'This is my survey'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe SurveyQuestion do
|
describe SurveyQuestion do
|
||||||
|
|
@ -7,7 +9,7 @@ describe SurveyQuestion do
|
||||||
|
|
||||||
let(:single_choice_question) { create(:choice_mandatory_1_reply) }
|
let(:single_choice_question) { create(:choice_mandatory_1_reply) }
|
||||||
let(:multiple_choice_question) { create(:choice_mandatory_2_replies) }
|
let(:multiple_choice_question) { create(:choice_mandatory_2_replies) }
|
||||||
let(:boolean_question) { create(:boolean_question, min_choices: 3)}
|
let(:boolean_question) { create(:boolean_question, min_choices: 3) }
|
||||||
|
|
||||||
describe 'association' do
|
describe 'association' do
|
||||||
it { is_expected.to belong_to(:survey) }
|
it { is_expected.to belong_to(:survey) }
|
||||||
|
|
@ -88,7 +90,7 @@ describe SurveyQuestion do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fields = ['min_choices', 'max_choices', 'possible_answers']
|
fields = %w[min_choices max_choices possible_answers]
|
||||||
(SurveyQuestion.kinds.keys - ['choice']).each do |kind|
|
(SurveyQuestion.kinds.keys - ['choice']).each do |kind|
|
||||||
fields.each do |field|
|
fields.each do |field|
|
||||||
it_behaves_like 'is nil', kind, field
|
it_behaves_like 'is nil', kind, field
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe SurveyReply do
|
describe SurveyReply do
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Survey do
|
describe Survey do
|
||||||
subject { create(:survey) }
|
subject { create(:survey) }
|
||||||
let(:survey_active) { create(:conference_survey, start_date: Date.current - 1.day, end_date: Date.current + 1.day) }
|
let(:survey_active) { create(:conference_survey, start_date: Date.current - 1.day, end_date: Date.current + 1.day) }
|
||||||
let(:survey_inactive) { create(:conference_survey, start_date: Date.current - 2.day, end_date: Date.current - 1.day) }
|
let(:survey_inactive) { create(:conference_survey, start_date: Date.current - 2.days, end_date: Date.current - 1.day) }
|
||||||
|
|
||||||
describe 'association' do
|
describe 'association' do
|
||||||
it { is_expected.to have_many(:survey_questions) }
|
it { is_expected.to have_many(:survey_questions) }
|
||||||
|
|
@ -17,12 +19,8 @@ describe Survey do
|
||||||
describe '#active?' do
|
describe '#active?' do
|
||||||
it { expect(survey_active.active?).to eq true }
|
it { expect(survey_active.active?).to eq true }
|
||||||
it { expect(survey_inactive.active?).to eq false }
|
it { expect(survey_inactive.active?).to eq false }
|
||||||
it 'returns false, if start_date is not set' do
|
it 'returns true, if both start_date and end_date are not set' do
|
||||||
expect(create(:survey, start_date: nil, end_date: Date.current + 1.day).active?).to eq false
|
expect(create(:survey, start_date: nil, end_date: nil, surveyable: create(:conference)).active?).to eq true
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns false, if end_date is not set' do
|
|
||||||
expect(create(:survey, start_date: Date.current + 1.day, end_date: nil).active?).to eq false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe SurveySubmission do
|
describe SurveySubmission do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue