Skip to content

Commit

Permalink
Organizers can preview the survey before sending it to participants
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraKirby authored and tjgrathwell committed Jan 6, 2016
1 parent c017079 commit 996fe78
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
8 changes: 7 additions & 1 deletion app/controllers/surveys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class SurveysController < ApplicationController
before_action :authenticate_user!
before_action :find_event
before_action :find_rsvp, except: :index
before_action :validate_user!, except: :index
before_action :validate_user!, except: [:index, :preview]
before_action :validate_organizer!, only: :index

def new
Expand Down Expand Up @@ -30,6 +30,12 @@ def index
@volunteer_surveys = Survey.where(rsvp_id: @event.volunteer_rsvps.pluck(:id))
end

def preview
@survey = Survey.new
@preview = true
render :new
end

private

def survey_params
Expand Down
10 changes: 4 additions & 6 deletions app/views/events/organizer_tools/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@


<h2>Tools for after the event</h2>
<p>We encourage you to send this quick survey to everyone who participated.</p>
<% if @event.survey_sent? %>
<section class="organizer-dashboard-section">
<%= render partial: 'shared/organizer_action', locals: {
Expand All @@ -81,11 +82,10 @@
<% else %>
<section class="organizer-dashboard-section">
<%= render partial: 'shared/organizer_action', locals: {
path: event_send_survey_email_path(@event),
path: preview_event_surveys_path(@event),
icon: 'fa fa-envelope',
text: 'Send Survey',
tip: 'Click here to send a link to the follow up survey to all students and volunteers.',
confirm: 'Are you sure?'
text: 'Preview & Send Survey',
tip: 'Email all students and volunteers with a short follow-up survey.',
} %>
<%= render partial: 'shared/organizer_action', locals: {
path: edit_event_survey_path(@event),
Expand All @@ -97,5 +97,3 @@
<% end %>
</div>
</div>


28 changes: 20 additions & 8 deletions app/views/surveys/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
<%= content_for(:header_text, "Follow-up Survey") %>
<%= content_for(:header_text, @event.title) %>
<%= render 'shared/model_error_messages', model: @survey %>
<% if @preview %>
<%= render :partial => 'shared/organizer_breadcrumb', locals: {current_page_title: 'Survey Preview'} %>
<% end %>

<h2>How was <%= @event.title %>?</h2>

<p>We love feedback, so let us know how things went for you and anything you think we could make better in the future!</p>

<div class="row">
<div class="col-md-6 survey-form">
<%= simple_form_for @survey, url: event_rsvp_surveys_path(@event.id, @rsvp.id) do |f| %>
<%= f.input :good_things, label: "What was great?" %>
<%= f.input :good_things, label: "What was great?", readonly: @preview %>
<%= f.input :bad_things, label: "What could have been better?" %>
<%= f.input :bad_things, label: "What could have been better?", readonly: @preview %>
<%= f.input :other_comments, label: "Any other comments?" %>
<%= f.input :other_comments, label: "Any other comments?", readonly: @preview %>
<%= f.label :recommendation_likelihood, "How likely are you to recommend this workshop to a friend or colleague? (10 is very likely, 1 is unlikely)" %>
<%= f.select :recommendation_likelihood, (1..10).to_a.reverse, {}, {class: 'form-control'} %>
<% unless @survey.persisted? %>
<%= f.select :recommendation_likelihood, (1..10).to_a.reverse, {}, {class: 'form-control', disabled: @preview} %>
<% if !@survey.persisted? && !@preview%>
<%= f.submit "Submit", class: "btn", data: {disable_with: 'Please wait...'} %>
<% end %>
<p></p>
<% if @preview && @event.survey_sent?%>
<p>Survey has been sent.</p>
<% elsif @preview %>
<p><%= link_to 'Send Survey', event_send_survey_email_path(@event), class: "btn", :data => {:confirm => 'Are you sure?'} %></p>
<p><%= link_to 'Back', event_organizer_tools_path(@event), class: "btn" %></p>
<% end %>
<% end %>
</div>
</div>
</div>
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
resources :surveys, only: [:new, :create]
end

resources :surveys, only: [:new, :index]
resources :surveys, only: [:new, :index] do
get :preview, on: :collection
end

resources :event_sessions, only: [:index, :show, :destroy] do
resources :checkins, only: [:index, :create, :destroy]
Expand Down
15 changes: 15 additions & 0 deletions spec/features/event_survey_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
@rsvp = create(:rsvp, user: @user, event: @event)
end

describe 'previewing survey' do
before do
sign_in_as @user
visit preview_event_surveys_path(@event)
end

it 'should not allow organizer to submit survey' do
expect(page).not_to have_content("Submit")
end

it 'should allow organizer to email RSVPs the survey' do
expect(page).to have_content("Send Survey")
end
end

describe 'taking a survey' do
before do
sign_in_as @user
Expand Down

0 comments on commit 996fe78

Please sign in to comment.