From 345c96f99aa98d5e90a46fa3f175ec0a2e6d4f36 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Sat, 9 Jul 2022 11:49:39 +1000 Subject: Fix links-to-node failing on load Was setting SERVER_URL incorrectly Also changed server API to include 'excl' param --- backend/tilo.py | 26 ++++++++++++++------------ src/App.vue | 2 +- src/components/SearchModal.vue | 3 ++- src/components/TileInfoModal.vue | 2 +- src/lib.ts | 4 ++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/tilo.py b/backend/tilo.py index 2f49baa..f2a177e 100755 --- a/backend/tilo.py +++ b/backend/tilo.py @@ -22,7 +22,8 @@ Expected HTTP query parameters: If 'sugg', reply with a SearchSuggResponse, describing search suggestions for the possibly-partial name. If 'info', reply with an InfoResponse, describing the named node. - toroot: Used with type=node, and causes inclusion of ancestors, and their children. - The value names a node whose ancestors need not be included. + A value of 1 indicates true, and other indicate false +- excl: Used with toroot, and names a node whose ancestors need not be included. - limit: Used with type=sugg to specify the max number of suggestions. - tree: Specifies which tree should be used. May be 'trimmed', 'images', or 'picked', corresponding to the @@ -239,8 +240,8 @@ def handleReq(dbCur, environ): return None # Get data of requested type if reqType == "node": - toroot = queryDict["toroot"][0] if "toroot" in queryDict else None - if toroot == None: + toroot = queryDict["toroot"][0] == '1' if "toroot" in queryDict else False + if not toroot: tolNodes = lookupNodes([name], tree, dbCur) if len(tolNodes) > 0: tolNode = tolNodes[name] @@ -250,15 +251,16 @@ def handleReq(dbCur, environ): else: # Get ancestors to skip inclusion of nodesToSkip = set() - nodeName = toroot - edgesTable = f"edges_{getTableSuffix(tree)}" - while True: - row = dbCur.execute(f"SELECT parent FROM {edgesTable} WHERE child = ?", (nodeName,)).fetchone() - if row == None: - break - parent = row[0] - nodesToSkip.add(parent) - nodeName = parent + nodeName = queryDict["excl"][0] if "excl" in queryDict else None + if nodeName != None: + edgesTable = f"edges_{getTableSuffix(tree)}" + while True: + row = dbCur.execute(f"SELECT parent FROM {edgesTable} WHERE child = ?", (nodeName,)).fetchone() + if row == None: + break + parent = row[0] + nodesToSkip.add(parent) + nodeName = parent # results = {} ranOnce = False diff --git a/src/App.vue b/src/App.vue index 77de7ca..784b15d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -865,7 +865,7 @@ export default defineComponent({ let urlParams = new URLSearchParams({type: 'node', tree: this.uiOpts.tree}); if (nodeName != null){ urlParams.append('name', nodeName); - urlParams.append('toroot', this.activeRoot.name); + urlParams.append('toroot', '1'); } let responseObj: {[x: string]: TolNode} = await this.loadFromServer(urlParams); if (responseObj == null){ diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue index 990312a..9dc8f9b 100644 --- a/src/components/SearchModal.vue +++ b/src/components/SearchModal.vue @@ -206,7 +206,8 @@ export default defineComponent({ let urlParams = new URLSearchParams({ type: 'node', name: tolNodeName, - toroot: this.activeRoot.name, + toroot: '1', + excl: this.activeRoot.name, tree: this.uiOpts.tree, }); this.$emit('net-wait'); // Allows the parent component to show a loading-indicator diff --git a/src/components/TileInfoModal.vue b/src/components/TileInfoModal.vue index e5ea77b..a70215d 100644 --- a/src/components/TileInfoModal.vue +++ b/src/components/TileInfoModal.vue @@ -240,7 +240,7 @@ export default defineComponent({ onLinkIconClick(evt: Event){ // Copy link to clipboard let url = new URL(window.location.href); - url.search = 'node=' + encodeURIComponent(this.nodeName); + url.search = new URLSearchParams({node: this.nodeName}); navigator.clipboard.writeText(url.toString()); // Show visual indicator this.linkCopied = true; diff --git a/src/lib.ts b/src/lib.ts index 0422389..9afe199 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -7,7 +7,7 @@ import {LayoutOptions} from './layout'; import {getBreakpoint, Breakpoint, getScrollBarWidth, onTouchDevice} from './util'; // For server requests -const SERVER_URL = window.location.href + 'data' +const SERVER_URL = (new URL(window.location.href)).origin + '/data' export async function queryServer(params: URLSearchParams){ // Construct URL let url = new URL(SERVER_URL); @@ -18,7 +18,7 @@ export async function queryServer(params: URLSearchParams){ let response = await fetch(url.toString()); responseObj = await response.json(); } catch (error){ - console.log(`Error with querying ${url}: ${error}`); + console.log(`Error with querying ${url.toString()}: ${error}`); return null; } return responseObj; -- cgit v1.2.3