From 7e67af7003ece713d7823fa7d6b32749516d508a Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Wed, 6 Jul 2022 17:04:57 +1000
Subject: Add link-to-node functionality

---
 src/App.vue | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

(limited to 'src/App.vue')

diff --git a/src/App.vue b/src/App.vue
index df2b9b7..cd38621 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -889,8 +889,13 @@ export default defineComponent({
 		},
 		// For initialisation
 		async initTreeFromServer(firstInit = true){
+			// Get possible target node from URL
+			let nodeName = (new URL(window.location.href)).searchParams.get('node');
 			// Query server
 			let urlParams = 'type=node';
+			if (nodeName != null){
+				urlParams += '&name=' + encodeURIComponent(nodeName) + '&toroot=true';
+			}
 			urlParams += '&tree=' + this.uiOpts.tree;
 			let responseObj: {[x: string]: TolNode} = await this.loadFromServer(urlParams);
 			if (responseObj == null){
@@ -915,14 +920,21 @@ export default defineComponent({
 			this.layoutTree = initLayoutTree(this.tolMap, rootName, 0);
 			this.activeRoot = this.layoutTree;
 			this.layoutMap = initLayoutMap(this.layoutTree);
-			// Relayout
-			await this.updateAreaDims();
-			this.relayoutWithCollapse(false);
 			// Skip initial transition
 			if (firstInit){
 				this.justInitialised = true;
 				setTimeout(() => {this.justInitialised = false}, this.uiOpts.transitionDuration);
 			}
+			// Relayout
+			await this.updateAreaDims();
+			this.relayoutWithCollapse(false);
+			// Possibly jump to a target node
+			if (nodeName != null){
+				let oldSetting = this.uiOpts.searchJumpMode;
+				this.uiOpts.searchJumpMode = true;
+				await this.onSearch(nodeName);
+				this.uiOpts.searchJumpMode = oldSetting;
+			}
 		},
 		async reInit(){
 			if (this.activeRoot != this.layoutTree){
-- 
cgit v1.2.3

