OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

_content.php

6 KB
<?php
use OpenNIT\Status\StatusManager;

/** @var array $overall @var array $services @var array $active_incidents @var array $maintenances */
$services        = $services ?? [];
$activeIncidents = $active_incidents ?? [];
$maintenances    = $maintenances ?? [];
$overall         = $overall ?? ['key' => 'operational', 'label' => 'Alle Systeme betriebsbereit', 'all_ok' => true];
$brand           = $brand ?? [];
$uptime          = $uptime ?? [];
$showUptime      = !empty($brand['show_uptime']);
$e               = fn($v) => htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
$dt              = fn($v) => $v ? date('d.m.Y H:i', strtotime((string)$v)) : '';
$d               = fn($v) => $v ? date('d.m.Y', strtotime((string)$v)) : '';

// Dienste nach Gruppe bündeln (Reihenfolge: ungruppiert zuerst, dann alphabetisch)
$grouped = [];
foreach ($services as $s) {
    $grouped[trim((string)($s['group_name'] ?? ''))][] = $s;
}
// 90-Tage-Achse (alt → neu)
$days = [];
if ($showUptime) {
    for ($i = 89; $i >= 0; $i--) { $days[] = date('Y-m-d', strtotime("-$i day")); }
}
?>

<!-- Gesamtstatus -->
<div class="sp-banner sp-banner--<?= $e($overall['key']) ?>">
    <span class="sp-banner-icon" aria-hidden="true"><?= $overall['all_ok'] ? '&#10003;' : '&#9888;' ?></span>
    <span><?= $e($overall['label']) ?></span>
</div>

<!-- Geplante Wartungen -->
<?php if (!empty($maintenances)): ?>
<div class="sp-section">
    <h2 class="sp-section-title"><?= $this->te('Geplante Wartungen') ?></h2>
    <?php foreach ($maintenances as $m): ?>
    <div class="sp-maint">
        <p class="sp-maint-title"><?= $e($m['title']) ?> <span class="sp-tag"><?= $e(StatusManager::MAINTENANCE_STATUS[$m['status']] ?? $m['status']) ?></span></p>
        <div class="sp-maint-time">
            <?php if (!empty($m['all_day'])): ?>
                <?= $d($m['scheduled_start']) ?><?= !empty($m['scheduled_end']) ? ' &ndash; ' . $d($m['scheduled_end']) : '' ?>
            <?php else: ?>
                <?= $this->te('{zeitpunkt} Uhr', ['zeitpunkt' => $dt($m['scheduled_start']) . (!empty($m['scheduled_end']) ? ' – ' . $dt($m['scheduled_end']) : '')]) ?>
            <?php endif; ?>
        </div>
        <?php if (!empty($m['body'])): ?><p class="sp-maint-body"><?= $e($m['body']) ?></p><?php endif; ?>
        <?php if (!empty($m['services'])): ?>
            <div class="sp-affected"><?= $this->t('Betroffen') ?>: <?= $e(implode(', ', array_column($m['services'], 'name'))) ?></div>
        <?php endif; ?>
    </div>
    <?php endforeach; ?>
</div>
<?php endif; ?>

<!-- Aktive Störungen -->
<?php if (!empty($activeIncidents)): ?>
<div class="sp-section">
    <h2 class="sp-section-title"><?= $this->te('Aktuelle Störungen') ?></h2>
    <?php foreach ($activeIncidents as $inc): ?>
    <div class="sp-incident sp-incident--<?= $e($inc['impact']) ?>">
        <div class="sp-incident-head">
            <h3 class="sp-incident-title"><?= $e($inc['title']) ?></h3>
            <span class="sp-tag sp-tag--<?= $e($inc['impact']) ?>"><?= $e(StatusManager::INCIDENT_IMPACT[$inc['impact']] ?? $inc['impact']) ?></span>
        </div>
        <div class="sp-incident-meta">
            <?= $this->t('Seit') ?> <?= $this->te('{zeitpunkt} Uhr', ['zeitpunkt' => $dt($inc['started_at'])]) ?> · Status: <?= $e(StatusManager::INCIDENT_STATUS[$inc['status']] ?? $inc['status']) ?>
        </div>
        <?php if (!empty($inc['services'])): ?>
            <div class="sp-affected"><?= $this->t('Betroffen') ?>: <?= $e(implode(', ', array_column($inc['services'], 'name'))) ?></div>
        <?php endif; ?>
        <?php if (!empty($inc['updates'])): ?>
        <ul class="sp-timeline">
            <?php foreach ($inc['updates'] as $u): ?>
            <li class="sp-update">
                <span class="sp-update-status"><?= $e(StatusManager::INCIDENT_STATUS[$u['status']] ?? $u['status']) ?></span>
                <span class="sp-update-time"><?= $this->te('{zeitpunkt} Uhr', ['zeitpunkt' => $dt($u['created_at'])]) ?></span>
                <p class="sp-update-body"><?= $e($u['body']) ?></p>
            </li>
            <?php endforeach; ?>
        </ul>
        <?php endif; ?>
    </div>
    <?php endforeach; ?>
</div>
<?php endif; ?>

<!-- Dienste -->
<div class="sp-section">
    <h2 class="sp-section-title"><?= $this->te('Dienste') ?></h2>
    <?php if (empty($services)): ?>
        <div class="sp-card"><div class="sp-empty"><?= $this->te('Es wurden noch keine Dienste angelegt.') ?></div></div>
    <?php else: foreach ($grouped as $gname => $list): ?>
        <?php if ($gname !== ''): ?><h3 class="sp-group-title"><?= $e($gname) ?></h3><?php endif; ?>
        <div class="sp-card">
            <?php foreach ($list as $s): ?>
            <div class="sp-service">
                <div class="sp-service-row">
                    <div>
                        <div class="sp-service-name"><?= $e($s['name']) ?></div>
                        <?php if (!empty($s['description'])): ?><div class="sp-service-desc"><?= $e($s['description']) ?></div><?php endif; ?>
                    </div>
                    <span class="sp-pill sp-pill--<?= $e($s['status']) ?>"><?= $e(StatusManager::SERVICE_STATUS[$s['status']] ?? $s['status']) ?></span>
                </div>
                <?php if ($showUptime): ?>
                <div class="sp-uptime" role="img" aria-label="<?= $this->te('Verfügbarkeit der letzten 90 Tage') ?>">
                    <?php foreach ($days as $day): $st = $uptime[(int)$s['id']][$day] ?? 'nodata'; ?>
                        <span class="sp-uptime-day sp-uptime-day--<?= $e($st) ?>" title="<?= date('d.m.Y', strtotime($day)) ?>: <?= $st === 'nodata' ? 'keine Daten' : $e(StatusManager::SERVICE_STATUS[$st] ?? $st) ?>"></span>
                    <?php endforeach; ?>
                </div>
                <div class="sp-uptime-legend"><span><?= $this->te('vor 90 Tagen') ?></span><span><?= $this->te('heute') ?></span></div>
                <?php endif; ?>
            </div>
            <?php endforeach; ?>
        </div>
    <?php endforeach; endif; ?>
</div>