js.ontology-tree-view.min.js Maven / Gradle / Ivy
(function(g,w){var p=new w.RestClient();var C=new w.StandardModal();var z="label";var c="root";var u="isLast";var A="entity_type";var b="ontologyIRI";var j="id";var k="ontologyName";var d="ontologyTerm";var i="ontologyTermIRI";var r="ontologyTermSynonym";var v="definition";var B="nodePath";var s="parentNodePath";var e="parentOntologyTermIRI";var f=null;var n=null;w.OntologyTree=function m(D){n=g("#"+D)};w.OntologyTree.prototype.updateOntologyTree=function(G){var F=y(G);if(F&&F.items.length>0){var E=F.items[0];E.attributes=h(D(E));o(E,null)}function D(I){var H=p.get("/api/v1/"+I[k],{expand:["attributes"],q:{q:[{field:c,operator:"EQUALS",value:true},{operator:"AND"},{field:b,operator:"EQUALS",value:I[b]},{operator:"AND"},{field:u,operator:"EQUALS",value:false}]}});return H.items}};w.OntologyTree.prototype.queryTree=function(E,I){if(I!==undefined&&I!==""){var J=n.tree("getTree");f=f?f:J.rootNode.toDict(true);J.reload();var D=y(E);if(D.items.length>0){var G=D.items[0];var H=h(F(G,I)).sort(function(L,K){return w.naturalSort(K.nodePath.split(".").length,L.nodePath.split(".").length)});if(H.length>0){g.each(H,function(L,K){q(J,K)})}else{w.createAlert([{message:'No ontology terms are found for query "'+I+'".'}],"error")}}}function F(K,L){var M=p.get("/api/v1/"+K[j],{expand:["attributes"],q:{q:[{field:r,operator:"EQUALS",value:L}]}},null);return M.items}};w.OntologyTree.prototype.restoreTree=function(){if(f){var D=n.tree("getTree");D.rootNode.fromDict(f);f=null}};w.OntologyTree.prototype.locateTerm=function(E){var G=n.tree("getTree");G.reload();E=x(E);var F=q(G,E,true);F.setFocus();var D=n.offset().top+n.height()/2;var H=Math.abs(g(G.rootNode.ul).offset().top-n.offset().top);if(g(F.li).offset().top>D){n.scrollTop(g(F.li).offset().top-D+H)}else{n.scrollTop(H-D+g(F.li).offset().top)}};function q(I,F,J){var G=null;if(F){var E=F.href;if(!I.getNodeByKey(E)){var H=l(F);var D=q(I,l(F),J);if(D){n.tree("appendChildNodes",D,J?h(H.attributes.items):h([F]))}else{console.log("error parent node cannot but null!")}}G=I.getNodeByKey(E)}return G}function h(E){var D=[];if(E.length>0){var F={};g.each(E,function(H,J){var G=J[i];if(F[G]){if(J[r]!==J[d]){var I=F[G];I.synonyms.push(J[r]);F[G]=I}}else{J.synonyms=[];if(J[r]!==J[d]){J.synonyms.push(J[r])}F[G]=J}});g.map(F,function(H,G){if(H[d]){H[z]=H[d]}else{if(H[k]){H[z]=H[k]}}D.push(H)})}return D.sort(function(H,G){return w.naturalSort(H[z],G[z])})}function y(D){if(D){var E={q:[{field:b,operator:"EQUALS",value:D}]};return p.get("/api/v1/ontologyindex/",{q:E},null)}return null}function x(D){var E=p.get("/api/v1/"+D[k],{expand:["attributes"],q:{q:[{field:i,operator:"EQUALS",value:D[i]},{operator:"AND"},{field:B,operator:"EQUALS",value:D[B]}]}});return E.items.length>0?E.items[0]:null}function l(E){var D=p.get("/api/v1/"+E[k],{expand:["attributes"],q:{q:[{field:i,operator:"EQUALS",value:E[e]},{operator:"AND"},{field:B,operator:"EQUALS",value:E[s]}]}});return D.items.length>0?D.items[0]:null}function o(E,D){n.css({height:"500px",overflow:"auto"}).tree({entityMetaData:E,selectedAttributes:D,onAttributesSelect:function(F){console.log(F)},onAttributeClick:function(F){g("#ontology-term-info").empty().append(t(F))},lazyload:function(I,H){var F=I.node.data.attribute.href;var G=p.get(F,{expand:["attributes"]});I.result=H(h(G.attributes.items))}});n.on("hover","span.fancytree-title",function(H){var G=g.ui.fancytree.getNode(H);var J=G.li?g(G.li):g(G.ul);var I=a(G.data.attribute);if(I.synonyms.length>0){var F=g("");g.each(I.synonyms,function(K,L){F.append("* "+L+"
")});g(G.li).children("span:eq(0)").popover({title:"Synonyms",trigger:"hover",placement:"bottom",html:true,content:F}).popover("show")}})}function a(G){var H={};var E=p.get(G.href,{expand:["attributes"]},null);var F=E.href.substring(0,E.href.lastIndexOf("/")+1);var D=p.get(F,{expand:["attributes"],q:{q:[{field:i,operator:"EQUALS",value:E[i]}]}},null);if(D.items.length>0){H=h(D.items)[0]}return H}function t(G){var F=g("
").addClass("table").width("500px");var H=a(G);F.append('Ontology '+H[b]+" ");F.append('OntologyTerm '+H[i]+" ");F.append("Name "+H[d]+" ");if(H.description){F.append("Definition "+H[v]+" ")}if(H.synonyms&&H.synonyms.length>0){var E=g("
");g.each(H.synonyms,function(I,J){E.append(""+J+" ")});var D=g(" ").append(E);g(" ").append("Synonyms ").append(D).appendTo(F)}F.find("th").width("30%");return F}}($,window.top.molgenis=window.top.molgenis||{}));
© 2015 - 2025 Weber Informatics LLC | Privacy Policy