From 92df5abf9c1a68d1b02809da7d585b1d5f930a49 Mon Sep 17 00:00:00 2001 From: Adam Bem Date: Thu, 18 May 2023 15:05:28 +0200 Subject: [PATCH] XML request bodies are now formatted --- .../assets/scripts/tools/mock/uianimation.js | 41 +++++++++++++-- Frontend/tools/mock.html | 52 +++++++++---------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/Frontend/assets/scripts/tools/mock/uianimation.js b/Frontend/assets/scripts/tools/mock/uianimation.js index ca8755e..29c393a 100644 --- a/Frontend/assets/scripts/tools/mock/uianimation.js +++ b/Frontend/assets/scripts/tools/mock/uianimation.js @@ -77,10 +77,41 @@ function showHeadersHistory(element){ showPopup(); } +function formatXML(xml) { + const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify"; + var data = { + data: xml, + process: "", + processor: "libxml", + version: "1.0" + } + + console.log("formattedXML"); + fetch(address, { + method: 'POST', + body: JSON.stringify(data) + }) + .then(async (response) => { + const promise = response.json(); + if (!response.ok) { + throw Error(await promise); + } + return promise; + }) + .then((data) => { + document.getElementById('code-highlight-content').innerText = data.result; + highlightSyntax('code-highlight-content'); + //console.log(data.result); + }) + .catch((error) => { + console.error('Error:', error); + }); + +} + function showRequestBody(element){ requestBody = ""; historyRequestBody = historyJson[element.id].requestBody; - console.log(historyRequestBody); switch(historyJson[element.id].headers["content-type"]){ case "application/json":{ const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting" @@ -97,6 +128,7 @@ function showRequestBody(element){ }) .then((data) => { requestBody = ''+data.data+''; + document.getElementById('history-request-body-content').innerHTML = requestBody; hljs.highlightElement(document.getElementById('history-request-body-content')); }) @@ -106,13 +138,14 @@ function showRequestBody(element){ break; } case "application/xml":{ - document.getElementById('code-highlight-content').innerText = historyRequestBody; - highlightSyntax('code-highlight-content'); + //document.getElementById('code-highlight-content').innerText = historyRequestBody; + formatXML(historyRequestBody); + break; } default:{ - requestBody = ''+historyRequestBody+'' + requestBody = ''+historyRequestBody+''; document.getElementById('history-request-body-content').innerText = requestBody; hljs.highlightElement(document.getElementById('history-request-body-content')); } diff --git a/Frontend/tools/mock.html b/Frontend/tools/mock.html index ffc5e09..707f9e7 100644 --- a/Frontend/tools/mock.html +++ b/Frontend/tools/mock.html @@ -9,36 +9,36 @@ - +