diff --git a/Gemfile b/Gemfile
index 0421803e..c95902d6 100644
--- a/Gemfile
+++ b/Gemfile
@@ -113,6 +113,8 @@ source 'https://rails-assets.org' do
gem 'rails-assets-waypoints'
# for markdown editors
gem 'rails-assets-bootstrap-markdown'
+ # for select with icon
+ gem 'rails-assets-bootstrap-select'
gem 'rails-assets-markdown'
gem 'rails-assets-to-markdown'
end
diff --git a/Gemfile.lock b/Gemfile.lock
index e3092559..831909b1 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -380,17 +380,19 @@ GEM
rails-assets-jquery (>= 1.9.1, < 3)
rails-assets-bootstrap-markdown (2.10.0)
rails-assets-bootstrap (~> 3)
+ rails-assets-bootstrap-select (1.10.0)
+ rails-assets-jquery (>= 1.8)
rails-assets-date.format (1.2.3)
rails-assets-holderjs (2.9.3)
- rails-assets-jquery (2.2.1)
+ rails-assets-jquery (2.2.4)
rails-assets-jquery-smooth-scroll (1.7.2)
rails-assets-jquery (>= 1.4.2)
rails-assets-markdown (0.5.0)
- rails-assets-momentjs (2.11.2)
+ rails-assets-momentjs (2.13.0)
rails-assets-spectrum (1.8.0)
rails-assets-jquery (>= 1.7.2)
rails-assets-tinycolor (1.3.0)
- rails-assets-to-markdown (1.3.0)
+ rails-assets-to-markdown (3.0.0)
rails-assets-trianglify (0.4.0)
rails-assets-waypoints (4.0.0)
rails-controller-testing (1.0.2)
@@ -639,6 +641,7 @@ DEPENDENCIES
puma (~> 3.0)
rails (~> 5.0.5)
rails-assets-bootstrap-markdown!
+ rails-assets-bootstrap-select!
rails-assets-date.format!
rails-assets-holderjs!
rails-assets-jquery-smooth-scroll!
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index b347821b..34bd66a7 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -47,6 +47,8 @@
//= require unobtrusive_flash_bootstrap
//= require countable
//= require selectize
+//= require bootstrap-select
+//= require osem-survey
$(document).ready(function() {
$('a[disabled=disabled]').click(function(event){
diff --git a/app/assets/javascripts/osem-datepickers.js b/app/assets/javascripts/osem-datepickers.js
index 6dc89f43..04a5c844 100644
--- a/app/assets/javascripts/osem-datepickers.js
+++ b/app/assets/javascripts/osem-datepickers.js
@@ -9,6 +9,13 @@ $(function () {
format: 'YYYY-MM-DD HH:mm'
});
+ $('.datetimepicker').datetimepicker({
+ pickTime: true,
+ useCurrent: false,
+ sideBySide: true,
+ format: 'YYYY-MM-DD HH:mm'
+ });
+
$("#registration-arrival-datepicker").datetimepicker({
pickTime: true,
useCurrent: false,
diff --git a/app/assets/javascripts/osem-survey.js b/app/assets/javascripts/osem-survey.js
new file mode 100644
index 00000000..20ed2a19
--- /dev/null
+++ b/app/assets/javascripts/osem-survey.js
@@ -0,0 +1,33 @@
+$(function() {
+ $('.selectpicker').on('changed.bs.select', function (e, clickedIndex) {
+ $('.kinds').addClass('hidden');
+ var selected = $('.selectpicker').find('option:selected').val();
+ $('.' + selected).removeClass('hidden');
+
+ if (selected == 'choice') {
+ $('.survey-possible-answers').removeClass('hidden');
+ }
+ else
+ {
+ $('.survey-possible-answers').addClass('hidden');
+ }
+ });
+ $('#survey_question_title').on('keyup', function(){
+ $('#survey_question_preview #title').text($(this).val())
+ });
+
+ function render_possible_answers_preview() {
+ var options_html = '';
+ var options_array = $('#survey_question_possible_answers').val().split(',');
+ var input_type = ($('#survey_question_min_choices').val() == 1 &&
+ $('#survey_question_max_choices').val() == 1) ? 'radio' : 'checkbox';
+ $.each(options_array, function(index, option) {
+ options_html += ' ' + option.trim() + '
';
+ });
+ $('#survey_question_preview .choice').html(options_html)
+ };
+
+ $('#survey_question_possible_answers').on('keyup', render_possible_answers_preview);
+ $('#survey_question_min_choices').on('change', render_possible_answers_preview);
+ $('#survey_question_max_choices').on('change', render_possible_answers_preview);
+});
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index 0767d15d..a316f473 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -19,4 +19,5 @@
*= require selectize
*= require selectize.bootstrap3
*= require mastodon
+ *= require bootstrap-select
*/
diff --git a/app/controllers/admin/survey_questions_controller.rb b/app/controllers/admin/survey_questions_controller.rb
new file mode 100644
index 00000000..2fb836c3
--- /dev/null
+++ b/app/controllers/admin/survey_questions_controller.rb
@@ -0,0 +1,52 @@
+module Admin
+ class SurveyQuestionsController < Admin::BaseController
+ load_and_authorize_resource :conference, find_by: :short_title
+ load_and_authorize_resource :survey, through: :conference
+ load_and_authorize_resource through: :survey
+
+ def new
+ @survey_question = @survey.survey_questions.new(min_choices: 1, max_choices: 1)
+ @url = admin_conference_survey_survey_questions_path(@conference.short_title, @survey)
+ end
+
+ def create
+ @survey_question = @survey.survey_questions.new(survey_question_params)
+ if @survey_question.save
+ redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully created Survey Question.'
+ else
+ @url = admin_conference_survey_survey_questions_path(@conference.short_title, @survey)
+ render :new
+ end
+ end
+
+ # GET questions/1/edit
+ def edit
+ @url = admin_conference_survey_survey_question_path(@conference.short_title, @survey, @survey_question)
+ end
+
+ # PUT questions/1
+ def update
+ if @survey_question.update_attributes(survey_question_params)
+ redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully updated Survey Question.'
+ else
+ @url = admin_conference_survey_survey_question_path(@conference.short_title, @survey, @survey_question)
+ render :edit
+ end
+ end
+
+ # DELETE questions/1
+ def destroy
+ if @survey_question.destroy
+ redirect_to admin_conference_survey_path(@conference.short_title, @survey), notice: 'Successfully deleted Survey Question.'
+ else
+ redirect_to admin_conference_survey_path(@conference.short_title, @survey), error: "Can't delete this Survey Question"
+ end
+ end
+
+ private
+
+ def survey_question_params
+ params.require(:survey_question).permit(:title, :kind, :possible_answers, :min_choices, :max_choices, :mandatory)
+ end
+ end
+end
diff --git a/app/controllers/admin/surveys_controller.rb b/app/controllers/admin/surveys_controller.rb
new file mode 100644
index 00000000..81929d7a
--- /dev/null
+++ b/app/controllers/admin/surveys_controller.rb
@@ -0,0 +1,48 @@
+module Admin
+ class SurveysController < Admin::BaseController
+ load_and_authorize_resource :conference, find_by: :short_title
+ load_and_authorize_resource
+
+ def index
+ @surveys = @conference.surveys
+ end
+
+ def new
+ @survey = Survey.new(survey_params)
+ @url = admin_conference_surveys_path(@conference.short_title)
+ end
+
+ def create
+ @survey = Survey.new(survey_params)
+ if @survey.save
+ redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), notice: 'Successfully created survey'
+ 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
+ end
+ end
+
+ def edit
+ @url = admin_conference_survey_path(@conference.short_title, @survey)
+ end
+
+ def update
+ if @survey.update_attributes(survey_params)
+ redirect_to admin_conference_surveys_path(@conference.short_title)
+ else
+ @url = admin_conference_survey_path(@conference.short_title, @survey)
+ render action: :edit
+ end
+ end
+
+ def destroy
+ @survey.destroy
+ redirect_to admin_conference_surveys_path(@conference.short_title)
+ end
+
+ private
+
+ def survey_params
+ params.require(:survey).permit(:title, :description, :target, :start_date, :end_date, :surveyable_type, :surveyable_id)
+ end
+ end
+end
diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb
new file mode 100644
index 00000000..303b9f25
--- /dev/null
+++ b/app/controllers/surveys_controller.rb
@@ -0,0 +1,30 @@
+class SurveysController < ApplicationController
+ load_resource :conference, find_by: :short_title
+ load_and_authorize_resource
+
+ def index
+ @surveys = @conference.surveys.select(&:active?)
+ end
+
+ def show
+ @survey_submission = @survey.survey_submissions.new
+ end
+
+ def reply
+ survey_submission = params[:survey_submission]
+
+ @survey.survey_questions.each do |survey_question|
+ reply = survey_question.survey_replies.find_by(user: current_user)
+ reply_text = survey_submission[survey_question.id.to_s].reject(&:blank?).join(',')
+
+ if reply
+ reply.update_attributes(text: reply_text) unless reply.text == reply_text
+ else
+ survey_question.survey_replies.create!(text: reply_text, user: current_user)
+ end
+ @survey.survey_submissions.create!(user: current_user) unless @survey.survey_submissions.find_by(user: current_user)
+ end
+
+ redirect_to :back
+ end
+end
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 71f22cfb..ce7fe202 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -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|
diff --git a/app/models/conference.rb b/app/models/conference.rb
index 95d63941..adffe619 100644
--- a/app/models/conference.rb
+++ b/app/models/conference.rb
@@ -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
diff --git a/app/models/survey.rb b/app/models/survey.rb
new file mode 100644
index 00000000..14975b55
--- /dev/null
+++ b/app/models/survey.rb
@@ -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
diff --git a/app/models/survey_question.rb b/app/models/survey_question.rb
new file mode 100644
index 00000000..e80129ab
--- /dev/null
+++ b/app/models/survey_question.rb
@@ -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
diff --git a/app/models/survey_reply.rb b/app/models/survey_reply.rb
new file mode 100644
index 00000000..1abca384
--- /dev/null
+++ b/app/models/survey_reply.rb
@@ -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
diff --git a/app/models/survey_submission.rb b/app/models/survey_submission.rb
new file mode 100644
index 00000000..997f6947
--- /dev/null
+++ b/app/models/survey_submission.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index 5c9c5209..11dcdc40 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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) }
diff --git a/app/views/admin/survey_questions/_form.html.haml b/app/views/admin/survey_questions/_form.html.haml
new file mode 100644
index 00000000..7cd7bbdb
--- /dev/null
+++ b/app/views/admin/survey_questions/_form.html.haml
@@ -0,0 +1,92 @@
+.row
+ .col-md-12
+ .page-header
+ - if @survey_question.new_record?
+ %h1
+ New Survey Question
+ - else
+ %h1
+ Edit Survey Question
+ .text-muted
+ = @survey_question.title
+
+ .col-md-6
+ = semantic_form_for @survey_question, url: @url do |f|
+
+ .row
+ .col-md-12
+ = f.input :title
+ = f.input :mandatory
+ %div.survey-possible-answers{ class: @survey_question.choice? ? '' : 'hidden'}
+ = f.input :possible_answers, hint: 'Comma separated', input_html: { rows: 3 }
+ .row
+ .col-md-6
+ = f.input :min_choices
+ .col-md-6
+ = f.input :max_choices
+ %hr
+ .row
+ .col-md-6
+ %label{ required: 'required' }
+ Type of Question:
+ .form-group
+ %select.selectpicker.form-control{ id: 'survey_question_kind', name: 'survey_question[kind]' }
+ - SurveyQuestion.kinds.each do |kind|
+ %option{ id: "#{kind.second}", 'data-icon' => "fa fa-#{SurveyQuestion::ICONS[kind.first.to_sym]}", selected: @survey_question.kind == kind.first }
+ = kind.first
+ .col-md-6
+ %label
+ Preview:
+ .panel.panel-default
+ .panel-body{id: 'survey_question_preview'}
+ %p{id: 'title', style: 'word-wrap: break-word'}
+ = @survey_question.title.blank? ? 'What is your answer?' : @survey_question.title
+
+ %div.kinds.boolean{ class: @survey_question.boolean? ? '' : 'hidden'}
+ %input{type: 'radio', name: 'radio'} Yes
+ %br
+ %input{type: 'radio', name: 'radio'} No
+
+ %div.kinds.choice{ id: '', class: @survey_question.choice? ? '' : 'hidden'}
+ - if @survey_question.possible_answers.blank?
+ - if @survey_question.single_choice?
+ %input{ type: 'radio', name: 'radio' } Choice 1
+ %br
+ %input{ type: 'radio', name: 'radio' } Choice 2
+ %br
+ %input{ type: 'radio', name: 'radio' } Choice 3
+ - else
+ %input{ type: 'checkbox', name: 'checkbox' } Choice 1
+ %br
+ %input{ type: 'checkbox', name: 'checkbox' } Choice 2
+ %br
+ %input{ type: 'checkbox', name: 'checkbox' } Choice 3
+ - else
+ - @survey_question.possible_answers.split(',').map(&:strip).each do |option|
+ - if @survey_question.single_choice?
+ %input{ type: 'radio', name: 'radio' }
+ = option
+ %br
+ - else
+ %input{ type: 'checkbox', name: 'checkbox' }
+ = option
+ %br
+
+ %div.kinds.string{ class: @survey_question.string? ? '' : 'hidden'}
+ %input.form-control
+
+ %div.kinds.text{ class: @survey_question.text? ? '' : 'hidden'}
+ %textarea.form-control{ rows: 4 }
+
+
+ %div.kinds.datetime{ class: @survey_question.datetime? ? '' : 'hidden'}
+ .form-group{class: 'datetimepicker'}
+ .input-group
+ .input-group-addon
+ %span.fa.fa-calendar
+ %input.form-control{readonly: 'readonly'}
+
+ %div.kinds.numeric{ class: @survey_question.numeric? ? '' : 'hidden'}
+ %input.form-control{ type: 'number' }
+
+ = f.submit 'Save', class: 'btn btn-primary'
diff --git a/app/views/admin/survey_questions/edit.html.haml b/app/views/admin/survey_questions/edit.html.haml
new file mode 100644
index 00000000..72992799
--- /dev/null
+++ b/app/views/admin/survey_questions/edit.html.haml
@@ -0,0 +1 @@
+= render partial: 'form'
diff --git a/app/views/admin/surveys/_form.html.haml b/app/views/admin/surveys/_form.html.haml
new file mode 100644
index 00000000..d01eb467
--- /dev/null
+++ b/app/views/admin/surveys/_form.html.haml
@@ -0,0 +1,18 @@
+.row
+ .col-md-12
+ .page-header
+ - if @survey.new_record?
+ %h1 New Survey
+ - else
+ %h1 Edit Survey: #{ @survey.title }
+
+ .col-md-6
+ = semantic_form_for @survey, url: @url do |f|
+ = f.hidden_field :surveyable_type
+ = f.hidden_field :surveyable_id
+ = f.input :title
+ = f.input :description, input_html: { rows: 3 }
+ = f.input :target, as: :select, collection: Survey.targets.keys, label: "When to ask"
+ = f.input :start_date, as: :string, input_html: { class: 'datetimepicker' }
+ = f.input :end_date, as: :string, input_html: { class: 'datetimepicker' }
+ = f.submit 'Save', class: 'btn btn-primary'
diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml
new file mode 100644
index 00000000..dcf81d40
--- /dev/null
+++ b/app/views/admin/surveys/_survey_question.html.haml
@@ -0,0 +1,62 @@
+.panel.panel-default
+ .panel-heading
+ %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
+ = 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
+ - if survey_question.boolean?
+ %input{ type: 'hidden', name: "survey_submission[#{survey_question.id}][]" }
+ %label
+ %input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: 'Yes', checked: survey_reply.text == 'Yes' }
+ Yes
+ %br
+ %label
+ %input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: 'No', checked: survey_reply.text == 'No' }
+ No
+
+ - elsif survey_question.choice?
+ %input{ type: 'hidden', name: "survey_submission[#{survey_question.id}][]" }
+ - possible_answers = survey_question.possible_answers.split(',').map(&:strip)
+
+ - possible_answers.each.with_index(1) do |answer, answer_index|
+ - if survey_question.single_choice?
+ %label
+ %input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: answer, checked: (survey_reply.text.include? answer if survey_reply.text) }
+ = answer
+ %br
+ - else
+ %label
+ = check_box_tag "survey_submission[#{survey_question.id}][]", answer, (survey_reply.text.include? answer if survey_reply.text), id: dom_id(survey_reply)
+ = answer
+
+ %br
+ - elsif survey_question.string?
+ %input.form-control{ name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }
+ - elsif survey_question.text?
+ = text_area_tag "survey_submission[#{survey_question.id}][]", survey_reply.text, rows: 4, class: 'form-control'
+ - elsif survey_question.datetime?
+ .form-group{ class: 'datetimepicker' }
+ .input-group
+ .input-group-addon
+ %span.fa.fa-calendar
+ %input.form-control{ readonly: 'readonly', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }
+ - elsif survey_question.numeric?
+ %input.form-control{ type: 'number', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text }
diff --git a/app/views/admin/surveys/edit.html.haml b/app/views/admin/surveys/edit.html.haml
new file mode 100644
index 00000000..72992799
--- /dev/null
+++ b/app/views/admin/surveys/edit.html.haml
@@ -0,0 +1 @@
+= render partial: 'form'
diff --git a/app/views/admin/surveys/index.html.haml b/app/views/admin/surveys/index.html.haml
new file mode 100644
index 00000000..2c561e83
--- /dev/null
+++ b/app/views/admin/surveys/index.html.haml
@@ -0,0 +1,38 @@
+.row
+ .col-md-12
+ .page-header
+ %h1
+ Surveys
+ = link_to 'New', new_admin_conference_survey_path(@conference.short_title, survey: { surveyable_type: 'Conference', surveyable_id: @conference.id }), class: 'btn btn-success pull-right'
+ %p.text-muted
+ Available surveys for this conference
+
+
+- if @surveys.any?
+ .row
+ .col-md-12
+ %table.table.table-hover.datatable#surveys
+ %thead
+ %th Title
+ %th When
+ %th Start Date
+ %th End Date
+ %th Actions
+ %tbody
+ - @surveys.each_with_index do |survey, index|
+ %tr
+ %td
+ = link_to survey.title, admin_conference_survey_path(@conference.short_title, survey)
+ %td
+ = survey.target
+ %td
+ = survey.start_date
+ %td
+ = survey.end_date
+ %td
+ .btn-group
+ = link_to 'Edit', edit_admin_conference_survey_path(@conference.short_title, survey),
+ class: 'btn btn-primary'
+ = link_to 'Delete', admin_conference_survey_path(@conference.short_title, survey),
+ method: :delete, class: 'btn btn-danger',
+ data: { confirm: "Do you really want to delete #{survey.title}?"}
diff --git a/app/views/admin/surveys/new.html.haml b/app/views/admin/surveys/new.html.haml
new file mode 100644
index 00000000..72992799
--- /dev/null
+++ b/app/views/admin/surveys/new.html.haml
@@ -0,0 +1 @@
+= render partial: 'form'
diff --git a/app/views/admin/surveys/show.html.haml b/app/views/admin/surveys/show.html.haml
new file mode 100644
index 00000000..8a49b463
--- /dev/null
+++ b/app/views/admin/surveys/show.html.haml
@@ -0,0 +1,20 @@
+.row
+ .col-md-12
+ .page-header
+ %h1
+ Survey: #{@survey.title}
+ = link_to 'Edit Survey', edit_admin_conference_survey_path(@conference.short_title, @survey), class: 'btn btn-primary pull-right'
+ %p.text-muted
+ From:
+ = @survey.start_date
+ to
+ = @survey.end_date
+.row
+ .col-md-12
+ = 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'
diff --git a/app/views/conference_registrations/_registration_info.html.haml b/app/views/conference_registrations/_registration_info.html.haml
index cb6cd90c..2945a16e 100644
--- a/app/views/conference_registrations/_registration_info.html.haml
+++ b/app/views/conference_registrations/_registration_info.html.haml
@@ -9,8 +9,7 @@
= f.input :accepted_code_of_conduct,
label: "I have read and accept the #{code_of_conduct_link}".html_safe,
required: true
-- if @conference.questions.any?
- = render partial: 'conference_registrations/questions', locals: { f: f }
+
- if @conference.program.events.with_registration_open.any? || @registration.events.any?
= f.inputs 'Pre-registration required for the following:' do
diff --git a/app/views/conference_registrations/show.html.haml b/app/views/conference_registrations/show.html.haml
index 223d7c12..79e4b4fd 100644
--- a/app/views/conference_registrations/show.html.haml
+++ b/app/views/conference_registrations/show.html.haml
@@ -55,24 +55,17 @@
= @registration.departure.strftime('%A, %B %-d. %Y %H:%M')
- else
You haven't scheduled your departure
- - if @conference.questions.any?
+ - if @conference.surveys.for_registration.any?
.row
.col-md-12
%h4
%span.fa-stack
%i.fa.fa-square-o.fa-stack-2x
%i.fa.fa-info.fa-stack-1x
- Additional Info
+ Surveys
+
%ul
- - @conference.questions.each do |q|
- %li
- %strong
- = q.title
- - if @registration.qanswers.any?
- - @registration.qanswers.where(question_id: q.id).each do |qa|
- = qa.answer.title
- - else
- You haven't answered
+ = render partial: 'surveys/list', locals: { surveys: @conference.surveys.for_registration, conference: @conference }
- if @registration.events.any?
.row
.col-md-12
diff --git a/app/views/conferences/_conference_details.html.haml b/app/views/conferences/_conference_details.html.haml
index d07b3913..4595aa0a 100644
--- a/app/views/conferences/_conference_details.html.haml
+++ b/app/views/conferences/_conference_details.html.haml
@@ -51,4 +51,6 @@
- else
= link_to 'Unsubscribe', conference_subscriptions_path(conference.short_title), method: :delete, class: 'btn btn-default'
- if current_user && current_user.physical_tickets.by_conference(conference).any?
- = link_to "My Tickets", conference_physical_tickets_path(conference.short_title), class: 'btn btn-default'
+ = link_to 'My Tickets', conference_physical_tickets_path(conference.short_title), class: 'btn btn-default'
+ - surveys = conference.surveys.after_conference.select(&:active?)
+ = link_to 'Surveys', conference_surveys_path(conference.short_title), class: 'btn btn-default' if surveys.any?
diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml
index 4385d307..eebd7548 100644
--- a/app/views/layouts/_admin_sidebar.html.haml
+++ b/app/views/layouts/_admin_sidebar.html.haml
@@ -138,6 +138,10 @@
= link_to(admin_conference_emails_path(@conference.short_title)) do
%span.fa.fa-envelope
E-Mails
+ %li{ class: active_nav_li(admin_conference_surveys_path(@conference.short_title)) }
+ = link_to(admin_conference_surveys_path(@conference.short_title)) do
+ %span.fa.fa-list-alt
+ Surveys
- if can? :index, Role.new(resource: @conference)
%li{class: active_nav_li(admin_conference_roles_path(@conference.short_title))}
= link_to(admin_conference_roles_path(@conference.short_title)) do
diff --git a/app/views/surveys/_list.html.haml b/app/views/surveys/_list.html.haml
new file mode 100644
index 00000000..bba9b1c9
--- /dev/null
+++ b/app/views/surveys/_list.html.haml
@@ -0,0 +1,7 @@
+- surveys.each do |survey|
+ - if survey.survey_submissions.find_by(user: current_user)
+ %i.fa.fa-check-square-o.text-success{ title: 'Thank you for filling out the survey' }
+ - else
+ %i.fa.fa-minus-square-o.text-danger{ title: 'Please fill out the survey' }
+ = link_to survey.title, conference_survey_path(conference.short_title, survey)
+ %br
diff --git a/app/views/surveys/index.html.haml b/app/views/surveys/index.html.haml
new file mode 100644
index 00000000..9cb0bf2f
--- /dev/null
+++ b/app/views/surveys/index.html.haml
@@ -0,0 +1,8 @@
+.container
+ .row
+ .col-md-12
+ .page-header
+ %h1 Surveys
+ .row
+ .col-md-12
+ = render partial: 'surveys/list', locals: { surveys: @surveys, conference: @conference }
diff --git a/app/views/surveys/show.html.haml b/app/views/surveys/show.html.haml
new file mode 100644
index 00000000..5d7b85eb
--- /dev/null
+++ b/app/views/surveys/show.html.haml
@@ -0,0 +1,24 @@
+.row
+ .col-md-10.col-md-offset-1
+ .page-header
+ %h1
+ Survey #{@survey.title}
+ - if can? :edit, @survey
+ = link_to 'Edit Survey', admin_conference_survey_path(@conference.short_title, @survey), class: 'btn btn-primary pull-right'
+ %p.text-muted
+ From:
+ = @survey.start_date
+ to
+ = @survey.end_date
+
+.row
+ .col-md-12
+ = 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|
+ .row
+ .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)
+ = render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply }
+ .row
+ .col-md-10.col-md-offset-1
+ = f.submit 'Submit', class: 'btn btn-primary pull-right'
diff --git a/config/routes.rb b/config/routes.rb
index d4744788..7e46b6be 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -41,6 +41,9 @@ Osem::Application.routes.draw do
resource :ticket_scanning, only: [:create]
resources :comments, only: [:index]
resources :conferences do
+ resources :surveys do
+ resources :survey_questions, except: :index
+ end
resource :contact, except: [:index, :new, :create, :show, :destroy]
resources :schedules, except: [:edit, :update]
resources :event_schedules, only: [:create, :update, :destroy]
@@ -165,6 +168,11 @@ Osem::Application.routes.draw do
patch :restart
end
end
+ resources :surveys, only: [:index, :show] do
+ member do
+ post :reply
+ end
+ end
resource :program, only: [] do
resources :proposals, except: :destroy do
get 'commercials/render_commercial' => 'commercials#render_commercial'
diff --git a/db/migrate/20160627122446_create_surveys.rb b/db/migrate/20160627122446_create_surveys.rb
new file mode 100644
index 00000000..8a57053c
--- /dev/null
+++ b/db/migrate/20160627122446_create_surveys.rb
@@ -0,0 +1,13 @@
+class CreateSurveys < ActiveRecord::Migration
+ def change
+ create_table :surveys do |t|
+ t.datetime :start_date
+ t.datetime :end_date
+ t.string :title
+ t.text :description
+ t.references :surveyable, polymorphic: true, index: true
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/migrate/20160628093634_create_survey_questions.rb b/db/migrate/20160628093634_create_survey_questions.rb
new file mode 100644
index 00000000..233a7f4d
--- /dev/null
+++ b/db/migrate/20160628093634_create_survey_questions.rb
@@ -0,0 +1,13 @@
+class CreateSurveyQuestions < ActiveRecord::Migration
+ def change
+ create_table :survey_questions do |t|
+ t.references :survey
+ t.string :title
+ t.integer :kind, default: 0
+ t.integer :min_choices
+ t.integer :max_choices
+ t.text :possible_answers
+ t.boolean :mandatory, default: false
+ end
+ end
+end
diff --git a/db/migrate/20160629145954_add_target_to_surveys.rb b/db/migrate/20160629145954_add_target_to_surveys.rb
new file mode 100644
index 00000000..16c10b8d
--- /dev/null
+++ b/db/migrate/20160629145954_add_target_to_surveys.rb
@@ -0,0 +1,5 @@
+class AddTargetToSurveys < ActiveRecord::Migration
+ def change
+ add_column :surveys, :target, :integer, default: 0
+ end
+end
diff --git a/db/migrate/20160630094850_create_survey_replies.rb b/db/migrate/20160630094850_create_survey_replies.rb
new file mode 100644
index 00000000..3b8917de
--- /dev/null
+++ b/db/migrate/20160630094850_create_survey_replies.rb
@@ -0,0 +1,11 @@
+class CreateSurveyReplies < ActiveRecord::Migration
+ def change
+ create_table :survey_replies do |t|
+ t.integer :survey_question_id
+ t.integer :user_id
+ t.text :text
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/migrate/20160630130731_create_survey_submissions.rb b/db/migrate/20160630130731_create_survey_submissions.rb
new file mode 100644
index 00000000..bcab5271
--- /dev/null
+++ b/db/migrate/20160630130731_create_survey_submissions.rb
@@ -0,0 +1,10 @@
+class CreateSurveySubmissions < ActiveRecord::Migration
+ def change
+ create_table :survey_submissions do |t|
+ t.integer :user_id
+ t.integer :survey_id
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2af4b876..2f05a413 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -482,6 +482,45 @@ ActiveRecord::Schema.define(version: 20180316220446) do
t.datetime "updated_at"
end
+ create_table "survey_questions", force: :cascade do |t|
+ t.integer "survey_id"
+ t.string "title"
+ t.integer "kind", default: 0
+ t.integer "min_choices"
+ t.integer "max_choices"
+ t.text "possible_answers"
+ t.boolean "mandatory", default: false
+ end
+
+ create_table "survey_replies", force: :cascade do |t|
+ t.integer "survey_question_id"
+ t.integer "user_id"
+ t.text "text"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "survey_submissions", force: :cascade do |t|
+ t.integer "user_id"
+ t.integer "survey_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "surveys", force: :cascade do |t|
+ t.datetime "start_date"
+ t.datetime "end_date"
+ t.string "title"
+ t.text "description"
+ t.integer "surveyable_id"
+ t.string "surveyable_type"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "target", default: 0
+ end
+
+ add_index "surveys", ["surveyable_type", "surveyable_id"], name: "index_surveys_on_surveyable_type_and_surveyable_id"
+
create_table "targets", force: :cascade do |t|
t.integer "conference_id"
t.integer "campaign_id"
diff --git a/lib/tasks/demo_data_for_development.rake b/lib/tasks/demo_data_for_development.rake
index 4ce1f9e2..dac1967d 100644
--- a/lib/tasks/demo_data_for_development.rake
+++ b/lib/tasks/demo_data_for_development.rake
@@ -2,6 +2,26 @@
namespace :data do
desc 'Create demo data for our local development'
+
+ task survey: :environment do
+ include FactoryGirl::Syntax::Methods
+
+ conference = Conference.find_by(short_title: 'conf_with_survey') || create(:full_conference, short_title: 'conf_with_survey', start_date: Date.today)
+ # active survey
+ survey_after_conference_active = create(:survey, surveyable: conference, target: 0, title: 'Survey about the conference', start_date: conference.start_date - 1.day, end_date: conference.end_date + 5.days )
+ # inactive survey (will be available in 1 day)
+ survey_after_conference_active = create(:survey, surveyable: conference, target: 0, title: 'Survey about the conference', start_date: conference.start_date + 1.day, end_date: conference.end_date + 5.days )
+ survey_on_registration = create(:survey, surveyable: conference, target: 1, title: 'Survey during registation', start_date: conference.registration_period.start_date, end_date: conference.registration_period.end_date )
+ # boolean
+ create(:survey_question, survey: survey_after_conference, title: 'Did you like this conference?', kind: 0)
+ # single choice
+ create(:survey_question, survey: survey_after_conference, title: 'Which keynote did you like best?', kind: 1, min_choices: 1, max_choices: 1, possible_answers: 'Yes, No')
+ # string
+ create(:survey_question, survey: survey_after_conference, title: 'What did you like the most about this conference?', kind: 2)
+ # text
+ create(:survey_question, survey: survey_after_conference, title: 'Anything else you would like to share with us?', kind: 3)
+ end
+
task test: :environment do
include FactoryGirl::Syntax::Methods
diff --git a/spec/factories/survey_questions.rb b/spec/factories/survey_questions.rb
new file mode 100644
index 00000000..20db184b
--- /dev/null
+++ b/spec/factories/survey_questions.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :survey_question do
+ survey
+ title 'What about this question?'
+ end
+end
diff --git a/spec/factories/survey_replies.rb b/spec/factories/survey_replies.rb
new file mode 100644
index 00000000..54ce3744
--- /dev/null
+++ b/spec/factories/survey_replies.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :survey_reply do
+ user
+ survey_question
+ end
+end
diff --git a/spec/factories/survey_submissions.rb b/spec/factories/survey_submissions.rb
new file mode 100644
index 00000000..ad4a2dd4
--- /dev/null
+++ b/spec/factories/survey_submissions.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :survey_submission do
+ user
+ survey
+ end
+end
diff --git a/spec/factories/surveys.rb b/spec/factories/surveys.rb
new file mode 100644
index 00000000..f88631d5
--- /dev/null
+++ b/spec/factories/surveys.rb
@@ -0,0 +1,12 @@
+FactoryGirl.define do
+ factory :survey do
+ title 'This is my survey'
+ factory :conference_survey do
+ association :surveyable, factory: :conference
+ end
+
+ factory :registration_survey do
+ association :surveyable, factory: :registration
+ end
+ end
+end