@opengis/fastify-table 1.1.114 → 1.1.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.114",
3
+ "version": "1.1.115",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -3,16 +3,16 @@ import { handlebars } from '@opengis/fastify-hb/utils.js';
3
3
  import getTemplate from '../getTemplate.js';
4
4
  import getSelectVal from './getSelectVal.js';
5
5
 
6
- // import { getTemplate, getSelectVal } from '../../../../../utils.js';
7
-
8
- export default async function metaFormat({ rows, table }) {
9
- const loadTable = await getTemplate('table', table);
10
- const selectCols = loadTable?.columns?.filter((e) => e.data);
6
+ export default async function metaFormat({
7
+ rows, table, cls, sufix = true,
8
+ }) {
9
+ const loadTable = table ? await getTemplate('table', table) : {};
10
+ const selectCols = Object.keys(cls || {}).map(key => ({ name: key, data: cls[key] })).concat(loadTable?.columns?.filter((e) => e.data) || []);
11
11
  const metaCls = Object.keys(loadTable?.meta?.cls || {}).map((el) => ({ name: el, data: loadTable?.meta?.cls[el] }));
12
- const htmlCols = loadTable?.columns?.filter((e) => e.name && e.format === 'html' && e.html);
12
+ const htmlCols = loadTable?.columns?.filter?.((e) => e.name && e.format === 'html' && e.html) || [];
13
13
  if (!selectCols?.length && !metaCls?.length && !htmlCols?.length) return rows;
14
14
 
15
- await Promise.all(htmlCols?.map(async (attr) => {
15
+ await Promise.all(htmlCols.map(async (attr) => {
16
16
  await Promise.all(rows.filter(row => row?.[attr.name])?.map(async (row) => {
17
17
  const html = await handlebars.compile(attr.html)(row);
18
18
  Object.assign(row, { [attr.name]: html?.replaceAll(/<[^>]*>/g, '')?.replace(/\n/g, '')?.trim() });
@@ -24,13 +24,18 @@ export default async function metaFormat({ rows, table }) {
24
24
  const values = [...new Set(rows?.map((el) => el[attr.name]).flat())].filter((el) => (typeof el === 'boolean' ? true : el));
25
25
  if (!values.length) return null;
26
26
 
27
- const cls = await getSelectVal({ name: attr.data, values });
28
- if (!cls) return null;
27
+ const clsValues = await getSelectVal({ name: attr.data, values });
28
+ if (!clsValues) return null;
29
29
 
30
30
  rows.forEach(el => {
31
- const val = el[attr.name]?.map?.(c => cls[c.toString()] || cls[c] || c) || cls[el[attr.name]?.toString()] || cls[el[attr.name]] || el[attr.name];
31
+ const val = el[attr.name]?.map?.(c => clsValues[c.toString()] || clsValues[c] || c) || clsValues[el[attr.name]?.toString()] || clsValues[el[attr.name]] || el[attr.name];
32
32
  if (!val) return;
33
- Object.assign(el, { [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: (val.color ? val : val.text || val) });
33
+ if (!sufix) {
34
+ Object.assign(el, { [attr.name]: val.text || val });
35
+ }
36
+ else {
37
+ Object.assign(el, { [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: (val.color ? val : val.text || val) });
38
+ }
34
39
  });
35
40
 
36
41
  return null;