summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-01-18 16:15:18 +0100
committerSimon Rettberg2023-01-18 16:15:18 +0100
commit89d952f7e9475d79c9e9a46e78e84bd63978dd04 (patch)
tree5a15c3994ae8dcb5c061b3cf28a27f6337cdd5cc
parent[dnbd3] Extend timeout for inactive graph (diff)
downloadslx-admin-89d952f7e9475d79c9e9a46e78e84bd63978dd04.tar.gz
slx-admin-89d952f7e9475d79c9e9a46e78e84bd63978dd04.tar.xz
slx-admin-89d952f7e9475d79c9e9a46e78e84bd63978dd04.zip
[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.
-rw-r--r--modules-available/roomplanner/api.inc.php6
-rw-r--r--modules-available/roomplanner/inc/pvsgenerator.inc.php7
-rw-r--r--modules-available/roomplanner/templates/svg-plan.html14
-rw-r--r--modules-available/statistics/pages/list.inc.php47
-rw-r--r--modules-available/statistics/pages/machine.inc.php4
-rw-r--r--modules-available/statistics/style.css22
-rw-r--r--modules-available/statistics/templates/clientlist.html12
-rw-r--r--modules-available/statistics/templates/machine-main.html11
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 = <<<EOF
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 64 64" height="64" width="64">
<g>
<path d="M 0,0 64,64 Z" style="stroke:#ff0000;stroke-width:5" />
@@ -22,7 +22,7 @@ if (Request::any('show') === 'svg') {
EOF;
}
Header('Content-Type: image/svg+xml');
- die($ret);
+ die('<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $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 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
@@ -21,6 +20,9 @@
rect.hl {
fill: url(#screenhl);
}
+ rect.muted {
+ fill: url(#muted);
+ }
]]>
</style>
<defs>
@@ -32,12 +34,19 @@
<stop offset="0%" stop-color="#afa" />
<stop offset="100%" stop-color="#074" />
</radialGradient>
+ <radialGradient id="muted" cx=".4" cy=".3" r="1">
+ <stop offset="0%" stop-color="#bbb" />
+ <stop offset="100%" stop-color="#888" />
+ </radialGradient>
</defs>
<g transform="scale({{scale}}) rotate({{rotate}} {{centerX}} {{centerY}})">
<line x1="0" y1="{{line.y}}"
x2="{{line.x}}" y2="{{line.y}}"
style="stroke:#555;stroke-width:.2;opacity:.5" />
{{#machines}}
+ {{#links}}
+ <a xlink:href="./?do=statistics&amp;uuid={{machineuuid}}">
+ {{/links}}
<g transform="translate({{gridCol}} {{gridRow}})">
<rect transform="rotate({{rotation}} 1.9 1.9)"
x=".1"
@@ -55,6 +64,9 @@
class="scrn {{class}}"
/>
</g>
+ {{#links}}
+ </a>
+ {{/links}}
{{/machines}}
</g>
</svg>
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 @@
-<button class="pull-right btn btn-default" type="button" data-toggle="modal"
- data-target="#column-selector">{{lang_selectColumns}}</button>
+<div class="slx-right">
+ {{{roomsvg}}}
+ {{#sidebar}}
+ <div class="infobox">{{.}}</div>
+ {{/sidebar}}
+</div>
<h2>{{lang_clientList}} ({{rowCount}})</h2>
+<button class="btn btn-default" type="button" data-toggle="modal"
+ data-target="#column-selector">{{lang_selectColumns}}</button>
+
+<div class="clearfix"></div>
<form method="post" action="?do=statistics" id="list-form">
<input type="hidden" name="token" value="{{token}}">
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 @@
</td>
</tr>
{{/modeid}}
- {{#hasroomplan}}
+ {{#roomsvg}}
<tr>
<td class="text-nowrap">
{{lang_roomplan}}
</td>
<td>
+ <div>
+ {{{roomsvg}}}
+ </div>
<a href="?do=roomplanner&amp;locationid={{locationid}}" target="_blank"
- onclick="window.open(this.href, '_blank', 'toolbar=0,scrollbars,resizable');return false">
- <img src="api.php?do=roomplanner&amp;show=svg&amp;locationid={{locationid}}&amp;machineuuid={{machineuuid}}&amp;fallback=1"/>
+ onclick="window.open(this.href, '_blank', 'toolbar=0,scrollbars,resizable');return false">
+ {{lang_edit}}
</a>
</td>
</tr>
- {{/hasroomplan}}
+ {{/roomsvg}}
{{#rebootcontrol}}
<tr>
<td class="text-nowrap">