Skip to content

Commit

Permalink
pull request sparc-request#657 dashboard sorting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ying-pbrc committed Sep 19, 2016
1 parent 6939742 commit 1215775
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/dashboard/protocols.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ $(document).ready ->
show_archived = $('#show_archived').val()
with_status = $('#with_status').val()
with_organization = $('#with_organization').val()
with_owner = $('#with_owner').val()
admin_filter = $('#admin_filter').val()
sorted_by = "#{$(this).data('sort-name')} #{$(this).data('sort-order')}"
page = $('#page').val() || 1
Expand All @@ -170,6 +171,7 @@ $(document).ready ->
'show_archived': show_archived
'with_status': with_status
'with_organization': with_organization
'with_owner': with_owner
'admin_filter': admin_filter
'sorted_by': sorted_by
$.ajax
Expand Down
27 changes: 15 additions & 12 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,28 @@ class Protocol < ActiveRecord::Base
where(archived: boolean)
}

scope :with_status, -> (status) {
# returns protocols with ssrs in status
return nil if status.reject!(&:blank?) == []
scope :with_status, -> (statuses) {
# returns protocols with ssrs in statuses
statuses = statuses.split.flatten.reject(&:blank?)
return nil if statuses.empty?
joins(:sub_service_requests).
where(sub_service_requests: { status: status }).distinct
where(sub_service_requests: { status: statuses }).distinct
}

scope :with_organization, -> (org_id) {
# returns protocols with ssrs in org_id
return nil if org_id.reject!(&:blank?) == []
scope :with_organization, -> (org_ids) {
# returns protocols with ssrs in org_ids
org_ids = org_ids.split.flatten.reject(&:blank?)
return nil if org_ids.empty?
joins(:sub_service_requests).
where(sub_service_requests: { organization_id: org_id }).distinct
where(sub_service_requests: { organization_id: org_ids }).distinct
}

scope :with_owner, -> (owner_id) {
return nil if owner_id.reject!(&:blank?) == []
scope :with_owner, -> (owner_ids) {
owner_ids = owner_ids.split.flatten.reject(&:blank?)
return nil if owner_ids.empty?
joins(:sub_service_requests).
where(sub_service_requests: {owner_id: owner_id}).
where.not(sub_service_requests: {status: 'first_draft'})
where(sub_service_requests: {owner_id: owner_ids}).
where.not(sub_service_requests: {status: 'first_draft'})
}

scope :sorted_by, -> (key) {
Expand Down
1 change: 1 addition & 0 deletions app/views/dashboard/protocols/_protocols_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
= hidden_field_tag :show_archived, filterrific_params[:show_archived]
= hidden_field_tag :with_status, filterrific_params[:with_status]
= hidden_field_tag :with_organization, filterrific_params[:with_organization]
= hidden_field_tag :with_owner, filterrific_params[:with_owner]
= hidden_field_tag :admin_filter, filterrific_params[:admin_filter]
= hidden_field_tag :page, page
.panel.panel-primary
Expand Down
2 changes: 2 additions & 0 deletions app/views/notifier/_notification_email.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
= render "welcome"
- if @status == 'submitted'
= render "welcome_for_submitted_status"
%br
%br
= render "protocol_information", protocol: @protocol
- if @service_request.has_per_patient_per_visit_services? and @service_request.arms.count > 0
= render "arm_information"
Expand Down

0 comments on commit 1215775

Please sign in to comment.