Merge pull request #988 from lsmith77/fix-filters-always-as-query-parameters

Fix filters always as query parameters
This commit is contained in:
Guilhem Niot 2017-04-28 14:36:48 +00:00 committed by GitHub
commit 572c69a509
2 changed files with 35 additions and 1 deletions

View File

@ -438,8 +438,10 @@
method = $('[name="header_method"]', this).val(), method = $('[name="header_method"]', this).val(),
self = this, self = this,
params = {}, params = {},
filters = {},
formData = new FormData(), formData = new FormData(),
doubledParams = {}, doubledParams = {},
doubledFilters = {},
headers = {}, headers = {},
content = $(this).find('textarea.content').val(), content = $(this).find('textarea.content').val(),
result_container = $('.result', $(this).parent()); result_container = $('.result', $(this).parent());
@ -527,6 +529,26 @@
// retrieve all the filters to send
$('.parameters .tuple.filter', $(this)).each(function() {
var key, value;
key = $('.key', $(this)).val();
value = $('.value', $(this)).val();
if (value) {
// temporary save all additional/doubled parameters
if (key in filters) {
doubledFilters[key] = value;
} else {
filters[key] = value;
}
}
});
// retrieve the additional headers to send // retrieve the additional headers to send
$('.headers .tuple', $(this)).each(function() { $('.headers .tuple', $(this)).each(function() {
var key, value; var key, value;
@ -575,6 +597,18 @@
} }
{% endif %} {% endif %}
//add filters as GET params and remove them from params
if(method != 'GET'){
for (var filterKey in $.extend({}, filters)){
url += url.indexOf('?') > 0 ? '&' : '?';
url += filterKey + '=' + filters[filterKey];
if (params.hasOwnProperty(filterKey)){
delete(params[filterKey]);
}
}
}
// prepare final parameters // prepare final parameters
var body = {}; var body = {};
if(bodyFormat == 'json' && method != 'GET') { if(bodyFormat == 'json' && method != 'GET') {

View File

@ -252,7 +252,7 @@
{% if data.filters is defined %} {% if data.filters is defined %}
<h4>Filters</h4> <h4>Filters</h4>
{% for name, infos in data.filters %} {% for name, infos in data.filters %}
<p class="tuple"> <p class="tuple filter">
<input type="text" class="key" value="{{ name }}" placeholder="Key" /> <input type="text" class="key" value="{{ name }}" placeholder="Key" />
<span>=</span> <span>=</span>
<input type="text" class="value" placeholder="{% if infos.description is defined %}{{ infos.description }}{% else %}Value{% endif %}" {% if infos.default is defined %} value="{{ infos.default }}" {% endif %}/> <span class="remove">-</span> <input type="text" class="value" placeholder="{% if infos.description is defined %}{{ infos.description }}{% else %}Value{% endif %}" {% if infos.default is defined %} value="{{ infos.default }}" {% endif %}/> <span class="remove">-</span>