Files
nexus/modules/fx-rates/pages/index.php
Lars Gebhardt-Kusche 4ead35047a
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped
ysdsd
2026-04-29 02:21:22 +02:00

140 lines
5.7 KiB
PHP

<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/bootstrap.php';
$assets = app()->assets();
if ($assets) {
$assets->addStyle('/module/fx-rates/asset?file=fx-rates.css');
$assets->addScript('/module/fx-rates/asset?file=fx-rates.js', 'footer', true);
}
$settings = module_fn('fx-rates', 'settings');
$service = module_fn('fx-rates', 'service');
$latest = $service->latestStatus();
$recentFetches = $service->recentFetches(12);
$preferredCurrencies = is_array($settings['preferred_currencies'] ?? null) ? $settings['preferred_currencies'] : [];
$pageData = json_encode([
'settings' => $settings,
'latest' => $latest,
'preferred_currencies' => $preferredCurrencies,
'recent_fetches' => $recentFetches,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
?>
<?= module_shell_header('fx-rates', ['title' => 'Waehrungskurse']) ?>
<div id="fx-rates-app" data-page='<?= e(is_string($pageData) ? $pageData : '{}') ?>'>
<div class="fx-stack">
<div class="fx-card">
<div class="fx-card-head">
<div>
<h1>Waehrungskurse</h1>
<p>Zentrale Quelle fuer FX-Snapshots, Zeitabfragen und manuelle Aktualisierung.</p>
</div>
</div>
<div class="fx-meta-grid">
<div><strong>Standard-Basis:</strong> <span data-bind="default-base"><?= e((string) ($settings['default_base_currency'] ?? 'EUR')) ?></span></div>
<div><strong>Anzeige-Basis:</strong> <span data-bind="display-base"><?= e((string) ($settings['display_base_currency'] ?? 'EUR')) ?></span></div>
<div><strong>Scheduler:</strong> taeglich um <?= e(str_pad((string) ($settings['daily_refresh_hour'] ?? 18), 2, '0', STR_PAD_LEFT)) ?>:00 (<?= e((string) ($settings['schedule_timezone'] ?? 'Europe/Berlin')) ?>)</div>
<div><strong>Letzter Abruf:</strong> <span data-bind="last-fetch"><?= e((string) ($latest['fetched_at'] ?? 'noch keiner')) ?></span></div>
</div>
<div class="fx-message" data-bind="message"></div>
</div>
<div class="fx-card">
<h2>Setup</h2>
<p>Die Auswahl wird in den Modul-Settings gespeichert und steuert den Standardaufruf der letzten Kurse.</p>
<div class="fx-form-grid">
<label>
<span>Standard-Basiswaehrung</span>
<input type="text" name="default_base_currency" value="<?= e((string) ($settings['default_base_currency'] ?? 'EUR')) ?>">
</label>
<label>
<span>Anzeige-Basiswaehrung</span>
<input type="text" name="display_base_currency" value="<?= e((string) ($settings['display_base_currency'] ?? 'EUR')) ?>">
</label>
</div>
<label class="fx-block">
<span>Bevorzugte Waehrungen</span>
<input type="text" name="preferred_currencies" value="<?= e(implode(', ', $preferredCurrencies)) ?>" placeholder="EUR, USD, DOGE, BTC">
</label>
<div class="fx-actions">
<button type="button" class="fx-button" data-action="save-settings">Auswahl speichern</button>
<button type="button" class="fx-button fx-button--primary" data-action="refresh-rates">Aktuelle Kurse abrufen</button>
</div>
</div>
<div class="fx-card">
<h2>Umrechnung</h2>
<p>Umrechnung auf Basis des letzten verfuegbaren Kurses zwischen den bevorzugten Waehrungen.</p>
<div class="fx-form-grid">
<label>
<span>Quellwaehrung</span>
<select name="convert_from">
<?php foreach ($preferredCurrencies as $currency): ?>
<option value="<?= e((string) $currency) ?>"><?= e((string) $currency) ?></option>
<?php endforeach; ?>
</select>
</label>
<label>
<span>Zielwaehrung</span>
<select name="convert_to">
<?php foreach ($preferredCurrencies as $currency): ?>
<option value="<?= e((string) $currency) ?>" <?= (string) $currency === (string) ($preferredCurrencies[1] ?? $preferredCurrencies[0] ?? '') ? 'selected' : '' ?>><?= e((string) $currency) ?></option>
<?php endforeach; ?>
</select>
</label>
<label>
<span>Betrag</span>
<input type="number" name="convert_amount" min="0" step="0.00000001" value="1">
</label>
</div>
<div class="fx-convert-result" data-bind="convert-result">Noch keine Umrechnung berechnet.</div>
</div>
<div class="fx-card">
<h2>Letzter Snapshot</h2>
<div class="fx-table-wrap">
<table class="fx-table">
<thead>
<tr>
<th>Waehrung</th>
<th>Kurs</th>
</tr>
</thead>
<tbody data-bind="rates-body">
<tr><td colspan="2">Noch keine Daten geladen.</td></tr>
</tbody>
</table>
</div>
<div class="fx-history-block">
<h3>Letzte Abrufe</h3>
<div class="fx-table-wrap">
<table class="fx-table">
<thead>
<tr>
<th>Datum</th>
<th>Basis</th>
<th>Provider</th>
</tr>
</thead>
<tbody data-bind="fetches-body">
<?php if ($recentFetches === []): ?>
<tr><td colspan="3">Noch keine Abrufe vorhanden.</td></tr>
<?php else: ?>
<?php foreach ($recentFetches as $fetch): ?>
<tr>
<td><?= e((string) ($fetch['fetched_at'] ?? '')) ?></td>
<td><?= e((string) ($fetch['base_currency'] ?? '')) ?></td>
<td><?= e((string) ($fetch['provider'] ?? '')) ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?= module_shell_footer() ?>