Prevents replacing encoded quotes while searching against host filter

This commit is contained in:
mabashian 2019-04-03 15:17:41 -04:00
parent cfa2eabb57
commit 47d6e5c028
2 changed files with 10 additions and 10 deletions

View File

@ -18,11 +18,11 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
return defer.promise;
},
getCommonModelOptions(path, name) {
let resolve, base,
let base,
defer = $q.defer();
this.url = path;
resolve = this.options(path)
this.options(path)
.then((res) => {
base = res.data.actions.GET;
let relatedSearchFields = res.data.related_search_fields;
@ -46,7 +46,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
replaceEncodedTokens(value) {
return decodeURIComponent(value).replace(/"|'/g, "");
},
encodeTerms(value, key){
encodeTerms(value, key, singleSearchParam){
key = this.replaceDefaultFlags(key);
value = this.replaceDefaultFlags(value);
var that = this;
@ -54,7 +54,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
value = _.uniq(_.flattenDeep(value));
let concated = '';
angular.forEach(value, function(item){
if(item && typeof item === 'string') {
if(item && typeof item === 'string' && !singleSearchParam) {
item = that.replaceEncodedTokens(item);
}
concated += `${key}=${item}&`;
@ -63,7 +63,7 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
return concated;
}
else {
if(value && typeof value === 'string') {
if(value && typeof value === 'string' && !singleSearchParam) {
value = this.replaceEncodedTokens(value);
}
@ -71,10 +71,10 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
}
},
// encodes ui-router params from {operand__key__comparator: value} pairs to API-consumable URL
encodeQueryset(params) {
encodeQueryset(params, singleSearchParam) {
let queryset;
queryset = _.reduce(params, (result, value, key) => {
return result + this.encodeTerms(value, key);
return result + this.encodeTerms(value, key, singleSearchParam);
}, '');
queryset = queryset.substring(0, queryset.length - 1);
return angular.isObject(params) ? `?${queryset}` : '';
@ -268,9 +268,9 @@ function QuerysetService ($q, Rest, ProcessErrors, $rootScope, Wait, DjangoSearc
Rest.setUrl(endpoint);
return Rest.options(endpoint);
},
search(endpoint, params) {
search(endpoint, params, singleSearchParam) {
Wait('start');
this.url = `${endpoint}${this.encodeQueryset(params)}`;
this.url = `${endpoint}${this.encodeQueryset(params, singleSearchParam)}`;
Rest.setUrl(this.url);
return Rest.get()

View File

@ -202,7 +202,7 @@ function SmartSearchController (
});
}
qs.search(path, queryset)
qs.search(path, queryset, singleSearchParam)
.then(({ data }) => {
if ($scope.querySet) {
$scope.querySet = queryset;