bdd18de186c0f34406ca395e7ba9b1b88980587d chmalee Mon Sep 23 16:44:07 2019 -0700 Optimizing the jstree on hgHubConnect by writing out a javascript object and letting ajax load the nodes of the tree on an as-needed basis. Also adding measureTiming to hgHubConnect, refs #23812 diff --git src/hg/js/hgHubConnect.js src/hg/js/hgHubConnect.js index 4fc3bc8..a273807 100644 --- src/hg/js/hgHubConnect.js +++ src/hg/js/hgHubConnect.js @@ -40,15 +40,102 @@ } }); $('#hubSearchTerms').bind('keypress', function(e) { // binds listener to text field if (e.which === 13) { // listens for return key e.preventDefault(); // prevents return from also submitting whole form $('input[name="hubSearchButton"]').focus().click(); // clicks search button } }); $('#hubDbFilter').bind('keypress', function(e) { // binds listener to text field if (e.which === 13) { // listens for return key e.preventDefault(); // prevents return from also submitting whole form $('input[name="hubSearchButton"]').focus().click(); // clicks db filter button } }); }); + +var hubSearchTree = (function() { + var treeDiv; // Points to div we live in + + function hubSearchTreeContextMenuHandler (node, callback) { + var nodeType = node.li_attr.nodetype; + if (nodeType == 'track') { + callback({ + 'openConfig': { + 'label' : 'Configure this track', + 'action' : function () { + window.open(node.li_attr.configlink, '_blank'); + } + } + }); + } + else if (nodeType == 'assembly') { + callback({ + 'openConfig': { + 'label' : 'Open this assembly', + 'action' : function () { + window.open(node.li_attr.assemblylink, '_blank'); + } + } + }); + } + } + + function buildTracks(node, cb) { + // called when jstree wants data to open a node for the tracks tree + cb.call(this, trackData[node.id]); + } + + function init(searching) { + $.jstree.defaults.core.themes.icons = false; + $.jstree.defaults.core.themes.dots = true; + $.jstree.defaults.contextmenu.show_at_node = false; + if (searching === true) { + console.log("special build"); + $.jstree.defaults.contextmenu.items = hubSearchTreeContextMenuHandler; + + $('div[id^="tracks"]').each(function(i, obj) { + treeDiv = obj; + var hubId = treeDiv.id.slice(6); + arrId = '#_' + hubId; + $(treeDiv).jstree({ + 'plugins' : ['contextmenu'], + 'core' : { + 'data': function(node, cb) { + if (node.id === '#') { + cb([{"text" : "Search details ...", "id": arrId, "children": true}]); + } else { + cb(trackData[""+node.id]); + } + }, + 'dbclick_toggle': false + } + }) + .on('select_node.jstree', function(e, data) { + data.instance.open_node(data.node); + }); // jstree + }); // each div + } else { // validating hub, no contextmenu and easier tree building + console.log("regular trackData build"); + treeDiv = $('#validateHubResult'); + treeDiv.jstree({ + 'core' : { + 'data' : buildTracks, + 'dbclick_toggle': false + } + }); + treeDiv.on('select_node.jstree', function(e, data) { + $(e.target).instance.open_node(data.node); + }); + } + } // init + return { + init: init + }; +}()); + +$(function () { + console.time("init time"); + // the parameter describes whether we have searched or are validating + hubSearchTree.init(false); + console.timeEnd("init time"); +});