From a7e7662d5f5ab802091168a74f443ce100b5ff6c Mon Sep 17 00:00:00 2001 From: Dario Del Piano Date: Mon, 16 Dec 2019 12:44:09 +0000 Subject: [PATCH] trigger query builder from URL --- components/VFBMain.js | 62 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/components/VFBMain.js b/components/VFBMain.js index 8b86ebcf2..7a493f057 100644 --- a/components/VFBMain.js +++ b/components/VFBMain.js @@ -73,6 +73,7 @@ export default class VFBMain extends React.Component { this.idFromURL = undefined; this.firstLoad = true; this.idsFromURL = []; + this.urlQueryLoader = undefined; this.UIElementsVisibility = {}; @@ -914,10 +915,43 @@ export default class VFBMain extends React.Component { // Loading ids passed through the browser's url if ((this.props.location.search.indexOf("id=VFB") == -1) && (this.props.location.search.indexOf("i=VFB") == -1)) { this.idFromURL = "VFB_00017894"; + var idList = this.props.location.search; + idList = idList.replace("?","").split("&"); + for (let list in idList) { + if (idList[list].indexOf("q=") > -1) { + this.urlQueryLoader = idList[list].replace("q=","").replace("%20", " ").split(","); + } + } var that = this; console.log("Loading default Adult Brain VFB_00017894 template."); GEPPETTO.on(GEPPETTO.Events.Model_loaded, function () { that.addVfbId(that.idFromURL); + + var callback = function () { + // check if any results with count flag + if (that.refs.querybuilderRef.props.model.count > 0) { + // runQuery if any results + that.refs.querybuilderRef.runQuery(); + } else { + that.refs.querybuilderRef.switchView(false); + } + // show query component + that.refs.querybuilderRef.open(); + $("body").css("cursor", "default"); + GEPPETTO.trigger('stop_spin_logo'); + }; + + if (that.urlQueryLoader !== undefined) { + if (window[that.urlQueryLoader[0]] == undefined) { + window.fetchVariableThenRun(that.urlQueryLoader[0], function () { + that.refs.querybuilderRef.addQueryItem({ term: "", id: that.urlQueryLoader[0], queryObj: Model[that.urlQueryLoader[1]] }, callback) + }); + } else { + setTimeout(function () { + that.refs.querybuilderRef.addQueryItem({ term: "", id: that.urlQueryLoader[0], queryObj: Model[that.urlQueryLoader[1]] }, callback); + }, 100); + } + } }); } else { var idsList = ""; @@ -935,6 +969,8 @@ export default class VFBMain extends React.Component { idsList = "," + idsList; } idsList = idList[list].replace("i=","") + idsList; + } else if (idList[list].indexOf("q=") > -1) { + this.urlQueryLoader = idList[list].replace("q=","").replace("%20", " ").split(","); } } if ((idsList.length > 0) && (this.state.modelLoaded == true) && (this.urlIdsLoaded == false)) { @@ -956,6 +992,31 @@ export default class VFBMain extends React.Component { console.log("Loading IDS to add to the scene from url"); GEPPETTO.on(GEPPETTO.Events.Model_loaded, function () { that.addVfbId(that.idsFromURL); + + var callback = function () { + // check if any results with count flag + if (that.refs.querybuilderRef.props.model.count > 0) { + // runQuery if any results + that.refs.querybuilderRef.runQuery(); + } else { + that.refs.querybuilderRef.switchView(false); + } + // show query component + that.refs.querybuilderRef.open(); + $("body").css("cursor", "default"); + GEPPETTO.trigger('stop_spin_logo'); + }; + if (that.urlQueryLoader !== undefined) { + if (window[that.urlQueryLoader[0]] == undefined) { + window.fetchVariableThenRun(that.urlQueryLoader[0], function () { + that.refs.querybuilderRef.addQueryItem({ term: "", id: that.urlQueryLoader[0], queryObj: Model[that.urlQueryLoader[1]] }, callback) + }); + } else { + setTimeout(function () { + that.refs.querybuilderRef.addQueryItem({ term: "", id: that.urlQueryLoader[0], queryObj: Model[that.urlQueryLoader[1]] }, callback); + }, 100); + } + } }); } } @@ -1093,7 +1154,6 @@ export default class VFBMain extends React.Component { if (this.treeBrowserReference !== undefined && this.treeBrowserReference !== null) { this.treeBrowserReference.updateTree(this.instanceOnFocus); } - } render () {