UNPKG

@opengis/bi

Version:

BI data visualization module

46 lines (38 loc) 1.78 kB
import { handlebarsSync, handlebars } from '@opengis/fastify-table/utils.js' function format(d, key, data) { if (!key?.includes) return ''; if (d === true) return 'так'; if (d === false) return 'ні' if (key.includes('{{')) { return handlebarsSync.compile(key)(data); } if (!d) return '-'; return d; } export default async function descriptionList(data, opt) { const { hash } = opt; // no data if (hash.nodata && !data) { const noDataText = typeof hash.nodata == 'string' ? hash.nodata : 'no data'; return noDataText } if (!data) return 'empty data' if (!hash.columns.split) return 'columns empty' + JSON.stringify(hash.columns) const keys = hash.columns.split(hash.divider || '|').map(el => hash.comma ? el.trim().replace(new RegExp(hash.comma || '#', 'g'), ',') : el.trim()); const result = []; for (let i = 0; i < keys.length; i += 2) { const name = keys[i]; const nameHBS = name.includes('{{') ? handlebarsSync.compile(name)({ ...data, hash }) : false if (!nameHBS && name.includes('{{')) continue; const key = keys[i + 1]; const d1 = ['{{format', '{{select', '{{badge', '{{ifCond'].filter(el => key?.includes?.(el)).length ? await handlebars.compile(key)(data) || '-' : null if (d1 || data[key]) { result.push(`<div class="flex py-[16px] text-[14px] border-b border-[#E5E7EB"> <div class="text-[#6B7280] dark:text-white font-[600] w-[50%]">${nameHBS || name}</div> <div class="font-[400] text-black dark:text-[#bdbdbd] w-[50%]">${d1 || format(data[key], key, data)}</div> </div> `); } } return '<div class="w-full">' + result.join('') + '</div>'; }