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

Sj empty protocol admin view #124

Merged
merged 2 commits into from Mar 2, 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
6 changes: 5 additions & 1 deletion app/controllers/dashboard/base_controller.rb
Expand Up @@ -75,6 +75,10 @@ def establish_breadcrumber
end

def find_admin_for_protocol
@admin = Protocol.for_admin(@user).include?(@protocol)
if @user.super_users.any? && @protocol.sub_service_requests.empty?
@admin = true
else
@admin = Protocol.for_admin(@user).include?(@protocol)
end
end
end
32 changes: 20 additions & 12 deletions app/models/protocol.rb
Expand Up @@ -200,7 +200,7 @@ def unique_rm_id_to_protocol

#TODO temporary replacement for "MATCH(identities.first_name, identities.last_name) AGAINST (#{exact_search_term})"
case search_attrs[:search_drop]

when "PI"
joins(:principal_investigators).
where("CONCAT(identities.first_name, ' ', identities.last_name) LIKE #{like_search_term} escape '!'").
Expand Down Expand Up @@ -228,30 +228,38 @@ def unique_rm_id_to_protocol

}

scope :for_identity_id, -> (identity_id) {
return nil if identity_id == '0'
joins(:project_roles).
where(project_roles: { identity_id: identity_id }).
where.not(project_roles: { project_rights: 'none' })
}

scope :admin_filter, -> (params) {
filter, id = params.split(" ")
if filter == 'for_admin'
for_admin(id)
elsif filter == 'for_identity'
for_identity_id(id)
elsif filter == 'empty_protocols'
empty_protocols(id)
end
}

scope :for_admin, -> (identity_id) {
# returns protocols with ssrs in orgs authorized for identity_id
return nil if identity_id == '0'

ssrs = SubServiceRequest.where.not(status: 'first_draft').where(organization_id: Organization.authorized_for_identity(identity_id))
joins(:sub_service_requests).merge(ssrs).distinct
}

joins(:sub_service_requests).
merge(ssrs).distinct
scope :for_identity_id, -> (identity_id) {
# returns protocols user has a project role for
return nil if identity_id == '0'
joins(:project_roles).where(project_roles: { identity_id: identity_id }).where.not(project_roles: { project_rights: 'none' })
}

scope :empty_protocols, -> (identity_id) {
# returns protocols with no ssrs if you are a super user of any kind
return nil if identity_id == '0'
if Identity.find(identity_id).super_users.any?
includes(:sub_service_requests).where(sub_service_requests: {id: nil})
else
return nil
end
}

scope :show_archived, -> (boolean) {
Expand Down Expand Up @@ -288,7 +296,7 @@ def unique_rm_id_to_protocol
sort_order = arr[1]
case sort_name
when 'id'
order("id #{sort_order.upcase}")
order("protocols.id #{sort_order.upcase}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this might conflict with #125 @Stuart-Johnson @jwiel86

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kyle-glick @jwiel86 Yeah, It does I think. I had to change this because just 'id' was causing an ambiguity error if the initial query had any eager loading. I'm not sure, but it looks like Hanna's pull request also addresses this with the 'protocols.id'. I think the best thing would be to merge hers in first, then I'll address conflicts with mine, and make sure it still works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kyle-glick @jwiel86 After investigation, looks like this shouldn't actually conflict with Hanna's stuff. Should be fine.

when 'short_title'
order("TRIM(REPLACE(short_title, CHAR(9), ' ')) #{sort_order.upcase}")
when 'pis'
Expand Down
Expand Up @@ -39,7 +39,7 @@
= form.fields_for :search_query do |search|
.input-group-btn
.dd_select
= search.select :search_drop, t(:dashboard)[:protocol_filters][:search_by_options], { prompt: t(:dashboard)[:protocol_filters][:search_by] }, class: "form-control selectpicker ", data: { style: 'dropdown_filter' }
= search.select :search_drop, t(:dashboard)[:protocol_filters][:search_by_options], { prompt: t(:dashboard)[:protocol_filters][:search_by] }, class: "form-control selectpicker ", data: { style: 'dropdown_filter' }
= search.text_field :search_text, class: 'form-control', disabled: true

.form-group.row
Expand Down Expand Up @@ -76,6 +76,12 @@
.col-lg-2
= form.radio_button :admin_filter, "for_admin #{current_user.id}"

- if current_user.super_users.any?
.form-group.row.empty-protocols
= form.label :admin_filter, t(:dashboard)[:protocol_filters][:empty_protocols], class: 'col-lg-10 control-label'
.col-lg-2
= form.radio_button :admin_filter, "empty_protocols #{current_user.id}"

.panel-footer
.pull-right
%button.btn.btn-default#apply-filter-button{type: "submit"}
Expand Down
1 change: 1 addition & 0 deletions config/locales/dashboard.en.yml
Expand Up @@ -166,6 +166,7 @@ en:
owner: "Owner"
my_protocols: "My Protocols"
my_admin_protocols: "My Admin Protocols"
empty_protocols: "Empty Protocols (No Services)"
filter: "Filter"
saved_filters:
header: "Recently Saved Filters"
Expand Down
3 changes: 2 additions & 1 deletion spec/support/pages/dashboard/protocols/index_page.rb
Expand Up @@ -38,12 +38,13 @@ class IndexPage < SitePrism::Page
elements :status_options, "div.status-select li"
element :core_select, "div.core-select button"
elements :core_options, "div.core-select li"

# these appear if user is an admin
element :owner_select, "div.owner-select button"
elements :owner_options, "div.owner-select li"
element :my_protocols_checkbox, ".identity-protocols input"
element :my_admin_organizations_checkbox, ".admin-protocols input"
element :empty_protocols_checkbox, ".empty-protocols input"

element :apply_filter_button, :button, "Filter"

Expand Down