From 6d3bf03074a118e781f57519d980c8e6ee500671 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sat, 12 Mar 2022 16:14:09 -0600 Subject: [PATCH] Display Name in availability map (#13841) * Display Name option in availability map widget * fix availability map page and shortDisplayName --- app/Models/Device.php | 2 +- includes/html/common/availability-map.inc.php | 2 +- resources/views/widgets/availability-map.blade.php | 14 ++++++-------- .../widgets/settings/availability-map.blade.php | 1 + 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/Models/Device.php b/app/Models/Device.php index 0cdd96afc4..c4a539a354 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -242,7 +242,7 @@ class Device extends BaseModel $length = \LibreNMS\Config::get('shorthost_target_length', $length); if ($length < strlen($name)) { - $take = substr_count($name, '.', 0, $length) + 1; + $take = max(substr_count($name, '.', 0, $length), 1); return implode('.', array_slice(explode('.', $name), 0, $take)); } diff --git a/includes/html/common/availability-map.inc.php b/includes/html/common/availability-map.inc.php index 9137620006..ffd1f4d3bc 100644 --- a/includes/html/common/availability-map.inc.php +++ b/includes/html/common/availability-map.inc.php @@ -170,7 +170,7 @@ if (defined('SHOW_SETTINGS')) { $in_devices = dbFetchColumn($device_group, [Session::get('group_view')]); } - $sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`last_polled`, `D`.`os`, `D`.`icon`, `D`.`disable_notify`, `D`.`disabled` FROM `devices` AS `D`'; + $sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`display`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`last_polled`, `D`.`os`, `D`.`icon`, `D`.`disable_notify`, `D`.`disabled` FROM `devices` AS `D`'; if (! Auth::user()->hasGlobalRead()) { $sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND '; diff --git a/resources/views/widgets/availability-map.blade.php b/resources/views/widgets/availability-map.blade.php index 6ae9fb7cef..dbd8cbe053 100644 --- a/resources/views/widgets/availability-map.blade.php +++ b/resources/views/widgets/availability-map.blade.php @@ -30,17 +30,15 @@ @if($type == 0) @if($color_only_select == 1) - @else - @if($color_only_select == 2) - {{ __($row['device']->hostname) }} - @else - @if($color_only_select == 3) - {{ __($row['device']->sysName) }} + @elseif($color_only_select == 2) + {{ $row['device']->hostname }} + @elseif($color_only_select == 3) + {{ $row['device']->sysName }} + @elseif($color_only_select == 4) + {{ $row['device']->shortDisplayName() }} @else {{ __($row['stateName']) }} @endif - @endif - @endif @else
@endif diff --git a/resources/views/widgets/settings/availability-map.blade.php b/resources/views/widgets/settings/availability-map.blade.php index 4a76871220..525ccb76da 100644 --- a/resources/views/widgets/settings/availability-map.blade.php +++ b/resources/views/widgets/settings/availability-map.blade.php @@ -18,6 +18,7 @@