DSS-5579: Fixes bug with search input: first search operation is successful but subsequent search attempts fail on enter

This commit is contained in:
Seyi Adebajo 2016-11-29 15:49:28 -08:00
parent 20db44df20
commit d481bd42e9
2 changed files with 29 additions and 23 deletions

View File

@ -92,7 +92,7 @@
</ul> </ul>
</li> </li>
</ul> </ul>
<form class="navbar-form navbar-left" role="search"> <form class="navbar-form navbar-left" role="search" id="nav-keyword-search-form">
<div class="row"> <div class="row">
<div id="searchcategorybtngroup" class="btn-group" role="group"> <div id="searchcategorybtngroup" class="btn-group" role="group">
<button style="height: 30px;margin-right:-4px;" <button style="height: 30px;margin-right:-4px;"

View File

@ -1,10 +1,30 @@
(function (window, $) { (function (global, $) {
const searchForm = document.querySelector('#nav-keyword-search-form');
const searchInput = searchForm.querySelector('#searchInput');
// Prevent `enter` key on single input from triggering default form action resulting in page reload
searchForm && searchForm.addEventListener('submit', e => e.preventDefault());
/**
* Implements handler for search functionality on Navigation Bar search form.
* Updates location hash which will trigger Ember Search route model refresh
* *Unfortunately current application model does not abide by Ember recommended approach, hence manual plumbing
* *will be refactored in eventual `purge`
*/
const handleSearchInput = function () {
if (searchInput) {
const {value: keyword} = searchInput;
const searchRouteHash = `#/search?keywords=${btoa(keyword)}&category=${global.g_currentCategory}&source=default&page=1`;
keyword && (document.location.hash = searchRouteHash);
}
};
$('#advsearchtabs').find('a:first').tab('show'); $('#advsearchtabs').find('a:first').tab('show');
$('#datasetAdvSearchLink').addClass('active'); $('#datasetAdvSearchLink').addClass('active');
String.prototype.replaceAll = function (target, replacement) { String.prototype.replaceAll = function (target, replacement) {
return this.split(target).join(replacement); return this.split(target).join(replacement);
}; };
window.g_currentCategory = 'Datasets'; global.g_currentCategory = 'Datasets';
function renderAdvSearchDatasetSources(parent, sources) { function renderAdvSearchDatasetSources(parent, sources) {
let content = ''; let content = '';
if ((!parent) || (!sources) || sources.length == 0) { if ((!parent) || (!sources) || sources.length == 0) {
@ -67,7 +87,7 @@
$(objs[index]).parent().removeClass('active'); $(objs[index]).parent().removeClass('active');
}); });
} }
window.g_currentCategory = e.target.text; global.g_currentCategory = e.target.text;
updateSearchCategories(e.target.text); updateSearchCategories(e.target.text);
//$(e.target).parent().addClass( 'active' ); //$(e.target).parent().addClass( 'active' );
e.preventDefault(); e.preventDefault();
@ -147,7 +167,7 @@
return false; return false;
} }
}).on('autocompleteselect', () => document.querySelector('#searchBtn').click()); }).on('autocompleteselect', handleSearchInput);
}); });
$.get('/api/v1/advsearch/scopes', function (data) { $.get('/api/v1/advsearch/scopes', function (data) {
@ -322,24 +342,10 @@
}); });
}); });
$('#searchBtn').click(function () { document.querySelector('#searchBtn').addEventListener('click', handleSearchInput);
var inputObj = $('#searchInput');
if (inputObj) {
var keyword = inputObj.val();
if (keyword) {
window.location = '/#/search?keywords=' + btoa(keyword) +
'&category=' + window.g_currentCategory + '&source=default&page=1'
}
}
});
// This is a stop gap implementation to solve the issue with handling the enter key on user search // This is a stop gap implementation to solve the issue with handling the enter key on user search
document.querySelector('#searchInput') document.querySelector('#searchInput').addEventListener('keypress', e => e.keyCode === 13 && handleSearchInput(e));
.addEventListener('keypress', ({keyCode}) => {
if (keyCode === 13) {
document.querySelector('#searchBtn').click();
}
});
function advSearchForDataset() { function advSearchForDataset() {
var empty = true; var empty = true;
@ -426,7 +432,7 @@
advSearchOpts.fields = {'any': fieldAny, 'all': fieldAll, 'not': fieldNotIn}; advSearchOpts.fields = {'any': fieldAny, 'all': fieldAll, 'not': fieldNotIn};
advSearchOpts.comments = comments; advSearchOpts.comments = comments;
advSearchOpts.sources = sources; advSearchOpts.sources = sources;
window.location = '/#/advsearch/?query=' + btoa(JSON.stringify(advSearchOpts)) + '&page=1'; global.location = '/#/advsearch/?query=' + btoa(JSON.stringify(advSearchOpts)) + '&page=1';
} }
function advSearchForFlow() { function advSearchForFlow() {
@ -489,7 +495,7 @@
advSearchOpts.appcode = {'in': appcodeIn, 'not': appcodeNotIn}; advSearchOpts.appcode = {'in': appcodeIn, 'not': appcodeNotIn};
advSearchOpts.flow = {'in': flowIn, 'not': flowNotIn}; advSearchOpts.flow = {'in': flowIn, 'not': flowNotIn};
advSearchOpts.job = {'in': jobIn, 'not': jobNotIn}; advSearchOpts.job = {'in': jobIn, 'not': jobNotIn};
window.location = '/#/advsearch/?query=' + btoa(JSON.stringify(advSearchOpts)) + '&page=1'; global.location = '/#/advsearch/?query=' + btoa(JSON.stringify(advSearchOpts)) + '&page=1';
} }
$('#advSearchBtn').click(function () { $('#advSearchBtn').click(function () {