From 259b1c8bbb3617c65a9ed073ed340acade32c543 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 19 May 2020 15:37:44 +0200 Subject: [locations] Show colored bars for used/idle/offline in overview --- modules-available/locations/pages/locations.inc.php | 16 +++++++++------- modules-available/locations/style.css | 5 +++++ modules-available/locations/templates/locations.html | 14 ++++++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/modules-available/locations/pages/locations.inc.php b/modules-available/locations/pages/locations.inc.php index 54f44554..8afb454a 100644 --- a/modules-available/locations/pages/locations.inc.php +++ b/modules-available/locations/pages/locations.inc.php @@ -90,8 +90,7 @@ class SubPage unset($locationList[0]); // Statistics: Count machines for each subnet $unassigned = false; - $unassignedLoad = 0; - $unassignedOverrides = 0; + $unassignedIdle = $unassignedLoad = $unassignedOverrides = 0; $allowedLocationIds = User::getAllowedLocations("location.view"); foreach (array_keys($locationList) as $lid) { @@ -119,16 +118,19 @@ class SubPage if (in_array(0, $allowedLocationIds)) { $extra = ' OR locationid IS NULL'; } - $res = Database::simpleQuery("SELECT m.locationid, Count(*) AS cnt, Sum(If(m.state = 'OCCUPIED', 1, 0)) AS used + $res = Database::simpleQuery("SELECT m.locationid, Count(*) AS cnt, + Sum(If(m.state = 'OCCUPIED', 1, 0)) AS used, Sum(If(m.state = 'IDLE', 1, 0)) AS idle FROM machine m WHERE (locationid IN (:allowedLocationIds) $extra) GROUP BY locationid", compact('allowedLocationIds')); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $locId = (int)$row['locationid']; if (isset($locationList[$locId])) { $locationList[$locId]['clientCount'] = $row['cnt']; - $locationList[$locId]['clientLoad'] = round(100 * $row['used'] / $row['cnt']) . ' %'; + $locationList[$locId]['clientLoad'] = round(100 * $row['used'] / $row['cnt']); + $locationList[$locId]['clientIdle'] = round(100 * ($row['used'] + $row['idle']) / $row['cnt']); } else { $unassigned += $row['cnt']; $unassignedLoad += $row['used']; + $unassignedIdle += $row['idle']; } } $res = Database::simpleQuery("SELECT m.locationid, Count(DISTINCT sm.machineuuid) AS cnt FROM setting_machine sm @@ -149,8 +151,7 @@ class SubPage $loc['clientCountSum'] = 0; } if (!isset($loc['clientCount'])) { - $loc['clientCount'] = 0; - $loc['clientLoad'] = '0%'; + $loc['clientCount'] = $loc['clientIdle'] = $loc['clientLoad'] = 0; } $loc['clientCountSum'] += $loc['clientCount']; foreach ($loc['parents'] as $pid) { @@ -233,7 +234,8 @@ class SubPage 'overlapOther' => $overlapOther, 'mismatchMachines' => $mismatchMachines, 'unassignedCount' => $unassigned, - 'unassignedLoad' => ($unassigned ? (round(($unassignedLoad / $unassigned) * 100) . ' %') : ''), + 'unassignedLoad' => ($unassigned ? (round(($unassignedLoad / $unassigned) * 100)) : ''), + 'unassignedIdle' => ($unassigned ? (round((($unassignedLoad + $unassignedIdle) / $unassigned) * 100)) : ''), 'unassignedOverrides' => $unassignedOverrides, 'defaultConfig' => $defaultConfig, 'addAllowedList' => array_values($addAllowedList), diff --git a/modules-available/locations/style.css b/modules-available/locations/style.css index 042ac4d1..19950a38 100644 --- a/modules-available/locations/style.css +++ b/modules-available/locations/style.css @@ -12,3 +12,8 @@ table.locations tbody td:nth-of-type(even) { pointer-events: none; opacity: 0.6; } + +.load-col { + text-align: right; + text-shadow: 1px 1px #fff; +} \ No newline at end of file diff --git a/modules-available/locations/templates/locations.html b/modules-available/locations/templates/locations.html index e2224bc0..7adfe2fc 100644 --- a/modules-available/locations/templates/locations.html +++ b/modules-available/locations/templates/locations.html @@ -71,10 +71,10 @@ {{/havestatistics}} - - {{#havestatistics}} - {{clientLoad}} - {{/havestatistics}} + + {{#clientCount}} + {{clientLoad}} % + {{/clientCount}} {{#havebaseconfig}} @@ -125,8 +125,10 @@ - - {{unassignedLoad}} + + {{#unassignedCount}} + {{unassignedLoad}} % + {{/unassignedCount}} {{#unassignedOverrides}} -- cgit v1.2.3-55-g7522