diff --git a/Frontend/assets/css/tools/mock/common.css b/Frontend/assets/css/tools/mock/common.css index b7f1646..f814529 100644 --- a/Frontend/assets/css/tools/mock/common.css +++ b/Frontend/assets/css/tools/mock/common.css @@ -7,6 +7,7 @@ @import url('r11modal.css'); @import url('r11flexbox.css'); @import url('r11popup.css'); +@import url('../../highlight.css'); @font-face { font-family: 'Material Icons'; diff --git a/Frontend/assets/css/tools/mock/r11popup.css b/Frontend/assets/css/tools/mock/r11popup.css index 3b7f12f..ab9690d 100644 --- a/Frontend/assets/css/tools/mock/r11popup.css +++ b/Frontend/assets/css/tools/mock/r11popup.css @@ -16,6 +16,9 @@ .popup-body{ min-width: 33%; + max-width: 60%; + max-height: 70%; + overflow: scroll; background-color: white; box-shadow: 10px 10px 5px lightblue; min-height: 45%; @@ -47,6 +50,14 @@ display:none; } +.hidden-popup-type{ + display: none; +} + +#history-request-body{ + text-align: justify; +} + @keyframes blur { 0% { backdrop-filter: blur(0px); diff --git a/Frontend/assets/css/tools/mock/r11tables.css b/Frontend/assets/css/tools/mock/r11tables.css index 9762b67..fe1c17f 100644 --- a/Frontend/assets/css/tools/mock/r11tables.css +++ b/Frontend/assets/css/tools/mock/r11tables.css @@ -70,15 +70,23 @@ color: white; } +.table-default td{ + text-align: center; +} + #header-table tr td { border: 1px black solid; - padding: 1%; + padding: 1.5%; + } #header-table{ border-collapse: collapse; + width: 100%; + height: 100%; } #historyTable, td{ padding: 1%; + overflow-x: scroll; } \ No newline at end of file diff --git a/Frontend/assets/scripts/tools/mock/historyloader.js b/Frontend/assets/scripts/tools/mock/historyloader.js index 48e26d4..4c54671 100644 --- a/Frontend/assets/scripts/tools/mock/historyloader.js +++ b/Frontend/assets/scripts/tools/mock/historyloader.js @@ -46,15 +46,25 @@ function historyToHtml(){ for(let i=0; i' + - '' + historyJson[i].dateTimeStamp + '' + + '' + parseTimeStamp(historyJson[i].dateTimeStamp) + '' + '' + historyJson[i].httpMethod + '' + - '' + historyJson[i].requestBody + '' + + '' + parseRequestBody(historyJson[i].requestBody, i) + '' + ' ' + ''; } return innerHTML; } +function parseRequestBody(requestBody,i){ + return requestBody.length == 0 ? + "No request body" : + '' +} + +function parseTimeStamp(timeStamp){ + return timeStamp.substring(0,19).replace('T',' '); +} + function parseHeaders(pos){ parsedJson = new Map(); headers = historyJson[pos].headers diff --git a/Frontend/assets/scripts/tools/mock/popup.js b/Frontend/assets/scripts/tools/mock/popup.js new file mode 100644 index 0000000..0d2b91f --- /dev/null +++ b/Frontend/assets/scripts/tools/mock/popup.js @@ -0,0 +1,34 @@ + +function switchPopups (neededPopupOption) { + $('.hiddable-popup-option').addClass('hidden-popup-type'); + $('#'+neededPopupOption).removeClass('hidden-popup-type'); + } + +function showPopup(){ + $('.popup-flex').removeClass('hiddable-container'); +} + +function hidePopup(){ + $('.popup-flex').addClass('hiddable-container'); + $('.hiddable-popup-option').addClass('hidden-popup-type'); +} + +/* +* Event listener that's close the popup when user clicks out of a popup. +*/ + +window.addEventListener( + 'click' , + (clickedElement) => { + if(!document.getElementById('popup-body').contains(clickedElement.target) && clickedElement.target.className == 'popup-flex' ) { + hidePopup(); + } + } +); + +$('.popup-button-close').click( + () => { + hidePopup(); + $('.hiddable-popup-option').addClass('hidden-popup-type') + } +); \ No newline at end of file diff --git a/Frontend/assets/scripts/tools/mock/uianimation.js b/Frontend/assets/scripts/tools/mock/uianimation.js index fd6f60e..ca8755e 100644 --- a/Frontend/assets/scripts/tools/mock/uianimation.js +++ b/Frontend/assets/scripts/tools/mock/uianimation.js @@ -33,11 +33,6 @@ const historyFilterSwitch = function(){ $("#optional").click(changeAdvancedVisibility); $('#historyTab').click(showHistory); $('#btn-history-filter').click(historyFilterSwitch); -$('.popup-button-close').click( - () => { - $('.popup-flex').addClass('hiddable-container'); - } -); const tabitem = $('.tabitem'); @@ -77,19 +72,55 @@ function showHeadersHistory(element){ '' } ); - - $('.popup-flex').removeClass('hiddable-container'); document.getElementById('header-history-table-body').innerHTML = historyTable; + switchPopups('history-headers-table'); + showPopup(); } - window.addEventListener( - 'click' , - (clickedElement) => { - console.log(clickedElement.target); - if(!document.getElementById('header-history-popup').contains(clickedElement.target) && clickedElement.target.className == 'popup-flex' ) { - $('.popup-flex').addClass('hiddable-container'); - } + +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" + fetch(address, { + method: 'POST', + body: historyRequestBody + }) + .then(async (response) => { + const promise = response.json(); + if (!response.ok) { + throw Error(await promise); + } + return promise; + }) + .then((data) => { + requestBody = ''+data.data+''; + document.getElementById('history-request-body-content').innerHTML = requestBody; + hljs.highlightElement(document.getElementById('history-request-body-content')); + }) + .catch((error) => { + console.error('Error:', error); + }); + break; } - ); + case "application/xml":{ + document.getElementById('code-highlight-content').innerText = historyRequestBody; + highlightSyntax('code-highlight-content'); + break; + } + + default:{ + requestBody = ''+historyRequestBody+'' + document.getElementById('history-request-body-content').innerText = requestBody; + hljs.highlightElement(document.getElementById('history-request-body-content')); + } + } + switchPopups('history-request-body'); + showPopup(); +} + function focusInTip(element){ showTip(element); focusedField = true; diff --git a/Frontend/tools/mock.html b/Frontend/tools/mock.html index e426beb..ffc5e09 100644 --- a/Frontend/tools/mock.html +++ b/Frontend/tools/mock.html @@ -10,11 +10,11 @@