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

webui: added sysNames to pulldowns and the main page #8137

Merged
merged 8 commits into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
9 changes: 5 additions & 4 deletions html/includes/forms/get-host-dependencies.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
if ($_POST['viewtype'] == 'fulllist') {
$count_query = "SELECT count(device_id) from devices";

$deps_query = "SELECT a.device_id as id, a.hostname as hostname, GROUP_CONCAT(b.hostname) as parents, GROUP_CONCAT(b.device_id) as parentid FROM devices as a LEFT JOIN device_relationships a1 ON a.device_id=a1.child_device_id LEFT JOIN devices b ON b.device_id=a1.parent_device_id GROUP BY a.device_id, a.hostname";
$deps_query = "SELECT a.device_id as id, a.hostname as hostname, a.sysName as sysName, GROUP_CONCAT(b.hostname) as parents, GROUP_CONCAT(b.device_id) as parentid FROM devices as a LEFT JOIN device_relationships a1 ON a.device_id=a1.child_device_id LEFT JOIN devices b ON b.device_id=a1.parent_device_id GROUP BY a.device_id, a.hostname, a.sysName";

if (isset($_POST['format'])) {
if (isset($_POST['searchPhrase']) && !empty($_POST['searchPhrase'])) {
#This is a bit ugly
$deps_query = "SELECT * FROM (".$deps_query;
$deps_query .= " ) as t WHERE t.hostname LIKE ? OR t.parents LIKE ? ";
$deps_query .= " ) as t WHERE t.hostname LIKE ? OR t.parents LIKE ? OR t.sysname LIKE ? ";
$deps_query .= " ORDER BY t.hostname";
} else {
$deps_query .= " ORDER BY a.hostname";
Expand All @@ -42,7 +42,7 @@

if (isset($_POST['format']) && !empty($_POST['searchPhrase'])) {
$searchphrase = '%'.mres($_POST['searchPhrase']).'%';
$device_deps = dbFetchRows($deps_query, array($searchphrase, $searchphrase));
$device_deps = dbFetchRows($deps_query, array($searchphrase, $searchphrase, $searchphrase));
} else {
$device_deps = dbFetchRows($deps_query);
}
Expand All @@ -62,7 +62,8 @@
$parent = $myrow['parents'];
}

array_push($res_arr, array( "deviceid" => $myrow['id'], "hostname" => $myrow['hostname'], "parent" => $parent, "parentid" => $myrow['parentid'] ));
$hostname = add_sysname_or_hostname($myrow);
array_push($res_arr, array( "deviceid" => $myrow['id'], "hostname" => $myrow['hostname'], "sysname" => $hostname, "parent" => $parent, "parentid" => $myrow['parentid'] ));
}
$status = array('current' => $_POST['current'], 'rowCount' => $_POST['rowCount'], 'rows' => $res_arr, 'total' => $rec_count);
} else {
Expand Down
20 changes: 20 additions & 0 deletions html/includes/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1696,3 +1696,23 @@ function get_zfs_pools($device_id)

return array();
}

/**
* Returns the sysname of a device with a html line break prepended.
* if the device has an empty sysname it will return device's hostname instead
* And finally if the device has no hostname it will return an empty string
* @param device array
* @return string
*/
function add_sysname_or_hostname($device)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe return_sysname_or_hostname?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about get_device_name()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we pass a $html = false flag to it and it can then be re-used in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the html bits altogether.

{
$ret_str = '';

if (format_hostname($device) !== $device['sysName']) {
$ret_str .= '<br />' . $device['sysName'];
} elseif ($device['hostname'] !== $device['ip']) {
$ret_str .= '<br />' . $device['hostname'];
}

return $ret_str;
}
6 changes: 1 addition & 5 deletions html/includes/table/devices.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,7 @@
$os = $device['os_text'] . '<br>' . $device['version'];
$device['ip'] = inet6_ntop($device['ip']);
$uptime = formatUptime($device['uptime'], 'short');
if (format_hostname($device) !== $device['sysName']) {
$hostname .= '<br />' . $device['sysName'];
} elseif ($device['hostname'] !== $device['ip']) {
$hostname .= '<br />' . $device['hostname'];
}
$hostname .= add_sysname_or_hostname($device);

$metrics = array();
if ($port_count) {
Expand Down
14 changes: 8 additions & 6 deletions html/pages/device-dependencies.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<tr>
<th data-column-id="deviceid" data-visible="false" data-css-class="deviceid">No</th>
<th data-column-id="hostname" data-type="string" data-css-class="childhost" data-formatter="hostname">Hostname</th>
<th data-column-id="sysname" data-type="string" data-visible="false">Sysname</th>
<th data-column-id="parent" data-type="string" data-css-class="parenthost" data-formatter="parent">Parent Device(s)</th>
<th data-column-id="parentid" data-visible="false">Parent ID</th>
<th data-column-id="actions" data-searchable="false" data-formatter="actions">Actions</th>
Expand Down Expand Up @@ -79,7 +80,7 @@
return response;
},
"hostname": function(column, row) {
return '<a href="device/device='+row.deviceid+'/">'+row.hostname+'</a>';
return '<a href="device/device='+row.deviceid+'/" class="list-device">'+row.hostname+'</a>'+row.sysname;
},
"parent": function(column, row) {
if (row.parent == 'None') {
Expand All @@ -92,7 +93,7 @@
tempids = row.parentid.split(',');
var retstr = '';
for (i=0; i < temp.length; i++) {
retstr = retstr + '<a href="device/device='+tempids[i]+'/">'+temp[i]+'</a>, ';
retstr = retstr + '<a href="device/device='+tempids[i]+'/" class="list-device">'+temp[i]+'</a>, ';
}
return retstr.slice(0, -2);
}
Expand Down Expand Up @@ -155,10 +156,11 @@
editSelect.append($('<option>', { value: 0, text: 'None'}));
manParentDevstoClr.append($('<option>', { value: 0, text: 'None'}));
$.each(output.deps, function (i,elem) {
manParentDevs.append($('<option>',{value:elem.id, text:elem.hostname}));
editSelect.append($('<option>',{value:elem.id, text:elem.hostname}));
manAllDevs.append($('<option>',{value:elem.id, text:elem.hostname}));
manParentDevstoClr.append($('<option>',{value:elem.id, text:elem.hostname}));
var devtext = elem.hostname + ' (' + elem.sysname + ')';
manParentDevs.append($('<option>',{value:elem.id, text:devtext}));
editSelect.append($('<option>',{value:elem.id, text:devtext}));
manAllDevs.append($('<option>',{value:elem.id, text:devtext}));
manParentDevstoClr.append($('<option>',{value:elem.id, text:devtext}));
});
} else {
toastr.error('Device dependencies could not be retrieved from the database');
Expand Down
4 changes: 2 additions & 2 deletions html/pages/device/edit/device.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@
?>
<option value="0" <?=$selected?>>None</option>
<?php
$available_devs = dbFetchRows('SELECT `device_id`,`hostname` FROM `devices` WHERE `device_id` <> ? ORDER BY `hostname` ASC', array($device['device_id']));
$available_devs = dbFetchRows('SELECT `device_id`,`hostname`,`sysName` FROM `devices` WHERE `device_id` <> ? ORDER BY `hostname` ASC', array($device['device_id']));
foreach ($available_devs as $dev) {
if (in_array($dev['device_id'], $dev_parents)) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
echo "<option value=".$dev['device_id']." ".$selected.">".$dev['hostname']."</option>";
echo "<option value=". $dev['device_id']. " " . $selected . ">" . $dev['hostname'] . " (" . $dev['sysName'] .")</option>";
}
?>
</select>
Expand Down