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 - Add Dropdown Search Functionality #1772

Merged
merged 6 commits into from
Apr 3, 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
19 changes: 0 additions & 19 deletions app/models/survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,6 @@ class Survey < ApplicationRecord
'Multiple Dropdown': 'multiple_dropdown'
}

def self.for_dropdown_select(filtered_states=nil, filtered_surveys=nil)
self.all.order(:title).group_by(&:title).map do |title, surveys|
[
title,
surveys.map do |survey|
[
"Version #{survey.version} (#{survey.active ? I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:active] : I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:inactive]})",
survey.id,
{
disabled: filtered_states && filtered_states.length > 1 && !filtered_states.include?(survey.active ? 1 : 0),
selected: filtered_surveys && filtered_surveys.include?(survey.id),
data: { active: survey.active ? '1' : '0' }
}
]
end
]
end
end

# Added because version could not be written as an attribute by FactoryBot. Possible keyword issue?
def version=(v)
write_attribute(:version, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
.form-group.row
= form.label :with_status, t(:dashboard)[:protocol_filters][:status], class: 'col-lg-3 control-label'
.col-lg-9
= form.select :with_status, filterrific.select_options[:with_status], {}, class: "form-control selectpicker status-select", multiple: true, data: { none_selected_text: t(:constants)[:prompts][:any] }
= form.select :with_status, filterrific.select_options[:with_status], {}, class: "form-control selectpicker status-select", multiple: true, data: { none_selected_text: t(:constants)[:prompts][:any], live_search: true }

.form-group.row
= form.label :with_organization, t(:dashboard)[:protocol_filters][:organization], class: 'col-lg-3 control-label'
.col-lg-9.drop-underneath
= form.select :with_organization, nil, {}, class: "form-control selectpicker core-select", multiple: true, data: { none_selected_text: t(:constants)[:prompts][:any] } do
= form.select :with_organization, nil, {}, class: "form-control selectpicker core-select", multiple: true, data: { none_selected_text: t(:constants)[:prompts][:any], live_search: true } do
= filterrific.select_options[:with_organization].each do |org_type, orgs|
%optgroup{ label: org_type }
- orgs.each do |name, id|
Expand All @@ -68,7 +68,7 @@
.form-group.row
= form.label :with_owner, t(:dashboard)[:protocol_filters][:owner], class: 'col-lg-3 control-label'
.col-lg-9
= form.select :with_owner, filterrific.select_options[:with_owner], {}, class: "form-control selectpicker owner-select", multiple: true, data: { none_selected_text: t(:constants)[:prompts][:any] }
= form.select :with_owner, filterrific.select_options[:with_owner], {}, class: "form-control selectpicker owner-select", multiple: true, data: { none_selected_text: t(:constants)[:prompts][:any], live_search: true }
.form-group.row.identity-protocols
= form.label :admin_filter, t(:dashboard)[:protocol_filters][:my_protocols], class: 'col-lg-10 control-label'
.col-lg-2
Expand Down
4 changes: 2 additions & 2 deletions app/views/surveyor/responses/_filter_responses_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
.form-group.row{ id: "for-#{Form.name}", class: filterrific.of_type == Form.name ? "" : "hidden" }
= form.label :with_survey, Form.name, class: 'col-lg-3 control-label text-left'
.col-lg-9
= form.select :with_survey, grouped_options_for_select(Form.for(current_user).for_dropdown_select(filterrific.with_state, filterrific.with_survey)), {}, class: 'form-control selectpicker survey-select', multiple: true, data: { hide_disabled: 'true' }
= render 'surveyor/responses/surveys_dropdown', surveys: Form.for(current_user), filterrific: filterrific, form: form
.form-group.row{ id: "for-#{SystemSurvey.name}", class: filterrific.of_type == SystemSurvey.name ? "" : "hidden" }
= form.label :with_survey, Survey.name, class: 'col-lg-3 control-label text-left'
.col-lg-9
= form.select :with_survey, grouped_options_for_select(SystemSurvey.unscoped.for_dropdown_select(filterrific.with_state, filterrific.with_survey)), {}, class: 'form-control selectpicker survey-select', multiple: true, data: { hide_disabled: 'true' }
= render 'surveyor/responses/surveys_dropdown', surveys: SystemSurvey.unscoped, filterrific: filterrific, form: form
.form-group.row
.col-sm-12
%label
Expand Down
26 changes: 26 additions & 0 deletions app/views/surveyor/responses/_surveys_dropdown.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-# 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.

= hidden_field_tag "filterrific[with_survey][]"
%select.form-control.selectpicker.survey-select{ id: 'filterrific_with_survey', name: 'filterrific[with_survey][]', multiple: true, data: { hide_disabled: 'true', live_search: 'true' } }
- surveys.order(:title).group_by(&:title).each do |title, surveys|
%optgroup{ label: title }
- surveys.each do |survey|
%option{ value: survey.id, disabled: filterrific.with_state && filterrific.with_state.length > 1 && !filterrific.with_state.include?(survey.active ? 1 : 0), selected: filterrific.with_survey && filterrific.with_survey.include?(survey.id), data: { active: survey.active ? '1' : '0', content: "<span class='hidden'>#{survey.title}</span><span>Version #{survey.version} (#{I18n.t(:surveyor)[:response_filters][:fields][:state_filters][survey.active ? :active : :inactive]})</span>" } }
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

scenario 'and sees responses for those Surveys' do
find('#for-SystemSurvey select#filterrific_with_survey + .btn-group').click
first('.dropdown-menu.open span.text', text: "Version #{@survey.version} (#{@survey.active ? I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:active] : I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:inactive]})").click
first('.dropdown-menu.open span', text: "Version #{@survey.version} (#{@survey.active ? I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:active] : I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:inactive]})").click
find('body').click
click_button I18n.t(:actions)[:filter]
wait_for_javascript_to_finish
Expand All @@ -147,7 +147,7 @@
scenario 'and sees responses for those Forms' do
bootstrap_select '#filterrific_of_type', 'Form'
find('#for-Form select#filterrific_with_survey + .btn-group').click
first('.dropdown-menu.open span.text', text: "Version #{@form.version} (#{@form.active ? I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:active] : I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:inactive]})").click
first('.dropdown-menu.open span', text: "Version #{@form.version} (#{@form.active ? I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:active] : I18n.t(:surveyor)[:response_filters][:fields][:state_filters][:inactive]})").click
find('body').click
click_button I18n.t(:actions)[:filter]
wait_for_javascript_to_finish
Expand Down
3 changes: 2 additions & 1 deletion spec/features/surveyor/responses/user_saves_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
find('#filterrific_start_date').click
find('#filter-responses .panel-title').click
find('#filterrific_include_incomplete').click
click_link I18n.t(:actions)[:save]

find('#save-filters').click
wait_for_javascript_to_finish

fill_in 'response_filter_name', with: 'My Filters'
Expand Down