diff --git a/Frontend/src/components/XsltParamComponent.vue b/Frontend/src/components/XsltParamComponent.vue index 32a1a9a..4bd93bb 100644 --- a/Frontend/src/components/XsltParamComponent.vue +++ b/Frontend/src/components/XsltParamComponent.vue @@ -13,100 +13,32 @@ const sendToParent = () => { options.value.forEach((value) => {console.log("KID" + value + options.value.indexOf(value))}) emit('update-value', options.value); }; - - const nameInput = ref('') const valueInput = ref('') - - const selectedOption = ref(options.value[0].name) +const isNumeric = (string) => /^[+-]?\d+(\.\d+)?$/.test(string) + const selectedFunction = () => { - if (selectOption(selectedOption.value) === 'Add Param') { - if(!valueInput.value.length == 0 && !nameInput.value.length == 0){ - options.value.push({name: nameInput.value + " = " + valueInput.value}); - valueInput.value = ""; - nameInput.value = ""; - } + const action = selectOption(selectedOption.value); + const name = nameInput.value.trim(); + const value = valueInput.value.trim(); + if (action === "Add Param" && name && value && !isNumeric(name)) { + options.value.push({ name: `${name} = ${value}` }); + nameInput.value = valueInput.value = ""; } - if (selectOption(selectedOption.value) === 'Remove Param') { - const foundOption = options.value.find(option => option.name === selectedOption.value); - if (foundOption) { - const currentIndex = options.value.indexOf(foundOption); - if (currentIndex !== -1) { - options.value.splice(currentIndex, 1); - } - } - if (options.value.length > 0) { - selectedOption.value = options.value[0].name; - } else { - selectedOption.value = ""; - } - valueInput.value = ""; - nameInput.value = ""; + + if (action === "Remove Param") { + options.value = options.value.filter(option => option.name !== selectedOption.value); + selectedOption.value = options.value.length ? options.value[0].name : ""; + nameInput.value = valueInput.value = ""; } - sendToParent() - /* - - if(selectedOption.value === "Add Param") { - sendRequest("add"); - } - else { - sendRequest("remove"); - } - */ -} - -/* -const sendRequest = (type:string) => { - console.log(type) - let request: Request = prepareRequest(type) - fetchRequest(request).then((body) => { - - const {status} = body as any; - console.log(status) - if (status === "OK") { - options.value.push({ name: nameInput.value + " = " + valueInput.value }); - } - }); -} -*/ + sendToParent(); +}; function selectOption(option: string): string { return option == "Add Param" ? "Add Param" : "Remove Param" } - -// -// function prepareRequest(type :string): Request { -// let request = new Request(prepareURL(), { -// body: prepareRequestBody(type), -// method: "POST" -// }); -// return request -// } -// -// function prepareURL(): string { -// //const engineEndpoint = engine.value == "libxml" ? "libxml" : "java"; -// return document.location.protocol + "//" + document.location.hostname + "/" + "java" + "/xslt/param"; -// //return "http://localhost:8081/xslt/param"; -// } -// -// function prepareRequestBody(type: string): string { -// let requestBody = JSON.stringify({ -// "paramName": nameInput.value, -// "paramValue": valueInput.value, -// "type": type -// }); -// console.log(requestBody); -// return requestBody; -// } -// -// async function fetchRequest(request: Request): Promise { -// console.log(request) -// let responseBody = await fetch(request) -// return await responseBody.json() -// } -