From 47b10a42383d5a6eccbf414c254fde1d16191c99 Mon Sep 17 00:00:00 2001 From: Adam Bem Date: Thu, 23 Nov 2023 13:58:14 +0100 Subject: [PATCH] Changed value is sent to backend --- Frontend/src/components/xml/TabComponent.vue | 4 +- .../xml/XmlTabbedInputComponent.vue | 39 +++++++++++++------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Frontend/src/components/xml/TabComponent.vue b/Frontend/src/components/xml/TabComponent.vue index 480d9b6..cedc062 100644 --- a/Frontend/src/components/xml/TabComponent.vue +++ b/Frontend/src/components/xml/TabComponent.vue @@ -25,8 +25,8 @@ function remove() { \ No newline at end of file diff --git a/Frontend/src/components/xml/XmlTabbedInputComponent.vue b/Frontend/src/components/xml/XmlTabbedInputComponent.vue index aabb036..5d64066 100644 --- a/Frontend/src/components/xml/XmlTabbedInputComponent.vue +++ b/Frontend/src/components/xml/XmlTabbedInputComponent.vue @@ -6,7 +6,9 @@ import { ref } from 'vue' import CodeEditor from '../CodeEditorComponent.vue' const newTabId = ref(0); -const activeTabId = ref(0) +const activeTabId = ref(0); +const prevActiveTabId = ref(-1); + const tabs = ref(new Array); tabs.value.push({ id: newTabId.value++, @@ -60,12 +62,18 @@ function readFile(file : any) { const reader = new FileReader() reader.onloadend = () => { - var result = reader.result?.toString() - if (typeof result == "string") - sendNewValue(result) + var result = reader.result!.toString(); + console.log(result); + sendNewValue(result); } - reader.readAsText(file.target.files[0]) + reader.readAsText(file.target.files[0]); + let activeIndex = findIndexWithID(activeTabId.value); + + let filePath = inputFile.value.value.split("\\"); + let fileName = filePath.at(filePath.length - 1); + + tabs.value.at(activeIndex)!.name = fileName; } function changeActiveTab(id : number) { @@ -73,8 +81,11 @@ function changeActiveTab(id : number) { let newIndex = findIndexWithID(id); tabs.value.at(index)!.data = data.value; + prevActiveTabId.value = activeTabId.value; activeTabId.value = id; data.value = tabs.value.at(newIndex)!.data; + + sendValue(); } function addTab() { @@ -83,18 +94,24 @@ function addTab() { name: "XML" + newTabId.value, data: "" }) + + console.log(tabs.value); } function removeTab(id : number) { if (tabs.value.length == 1) return - let index = findIndexWithID(activeTabId.value); - tabs.value.splice(index, 1); - if (activeTabId.value == id) { - activeTabId.value = tabs.value.at(0)!.id; - data.value = tabs.value.at(0)!.data; - } + let indexToRemove = findIndexWithID(id); + let activeIndex = findIndexWithID(activeTabId.value); + + if (indexToRemove == activeIndex && activeIndex == 0) + changeActiveTab(tabs.value.at(1)!.id) + else if (indexToRemove == activeIndex) + changeActiveTab(tabs.value.at(0)!.id) + + + tabs.value.splice(indexToRemove, 1); }