Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Bug 1059352 and Bug 1059322: Allow multiple search words and insure t…
Browse files Browse the repository at this point in the history
…hat the searchQuery url parameters are honoured
  • Loading branch information
jeads committed Aug 28, 2014
1 parent e104f4c commit 5658db9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
15 changes: 9 additions & 6 deletions webapp/app/js/controllers/filters.js
Expand Up @@ -278,16 +278,19 @@ treeherder.controller('SearchCtrl', [
'$scope', '$rootScope', 'thEvents', '$location',
function SearchCtrl($scope, $rootScope, thEvents, $location){

$rootScope.searchQuery = "";

$scope.search = function(ev){

if($scope.searchQueryStr === ""){
$rootScope.searchQuery = [];
$rootScope.searchQueryStr = "";
}

//User hit enter
if( (ev.keyCode === 13) ||
($scope.searchQuery === "") ){

$rootScope.searchQuery = $scope.searchQuery;
($scope.searchQuery.length === 0) ){

var queryString = $rootScope.searchQuery? $rootScope.searchQuery: null;
var queryString = $scope.searchQueryStr.replace(/ +(?= )/g, ' ').toLowerCase();
$rootScope.searchQuery = queryString.split(' ');

$rootScope.skipNextSearchChangeReload = true;
$location.search("searchQuery", queryString);
Expand Down
33 changes: 26 additions & 7 deletions webapp/app/js/services/jobfilters.js
Expand Up @@ -311,11 +311,21 @@ treeherder.factory('thJobFilters', [
return false;
}
}
if(typeof $rootScope.searchQuery === 'string'){
//Confirm job matches search query
if(job.searchableStr.toLowerCase().indexOf(
$rootScope.searchQuery.toLowerCase()
) === -1){

var matchTargetCount = $rootScope.searchQuery.length;

if( matchTargetCount > 0 ){

var searchableStrLc = job.searchableStr.toLowerCase();
var matches = 0;
var j = 0;

for(; j<matchTargetCount; j++){
if(searchableStrLc.indexOf($rootScope.searchQuery[j]) != -1){
matches++;
}
}
if(matches != matchTargetCount){
return false;
}
}
Expand Down Expand Up @@ -542,8 +552,14 @@ treeherder.factory('thJobFilters', [
var search = _.clone($location.search());
$log.debug("query string params", $location.search());

if($rootScope.searchQuery === undefined){
$rootScope.searchQuery = [];
$rootScope.searchQueryStr = "";
}

_.each(search, function (filterVal, filterKey) {
$log.debug("field filter", filterKey, filterVal);

if (filterKey.slice(0, urlFilterPrefixLen) === urlFilterPrefix) {
$log.debug("adding field filter", filterKey, filterVal);
addFilter(filterKey.slice(urlFilterPrefixLen), filterVal, true);
Expand All @@ -561,7 +577,9 @@ treeherder.factory('thJobFilters', [
} else if (filterKey === "searchQuery") {
filterVal = _.isArray(filterVal)? filterVal[0]: filterVal;
$log.debug("searchQuery added", filterVal);
$rootScope.searchQuery = filterVal;

$rootScope.searchQuery = filterVal.replace(/ +(?= )/g, ' ').toLowerCase().split(' ');
$rootScope.searchQueryStr = filterVal;
}
});
$log.debug("done with loadFiltersFromQueryString", filters);
Expand All @@ -586,6 +604,7 @@ treeherder.factory('thJobFilters', [
};

var buildQueryStringFromFilters = function() {

var newSearchValues = removeFiltersFromQueryString(
_.clone($location.search()));

Expand All @@ -612,7 +631,7 @@ treeherder.factory('thJobFilters', [
}
});

if ($rootScope.searchQuery && typeof $rootScope.searchQuery === 'string'){
if ($rootScope.searchQuery.length > 0){
newSearchValues.searchQuery = $rootScope.searchQuery;
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/app/partials/thWatchedRepoNavPanel.html
Expand Up @@ -48,7 +48,7 @@
</span>
<div ng-controller="SearchCtrl" class="form-group form-inline">
<input id="platform-job-text-search-field"
ng-model="searchQuery" ng-keyup="search($event)" type="text"
ng-model="searchQueryStr" ng-keyup="search($event)" type="text"
class="form-control input-sm"
placeholder="Filter platforms & jobs">
</div>
Expand Down

0 comments on commit 5658db9

Please sign in to comment.