Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decorator for service & node name to allow using node metadata #70

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions samples/consul-ui/decorators.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ function usefullLinksGenerator(instance, serviceName, node_meta_info) {
return top;
}

/**
* createNodeDisplayElement resolves and displays the node name.
*/
function createNodeDisplayElement(nodeName, nodemeta) {
return document.createTextNode(nodeName);
}

/**
* serviceInstanceDecorator is called to decorate an instance.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/consul-ui/js/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NodeMainSelector extends MainSelector {
content.setAttribute('class', 'instance-content');
var contentHead = document.createElement('div');
contentHead.setAttribute('class', 'instance-content-header');
contentHead.appendChild(nodeNameGenator(node['Node']['Name'], node['Node']['Address']));
contentHead.appendChild(nodeNameGenator(node['Node']));
contentHead.appendChild(nodeAddressGenator(node['Node']['Address']));
contentHead.appendChild(nodeMetaGenerator(node['Node']['Meta']));
content.appendChild(contentHead);
Expand Down
2 changes: 1 addition & 1 deletion samples/consul-ui/js/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ class ServiceMainSelector extends MainSelector {
element.setAttribute("class", "list-group-item service-instance");
var state = nodeState(instance.checks);
element.appendChild(weightsGenerator(instance.weights, state));
element.appendChild(serviceTitleGenerator(instance, serviceName));
var node_info = this.nodes[instance.name];
element.appendChild(serviceTitleGenerator(instance, serviceName, node_info));
if (node_info != null) {
node_info = node_info.meta;
element.appendChild(nodeMetaGenerator(node_info, instance.sMeta));
Expand Down
13 changes: 8 additions & 5 deletions samples/consul-ui/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function nodeState(checks) {

supported_protocols = ['https', 'http', 'sftp', 'ftp', 'ssh', 'telnet']

function serviceTitleGenerator(instance, serviceName) {
function serviceTitleGenerator(instance, serviceName, node_info) {
var protocol = null;
for (i in supported_protocols) {
var protoc = supported_protocols[i]
Expand All @@ -86,7 +86,10 @@ function serviceTitleGenerator(instance, serviceName) {
instanceLink.setAttribute('target', '_blank');
}

instanceLink.appendChild(document.createTextNode(instance.name + appendPort));
var nodemeta = (node_info != null) ? node_info.meta : null;
instanceLink.appendChild(createNodeDisplayElement(instance.name, nodemeta));
instanceLink.appendChild(document.createTextNode(appendPort));

const nodeInfo = document.createElement('a');
nodeInfo.appendChild(document.createTextNode('\u24D8'));
nodeInfo.setAttribute('title', 'Click to see details of Node: ' + instance.name +
Expand All @@ -103,18 +106,18 @@ function serviceTitleGenerator(instance, serviceName) {
return htmlTitle;
}

function nodeNameGenator(nodename, nodeaddr) {
function nodeNameGenator(node) {
var protocol = 'ssh://'

var htmlTitle = document.createElement('h5');

var instanceLink = document.createElement('a');
instanceLink.setAttribute('class', 'instance-name');
if (protocol != null) {
instanceLink.setAttribute('href', protocol + nodeaddr);
instanceLink.setAttribute('href', protocol + node['Address']);
instanceLink.setAttribute('target', '_blank');
}
instanceLink.appendChild(document.createTextNode(nodename));
instanceLink.appendChild(createNodeDisplayElement(node['Name'], node['Meta']));
htmlTitle.appendChild(instanceLink);

return htmlTitle;
Expand Down