From 4e4e4eca94be33bfc95c5c5c5aa7f708a8875808 Mon Sep 17 00:00:00 2001 From: envoyr Date: Wed, 23 Feb 2022 16:27:13 +0100 Subject: [PATCH] move html from callbacks to twig --- lib/Froxlor/UI/Callbacks/Number.php | 17 ++--- lib/Froxlor/UI/Callbacks/ProgressBar.php | 73 +++++++++++---------- lib/Froxlor/UI/Callbacks/Text.php | 7 +- lng/lng_references.php | 1 + templates/Froxlor/table/callbacks.html.twig | 19 ++++++ templates/Froxlor/table/table.html.twig | 14 +++- 6 files changed, 81 insertions(+), 50 deletions(-) create mode 100644 templates/Froxlor/table/callbacks.html.twig diff --git a/lib/Froxlor/UI/Callbacks/Number.php b/lib/Froxlor/UI/Callbacks/Number.php index 2bbcdded..0eafdf7b 100644 --- a/lib/Froxlor/UI/Callbacks/Number.php +++ b/lib/Froxlor/UI/Callbacks/Number.php @@ -1,7 +1,8 @@ = 0 ? PhpHelper::sizeReadable($data * 1024, null, 'bi') : UI::getLng('panel.unlimited'); } /** @@ -43,10 +40,6 @@ class Number */ public static function traffic(string $data): string { - if ($data < 0) { - return 'Unlimited'; - } - - return round($data / (1024 * 1024), Settings::Get('panel.decimal_places')) . ' MB'; + return $data >= 0 ? PhpHelper::sizeReadable($data * (1024 * 1024), null, 'bi') : UI::getLng('panel.unlimited'); } -} \ No newline at end of file +} diff --git a/lib/Froxlor/UI/Callbacks/ProgressBar.php b/lib/Froxlor/UI/Callbacks/ProgressBar.php index 9338753a..98e0f429 100644 --- a/lib/Froxlor/UI/Callbacks/ProgressBar.php +++ b/lib/Froxlor/UI/Callbacks/ProgressBar.php @@ -2,6 +2,9 @@ namespace Froxlor\UI\Callbacks; +use Froxlor\PhpHelper; +use Froxlor\UI\Panel\UI; + /** * This file is part of the Froxlor project. * Copyright (c) 2010 the Froxlor Team (see authors). @@ -19,14 +22,14 @@ namespace Froxlor\UI\Callbacks; */ class ProgressBar { - /** - * TODO: use twig for html templates ... - * - * @param string $data - * @param array $attributes - * @return string - */ - public static function diskspace(string $data, array $attributes): string + /** + * get progressbar data for used diskspace + * + * @param string $data + * @param array $attributes + * @return array + */ + public static function diskspace(string $data, array $attributes): array { $infotext = ''; if (isset($attributes['customerid'])) { @@ -48,39 +51,35 @@ class ProgressBar ]; } - $infotext = \Froxlor\UI\Panel\UI::getLng('panel.used') . ':
'; - $infotext .= 'web: ' . \Froxlor\PhpHelper::sizeReadable($usages['webspace'] * 1024, null, 'bi') . '
'; - $infotext .= 'mail: ' . \Froxlor\PhpHelper::sizeReadable($usages['mailspace'] * 1024, null, 'bi') . '
'; - $infotext .= 'mysql: ' . \Froxlor\PhpHelper::sizeReadable($usages['dbspace'] * 1024, null, 'bi'); - - $infotext = ' '; + $infotext = UI::getLng('panel.used') . ':
'; + $infotext .= 'web: ' . PhpHelper::sizeReadable($usages['webspace'] * 1024, null, 'bi') . '
'; + $infotext .= 'mail: ' . PhpHelper::sizeReadable($usages['mailspace'] * 1024, null, 'bi') . '
'; + $infotext .= 'mysql: ' . PhpHelper::sizeReadable($usages['dbspace'] * 1024, null, 'bi'); } - $pbdata = self::pbData('diskspace', $attributes, 1024, (int)\Froxlor\Settings::Get('system.report_webmax')); - return '
' . $infotext . $pbdata['text'] . '
'; - } + return self::pbData('diskspace', $attributes, 1024, (int)\Froxlor\Settings::Get('system.report_webmax'), $infotext); + } - /** - * TODO: use twig for html templates ... - * - * @param string $data - * @param array $attributes - * @return string - */ - public static function traffic(string $data, array $attributes): string + /** + * get progressbar data for traffic + * + * @param string $data + * @param array $attributes + * @return array + */ + public static function traffic(string $data, array $attributes): array { - $pbdata = self::pbData('traffic', $attributes, 1024 * 1024, (int)\Froxlor\Settings::Get('system.report_trafficmax')); - return '
' . $pbdata['text'] . '
'; - } + return self::pbData('traffic', $attributes, 1024 * 1024, (int)\Froxlor\Settings::Get('system.report_trafficmax')); + } /** * do needed calculations */ - private static function pbData(string $field, array $attributes, int $size_factor = 1024, int $report_max = 90): array + private static function pbData(string $field, array $attributes, int $size_factor = 1024, int $report_max = 90, $infotext = null): array { $percent = 0; $style = 'bg-info'; - $text = \Froxlor\PhpHelper::sizeReadable($attributes[$field . '_used'] * $size_factor, null, 'bi') . ' / ' . \Froxlor\UI\Panel\UI::getLng('customer.unlimited'); + $text = PhpHelper::sizeReadable($attributes[$field . '_used'] * $size_factor, null, 'bi') . ' / ' . UI::getLng('customer.unlimited'); if ((int) $attributes[$field] >= 0) { if (($attributes[$field] / 100) * $report_max < $attributes[$field . '_used']) { $style = 'bg-danger'; @@ -91,13 +90,17 @@ class ProgressBar if ($percent > 100) { $percent = 100; } - $text = \Froxlor\PhpHelper::sizeReadable($attributes[$field . '_used'] * $size_factor, null, 'bi') . ' / ' . \Froxlor\PhpHelper::sizeReadable($attributes[$field] * $size_factor, null, 'bi'); + $text = PhpHelper::sizeReadable($attributes[$field . '_used'] * $size_factor, null, 'bi') . ' / ' . PhpHelper::sizeReadable($attributes[$field] * $size_factor, null, 'bi'); } return [ - 'percent' => $percent, - 'style' => $style, - 'text' => $text - ]; + 'type' => 'progressbar', + 'data' => [ + 'percent' => $percent, + 'style' => $style, + 'text' => $text, + 'infotext' => $infotext + ] + ]; } } diff --git a/lib/Froxlor/UI/Callbacks/Text.php b/lib/Froxlor/UI/Callbacks/Text.php index b33fdb18..0f6310f0 100644 --- a/lib/Froxlor/UI/Callbacks/Text.php +++ b/lib/Froxlor/UI/Callbacks/Text.php @@ -18,8 +18,11 @@ namespace Froxlor\UI\Callbacks; */ class Text { - public static function boolean(string $data): string + public static function boolean(string $data): array { - return $data ? '' : ''; + return [ + 'type' => 'boolean', + 'data' => (bool) $data + ]; } } \ No newline at end of file diff --git a/lng/lng_references.php b/lng/lng_references.php index 2fdbe385..0683d3aa 100644 --- a/lng/lng_references.php +++ b/lng/lng_references.php @@ -40,3 +40,4 @@ $lng['menue']['logger']['logger'] = $lng['admin']['loggersystem']; $lng['serversettings']['default_sslvhostconf']['description'] = $lng['serversettings']['default_vhostconf']['description']; $lng['admin']['include_ownvhostsettings'] = $lng['serversettings']['includedefault_sslvhostconf']; +$lng['panel']['unlimited'] = $lng['customer']['unlimited']; diff --git a/templates/Froxlor/table/callbacks.html.twig b/templates/Froxlor/table/callbacks.html.twig new file mode 100644 index 00000000..1ffbe3c8 --- /dev/null +++ b/templates/Froxlor/table/callbacks.html.twig @@ -0,0 +1,19 @@ +{% macro progressbar(data) %} +
+
+
+
+ {% if data.infotext is not empty %} + + {% endif %} + {{ data.text }} +
+{% endmacro %} + +{% macro boolean(data) %} + {% if (data) %} + + {% else %} + + {% endif %} +{% endmacro %} \ No newline at end of file diff --git a/templates/Froxlor/table/table.html.twig b/templates/Froxlor/table/table.html.twig index edf2ebce..bdf0776b 100644 --- a/templates/Froxlor/table/table.html.twig +++ b/templates/Froxlor/table/table.html.twig @@ -1,5 +1,7 @@ {% macro table(listing) %} + {% import "Froxlor/table/callbacks.html.twig" as callbacks %} +
{% if listing.title is not empty %}