()
| 70 | |
| 71 | |
| 72 | function loadTree () { |
| 73 | $.get('apiv2/connection', function (isConnected) { |
| 74 | if (isConnected) { |
| 75 | $('#keyTree').on('loaded.jstree', function () { |
| 76 | var tree = getKeyTree(); |
| 77 | if (tree) { |
| 78 | var root = tree.get_container().children('ul:eq(0)').children('li'); |
| 79 | tree.open_node(root, null, true); |
| 80 | } |
| 81 | }); |
| 82 | $.get('connections', function (data) { |
| 83 | if (data.connections) { |
| 84 | connections.list = data.connections; |
| 85 | data.connections.every(function (instance) { |
| 86 | // build root objects for jstree view on left side |
| 87 | var treeObj = { |
| 88 | id: instance.conId, |
| 89 | text: instance.label + ' (' + instance.options.host + ':' + instance.options.port + ':' + instance.options.db + ')', |
| 90 | state: {opened: false}, |
| 91 | icon: getIconForType('root'), |
| 92 | children: true, |
| 93 | rel: 'root' |
| 94 | }; |
| 95 | connections.treeObjects.push(treeObj); |
| 96 | return true; |
| 97 | }); |
| 98 | } |
| 99 | return onJSTreeDataComplete(); |
| 100 | |
| 101 | function getJsTreeData(node, cb) { |
| 102 | if (node.id === '#') return cb(connections.treeObjects); |
| 103 | |
| 104 | var dataUrl; |
| 105 | if (node.parent === '#') { |
| 106 | dataUrl = 'apiv2/keystree/' + encodeURIComponent(node.id) + '/'; |
| 107 | } |
| 108 | else { |
| 109 | var root = getRootConnection(node); |
| 110 | var path = getFullKeyPath(node); |
| 111 | dataUrl = 'apiv2/keystree/' + encodeURIComponent(root) + '/' + encodeURIComponent(path) + '?absolute=false'; |
| 112 | } |
| 113 | $.get({ |
| 114 | url: dataUrl, |
| 115 | dataType: 'json' |
| 116 | }).done(function(nodeData) { |
| 117 | if (Array.isArray(nodeData.data)) { |
| 118 | nodeData.data.forEach(function(elem) { |
| 119 | if (elem.rel) elem.icon = getIconForType(elem.rel); |
| 120 | }); |
| 121 | } |
| 122 | cb(nodeData.data) |
| 123 | }).fail(function(error) { |
| 124 | console.log('Error fetching data for node ' + node.id + ': ' + JSON.stringify(error)); |
| 125 | if (error.responseJSON && error.responseJSON.connectionClosed) { |
| 126 | setRootConnectionNetworkError(true, node) |
| 127 | } |
| 128 | cb('Error fetching data'); |
| 129 | }); |
nothing calls this directly
no test coverage detected