diff options
author | Simon Rettberg | 2022-07-06 15:56:29 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-07-06 15:56:29 +0200 |
commit | ae128c579ba1b06ee740ea5f07919cf4f33f340f (patch) | |
tree | ebdad61ec014babaffedf9bcc541b7fc179c33c6 /modules-available/statistics | |
parent | [dnbd3/vmstore] Add selection for DNBD3 server, or NFS mode, show any errors (diff) | |
download | slx-admin-ae128c579ba1b06ee740ea5f07919cf4f33f340f.tar.gz slx-admin-ae128c579ba1b06ee740ea5f07919cf4f33f340f.tar.xz slx-admin-ae128c579ba1b06ee740ea5f07919cf4f33f340f.zip |
[statistics] Fix Chart.js for HDD view
Diffstat (limited to 'modules-available/statistics')
-rw-r--r-- | modules-available/statistics/clientscript.js | 70 | ||||
-rw-r--r-- | modules-available/statistics/page.inc.php | 21 | ||||
-rw-r--r-- | modules-available/statistics/pages/machine.inc.php | 8 | ||||
-rw-r--r-- | modules-available/statistics/templates/clientlist.html | 8 | ||||
-rw-r--r-- | modules-available/statistics/templates/filterbox.html | 68 | ||||
-rw-r--r-- | modules-available/statistics/templates/machine-hdds.html | 31 |
6 files changed, 110 insertions, 96 deletions
diff --git a/modules-available/statistics/clientscript.js b/modules-available/statistics/clientscript.js new file mode 100644 index 00000000..90be29e9 --- /dev/null +++ b/modules-available/statistics/clientscript.js @@ -0,0 +1,70 @@ +'use strict'; + +// All the pie chars +function makePieChart($parent) { + var data = $parent.data('chart'); + var chartData = { + datasets: [{ + data: data.map(function(x) { return x.value; }), + backgroundColor: data.map(function(x) { return x.color; }) + }] + }; + var $canv = $('<canvas style="width:100%;height:250px">'); + $parent.append($canv); + (function() { + var $dest = $parent.data('chart-dest'); + var cur = null; + new Chart($canv[0].getContext('2d'), { + type: 'pie', data: chartData, options: { + animation: false, + onHover: function (_, list) { + if (list.length === 0 || list[0].index !== cur) { + if (cur !== null) { + $($dest + cur).removeClass('slx-bold'); + cur = null; + } + } + if (list.length !== 0 && list[0].index !== cur) { + cur = list[0].index; + $($dest + cur).addClass('slx-bold'); + } + }, + plugins: { + tooltip: {enabled: false}, + legend: {display: false} + } + } + }); + })(); +} + +function popupFilter(field) { + var $row = addFilter(field, null, null); + if ($row !== null) { + $row.find('.arg').focus(); + $row.removeClass('slx-focus') + setTimeout(function() { $row.addClass('slx-focus'); }, 10); + } +} + +function addFilter(field, op, argument) { + if (field === null) + return null; + var $row = $('#filter-' + field); + if ($row.length === 0) + return null; + if (argument !== null) { + $row.find('.op').val(op); + $row.find('.arg').val(argument); + } + // Enable checkbox only if we got a predefined value, or if argument is in a select, as the user might want the preselected item and doesn't notice the checkbox is unchecked + if (argument !== null || $row.find('select.arg').length !== 0) { + $row.find('.filter-enable').prop('checked', true); + } + $row.show(); + return $row; +} + +function refresh() { + $('#query-form').submit(); +}
\ No newline at end of file diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 04d9a515..71c9dea3 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -91,6 +91,8 @@ class Page_Statistics extends Page $this->rebootControl(false); } elseif ($action === 'wol') { $this->wol(); + } elseif ($action === 'benchmark') { + $this->vmstoreBenchmark(); } elseif ($action === 'prepare-exec') { if (Module::isAvailable('rebootcontrol')) { RebootControl::prepareExec(); @@ -169,6 +171,25 @@ class Page_Statistics extends Page } } + /** + * @param bool $reboot true = reboot, false = shutdown + */ + private function vmstoreBenchmark() + { + if (!Module::isAvailable('vmstore')) + return; + $ids = Request::post('uuid', [], 'array'); + $ids = array_values($ids); + if (empty($ids)) { + Message::addError('main.parameter-empty', 'uuid'); + return; + } + $this->getAllowedMachines(".vmstore.benchmark", $ids, $allowedMachines); + if (empty($allowedMachines)) + return; + VmStoreBenchmark::prepareSelectDialog($allowedMachines); + } + private function getAllowedMachines($permission, $ids, &$allowedMachines) { $allowedLocations = User::getAllowedLocations($permission); diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index 5bf5ec97..df6a561e 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -548,6 +548,8 @@ class SubPage private static function mangleHdd(array &$hdd) { + static $hddidx = 0; + $hdd['hddidx'] = $hddidx++; $hours = $hdd['power_on_time//hours'] ?? $hdd['attr_9']['raw'] ?? $hdd['power_on_hours'] ?? $hdd['power_on_time']['hours'] ?? null; if ($hours !== null) { @@ -575,14 +577,16 @@ class SubPage $json = []; $lastEnd = 0; $minDisplaySize = $hdd['size'] / 150; + $i = 0; foreach ($hdd['partitions'] as &$part) { $dist = $part['start'] - $lastEnd; if ($dist > $minDisplaySize) { - error_log('Dist: ' . Util::readableFileSize($dist)); $json[] = ['value' => $dist, 'color' => '#aaa']; + $i++; } if ($part['size'] > $minDisplaySize) { - $json[] = ['value' => $part['size'], 'color' => self::typeToColor($part), 'label' => $part['id']]; + $json[] = ['value' => $part['size'], 'color' => self::typeToColor($part)]; + $part['idx'] = $i++; } $part['size_s'] = Util::readableFileSize($part['size']); $used += $part['size']; diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html index 3df95d92..df271591 100644 --- a/modules-available/statistics/templates/clientlist.html +++ b/modules-available/statistics/templates/clientlist.html @@ -152,7 +152,7 @@ <span class="glyphicon glyphicon-refresh"></span> {{lang_reset}} </button> - <div class="btn-group"> + <div class="btn-group dropup"> <button class="btn btn-default dropdown-toggle btn-machine-action" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true"> <span class="glyphicon glyphicon-list"></span> @@ -184,7 +184,7 @@ </ul> </div> {{#rebootcontrol}} - <div class="btn-group"> + <div class="btn-group dropup"> <button class="btn btn-default dropdown-toggle btn-machine-action" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true"> <span class="glyphicon glyphicon-list"></span> @@ -222,7 +222,7 @@ {{#canBenchmark}} <button type="submit" name="action" value="benchmark" class="btn btn-primary btn-machine-action"> <span class="glyphicon glyphicon-dashboard"></span> - {{lang_remoteExec}} + {{lang_remoteSpeedcheck}} </button> {{/canBenchmark}} </div> @@ -230,7 +230,7 @@ </div> {{/rebootcontrol}} {{#canDelete}} - <div class="btn-group"> + <div class="btn-group dropup"> <button type="submit" name="action" value="delmachines" class="btn btn-danger btn-machine-action" data-confirm="{{lang_sureDeletePermanent}}"> <span class="glyphicon glyphicon-trash"></span> diff --git a/modules-available/statistics/templates/filterbox.html b/modules-available/statistics/templates/filterbox.html index aba4b41c..f62c4d7c 100644 --- a/modules-available/statistics/templates/filterbox.html +++ b/modules-available/statistics/templates/filterbox.html @@ -117,80 +117,12 @@ document.addEventListener("DOMContentLoaded", function () { }); }); - // All the pie chars - function makePieChart($parent) { - var data = $parent.data('chart'); - var chartData = { - datasets: [{ - data: data.map(function(x) { return x.value; }), - backgroundColor: data.map(function(x) { return x.color; }) - }] - }; - var $canv = $('<canvas style="width:100%;height:250px">'); - $parent.append($canv); - (function() { - var $dest = $parent.data('chart-dest'); - var cur = null; - new Chart($canv[0].getContext('2d'), { - type: 'pie', data: chartData, options: { - animation: false, - onHover: function (_, list) { - if (list.length === 0 || list[0].index !== cur) { - if (cur !== null) { - $($dest + cur).removeClass('slx-bold'); - cur = null; - } - } - if (list.length !== 0 && list[0].index !== cur) { - console.log(list[0]); - cur = list[0].index; - $($dest + cur).addClass('slx-bold'); - } - }, - plugins: { - tooltip: {enabled: false}, - legend: {display: false} - } - } - }); - })(); - } $('.auto-chart').each(function() { makePieChart($(this)); }); }, false); -function popupFilter(field) { - var $row = addFilter(field, null, null); - if ($row !== null) { - $row.find('.arg').focus(); - $row.removeClass('slx-focus') - setTimeout(function() { $row.addClass('slx-focus'); }, 10); - } -} - -function addFilter(field, op, argument) { - if (field === null) - return null; - var $row = $('#filter-' + field); - if ($row.length === 0) - return null; - if (argument !== null) { - $row.find('.op').val(op); - $row.find('.arg').val(argument); - } - // Enable checkbox only if we got a predefined value, or if argument is in a select, as the user might want the preselected item and doesn't notice the checkbox is unchecked - if (argument !== null || $row.find('select.arg').length !== 0) { - $row.find('.filter-enable').prop('checked', true); - } - $row.show(); - return $row; -} - -function refresh() { - $('#query-form').submit(); -} // --></script> diff --git a/modules-available/statistics/templates/machine-hdds.html b/modules-available/statistics/templates/machine-hdds.html index 84feccfd..49b49277 100644 --- a/modules-available/statistics/templates/machine-hdds.html +++ b/modules-available/statistics/templates/machine-hdds.html @@ -34,7 +34,7 @@ <th>{{lang_partType}}</th> </tr> {{#partitions}} - <tr id="{{id}}"> + <tr id="part-{{hddidx}}-{{idx}}"> <td>{{index}}</td> <td class="text-right text-nowrap">{{size_s}}</td> <td>{{name}}</td> @@ -46,31 +46,18 @@ <div class="slx-bold">{{lang_unused}}: {{unused_s}}</div> {{/unused_s}} </div> - <div class="col-sm-5"> - <canvas id="{{devid}}-chart" style="width:100%;height:250px"></canvas> - <script type="text/javascript"> - document.addEventListener("DOMContentLoaded", function() { - var data = {{{json}}}; - var sel = false; - new Chart(document.getElementById('{{devid}}-chart').getContext('2d')).Pie(data, { - animation: false, - tooltipTemplate: "<%if (label){%><%=label%><%}%>", - customTooltips: function(tooltip) { - if (sel !== false) sel.removeClass('info'); - if (!tooltip) { - sel = false; - return; - } - sel = $('#' + tooltip.text); - sel.addClass('info'); - } - }); - }, false); - </script> + <div class="col-sm-5 auto-chart" data-chart="{{json}}" data-chart-dest="#part-{{hddidx}}-"> </div> </div> </div> </div> </div> {{/hdds}} + <script type="text/javascript"> + document.addEventListener("DOMContentLoaded", function() { + $('.auto-chart').each(function() { + makePieChart($(this)); + }); + }); + </script> </div>
\ No newline at end of file |