From 47107b8fd4270e72a4df91e882c378b35cfda73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=98=84=EC=84=B1=ED=95=84?= Date: Tue, 16 May 2023 19:03:37 +0900 Subject: [PATCH] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=84=B0=20save=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/dto/ApiRequestKeyValueDTO.java | 2 +- .../resources/templates/page/apiTester.html | 47 +++++++++++++++---- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/eactive/httpmockserver/client/dto/ApiRequestKeyValueDTO.java b/src/main/java/com/eactive/httpmockserver/client/dto/ApiRequestKeyValueDTO.java index c3e4548..f73eee0 100644 --- a/src/main/java/com/eactive/httpmockserver/client/dto/ApiRequestKeyValueDTO.java +++ b/src/main/java/com/eactive/httpmockserver/client/dto/ApiRequestKeyValueDTO.java @@ -32,6 +32,6 @@ public class ApiRequestKeyValueDTO { } public String toString() { - return (enabled?"//":"")+ key + "=" + value; + return (enabled?"":"//")+ key + "=" + value; } } diff --git a/src/main/resources/templates/page/apiTester.html b/src/main/resources/templates/page/apiTester.html index a33b377..8ed3b2f 100644 --- a/src/main/resources/templates/page/apiTester.html +++ b/src/main/resources/templates/page/apiTester.html @@ -439,13 +439,13 @@ target.find('.request_headers').on('click', 'button', function () { if ($(this).hasClass('btn_remove')) { - controller.removeHeader(idx, $(this).attr("data-id")); + controller.removeHeader(idx, $(this).data("id")); } }); target.find('.query_params').on('click', 'button', function () { if ($(this).hasClass('btn_remove')) { - controller.removeQueryParam(idx, $(this).attr("data-id")); + controller.removeQueryParam(idx, $(this).data("id")); } }); @@ -465,11 +465,17 @@ target.find('.send').click(function () { controller.send(idx); }); + target.find('.save').attr('data-collection', ); //TODO + target.find('.save').click(function(){ + controller.saveAPIRequest(idx); + }); + let me = this; + require(['vs/editor/editor.main'], function () { let requestBodyEditor = monaco.editor.create(target.find(".request_body")[0], { - value: '', + value: model.requestBody, language: 'json', theme: 'vs-light', automaticLayout: true @@ -556,7 +562,7 @@ template.find('button.new_collection').attr('data-bs-target', '#btn_collection_' + i); template.find('button.delete_collection').attr('data-id', collections[i].id); template.find('button.delete_collection').on('click', function () { - $('#confirm_delete_modal').find('.confirm_delete').attr('data-id', $(this).attr('data-id')); + $('#confirm_delete_modal').find('.confirm_delete').attr('data-id', $(this).data('id')); $('#confirm_delete_modal').modal('show'); }); @@ -570,14 +576,13 @@ link.attr('data-collection', collections[i].id); link.attr('data-id', collections[i].apis[j].id); link.on('click', function () { - controller.openApiRequest($(this).attr('data-collection'), $(this).attr('data-id')); + controller.openApiRequest($(this).attr('data-collection'), $(this).data('id')); }) btn.attr('data-collection', collections[i].id); btn.attr('data-id', collections[i].apis[j].id); btn.on('click', function () { - //controller.deleteApiRequest($(this).attr('data-collection'), $(this).attr('data-id')); - $('#confirm_delete_api_modal').find('.confirm_delete_api').attr('data-id', $(this).attr('data-id')); - $('#confirm_delete_api_modal').find('.confirm_delete_api').attr('data-collection', $(this).attr('data-collection')); + $('#confirm_delete_api_modal').find('.confirm_delete_api').attr('data-id', $(this).data('id')); + $('#confirm_delete_api_modal').find('.confirm_delete_api').attr('data-collection', $(this).data('collection')); $('#confirm_delete_api_modal').modal('show'); }) template.find('.collapse ul').append(collectionApiTemplate); @@ -691,6 +696,13 @@ contentType: 'application/json', success: function (data) { collections = data; + for (let i = 0; i < collections.length; i++) { + if(collections[i].apis !== undefined){ + for (let j = 0; j< collections[i].apis.length; j++) { + collections[i].apis[j].collectionId = collections[i].id; + } + } + } }, error: function (response, textStatus, errorThrown) { controller.hideLoadingOverlay(); @@ -742,6 +754,25 @@ } }); }, + saveAPIRequest: function(idx){ + let model = apiRequests[idx]; + console.log(model); + + this.currentAjaxRequest = $.ajax({ + url: '/mgmt/collections/{id}/apis/save.do'.replace('{id}', model.collectionId), + type: 'POST', + contentType: 'application/json', + data: JSON.stringify(model), + success: function (data) { + }, + error: function (response, textStatus, errorThrown) { + controller.hideLoadingOverlay(); + }, + complete: function () { + controller.hideLoadingOverlay(); + } + }); + }, addAPIRequest: function (collectionId) { let name = 'New Request';