Prechádzať zdrojové kódy

instance dialog: refactor, add typedef

Martin Kunz 8 mesiacov pred
rodič
commit
6f84e64fb1
2 zmenil súbory, kde vykonal 37 pridanie a 31 odobranie
  1. 26 29
      src/components/TheInstance.vue
  2. 11 2
      src/ua/UABaseNode.ts

+ 26 - 29
src/components/TheInstance.vue

@@ -1,25 +1,25 @@
 <script setup lang="ts">
 import { useStore } from '@/store'
 import { storeToRefs } from 'pinia';
-import { computed } from 'vue';
+import { computed, ref, watch } from 'vue';
 import VCollaps from './VCollaps.vue';
 const store = useStore()
 const { selectedNode } = storeToRefs(store)
 const nameSpaceName = computed(() => {
-  if(!selectedNode.value)
+  if (!selectedNode.value)
     return "";
-  let nsIdx=selectedNode.value.nodeId.namespace;
+  let nsIdx = selectedNode.value.nodeId.namespace;
   return store.addressSpace?.nst.getUri(nsIdx);
 })
 
-const displayName=computed(() => {
-  if(!selectedNode.value)
-    return "";
-  for( const dn of selectedNode.value.displayName) { //TODO: locale handling
-    return dn.text;
-  }
-  return "";
-})
+const typeDef=ref("");
+
+watch(selectedNode, async (newNode, _oldNode) => {
+  if(!newNode)
+    return;
+  typeDef.value=newNode.getTypeDefinition()||"<undefind>";
+});
+
 
 function okPressed() {
   console.log('TODO: Handle OK Button');
@@ -28,43 +28,40 @@ defineExpose({ okPressed })
 </script>
 
 <template>
-  <VCollaps :selected=true name="Node">
+  <VCollaps :selected=true name="Instance">
     <div class="card-text" v-if="selectedNode">
       <div class="input-group mb-3">
         <div class="input-group-prepend">
-          <span class="input-group-text" id="inputGroup-sizing-default">DisplayName</span>
-        </div>
-        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="displayName">
-      </div>
-      <div class="input-group mb-3">
-        <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">NodeClass</span>
         </div>
-        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="selectedNode.browseName">
+        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"
+          v-model="selectedNode.nodeClass">
       </div>
       <div class="input-group mb-3">
         <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">Namespace</span>
         </div>
-        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="selectedNode.nodeId">
+        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"
+          v-model="nameSpaceName">
       </div>
       <div class="input-group mb-3">
         <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">Name</span>
         </div>
-        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="selectedNode.nodeClass">
+        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"
+          v-model="selectedNode.browseName">
       </div>
       <div class="input-group mb-3">
         <div class="input-group-prepend">
-          <span class="input-group-text" id="inputGroup-sizing-default">Namespace</span>
+          <span class="input-group-text" id="inputGroup-sizing-default">Type Definition</span>
         </div>
-        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default" v-model="nameSpaceName">
+        <input type="text" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"
+          v-model="typeDef">
       </div>
     </div>
+
   </VCollaps>
 </template>
 
 
-<style scoped>
-
-</style>
+<style scoped></style>

+ 11 - 2
src/ua/UABaseNode.ts

@@ -126,14 +126,23 @@ export class UABaseNode implements IToXML{
         return undefined;
     }
 
+    getTypeDefinition(): string|undefined{
+        for(const ref of this.references) {
+            if(ref.referenceType == "HasTypeDefinition"){
+                return ref.toNode.browseName;
+            }
+        }
+        return undefined;
+    }
+
     //TODO: check name, function, etc. or delete
-    getInstanceDecl(nid: string, mrType: string){
+    getInstanceDecl(mrType: string){
         const aggregates = (this.addressSpace?.getSubTreeAsList("i="+ReferenceTypeIds.Aggregates)||[]);
         const aggStrings:String[] = [];
         aggregates.forEach((item) => {
           aggStrings.push(item.browseName);
         })
-        const node =  (this.addressSpace.findNode(nid)) as UABaseNode;
+        const node =  (this.addressSpace.findNode(this.nodeId.toString())) as UABaseNode;
         const res:string[] = [];
         for(const item of node.references) {
           if(aggStrings.includes(item.referenceType) && item.isForward){