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

DSS-5579: Fixes bug with search input: first search operation is succ… #286

Merged
merged 1 commit into from
Dec 17, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</ul>
</li>
</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 id="searchcategorybtngroup" class="btn-group" role="group">
<button style="height: 30px;margin-right:-4px;"
Expand Down
50 changes: 28 additions & 22 deletions web/public/javascripts/search.js
Original file line number Diff line number Diff line change
@@ -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');
$('#datasetAdvSearchLink').addClass('active');
String.prototype.replaceAll = function (target, replacement) {
return this.split(target).join(replacement);
};
window.g_currentCategory = 'Datasets';
global.g_currentCategory = 'Datasets';
function renderAdvSearchDatasetSources(parent, sources) {
let content = '';
if ((!parent) || (!sources) || sources.length == 0) {
Expand Down Expand Up @@ -67,7 +87,7 @@
$(objs[index]).parent().removeClass('active');
});
}
window.g_currentCategory = e.target.text;
global.g_currentCategory = e.target.text;
updateSearchCategories(e.target.text);
//$(e.target).parent().addClass( 'active' );
e.preventDefault();
Expand Down Expand Up @@ -147,7 +167,7 @@

return false;
}
}).on('autocompleteselect', () => document.querySelector('#searchBtn').click());
}).on('autocompleteselect', handleSearchInput);
});

$.get('/api/v1/advsearch/scopes', function (data) {
Expand Down Expand Up @@ -322,24 +342,10 @@
});
});

$('#searchBtn').click(function () {
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'
}
}
});
document.querySelector('#searchBtn').addEventListener('click', handleSearchInput);

// This is a stop gap implementation to solve the issue with handling the enter key on user search
document.querySelector('#searchInput')
.addEventListener('keypress', ({keyCode}) => {
if (keyCode === 13) {
document.querySelector('#searchBtn').click();
}
});
document.querySelector('#searchInput').addEventListener('keypress', e => e.keyCode === 13 && handleSearchInput(e));

function advSearchForDataset() {
var empty = true;
Expand Down Expand Up @@ -426,7 +432,7 @@
advSearchOpts.fields = {'any': fieldAny, 'all': fieldAll, 'not': fieldNotIn};
advSearchOpts.comments = comments;
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() {
Expand Down Expand Up @@ -489,7 +495,7 @@
advSearchOpts.appcode = {'in': appcodeIn, 'not': appcodeNotIn};
advSearchOpts.flow = {'in': flowIn, 'not': flowNotIn};
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 () {
Expand Down