From 89d952f7e9475d79c9e9a46e78e84bd63978dd04 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 18 Jan 2023 16:15:18 +0100 Subject: [statistics] Listview: Display roomlayout and unique properties in a sidebar .... if viewport is wide enouh, it will be a sidebar, otherwise, it will be displayed above the actual list. --- modules-available/roomplanner/api.inc.php | 6 +-- .../roomplanner/inc/pvsgenerator.inc.php | 7 +++- .../roomplanner/templates/svg-plan.html | 14 ++++++- modules-available/statistics/pages/list.inc.php | 47 +++++++++++++++++++++- modules-available/statistics/pages/machine.inc.php | 4 ++ modules-available/statistics/style.css | 22 ++++++++++ .../statistics/templates/clientlist.html | 12 +++++- .../statistics/templates/machine-main.html | 11 +++-- 8 files changed, 110 insertions(+), 13 deletions(-) diff --git a/modules-available/roomplanner/api.inc.php b/modules-available/roomplanner/api.inc.php index 8ddb945c..1af25ca8 100644 --- a/modules-available/roomplanner/api.inc.php +++ b/modules-available/roomplanner/api.inc.php @@ -5,14 +5,14 @@ if (Request::any('show') === 'svg') { $ret = PvsGenerator::generateSvg(Request::any('locationid', false, 'int'), Request::any('machineuuid', false, 'string'), Request::any('rotate', 0, 'int'), - Request::any('scale', 1, 'float')); + Request::any('scale', 1, 'float'), + Request::any('url', false, 'bool')); if ($ret === false) { if (Request::any('fallback', 0, 'int') === 0) { Header('HTTP/1.1 404 Not Found'); exit; } $ret = << @@ -22,7 +22,7 @@ if (Request::any('show') === 'svg') { EOF; } Header('Content-Type: image/svg+xml'); - die($ret); + die('' . $ret); } // PVS.ini diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php index 0275054b..f23dcb20 100644 --- a/modules-available/roomplanner/inc/pvsgenerator.inc.php +++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php @@ -78,7 +78,7 @@ class PvsGenerator * @param float $scale scaling factor for output * @return string SVG */ - public static function generateSvg($locationId = false, $highlightUuid = false, $rotate = 0, $scale = 1) + public static function generateSvg($locationId = false, $highlightUuid = false, int $rotate = 0, $scale = 1, $links = false, array $present = null) { if ($locationId === false) { $locationId = Database::queryFirst('SELECT fixedlocationid FROM machine @@ -105,7 +105,7 @@ class PvsGenerator // Figure out autorotate $auto = ($rotate < 0); if ($auto && $highlightUuid !== false) { - foreach ($machines as &$machine) { + foreach ($machines as $machine) { if ($machine['machineuuid'] === $highlightUuid) { $rotate = 4 - $ORIENTATION[$machine['rotation']]; // Reverse rotation break; @@ -117,6 +117,8 @@ class PvsGenerator foreach ($machines as &$machine) { if ($machine['machineuuid'] === $highlightUuid) { $machine['class'] = 'hl'; + } elseif (!empty($present) && !in_array($machine['machineuuid'], $present)) { + $machine['class'] = 'muted'; } $machine['rotation'] = $ORIENTATION[$machine['rotation']] * 90; } @@ -140,6 +142,7 @@ class PvsGenerator 'centerY' => $centerY, 'rotate' => $rotate * 90, 'machines' => $machines, + 'links' => $links, 'line' => ['x' => $sizeX, 'y' => $sizeY], ], 'roomplanner'); // FIXME: Needs module param if called from api.inc.php } diff --git a/modules-available/roomplanner/templates/svg-plan.html b/modules-available/roomplanner/templates/svg-plan.html index a2ecd5a7..4b0339f3 100644 --- a/modules-available/roomplanner/templates/svg-plan.html +++ b/modules-available/roomplanner/templates/svg-plan.html @@ -1,4 +1,3 @@ - @@ -32,12 +34,19 @@ + + + + {{#machines}} + {{#links}} + + {{/links}} + {{#links}} + + {{/links}} {{/machines}} diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php index db5f262a..2c49c525 100644 --- a/modules-available/statistics/pages/list.inc.php +++ b/modules-available/statistics/pages/list.inc.php @@ -25,7 +25,7 @@ class SubPage /** * @param \StatisticsFilterSet $filterSet */ - private static function showMachineList($filterSet) + private static function showMachineList(StatisticsFilterSet $filterSet) { Module::isAvailable('js_stupidtable'); $filterSet->makeFragments($where, $join, $args); @@ -77,6 +77,7 @@ class SubPage $detailsAllowedLocations = User::getAllowedLocations("machine.view-details"); $location = self::buildLocationLookup(); $rows = []; + $colValCount = []; // Count unique values for several columns foreach ($allRows as &$row) { $row['link_details'] = in_array($row['locationid'], $detailsAllowedLocations); //$row['firstseen'] = Util::prettyTime($row['firstseen']); @@ -145,8 +146,40 @@ class SubPage if ($row['locationid'] > 0) { $row['location'] = $location[$row['locationid']]; } + foreach (['locationid', 'cpumodel', 'nic-speed_s', 'gbram', 'gbtmp'] as $key) { + if (!isset($colValCount[$key][$row[$key]])) { + $colValCount[$key][$row[$key]] = []; + } + $colValCount[$key][$row[$key]][] = $row['machineuuid']; + } $rows[] =& $row; } + $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; + } + $side[] = $val; + } + } $data = array( 'rowCount' => count($rows), 'rows' => $rows, @@ -160,6 +193,8 @@ class SubPage 'canWol' => !empty($wolAllowedLocations), 'canExec' => !empty($execAllowedLocations), 'canBenchmark' => !empty($benchmarkAllowedLocations), + 'roomsvg' => $roomsvg, + 'sidebar' => $side, ); Render::addTemplate('clientlist', $data); } @@ -175,3 +210,13 @@ class SubPage } } + +// Remove when we require >= 7.3.0 +if (!function_exists('array_key_first')) { + function array_key_first(array $arr) { + foreach($arr as $key => $unused) { + return $key; + } + return NULL; + } +} \ No newline at end of file diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index f9724b5c..1b93584e 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -71,6 +71,10 @@ class SubPage } $locations = Location::getLocationRootChain($client['locationid']); } + if ($client['locationid'] && $client['hasroomplan'] && Module::isAvailable('roomplanner')) { + $client['roomsvg'] = PvsGenerator::generateSvg($client['locationid'], $client['machineuuid'], + 0, 1, true); + } User::assertPermission('machine.view-details', (int)$client['locationid']); // Hack: Get raw collected data if (Request::get('raw', false)) { diff --git a/modules-available/statistics/style.css b/modules-available/statistics/style.css index 7e1539ec..7bd60b44 100644 --- a/modules-available/statistics/style.css +++ b/modules-available/statistics/style.css @@ -93,3 +93,25 @@ 50% { background: #f2dede } 100% { background: unset } } + +.slx-right { + float: right; +} +@media (min-width: 1650px) { + .slx-right { + position: fixed; + right: 10px; + display: block; + min-width: 140px; + width: calc(100vw - 1550px); + float: none !important; + } +} + +.infobox { + border: 1px solid #aaa; + background: #eee; + border-radius: 3px; + margin: 3px auto; + padding: 0 2px; +} \ No newline at end of file diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html index 714fdfc0..d0e330e8 100644 --- a/modules-available/statistics/templates/clientlist.html +++ b/modules-available/statistics/templates/clientlist.html @@ -1,7 +1,15 @@ - +
+ {{{roomsvg}}} + {{#sidebar}} +
{{.}}
+ {{/sidebar}} +

{{lang_clientList}} ({{rowCount}})

+ + +
diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html index cba9c62a..be32f9c7 100644 --- a/modules-available/statistics/templates/machine-main.html +++ b/modules-available/statistics/templates/machine-main.html @@ -104,19 +104,22 @@ {{/modeid}} - {{#hasroomplan}} + {{#roomsvg}} {{lang_roomplan}} +
+ {{{roomsvg}}} +
- + onclick="window.open(this.href, '_blank', 'toolbar=0,scrollbars,resizable');return false"> + {{lang_edit}} - {{/hasroomplan}} + {{/roomsvg}} {{#rebootcontrol}} -- cgit v1.2.3-55-g7522