Reimplemented XML Tools and added styling (#227)
Co-authored-by: Adam Bem <adam.bem@zoho.eu> Reviewed-on: #227 Reviewed-by: Mikolaj Widla <widlam@noreply.example.com>
This commit is contained in:
@@ -1,23 +1,47 @@
|
||||
<script setup lang="ts">
|
||||
import xmlInputFieldToolbarComponent from '@/components/xml/XmlInputFieldToolbarComponent.vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
const xml = ref('')
|
||||
const query = ref('')
|
||||
|
||||
const props = defineProps(
|
||||
{
|
||||
transformationName: {type: String},
|
||||
prettyName: {type: String, required: true},
|
||||
xmlData: {type: String},
|
||||
}
|
||||
)
|
||||
const emit = defineEmits(['update:xml', 'update:transform'])
|
||||
|
||||
function sendXml() {
|
||||
emit('update:xml', xml.value)
|
||||
}
|
||||
|
||||
function sendTransform() {
|
||||
emit('update:transform', query.value)
|
||||
}
|
||||
|
||||
function setToDefaultXML(data: string) {
|
||||
xml.value = data;
|
||||
sendXml();
|
||||
}
|
||||
|
||||
function setToDefaultQuery(data: string) {
|
||||
query.value = data;
|
||||
sendTransform();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-6 w-full h-full items-center">
|
||||
<label for="xmlfield" class="dark:text-white">XML</label>
|
||||
<textarea id="xmlfield" class="w-1/2 h-36 bg-gray-500">
|
||||
|
||||
|
||||
</textarea>
|
||||
<label for="transformField" class="dark:text-white">{{ props.transformationName }}</label>
|
||||
<textarea id="transformField" class="w-1/2 h-36 bg-gray-500">
|
||||
|
||||
</textarea>
|
||||
<div class="flex flex-col w-full lg:w-1/2 h-full items-center gap-4">
|
||||
<div class="flex flex-col w-full h-1/2">
|
||||
<xmlInputFieldToolbarComponent prettyName="XML" @update:defaultData="(data) => setToDefaultXML(data)"></xmlInputFieldToolbarComponent>
|
||||
<textarea id="xmlField" v-model="xml" @input="sendXml()" class="w-full h-full resize-none dark:text-slate-100 dark:bg-gray-600 border border-slate-400 p-2 rounded-md"></textarea>
|
||||
</div>
|
||||
<div class="flex flex-col w-full h-1/2">
|
||||
<xmlInputFieldToolbarComponent :prettyName="$props.prettyName" @update:defaultData="(data) => setToDefaultQuery(data)"></xmlInputFieldToolbarComponent>
|
||||
<textarea id="transformField" v-model="query" @input="sendTransform()" class="w-full h-full resize-none dark:text-slate-100 dark:bg-gray-600 border border-slate-400 p-2 rounded-md"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,50 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import sampleXML from "@/assets/sampleXml.xml?raw"
|
||||
import sampleXSLT from "@/assets/sampleXslt.xml?raw"
|
||||
import sampleXSD from "@/assets/sampleXsd.xml?raw"
|
||||
import sampleXQuery from "@/assets/sampleXQuery.xquery?raw"
|
||||
|
||||
|
||||
const props = defineProps(
|
||||
{
|
||||
prettyName: {type: String, required: true}
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits(['update:defaultData'])
|
||||
|
||||
function setDefault() {
|
||||
const emitName = "update:defaultData";
|
||||
switch (props.prettyName.toLowerCase()) {
|
||||
case "xpath":
|
||||
emit(emitName, "string(/l:library/l:libraryName)")
|
||||
break;
|
||||
case "xsd":
|
||||
emit(emitName, sampleXSD)
|
||||
break;
|
||||
case "xslt":
|
||||
emit(emitName, sampleXSLT)
|
||||
break;
|
||||
case "xquery":
|
||||
emit(emitName, sampleXQuery)
|
||||
break;
|
||||
|
||||
default:
|
||||
emit(emitName, sampleXML)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex place-content-between w-full pr-2 items-center m-2">
|
||||
<span class="dark:text-white">{{ prettyName }}</span>
|
||||
<div class="flex space-x-2">
|
||||
<button class="tool-button" @click="setDefault()">Insert default {{ prettyName }}</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
30
Frontend/src/components/xml/XmlOutputFieldComponent.vue
Normal file
30
Frontend/src/components/xml/XmlOutputFieldComponent.vue
Normal file
@@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import xmlOutputFieldToolbarComponent from '@/components/xml/XmlOutputFieldToolbarComponent.vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
|
||||
const props = defineProps(
|
||||
{
|
||||
tool: {type: String, required: true},
|
||||
xml: {type: String},
|
||||
query: {type: String}
|
||||
}
|
||||
)
|
||||
|
||||
const result = ref('');
|
||||
|
||||
function parseResult(data: any) {
|
||||
result.value = data.result;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col w-full lg:w-1/2 h-full items-center">
|
||||
<xmlOutputFieldToolbarComponent :xml="$props.xml" :query="$props.query" :tool="$props.tool" @update:result="(data) => parseResult(data)"></xmlOutputFieldToolbarComponent>
|
||||
<div class="w-full h-full p-2 overflow-scroll border border-slate-400 rounded-md text-left bg-white dark:text-slate-100 dark:bg-gray-600">
|
||||
<pre class="break-words"><code>{{ result }}</code></pre>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
112
Frontend/src/components/xml/XmlOutputFieldToolbarComponent.vue
Normal file
112
Frontend/src/components/xml/XmlOutputFieldToolbarComponent.vue
Normal file
@@ -0,0 +1,112 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
var engines = ["saxon", "xalan", "libxml"];
|
||||
var versions = ["1.0", "2.0", "3.0", "3.1"];
|
||||
|
||||
const props = defineProps(
|
||||
{
|
||||
tool: {type: String, required: true},
|
||||
xml: {type: String},
|
||||
query: {type: String},
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits(['update:result'])
|
||||
|
||||
const engine = ref('');
|
||||
const version = ref('');
|
||||
|
||||
const isSaxonHidden = ref(false);
|
||||
const isXalanHidden = ref(false);
|
||||
const isLibXMLHidden = ref(false);
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
selectAvailableEngines();
|
||||
selectAvailableVersions();
|
||||
selectDefaults();
|
||||
})
|
||||
|
||||
function selectAvailableEngines() {
|
||||
if (props.tool == "xsd") {
|
||||
engines = ["xalan", "libxml"]
|
||||
}
|
||||
else if (props.tool == "xquery") {
|
||||
engines = ["saxon"]
|
||||
}
|
||||
}
|
||||
|
||||
function selectAvailableVersions() {
|
||||
if (props.tool == "xquery")
|
||||
versions = ["3.1"];
|
||||
else if (props.tool == "xsd")
|
||||
versions = ["N/A"];
|
||||
}
|
||||
|
||||
function selectDefaults() {
|
||||
version.value = versions[versions.length - 1];
|
||||
engine.value = engines[0];
|
||||
}
|
||||
|
||||
function process() {
|
||||
var request:Request = prepareRequest();
|
||||
fetchRequest(request).then((data) => {
|
||||
sendProcessedData(data);
|
||||
})
|
||||
}
|
||||
|
||||
function prepareRequest():Request {
|
||||
var request = new Request(prepareURL(), {
|
||||
body: prepareRequestBody(),
|
||||
method: "POST"
|
||||
});
|
||||
return request
|
||||
}
|
||||
|
||||
function prepareURL(): string {
|
||||
const engineEndpoint = engine.value == "libxml" ? "libxml" : "java";
|
||||
return document.location.protocol + "//" + document.location.hostname + "/" + engineEndpoint + "/" + props.tool;
|
||||
}
|
||||
|
||||
function prepareRequestBody():string {
|
||||
var requestBody = JSON.stringify({
|
||||
"data": props.xml,
|
||||
"process": props.query,
|
||||
"processor": engine.value,
|
||||
"version": version.value
|
||||
});
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
async function fetchRequest(request: Request):Promise<JSON> {
|
||||
var responseBody = await fetch(request)
|
||||
.then(response => response.json())
|
||||
.then((body) => body);
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
function sendProcessedData(data: JSON) {
|
||||
emit("update:result", data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex place-content-between w-full items-center m-2">
|
||||
<span class="dark:text-white">Result:</span>
|
||||
<div class="flex space-x-2">
|
||||
<select v-model="engine" name="engine" class="px-3 rounded-full border border-slate-400 bg-white dark:text-slate-100 dark:bg-gray-600">
|
||||
<option v-for="engine in engines" :value="engine">{{ engine }}</option>
|
||||
</select>
|
||||
<select v-model="version" name="version" class="px-3 rounded-full border border-slate-400 bg-white dark:text-slate-100 dark:bg-gray-600">
|
||||
<option v-for="version in versions" :value="version">{{ version }}</option>
|
||||
</select>
|
||||
<button class="tool-button">Clear</button>
|
||||
<button class="tool-button" @click="process">Process</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user