Skip to content

Commit

Permalink
Merge pull request #1267 from sparc-request/kg-responses_table
Browse files Browse the repository at this point in the history
KG - Simple Responses Table (SPARCForms)
  • Loading branch information
Stuart-Johnson committed Mar 8, 2018
2 parents a8b3c69 + 7bc25af commit 3c854bc
Show file tree
Hide file tree
Showing 38 changed files with 703 additions and 73 deletions.
21 changes: 12 additions & 9 deletions app/assets/javascripts/bootstrap-table-custom.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ getOrder = ->
if $table.bootstrapTable('getOptions').sortOrder == 'asc' then -1 else 1

(exports ? this).dateSorter = (a, b) ->
return -1 * getOrder() if !a
return 1 * getOrder() if !b

sort_a = new Date(a)
sort_b = new Date(b)

return 1 if sort_a > sort_b
return -1 if sort_a < sort_b
return 0
if !a && !b
return 0
else if a && !b
return 1
else if !a && b
return -1
else
sort_a = new Date(a)
sort_b = new Date(b)
return 1 if sort_a > sort_b
return -1 if sort_a < sort_b
return 0
2 changes: 1 addition & 1 deletion app/assets/javascripts/forms.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# 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.
$ ->
$(document).on 'click', '.delete-form-response', (event) ->
$(document).on 'click', '.delete-response', (event) ->
event.preventDefault()

form_id = $(this).data('response-id')
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/surveyor/responses.js.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2011-2018 MUSC Foundation for Research Development~
# Copyright © 2011-2018 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:~
Expand Down
27 changes: 27 additions & 0 deletions app/assets/stylesheets/surveyor/responses.sass
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// 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.
@import 'proper/colors'

#survey-response
.modal-title,
.panel-title,
Expand Down Expand Up @@ -63,3 +65,28 @@
.likert-option:last-child
.likert:before
width: 50%

#responses-panel
.fixed-table-toolbar
display: inline-table
width: 100%
padding: 10px 15px
background: $sparc-blue

.bars.pull-left
width: 73%

#responses-custom-toolbar
width: 100%

.panel-title
color: white

.fixed-table-container
border-radius: 0

.fixed-table-pagination
padding: 0 20px

td.short-title, td.primary-pi, td.title
word-break: break-all
4 changes: 2 additions & 2 deletions app/controllers/surveyor/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def current_user
def authorize_survey_builder_access
# If SystemSurvey-specific actions, verify the user is a Site Admin
if params[:type] && params[:type] == 'SystemSurvey'
unless Setting.find_by_key("site_admins").value.include?(current_user.ldap_uid)
unless current_user.is_site_admin?
raise ActionController::RoutingError.new('Not Found')
end
# If Form-specific actions, verify the user is a Super User, Service Provider, or Overlord
Expand All @@ -46,7 +46,7 @@ def authorize_survey_builder_access
end
# If non-specific actions, verify the user is a Site Admin, Super User, Service Provider, or Overlord
else
unless Setting.find_by_key("site_admins").value.include?(current_user.ldap_uid) || current_user.is_super_user? || current_user.is_service_provider? || current_user.is_overlord?
unless current_user.is_site_admin? || current_user.is_super_user? || current_user.is_service_provider? || current_user.is_overlord?
raise ActionController::RoutingError.new('Not Found')
end
end
Expand Down
49 changes: 47 additions & 2 deletions app/controllers/surveyor/responses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,38 @@ class Surveyor::ResponsesController < Surveyor::BaseController
before_action :authenticate_identity!
before_action :find_response, only: [:show, :edit, :update]

def set_highlighted_link
@highlighted_link ||= 'sparc_forms'
end

def index
@filterrific =
initialize_filterrific(Response, params[:filterrific],
select_options: {
with_type: [['Form', 'Form'], ['Survey', 'SystemSurvey']]
}
)

@type = @filterrific.with_type.constantize.yaml_klass
@responses = @filterrific.find.eager_load(:survey, :question_responses)

respond_to do |format|
format.html
format.js
format.json {
preload_responses
}
# format.xlsx
end
end

def show
@survey = @response.survey

respond_to do |format|
format.html
format.js
format.xlsx
end
end

Expand Down Expand Up @@ -61,7 +87,10 @@ def edit
end

def create
@response = Response.new(response_params)
@response = Response.new(response_params)
@protocol = @response.respondable.try(:protocol)
@protocol_role = @protocol.project_roles.find_by(identity_id: current_user.id) if @protocol
@permission_to_edit = @protocol_role.nil? ? false : @protocol_role.can_edit? if @protocol

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'
Expand All @@ -84,8 +113,13 @@ def update
end

def destroy
(@response = Response.find(params[:id])).destroy
@response = Response.find(params[:id])
@protocol = @response.respondable.try(:protocol)
@protocol_role = @protocol.project_roles.find_by(identity_id: current_user.id) if @protocol
@permission_to_edit = @protocol_role.nil? ? false : @protocol_role.can_edit? if @protocol

@response.destroy

respond_to do |format|
format.js
end
Expand All @@ -100,7 +134,18 @@ def find_response
@response = Response.find(params[:id])
end

def filterrific_params
params.require(:filterrific).permit(
:with_type
)
end

def response_params
params.require(:response).permit!
end

def preload_responses
preloader = ActiveRecord::Associations::Preloader.new
preloader.preload(@responses.select { |r| r.respondable_type == SubServiceRequest.name }, { respondable: { protocol: { primary_pi_role: :identity } } })
end
end
42 changes: 7 additions & 35 deletions app/helpers/forms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# 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.

module FormsHelper
def form_completed_display(form, completed)
def form_completed_display(completed)
klass = completed ? 'glyphicon glyphicon-ok text-success' : 'glyphicon glyphicon-remove text-danger'

content_tag(:h4, content_tag(:span, '', class: klass))
Expand All @@ -28,47 +28,19 @@ def form_completed_display(form, completed)
def form_options(form, completed, respondable, review)
if review
response = Response.where(survey: form, respondable: respondable).first
response ? view_form_response_button(form, response) : link_to(t(:actions)[:view], 'javascript:void(0)', class: 'btn btn-info disabled')
response ? view_response_button(response) : link_to(t(:actions)[:view], 'javascript:void(0)', class: 'btn btn-info disabled')
elsif completed
response = Response.where(survey: form, respondable: respondable).first
[ view_form_response_button(form, response),
edit_form_response_button(form, response),
delete_form_response_button(form, response)
[ view_response_button(response),
edit_response_button(response),
delete_response_button(response)
].join('')
else
complete_form_response_button(form, respondable)
complete_form_button(form, respondable)
end
end

def view_form_response_button(form, response)
link_to(
t(:actions)[:view],
surveyor_response_path(response),
remote: true,
class: 'btn btn-info view-form-response'
)
end

def edit_form_response_button(form, response)
link_to(
content_tag(:span, '', class: 'glyphicon glyphicon-edit', aria: { hidden: 'true' }),
edit_surveyor_response_path(response),
remote: true,
class: 'btn btn-warning edit-form-response'
)
end

def delete_form_response_button(form, response)
content_tag(:button,
raw(
content_tag(:span, '', class: 'glyphicon glyphicon-remove', aria: { hidden: 'true' })
),
data: { response_id: response.id },
class: 'btn btn-danger delete-form-response'
)
end

def complete_form_response_button(form, respondable)
def complete_form_button(form, respondable)
link_to(
'Complete',
new_surveyor_response_path(type: form.class.name, survey_id: form.id, respondable_id: respondable.id, respondable_type: respondable.class.name),
Expand Down
48 changes: 48 additions & 0 deletions app/helpers/surveyor/responses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,54 @@
# 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.

module Surveyor::ResponsesHelper

def complete_display(response)
klass = response.completed? ? 'glyphicon glyphicon-ok text-success' : 'glyphicon glyphicon-remove text-danger'

content_tag(:h4, content_tag(:span, '', class: klass))
end

def response_options(response)
[ view_response_button(response),
edit_response_button(response)#,
# download_response_button(response)
].join('')
end

def view_response_button(response)
link_to(
content_tag(:span, '', class: 'glyphicon glyphicon-search', aria: { hidden: 'true' }),
surveyor_response_path(response),
remote: true,
class: ['btn btn-info view-response', response.completed? ? '' : 'disabled']
)
end

def edit_response_button(response)
link_to(
content_tag(:span, '', class: 'glyphicon glyphicon-edit', aria: { hidden: 'true' }),
edit_surveyor_response_path(response),
remote: true,
class: ['btn btn-warning edit-response', response.completed? ? '' : 'disabled']
)
end

def delete_response_button(response)
content_tag(:button,
content_tag(:span, '', class: 'glyphicon glyphicon-remove', aria: { hidden: 'true' }),
data: { response_id: response.id },
class: 'btn btn-danger delete-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'
)
end

def dependency_classes(question)
if question.is_dependent?
["dependent-for-option-#{question.depender_id}",
Expand Down
4 changes: 4 additions & 0 deletions app/models/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def professional_org_lookup(org_type)
############################ ATTRIBUTE METHODS ################################
###############################################################################

def is_site_admin?
Setting.find_by_key("site_admins").value.include?(self.ldap_uid)
end

# Returns true if the user is a catalog overlord. Should only be true for three uids:
# lmf5, anc63, mas244
def is_overlord?
Expand Down
8 changes: 2 additions & 6 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,7 @@ def validate_proxy_rights
end

def primary_principal_investigator
primary_pi_project_role.try(:identity)
end

def primary_pi_project_role
project_roles.find_by(role: 'primary-pi')
primary_pi_role.try(:identity)
end

def billing_business_manager_email
Expand Down Expand Up @@ -462,7 +458,7 @@ def awaiting_final_review_for_epic_push
end

def ensure_epic_user
primary_pi_project_role.set_epic_rights.save
primary_pi_role.set_epic_rights.save
project_roles.reload
end

Expand Down
11 changes: 11 additions & 0 deletions app/models/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class Response < ActiveRecord::Base

accepts_nested_attributes_for :question_responses

filterrific(
default_filter_params: { with_type: 'Form' },
available_filters: [
:with_type
]
)

scope :with_type, -> (params) {
joins(:survey).where(surveys: { type: params })
}

def completed?
self.question_responses.any?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
.panel-footer
.pull-right
%button.btn.btn-default#apply-filter-button{type: "submit"}
= t(:dashboard)[:protocol_filters][:filter]
= t(:actions)[:filter]
.clearfix


Expand Down
2 changes: 1 addition & 1 deletion app/views/forms/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ json.(@forms) do |form, respondable|
json.srid respondable.try(&:display_id)
json.association form.surveyable.try(:organization_hierarchy, true, false, true)
json.title form.title
json.completed form_completed_display(form, completed)
json.completed form_completed_display(completed)
json.options form_options(form, completed, respondable, @review)
end

0 comments on commit 3c854bc

Please sign in to comment.