asdasd
All checks were successful
Deploy / deploy-staging (push) Successful in 5s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-29 02:32:42 +02:00
parent 4ead35047a
commit 79872f3337
5 changed files with 159 additions and 191 deletions

View File

@@ -59,17 +59,11 @@
cursor: wait;
}
.fx-meta-grid,
.fx-form-grid {
display: grid;
gap: 0.75rem;
}
.fx-meta-grid {
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
margin-top: 0.75rem;
}
.fx-form-grid {
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
@@ -96,7 +90,7 @@
}
.fx-message {
min-height: 1.5rem;
margin-bottom: 0.9rem;
color: #1c2734;
}
@@ -137,11 +131,10 @@
color: #1c2734;
}
.fx-history-block {
margin-top: 1.25rem;
}
.fx-history-block h3 {
margin: 0 0 0.75rem;
font-size: 1rem;
.fx-card-meta {
display: grid;
gap: 0.35rem;
color: #5b6573;
font-size: 0.95rem;
text-align: right;
}

View File

@@ -7,40 +7,19 @@
const page = JSON.parse(root.dataset.page || '{}');
const settings = page.settings || {};
const nodes = {
message: root.querySelector('[data-bind="message"]'),
lastFetch: root.querySelector('[data-bind="last-fetch"]'),
defaultBase: root.querySelector('[data-bind="default-base"]'),
displayBase: root.querySelector('[data-bind="display-base"]'),
ratesBody: root.querySelector('[data-bind="rates-body"]'),
fetchesBody: root.querySelector('[data-bind="fetches-body"]'),
convertResult: root.querySelector('[data-bind="convert-result"]'),
defaultBaseInput: root.querySelector('input[name="default_base_currency"]'),
displayBaseInput: root.querySelector('input[name="display_base_currency"]'),
preferredCurrenciesInput: root.querySelector('input[name="preferred_currencies"]'),
convertFrom: root.querySelector('select[name="convert_from"]'),
convertTo: root.querySelector('select[name="convert_to"]'),
convertAmount: root.querySelector('input[name="convert_amount"]'),
};
const apiBase = '/api/fx-rates/v1';
const setMessage = (text, type = '') => {
if (!nodes.message) {
return;
}
nodes.message.textContent = text || '';
nodes.message.className = `fx-message${type ? ` is-${type}` : ''}`;
};
const setLoading = (state) => {
root.querySelectorAll('button[data-action]').forEach((button) => {
button.disabled = state;
});
};
const parsePreferredCurrencies = () => String(nodes.preferredCurrenciesInput?.value || '')
.split(/[\s,;]+/)
.map((item) => item.trim().toUpperCase())
.filter(Boolean);
const preferredCurrencies = Array.isArray(page.preferred_currencies)
? page.preferred_currencies
.map((item) => String(item || '').trim().toUpperCase())
.filter(Boolean)
: [];
const renderSnapshot = (snapshot) => {
const rates = snapshot && snapshot.rates ? snapshot.rates : null;
@@ -73,7 +52,7 @@
}
nodes.fetchesBody.innerHTML = entries.map((entry) => `
<tr>
<td>${entry?.fetched_at || ''}</td>
<td>${entry?.fetched_at_display || entry?.fetched_at || ''}</td>
<td>${entry?.base_currency || ''}</td>
<td>${entry?.provider || ''}</td>
</tr>
@@ -99,23 +78,16 @@
const loadLatest = async () => {
const base = String(
nodes.displayBaseInput?.value || settings.display_base_currency || settings.default_base_currency || 'EUR'
settings.display_base_currency || settings.default_base_currency || 'EUR'
).trim().toUpperCase();
const preferred = parsePreferredCurrencies();
const query = new URLSearchParams();
query.set('base', base);
if (preferred.length) {
query.set('symbols', preferred.join(','));
if (preferredCurrencies.length) {
query.set('symbols', preferredCurrencies.join(','));
}
const data = await request(`/latest?${query.toString()}`);
renderSnapshot(data);
if (nodes.lastFetch) {
nodes.lastFetch.textContent = data?.fetched_at || 'noch keiner';
}
if (nodes.displayBase) {
nodes.displayBase.textContent = base;
}
return data;
};
@@ -152,54 +124,6 @@
}
};
root.querySelector('[data-action="refresh-rates"]')?.addEventListener('click', async () => {
try {
setLoading(true);
setMessage('Ich rufe jetzt die aktuellen Kurse ab.');
const payload = {
force: true,
base: String(nodes.defaultBaseInput?.value || settings.default_base_currency || 'EUR').trim().toUpperCase(),
currencies: parsePreferredCurrencies(),
};
const data = await request('/refresh', { method: 'POST', body: JSON.stringify(payload) });
setMessage(`Aktuelle Kurse gespeichert. ${data?.updated_count || 0} Werte aktualisiert.`, 'success');
await loadLatest();
const recentFetches = await request('/recent-fetches?limit=12');
renderFetches(recentFetches);
await calculateConversion();
} catch (error) {
setMessage(error.message || 'Kurse konnten nicht aktualisiert werden.', 'error');
} finally {
setLoading(false);
}
});
root.querySelector('[data-action="save-settings"]')?.addEventListener('click', async () => {
try {
setLoading(true);
setMessage('Ich speichere jetzt die Waehrungs-Auswahl.');
const payload = {
default_base_currency: String(nodes.defaultBaseInput?.value || '').trim().toUpperCase(),
display_base_currency: String(nodes.displayBaseInput?.value || '').trim().toUpperCase(),
preferred_currencies: parsePreferredCurrencies(),
};
const data = await request('/settings', { method: 'PUT', body: JSON.stringify(payload) });
if (nodes.defaultBase) {
nodes.defaultBase.textContent = data?.default_base_currency || '';
}
if (nodes.displayBase) {
nodes.displayBase.textContent = data?.display_base_currency || '';
}
setMessage('Waehrungs-Auswahl gespeichert.', 'success');
await loadLatest();
await calculateConversion();
} catch (error) {
setMessage(error.message || 'Waehrungs-Auswahl konnte nicht gespeichert werden.', 'error');
} finally {
setLoading(false);
}
});
[nodes.convertFrom, nodes.convertTo, nodes.convertAmount].forEach((node) => {
node?.addEventListener('change', () => {
calculateConversion().catch(() => {});
@@ -211,8 +135,6 @@
renderFetches(page.recent_fetches || []);
loadLatest().catch((error) => {
setMessage(error.message || 'Letzter Snapshot konnte nicht geladen werden.', 'error');
});
loadLatest().catch(() => {});
calculateConversion().catch(() => {});
})();