samples/consul-ui/js/utils.js in consul-templaterb-1.12.0 vs samples/consul-ui/js/utils.js in consul-templaterb-1.13.0

- old
+ new

@@ -51,16 +51,16 @@ } } var htmlTitle = document.createElement('h5'); htmlTitle.setAttribute('title', 'Node Name: ' + instance.name + - '\nAddress : ' + instance.addr + + '\nAddress: ' + instance.addr + '\nService ID: ' + instance.id + - '\nService Port : ' + instance.port); + '\nService Port: ' + instance.port); + htmlTitle.setAttribute('class', 'instance-name'); var instanceLink = document.createElement('a'); - instanceLink.setAttribute('class', 'instance-name'); var appendPort = ""; if (instance.port > 0) { appendPort = ':' + instance.port; } if (protocol != null) { @@ -68,10 +68,12 @@ instanceLink.setAttribute('target', '_blank'); } instanceLink.appendChild(document.createTextNode(instance.name + appendPort)); htmlTitle.appendChild(instanceLink); + htmlTitle.appendChild(document.createTextNode(' ')); + htmlTitle.appendChild(document.createTextNode(instance.addr)); return htmlTitle; } function nodeNameGenator(nodename, nodeaddr) { @@ -91,39 +93,39 @@ return htmlTitle; } function nodeAddressGenator(nodeaddr) { var htmlAddress = document.createElement('h5'); - htmlAddress.className = 'instance-addr'; + htmlAddress.className = 'instance-addr lookup'; htmlAddress.appendChild(document.createTextNode(nodeaddr)); return htmlAddress; } -function nodeMetaGenator(nodeMetaTags) { +function nodeMetaGenerator(nodeMetaTags) { var metaTags = document.createElement('div'); - metaTags.className = 'meta-tags'; + metaTags.setAttribute('title', 'Node Meta') + metaTags.className = 'node-meta'; for (var tagKey in nodeMetaTags) { if(!nodeMetaTags[tagKey]) { continue; } var metaTag = document.createElement('span'); - metaTag.setAttribute('class', 'badge badge-primary mx-1'); + metaTag.setAttribute('class', 'badge badge-primary mx-1 lookup'); metaTag.appendChild(document.createTextNode(tagKey + ':' + nodeMetaTags[tagKey])); metaTags.appendChild(metaTag); } return metaTags; } function tagsGenerator(instanceTags) { var tags = document.createElement('div'); tags.className = 'instance-tags'; - tags.appendChild(document.createTextNode("Tags: ")); - tags.appendChild(document.createElement('br')); + tags.setAttribute('title', 'Tags of Service'); for (var tagKey in instanceTags) { var tag = document.createElement('span'); - tag.setAttribute('class', 'badge badge-secondary mx-1'); + tag.setAttribute('class', 'badge badge-secondary mx-1 lookup'); tag.appendChild(document.createTextNode(instanceTags[tagKey])); tags.appendChild(tag); } return tags; } @@ -158,15 +160,15 @@ var container = document.createElement('dl'); top.appendChild(container); container.className = 'row'; for (var meta in instanceMeta) { var metaH = document.createElement('dt'); - metaH.className = 'col-sm-4'; + metaH.className = 'col-sm-4 lookup'; metaH.appendChild(document.createTextNode(meta)); container.appendChild(metaH); var metaVH = document.createElement('dd'); - metaVH.className = 'col-sm-8'; + metaVH.className = 'col-sm-8 lookup'; metaVH.appendChild(document.createTextNode(instanceMeta[meta])); container.appendChild(metaVH); } } return top; @@ -214,11 +216,11 @@ services.appendChild(document.createElement('br')); for (var serviceKey in instanceServices) { var service = document.createElement('a'); var serviceName = instanceServices[serviceKey]['Service']['Service']; var servicePort = instanceServices[serviceKey]['Service']['Port']; - service.setAttribute('class', 'btn btn-sm m-1'); + service.setAttribute('class', 'btn btn-sm m-1 lookup'); service.setAttribute('target', '_blank'); nodeAddr = instanceServices[serviceKey]['Service']['Address']; service.setAttribute('href', 'http://' + nodeAddr + ':' + servicePort); service.classList.add('btn-outline-'+toCSSClass(nodeState(instanceServices[serviceKey]['Checks']))) service.appendChild(document.createTextNode(serviceName + ':' + servicePort)); @@ -229,12 +231,11 @@ function checksStatusGenerator(instance, prefix) { var instanceChecks = instance.checks; var checks = document.createElement('div'); checks.className = 'checks'; - checks.appendChild(document.createTextNode("Checks: ")); - checks.appendChild(document.createElement('br')); + checks.setAttribute('title', 'Checks of Node/Service') for (var checkKey in instanceChecks) { var checkInstance = instanceChecks[checkKey]; var checkId = prefix + '::' + checkInstance.checkid; var btn = 'btn-' + toCSSClass(instanceChecks[checkKey]['status']) @@ -352,47 +353,34 @@ if(service.getElementsByClassName('key-name')[0].innerHTML.match(regex)) { return true; } } +function hasMatches(instance, regex) { + var toLookup = instance.getElementsByClassName('lookup'); + for (var i = 0 ; i < toLookup.length; i++) { + if(toLookup[i].innerHTML.match(regex)) { + return true; + } + } + return false; +} + function instanceMatcher(instance, regex) { if(instance.getElementsByClassName('instance-name')[0].innerHTML.match(regex)) { return true; } - var tags = instance.getElementsByClassName('instance-tags')[0].getElementsByClassName('badge'); - - for (var i=0; i < tags.length; i++) { - if(tags[i].innerHTML.match(regex)) { - return true; - } - } - return false; + return hasMatches(instance, regex); } function nodeMatcher(instance, regex) { instanceMatcher(instance, regex); if(instance.getElementsByClassName('instance-name')[0].innerHTML.match(regex)) { return true; } - if(instance.getElementsByClassName('instance-addr')[0].innerHTML.match(regex)) { - return true; - } - - var metaTags = instance.getElementsByClassName('meta-tags')[0].getElementsByClassName('badge'); - for (var i=0; i < metaTags.length; i++) { - if(metaTags[i].innerHTML.match(regex)) { - return true; - } - } - - var services = instance.getElementsByClassName('instance-services')[0].getElementsByClassName('btn'); - for (var i=0; i < services.length; i++) { - if(services[i].innerHTML.match(regex)) { - return true; - } - } + return hasMatches(instance, regex); } function getTagsNode(node) { tags = new Set([]); for (service in node['Service']) {