diff --git a/index.html b/index.html index 105a328..c41196c 100644 --- a/index.html +++ b/index.html @@ -304,21 +304,20 @@ -
+
diff --git a/js/tree-edam-stand-alone.js b/js/tree-edam-stand-alone.js index 776d4cb..a822de8 100644 --- a/js/tree-edam-stand-alone.js +++ b/js/tree-edam-stand-alone.js @@ -71,57 +71,45 @@ function interactive_edam_browser(){ branch='edam'; } $("#edam-branches .branch."+branch).addClass("active"); - updateVersion(version); - updateBranch(branch); //setCookie("edam_browser_branch",branch); current_branch=branch; + //get tree from cache (either same version or a subset request) - if(!version || version==getCookie("edam_version","stable" )){ - + if(!version){ tree=JSON.parse(localStorage.getItem("current_edam")); + //cache is empty, load default version if(!tree){ version='stable'; tree_url=getTreeURL(version); __my_interactive_tree.data_url(tree_url); setCookie("edam_version",version); } + setCookie("isLoaded",true) __my_interactive_tree.data(tree); } //load version (pre-determined or custom) else { + //show loading spinner document.getElementById("tree").style.display = "none"; $(".loader-wrapper").show(); - //in case we're passed the raw url link directly + + //in case we're passed the raw url link directly, no need to map it if(customRe.test(version)){ tree_url=version; - setCookie("edam_version",version); - - } - else{ - tree_url=getTreeURL(version); - setCookie("edam_version",version); - + setCookie("edam_version",tree_url); } - - if(version=='custom'){ - version=tree_url; + //listed branch + else { + //maping branch to url + tree_url=getTreeURL(version); setCookie("edam_version",version); - } - - let uri = __my_interactive_tree.cmd.getElementByIdentifier(getInitURI(current_branch)); - if (uri){ - uri = __my_interactive_tree.identifierAccessor()(uri) - let params = "" - if(version!="stable"){ - params+="&version="+version - } - if(current_branch!="edam"){ - params+="&branch="+current_branch + if(version=='custom'){ + //custom branch, identify it by the url + version=tree_url; + setCookie("edam_version",version); } - window.location.hash = uri.replace("http://edamontology.org/","") + params; - - } + } __my_interactive_tree.data_url(tree_url); } @@ -131,7 +119,7 @@ function interactive_edam_browser(){ function loadCustomVersion(){ $("#versionModal").modal('hide'); let versionURL=document.getElementById('version_url').value; - setCookie("edam_version",versionURL); + setCookie("custom_url",versionURL); } function getTreeURL(version){ @@ -139,7 +127,7 @@ function interactive_edam_browser(){ case 'latest': return "https://raw.githubusercontent.com/edamontology/edamontology/main/EDAM_dev.owl"; case 'custom': - return getCookie("edam_version",""); + return getCookie("custom_url",""); case 'stable': return "https://raw.githubusercontent.com/edamontology/edamontology/main/releases/EDAM_1.25.owl"; default: @@ -286,6 +274,9 @@ function interactive_edam_browser(){ .toLowerCase() .replace(/[-]+/g,'-'); let params = "" + //update url only if the tree is loaded successfully + if(getCookie("isLoaded",true)=="true") { + if(version!="stable"){ params+="&version="+version } @@ -293,6 +284,11 @@ function interactive_edam_browser(){ params+="&branch="+current_branch } window.location.hash = uri.replace("http://edamontology.org/","") + params; + + //update version and branch as well + updateVersion(version); + updateBranch(current_branch); + } if(current_branch!="custom_url" && window.location.search){ setUrlParameters(""); } diff --git a/js/tree-reusable-d3.js b/js/tree-reusable-d3.js index dd0a1c1..5e8f97f 100644 --- a/js/tree-reusable-d3.js +++ b/js/tree-reusable-d3.js @@ -872,11 +872,23 @@ var interactive_tree = function() { identifierToElement={}; data_url = value; - jsonTreeFromURL(value,(tree) => { + jsonTreeFromURL(value, + //tree loaded successfully + (tree) => { + setCookie("isLoaded",true); localStorage.setItem("current_edam",JSON.stringify(tree)) setCookie("edam_url",value) tree.meta.data_url=data_url; chart.data(tree); + }, + //tree can't be loaded, restore the previous state + (err)=>{ + //alert the error + alert('We encountered the following error: '+ err.message+". Taking you back to the previous version."); + //load previous version from cache + setCookie("isLoaded",false); + var tree=JSON.parse(localStorage.getItem("current_edam")); + chart.data(tree); }); } diff --git a/package.json b/package.json index 493d689..e0d5bbd 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@babel/core": "^7.14.8", - "@babel/preset-env": "^7.14.8", + "@babel/preset-env": "^7.14.9", "@fortawesome/fontawesome-free": "^5.15.3", "cssnano": "^5.0.6", "jshint": "^2.9.5", @@ -20,7 +20,7 @@ "dependencies": { "bootstrap": "^3.4.1", "d3": "^4.13.0", - "edam2json-js": "^0.2.2", + "edam2json-js": "^0.2.3", "ga-gtag": "^1.1.0", "gh-pages": "^3.2.3", "jquery": "^3.2.1",