webui: Added sysNames to pulldowns and the main page (#8137)

* Add dependency info for api

* webui: made dev dependency list more like devices page. Also added sysNames to pulldowns and the manin page

* Create common function for sysname display

* A better function name
This commit is contained in:
Aldemir Akpinar
2018-02-10 16:18:53 +03:00
committed by Neil Lathwood
parent 2018c9f804
commit 5880f06780
5 changed files with 36 additions and 17 deletions

View File

@ -19,13 +19,13 @@ if (is_admin() === false) {
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";
@ -42,7 +42,7 @@ if (is_admin() === false) {
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);
}
@ -62,7 +62,8 @@ if (is_admin() === false) {
$parent = $myrow['parents'];
}
array_push($res_arr, array( "deviceid" => $myrow['id'], "hostname" => $myrow['hostname'], "parent" => $parent, "parentid" => $myrow['parentid'] ));
$hostname = get_device_name($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 {

View File

@ -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 get_device_name($device)
{
$ret_str = '';
if (format_hostname($device) !== $device['sysName']) {
$ret_str = $device['sysName'];
} elseif ($device['hostname'] !== $device['ip']) {
$ret_str = $device['hostname'];
}
return $ret_str;
}

View File

@ -198,11 +198,7 @@ foreach (dbFetchRows($sql, $param) as $device) {
$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 .= '<br />' . get_device_name($device);
$metrics = array();
if ($port_count) {

View File

@ -32,6 +32,7 @@ require_once 'includes/modal/manage_host_dependencies.inc.php';
<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>
@ -79,7 +80,7 @@ var grid = $("#hostdeps").bootgrid({
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><br />'+row.sysname;
},
"parent": function(column, row) {
if (row.parent == 'None') {
@ -92,7 +93,7 @@ var grid = $("#hostdeps").bootgrid({
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);
}
@ -155,10 +156,11 @@ $(document).ready(function() {
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');

View File

@ -188,14 +188,14 @@ if ($updated && $update_message) {
?>
<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>