Browse Source

make selectedNode reactive

Martin Kunz 1 year ago
parent
commit
4881ca4041
2 changed files with 13 additions and 9 deletions
  1. 11 8
      src/components/TheDetail.vue
  2. 2 1
      src/util/store.ts

+ 11 - 8
src/components/TheDetail.vue

@@ -1,44 +1,47 @@
 <script setup lang="ts">
 <script setup lang="ts">
 import { useStore } from '@/util/store'
 import { useStore } from '@/util/store'
+import { storeToRefs } from 'pinia';
 import { computed } from 'vue';
 import { computed } from 'vue';
 const store = useStore()
 const store = useStore()
 
 
+const { selectedNode } = storeToRefs(store)
+
 const nameSpaceName = computed(() => {
 const nameSpaceName = computed(() => {
-  if(!store.selectedNode)
+  if(!selectedNode.value)
     return "";
     return "";
-  let nsIdx=store.selectedNode.nodeId.namespace;
+  let nsIdx=selectedNode.value.nodeId.namespace;
   return store.addressSpace?.nst.getUri(nsIdx);
   return store.addressSpace?.nst.getUri(nsIdx);
 })
 })
 </script>
 </script>
 
 
 <template>
 <template>
-    <div class="card">
-    <div class="card-body" v-if="store.selectedNode != null" :elem="store.selectedNode">
+    <div class="card" v-if="selectedNode!=null">
+    <div class="card-body" >
       <h5 class="card-title">Node Editor</h5>
       <h5 class="card-title">Node Editor</h5>
       <div class="card-text" >
       <div class="card-text" >
         <div class="input-group mb-3">
         <div class="input-group mb-3">
           <div class="input-group-prepend">
           <div class="input-group-prepend">
             <span class="input-group-text" id="inputGroup-sizing-default">DisplayName</span>
             <span class="input-group-text" id="inputGroup-sizing-default">DisplayName</span>
           </div>
           </div>
-          <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="store.selectedNode.displayName">
+          <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="selectedNode.displayName">
         </div>
         </div>
         <div class="input-group mb-3">
         <div class="input-group mb-3">
           <div class="input-group-prepend">
           <div class="input-group-prepend">
             <span class="input-group-text" id="inputGroup-sizing-default">BrowseName</span>
             <span class="input-group-text" id="inputGroup-sizing-default">BrowseName</span>
           </div>
           </div>
-          <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="store.selectedNode.browseName">
+          <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="selectedNode.browseName">
         </div>
         </div>
         <div class="input-group mb-3">
         <div class="input-group mb-3">
           <div class="input-group-prepend">
           <div class="input-group-prepend">
             <span class="input-group-text" id="inputGroup-sizing-default">NodeId</span>
             <span class="input-group-text" id="inputGroup-sizing-default">NodeId</span>
           </div>
           </div>
-          <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="store.selectedNode.nodeId">
+          <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="selectedNode.nodeId">
         </div>
         </div>
         <div class="input-group mb-3">
         <div class="input-group mb-3">
           <div class="input-group-prepend">
           <div class="input-group-prepend">
             <span class="input-group-text" id="inputGroup-sizing-default">NodeClass</span>
             <span class="input-group-text" id="inputGroup-sizing-default">NodeClass</span>
           </div>
           </div>
-          <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="store.selectedNode.nodeClass">
+          <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="selectedNode.nodeClass">
         </div>
         </div>
         <div class="input-group mb-3">
         <div class="input-group mb-3">
           <div class="input-group-prepend">
           <div class="input-group-prepend">

+ 2 - 1
src/util/store.ts

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