Runtime Engine generisch
This commit is contained in:
@@ -13,8 +13,11 @@
|
||||
"{ toIntermediate: v => %s, fromIntermediate: v => %s }"
|
||||
$toExpr $fromExpr }}
|
||||
{{ else if eq .Params.engine "runtime" }}
|
||||
{{ $config = dict "fromCurrency" .Params.from
|
||||
"toCurrency" .Params.to | jsonify }}
|
||||
{{ $fromCode := .Params.from }}
|
||||
{{ $toCode := .Params.to }}
|
||||
{{ $config = printf
|
||||
"{ init: async function () { 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(); for (const item of data.items || []) { this.rates[item.id] = item.rate; } } catch (e) { this.ratesError = 'Wechselkurse konnten nicht geladen werden.'; } }, convert: function (value) { const fromRate = '%s' === 'eur' ? 1 : this.rates['%s']; const toRate = '%s' === 'eur' ? 1 : this.rates['%s']; if (!fromRate || !toRate) { return null; } return value.times(new Decimal(toRate)).dividedBy(new Decimal(fromRate)); } }"
|
||||
$fromCode $fromCode $toCode $toCode }}
|
||||
{{ end }}
|
||||
{{ $availableUnits := partial "available-units.html"
|
||||
(dict "category" .Params.category "units" $catData.units) }}
|
||||
|
||||
Reference in New Issue
Block a user