Fixes und Währungsumstellung
This commit is contained in:
@@ -48,24 +48,32 @@
|
||||
{{ replace $fromI "v" $intermediateName 1 }}</b>
|
||||
</p>
|
||||
{{ end }}
|
||||
{{ else if eq .Params.engine "runtime" }}
|
||||
{{ else if eq .Params.engine "temperatures" }}
|
||||
<p class="mb-4 mt-8">
|
||||
Die Umrechnung von {{ $fromName }} in {{ $toName }}
|
||||
erfolgt mittels dieser Formel:
|
||||
</p>
|
||||
<div x-show="currentRate > 0">
|
||||
<p class="text-lg text-primary dark:text-primary-light">
|
||||
<b>{{ .Params.displayFormula }}</b>
|
||||
</p>
|
||||
{{ else if eq .Params.engine "currencies" }}
|
||||
<p class="mb-4 mt-8">
|
||||
Die Umrechnung von {{ $fromName }} in {{ $toName }}
|
||||
erfolgt mittels dieser Formel:
|
||||
</p>
|
||||
<div x-show="rate > 0">
|
||||
<p class="text-lg text-primary dark:text-primary-light"
|
||||
x-show="currentRate >= 1">
|
||||
x-show="rate >= 1">
|
||||
<b x-text="'{{ $toName }} = {{ $fromName }} × '
|
||||
+ prettyNumber(currentRate)"></b>
|
||||
+ prettyNumber(rate)"></b>
|
||||
</p>
|
||||
<p class="text-lg text-primary dark:text-primary-light"
|
||||
x-show="currentRate < 1">
|
||||
x-show="rate < 1">
|
||||
<b x-text="'{{ $toName }} = {{ $fromName }} / '
|
||||
+ prettyNumber(1 / currentRate)"></b>
|
||||
+ prettyNumber(1 / rate)"></b>
|
||||
</p>
|
||||
</div>
|
||||
<div x-show="!currentRate">
|
||||
<div x-show="!rate">
|
||||
{{ $rate := float .Params.rate }}
|
||||
{{ if ge $rate 1 }}
|
||||
<p class="text-lg text-primary dark:text-primary-light">
|
||||
|
||||
40
hugo/layouts/partials/conversion/currencies-data.html
Normal file
40
hugo/layouts/partials/conversion/currencies-data.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<div x-data="{
|
||||
inputValue: '1',
|
||||
rate: 0,
|
||||
formula: '',
|
||||
ratesError: '',
|
||||
ratesUpdated: '',
|
||||
convert(v) { return v.times(this.rate); },
|
||||
async init() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const valueParam = params.get('v');
|
||||
if (valueParam) this.inputValue = valueParam.replace(/,/g, '.');
|
||||
|
||||
const pbUrl = document.querySelector('meta[name=\'pocketbase-url\']')?.content || 'https://www.alphabreed.com';
|
||||
try {
|
||||
const response = await fetch(pbUrl + '/api/collections/currencies/records');
|
||||
if (!response.ok) {
|
||||
this.ratesError = 'Wechselkurse konnten nicht geladen werden.';
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
const rates = {};
|
||||
let updated = '';
|
||||
for (const item of data.items || []) {
|
||||
rates[item.id] = item.rate;
|
||||
updated = item.updated;
|
||||
}
|
||||
const fromRate = '{{ .Params.from }}' === 'eur' ? 1 : rates['{{ .Params.from }}'];
|
||||
const toRate = '{{ .Params.to }}' === 'eur' ? 1 : rates['{{ .Params.to }}'];
|
||||
if (fromRate && toRate) {
|
||||
this.rate = parseFloat(toRate) / parseFloat(fromRate);
|
||||
this.ratesUpdated = new Date(updated).toLocaleString('de-DE', { day: '2-digit', month: 'long', year: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||
this.formula = '1 {{ .Params.from | upper }} = ' + prettyNumber(this.rate) + ' {{ .Params.to | upper }}';
|
||||
} else {
|
||||
this.ratesError = 'Wechselkurse nicht gefunden.';
|
||||
}
|
||||
} catch (e) {
|
||||
this.ratesError = 'Wechselkurse konnten nicht geladen werden.';
|
||||
}
|
||||
}
|
||||
}">
|
||||
9
hugo/layouts/partials/conversion/linear-data.html
Normal file
9
hugo/layouts/partials/conversion/linear-data.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<div x-data="{
|
||||
inputValue: '1',
|
||||
convert: v => new Decimal(v).times({{ .Params.from_factor }}).dividedBy({{ .Params.to_factor }}),
|
||||
async init() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const valueParam = params.get('v');
|
||||
if (valueParam) this.inputValue = valueParam.replace(/,/g, '.');
|
||||
}
|
||||
}" x-init="init()">
|
||||
9
hugo/layouts/partials/conversion/temperatures-data.html
Normal file
9
hugo/layouts/partials/conversion/temperatures-data.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<div x-data="{
|
||||
inputValue: '1',
|
||||
convert: {{ .Params.convertFormula | safeJS }},
|
||||
async init() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const valueParam = params.get('v');
|
||||
if (valueParam) this.inputValue = valueParam.replace(/,/g, '.');
|
||||
}
|
||||
}" x-init="init()">
|
||||
Reference in New Issue
Block a user