move html from callbacks to twig
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Froxlor\UI\Callbacks;
|
namespace Froxlor\UI\Callbacks;
|
||||||
|
|
||||||
use Froxlor\Settings;
|
use Froxlor\PhpHelper;
|
||||||
|
use Froxlor\UI\Panel\UI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file is part of the Froxlor project.
|
* This file is part of the Froxlor project.
|
||||||
@@ -28,11 +29,7 @@ class Number
|
|||||||
*/
|
*/
|
||||||
public static function diskspace(string $data): string
|
public static function diskspace(string $data): string
|
||||||
{
|
{
|
||||||
if ($data < 0) {
|
return $data >= 0 ? PhpHelper::sizeReadable($data * 1024, null, 'bi') : UI::getLng('panel.unlimited');
|
||||||
return 'Unlimited';
|
|
||||||
}
|
|
||||||
|
|
||||||
return round($data / 1024, Settings::Get('panel.decimal_places')) . ' MB';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,10 +40,6 @@ class Number
|
|||||||
*/
|
*/
|
||||||
public static function traffic(string $data): string
|
public static function traffic(string $data): string
|
||||||
{
|
{
|
||||||
if ($data < 0) {
|
return $data >= 0 ? PhpHelper::sizeReadable($data * (1024 * 1024), null, 'bi') : UI::getLng('panel.unlimited');
|
||||||
return 'Unlimited';
|
|
||||||
}
|
|
||||||
|
|
||||||
return round($data / (1024 * 1024), Settings::Get('panel.decimal_places')) . ' MB';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Froxlor\UI\Callbacks;
|
namespace Froxlor\UI\Callbacks;
|
||||||
|
|
||||||
|
use Froxlor\PhpHelper;
|
||||||
|
use Froxlor\UI\Panel\UI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file is part of the Froxlor project.
|
* This file is part of the Froxlor project.
|
||||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||||
@@ -20,13 +23,13 @@ namespace Froxlor\UI\Callbacks;
|
|||||||
class ProgressBar
|
class ProgressBar
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* TODO: use twig for html templates ...
|
* get progressbar data for used diskspace
|
||||||
*
|
*
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @return string
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function diskspace(string $data, array $attributes): string
|
public static function diskspace(string $data, array $attributes): array
|
||||||
{
|
{
|
||||||
$infotext = '';
|
$infotext = '';
|
||||||
if (isset($attributes['customerid'])) {
|
if (isset($attributes['customerid'])) {
|
||||||
@@ -48,39 +51,35 @@ class ProgressBar
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$infotext = \Froxlor\UI\Panel\UI::getLng('panel.used') . ':<br>';
|
$infotext = UI::getLng('panel.used') . ':<br>';
|
||||||
$infotext .= 'web: ' . \Froxlor\PhpHelper::sizeReadable($usages['webspace'] * 1024, null, 'bi') . '<br>';
|
$infotext .= 'web: ' . PhpHelper::sizeReadable($usages['webspace'] * 1024, null, 'bi') . '<br>';
|
||||||
$infotext .= 'mail: ' . \Froxlor\PhpHelper::sizeReadable($usages['mailspace'] * 1024, null, 'bi') . '<br>';
|
$infotext .= 'mail: ' . PhpHelper::sizeReadable($usages['mailspace'] * 1024, null, 'bi') . '<br>';
|
||||||
$infotext .= 'mysql: ' . \Froxlor\PhpHelper::sizeReadable($usages['dbspace'] * 1024, null, 'bi');
|
$infotext .= 'mysql: ' . PhpHelper::sizeReadable($usages['dbspace'] * 1024, null, 'bi');
|
||||||
|
|
||||||
$infotext = '<i class="fa-solid fa-circle-info" title="' . $infotext . '"></i> ';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$pbdata = self::pbData('diskspace', $attributes, 1024, (int)\Froxlor\Settings::Get('system.report_webmax'));
|
return self::pbData('diskspace', $attributes, 1024, (int)\Froxlor\Settings::Get('system.report_webmax'), $infotext);
|
||||||
return '<div class="progress progress-thin"><div class="progress-bar ' . $pbdata['style'] . '" style="width: ' . $pbdata['percent'] . '%;"></div></div><div class="text-end">' . $infotext . $pbdata['text'] . '</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: use twig for html templates ...
|
* get progressbar data for traffic
|
||||||
*
|
*
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @return string
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function traffic(string $data, array $attributes): string
|
public static function traffic(string $data, array $attributes): array
|
||||||
{
|
{
|
||||||
$pbdata = self::pbData('traffic', $attributes, 1024 * 1024, (int)\Froxlor\Settings::Get('system.report_trafficmax'));
|
return self::pbData('traffic', $attributes, 1024 * 1024, (int)\Froxlor\Settings::Get('system.report_trafficmax'));
|
||||||
return '<div class="progress progress-thin"><div class="progress-bar ' . $pbdata['style'] . '" style="width: ' . $pbdata['percent'] . '%;"></div></div><div class="text-end">' . $pbdata['text'] . '</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* do needed calculations
|
* 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;
|
$percent = 0;
|
||||||
$style = 'bg-info';
|
$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 ((int) $attributes[$field] >= 0) {
|
||||||
if (($attributes[$field] / 100) * $report_max < $attributes[$field . '_used']) {
|
if (($attributes[$field] / 100) * $report_max < $attributes[$field . '_used']) {
|
||||||
$style = 'bg-danger';
|
$style = 'bg-danger';
|
||||||
@@ -91,13 +90,17 @@ class ProgressBar
|
|||||||
if ($percent > 100) {
|
if ($percent > 100) {
|
||||||
$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 [
|
return [
|
||||||
|
'type' => 'progressbar',
|
||||||
|
'data' => [
|
||||||
'percent' => $percent,
|
'percent' => $percent,
|
||||||
'style' => $style,
|
'style' => $style,
|
||||||
'text' => $text
|
'text' => $text,
|
||||||
|
'infotext' => $infotext
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ namespace Froxlor\UI\Callbacks;
|
|||||||
*/
|
*/
|
||||||
class Text
|
class Text
|
||||||
{
|
{
|
||||||
public static function boolean(string $data): string
|
public static function boolean(string $data): array
|
||||||
{
|
{
|
||||||
return $data ? '<i class="fa fa-check-circle"></i>' : '<i class="fa fa-times-circle"></i>';
|
return [
|
||||||
|
'type' => 'boolean',
|
||||||
|
'data' => (bool) $data
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,3 +40,4 @@ $lng['menue']['logger']['logger'] = $lng['admin']['loggersystem'];
|
|||||||
|
|
||||||
$lng['serversettings']['default_sslvhostconf']['description'] = $lng['serversettings']['default_vhostconf']['description'];
|
$lng['serversettings']['default_sslvhostconf']['description'] = $lng['serversettings']['default_vhostconf']['description'];
|
||||||
$lng['admin']['include_ownvhostsettings'] = $lng['serversettings']['includedefault_sslvhostconf'];
|
$lng['admin']['include_ownvhostsettings'] = $lng['serversettings']['includedefault_sslvhostconf'];
|
||||||
|
$lng['panel']['unlimited'] = $lng['customer']['unlimited'];
|
||||||
|
|||||||
19
templates/Froxlor/table/callbacks.html.twig
Normal file
19
templates/Froxlor/table/callbacks.html.twig
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{% macro progressbar(data) %}
|
||||||
|
<div class="progress progress-thin">
|
||||||
|
<div class="progress-bar {{ data.style }}" style="width: {{ data.percent }}%;"></div>
|
||||||
|
</div>
|
||||||
|
<div class="text-end">
|
||||||
|
{% if data.infotext is not empty %}
|
||||||
|
<i class="fa-solid fa-circle-info" data-toggle="tooltip" data-placement="right" title="{{ data.infotext|raw }}"></i>
|
||||||
|
{% endif %}
|
||||||
|
{{ data.text }}
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro boolean(data) %}
|
||||||
|
{% if (data) %}
|
||||||
|
<i class="fa fa-check-circle"></i>
|
||||||
|
{% else %}
|
||||||
|
<i class="fa fa-times-circle"></i>
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
{% macro table(listing) %}
|
{% macro table(listing) %}
|
||||||
|
|
||||||
|
{% import "Froxlor/table/callbacks.html.twig" as callbacks %}
|
||||||
|
|
||||||
<form action="{{ action|default("") }}" method="post" enctype="application/x-www-form-urlencoded" class="form">
|
<form action="{{ action|default("") }}" method="post" enctype="application/x-www-form-urlencoded" class="form">
|
||||||
{% if listing.title is not empty %}
|
{% if listing.title is not empty %}
|
||||||
<h3 class="page-header">
|
<h3 class="page-header">
|
||||||
@@ -24,7 +26,17 @@
|
|||||||
<tr>
|
<tr>
|
||||||
{% for value in td %}
|
{% for value in td %}
|
||||||
<td class="p-3">
|
<td class="p-3">
|
||||||
|
{% if value is iterable %}
|
||||||
|
{% if value.type == 'progressbar' %}
|
||||||
|
{{ callbacks.progressbar(value.data) }}
|
||||||
|
{% elseif value.type == 'boolean' %}
|
||||||
|
{{ callbacks.boolean(value.data) }}
|
||||||
|
{% else %}
|
||||||
|
Callback '{{ value|json_encode }}' is not implemented!
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
{{ value|raw }}
|
{{ value|raw }}
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user