Skip to content

Commit

Permalink
filter more facets results in a modal per page
Browse files Browse the repository at this point in the history
  • Loading branch information
christinach committed Jul 30, 2019
1 parent f9ccafd commit 1b63754
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/assets/javascripts/geoblacklight/modules/modal-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Filter specific value in a facet modal

function filterList() {
var input = document.getElementById('filterInput');
var filter = input.value.toUpperCase();
var ul = document.querySelectorAll('div.modal-body div.facet-extended-list .facet-values')[0];
var li = ul.getElementsByTagName('li');
// Loop through all list items, and hide those who don't match the search query
for (var i = 0; i < li.length; i++) {
var a = li[i].getElementsByTagName("a")[0];
var txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}

$(document).on('keyup', '#filterInput', function(e) { filterList() });
29 changes: 29 additions & 0 deletions app/views/catalog/facet.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="facet-pagination top">
<%= render :partial=>'facet_pagination' %>
</div>

<div class="modal-header">
<h1 class="modal-title"><%= facet_field_label(@facet.key) %></h1>
<button type="button" class="blacklight-modal-close close" data-dismiss="modal" aria-label="<%= t('blacklight.modal.close') %>">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body">
<%= render partial: 'facet_index_navigation' if @facet.index_range && @display_facet.index? %>

<div class="facet-extended-list">
<%= render_facet_limit(@display_facet, layout: false) %>
</div>
</div>

<div class="modal-footer">
<div class="row">
<div class="col col-sm-4">
<input type="text" id="filterInput" placeholder="Filter..." class="form-control form-control-sm" />
</div>
<div class="facet-pagination bottom">
<%= render :partial=>'facet_pagination' %>
</div>
</div>
</div>
15 changes: 15 additions & 0 deletions spec/features/more_facets_filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

RSpec.feature 'More facets modal', js: true do
before do
visit '/catalog/facet/dct_provenance_s?q=&search_field=all_fields'
end

it 'filters a value in the more facet modal' do
ul_count = page.all('ul .facet-label').count
filter = find_field(id: 'filterInput')
filter.fill_in(with: 'co')
ul_filtered = page.all('ul .facet-label')
expect(ul_filtered.count).to be < ul_count
end
end

0 comments on commit 1b63754

Please sign in to comment.