Преглед на файлове

fix loading from filedrop

Martin Kunz преди 1 година
родител
ревизия
4f8d5171a3
променени са 4 файла, в които са добавени 38 реда и са изтрити 27 реда
  1. 27 18
      src/components/TheModels.vue
  2. 2 2
      src/ua/AddressSpace.ts
  3. 6 3
      src/ua/UABaseNode.ts
  4. 3 4
      src/util/store.ts

+ 27 - 18
src/components/TheModels.vue

@@ -12,7 +12,7 @@ const newDialogDisabled = ref(false);
 const projectType = ref("ua");
 
 async function exportProject() {
-  const blob = await store.addressSpace?.export();
+  const blob = await store.addressSpace?.exportProject();
   if (blob)
     downloadBlob(blob, "proj.zip");
 }
@@ -27,10 +27,10 @@ function downloadBlob(blob: Blob, filename: string) {
 }
 
 async function newProject() {
-  newDialogDisabled.value=true;
+  newDialogDisabled.value = true;
   store.addressSpace = new AddressSpace([] as UANodeSet[])
-  let nodesets:string[]=[];
-  switch(projectType.value) {
+  let nodesets: string[] = [];
+  switch (projectType.value) {
     case "emco":
       nodesets.push("nodesets/emco_machine_tools.xml");
     case "machinetool":
@@ -43,25 +43,25 @@ async function newProject() {
     default:
       break;
   }
-  let as= await AddressSpace.load(nodesets.reverse());
+  let as = await AddressSpace.load(nodesets.reverse());
   store.setAddressSpace(as);
-  newDialogOpen.value=false;
-  newDialogDisabled.value=false;
+  newDialogOpen.value = false;
+  newDialogDisabled.value = false;
 }
 
-async function handleDrop(e:DragEvent) {
-  if(!e.dataTransfer)
+async function handleDrop(e: DragEvent) {
+  if (!e.dataTransfer)
     return;
-  for(let file of e.dataTransfer.files) {
-      let xmlString= await file.text();
-      store.addNodeset(await UANodeSet.parse(xmlString, file.name));
+  for (let file of e.dataTransfer.files) {
+    let xmlString = await file.text();
+    store.addNodeset(await UANodeSet.parse(xmlString, file.name));
   }
 }
 </script>
 
 <template>
-  <div v-if="store.addressSpace" >
-    <div class="card" @drop.prevent="handleDrop($event)" dropzone="copy" @dragover="$event.preventDefault();">
+  <div v-if="store.addressSpace">
+    <div class="card">
       <div class="card-body" v-if="store.addressSpace">
         <h5 class="card-title">Models</h5>
         <p class="card-text">
@@ -71,14 +71,22 @@ async function handleDrop(e:DragEvent) {
             <li class="list-group-item">{{ model.modelUri }}</li>
           </div>
         </ul>
+        <ul class="list-group list-group-flush" @drop.prevent="handleDrop($event)" dropzone="copy"
+          @dragover="$event.preventDefault();">
+          <div>
+            <li class="list-group-item">(drop .xml nodeset or .zip project file here)</li>
+          </div>
+        </ul>
         </p>
+        <button class="btn btn-light" @click.prevent="exportProject()">Export</button>
+        <button class="btn btn-light" @click="newDialogOpen = true">New project</button>
       </div>
+
     </div>
-    <button class="btn btn-light" @click.prevent="exportProject()">Export</button>
-    <button class="btn btn-light" @click="newDialogOpen = true">New project</button>
+
   </div>
 
-  <v-dialog :open="newDialogOpen" @cancel="newDialogOpen=false">
+  <v-dialog :open="newDialogOpen" @cancel="newDialogOpen = false">
     <p>New project</p>
     <div class="form-check">
       <input class="form-check-input" type="radio" name="projectType" id="empty" value="empty" v-model="projectType">
@@ -89,7 +97,8 @@ async function handleDrop(e:DragEvent) {
       <label class="form-check-label" for="ua">http://opcfoundation.org/UA/ Namespace</label>
     </div>
     <div class="form-check">
-      <input class="form-check-input" type="radio" name="projectType" id="machinetool" value="machinetool" v-model="projectType">
+      <input class="form-check-input" type="radio" name="projectType" id="machinetool" value="machinetool"
+        v-model="projectType">
       <label class="form-check-label" for="machinetool">Machinetool Namespace +dependencies</label>
     </div>
     <div class="form-check">

+ 2 - 2
src/ua/AddressSpace.ts

@@ -22,7 +22,7 @@ export class AddressSpace{
         return this.nodeMap.get(nodeId)
     }
 
-    public addNodeset(nodeset: UANodeSet) {
+    public  addNodeset(nodeset: UANodeSet) {
         nodeset.reIndex(this.nst);
         for(const node of nodeset.nodes) {
             this.nodeMap.set(node.nodeId.toString(), node);
@@ -43,7 +43,7 @@ export class AddressSpace{
         return new AddressSpace(sets);
     }
 
-    public export() {
+    public exportProject() {
         const zip = new JSZip();
         const fileNames:string[]=[];
         for(const ns of this.nodesets) {

+ 6 - 3
src/ua/UABaseNode.ts

@@ -55,9 +55,12 @@ export class UABaseNode implements IToXML{
             if(fromNode)
                 ref.fromNode=fromNode;
             const toNode=nm.get(ref.toRef.toString()) 
-            if(toNode) //TODO: if we cant find the node; the parser is incomplete or the nodeset is broken
-                ref.toNode=toNode;
-            if(ref.fromNode===this&&toNode){ //add this reference to referenced node
+            if(!toNode) 
+                continue; //TODO: if we cant find the node; the parser is still incomplete or the nodeset is broken
+            
+            ref.toNode=toNode;
+            if(ref.fromNode.nodeId.toString()===this.nodeId.toString()){ //add this reference to referenced node
+                //Bug? when loading from filedrop; fromNode is a proxy; this is not.
                 if(!ref.toNode.references.includes(ref))
                     ref.toNode.references.push(ref);
             } 

+ 3 - 4
src/util/store.ts

@@ -4,13 +4,12 @@ import type { UANodeSet } from '@/ua/UANodeSet'
 import { defineStore } from 'pinia'
 
 export const useStore = defineStore('user', {
-  state: () => {
-    return {
+  state: () => ({
       addressSpace: null as AddressSpace | null,
       rootNode: null as UABaseNode | null,
       selectedNode: null as UABaseNode | null
-    }
-  },
+
+  }),
   actions: {
     setAddressSpace(as: AddressSpace) {
       this.addressSpace=as;