Skip to content
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
6 changes: 6 additions & 0 deletions serveradmin/servershell/static/css/servershell.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,9 @@ th:hover .attr-headericons {
#result_table textarea {
resize: both;
}

/* Relation/reverse attribute values, ctrl-click opens inspect in new tab */
.relation-link {
cursor: pointer;
text-decoration: underline dotted;
}
55 changes: 54 additions & 1 deletion serveradmin/servershell/static/js/servershell/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ get_row_html = function(object, number) {
cell.append(current);
}
}
else if (attribute.type === 'relation' || attribute.type === 'reverse') {
// Render related objects as ctrl-clickable links to inspect
append_relation_links(cell, object[attribute_id]);
}
else {
cell.text(get_string(object_id, attribute_id));
}
Expand All @@ -152,8 +156,16 @@ get_row_html = function(object, number) {
row.append(cell);
}
else {
let attribute = servershell.get_attribute(attribute_id);
let cell = $('<td class="disabled">');
cell.text(get_string(object.object_id, attribute_id));
if (attribute.type === 'relation' || attribute.type === 'reverse') {
// Reverse attributes are readonly and land here, make them
// ctrl-clickable links to inspect the related objects.
append_relation_links(cell, object[attribute_id]);
}
else {
cell.text(get_string(object.object_id, attribute_id));
}
row.append(cell);
}
});
Expand Down Expand Up @@ -223,6 +235,47 @@ get_string = function(object_id, attribute_id) {
return '';
};

/**
* Append relation/reverse attribute values as ctrl-clickable links
*
* Each related object is identified by its hostname. Ctrl-click (or cmd-click
* on macOS) opens the inspect page for that hostname in a new tab. Plain click
* is left untouched so row selection and inline editing (double click) on
* editable relations keep working as before.
*
* @param cell jQuery td element
* @param value hostname string (multi=false) or array of hostnames (multi=true)
*/
append_relation_links = function(cell, value) {
if (value === null || value === undefined) {
return;
}

// Normalize single relations and multi relations to a sorted list so the
// display matches get_string() ordering.
let hostnames = Array.isArray(value) ? value.slice().sort() : [value];

hostnames.forEach(function(hostname, index) {
if (index > 0) {
cell.append(', ');
}

let link = $('<span class="relation-link" title="Ctrl-click to inspect">').text(hostname);
link.click(function(event) {
// Only hijack ctrl/cmd-click, leave plain clicks alone.
if (!event.ctrlKey && !event.metaKey) {
return;
}
event.preventDefault();
window.open(
`${servershell.urls.inspect}?hostname=${encodeURIComponent(hostname)}`,
'_blank'
);
});
cell.append(link);
});
};

/**
* Make row editable by double click
*
Expand Down
Loading