|
@@ -1,10 +1,15 @@
|
|
<!-- eslint-disable no-fallthrough -->
|
|
<!-- eslint-disable no-fallthrough -->
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
-import { AddressSpace } from '@/ua/AddressSpace';
|
|
|
|
|
|
+import { AddressSpace, type IMappingValue } from '@/ua/AddressSpace';
|
|
import { UANodeSet } from '@/ua/UANodeSet';
|
|
import { UANodeSet } from '@/ua/UANodeSet';
|
|
import { useStore } from '@/util/store'
|
|
import { useStore } from '@/util/store'
|
|
import { ref } from 'vue';
|
|
import { ref } from 'vue';
|
|
import VDialog from './VDialog.vue'
|
|
import VDialog from './VDialog.vue'
|
|
|
|
+import JSZip from "jszip";
|
|
|
|
+import YAML from 'yaml'
|
|
|
|
+import { stringify } from 'querystring';
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
const store = useStore()
|
|
const store = useStore()
|
|
const newDialogOpen = ref(false);
|
|
const newDialogOpen = ref(false);
|
|
@@ -14,7 +19,7 @@ const projectType = ref("ua");
|
|
async function exportProject() {
|
|
async function exportProject() {
|
|
const blob = await store.addressSpace?.exportProject();
|
|
const blob = await store.addressSpace?.exportProject();
|
|
if (blob)
|
|
if (blob)
|
|
- downloadBlob(blob, "proj.zip");
|
|
|
|
|
|
+ downloadBlob(blob, "project.zip");
|
|
}
|
|
}
|
|
|
|
|
|
function downloadBlob(blob: Blob, filename: string) {
|
|
function downloadBlob(blob: Blob, filename: string) {
|
|
@@ -52,10 +57,32 @@ async function newProject() {
|
|
async function handleDrop(e: DragEvent) {
|
|
async function handleDrop(e: DragEvent) {
|
|
if (!e.dataTransfer)
|
|
if (!e.dataTransfer)
|
|
return;
|
|
return;
|
|
- for (let file of e.dataTransfer.files) {
|
|
|
|
- let xmlString = await file.text();
|
|
|
|
- store.addNodeset(await UANodeSet.parse(xmlString, file.name));
|
|
|
|
|
|
+ if(e.dataTransfer.files.length==1 && e.dataTransfer.files[0].name.endsWith(".zip")) {
|
|
|
|
+ loadZip(e.dataTransfer.files[0]);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ for (const file of e.dataTransfer.files) {
|
|
|
|
+ const xmlString = await file.text();
|
|
|
|
+ store.addNodeset(await UANodeSet.parse(xmlString, file.name));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+async function loadZip(file: File){
|
|
|
|
+ const zip= await JSZip.loadAsync(file.arrayBuffer())
|
|
|
|
+ const filenames=JSON.parse(await zip.files['project.json'].async("string"));
|
|
|
|
+ let nodesets: UANodeSet[]=[];
|
|
|
|
+ for(const fileName of filenames) {
|
|
|
|
+ nodesets.push(await UANodeSet.parse(await zip.files[fileName].async("string"), fileName));
|
|
}
|
|
}
|
|
|
|
+ const as=new AddressSpace(nodesets);
|
|
|
|
+ const mlist=YAML.parse(await zip.files['mapping.yaml'].async("string")) as IMappingValue[];
|
|
|
|
+ const mapping=new Map<string, IMappingValue>();
|
|
|
|
+ for(const entry of mlist) {
|
|
|
|
+ mapping.set(entry.path, entry);
|
|
|
|
+ }
|
|
|
|
+ as.mapping=mapping;
|
|
|
|
+ store.setAddressSpace(as);
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|