@opengis/admin 0.3.22 → 0.3.24
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/dist/{add-page-DsqxZzEq.js → add-page-CY3jyjng.js} +29 -26
- package/dist/{admin-interface-C8SGlC1N.js → admin-interface-B09NhAi-.js} +259 -257
- package/dist/{admin-view-DtdqTUPa.js → admin-view-obFqHA0_.js} +29 -29
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +89 -89
- package/dist/{card-view-juhvChuX.js → card-view-CAnhvY0b.js} +3 -3
- package/dist/{edit-page-DB1hlRzp.js → edit-page-DOpbSZWg.js} +33 -31
- package/dist/{import-file-BSdaeh6s.js → import-file-DAyouRPm.js} +23212 -23090
- package/dist/{profile-page-B-RhB5JP.js → profile-page-Cm3oX_ZN.js} +2 -2
- package/dist/style.css +1 -1
- package/module/settings/card/admin.roles.table/access.hbs +11 -11
- package/module/settings/card/admin.roles.table/general_info.hbs +9 -9
- package/module/settings/card/admin.roles.table/index.yml +22 -22
- package/module/settings/card/admin.roles.table/users.hbs +12 -12
- package/module/settings/card/admin.routes.table/general_info.hbs +13 -13
- package/module/settings/card/admin.routes.table/index.yml +15 -15
- package/module/settings/card/admin.table_properties.table/custom_columns.hbs +22 -22
- package/module/settings/card/admin.table_properties.table/index.yml +12 -12
- package/module/settings/card/admin.table_properties.table/info.hbs +17 -17
- package/module/settings/card/admin.users.table/general_info.hbs +18 -18
- package/module/settings/card/admin.users.table/index.yml +20 -20
- package/module/settings/card/admin.users.table/last_login.hbs +17 -17
- package/module/settings/card/admin.users.table/logs.hbs +16 -16
- package/module/settings/card/admin.users.table/routes.hbs +13 -13
- package/module/settings/card/admin.users.table/user_roles.hbs +35 -35
- package/module/settings/cls/change_type.json +13 -13
- package/module/settings/cls/core.column_type.json +14 -14
- package/module/settings/form/admin.custom_column.form.json +55 -55
- package/module/settings/form/admin.routes.form.json +25 -25
- package/module/settings/form/admin.rules.form.json +30 -30
- package/module/settings/form/admin.table_properties.form.json +19 -19
- package/module/settings/form/admin.user_roles.form.json +24 -24
- package/module/settings/form/admin.users.form.json +177 -177
- package/module/settings/form/admin.users_edit.form.json +145 -145
- package/module/settings/form/context.account_grants.form.json +24 -24
- package/module/settings/form/context.account_users.form.json +12 -12
- package/module/settings/form/user.user_roles.form.json +13 -13
- package/module/settings/menu.json +72 -72
- package/module/settings/table/admin.accounts.table.json +49 -49
- package/module/settings/table/admin.custom_column.table.json +100 -100
- package/module/settings/table/admin.roles.table.json +77 -77
- package/module/settings/table/admin.routes.table.json +73 -73
- package/module/settings/table/admin.rules.table.json +77 -77
- package/module/settings/table/admin.table_properties.table.json +37 -37
- package/module/settings/table/admin.user_roles.table.json +74 -74
- package/module/settings/table/admin.users.table.json +135 -135
- package/module/settings/table/context.account_grants.table.json +88 -88
- package/module/settings/table/context.account_users.table.json +53 -53
- package/module/settings/table/log.table_changes.table.json +100 -100
- package/package.json +102 -102
- package/plugin.js +30 -30
- package/server/helpers/index.js +40 -40
- package/server/helpers/list/descriptionList.js +45 -45
- package/server/helpers/list/tableList.js +82 -82
- package/server/helpers/list/utils/buttonDel.js +12 -12
- package/server/helpers/list/utils/buttonEdit.js +14 -14
- package/server/helpers/utils/buttonAdd.js +6 -6
- package/server/helpers/utils/buttonDel.js +6 -6
- package/server/helpers/utils/buttonEdit.js +5 -5
- package/server/helpers/utils/paddingNumber.js +3 -3
- package/server/plugins/access/funcs/getAdminAccess.js +12 -12
- package/server/plugins/hook.js +276 -276
- package/server/plugins/vite.js +77 -77
- package/server/routes/access/controllers/access.interface.js +33 -33
- package/server/routes/data/controllers/cardData.js +127 -127
- package/server/routes/data/controllers/tableFilter.js +9 -9
- package/server/routes/data/controllers/tableInfo.js +112 -112
- package/server/routes/dblist/controllers/readItems.js +20 -20
- package/server/routes/dblist/controllers/setItem.js +22 -22
- package/server/routes/dblist/index.mjs +18 -18
- package/server/routes/dblist/utils/formatData.js +7 -7
- package/server/routes/menu/controllers/getMenu.js +77 -77
- package/server/routes/menu/controllers/interfaces.js +20 -20
- package/server/routes/menu/index.mjs +7 -7
- package/server/routes/print/controllers/printTemplate.add.js +37 -37
- package/server/routes/print/controllers/printTemplate.delete.js +29 -29
- package/server/routes/print/controllers/printTemplate.edit.js +42 -42
- package/server/routes/print/controllers/printTemplate.js +67 -67
- package/server/routes/print/controllers/printTemplateList.js +19 -19
- package/server/routes/print/controllers/printTemplatePreview.js +87 -87
- package/server/routes/print/index.mjs +19 -19
- package/server/routes/properties/controllers/admin.properties.get.js +31 -31
- package/server/routes/properties/controllers/table.properties.get.js +120 -120
- package/server/routes/properties/controllers/table.properties.post.js +115 -115
- package/server/routes/properties/controllers/user.properties.get.js +19 -19
- package/server/routes/properties/controllers/user.properties.post.js +10 -10
- package/server/routes/properties/index.mjs +21 -21
- package/server/routes/properties/utils/dataInsert.js +26 -26
- package/server/routes/properties/utils/getColumnMetaData.js +17 -17
- package/server/routes/properties/utils/refreshData.js +128 -128
- package/server/routes/report/utils/getFilterQuery.js +67 -67
- package/server/routes/templates/index.mjs +16 -16
- package/server/routes/user/controllers/user.cls.post.js +54 -54
- package/server/routes/util/index.mjs +5 -5
- package/server/routes/widget/controllers/widget.get.js +125 -125
- package/server/templates/form/admin.profile.form.json +31 -31
- package/server/templates/form/cp_building.form.json +32 -32
- package/server/templates/pt/card-print.pt.hbs +245 -245
- package/utils.js +26 -26
package/server/plugins/vite.js
CHANGED
@@ -1,77 +1,77 @@
|
|
1
|
-
import fs from 'fs';
|
2
|
-
import path, { dirname } from 'path';
|
3
|
-
import { fileURLToPath } from 'url';
|
4
|
-
|
5
|
-
const dir = dirname(fileURLToPath(import.meta.url));
|
6
|
-
const root = `${dir}/../..`;
|
7
|
-
import { config } from '@opengis/fastify-table/utils.js';
|
8
|
-
|
9
|
-
const isProduction = process.env.NODE_ENV === 'production' || config.production;
|
10
|
-
|
11
|
-
async function plugin(fastify) {
|
12
|
-
// vite server
|
13
|
-
if (!isProduction) {
|
14
|
-
const vite = await import('vite');
|
15
|
-
|
16
|
-
const viteServer = await vite.createServer({
|
17
|
-
server: {
|
18
|
-
middlewareMode: true,
|
19
|
-
},
|
20
|
-
});
|
21
|
-
// hot reload
|
22
|
-
viteServer.watcher.on('all', function (d, t) {
|
23
|
-
if (!t.includes('module')) return;
|
24
|
-
console.log(d, t);
|
25
|
-
viteServer.ws.send({ type: 'full-reload' });
|
26
|
-
});
|
27
|
-
|
28
|
-
// this is middleware for vite's dev servert
|
29
|
-
fastify.addHook('onRequest', async (req, reply) => {
|
30
|
-
const { user } = req.session?.passport || {};
|
31
|
-
|
32
|
-
if (!user && req.url.startsWith('/login')) {
|
33
|
-
return reply.redirect(`/login?redirect=${req.url}`);
|
34
|
-
}
|
35
|
-
|
36
|
-
const next = () => new Promise((resolve) => {
|
37
|
-
viteServer.middlewares(req.raw, reply.raw, () => resolve());
|
38
|
-
});
|
39
|
-
await next();
|
40
|
-
});
|
41
|
-
fastify.get('*', async () => { });
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
|
45
|
-
// From Build
|
46
|
-
fastify.get('*', async (req, reply) => {
|
47
|
-
const { user } = req.session?.passport || {};
|
48
|
-
|
49
|
-
if (!user && req.url.startsWith('/login')) {
|
50
|
-
return reply.redirect(`/login?redirect=${req.url}`);
|
51
|
-
}
|
52
|
-
const stream = fs.createReadStream('dist/index.html');
|
53
|
-
return reply.type('text/html').send(stream);
|
54
|
-
});
|
55
|
-
|
56
|
-
const fileSize = {}
|
57
|
-
async function staticFile(req, reply) {
|
58
|
-
const assetsDir = 'dist';
|
59
|
-
const filePath = path.join(root, assetsDir, req.url);
|
60
|
-
const ext = path.extname(filePath);
|
61
|
-
|
62
|
-
if (!fs.existsSync(filePath)) return { status: 404, message: 'not found' }
|
63
|
-
fileSize[filePath] = fileSize[filePath] || fs.statSync(filePath).size;
|
64
|
-
const mime = {
|
65
|
-
'.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg',
|
66
|
-
}[ext];
|
67
|
-
reply.headers({ 'Cache-control': 'max-age=3600, public', 'Content-length': fileSize[filePath], 'Content-Encoding': 'identity' });
|
68
|
-
|
69
|
-
const stream = fs.createReadStream(filePath);
|
70
|
-
return mime ? reply.type(mime).send(stream) : stream;
|
71
|
-
}
|
72
|
-
|
73
|
-
fastify.get('/assets/*', staticFile);
|
74
|
-
fastify.get('/public/*', staticFile);
|
75
|
-
}
|
76
|
-
|
77
|
-
export default plugin;
|
1
|
+
import fs from 'fs';
|
2
|
+
import path, { dirname } from 'path';
|
3
|
+
import { fileURLToPath } from 'url';
|
4
|
+
|
5
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
6
|
+
const root = `${dir}/../..`;
|
7
|
+
import { config } from '@opengis/fastify-table/utils.js';
|
8
|
+
|
9
|
+
const isProduction = process.env.NODE_ENV === 'production' || config.production;
|
10
|
+
|
11
|
+
async function plugin(fastify) {
|
12
|
+
// vite server
|
13
|
+
if (!isProduction) {
|
14
|
+
const vite = await import('vite');
|
15
|
+
|
16
|
+
const viteServer = await vite.createServer({
|
17
|
+
server: {
|
18
|
+
middlewareMode: true,
|
19
|
+
},
|
20
|
+
});
|
21
|
+
// hot reload
|
22
|
+
viteServer.watcher.on('all', function (d, t) {
|
23
|
+
if (!t.includes('module')) return;
|
24
|
+
console.log(d, t);
|
25
|
+
viteServer.ws.send({ type: 'full-reload' });
|
26
|
+
});
|
27
|
+
|
28
|
+
// this is middleware for vite's dev servert
|
29
|
+
fastify.addHook('onRequest', async (req, reply) => {
|
30
|
+
const { user } = req.session?.passport || {};
|
31
|
+
|
32
|
+
if (!user && req.url.startsWith('/login')) {
|
33
|
+
return reply.redirect(`/login?redirect=${req.url}`);
|
34
|
+
}
|
35
|
+
|
36
|
+
const next = () => new Promise((resolve) => {
|
37
|
+
viteServer.middlewares(req.raw, reply.raw, () => resolve());
|
38
|
+
});
|
39
|
+
await next();
|
40
|
+
});
|
41
|
+
fastify.get('*', async () => { });
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
|
45
|
+
// From Build
|
46
|
+
fastify.get('*', async (req, reply) => {
|
47
|
+
const { user } = req.session?.passport || {};
|
48
|
+
|
49
|
+
if (!user && req.url.startsWith('/login')) {
|
50
|
+
return reply.redirect(`/login?redirect=${req.url}`);
|
51
|
+
}
|
52
|
+
const stream = fs.createReadStream('dist/index.html');
|
53
|
+
return reply.type('text/html').send(stream);
|
54
|
+
});
|
55
|
+
|
56
|
+
const fileSize = {}
|
57
|
+
async function staticFile(req, reply) {
|
58
|
+
const assetsDir = 'dist';
|
59
|
+
const filePath = path.join(root, assetsDir, req.url);
|
60
|
+
const ext = path.extname(filePath);
|
61
|
+
|
62
|
+
if (!fs.existsSync(filePath)) return { status: 404, message: 'not found' }
|
63
|
+
fileSize[filePath] = fileSize[filePath] || fs.statSync(filePath).size;
|
64
|
+
const mime = {
|
65
|
+
'.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg',
|
66
|
+
}[ext];
|
67
|
+
reply.headers({ 'Cache-control': 'max-age=3600, public', 'Content-length': fileSize[filePath], 'Content-Encoding': 'identity' });
|
68
|
+
|
69
|
+
const stream = fs.createReadStream(filePath);
|
70
|
+
return mime ? reply.type(mime).send(stream) : stream;
|
71
|
+
}
|
72
|
+
|
73
|
+
fastify.get('/assets/*', staticFile);
|
74
|
+
fastify.get('/public/*', staticFile);
|
75
|
+
}
|
76
|
+
|
77
|
+
export default plugin;
|
@@ -1,34 +1,34 @@
|
|
1
|
-
import { pgClients, metaFormat } from '@opengis/fastify-table/utils.js';
|
2
|
-
import { getAdminAccess } from '../../../../utils.js';
|
3
|
-
|
4
|
-
const q = `select a.route_id as id, coalesce(b.user_uid, d.user_uid) as user_uid, coalesce(d.actions, b.actions, array['view']) as actions, b.scope, c.role_id
|
5
|
-
from admin.routes a
|
6
|
-
left join admin.role_access b on
|
7
|
-
a.route_id=b.route_id
|
8
|
-
left join admin.roles c on
|
9
|
-
b.role_id=c.role_id
|
10
|
-
and c.enabled
|
11
|
-
left join admin.user_roles d on
|
12
|
-
c.role_id=d.role_id
|
13
|
-
and ( case when
|
14
|
-
d.expiration is not null
|
15
|
-
then d.expiration > CURRENT_DATE
|
16
|
-
else 1=1
|
17
|
-
end )
|
18
|
-
where $1 in (a.route_id, a.alias, a.table_name) and coalesce(b.user_uid, d.user_uid) is not null`;
|
19
|
-
|
20
|
-
export default async function accessInterface(req) {
|
21
|
-
const { pg = pgClients.client, params = {}, user = {} } = req;
|
22
|
-
|
23
|
-
// restrict access - admin only
|
24
|
-
const check = await getAdminAccess({
|
25
|
-
id: params.name, user,
|
26
|
-
});
|
27
|
-
if (check) return check;
|
28
|
-
|
29
|
-
const { rows = [] } = await pg.query(q, [params.name]);
|
30
|
-
|
31
|
-
const cls = { user_uid: 'core.user_uid', actions: 'core.actions', role_id: 'core.roles' };
|
32
|
-
await metaFormat({ rows, cls, sufix: false });
|
33
|
-
return { rows };
|
1
|
+
import { pgClients, metaFormat } from '@opengis/fastify-table/utils.js';
|
2
|
+
import { getAdminAccess } from '../../../../utils.js';
|
3
|
+
|
4
|
+
const q = `select a.route_id as id, coalesce(b.user_uid, d.user_uid) as user_uid, coalesce(d.actions, b.actions, array['view']) as actions, b.scope, c.role_id
|
5
|
+
from admin.routes a
|
6
|
+
left join admin.role_access b on
|
7
|
+
a.route_id=b.route_id
|
8
|
+
left join admin.roles c on
|
9
|
+
b.role_id=c.role_id
|
10
|
+
and c.enabled
|
11
|
+
left join admin.user_roles d on
|
12
|
+
c.role_id=d.role_id
|
13
|
+
and ( case when
|
14
|
+
d.expiration is not null
|
15
|
+
then d.expiration > CURRENT_DATE
|
16
|
+
else 1=1
|
17
|
+
end )
|
18
|
+
where $1 in (a.route_id, a.alias, a.table_name) and coalesce(b.user_uid, d.user_uid) is not null`;
|
19
|
+
|
20
|
+
export default async function accessInterface(req) {
|
21
|
+
const { pg = pgClients.client, params = {}, user = {} } = req;
|
22
|
+
|
23
|
+
// restrict access - admin only
|
24
|
+
const check = await getAdminAccess({
|
25
|
+
id: params.name, user,
|
26
|
+
});
|
27
|
+
if (check) return check;
|
28
|
+
|
29
|
+
const { rows = [] } = await pg.query(q, [params.name]);
|
30
|
+
|
31
|
+
const cls = { user_uid: 'core.user_uid', actions: 'core.actions', role_id: 'core.roles' };
|
32
|
+
await metaFormat({ rows, cls, sufix: false });
|
33
|
+
return { rows };
|
34
34
|
}
|
@@ -1,128 +1,128 @@
|
|
1
|
-
import path from 'node:path';
|
2
|
-
|
3
|
-
import { getAccess, handlebars, setOpt, setToken, getTemplate, handlebarsSync, applyHook } from "@opengis/fastify-table/utils.js";
|
4
|
-
//import { setOpt, setToken } from "../../../../../fastify-table/utils.js";
|
5
|
-
// import yaml from 'js-yaml';
|
6
|
-
import getTableData from "./tableData.js";
|
7
|
-
import conditions from './utils/conditions.js';
|
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
|
-
|
14
|
-
export default async function getCardData(req) {
|
15
|
-
|
16
|
-
const {
|
17
|
-
pg, params = {}, session = {}, user
|
18
|
-
} = req;
|
19
|
-
const { table, id } = params;
|
20
|
-
const uid = session.passport?.user?.uid;
|
21
|
-
|
22
|
-
const res = await applyHook('cardData', { table, id, user });
|
23
|
-
if (res) return res;
|
24
|
-
|
25
|
-
|
26
|
-
const time = Date.now();
|
27
|
-
|
28
|
-
const template = await getTemplate('card', table);
|
29
|
-
const access = await getAccess({ table, user });
|
30
|
-
|
31
|
-
const tableTemplate = await getTemplate('table', table);
|
32
|
-
|
33
|
-
const index = template?.find(el => el[0] === 'index.yml')?.[1] || {};
|
34
|
-
|
35
|
-
const { message, rows = [] } = index.table && index.query ? await pg.query(`select * from ${index.table} where ${handlebarsSync.compile(index.query)({ uid, user })}`) :
|
36
|
-
await getTableData({ pg, params: { table, id }, session, user });
|
37
|
-
|
38
|
-
if (message) return { message };
|
39
|
-
|
40
|
-
// conditions
|
41
|
-
index.panels?.filter(el => el.items).forEach(el => {
|
42
|
-
el.items = el.items?.filter(el => conditions(el.conditions, rows[0]));
|
43
|
-
})
|
44
|
-
|
45
|
-
// title, count
|
46
|
-
index.panels?.filter(el => el.items).forEach(async el => {
|
47
|
-
const filtered = el.items.filter(el => el.count?.toLowerCase?.().includes('select'));
|
48
|
-
const data = await Promise.all(filtered.map(el => pg.query(el.count).then(el => el.rows[0] || {})))
|
49
|
-
filtered.forEach((el, i) => {
|
50
|
-
Object.assign(el, data[i] || {}, data[i].count ? {} : { count: undefined })
|
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] }));
|
58
|
-
})
|
59
|
-
|
60
|
-
|
61
|
-
// tokens result
|
62
|
-
const tokens = {};
|
63
|
-
if (index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
|
64
|
-
Object.keys(index.tokens || {})
|
65
|
-
.filter(key => index?.tokens[key]?.public
|
66
|
-
|| access.actions?.includes?.('edit')
|
67
|
-
|| access.actions?.includes?.('add')
|
68
|
-
|| !index?.tokens[key]?.table
|
69
|
-
)
|
70
|
-
.forEach(key => {
|
71
|
-
const item = index?.tokens[key];
|
72
|
-
Object.keys(item).filter(el => item[el]?.includes?.('{{')).forEach(el => {
|
73
|
-
item[el] = handlebarsSync.compile(item[el])({ user, uid: user?.uid, id, data: rows[0] });
|
74
|
-
});
|
75
|
-
|
76
|
-
const token = item.form && item.table ? setToken({
|
77
|
-
ids: [JSON.stringify(item)],
|
78
|
-
uid,
|
79
|
-
array: 1,
|
80
|
-
})[0] : setOpt(item, user.uid);
|
81
|
-
tokens[key] = token;
|
82
|
-
});
|
83
|
-
}
|
84
|
-
|
85
|
-
// vue result
|
86
|
-
const vue = template?.filter((el) => el[0].endsWith('.vue'))
|
87
|
-
.reduce((acc, curr) => Object.assign(acc, { [path.parse(curr[0]).name]: curr[1].match(/<template[^>]*>([\s\S]*?)<\/template>/)[1].trim() }), {});
|
88
|
-
|
89
|
-
// data result
|
90
|
-
const data = {};
|
91
|
-
const route = await pg.query(`select route_id as path, title from admin.routes where enabled and alias=$1 limit 1`, [table])
|
92
|
-
.then(el => el.rows?.[0] || {});
|
93
|
-
Object.assign(route, { tableTitle: tableTemplate?.title });
|
94
|
-
if (index?.data && index?.data?.[0]?.name) {
|
95
|
-
await Promise.all(index.data.filter((el) => el?.name && el?.sql).map(async (el) => {
|
96
|
-
const q = handlebarsSync.compile(el.sql)({ data: rows[0], user, uid: user?.uid, id });
|
97
|
-
const { rows: sqlData } = await pg.query(q);
|
98
|
-
data[el.name] = sqlData;
|
99
|
-
}));
|
100
|
-
}
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
// html result
|
105
|
-
const html = {};
|
106
|
-
if (template) {
|
107
|
-
await Promise.all(template.filter(el => el[0].includes('.hbs')).map(async (el) => {
|
108
|
-
const htmlContent = await handlebars.compile(el[1])({ ...rows[0], user, data, tokens });
|
109
|
-
const name = el[0].substring(0, el[0].lastIndexOf('.'))
|
110
|
-
html[name] = htmlContent;
|
111
|
-
}));
|
112
|
-
}
|
113
|
-
|
114
|
-
return {
|
115
|
-
time: Date.now() - time,
|
116
|
-
...index,
|
117
|
-
tokens,
|
118
|
-
vue,
|
119
|
-
data,
|
120
|
-
route,
|
121
|
-
html,
|
122
|
-
rows,
|
123
|
-
columns: tableTemplate?.columns || tableTemplate?.colModel,
|
124
|
-
table: undefined,
|
125
|
-
query: undefined,
|
126
|
-
};
|
127
|
-
|
1
|
+
import path from 'node:path';
|
2
|
+
|
3
|
+
import { getAccess, handlebars, setOpt, setToken, getTemplate, handlebarsSync, applyHook } from "@opengis/fastify-table/utils.js";
|
4
|
+
//import { setOpt, setToken } from "../../../../../fastify-table/utils.js";
|
5
|
+
// import yaml from 'js-yaml';
|
6
|
+
import getTableData from "./tableData.js";
|
7
|
+
import conditions from './utils/conditions.js';
|
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
|
+
|
14
|
+
export default async function getCardData(req) {
|
15
|
+
|
16
|
+
const {
|
17
|
+
pg, params = {}, session = {}, user
|
18
|
+
} = req;
|
19
|
+
const { table, id } = params;
|
20
|
+
const uid = session.passport?.user?.uid;
|
21
|
+
|
22
|
+
const res = await applyHook('cardData', { table, id, user });
|
23
|
+
if (res) return res;
|
24
|
+
|
25
|
+
|
26
|
+
const time = Date.now();
|
27
|
+
|
28
|
+
const template = await getTemplate('card', table);
|
29
|
+
const access = await getAccess({ table, user });
|
30
|
+
|
31
|
+
const tableTemplate = await getTemplate('table', table);
|
32
|
+
|
33
|
+
const index = template?.find(el => el[0] === 'index.yml')?.[1] || {};
|
34
|
+
|
35
|
+
const { message, rows = [] } = index.table && index.query ? await pg.query(`select * from ${index.table} where ${handlebarsSync.compile(index.query)({ uid, user })}`) :
|
36
|
+
await getTableData({ pg, params: { table, id }, session, user });
|
37
|
+
|
38
|
+
if (message) return { message };
|
39
|
+
|
40
|
+
// conditions
|
41
|
+
index.panels?.filter(el => el.items).forEach(el => {
|
42
|
+
el.items = el.items?.filter(el => conditions(el.conditions, rows[0]));
|
43
|
+
})
|
44
|
+
|
45
|
+
// title, count
|
46
|
+
index.panels?.filter(el => el.items).forEach(async el => {
|
47
|
+
const filtered = el.items.filter(el => el.count?.toLowerCase?.().includes('select'));
|
48
|
+
const data = await Promise.all(filtered.map(el => pg.query(el.count).then(el => el.rows[0] || {})))
|
49
|
+
filtered.forEach((el, i) => {
|
50
|
+
Object.assign(el, data[i] || {}, data[i].count ? {} : { count: undefined })
|
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] }));
|
58
|
+
})
|
59
|
+
|
60
|
+
|
61
|
+
// tokens result
|
62
|
+
const tokens = {};
|
63
|
+
if (index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
|
64
|
+
Object.keys(index.tokens || {})
|
65
|
+
.filter(key => index?.tokens[key]?.public
|
66
|
+
|| access.actions?.includes?.('edit')
|
67
|
+
|| access.actions?.includes?.('add')
|
68
|
+
|| !index?.tokens[key]?.table
|
69
|
+
)
|
70
|
+
.forEach(key => {
|
71
|
+
const item = index?.tokens[key];
|
72
|
+
Object.keys(item).filter(el => item[el]?.includes?.('{{')).forEach(el => {
|
73
|
+
item[el] = handlebarsSync.compile(item[el])({ user, uid: user?.uid, id, data: rows[0] });
|
74
|
+
});
|
75
|
+
|
76
|
+
const token = item.form && item.table ? setToken({
|
77
|
+
ids: [JSON.stringify(item)],
|
78
|
+
uid,
|
79
|
+
array: 1,
|
80
|
+
})[0] : setOpt(item, user.uid);
|
81
|
+
tokens[key] = token;
|
82
|
+
});
|
83
|
+
}
|
84
|
+
|
85
|
+
// vue result
|
86
|
+
const vue = template?.filter((el) => el[0].endsWith('.vue'))
|
87
|
+
.reduce((acc, curr) => Object.assign(acc, { [path.parse(curr[0]).name]: curr[1].match(/<template[^>]*>([\s\S]*?)<\/template>/)[1].trim() }), {});
|
88
|
+
|
89
|
+
// data result
|
90
|
+
const data = {};
|
91
|
+
const route = await pg.query(`select route_id as path, title from admin.routes where enabled and alias=$1 limit 1`, [table])
|
92
|
+
.then(el => el.rows?.[0] || {});
|
93
|
+
Object.assign(route, { tableTitle: tableTemplate?.title });
|
94
|
+
if (index?.data && index?.data?.[0]?.name) {
|
95
|
+
await Promise.all(index.data.filter((el) => el?.name && el?.sql).map(async (el) => {
|
96
|
+
const q = handlebarsSync.compile(el.sql)({ data: rows[0], user, uid: user?.uid, id });
|
97
|
+
const { rows: sqlData } = await pg.query(q);
|
98
|
+
data[el.name] = sqlData;
|
99
|
+
}));
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
// html result
|
105
|
+
const html = {};
|
106
|
+
if (template) {
|
107
|
+
await Promise.all(template.filter(el => el[0].includes('.hbs')).map(async (el) => {
|
108
|
+
const htmlContent = await handlebars.compile(el[1])({ ...rows[0], user, data, tokens });
|
109
|
+
const name = el[0].substring(0, el[0].lastIndexOf('.'))
|
110
|
+
html[name] = htmlContent;
|
111
|
+
}));
|
112
|
+
}
|
113
|
+
|
114
|
+
return {
|
115
|
+
time: Date.now() - time,
|
116
|
+
...index,
|
117
|
+
tokens,
|
118
|
+
vue,
|
119
|
+
data,
|
120
|
+
route,
|
121
|
+
html,
|
122
|
+
rows,
|
123
|
+
columns: tableTemplate?.columns || tableTemplate?.colModel,
|
124
|
+
table: undefined,
|
125
|
+
query: undefined,
|
126
|
+
};
|
127
|
+
|
128
128
|
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { getFilter } from "@opengis/fastify-table/utils.js";
|
2
|
-
|
3
|
-
export default async function tableFilter(req) {
|
4
|
-
const { pg, params = {}, query = {}, user = {} } = req;
|
5
|
-
|
6
|
-
const { table } = params;
|
7
|
-
const { filter, custom, state, search } = query;
|
8
|
-
const result = await getFilter({ table, pg, filter, custom, state, search, user });
|
9
|
-
return result;
|
1
|
+
import { getFilter } from "@opengis/fastify-table/utils.js";
|
2
|
+
|
3
|
+
export default async function tableFilter(req) {
|
4
|
+
const { pg, params = {}, query = {}, user = {} } = req;
|
5
|
+
|
6
|
+
const { table } = params;
|
7
|
+
const { filter, custom, state, search } = query;
|
8
|
+
const result = await getFilter({ table, pg, filter, custom, state, search, user });
|
9
|
+
return result;
|
10
10
|
}
|