mirror of
https://github.com/ansible/awx.git
synced 2026-05-16 13:57:39 -02:30
Merge pull request #524 from gconsidine/ui/fix/remove-unsupported-query-tokens
Remove unsupported tokens from search generated queries
This commit is contained in:
@@ -29,43 +29,48 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
|
|||||||
return defer.promise;
|
return defer.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
replaceDefaultFlags (value) {
|
||||||
|
value = value.toString().replace(/__icontains_DEFAULT/g, "__icontains");
|
||||||
|
value = value.toString().replace(/__search_DEFAULT/g, "__search");
|
||||||
|
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
|
||||||
|
replaceEncodedTokens(value) {
|
||||||
|
return decodeURIComponent(value).replace(/"|'/g, "");
|
||||||
|
},
|
||||||
|
|
||||||
|
encodeTerms (values, key) {
|
||||||
|
key = this.replaceDefaultFlags(key);
|
||||||
|
|
||||||
|
if (!Array.isArray(values)) {
|
||||||
|
values = this.replaceEncodedTokens(values);
|
||||||
|
|
||||||
|
return `${key}=${values}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return values
|
||||||
|
.map(value => {
|
||||||
|
value = this.replaceDefaultFlags(value);
|
||||||
|
value = this.replaceEncodedTokens(value);
|
||||||
|
|
||||||
|
return `${key}=${value}`;
|
||||||
|
})
|
||||||
|
.join('&');
|
||||||
|
},
|
||||||
// encodes ui-router params from {operand__key__comparator: value} pairs to API-consumable URL
|
// encodes ui-router params from {operand__key__comparator: value} pairs to API-consumable URL
|
||||||
encodeQueryset(params) {
|
encodeQueryset(params) {
|
||||||
let queryset;
|
if (typeof params !== 'object') {
|
||||||
queryset = _.reduce(params, (result, value, key) => {
|
return '';
|
||||||
return result + encodeTerm(value, key);
|
|
||||||
}, '');
|
|
||||||
queryset = queryset.substring(0, queryset.length - 1);
|
|
||||||
return angular.isObject(params) ? `?${queryset}` : '';
|
|
||||||
|
|
||||||
function encodeTerm(value, key){
|
|
||||||
|
|
||||||
key = key.toString().replace(/__icontains_DEFAULT/g, "__icontains");
|
|
||||||
key = key.toString().replace(/__search_DEFAULT/g, "__search");
|
|
||||||
|
|
||||||
value = value.toString().replace(/__icontains_DEFAULT/g, "__icontains");
|
|
||||||
value = value.toString().replace(/__search_DEFAULT/g, "__search");
|
|
||||||
|
|
||||||
if (Array.isArray(value)){
|
|
||||||
value = _.uniq(_.flattenDeep(value));
|
|
||||||
let concated = '';
|
|
||||||
angular.forEach(value, function(item){
|
|
||||||
if(item && typeof item === 'string') {
|
|
||||||
item = decodeURIComponent(item).replace(/"|'/g, "");
|
|
||||||
}
|
|
||||||
concated += `${key}=${item}&`;
|
|
||||||
});
|
|
||||||
|
|
||||||
return concated;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(value && typeof value === 'string') {
|
|
||||||
value = decodeURIComponent(value).replace(/"|'/g, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${key}=${value}&`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return _.reduce(params, (result, value, key) => {
|
||||||
|
if (result !== '?') {
|
||||||
|
result += '&';
|
||||||
|
}
|
||||||
|
|
||||||
|
return result += this.encodeTerms(value, key);
|
||||||
|
}, '?');
|
||||||
},
|
},
|
||||||
// encodes a ui smart-search param to a django-friendly param
|
// encodes a ui smart-search param to a django-friendly param
|
||||||
// operand:key:comparator:value => {operand__key__comparator: value}
|
// operand:key:comparator:value => {operand__key__comparator: value}
|
||||||
|
|||||||
Reference in New Issue
Block a user