Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRY - Adding date to previously sent survey #1724

Merged
merged 3 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/assets/javascripts/surveyor/responses.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
#= require likert

$(document).ready ->
$(document).on 'load-success.bs.table', '#responses-table', ->
$('[data-toggle="tooltip"]').tooltip()

$(document).on 'change', '.option input', ->
question_id = $(this).parents('.option').data('question-id')
option_id = $(this).parents('.option').data('option-id')

$(".dependent-for-question-#{question_id}").addClass('hidden')

if $(this).is(":checked")
$(".dependent-for-option-#{option_id}").removeClass('hidden')
else
Expand All @@ -40,7 +43,7 @@ $(document).ready ->

$(document).on 'change', '.question .selectpicker[multiple=multiple]', ->
question_id = $(this).data('question-id')
option_ids = $(this).find('.option:checked').map( ->
option_ids = $(this).find('.option:checked').map( ->
$(this).data('option-id')).get()

$(".dependent-for-question-#{question_id}").addClass('hidden')
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/dashboard/sub_service_requests.sass
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
.panel-heading:hover
cursor: pointer

#resend-surveys-button
margin-left: 10px

.details-table
padding: 15px 0px 15px 0px
height: 400px
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def resend_surveys
flash[:alert] = 'All surveys have already been completed.'
else
@sub_service_request.distribute_surveys
@refresh = true
flash[:success] = 'Surveys re-sent!'
end
end
Expand Down
19 changes: 16 additions & 3 deletions app/controllers/surveyor/responses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def create

if @response.save
SurveyNotification.system_satisfaction_survey(@response).deliver_now if @response.survey.access_code == 'system-satisfaction-survey' && Rails.application.routes.recognize_path(request.referrer)[:action] == 'review'
flash[:success] = t(:surveyor)[:responses][:create]
flash[:success] = t(:surveyor)[:responses][:completed]
end

respond_to do |format|
Expand All @@ -110,7 +110,7 @@ def create

def update
if @response.update_attributes(response_params)
flash[:success] = t(:surveyor)[:responses][:update]
flash[:success] = t(:surveyor)[:responses][:completed]
end

respond_to do |format|
Expand All @@ -125,7 +125,7 @@ def destroy
@permission_to_edit = @protocol_role.nil? ? false : @protocol_role.can_edit? if @protocol

@response.destroy

respond_to do |format|
format.js
end
Expand All @@ -134,6 +134,17 @@ def destroy
def complete
end

def resend_survey
@response = Response.find(params[:response_id])
if @response.survey.access_code == 'system-satisfaction-survey'
SurveyNotification.system_satisfaction_survey(@response).deliver
@response.update_attribute(:updated_at, Time.now)
else
SurveyNotification.service_survey([@response.survey], @response.identity, @response.try(:respondable)).deliver
end
flash[:success] = t(:surveyor)[:responses][:resent]
end

private

def find_response
Expand Down Expand Up @@ -177,6 +188,7 @@ def load_responses
def preload_responses
preloader = ActiveRecord::Associations::Preloader.new
preloader.preload(@responses.select { |r| r.respondable_type == SubServiceRequest.name }, { respondable: { protocol: { primary_pi_role: :identity } } })
preloader.preload(@responses.select { |r| r.respondable_type == ServiceRequest.name }, { respondable: { protocol: { primary_pi_role: :identity } } })
end

def get_incomplete_form_responses
Expand All @@ -198,4 +210,5 @@ def get_incomplete_form_responses

responses
end

end
28 changes: 20 additions & 8 deletions app/helpers/surveyor/responses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ def response_options(response, accessible_surveys)
accessible_surveys.include?(response.survey)
end

resend_permissions =
if response.completed?
false
else
current_user.is_site_admin? || accessible_surveys.include?(response.survey)
end

[ view_response_button(response, view_permissions),
edit_response_button(response, edit_permissions)
edit_response_button(response, edit_permissions),
resend_survey_button(response, resend_permissions)
].join('')
end

Expand All @@ -55,7 +63,7 @@ def view_response_button(response, permissions=true)
content_tag(:span, '', class: 'glyphicon glyphicon-search', aria: { hidden: 'true' }),
response.new_record? ? '' : surveyor_response_path(response),
remote: true,
class: ['btn btn-info view-response', permissions && response.completed? ? '' : 'disabled'],
class: ['btn btn-primary view-response', permissions && response.completed? ? '' : 'disabled'],
title: I18n.t('surveyor.responses.tooltips.view', klass: response.survey.class.yaml_klass),
data: { toggle: 'tooltip', placement: 'top', delay: '{"show":"500"}', container: 'body' }
)
Expand All @@ -81,12 +89,16 @@ def delete_response_button(response)
)
end

def download_response_button(response)
link_to(
content_tag(:span, '', class: 'glyphicon glyphicon-download-alt', aria: { hidden: 'true' }),
'javascript:void(0)',
class: 'btn btn-success download-response'
)
def resend_survey_button(response, permissions=true)
if @type == 'Survey'
link_to(
content_tag(:span, '', class: 'glyphicon glyphicon-share-alt', aria: { hidden: 'true'}),
surveyor_response_resend_survey_path(response), method: :put, remote: true,
class: ['btn btn-info resend-survey', permissions ? '' : 'disabled'],
title: I18n.t('surveyor.responses.tooltips.resend', klass: response.survey.class.yaml_klass),
data: { response_id: response.id, toggle: 'tooltip', placement: 'top', delay: '{"show":"500"}', container: 'body'}
)
end
end

def dependency_classes(question, question_response)
Expand Down
4 changes: 4 additions & 0 deletions app/models/sub_service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ def surveys_completed?
all?{ |s| s.responses.where(respondable: self).joins(:question_responses).any? }
end

def survey_latest_sent_date
self.responses.joins(:survey).where(surveys: { type: 'SystemSurvey' }).first.updated_at
end

###############################
### AUDIT REPORTING METHODS ###
###############################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
= link_to t(:dashboard)[:sub_service_requests][:tabs][:request_details][:options][:export_to_excel], service_request_path(service_request, format: :xlsx, report_type: 'request_report', admin_offset: 1, sub_service_request_id: sub_service_request.id), :class => "export_to_excel_button btn btn-sm btn-primary", data: { toggle: 'tooltip', placement: 'top', delay: '{"show":"500"}' }, title: t(:dashboard)[:sub_service_requests][:tabs][:request_details][:tooltips][:export_to_excel]
- if sub_service_request.is_complete? && !sub_service_request.surveys_completed?
%td.text-center
%span
= I18n.t('dashboard.sub_service_requests.tabs.request_details.options.last_sent', date: format_date(sub_service_request.survey_latest_sent_date))
%button.btn.btn-sm.btn-primary#resend-surveys-button{ data: { sub_service_request_id: sub_service_request.id } }
= t(:dashboard)[:sub_service_requests][:tabs][:request_details][:options][:resend_surveys]
- if !sub_service_request.in_work_fulfillment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
$("#flashes_container").html("<%= escape_javascript(render( 'shared/flash' )) %>")
$("#flashes_container").html("<%= j render 'shared/flash' %>")
$('#resend-surveys-button').prop('disabled', false)

<% if @refresh %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/survey_notification/service_survey.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

%ul
- @surveys.each do |survey|
- unless response = survey.responses.where(identity: @identity, respondable: @ssr).first
- if response = survey.responses.where(identity: @identity, respondable: @ssr).first
- response.update_attribute(:updated_at, Time.now)
- else
- response = survey.responses.create(identity: @identity, respondable: @ssr)
%li
= link_to survey.title, url_for(controller: '/surveyor/responses', action: :edit, only_path: false, id: response.id, format: :html), target: '_blank'
Expand Down
2 changes: 2 additions & 0 deletions app/views/surveyor/responses/_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@
= t(:surveyor)[:responses][:table][:headers][:complete]
%th{ data: { class: 'completion-date col-sm-1', align: 'left', sortable: 'true', sorter: 'dateSorter', field: 'completion_date' } }
= t(:surveyor)[:responses][:table][:headers][:date]
%th{ data: {class: 'survey-sent-date col-sm-1', align: 'left', sortable: 'true', sorter: 'dateSorter', field: 'survey_sent_date', visible: 'false'} }
= t(:surveyor)[:responses][:table][:headers][:survey_sent_date]
%th{ data: { class: 'actions col-sm-2', align: 'center', sortable: 'false', field: 'actions' } }
= t(:surveyor)[:responses][:table][:headers][:actions]
1 change: 1 addition & 0 deletions app/views/surveyor/responses/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ json.(@responses) do |response|
json.by response.identity.try(:full_name) || 'N/A'
json.complete complete_display(response)
json.completion_date response.completed? ? format_date(response.created_at) : ""
json.survey_sent_date format_date(response.updated_at)
json.actions response_options(response, accessible_surveys)
end
22 changes: 22 additions & 0 deletions app/views/surveyor/responses/resend_survey.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
$("#flashes_container").html("<%= j render 'shared/flash' %>")
$('#responses-table').bootstrapTable('refresh')
$("[data-toggle='tooltip']").tooltip()
1 change: 1 addition & 0 deletions config/locales/dashboard.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ en:
send_to_epic: "Send to Epic"
core_approvals: "Administrative Approvals"
export_to_excel: "Export to Excel"
last_sent: "Surveys last sent on %{date}"
resend_surveys: "Resend Surveys"
delete_request: "Delete Request"
timeline:
Expand Down
7 changes: 5 additions & 2 deletions config/locales/surveyor.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ en:
reset: "Reset current search"

responses:
create: "Thank you for participating in this survey!"
completed: "Thank you for participating in this survey!"
resent: "Survey re-sent!"
complete:
header: "Survey Completed"
thanks: "Thank you for completing the survey!"
thanks: "Thank you for participating in this survey!"
to_dashboard: "Return to Dashboard"
table:
header: "%{type} Responses"
Expand All @@ -74,6 +75,7 @@ en:
title: "%{type} Title"
complete: "Complete"
date: "Date"
survey_sent_date: "Last Sent"
actions: "Actions"
by: "By"
emails:
Expand All @@ -95,6 +97,7 @@ en:
view: "View existing %{klass} answers."
edit: "Edit existing %{klass} answers."
delete: "Delete existing %{klass} answers."
resend: "Resend Survey"

surveys:
new_form:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
resources :options, only: [:create, :destroy]
resources :responses do
get :complete
put :resend_survey
end
resources :response_filters, only: [:new, :create, :destroy]
resources :survey_updater, only: [:update]
Expand Down