@opengis/admin 0.2.103 → 0.2.105
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -10,8 +10,10 @@ function format(d, key, data, hash) {
|
|
10
10
|
if (key === 'actions') {
|
11
11
|
return `<div class="flex items-center gap-2">${(hash.form ? buttonEdit(d, 'Редагувати') : '') + buttonDel(d)}</div>`
|
12
12
|
}
|
13
|
-
if (key.
|
13
|
+
if (key.startsWith('{{') && key.match(/\{\{([^\s]+)/)?.[1] in handlebarsSync.helpers) {
|
14
14
|
return handlebarsSync.compile(key)(data);
|
15
|
+
} else if (key.startsWith('{{') && key.includes(' ') && !(key.match(/\{\{([^\s]+)/)?.[1] in handlebars.helpers)) {
|
16
|
+
return null;
|
15
17
|
}
|
16
18
|
if (!d) return '-';
|
17
19
|
return d;
|
@@ -6,6 +6,11 @@ import { getAccess, handlebars, setOpt, setToken, getTemplate, handlebarsSync, a
|
|
6
6
|
import getTableData from "./tableData.js";
|
7
7
|
import conditions from './utils/conditions.js';
|
8
8
|
|
9
|
+
const components = {
|
10
|
+
'vs-widget-file': `select 'vs-widget-file' as component, count(*) from crm.files where entity_id=$1 and file_status<>3`,
|
11
|
+
'vs-widget-comments': `select 'vs-widget-comments' as component, count(*) from crm.communications where entity_id=$1`
|
12
|
+
};
|
13
|
+
|
9
14
|
export default async function getCardData(req) {
|
10
15
|
|
11
16
|
const {
|
@@ -43,7 +48,13 @@ export default async function getCardData(req) {
|
|
43
48
|
const data = await Promise.all(filtered.map(el => pg.query(el.count).then(el => el.rows[0] || {})))
|
44
49
|
filtered.forEach((el, i) => {
|
45
50
|
Object.assign(el, data[i] || {}, data[i].count ? {} : { count: undefined })
|
46
|
-
})
|
51
|
+
});
|
52
|
+
const q = el.items.map((el) => el.component ? components[el.component] : null).filter(el => el).join(' union all ');
|
53
|
+
const counts = q && id
|
54
|
+
? await pg.query(q, [id])
|
55
|
+
.then(e => e.rows.reduce((acc, curr) => Object.assign(acc, { [curr.component]: curr.count }), {}))
|
56
|
+
: {};
|
57
|
+
el.items?.filter?.(item => item.component)?.forEach(item => Object.assign(item, { count: counts?.[item.component] }));
|
47
58
|
})
|
48
59
|
|
49
60
|
|
@@ -1,20 +1,22 @@
|
|
1
1
|
import getData from '@opengis/fastify-table/server/routes/table/controllers/data.js';
|
2
|
-
import { getOpt } from '@opengis/fastify-table/utils.js';
|
2
|
+
import { getOpt, getMeta } from '@opengis/fastify-table/utils.js';
|
3
3
|
// import getData from '../../../../../../npm/fastify-table/server/routes/table/controllers/data.js';
|
4
4
|
|
5
5
|
export default async function getTableData(req) {
|
6
6
|
const { user = {}, pg } = req
|
7
7
|
const tokenData = await getOpt(req.params.table, req.user?.uid);
|
8
8
|
if (tokenData) {
|
9
|
-
const { rows } = await req.pg.query(`select ${tokenData.columns || '*'} from ${tokenData.table} where ${tokenData.query || 'true'} limit 10`)
|
10
|
-
|
9
|
+
const { rows = [], fields = [] } = await req.pg.query(`select ${tokenData.columns || '*'} from ${tokenData.table} where ${tokenData.query || 'true'} limit 10`);
|
10
|
+
const meta = await getMeta({ pg, table: tokenData.table });
|
11
|
+
const columns = (meta?.columns || fields).map(el => ({ name: el.name, type: pg.pgType?.[el.dataTypeID], title: el.title }));
|
12
|
+
return { rows, columns };
|
11
13
|
}
|
12
14
|
|
13
15
|
// Це можна 1 раз на старті
|
14
16
|
const interfaceName = req.headers?.referer?.match(/.*\/([^?]+)/)?.[1];
|
15
17
|
const { query } = interfaceName ?
|
16
18
|
await req.pg.query(`select query from admin.routes where route_id=$1`, [interfaceName])
|
17
|
-
.then(
|
19
|
+
.then(el => el.rows?.[0] || {}) : {};
|
18
20
|
|
19
21
|
// це можна від користувача
|
20
22
|
const { rows = [] } = pg.pk?.['admin.rules'] ? await req.pg.query(`select attr,(select rule_values from admin.account_grants where account_id in (select account_id from admin.account_users where user_uid=$2) and rule_id=r.rule_id limit 1) from admin.rules r where (select route_id from admin.routes where $1 in (alias,table_name)) = any(routes)`, [req.params.table, user.uid]) : {};
|