console 추가
This commit is contained in:
@@ -1920,4 +1920,8 @@ footer div.foot_info span {
|
|||||||
|
|
||||||
.bar-zoom svg:nth-child(1) {
|
.bar-zoom svg:nth-child(1) {
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.response_headers td{
|
||||||
|
padding: 1px !important;
|
||||||
}
|
}
|
||||||
@@ -14,9 +14,10 @@ class APIClient {
|
|||||||
this.abortController = null;
|
this.abortController = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendAPIRequest(model, preProcessCallback) {
|
|
||||||
|
async sendAPIRequest(model, preProcessCallback, consoleOutput) {
|
||||||
// try {
|
// try {
|
||||||
const updatedModel = await this.executePreRequestScript(model);
|
const updatedModel = await this.executePreRequestScript(model, consoleOutput);
|
||||||
let processedRequest = this.replacePlaceholdersWithVariables(updatedModel);
|
let processedRequest = this.replacePlaceholdersWithVariables(updatedModel);
|
||||||
if (preProcessCallback) {
|
if (preProcessCallback) {
|
||||||
preProcessCallback(processedRequest);
|
preProcessCallback(processedRequest);
|
||||||
@@ -25,7 +26,6 @@ class APIClient {
|
|||||||
.then(async response => {
|
.then(async response => {
|
||||||
const responseData = await response.json(); // Parse the JSON response
|
const responseData = await response.json(); // Parse the JSON response
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
// If response is not OK, use the parsed error information
|
|
||||||
const errorMessage = responseData.error || 'Unknown error';
|
const errorMessage = responseData.error || 'Unknown error';
|
||||||
throw new Error(`API 호출 중 오류가 발생했습니다. 사유[${errorMessage}]`);
|
throw new Error(`API 호출 중 오류가 발생했습니다. 사유[${errorMessage}]`);
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ class APIClient {
|
|||||||
_.forEach(data.headers, (header) => {
|
_.forEach(data.headers, (header) => {
|
||||||
response.headers[header.key] = header.value;
|
response.headers[header.key] = header.value;
|
||||||
});
|
});
|
||||||
return this.executePostRequestScript(model.postRequestScript, response)
|
return this.executePostRequestScript(model.postRequestScript, response, consoleOutput)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
$('.toast-body').text(error);
|
$('.toast-body').text(error);
|
||||||
$('.toast').toast('show');
|
$('.toast').toast('show');
|
||||||
@@ -112,17 +112,13 @@ class APIClient {
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
executePreRequestScript(model) {
|
|
||||||
|
executePreRequestScript(model, consoleOutput) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let script = model.preRequestScript;
|
let script = model.preRequestScript;
|
||||||
let resultFrame = document.getElementById('preRequest');
|
let resultFrame = document.getElementById('preRequest');
|
||||||
|
|
||||||
this.variables = {};
|
this.variables = {};
|
||||||
model.variables.forEach((item) => {
|
|
||||||
if (item.enabled) {
|
|
||||||
this.variables[item.key] = item.value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
window.preRequestComplete = (updatedModel, error) => {
|
window.preRequestComplete = (updatedModel, error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -134,7 +130,15 @@ class APIClient {
|
|||||||
|
|
||||||
window.temp_variable = this.variables;
|
window.temp_variable = this.variables;
|
||||||
window.currentRequest = model;
|
window.currentRequest = model;
|
||||||
|
window.consoleOutput = consoleOutput;
|
||||||
resultFrame.srcdoc = `<script>
|
resultFrame.srcdoc = `<script>
|
||||||
|
var oldLog = console.log;
|
||||||
|
console.log = function(message) {
|
||||||
|
if(window.parent.consoleOutput)
|
||||||
|
window.parent.consoleOutput(message);
|
||||||
|
oldLog.apply(console, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
window.globals = window.parent.globals;
|
window.globals = window.parent.globals;
|
||||||
window.variables = window.parent.temp_variable;
|
window.variables = window.parent.temp_variable;
|
||||||
window.request = window.parent.currentRequest;
|
window.request = window.parent.currentRequest;
|
||||||
@@ -149,21 +153,26 @@ class APIClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
executePostRequestScript(script, response) {
|
executePostRequestScript(script, response, consoleOutput) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let resultFrame = document.getElementById('postRequest');
|
let resultFrame = document.getElementById('postRequest');
|
||||||
window.response = response;
|
window.response = response;
|
||||||
window.temp_variable = this.variables;
|
window.temp_variable = this.variables;
|
||||||
window.postRequestComplete = (response, error) => {
|
window.postRequestComplete = (response, error) => {
|
||||||
console.log(response)
|
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
resolve(response);
|
resolve(response);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
window.consoleOutput = consoleOutput;
|
||||||
resultFrame.srcdoc = `<script>
|
resultFrame.srcdoc = `<script>
|
||||||
|
var oldLog = console.log;
|
||||||
|
console.log = function(message) {
|
||||||
|
if(window.parent.consoleOutput)
|
||||||
|
window.parent.consoleOutput(message);
|
||||||
|
oldLog.apply(console, arguments);
|
||||||
|
};
|
||||||
window.globals = window.parent.globals;
|
window.globals = window.parent.globals;
|
||||||
window.variables = window.parent.temp_variable;
|
window.variables = window.parent.temp_variable;
|
||||||
window.response = window.parent.response;
|
window.response = window.parent.response;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class APIScenario {
|
|||||||
this.showOutput = true;
|
this.showOutput = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadScenarioList() {
|
loadScenarioList(callback) {
|
||||||
const me = this;
|
const me = this;
|
||||||
this.currentAjaxRequest = $.ajax({
|
this.currentAjaxRequest = $.ajax({
|
||||||
url: '/mgmt/api_scenario/list.do',
|
url: '/mgmt/api_scenario/list.do',
|
||||||
@@ -53,12 +53,7 @@ class APIScenario {
|
|||||||
});
|
});
|
||||||
|
|
||||||
me.editor.import(drawflowData);
|
me.editor.import(drawflowData);
|
||||||
// if (data.length === 0) {
|
|
||||||
me.editor.changeModule('Home');
|
me.editor.changeModule('Home');
|
||||||
// } else {
|
|
||||||
// me.editor.changeModule(data[0].id);
|
|
||||||
// me.currentScenario = data[0].id;
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
error: function (response, textStatus, errorThrown) {
|
error: function (response, textStatus, errorThrown) {
|
||||||
me.hideLoadingOverlay();
|
me.hideLoadingOverlay();
|
||||||
@@ -67,6 +62,9 @@ class APIScenario {
|
|||||||
},
|
},
|
||||||
complete: function () {
|
complete: function () {
|
||||||
me.renderScenarioList();
|
me.renderScenarioList();
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
me.hideLoadingOverlay();
|
me.hideLoadingOverlay();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -79,12 +77,18 @@ class APIScenario {
|
|||||||
openScenario(event) {
|
openScenario(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let scenarioId = $(event.target).closest('li').data('id');
|
let scenarioId = $(event.target).closest('li').data('id');
|
||||||
|
this.openScenarioById(scenarioId);
|
||||||
|
}
|
||||||
|
openScenarioById(scenarioId) {
|
||||||
let all = document.querySelectorAll(".api-scenario-list li");
|
let all = document.querySelectorAll(".api-scenario-list li");
|
||||||
|
|
||||||
for (let i = 0; i < all.length; i++) {
|
for (let i = 0; i < all.length; i++) {
|
||||||
all[i].classList.remove('selected');
|
all[i].classList.remove('selected');
|
||||||
}
|
}
|
||||||
event.target.closest('li').classList.add('selected');
|
|
||||||
|
//find li by data-id and add class selected
|
||||||
|
|
||||||
|
document.querySelector(`.api-scenario-list li[data-id="${scenarioId}"]`).classList.add('selected');
|
||||||
|
|
||||||
this.editor.changeModule(scenarioId);
|
this.editor.changeModule(scenarioId);
|
||||||
this.currentScenario = scenarioId;
|
this.currentScenario = scenarioId;
|
||||||
@@ -116,13 +120,24 @@ class APIScenario {
|
|||||||
type: 'POST',
|
type: 'POST',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
data: JSON.stringify({name: name, scenario: "{}", description: ""}),
|
data: JSON.stringify({name: name, scenario: "{}", description: ""}),
|
||||||
|
success: function (data) {
|
||||||
|
me.loadScenarioList(()=> {
|
||||||
|
me.openScenarioById(data.id);
|
||||||
|
let start = `
|
||||||
|
<div>
|
||||||
|
<div><i class="fas fa-play"></i> Start </div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
me.editor.addNode('Start', 0, 1, 100, 100, 'start', {}, start);
|
||||||
|
});
|
||||||
|
},
|
||||||
error: function (response, textStatus, errorThrown) {
|
error: function (response, textStatus, errorThrown) {
|
||||||
me.hideLoadingOverlay();
|
me.hideLoadingOverlay();
|
||||||
$('.toast-body').text(response.responseJSON.error);
|
$('.toast-body').text(response.responseJSON.error);
|
||||||
$('.toast').toast('show');
|
$('.toast').toast('show');
|
||||||
},
|
},
|
||||||
complete: function () {
|
complete: function () {
|
||||||
me.loadScenarioList();
|
|
||||||
me.hideLoadingOverlay();
|
me.hideLoadingOverlay();
|
||||||
$('#new_scenario_modal').modal('hide');
|
$('#new_scenario_modal').modal('hide');
|
||||||
}
|
}
|
||||||
@@ -302,7 +317,7 @@ class APIScenario {
|
|||||||
{type: 'click', selector: '#new_scenario', action: this.showNewScenarioModal.bind(this)},
|
{type: 'click', selector: '#new_scenario', action: this.showNewScenarioModal.bind(this)},
|
||||||
{type: 'click', selector: '.create_scenario', action: this.createScenario.bind(this)},
|
{type: 'click', selector: '.create_scenario', action: this.createScenario.bind(this)},
|
||||||
{type: 'click', selector: '.save_scenario', action: this.saveScenario.bind(this)},
|
{type: 'click', selector: '.save_scenario', action: this.saveScenario.bind(this)},
|
||||||
{type: 'click', selector: '.add_start', action: this.addStart.bind(this)},
|
// {type: 'click', selector: '.add_start', action: this.addStart.bind(this)},
|
||||||
{type: 'click', selector: '.delete_scenario', action: this.showDeleteModal.bind(this)},
|
{type: 'click', selector: '.delete_scenario', action: this.showDeleteModal.bind(this)},
|
||||||
{type: 'click', selector: '.confirm_delete_scenario', action: this.removeScenario.bind(this)},
|
{type: 'click', selector: '.confirm_delete_scenario', action: this.removeScenario.bind(this)},
|
||||||
{type: 'click', selector: '.stop_scenario', action: this.stopScenario.bind(this)}
|
{type: 'click', selector: '.stop_scenario', action: this.stopScenario.bind(this)}
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ class APITester {
|
|||||||
this.collections = []; //API 컬렉션
|
this.collections = []; //API 컬렉션
|
||||||
this.requestEditors = []; //API request body editor
|
this.requestEditors = []; //API request body editor
|
||||||
this.responseEditors = []; //API response body editor
|
this.responseEditors = []; //API response body editor
|
||||||
|
this.consoleEditors = []; //API console editor
|
||||||
this.preRequestEditors = [];
|
this.preRequestEditors = [];
|
||||||
this.postRequestEditors = [];
|
this.postRequestEditors = [];
|
||||||
|
|
||||||
// this.variables = {};
|
|
||||||
this.apiClient = new APIClient();
|
this.apiClient = new APIClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,14 +175,17 @@ class APITester {
|
|||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation">
|
||||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#responseHeaderTab_${apiRequest.id}" type="button" role="tab" aria-controls="responseHeader" aria-selected="false">Header</button>
|
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#responseHeaderTab_${apiRequest.id}" type="button" role="tab" aria-controls="responseHeader" aria-selected="false">Header</button>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item" role="presentation">
|
||||||
|
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#consoleTab_${apiRequest.id}" type="button" role="tab" aria-controls="consoleTab" aria-selected="false">Console</button>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content border-bottom" style="min-height: 250px;">
|
<div class="tab-content border-bottom" style="min-height: 250px;">
|
||||||
<div class="tab-pane fade show active" id="responseBodyTab_${apiRequest.id}" role="tabpanel"
|
<div class="tab-pane fade show active" id="responseBodyTab_${apiRequest.id}" role="tabpanel"
|
||||||
aria-labelledby="requestParams-tab">
|
aria-labelledby="responseParams-tab">
|
||||||
<div class="response_body mt-1" style="width:100%;height:250px;border:1px solid grey;"></div>
|
<div class="response_body mt-1" style="width:100%;height:250px;border:1px solid grey;"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane fade" id="responseHeaderTab_${apiRequest.id}" role="tabpanel"
|
<div class="tab-pane fade" id="responseHeaderTab_${apiRequest.id}" role="tabpanel"
|
||||||
aria-labelledby="requestParams-tab">
|
aria-labelledby="responseParams-tab">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -194,6 +197,10 @@ class APITester {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-pane fade" id="consoleTab_${apiRequest.id}" role="tabpanel"
|
||||||
|
aria-labelledby="console-tab">
|
||||||
|
<div class="console mt-1" style="width:100%;height:250px;border:1px solid grey;"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -220,27 +227,6 @@ class APITester {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// variableTemplate(variable, index) {
|
|
||||||
// return `
|
|
||||||
// <tr data-index="${index}">
|
|
||||||
// <td>
|
|
||||||
// <div class="form-check">
|
|
||||||
// <input class="form-check-input" type="checkbox" name="variables[${index}].enabled" ${variable.enabled ? 'checked' : ''} />
|
|
||||||
// </div>
|
|
||||||
// </td>
|
|
||||||
// <td>
|
|
||||||
// <input class="form-control" type="text" name="variables[${index}].key" value="${variable.key}"/>
|
|
||||||
// </td>
|
|
||||||
// <td>
|
|
||||||
// <input class="form-control" type="text" name="variables[${index}].value" value="${variable.value}"/>
|
|
||||||
// </td>
|
|
||||||
// <td>
|
|
||||||
// <button type="button" class="btn btn-secondary btn-sm btn_remove_variable">제거</button>
|
|
||||||
// </td>
|
|
||||||
// </tr>
|
|
||||||
// `;
|
|
||||||
// }
|
|
||||||
|
|
||||||
headerTemplate(header, index) {
|
headerTemplate(header, index) {
|
||||||
return `
|
return `
|
||||||
<tr data-index="${index}">
|
<tr data-index="${index}">
|
||||||
@@ -327,9 +313,6 @@ class APITester {
|
|||||||
{selector: '.btn_remove_header', action: this.removeHeader.bind(this)},
|
{selector: '.btn_remove_header', action: this.removeHeader.bind(this)},
|
||||||
{selector: '.btn_add_query', action: this.addQueryParam.bind(this)},
|
{selector: '.btn_add_query', action: this.addQueryParam.bind(this)},
|
||||||
{selector: '.btn_remove_query', action: this.removeQueryParam.bind(this)},
|
{selector: '.btn_remove_query', action: this.removeQueryParam.bind(this)},
|
||||||
// {selector: '.btn_add_variables', action: this.addVariable.bind(this)},
|
|
||||||
// {selector: '.btn_remove_variable', action: this.removeVariable.bind(this)},
|
|
||||||
|
|
||||||
{selector: '.send', action: this.handleSendAPIRequest.bind(this)},
|
{selector: '.send', action: this.handleSendAPIRequest.bind(this)},
|
||||||
{selector: '.save', action: this.saveAPIRequest.bind(this)},
|
{selector: '.save', action: this.saveAPIRequest.bind(this)},
|
||||||
{selector: '.save_collection', action: this.addCollection.bind(this)},
|
{selector: '.save_collection', action: this.addCollection.bind(this)},
|
||||||
@@ -358,7 +341,6 @@ class APITester {
|
|||||||
$(document).on('change', '.query_params input', this.buildPath.bind(this));
|
$(document).on('change', '.query_params input', this.buildPath.bind(this));
|
||||||
$(document).on('input', '.path', this.parseParam.bind(this));
|
$(document).on('input', '.path', this.parseParam.bind(this));
|
||||||
$(document).on('change', '.request_headers input', this.handleUIUpdate.bind(this));
|
$(document).on('change', '.request_headers input', this.handleUIUpdate.bind(this));
|
||||||
// $(document).on('change', '.variables input', this.handleUIUpdate.bind(this));
|
|
||||||
$(document).on('change', '.api_request_info select, .api_request_info input', this.handleUIUpdate.bind(this));
|
$(document).on('change', '.api_request_info select, .api_request_info input', this.handleUIUpdate.bind(this));
|
||||||
$(document).on('change', '.api_request_info select', this.handleUpdateServer.bind(this));
|
$(document).on('change', '.api_request_info select', this.handleUpdateServer.bind(this));
|
||||||
|
|
||||||
@@ -449,7 +431,6 @@ class APITester {
|
|||||||
showDeleteApiRequestModal(event) {
|
showDeleteApiRequestModal(event) {
|
||||||
let collectionId = $(event.currentTarget).closest('li').data('collection');
|
let collectionId = $(event.currentTarget).closest('li').data('collection');
|
||||||
let apiId = $(event.currentTarget).closest('li').data('id');
|
let apiId = $(event.currentTarget).closest('li').data('id');
|
||||||
console.log('apiId: ' + apiId);
|
|
||||||
$('#confirm_delete_api_modal').find('.confirm_delete_api').data('id', apiId);
|
$('#confirm_delete_api_modal').find('.confirm_delete_api').data('id', apiId);
|
||||||
$('#confirm_delete_api_modal').find('.confirm_delete_api').data('collection', collectionId);
|
$('#confirm_delete_api_modal').find('.confirm_delete_api').data('collection', collectionId);
|
||||||
$('#confirm_delete_api_modal').modal('show');
|
$('#confirm_delete_api_modal').modal('show');
|
||||||
@@ -515,16 +496,13 @@ class APITester {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const element = event.currentTarget;
|
const element = event.currentTarget;
|
||||||
const fieldName = $(element).attr('name');
|
const fieldName = $(element).attr('name');
|
||||||
//console.log(fieldName);
|
|
||||||
const newValue = this.getFieldValue(element);
|
const newValue = this.getFieldValue(element);
|
||||||
//console.log(newValue);
|
|
||||||
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
||||||
let model = this.apiRequests[tabIndex];
|
let model = this.apiRequests[tabIndex];
|
||||||
|
|
||||||
if (fieldName !== '') {
|
if (fieldName !== '') {
|
||||||
_.set(model, fieldName, newValue);
|
_.set(model, fieldName, newValue);
|
||||||
}
|
}
|
||||||
//console.log(model);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,7 +510,6 @@ class APITester {
|
|||||||
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
||||||
let model = this.apiRequests[tabIndex];
|
let model = this.apiRequests[tabIndex];
|
||||||
let target = $('#api_request_' + model.id);
|
let target = $('#api_request_' + model.id);
|
||||||
//console.log('model.server: ' + model.server);
|
|
||||||
target.find('input[name="basePath"]').val(this.basePath(model.server));
|
target.find('input[name="basePath"]').val(this.basePath(model.server));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,32 +517,11 @@ class APITester {
|
|||||||
return params.map((param, index) => this.queryParamTemplate(param, index)).join('');
|
return params.map((param, index) => this.queryParamTemplate(param, index)).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
// renderGlobalVariables() {
|
|
||||||
// let globalVaraibes = '';
|
|
||||||
// if (window.globals) {
|
|
||||||
// //for each key in globals
|
|
||||||
// Object.keys(window.globals).map((key, index) => {
|
|
||||||
// globalVaraibes += this.variableTemplate({
|
|
||||||
// enabled: true,
|
|
||||||
// key: key,
|
|
||||||
// value: window.globals[key]
|
|
||||||
// }, index);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return globalVaraibes;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// renderVariables(variables) {
|
|
||||||
// return variables.map((variable, index) => this.variableTemplate(variable, index)).join('');
|
|
||||||
// }
|
|
||||||
|
|
||||||
renderHeaders(headers) {
|
renderHeaders(headers) {
|
||||||
return headers.map((header, index) => this.headerTemplate(header, index)).join('');
|
return headers.map((header, index) => this.headerTemplate(header, index)).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTabHeader() {
|
renderTabHeader() {
|
||||||
//console.log('renderTabHeader');
|
|
||||||
let apiRequestTabTitle = $('#apiRequestTabTitle');
|
let apiRequestTabTitle = $('#apiRequestTabTitle');
|
||||||
apiRequestTabTitle.empty();
|
apiRequestTabTitle.empty();
|
||||||
|
|
||||||
@@ -581,7 +537,6 @@ class APITester {
|
|||||||
|
|
||||||
renderTabContent(index) {
|
renderTabContent(index) {
|
||||||
var me = this;
|
var me = this;
|
||||||
//console.log('renderTabContent: ' + index);
|
|
||||||
let apiRequestTabContent = $(this.apiTabContentTarget);
|
let apiRequestTabContent = $(this.apiTabContentTarget);
|
||||||
let model = this.apiRequests[index];
|
let model = this.apiRequests[index];
|
||||||
|
|
||||||
@@ -619,6 +574,16 @@ class APITester {
|
|||||||
});
|
});
|
||||||
me.responseEditors.push(responseBodyEditor);
|
me.responseEditors.push(responseBodyEditor);
|
||||||
|
|
||||||
|
let consoleEditor = monaco.editor.create(target.find(".console")[0], {
|
||||||
|
value: '',
|
||||||
|
language: 'text/plain',
|
||||||
|
theme: 'vs-light',
|
||||||
|
automaticLayout: true
|
||||||
|
});
|
||||||
|
|
||||||
|
me.consoleEditors.push(consoleEditor);
|
||||||
|
|
||||||
|
|
||||||
let preRequestEditor = monaco.editor.create(target.find(".pre-request")[0], {
|
let preRequestEditor = monaco.editor.create(target.find(".pre-request")[0], {
|
||||||
value: model.preRequestScript,
|
value: model.preRequestScript,
|
||||||
language: 'javascript',
|
language: 'javascript',
|
||||||
@@ -729,15 +694,11 @@ class APITester {
|
|||||||
try {
|
try {
|
||||||
$(`#api_request_tab_${id}`).tab('show'); // API request 탭 활성화
|
$(`#api_request_tab_${id}`).tab('show'); // API request 탭 활성화
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//console.log(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log('openTab, api_request: ' + id);
|
|
||||||
try {
|
try {
|
||||||
$(`#api_request_${id}`).find('.btn_request_body_tab').tab('show'); // Body 탭 활성화
|
$(`#api_request_${id}`).find('.btn_request_body_tab').tab('show'); // Body 탭 활성화
|
||||||
//console.log('openTab, done: ' + id);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//console.log(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,7 +723,6 @@ class APITester {
|
|||||||
|
|
||||||
renderHeaderView(tabIndex) {
|
renderHeaderView(tabIndex) {
|
||||||
let model = this.apiRequests[tabIndex];
|
let model = this.apiRequests[tabIndex];
|
||||||
//console.log(model);
|
|
||||||
let target = $('#api_request_' + model.id);
|
let target = $('#api_request_' + model.id);
|
||||||
target.find('.request_headers').empty();
|
target.find('.request_headers').empty();
|
||||||
target.find('.request_headers').append(this.renderHeaders(model.headers));
|
target.find('.request_headers').append(this.renderHeaders(model.headers));
|
||||||
@@ -771,7 +731,6 @@ class APITester {
|
|||||||
|
|
||||||
addQueryParam(event) {
|
addQueryParam(event) {
|
||||||
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
||||||
//console.log('addQueryParam');
|
|
||||||
let model = this.apiRequests[tabIndex];
|
let model = this.apiRequests[tabIndex];
|
||||||
model.queryParams.push({
|
model.queryParams.push({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@@ -783,7 +742,6 @@ class APITester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeQueryParam(event) {
|
removeQueryParam(event) {
|
||||||
//console.log('removeQueryParam');
|
|
||||||
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
||||||
const index = $(event.currentTarget).closest('tr').data('index');
|
const index = $(event.currentTarget).closest('tr').data('index');
|
||||||
let model = this.apiRequests[tabIndex];
|
let model = this.apiRequests[tabIndex];
|
||||||
@@ -799,43 +757,12 @@ class APITester {
|
|||||||
target.find('.query_params').append(this.renderParams(model.queryParams));
|
target.find('.query_params').append(this.renderParams(model.queryParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
// addVariable(event) {
|
|
||||||
// //console.log('addVariable');
|
|
||||||
// const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
|
||||||
// let model = this.apiRequests[tabIndex];
|
|
||||||
// model.variables.push({
|
|
||||||
// enabled: true,
|
|
||||||
// key: '',
|
|
||||||
// value: ''
|
|
||||||
// });
|
|
||||||
// this.renderVariablesView(tabIndex);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// removeVariable(event) {
|
|
||||||
// //console.log('removeVariable');
|
|
||||||
// const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
|
||||||
// const index = $(event.currentTarget).closest('tr').data('index');
|
|
||||||
// let model = this.apiRequests[tabIndex];
|
|
||||||
// model.variables.splice(index, 1);
|
|
||||||
// this.renderVariablesView(tabIndex);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// renderVariablesView(tabIndex) {
|
|
||||||
// let model = this.apiRequests[tabIndex];
|
|
||||||
// //console.log(model);
|
|
||||||
// let target = $('#api_request_' + model.id);
|
|
||||||
// target.find('.variables').empty();
|
|
||||||
// target.find('.variables').append(this.renderVariables(model.variables));
|
|
||||||
// }
|
|
||||||
|
|
||||||
parseParam(event) {
|
parseParam(event) {
|
||||||
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
||||||
let model = this.apiRequests[tabIndex];
|
let model = this.apiRequests[tabIndex];
|
||||||
model.path = $(event.currentTarget).val();
|
model.path = $(event.currentTarget).val();
|
||||||
//console.log(model.path);
|
|
||||||
model.queryParams = [];
|
model.queryParams = [];
|
||||||
let queryString = model.path.split('?')[1];
|
let queryString = model.path.split('?')[1];
|
||||||
//console.log('parseParam:' + queryString);
|
|
||||||
if (queryString) {
|
if (queryString) {
|
||||||
let queryParamArray = queryString.split('&');
|
let queryParamArray = queryString.split('&');
|
||||||
for (let i = 0; i < queryParamArray.length; i++) {
|
for (let i = 0; i < queryParamArray.length; i++) {
|
||||||
@@ -881,7 +808,6 @@ class APITester {
|
|||||||
|
|
||||||
handleSendAPIRequest(event) {
|
handleSendAPIRequest(event) {
|
||||||
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
|
||||||
console.log(tabIndex);
|
|
||||||
|
|
||||||
let model = this.apiRequests[tabIndex];
|
let model = this.apiRequests[tabIndex];
|
||||||
|
|
||||||
@@ -894,11 +820,12 @@ class APITester {
|
|||||||
let target = $('#api_request_' + model.id);
|
let target = $('#api_request_' + model.id);
|
||||||
target.find('.response_headers').empty();
|
target.find('.response_headers').empty();
|
||||||
this.responseEditors[tabIndex].setValue('');
|
this.responseEditors[tabIndex].setValue('');
|
||||||
|
let console = this.consoleEditors[tabIndex];
|
||||||
model.responseModel = {};
|
model.responseModel = {};
|
||||||
this.showLoadingOverlay();
|
this.showLoadingOverlay();
|
||||||
|
|
||||||
let startTime = new Date().getTime();
|
let startTime = new Date().getTime();
|
||||||
this.currentAjaxRequest = this.apiClient.sendAPIRequest(model)
|
this.currentAjaxRequest = this.apiClient.sendAPIRequest(model, null, this.consoleOutput.bind(this, console))
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response) {
|
if (response) {
|
||||||
model.responseModel = response;
|
model.responseModel = response;
|
||||||
@@ -918,14 +845,20 @@ class APITester {
|
|||||||
this.hideLoadingOverlay();
|
this.hideLoadingOverlay();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
// if (error.name === 'AbortError') {
|
|
||||||
// console.log('Fetch aborted');
|
|
||||||
// }
|
|
||||||
$('.toast-body').text(error);
|
$('.toast-body').text(error);
|
||||||
$('.toast').toast('show');
|
$('.toast').toast('show');
|
||||||
this.hideLoadingOverlay();
|
this.hideLoadingOverlay();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
consoleOutput(console, message) {
|
||||||
|
var range = new monaco.Range(console.getModel().getLineCount(), 1, console.getModel().getLineCount(), 1);
|
||||||
|
var id = {major: 1, minor: 1};
|
||||||
|
if (typeof message === 'object') {
|
||||||
|
message = JSON.stringify(message, null, 2);
|
||||||
|
}
|
||||||
|
var op = {identifier: id, range: range, text: message + '\n', forceMoveMarkers: true};
|
||||||
|
console.executeEdits("my-source", [op]);
|
||||||
|
}
|
||||||
|
|
||||||
loadCollections() {
|
loadCollections() {
|
||||||
const me = this;
|
const me = this;
|
||||||
@@ -1050,8 +983,6 @@ class APITester {
|
|||||||
let model = this.apiRequests[index];
|
let model = this.apiRequests[index];
|
||||||
me.showLoadingOverlay();
|
me.showLoadingOverlay();
|
||||||
|
|
||||||
//console.log('model.collectionId: '+ model.collectionId);
|
|
||||||
|
|
||||||
this.currentAjaxRequest = $.ajax({
|
this.currentAjaxRequest = $.ajax({
|
||||||
url: `/mgmt/collections/${model.collectionId}/apis/save.do`,
|
url: `/mgmt/collections/${model.collectionId}/apis/save.do`,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@@ -1092,7 +1023,6 @@ class APITester {
|
|||||||
path: '',
|
path: '',
|
||||||
headers: [],
|
headers: [],
|
||||||
queryParams: [],
|
queryParams: [],
|
||||||
variables: [],
|
|
||||||
requestBody: '',
|
requestBody: '',
|
||||||
preRequestScript: '',
|
preRequestScript: '',
|
||||||
postRequestScript: '',
|
postRequestScript: '',
|
||||||
@@ -1192,14 +1122,9 @@ class APITester {
|
|||||||
deleteApiRequest(event) {
|
deleteApiRequest(event) {
|
||||||
let collectionId = $(event.currentTarget).closest('button').data('collection');
|
let collectionId = $(event.currentTarget).closest('button').data('collection');
|
||||||
let apiId = $(event.currentTarget).closest('.confirm_delete_api').data('id');
|
let apiId = $(event.currentTarget).closest('.confirm_delete_api').data('id');
|
||||||
console.log(event.currentTarget);
|
|
||||||
console.log($(event.currentTarget));
|
|
||||||
console.log('deleteApiRequest: ' + apiId);
|
|
||||||
console.log('collectionId: ' + collectionId);
|
|
||||||
let apiIndex = this.apiRequests.findIndex(function (api) {
|
let apiIndex = this.apiRequests.findIndex(function (api) {
|
||||||
return api.id === apiId;
|
return api.id === apiId;
|
||||||
});
|
});
|
||||||
console.log(apiIndex);
|
|
||||||
if (apiIndex >= 0) {
|
if (apiIndex >= 0) {
|
||||||
this.closeTabWithApiIndex(apiIndex);
|
this.closeTabWithApiIndex(apiIndex);
|
||||||
}
|
}
|
||||||
@@ -1224,11 +1149,8 @@ class APITester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
closeTabWithApiIndex(index) {
|
closeTabWithApiIndex(index) {
|
||||||
console.log(index);
|
|
||||||
if (index !== undefined) {
|
if (index !== undefined) {
|
||||||
//console.log('closeTabWithApiIndex: ' + index);
|
|
||||||
const model = this.apiRequests[index];
|
const model = this.apiRequests[index];
|
||||||
console.log(model);
|
|
||||||
this.apiRequests.splice(index, 1);
|
this.apiRequests.splice(index, 1);
|
||||||
|
|
||||||
let apiRequestTabTitle = $(this.apiTabTitleTarget);
|
let apiRequestTabTitle = $(this.apiTabTitleTarget);
|
||||||
|
|||||||
Reference in New Issue
Block a user