Skip to content

Commit

Permalink
Merge pull request #278 from rka12/#218
Browse files Browse the repository at this point in the history
Populated query params to key value pair and vice-versa #218
  • Loading branch information
AnujaK committed Jun 29, 2015
2 parents 5de67e1 + d9969a0 commit 2ee2ffd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/main/resources/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ ul.fancytree-container {
outline: none;
}

.tt-hint {
color: LightGrey;
}

.tt-menu {
width: 100%;
padding: 8px 0;
Expand Down
61 changes: 43 additions & 18 deletions src/main/resources/static/js/views/conversation-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ define(function(require) {

});

$("#addQueryParamBtn").unbind("click").bind("click", function() {
var queryParamListItemView = new QueryParamListItemView();
$("#queryParamsWrapper").append(queryParamListItemView.render().el);
});

$("#addFormDataBtn").unbind("click").bind("click", function() {
var formListItemView = new FormListItemView();
Expand Down Expand Up @@ -388,24 +384,24 @@ define(function(require) {
var urlData = {};
urlData.key = urlDataNames[counter];
urlData.value = urlDataValues[counter];
urlDataArr.push(urlData);
if(urlData.key)
urlDataArr.push(urlData);
counter++;
});
_.each(urlDataArr,function(item,index){
queryString += item.key + '=' + item.value;
if(index != urlDataArr.length-1){
queryString += '&';
}
})
queryString += item.key + '=' + item.value;
if(index != urlDataArr.length-1){
queryString += '&';
}
});

var apiUrlData = $("#apiUrl").val().split('?');
if(queryString != ""){
$("#apiUrl").val(apiUrlData[0] + '?' + queryString);
$("#apiUrl").typeahead('val', apiUrlData[0] + '?' + queryString);
}
else{
$("#apiUrl").val(apiUrlData[0]);
$("#apiUrl").typeahead('val', apiUrlData[0]);
}

}
});

Expand Down Expand Up @@ -500,8 +496,9 @@ define(function(require) {
el : '#conversationSection',
events : {
"click #apiRequestNameEdit" : "convertToTextBox",
"focusout #apiRequestNameTextBox" : "converToLabel"

"focusout #apiRequestNameTextBox" : "converToLabel",
"typeahead:change #apiUrl" : "updateParams",
"click #addQueryParamBtn" : "addParams"
},

initialize : function(){
Expand Down Expand Up @@ -773,7 +770,7 @@ render : function(conversation) {
})
}

this.$el.find("#apiUrl").val(request.apiUrlString);
this.$el.find("#apiUrl").typeahead('val', request.apiUrlString).trigger('typeahead:change');
var evaluationExp = /(\{{)(.+)(\}})/
var apiUrlValue = this.$el.find("#apiUrl").val();
$('#evaluatedApiUrl').val(apiUrlValue);
Expand Down Expand Up @@ -876,8 +873,36 @@ handleOauthResult : function handleOauthResult(result) {
headerListItemView.$el.find('.headerName').val("Authorization");
headerListItemView.$el.find('.headerValue').val("Bearer "+result);

}
},

updateParams : function() {
var url = $("#apiUrl").val();
var queryString = url.split('?')[1];
if (queryString) {
var params = queryString.replace(/\+/g, ' ').split('&');
var paramInputRows = $("#queryParamsWrapper .row");
if (params.length > paramInputRows.length) {
for (var i = 0; i < (params.length - paramInputRows.length); i++) {
this.addParams();
}
}

var i = 0;
$('.urlDataName').each(function() {
$(this).val(params[i] ? params[i++].split('=')[0] : '');
});

i = 0;
$(".urlDataValue").each(function() {
$(this).val(params[i] ? params[i++].split('=')[1] : '');
});
}
},
addParams : function() {
var queryParamListItemView = new QueryParamListItemView();
$("#queryParamsWrapper").append(queryParamListItemView.render().el);
}

});
});
return ConversationView;
});

0 comments on commit 2ee2ffd

Please sign in to comment.