feat: improve dashboard and connection workflows
- add connection delete endpoint and update connection list handling - expand dashboard visualization behavior - update helpers/header and project TODO tracking
This commit is contained in:
@@ -297,8 +297,83 @@ HTML, [
|
||||
* Sonstiges
|
||||
* ========================= */
|
||||
|
||||
// TODO: Weitere Helfer nach Bedarf
|
||||
// - Datum formatieren
|
||||
// - Bytes → MB
|
||||
// - UUID erzeugen
|
||||
// - SVG-Koordinaten normalisieren
|
||||
/**
|
||||
* Formatiert Datum/Uhrzeit robust oder gibt Fallback zurueck.
|
||||
*
|
||||
* @param string|null $value
|
||||
* @param string $format
|
||||
* @param string $fallback
|
||||
* @return string
|
||||
*/
|
||||
function formatDateTime(?string $value, string $format = 'd.m.Y H:i', string $fallback = '-'): string
|
||||
{
|
||||
if ($value === null || trim($value) === '') {
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
$timestamp = strtotime($value);
|
||||
if ($timestamp === false) {
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert Byte-Werte in menschenlesbare Einheit.
|
||||
*
|
||||
* @param int|float $bytes
|
||||
* @param int $precision
|
||||
* @return string
|
||||
*/
|
||||
function formatBytes($bytes, int $precision = 2): string
|
||||
{
|
||||
$value = (float)$bytes;
|
||||
if ($value <= 0) {
|
||||
return '0 B';
|
||||
}
|
||||
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$power = min((int)floor(log($value, 1024)), count($units) - 1);
|
||||
$scaled = $value / (1024 ** $power);
|
||||
|
||||
return number_format($scaled, $precision, '.', '') . ' ' . $units[$power];
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt eine UUID v4.
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
function generateUuidV4(): string
|
||||
{
|
||||
$bytes = random_bytes(16);
|
||||
$bytes[6] = chr((ord($bytes[6]) & 0x0f) | 0x40);
|
||||
$bytes[8] = chr((ord($bytes[8]) & 0x3f) | 0x80);
|
||||
$hex = bin2hex($bytes);
|
||||
|
||||
return sprintf(
|
||||
'%s-%s-%s-%s-%s',
|
||||
substr($hex, 0, 8),
|
||||
substr($hex, 8, 4),
|
||||
substr($hex, 12, 4),
|
||||
substr($hex, 16, 4),
|
||||
substr($hex, 20, 12)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Klemmt eine SVG-Koordinate auf gueltigen Bereich.
|
||||
*
|
||||
* @param float $value
|
||||
* @param float $min
|
||||
* @param float $max
|
||||
* @param int $precision
|
||||
* @return float
|
||||
*/
|
||||
function normalizeSvgCoordinate(float $value, float $min, float $max, int $precision = 2): float
|
||||
{
|
||||
$normalized = max($min, min($max, $value));
|
||||
return round($normalized, $precision);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user