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

KG - Request Details Tab New Feature: Resend Survey #1078

Merged
merged 2 commits into from
Aug 22, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ $(document).ready ->
type: 'PUT'
url: "/dashboard/sub_service_requests/#{sub_service_request_id}/push_to_epic"

$(document).on 'click', '#resend-surveys-button', ->
$(this).prop('disabled', true)
ssr_id = $(this).data('sub-service-request-id')
$.ajax
type: 'PUT'
url: "/dashboard/sub_service_requests/#{ssr_id}/resend_surveys"
success: ->

# SERVICE REQUEST INFO LISTENERS END
# ADMIN TAB LISTENER BEGIN
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/dashboard/sub_service_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ def push_to_epic
end
end

def resend_surveys
if @sub_service_request.surveys_completed?
@refresh = true # Refresh the details options
flash[:alert] = 'All surveys have already been completed.'
else
@sub_service_request.distribute_surveys
flash[:success] = 'Surveys re-sent!'
end
end

#History Table Methods Begin
def change_history_tab
#Replaces currently displayed ssr history bootstrap table
Expand Down
17 changes: 12 additions & 5 deletions app/mailers/survey_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ def system_satisfaction_survey(response)
end

def service_survey(surveys, identity, ssr)
@identity = identity
@surveys = surveys
@ssr = ssr
email = @identity.email
subject = t('surveyor.responses.emails.service_survey.subject', site_name: t(:proper)[:header], ssr_id: @ssr.display_id)
@identity = identity
@ssr = ssr
@surveys = surveys
@responses = []
email = @identity.email
subject = t('surveyor.responses.emails.service_survey.subject', site_name: t(:proper)[:header], ssr_id: @ssr.display_id)

surveys.each do |survey|
response = survey.responses.where(identity: identity, sub_service_request: ssr).first || survey.responses.create(identity: identity, sub_service_request: ssr)

@responses << response unless response.completed?
end

mail(to: email, from: NO_REPLY_FROM, subject: subject)
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/sub_service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SubServiceRequest < ApplicationRecord
has_many :reports, :dependent => :destroy
has_many :notifications, :dependent => :destroy
has_many :subsidies
has_many :responses
has_one :approved_subsidy, :dependent => :destroy
has_one :pending_subsidy, :dependent => :destroy

Expand Down Expand Up @@ -420,6 +421,10 @@ def distribute_surveys
end
end

def surveys_completed?
self.responses.all?(&:completed?)
end

###############################
### AUDIT REPORTING METHODS ###
###############################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
= t(:dashboard)[:sub_service_requests][:tabs][:request_details][:options][:core_approvals]
%td.text-center
= link_to t(:dashboard)[:sub_service_requests][:tabs][:request_details][:options][:export_to_excel], service_request_path(service_request, format: :xlsx, admin_offset: 1, sub_service_request_id: sub_service_request.id), :class => "export_to_excel_button btn btn-sm btn-primary"
- if sub_service_request.is_complete? && !sub_service_request.surveys_completed?
%td.text-center
%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]
%td.text-center
%button.btn.btn-sm.btn-danger#delete_ssr_button{ data: { sub_service_request_id: sub_service_request.id }}
%span
Expand Down
25 changes: 25 additions & 0 deletions app/views/dashboard/sub_service_requests/resend_surveys.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright © 2011-2017 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("<%= escape_javascript(render( 'shared/flash' )) %>")
$('#resend-surveys-button').prop('disabled', false)

<% if @refresh %>
$("#details").html("<%= j render 'dashboard/sub_service_requests/request_details', protocol: @sub_service_request.protocol, service_request: @sub_service_request.service_request, sub_service_request: @sub_service_request %>")
<% end %>
1 change: 1 addition & 0 deletions app/views/dashboard/sub_service_requests/update.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<% unless @errors %>
$("#sub_service_request_header").html("<%= escape_javascript(render(partial: 'dashboard/sub_service_requests/header', locals: { sub_service_request: @sub_service_request })) %>");
$("#subsidy_information").html("<%= escape_javascript(render(partial: 'dashboard/subsidies/subsidy', locals: { sub_service_request: @sub_service_request, admin: true })) %>");
$("#details").html("<%= j render 'dashboard/sub_service_requests/request_details', protocol: @sub_service_request.protocol, service_request: @sub_service_request.service_request, sub_service_request: @sub_service_request %>")

$("#status-history-table").bootstrapTable 'refresh'

Expand Down
6 changes: 3 additions & 3 deletions app/views/survey_notification/service_survey.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
%br

%ul
- @surveys.each do |survey|
- @responses.each do |response|
%li
= link_to survey.title, url_for(controller: '/surveyor/responses', action: :edit, only_path: false, id: Response.create(survey: survey, identity: @identity, sub_service_request: @ssr).id, format: :html), target: '_blank'
= link_to response.survey.title, url_for(controller: '/surveyor/responses', action: :edit, only_path: false, id: response.id, format: :html), target: '_blank'

- if @surveys.map(&:access_code).include?("sctr-customer-satisfaction-survey")
- if @surveys.pluck(:access_code).include?("sctr-customer-satisfaction-survey")
#sctr-grant-citation
%br
= t(:surveyor)[:responses][:emails][:sctr_customer_satisfaction][:grant_reminder]
Expand Down
1 change: 1 addition & 0 deletions config/locales/dashboard.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ en:
send_to_epic: "Send to Epic"
core_approvals: "Administrative Approvals"
export_to_excel: "Export to Excel"
resend_surveys: "Resend Surveys"
delete_request: "Delete Request"
timeline:
header: "Timeline"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
resources :sub_service_requests, except: [:new, :create, :edit]do
member do
put :push_to_epic
put :resend_surveys
get :change_history_tab
get :status_history
get :approval_history
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright © 2011-2017 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.

require 'rails_helper'

RSpec.describe Dashboard::SubServiceRequestsController do

describe '#resend_surveys' do
before :each do
logged_in_user = build_stubbed(:identity)
log_in_dashboard_identity(obj: logged_in_user)

org = build_stubbed(:organization)

allow(logged_in_user).to receive(:authorized_admin_organizations).and_return([org])

@ssr = findable_stub(SubServiceRequest) do
build_stubbed(:sub_service_request, organization: org)
end

allow(@ssr).to receive(:distribute_surveys).and_return(true)
end

context 'surveys have already been completed' do
before :each do
allow(@ssr).to receive(:surveys_completed?).and_return(true)

put :resend_surveys, params: { id: @ssr.id, format: :js }, xhr: true
end

it 'should assign @refresh' do
expect(assigns(:refresh)).to eq(true)
end
end

context 'surveys are pending' do
before :each do
allow(@ssr).to receive(:surveys_completed?).and_return(false)

put :resend_surveys, params: { id: @ssr.id, format: :js }, xhr: true
end

it 'should distribute surveys' do
expect(@ssr).to have_received(:distribute_surveys)
end
end

it 'should render template' do
put :resend_surveys, params: { id: @ssr.id, format: :js }, xhr: true

expect(controller).to render_template(:resend_surveys)
end

it 'should respond ok' do
put :resend_surveys, params: { id: @ssr.id, format: :js }, xhr: true

expect(controller).to respond_with(:ok)
end
end
end