Skip to content

Commit

Permalink
trigger query builder from URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelpiano committed Dec 16, 2019
1 parent cfc53e1 commit a7e7662
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion components/VFBMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default class VFBMain extends React.Component {
this.idFromURL = undefined;
this.firstLoad = true;
this.idsFromURL = [];
this.urlQueryLoader = undefined;

this.UIElementsVisibility = {};

Expand Down Expand Up @@ -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 = "";
Expand All @@ -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)) {
Expand All @@ -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);
}
}
});
}
}
Expand Down Expand Up @@ -1093,7 +1154,6 @@ export default class VFBMain extends React.Component {
if (this.treeBrowserReference !== undefined && this.treeBrowserReference !== null) {
this.treeBrowserReference.updateTree(this.instanceOnFocus);
}

}

render () {
Expand Down

0 comments on commit a7e7662

Please sign in to comment.