Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
[#1386] make filters update on change
Browse files Browse the repository at this point in the history
  • Loading branch information
jnguyenx committed Feb 24, 2017
1 parent c37cfac commit 7ba45f1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 33 deletions.
11 changes: 9 additions & 2 deletions js/search_results.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $( document ).ready(function() {
}
}

// TODO change that to a POST request (Jeremy)
// Convert object to JSON string
// E.g. {"category": ["gene"], "taxon_label": ["Danio rerio"]}
// Must use "/" at the beginning of the URL
Expand All @@ -62,13 +63,19 @@ $( document ).ready(function() {

if (typeof(data) !== 'undefined') {
// update the table with this new table content
$('.search-results-rows').html(data.table);
$('#search-results-rows').html(data.table);

// update the category filter
$('#category-filter').html(data.categoryFilter);

// update the species filter
$('#species-filter').html(data.speciesFilter);

// Update the total count number
$('#totalCount').html(data.count);

if (data.loadMoreBtn === false) {
// Hide the load mroe button
// Hide the load more button
$('#more').hide();
} else {
$('#more').show();
Expand Down
6 changes: 6 additions & 0 deletions lib/monarch/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2853,9 +2853,15 @@ bbop.monarch.Engine.prototype.search = function(term, filters, facets, rows, sta
if(facets != null && facets != undefined) {
searchGolrManager.facets(facets);
}
// TODO/BUG facet.mincount cannot be set through the golr manager. It needs to be added to the API.
searchGolrManager.query_variants['facet.mincount'] = 0;
searchGolrManager.query_variants['facet.sort'] = 'index';

var r = searchGolrManager.page(rows, start);

// debug
//console.log(searchGolrManager.get_query_url());

// TODO DELETE THIS WHEN #1387 is done
var postfixes = ["_eng", "_kw", "_std"];
var zipped = _.zip(r._raw.response.docs, _.values(r._raw.highlighting));
Expand Down
85 changes: 58 additions & 27 deletions lib/monarch/web/webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,58 @@ function searchFilteringHandler(request, term, filters, pageNum) {
if (endRow > count) {
endRow = count;
}

// Combination filters

// No sorting, just use the default order
var categories = golrResults.facet_counts.facet_fields.category;

// Sorting: human, mouse, zebrafish, fly, worm, and then everything else by data richness
var taxa = golrResults.facet_counts.facet_fields.taxon_label;

var categoryMap = bgr.query_filters().category;
if (categoryMap != null) {
var selectedCategories = Object.keys(categoryMap);
} else {
var selectedCategories = [];
}

// Category filter
resultsCategoryFilter = '<ul class="search-results-button-group" data-filter-group="category">'
+ '<li class="search-results-button" data-filter="">Select all</li>';
for (var k = 0; k < categories.length; k++) {
if(selectedCategories.indexOf(categories[k][0]) >= 0) {
resultsCategoryFilter += '<li class="search-results-button is-checked" data-filter="' + categories[k][0] + '">' + categories[k][0] + ' (' + categories[k][1] + ')</li>';
} else {
resultsCategoryFilter += '<li class="search-results-button" data-filter="' + categories[k][0] + '">' + categories[k][0] + ' (' + categories[k][1] + ')</li>';
}
}
resultsCategoryFilter += '</ul>';

// Species filter

// If possible that some results don't have taxon specified
// we are not handling that since it's a data issue - Zhou
resultsSpeciesFilter = '<ul class="search-results-button-group" data-filter-group="taxon_label">'
+ '<li class="search-results-button" data-filter="">Select all</li>';

var speciesMap = bgr.query_filters().taxon_label;
if (speciesMap != null) {
var selectedSpecies = Object.keys(speciesMap);
} else {
var selectedSpecies = [];
}

for (var j = 0; j < taxa.length; j++) {
if(selectedSpecies.indexOf(taxa[j][0]) >= 0) {
resultsSpeciesFilter += '<li class="search-results-button is-checked" data-filter="' + taxa[j][0] + '">' + taxa[j][0] + ' (' + taxa[j][1] + ')</li>';
} else {
resultsSpeciesFilter += '<li class="search-results-button" data-filter="' + taxa[j][0] + '">' + taxa[j][0] + ' (' + taxa[j][1] + ')</li>';
}
}

resultsSpeciesFilter += '</ul>';

// Create the new output format - Zhou
resultsOutput = '<table class="search-results-table table table-striped table-condensed simpletable">'
+ '<caption> showing ' + startRow + ' - ' + endRow + ' of ' + count + ' results for "' + term + '"</caption>'
Expand Down Expand Up @@ -1191,6 +1243,8 @@ function searchFilteringHandler(request, term, filters, pageNum) {
obj.count = count;
obj.table = resultsOutput;
obj.loadMoreBtn = loadMoreBtn;
obj.categoryFilter = resultsCategoryFilter;
obj.speciesFilter = resultsSpeciesFilter;

return formattedResults(obj, 'json');;
}
Expand Down Expand Up @@ -1299,44 +1353,21 @@ function searchHandler(request, term) {

// Category filter
info.resultsCategoryFilter = '<ul class="search-results-button-group" data-filter-group="category">'
+ '<li class="search-results-button is-checked" data-filter="">All Categories</li>';
+ '<li class="search-results-button" data-filter="">Select all</li>';
for (var k = 0; k < categories.length; k++) {
info.resultsCategoryFilter += '<li class="search-results-button" data-filter="' + categories[k][0] + '">' + categories[k][0] + '(' + categories[k][1] + ')</li>';
info.resultsCategoryFilter += '<li class="search-results-button" data-filter="' + categories[k][0] + '">' + categories[k][0] + ' (' + categories[k][1] + ')</li>';
}
info.resultsCategoryFilter += '</ul>';

// Species filter
// Sorting: human, mouse, zebrafish, fly, worm, and then everything else by data richness
var dummyTaxa = [
"Homo sapiens",
"Mus musculus",
"Danio rerio",
"Drosophila melanogaster",
"Caenorhabditis elegans"
];

// If possible that some results don't have taxon specified
// we are not handling that since it's a data issue - Zhou
info.resultsSpeciesFilter = '<ul class="search-results-button-group" data-filter-group="taxon_label">'
+ '<li class="search-results-button is-checked" data-filter="">All Species</li>';
+ '<li class="search-results-button" data-filter="">Select all</li>';

// This array holds all the unmatched taxa against dummyTaxa
var restTaxa = [];

for (var j = 0; j < taxa.length; j++) {
if (taxa[j][0] === dummyTaxa[0]) {
info.resultsSpeciesFilter += '<li class="search-results-button" data-filter="' + taxa[j][0] + '">' + taxa[j][0] + '(' + taxa[j][1] + ')</li>';
// Remove the first element from the dummyTaxa array
dummyTaxa.shift();
} else {
// Add the unmatched element into restTaxa
restTaxa.push(taxa[j]);
}
}

// Render the rest of species that are left in the tax array
for (var m = 0; m < restTaxa.length; m++) {
info.resultsSpeciesFilter += '<li class="search-results-button" data-filter="' + restTaxa[m][0] + '">' + restTaxa[m][0] + '(' + restTaxa[m][1] + ')</li>';
info.resultsSpeciesFilter += '<li class="search-results-button" data-filter="' + taxa[j][0] + '">' + taxa[j][0] + ' (' + taxa[j][1] + ')</li>';
}

info.resultsSpeciesFilter += '</ul>';
Expand Down
12 changes: 8 additions & 4 deletions templates/search_results.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div class="row">
<div class="col-xs-12 col-md-6">
<h2><span class="searchTerm">"{{term}}"</span> we found <span id="totalCount">{{count}}</span> matches</h2>
<h2><span class="searchTerm">"{{term}}"</span> has <span id="totalCount">{{count}}</span> matches</h2>
</div>

<div class="col-xs-12 col-md-6">
Expand All @@ -26,12 +26,16 @@

<div class="search-results-ui-group">
<h3>Category</h3>
{{{resultsCategoryFilter}}}
<div id="category-filter">
{{{resultsCategoryFilter}}}
</div>
</div>

<div class="search-results-ui-group">
<h3>Taxon</h3>
{{{resultsSpeciesFilter}}}
<div id="species-filter">
{{{resultsSpeciesFilter}}}
</div>
</div>

</div>
Expand All @@ -40,7 +44,7 @@

<div class="col-xs-12 col-md-9">

<div class="search-results-rows">
<div id="search-results-rows" class="search-results-rows">
{{{resultsOutput}}}
</div>

Expand Down

0 comments on commit 7ba45f1

Please sign in to comment.