Fix search controller reloading when a text parameter is added

This replaces the use of $stateParams with parsing the query string
in the given URL instead, using $location. This way the controller
doesn't reload when a text parameter is added to the URL, which was
causing non-text criteria to be lost upon the addition of a text
criterion.

Change-Id: If1fbf8ce4a06538c97aa430cf5c8e703ac453db0
Task: 3493
This commit is contained in:
Adam Coldrick 2017-02-21 22:33:25 +00:00
parent 28b4809425
commit 13a889d38d
2 changed files with 5 additions and 4 deletions

View File

@ -18,7 +18,7 @@
* This controller provides initialization logic for the generic search view.
*/
angular.module('sb.search').controller('SearchController',
function ($log, $q, $scope, Criteria, $stateParams) {
function ($log, $q, $scope, Criteria, $location) {
'use strict';
/**
@ -39,9 +39,10 @@ angular.module('sb.search').controller('SearchController',
/**
* If a 'q' exists in the state params, go ahead and add it.
*/
if ($stateParams.hasOwnProperty('q') && !!$stateParams.q) {
var params = $location.search();
if (params.hasOwnProperty('q') && !!params.q) {
$scope.defaultCriteria.push(
Criteria.create('Text', $stateParams.q)
Criteria.create('Text', params.q)
);
}
}

View File

@ -26,7 +26,7 @@ angular.module('sb.search',
// Set our page routes.
$stateProvider
.state('sb.search', {
url: '/search?q',
url: '/search',
templateUrl: 'app/search/template/index.html',
controller: 'SearchController'
});