Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

id= if non visual instances are passed in the url #431

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions components/VFBMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,15 @@ export default class VFBMain extends React.Component {
continue;
}
if (this.hasVisualType(variableIds[singleId])) {
var instance = Instances.getInstance(variableIds[singleId]);
this.resolve3D(variableIds[singleId], function () {
this.resolve3D(variableIds[singleId], function (id) {
var instance = Instances.getInstance(id);
GEPPETTO.SceneController.deselectAll();
if ((instance != undefined) && (typeof instance.select === "function")) {
instance.select();
if (this.idsFromURL.length > 0 && window.templateID !== undefined && Instances[window.templateID]) {
this.handlerInstanceUpdate(instance);
} else {
instance.select();
}
}
}.bind(this));
} else {
Expand Down Expand Up @@ -390,7 +394,7 @@ export default class VFBMain extends React.Component {
var postResolve = () => {
this.setSepCol(path);
if (callback != undefined) {
callback();
callback(path);
}
};

Expand Down Expand Up @@ -863,8 +867,8 @@ export default class VFBMain extends React.Component {
}.bind(this);

window.resolve3D = function (externalID) {
this.resolve3D(externalID, function () {
var instance = Instances.getInstance(externalID);
this.resolve3D(externalID, function (id) {
var instance = Instances.getInstance(id);
if ((instance != undefined) && (typeof instance.select === "function")) {
GEPPETTO.SceneController.deselectAll();
instance.select();
Expand Down Expand Up @@ -949,20 +953,6 @@ 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 loadOnDelay = new Promise(function (resolve, reject) {
* that.addVfbId(that.idsFromURL);
* while (Instances[that.idFromURL] === undefined && window.templateID === undefined) {
* setTimeout(null, 500);
* }
* resolve(true);
* });
* loadOnDelay.then(function (reason) {
* if (reason) {
* that.handlerInstanceUpdate(Instances[that.idFromURL]);
* }
* });
*/
});
}
}
Expand Down Expand Up @@ -1046,6 +1036,7 @@ export default class VFBMain extends React.Component {
});
}

// Handler created to manage all the update that relates to components of the UI
handlerInstanceUpdate (instance) {
let metaInstance = undefined;
let parentInstance = undefined;
Expand All @@ -1056,6 +1047,7 @@ export default class VFBMain extends React.Component {
return;
}

// Logic to determine the parent and the meta instance, used to get all the data needed
if (instance.getId().indexOf("_meta") === -1 && instance.getParent() === null) {
parentInstance = instance;
metaInstance = parentInstance[parentInstance.getId() + "_meta"];
Expand All @@ -1067,6 +1059,17 @@ export default class VFBMain extends React.Component {
this.instanceOnFocus = metaInstance;
this.idOnFocus = parentInstance.getId();

/*
* this is the core of the logic id= that we use on startup of the application from the URL.
* All the ids in the url in i= and id= are placed in the idsFromURL array, where the only id in
* id= is placed in idFromURL. In this portion of code we loop through this list, if the id on focus
* at the moment is in the list but is different from the id= that should take over term info and
* tree browser we simply remove this id from the array and return, instead if the id on focus is the
* the same that we stored in idFromURL in that case we remove this id from the array, break the loop
* and go forward to place all this information.
* Keep in mind this loop is executed only once, on startup, since the array is emptied and never
* filled again, for that reason DO NOT REUSE idsFromURL differently this logic will be broken.
*/
for (var counter = 0; counter < this.idsFromURL.length; counter++) {
if (this.idsFromURL[counter] === this.idOnFocus && this.idFromURL !== this.idOnFocus) {
this.idsFromURL.splice(counter, 1);
Expand Down