diff --git a/Backend/mocked-services/src/main/java/com/r11/tools/controller/MockController.java b/Backend/mocked-services/src/main/java/com/r11/tools/controller/MockController.java index 184f5e7..7187ed2 100644 --- a/Backend/mocked-services/src/main/java/com/r11/tools/controller/MockController.java +++ b/Backend/mocked-services/src/main/java/com/r11/tools/controller/MockController.java @@ -188,6 +188,7 @@ public class MockController { MockedMessageDto mockedMessageDto = klausService.getMockedResponse(clientUUID, mockedResponseId); HttpHeaders httpHeaders = new HttpHeaders(); if (mockedMessageDto.getHttpHeaders() != null) mockedMessageDto.getHttpHeaders().forEach(httpHeaders::set); + httpHeaders.add("Content-Type", mockedMessageDto.getMediaType()); return new ResponseEntity<>(mockedMessageDto.getMessageBody(), httpHeaders, Objects.requireNonNull(HttpStatus.valueOf(mockedMessageDto.getHttpStatus()))); } diff --git a/Backend/mocked-services/src/main/resources/static/html/mock.html b/Backend/mocked-services/src/main/resources/static/html/mock.html index e3b6254..d3ff264 100644 --- a/Backend/mocked-services/src/main/resources/static/html/mock.html +++ b/Backend/mocked-services/src/main/resources/static/html/mock.html @@ -15,7 +15,7 @@
-

MockedServices v1.0.0

+

MockedServices

diff --git a/Frontend/assets/css/frame.css b/Frontend/assets/css/frame.css index 70d0b07..c6a6ba2 100644 --- a/Frontend/assets/css/frame.css +++ b/Frontend/assets/css/frame.css @@ -41,7 +41,7 @@ div#header { grid-column: 1; } -iframe#frame { +iframe#iframe { flex-grow: 1; background-color: #FFFFFF; } diff --git a/Frontend/assets/scripts/dyn_host.js b/Frontend/assets/scripts/dyn_host.js deleted file mode 100644 index efdc4c1..0000000 --- a/Frontend/assets/scripts/dyn_host.js +++ /dev/null @@ -1,6 +0,0 @@ -$(document).ready( function() { - document.getElementById("rest-mock").href = - window.location.protocol + "//" + window.location.hostname + ":8097"; - -}); - \ No newline at end of file diff --git a/Frontend/assets/scripts/frame.js b/Frontend/assets/scripts/frame.js index 15cd0fa..493333a 100644 --- a/Frontend/assets/scripts/frame.js +++ b/Frontend/assets/scripts/frame.js @@ -1,6 +1,51 @@ +const tools = new Map(); +/** + * This functions imports other js file. I hate this solution, but other didn't work. + * + * @function + * @name importScript + * @kind function + * @param {any} url + * @returns {void} + */ +function importScript(url) { + var script = document.createElement("script"); + script.src = url; + document.head.appendChild(script); +} + +/** + * Get address of Mock Services + * + * @function + * @name getMockHost + * @kind function + * @returns {string} + */ +function getMockHost() { + return window.location.protocol + "//" + window.location.hostname + ":8097"; +} + +/** + * Function called after page is loaded + * + * @function + * @name init + * @kind function + * @returns {void} + */ function init() { - changeActiveTools('xmlTool', 'XML'); + + tools.set("xpath", "tools/xpath.html"); + tools.set("xsd", "tools/xsd.html"); + tools.set("xslt", "tools/xslt.html"); + tools.set("xmlform", "tools/xmlFormatter.html"); + tools.set("jsonform", "tools/jsonFormatter.html"); + tools.set("mock", getMockHost()); + + changeActiveTools('XML'); + loadLastPage(); } /** @@ -12,26 +57,65 @@ function init() { * @param {any} activeClass class of elements that have to be shown * @param {any} activeCategoryButton class of category button that has to be active */ -function changeActiveTools(activeClass, activeCategoryButton) { - let tools = document.getElementById("toolList").children +function changeActiveTools(activeCategoryButton) { + let toolList = document.getElementById("toolList").children; + let categoryToClass = new Map([["XML", "xmlTool"], + ["JSON", "jsonTool"], + ["REST", "restTool"]]); - for (i = 0; i < tools.length; i++) { - if (tools[i].classList.contains(activeClass)) { - tools[i].style.display = "block"; - } - else { - tools[i].style.display = "none"; - } + let activeClass = categoryToClass.get(activeCategoryButton.toUpperCase()); + if(activeClass == null) return; + + for (i = 0; i < toolList.length; i++) { + if (toolList[i].classList.contains(activeClass)) + toolList[i].style.display = "block"; + else + toolList[i].style.display = "none"; } - let categories = document.getElementById("menu").children + let categoryList = document.getElementById("menu").children; - for (i = 0; i < categories.length; i++) { - if (categories[i].innerText == activeCategoryButton) { - categories[i].classList.add("active") - } - else { - categories[i].classList.remove("active") - } + for (i = 0; i < categoryList.length; i++) { + if (categoryList[i].innerText == activeCategoryButton) + categoryList[i].classList.add("active"); + else + categoryList[i].classList.remove("active"); } +} + +/** + * Function that changes active tool + * + * @function + * @name changeTool + * @kind function + * @param {any} tool + * @returns {void} + */ +function changeTool(tool) { + const url = tools.get(tool); + localStorage.setItem("lastPage", tool); + document.getElementById("iframe").src = url; +} + +/** + * Function that loads last used tool and sets active category accordingly + * + * @function + * @name loadLastPage + * @kind function + * @returns {void} + */ +function loadLastPage() { + const lastPage = localStorage.getItem("lastPage"); + switch (lastPage) { // XML category is default. + case "jsonform": + changeActiveTools('JSON'); + break; + case "mock": + changeActiveTools('REST'); + break; + + } + document.getElementById("iframe").src = tools.get(lastPage); } \ No newline at end of file diff --git a/Frontend/index.html b/Frontend/index.html index abb8dbe..4073ca4 100644 --- a/Frontend/index.html +++ b/Frontend/index.html @@ -4,7 +4,6 @@ - @@ -22,9 +21,9 @@
@@ -34,14 +33,12 @@
- +
diff --git a/docker-compose.yml b/docker-compose.yml index 6a620bb..c317aaf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,9 @@ services: redis: image: 'redis' restart: "no" + volumes: + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro xmltools-frontend: build: ./Frontend @@ -11,6 +14,9 @@ services: image: xmltools-frontend ports: - 8086:80 + volumes: + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro xmltools-backend: build: ./Backend/tools-services @@ -25,6 +31,9 @@ services: image: xmltools-libxml-backend ports: - 8082:80 + volumes: + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro xmltools-mocked-services: build: @@ -38,6 +47,9 @@ services: - redis environment: SPRING_PROFILES_ACTIVE: DEV + volumes: + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro swagger: image: "swaggerapi/swagger-ui:latest" @@ -63,6 +75,9 @@ services: command: - "-e" - "--strict.perms=false" + volumes: + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro networks: default: