From bc1892d4ec05277a199537bb96fda0200cc3ef7d Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Fri, 19 Jan 2024 09:21:38 +0100 Subject: [PATCH] fix incorrect top-5 customers in traffic overview for admins; show manual update command if webupdate is disabled Signed-off-by: Michael Kaufmann --- lib/Froxlor/Traffic/Traffic.php | 8 ++++++++ templates/Froxlor/misc/version_popover.html.twig | 3 +++ templates/Froxlor/user/traffic.html.twig | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Froxlor/Traffic/Traffic.php b/lib/Froxlor/Traffic/Traffic.php index 5eab6af39f..b432d418d5 100644 --- a/lib/Froxlor/Traffic/Traffic.php +++ b/lib/Froxlor/Traffic/Traffic.php @@ -140,6 +140,14 @@ public static function getCustomerStats(array $userinfo, string $range = null, b $years_avail = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC); } + // sort users by total traffic + usort($users, function ($user_a, $user_b) { + if ($user_a['total'] == $user_b['total']) { + return 0; + } + return ($user_a['total'] < $user_b['total']) ? 1 : -1; + }); + return [ 'metrics' => $metrics, 'users' => $users, diff --git a/templates/Froxlor/misc/version_popover.html.twig b/templates/Froxlor/misc/version_popover.html.twig index 02916f4548..554bc0ebfd 100644 --- a/templates/Froxlor/misc/version_popover.html.twig +++ b/templates/Froxlor/misc/version_popover.html.twig @@ -21,6 +21,9 @@

{{ message }}

{% if get_config('enable_webupdate') %} Open updater + {% else %} +

Run the following command in your shell to update:

+ {{ call_static('\\Froxlor\\Froxlor', 'getInstallDir') }}bin/froxlor-cli froxlor:update {% endif %} {% endif %} {% endmacro %} diff --git a/templates/Froxlor/user/traffic.html.twig b/templates/Froxlor/user/traffic.html.twig index 2cff65bde0..bd96a8b7ed 100644 --- a/templates/Froxlor/user/traffic.html.twig +++ b/templates/Froxlor/user/traffic.html.twig @@ -152,7 +152,7 @@ {% if userinfo.adminsession == 1 %} const labelsC = []; const dataValues = []; - {% for user in users|sort((a, b) => a.total <=> b.total)|slice(0, 5) %} + {% for user in users|slice(0, 5) %} labelsC.push('{{ user.loginname }}'); dataValues.push({value: '{{ user.total|default(0) }}', formatted: '{{ user.total|formatBytes }}'}); {% endfor %}