From c8c07db57da7f7aec01c209aed82297cd321bbec Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 28 Feb 2023 11:07:30 +0100 Subject: [statistics] Fix warning on empty list; add comments --- modules-available/statistics/pages/list.inc.php | 51 ++++++++++++++----------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'modules-available/statistics/pages') diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php index 2c49c525..12689e97 100644 --- a/modules-available/statistics/pages/list.inc.php +++ b/modules-available/statistics/pages/list.inc.php @@ -118,6 +118,7 @@ class SubPage if (isset($row['data']) && !$row['data']) { $row['nohdd'] = true; } + // Shorten CPU names a bit for prettier display in small column $row['cpumodel'] = preg_replace('/\(R\)|\(TM\)|\bintel\b|\bamd\b|\bcpu\b|dual-core|\bdual\s+core\b|\bdual\b|\bprocessor\b/i', ' ', $row['cpumodel']); if (!empty($row['rmmodule'])) { $data = RunMode::getRunMode($row['machineuuid'], RunMode::DATA_STRINGS); @@ -154,30 +155,36 @@ class SubPage } $rows[] =& $row; } + // Now if all machines are from the same location, try to load the roomplan + // Also, collect all properties that are the same across all machines for display in the sidebar $roomsvg = null; - if (count($colValCount['locationid']) === 1 && ($lid = array_key_first($colValCount['locationid'])) - && Module::isAvailable('roomplanner')) { - $roomsvg = PvsGenerator::generateSvg($lid, false, 0, 1, true, $colValCount['locationid'][$lid]); - } $side = []; - foreach (['locationid', 'cpumodel', 'nic-speed_s', 'gbram', 'gbtmp'] as $key) { - if (count($colValCount[$key]) === 1) { - $val = array_key_first($colValCount[$key]); - switch ($key) { - case 'locationid': - $val = $location[$val]['name']; - break; - case 'gbram': - $val .= ' GiB RAM'; - break; - case 'gbtmp': - $val .= ' GiB ID-44'; - break; - case 'nic-speed_s': - $val .= ' MBit/s'; - break; + if (!empty($rows) && !empty($colValCount)) { + if (count($colValCount['locationid']) === 1 && ($lid = array_key_first($colValCount['locationid'])) + && Module::isAvailable('roomplanner')) { + $roomsvg = PvsGenerator::generateSvg($lid, false, 0, 1, true, $colValCount['locationid'][$lid]); + } + // Handle our selected attributes + foreach (['locationid', 'cpumodel', 'nic-speed_s', 'gbram', 'gbtmp'] as $key) { + if (count($colValCount[$key]) === 1) { + $val = array_key_first($colValCount[$key]); + // Suffixes are not localized, but hopefully generic enough for now + switch ($key) { + case 'locationid': + $val = $location[$val]['name']; + break; + case 'gbram': + $val .= ' GiB RAM'; + break; + case 'gbtmp': + $val .= ' GiB ID-44'; + break; + case 'nic-speed_s': + $val .= ' MBit/s'; + break; + } + $side[] = $val; } - $side[] = $val; } } $data = array( @@ -199,7 +206,7 @@ class SubPage Render::addTemplate('clientlist', $data); } - private static function buildLocationLookup() + private static function buildLocationLookup(): array { $ret = []; $i = 0; -- cgit v1.2.3-55-g7522