diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-06-23 16:11:30 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-06-23 16:11:30 +1000 |
| commit | c8d2ebcb27832da453ea596d23b67731cf86de2e (patch) | |
| tree | 4c2dd71fc8350ebb1f394c78ea5a66563d1effb8 /src | |
| parent | 47ec05706dec6c78aace3c5669b0c59d9ab03d8d (diff) | |
Remove hard-coded root-name from App.vue
Diffstat (limited to 'src')
| -rw-r--r-- | src/App.vue | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/App.vue b/src/App.vue index d0d9a86..3309879 100644 --- a/src/App.vue +++ b/src/App.vue @@ -42,9 +42,8 @@ function getReverseAction(action: AutoAction): AutoAction | null { } // Initialise tree-of-life data -const ROOT_NAME = "cellular organisms"; const initialTolMap: TolMap = new Map(); -initialTolMap.set(ROOT_NAME, new TolNode()); +initialTolMap.set("", new TolNode()); // Configurable options const defaultLytOpts: LayoutOptions = { @@ -99,7 +98,7 @@ const defaultUiOpts = { export default defineComponent({ data(){ - let layoutTree = initLayoutTree(initialTolMap, ROOT_NAME, 0); + let layoutTree = initLayoutTree(initialTolMap, "", 0); layoutTree.hidden = true; return { tolMap: initialTolMap, @@ -670,14 +669,27 @@ export default defineComponent({ }, // Helper methods initTreeFromServer(){ - let urlPath = '/data/node?name=' + encodeURIComponent(ROOT_NAME); + let urlPath = '/data/node'; urlPath += this.uiOpts.useReducedTree ? '&tree=reduced' : ''; fetch(urlPath) .then(response => response.json()) .then(obj => { + // Get root node name + let rootName = null; + let nodeNames = Object.getOwnPropertyNames(obj); + for (let n of nodeNames){ + if (obj[n].parent == null){ + rootName = n; + break; + } + } + if (rootName == null){ + throw new Error('Server response has no root node'); + } + // Initialise tree this.tolMap.clear(); - Object.getOwnPropertyNames(obj).forEach(key => {this.tolMap.set(key, obj[key])}); - this.layoutTree = initLayoutTree(this.tolMap, this.layoutTree.name, 0); + nodeNames.forEach(n => {this.tolMap.set(n, obj[n])}); + this.layoutTree = initLayoutTree(this.tolMap, rootName, 0); this.activeRoot = this.layoutTree; this.layoutMap = initLayoutMap(this.layoutTree); this.updateAreaDims().then(() => { |
