widlam/refactoring/issue#120 (#128)

Co-authored-by: mikolaj widla <mikolaj.widla@gmail.com>
Co-authored-by: widlam <mikolaj.widla@gmail.com>
Co-authored-by: Adam Bem <adam.bem@zoho.eu>
Reviewed-on: #128
Co-authored-by: Mikolaj Widla <widlam@noreply.example.com>
Co-committed-by: Mikolaj Widla <widlam@noreply.example.com>
This commit is contained in:
2023-03-23 10:16:47 +01:00
committed by Adam Bem
parent 19de505ca4
commit 71f9ae9553
6 changed files with 220 additions and 326 deletions

View File

@@ -90,7 +90,7 @@ div#copyright a, a:visited, a:active {
backdrop-filter: blur(10px);
}
#toolListRow a {
.toolListRow a {
display: block;
color: white;
text-align: center;
@@ -98,7 +98,7 @@ div#copyright a, a:visited, a:active {
text-decoration: none;
}
#toolListRow a:hover {
.toolListRow a:hover {
background-color: #2A93B0;
color: white;
transform: scale(1.25, 1.25);

View File

@@ -3,15 +3,15 @@ const color_grey = "#6b6b6b";
const color_red = "#ff8f8f";
/**
* It clears default content of the element and sets it's color to black.
*
* @function
* @name clearDefaultContent
* @kind function
* @param {any} element to set
* @param {any} text to set
* @returns {void}
*/
* It clears default content of the element and sets it's color to black.
*
* @function
* @name clearDefaultContent
* @kind function
* @param {any} element to set
* @param {any} text to set
* @returns {void}
*/
function clearDefaultContent(element, text) {
if (element.value == text) {
element.value = "";
@@ -21,13 +21,38 @@ function clearDefaultContent(element, text) {
}
/**
* It clears all data fields.
* It returns the value of the element with id "processors".
*
* @function
* @name getProcessor
* @kind function
* @returns {any}
*/
function getProcessor() {
return document.getElementById("processors").value;
}
/**
* It returns the value of the element with id "versions".
*
* @function
* @name clearDataField
* @name getVersion
* @kind function
* @returns {any}
*/
function clearDataField(){
function getVersion() {
return document.getElementById("versions").value;
}
/**
* It clears all data fields.
*
* @function
* @name clearDataField
* @kind function
*/
function clearDataField() {
document.getElementById("xmlArea").value = "";
document.getElementById("xmlArea").style.color = null;
document.getElementById("xmlArea").style.backgroundColor = null;
@@ -37,28 +62,37 @@ function clearDataField(){
document.getElementById("transformArea").style.backgroundColor = null;
}
/**
* It fills the XML area with a sample XML.
*
* @function
* @name fillDefaultXML
* @kind function
* @param {any} element
* @returns {void}
*/
function fillDefaultXML(element) {
if(element.classList.contains("active")){
if (element.classList.contains("active")) {
const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086";
clearDefaultContent(document.getElementById("xmlArea"), "Insert XML here");
fetch(serverAddress + "/assets/samples/sampleXml.xml")
.then(response => response.text())
.then((exampleData) => {
document.getElementById("xmlArea").value = exampleData;
document.getElementById("xmlArea").style.backgroundColor = null;
})
}
}
.then(response => response.text())
.then((exampleData) => {
document.getElementById("xmlArea").value = exampleData;
document.getElementById("xmlArea").style.backgroundColor = null;
})
}
}
/**
* It sets default content for the element an changes it's color to grey
*
* @function
* @name setDefaultContent
* @kind function
* @param {any} element to set
* @param {any} text to set
*/
* It sets default content for the element an changes it's color to grey
*
* @function
* @name setDefaultContent
* @kind function
* @param {any} element to set
* @param {any} text to set
*/
function setDefaultContent(element, text) {
if (element.value == "") {
var id = element.getAttribute('id');
@@ -81,14 +115,14 @@ function setDefaultContent(element, text) {
}
/**
* It hides list for specified version of XPath
*
* @function
* @name hideList
* @kind function
* @param {any} collList class name of list to hide
* @returns {void}
*/
* It hides list for specified version of XPath
*
* @function
* @name hideList
* @kind function
* @param {any} collList class name of list to hide
* @returns {void}
*/
function hideList(collList) {
for (i = 0; i < collList.length; i++) {
if (collList[i].nextElementSibling !== null) {
@@ -101,27 +135,27 @@ function hideList(collList) {
}
/**
* It checks if the text is a default text.
*
* @function
* @name checkDefault
* @kind function
* @param {any} text
* @returns {boolean}
*/
function checkDefault(text){
* It checks if the text is a default text.
*
* @function
* @name checkDefault
* @kind function
* @param {any} text
* @returns {boolean}
*/
function checkDefault(text) {
return defaultStrings.includes(text);
}
/**
* It show list for specified version of XPath
*
* @function
* @name showList
* @kind function
* @param {any} collList class name of list to hide
* @returns {void}
*/
* It show list for specified version of XPath
*
* @function
* @name showList
* @kind function
* @param {any} collList class name of list to hide
* @returns {void}
*/
function showList(collList) {
for (i = 0; i < collList.length; i++) {
collList[i].style.display = 'block';
@@ -129,20 +163,19 @@ function showList(collList) {
}
/**
* A function that is used to fold/unfold collapsible elements.
*
* @function
* @name smoothFoldElement
* @kind function
* @param {any} element
* @param {any} toogleState
* @param {any} toggleParrent
* @returns {void}
*/
function smoothFoldElement(element, toogleState, toggleParrent){
* A function that is used to fold/unfold collapsible elements.
*
* @function
* @name smoothFoldElement
* @kind function
* @param {any} element
* @param {any} toogleState
* @param {any} toggleParrent
* @returns {void}
*/
function smoothFoldElement(element, toogleState, toggleParrent) {
if (toogleState) {
console.log("DUPA");
if(toggleParrent){
if (toggleParrent) {
element.parentElement.style.maxHeight = "0px";
}
@@ -161,13 +194,13 @@ function smoothFoldElement(element, toogleState, toggleParrent){
}
/**
* Set tooltip info, function is called by onClick handlers
*
* @function
* @name refreshTooltip
* @kind function
* @returns {void}
*/
* Set tooltip info, function is called by onClick handlers
*
* @function
* @name refreshTooltip
* @kind function
* @returns {void}
*/
function refreshTooltip() {
var resizeList = document.getElementsByClassName("collapsibleData");
console.log("collDataList: " + resizeList.length)
@@ -178,17 +211,17 @@ function refreshTooltip() {
/**
* A function that performs a request to the server.
*
* @function
* @name performRequest
* @kind function
* @param {any} endpoint of target service
* @param {any} checkXML enable checking for empty XML
* @param {any} checkTransform enable checking for empty transform data
* @returns {false | undefined}
*/
function performRequest(endpoint, checkXML, checkTransform){
* A function that performs a request to the server.
*
* @function
* @name performRequest
* @kind function
* @param {any} endpoint of target service
* @param {any} checkXML enable checking for empty XML
* @param {any} checkTransform enable checking for empty transform data
* @returns {false | undefined}
*/
function performRequest(endpoint, checkXML, checkTransform) {
const sourceId = "xmlArea";
const transformId = "transformArea";
var xmlData = document.getElementById(sourceId).value.trim();
@@ -198,19 +231,19 @@ function performRequest(endpoint, checkXML, checkTransform){
if (getProcessor() == "libxml") {
port = 8082;
}
var empty = false;
if (defaultStrings.includes(xmlData) && checkXML) {
document.getElementById(sourceId).style.backgroundColor = color_red;
xmlData = "";
empty = true;
document.getElementById(sourceId).style.backgroundColor = color_red;
xmlData = "";
empty = true;
}
if (defaultStrings.includes(transformData) && checkTransform) {
document.getElementById(transformId).style.backgroundColor = color_red;
empty = true;
}
if (!empty) {
restRequest(port, endpoint, xmlData, transformData).then(function(result) {
restRequest(port, endpoint, xmlData, transformData).then(function (result) {
document.getElementById("resultArea").value = result.result;
document.getElementById("procinfo").innerText = ' Computed using '.concat(" ", result.processor);
if (result.status = "OK") {
@@ -220,7 +253,7 @@ function performRequest(endpoint, checkXML, checkTransform){
procinfo.style.color = "#aa3030";
}
});
}else{
} else {
document.getElementById("resultArea").value = "No data provided!";
return false;
}
@@ -228,18 +261,18 @@ function performRequest(endpoint, checkXML, checkTransform){
}
/**
* Function that prepares data to send and handles response
*
* @function
* @name performFormatRequest
* @kind function
* @param {any} endpoint of target service
* @param {any} checkXML enable checking for empty XML
* @param {any} sourceId ID of element to get XML from
* @param {any} targetId ID of element to write formatted XML
* @returns {void}
*/
function performFormatRequest(endpoint, checkXML, sourceId, targetId){
* Function that prepares data to send and handles response
*
* @function
* @name performFormatRequest
* @kind function
* @param {any} endpoint of target service
* @param {any} checkXML enable checking for empty XML
* @param {any} sourceId ID of element to get XML from
* @param {any} targetId ID of element to write formatted XML
* @returns {void}
*/
function performFormatRequest(endpoint, checkXML, sourceId, targetId) {
const sourceElement = document.getElementById(sourceId);
const targetElement = document.getElementById(targetId);
const infoElement = document.getElementById("formatinfo");
@@ -248,13 +281,13 @@ function performFormatRequest(endpoint, checkXML, sourceId, targetId){
var empty = false;
if (defaultStrings.includes(xmlData) && checkXML) {
sourceElement.style.backgroundColor = color_red;
xmlData = "";
empty = true;
sourceElement.style.backgroundColor = color_red;
xmlData = "";
empty = true;
}
if (!empty) {
restRequest(port, endpoint, xmlData, "").then(function(result) {
restRequest(port, endpoint, xmlData, "").then(function (result) {
console.log(result);
if (result.status == "OK") {
targetElement.value = result.result;
@@ -275,36 +308,36 @@ function performFormatRequest(endpoint, checkXML, sourceId, targetId){
/**
* Form REST request, send and return received data
*
* @async
* @function
* @name restRequest
* @kind function
* @param {any} port of target service
* @param {any} endpoint of target service
* @param {any} xmlData XML that will be sent
* @param {any} transformData data used to transform given XML
* @returns {Promise<any>}
*/
* Form REST request, send and return received data
*
* @async
* @function
* @name restRequest
* @kind function
* @param {any} port of target service
* @param {any} endpoint of target service
* @param {any} xmlData XML that will be sent
* @param {any} transformData data used to transform given XML
* @returns {Promise<any>}
*/
async function restRequest(port, endpoint, xmlData, transformData) {
const escapeChar = "specialEscapeChar";
const addr = window.location.protocol + "//" + window.location.hostname + ":" + port + "/" + endpoint;
if(defaultStrings.includes(xmlData)){
if (defaultStrings.includes(xmlData)) {
xmlData = "<empty/>";
}
// var data = xmlData.concat(escapeChar, transformData);
// const url = addr.concat("?escapechar=", escapeChar, "&processor=", getProcInfo());
var jsonData = JSON.stringify({
"data" : xmlData,
"process" : transformData,
"processor" : getProcessor(),
"version" : getVersion()
"data": xmlData,
"process": transformData,
"processor": getProcessor(),
"version": getVersion()
});
// console.log(jsonData);
var init = {
@@ -315,10 +348,10 @@ async function restRequest(port, endpoint, xmlData, transformData) {
method: "POST"
};
var request = new Request(addr, init);
var result = await fetch(request).then(response => {
return response.text().then(function(text) {
return response.text().then(function (text) {
return JSON.parse(text);
});

View File

@@ -9,8 +9,7 @@
<script src="assets/scripts/frame.js"></script>
<!-- <link rel="stylesheet" href="common.css"> -->
<link rel="shortcut icon" href="assets/images/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="assets/images/favicon.ico" type="image/x-icon">
</head>
<body onload="init()">
@@ -30,14 +29,14 @@
<div id="content">
<div id="leftBar">
<ul id="toolList">
<li id="toolListRow" class="dynamic restTool" style="display: none;">
<li class="dynamic restTool toolListRow" style="display: none;">
<a id="rest-mock" href="http://tools.zipper.release11.com:8097/" target="iframe">REST Mock</a>
</li>
<li id="toolListRow" class="xmlTool"><a href="./tools/xpath.html" target="iframe">XPath</a></li>
<li id="toolListRow" class="xmlTool"><a href="./tools/xslt.html" target="iframe">XSLT</a></li>
<li id="toolListRow" class="xmlTool"><a href="./tools/xsd.html" target="iframe">XSD</a></li>
<li id="toolListRow" class="xmlTool"><a href="tools/xmlFormatter.html" target="iframe">XML Formatter</a></li>
<li id="toolListRow" class="jsonTool" style="display: none;"><a href="tools/jsonFormatter.html" target="iframe">JSON Formatter</a></li>
<li class="toolListRow xmlTool"><a href="./tools/xpath.html" target="iframe">XPath</a></li>
<li class="toolListRow xmlTool"><a href="./tools/xslt.html" target="iframe">XSLT</a></li>
<li class="toolListRow xmlTool"><a href="./tools/xsd.html" target="iframe">XSD</a></li>
<li class="toolListRow xmlTool"><a href="tools/xmlFormatter.html" target="iframe">XML Formatter</a></li>
<li class="toolListRow jsonTool" style="display: none;"><a href="tools/jsonFormatter.html" target="iframe">JSON Formatter</a></li>
</ul>
<div id="copyright">
Build: [:VERSION:]<br>

View File

@@ -4,9 +4,8 @@
<head>
<!-- <link rel="stylesheet" href="../common.css"> -->
<!-- <link rel="stylesheet" href="styles.css"> -->
<script src="../assets/scripts/tools/jquery-3.6.0.slim.min.js"></script>
<link rel="stylesheet" href="../assets/css/tools/r11form.css">
<script src="../assets/scripts/tools/scripts.js"></script>
<script src="../assets/scripts/tools/scripts.js"> </script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8" />
</head>
@@ -131,7 +130,6 @@
</div>
[1.0] <a href="#" onClick="return false;"
class="hyperlink collapsible collapsibleMini collapseTrigger"><code>fn:position()</code></a>
<div class="content">
@@ -3384,16 +3382,12 @@
</div>
<script>
function processVersionSelector() {
var processor = getProcessor();
var hideableOptions = document.getElementsByClassName("hideable");
for (let i = 0; i < hideableOptions.length; i++) {
hideableOptions[i].style = "display: none;";
hideableOptions[i].style = "display: none;";
}
if (processor == "xalan" || processor == "libxml") {
var xalanOptions = document.getElementsByClassName("xalan");
@@ -3408,7 +3402,7 @@
saxonOptions[i].style = "";
}
document.getElementById("versions").selectedIndex = 3;
}
processTooltip();
@@ -3432,7 +3426,7 @@
showList(document.getElementsByName("collapse30"));
showList(document.getElementsByName("collapse31"));
console.log("collapsed 3.1");
} else if (filter == "collapse2.0"){
} else if (filter == "collapse2.0") {
document.getElementById("tooltipFunctionInfo").innerText = "XPath 1.0 & 2.0 functions";
showList(document.getElementsByName("collapse20"));
hideList(document.getElementsByName("collapse30"));
@@ -3444,39 +3438,8 @@
hideList(document.getElementsByName("collapse31"));
}
// if (checkDefault(document.getElementById("xmlArea").value.trim()) || document.getElementById("xmlArea").value.trim() == "") {
// document.getElementById("defaultXMLButton").classList.toggle("active", true);
// } else {
// document.getElementById("defaultXMLButton").classList.toggle("active", false);
// }
}
</script>
<script>
function getVersion() {
return document.getElementById("versions").value;
}
</script>
<script>
function getProcessor() {
return document.getElementById("processors").value;
}
</script>
<script>
function getProcInfo() {
var processVariables = document.getElementById("processors").value + "&version=" + getVersion();
return processVariables;
}
</script>
<script>
var triggerList = document.getElementsByClassName("collapseTrigger");
for (i = 0; i < triggerList.length; i++) {
console.log("trigger connected");
@@ -3486,7 +3449,7 @@
var collapsibleData = this.nextElementSibling;
} else {
var collapsibleData = this.parentElement.nextElementSibling;
}
console.log(collapsibleData);
@@ -3519,13 +3482,7 @@
}
});
}
</script>
<script>
</script>
<script>
function init() {
//Handle clicks in whole form and set info in tooltip
setDefaultContent(document.getElementById("xmlArea"), 'Insert XML here');
@@ -3543,8 +3500,8 @@
else if (targetID == "versions") {
processTooltip();
}
})
tool.addEventListener('click', event => {
//Check if script was called from textarea or selector
@@ -3564,8 +3521,8 @@
processTooltip();
})
}
</script>
</script>
</body>

View File

@@ -18,11 +18,11 @@
</div>
<div class="display-space-between">
<div style="text-align: center;">
<label for="processors">Select XSLT processor:</label>
<select name="processors" id="processors">
<option value="xalan">Xalan</option>
<option value="libxml">libXML</option>
</select>
<label for="processors">Select XSLT processor:</label>
<select name="processors" id="processors">
<option value="xalan">Xalan</option>
<option value="libxml">libXML</option>
</select>
</div>
<div>
<button class="action-button active" id="clearXMLButton" style="padding: 3px 10px;"
@@ -62,101 +62,20 @@
<div class="tooltip-window rwd-hideable">
<h2>What is XSD?</h2>
<p><b>XSD is a W3C recomedation that specifies how to describe the elements in XML document</b></p>
<p>XSD specifies data types, order and arity of elements in XML file.<br>
Main components of XSD file are:<br>
- Element declaration - declares properties of elements (names and namespaces)<br>
- Attribute declarations - declares properties of attributes<br>
- Simple and complex types:<br>
- - XSD provides 19 simple data types<br>
- - More complex types are declared using simple types and relationships<br>
</p>
<p>XSD specifies data types, order and arity of elements in XML file.<br>
Main components of XSD file are:<br>
- Element declaration - declares properties of elements (names and namespaces)<br>
- Attribute declarations - declares properties of attributes<br>
- Simple and complex types:<br>
- - XSD provides 19 simple data types<br>
- - More complex types are declared using simple types and relationships<br>
</p>
</div>
</div>
<!-- <script>
function getVersion() {
return document.getElementById("versions").value;
}
</script> -->
<script>
function processTooltip() {
console.log("processTooltip");
if (getProcInfo() == "xalan") {
document.getElementById("tooltipFunctionInfo").innerText = "XSLT 1.0 functions";
document.getElementById("processorTooltipInfo").innerText = "Supports XSLT 1.0";
hideList(document.getElementsByName("collapse30"));
} else {
document.getElementById("tooltipFunctionInfo").innerText = "XSLT 1.0, 2.0 & 3.0 functions";
document.getElementById("processorTooltipInfo").innerText = "Supports XSLT up to 3.0";
showList(document.getElementsByName("collapse30"));
}
}
</script>
<script>
function getProcessor() {
return document.getElementById("processors").value;
}
</script>
<script>
function getVersion() {
if (getProcInfo() == "xalan") {
return "1.0";
} else {
return "3.0";
}
}
</script>
<script>
function getProcInfo() {
var processVariables = document.getElementById("processors").value;// + "&version=" + document.getElementById("versions").value;
return processVariables;
}
</script>
<script>
var triggerList = document.getElementsByClassName("collapseTrigger");
for (i = 0; i < triggerList.length; i++) {
console.log("trigger connected");
triggerList[i].addEventListener("click", function () {
console.log("click");
var collapsible = this.parentElement;
var collapsibleData = this.nextElementSibling;
if (collapsibleData.style.maxHeight > "0px") {
collapsibleData.style.maxHeight = "0px";
this.classList.toggle("active", false);
if (!this.classList.contains("collapsibleMini")) {
collapsible.classList.toggle("active", false);
}
var subLists1 = collapsibleData.getElementsByClassName("content");
var subLists2 = collapsibleData.getElementsByClassName("active");
for (j = 0; j < subLists1.length; j++) {
subLists1[j].style.maxHeight = "0px";
}
for (j = 0; j < subLists2.length; j++) {
subLists2[j].classList.toggle("active", false);
}
} else {
collapsibleData.style.maxHeight = (collapsibleData.scrollHeight) + "px";
this.classList.toggle("active", true);
if (!this.classList.contains("collapsibleMini")) {
collapsible.classList.toggle("active", true);
} else {
var parentContent = this.closest(".content");
parentContent.style.maxHeight = (parentContent.scrollHeight + collapsibleData.scrollHeight) + "px";
}
}
});
}
</script>
<script>
function init() {
//Handle clicks in whole form and set info in tooltip
@@ -176,8 +95,24 @@
// console.log("clock");
})
}
function processTooltip() {
console.log("processTooltip");
if (getProcessor() == "xalan") {
document.getElementById("tooltipFunctionInfo").innerText = "XSLT 1.0 functions";
document.getElementById("processorTooltipInfo").innerText = "Supports XSLT 1.0";
hideList(document.getElementsByName("collapse30"));
} else {
document.getElementById("tooltipFunctionInfo").innerText = "XSLT 1.0, 2.0 & 3.0 functions";
document.getElementById("processorTooltipInfo").innerText = "Supports XSLT up to 3.0";
showList(document.getElementsByName("collapse30"));
}
}
</script>
</body>
</html>
</html>

View File

@@ -18,12 +18,12 @@
</div>
<div class="display-space-between">
<div style="text-align: center;">
<label for="processors">Select XSLT processor:</label>
<select name="processors" id="processors">
<option value="saxon">Saxon</option>
<option value="xalan">Xalan</option>
<option value="libxml">libXML</option>
</select>
<label for="processors">Select XSLT processor:</label>
<select name="processors" id="processors">
<option value="saxon">Saxon</option>
<option value="xalan">Xalan</option>
<option value="libxml">libXML</option>
</select>
</div>
<div>
<button class="action-button active" id="clearXMLButton" style="padding: 3px 10px;"
@@ -57,7 +57,8 @@
<label for="resultArea"><b>Transform result:<span id="procinfo"></span></b></label>
<textarea disabled id="resultArea" name="resultArea" rows="10"
class="textarea-300 bordered-field vertically-resizeable max-width" style="margin-bottom: 50px;" ></textarea>
class="textarea-300 bordered-field vertically-resizeable max-width"
style="margin-bottom: 50px;"></textarea>
</div>
</div>
@@ -1135,17 +1136,10 @@
</div>
<!-- <script>
function getVersion() {
return document.getElementById("versions").value;
}
</script> -->
<script>
function processTooltip() {
console.log("processTooltip");
if (getProcInfo() == "xalan" || getProcInfo() == "libxml") {
if (getProcessor() == "xalan" || getProcessor() == "libxml") {
document.getElementById("tooltipFunctionInfo").innerText = "XSLT 1.0 functions";
document.getElementById("processorTooltipInfo").innerText = "Supports XSLT 1.0";
hideList(document.getElementsByName("collapse30"));
@@ -1155,29 +1149,7 @@
showList(document.getElementsByName("collapse30"));
}
}
</script>
<script>
function getProcessor() {
return document.getElementById("processors").value;
}
</script>
<script>
function getVersion() {
if (getProcInfo() == "xalan") {
return "1.0";
} else {
return "3.0";
}
}
</script>
<script>
function getProcInfo() {
var processVariables = document.getElementById("processors").value;// + "&version=" + document.getElementById("versions").value;
return processVariables;
}
</script>
<script>
var triggerList = document.getElementsByClassName("collapseTrigger");
for (i = 0; i < triggerList.length; i++) {
console.log("trigger connected");
@@ -1214,9 +1186,7 @@
}
});
}
</script>
<script>
function init() {
//Handle clicks in whole form and set info in tooltip
setDefaultContent(document.getElementById("xmlArea"), 'Insert XML here');
@@ -1248,4 +1218,4 @@
</body>
</html>
</html>