// Generated, do not edit. sha256:ae09cffb6bcb813ac103c0c39e8227c38347409ffb83175ba705ade666f63970 import { listMetalAssets, listMetalProducts, createMetalProduct, updateMetalProduct, deleteMetalProduct } from '../data/metals.js'; import { tableViewCfg } from '../data/preferences.js'; import { t, localeTag } from '../i18n/index.js'; import * as dialog from '../ui/dialog.js'; import { ENUMS, CONFIG } from '../../shared/config.js'; import { renderTable } from '../ui/table.js'; import { toBaseByFactor, fromBaseByFactor } from '../ui/format.js'; import { assetLabelHtml } from '../ui/asset-label.js'; import { esc } from '../ui/escape.js'; let tableApi = null; export async function mount(host) { await buildTable(host); } async function assetOpts() { return (await listMetalAssets()).map(a => ({ value: a.id, label: `${a.symbol}: ${a.name}` })); } function formOpts() { return ENUMS.METAL_FORM.map(v => ({ value: v, label: t('enums.metal_form.' + v) })); } const DEC = CONFIG.METALS.DISPLAY_DECIMALS; const fmtG = grams => grams.toLocaleString(localeTag(), { maximumFractionDigits: DEC }); async function buildTable(el) { const metalAssets = await listMetalAssets(); const columns = [ { key: 'assetId', label: t('metalProducts.asset'), sortable: true, sortValue: r => r.asset_symbol, render: r => assetLabelHtml({ asset_name: r.asset_name, asset_symbol: r.asset_symbol }), group: { value: r => r.asset_symbol, label: v => v }, edit: { type: 'select', options: assetOpts } }, { key: 'name', label: t('metalProducts.name'), sortable: true, text: true, edit: { type: 'text', placeholder: 'Krugerrand 1 oz' } }, { key: 'form', label: t('metalProducts.form'), sortable: true, render: r => t('enums.metal_form.' + r.form), group: { value: r => r.form, label: v => t('enums.metal_form.' + v) }, edit: { type: 'select', options: formOpts } }, { key: 'fineGrams', label: t('metalProducts.fineWeight'), align: 'num', sortable: true, sortValue: r => r.fineGrams, render: r => `${fmtG(fromBaseByFactor(r.fineGrams, 'g'))} g ยท ${fmtG(fromBaseByFactor(r.fineGrams, 'ozt'))} ozt`, edit: { render: vals => { const grams = Number.isFinite(Number(vals.fineGrams)) && vals.fineGrams !== '' && vals.fineGrams != null ? fromBaseByFactor(vals.fineGrams, 'g') : ''; const opt = u => ``; return `