@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.
Files changed (99) hide show
  1. package/dist/{add-page-DsqxZzEq.js → add-page-CY3jyjng.js} +29 -26
  2. package/dist/{admin-interface-C8SGlC1N.js → admin-interface-B09NhAi-.js} +259 -257
  3. package/dist/{admin-view-DtdqTUPa.js → admin-view-obFqHA0_.js} +29 -29
  4. package/dist/admin.js +1 -1
  5. package/dist/admin.umd.cjs +89 -89
  6. package/dist/{card-view-juhvChuX.js → card-view-CAnhvY0b.js} +3 -3
  7. package/dist/{edit-page-DB1hlRzp.js → edit-page-DOpbSZWg.js} +33 -31
  8. package/dist/{import-file-BSdaeh6s.js → import-file-DAyouRPm.js} +23212 -23090
  9. package/dist/{profile-page-B-RhB5JP.js → profile-page-Cm3oX_ZN.js} +2 -2
  10. package/dist/style.css +1 -1
  11. package/module/settings/card/admin.roles.table/access.hbs +11 -11
  12. package/module/settings/card/admin.roles.table/general_info.hbs +9 -9
  13. package/module/settings/card/admin.roles.table/index.yml +22 -22
  14. package/module/settings/card/admin.roles.table/users.hbs +12 -12
  15. package/module/settings/card/admin.routes.table/general_info.hbs +13 -13
  16. package/module/settings/card/admin.routes.table/index.yml +15 -15
  17. package/module/settings/card/admin.table_properties.table/custom_columns.hbs +22 -22
  18. package/module/settings/card/admin.table_properties.table/index.yml +12 -12
  19. package/module/settings/card/admin.table_properties.table/info.hbs +17 -17
  20. package/module/settings/card/admin.users.table/general_info.hbs +18 -18
  21. package/module/settings/card/admin.users.table/index.yml +20 -20
  22. package/module/settings/card/admin.users.table/last_login.hbs +17 -17
  23. package/module/settings/card/admin.users.table/logs.hbs +16 -16
  24. package/module/settings/card/admin.users.table/routes.hbs +13 -13
  25. package/module/settings/card/admin.users.table/user_roles.hbs +35 -35
  26. package/module/settings/cls/change_type.json +13 -13
  27. package/module/settings/cls/core.column_type.json +14 -14
  28. package/module/settings/form/admin.custom_column.form.json +55 -55
  29. package/module/settings/form/admin.routes.form.json +25 -25
  30. package/module/settings/form/admin.rules.form.json +30 -30
  31. package/module/settings/form/admin.table_properties.form.json +19 -19
  32. package/module/settings/form/admin.user_roles.form.json +24 -24
  33. package/module/settings/form/admin.users.form.json +177 -177
  34. package/module/settings/form/admin.users_edit.form.json +145 -145
  35. package/module/settings/form/context.account_grants.form.json +24 -24
  36. package/module/settings/form/context.account_users.form.json +12 -12
  37. package/module/settings/form/user.user_roles.form.json +13 -13
  38. package/module/settings/menu.json +72 -72
  39. package/module/settings/table/admin.accounts.table.json +49 -49
  40. package/module/settings/table/admin.custom_column.table.json +100 -100
  41. package/module/settings/table/admin.roles.table.json +77 -77
  42. package/module/settings/table/admin.routes.table.json +73 -73
  43. package/module/settings/table/admin.rules.table.json +77 -77
  44. package/module/settings/table/admin.table_properties.table.json +37 -37
  45. package/module/settings/table/admin.user_roles.table.json +74 -74
  46. package/module/settings/table/admin.users.table.json +135 -135
  47. package/module/settings/table/context.account_grants.table.json +88 -88
  48. package/module/settings/table/context.account_users.table.json +53 -53
  49. package/module/settings/table/log.table_changes.table.json +100 -100
  50. package/package.json +102 -102
  51. package/plugin.js +30 -30
  52. package/server/helpers/index.js +40 -40
  53. package/server/helpers/list/descriptionList.js +45 -45
  54. package/server/helpers/list/tableList.js +82 -82
  55. package/server/helpers/list/utils/buttonDel.js +12 -12
  56. package/server/helpers/list/utils/buttonEdit.js +14 -14
  57. package/server/helpers/utils/buttonAdd.js +6 -6
  58. package/server/helpers/utils/buttonDel.js +6 -6
  59. package/server/helpers/utils/buttonEdit.js +5 -5
  60. package/server/helpers/utils/paddingNumber.js +3 -3
  61. package/server/plugins/access/funcs/getAdminAccess.js +12 -12
  62. package/server/plugins/hook.js +276 -276
  63. package/server/plugins/vite.js +77 -77
  64. package/server/routes/access/controllers/access.interface.js +33 -33
  65. package/server/routes/data/controllers/cardData.js +127 -127
  66. package/server/routes/data/controllers/tableFilter.js +9 -9
  67. package/server/routes/data/controllers/tableInfo.js +112 -112
  68. package/server/routes/dblist/controllers/readItems.js +20 -20
  69. package/server/routes/dblist/controllers/setItem.js +22 -22
  70. package/server/routes/dblist/index.mjs +18 -18
  71. package/server/routes/dblist/utils/formatData.js +7 -7
  72. package/server/routes/menu/controllers/getMenu.js +77 -77
  73. package/server/routes/menu/controllers/interfaces.js +20 -20
  74. package/server/routes/menu/index.mjs +7 -7
  75. package/server/routes/print/controllers/printTemplate.add.js +37 -37
  76. package/server/routes/print/controllers/printTemplate.delete.js +29 -29
  77. package/server/routes/print/controllers/printTemplate.edit.js +42 -42
  78. package/server/routes/print/controllers/printTemplate.js +67 -67
  79. package/server/routes/print/controllers/printTemplateList.js +19 -19
  80. package/server/routes/print/controllers/printTemplatePreview.js +87 -87
  81. package/server/routes/print/index.mjs +19 -19
  82. package/server/routes/properties/controllers/admin.properties.get.js +31 -31
  83. package/server/routes/properties/controllers/table.properties.get.js +120 -120
  84. package/server/routes/properties/controllers/table.properties.post.js +115 -115
  85. package/server/routes/properties/controllers/user.properties.get.js +19 -19
  86. package/server/routes/properties/controllers/user.properties.post.js +10 -10
  87. package/server/routes/properties/index.mjs +21 -21
  88. package/server/routes/properties/utils/dataInsert.js +26 -26
  89. package/server/routes/properties/utils/getColumnMetaData.js +17 -17
  90. package/server/routes/properties/utils/refreshData.js +128 -128
  91. package/server/routes/report/utils/getFilterQuery.js +67 -67
  92. package/server/routes/templates/index.mjs +16 -16
  93. package/server/routes/user/controllers/user.cls.post.js +54 -54
  94. package/server/routes/util/index.mjs +5 -5
  95. package/server/routes/widget/controllers/widget.get.js +125 -125
  96. package/server/templates/form/admin.profile.form.json +31 -31
  97. package/server/templates/form/cp_building.form.json +32 -32
  98. package/server/templates/pt/card-print.pt.hbs +245 -245
  99. package/utils.js +26 -26
@@ -1,29 +1,29 @@
1
- import { pgClients, dataDelete } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function printTemplateDelete({
4
- pg = pgClients.client, params = {}, user = {},
5
- }) {
6
- if (!user?.uid) {
7
- return { message: 'access restricted', status: 403 };
8
- }
9
-
10
- const { id, type } = await pg.query(`select template_id as id, type from admin.templates where enabled and $1 in (template_id, name)`, [params.id])
11
- .then(el => el.rows?.[0] || {});
12
-
13
- if (!id) {
14
- return { message: 'template not found', status: 404 };
15
- }
16
-
17
- if (type === 'demo') {
18
- return { message: 'access restricted: demo', status: 403 };
19
- }
20
-
21
- const res = await dataDelete({
22
- pg,
23
- table: 'admin.templates',
24
- id,
25
- uid: user?.uid,
26
- });
27
-
28
- return { id: res?.template_id, data: res };
29
- }
1
+ import { pgClients, dataDelete } from '@opengis/fastify-table/utils.js';
2
+
3
+ export default async function printTemplateDelete({
4
+ pg = pgClients.client, params = {}, user = {},
5
+ }) {
6
+ if (!user?.uid) {
7
+ return { message: 'access restricted', status: 403 };
8
+ }
9
+
10
+ const { id, type } = await pg.query(`select template_id as id, type from admin.templates where enabled and $1 in (template_id, name)`, [params.id])
11
+ .then(el => el.rows?.[0] || {});
12
+
13
+ if (!id) {
14
+ return { message: 'template not found', status: 404 };
15
+ }
16
+
17
+ if (type === 'demo') {
18
+ return { message: 'access restricted: demo', status: 403 };
19
+ }
20
+
21
+ const res = await dataDelete({
22
+ pg,
23
+ table: 'admin.templates',
24
+ id,
25
+ uid: user?.uid,
26
+ });
27
+
28
+ return { id: res?.template_id, data: res };
29
+ }
@@ -1,42 +1,42 @@
1
- import { pgClients, dataInsert } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function printTemplateEdit({
4
- pg = pgClients.client, params = {}, body = {}, user = {},
5
- }) {
6
- if (!user?.uid) {
7
- return { message: 'access restricted', status: 403 };
8
- }
9
-
10
- if (!params?.id) {
11
- return { message: 'not enough params: id', status: 400 };
12
- }
13
-
14
- const { html, route, title } = body;
15
-
16
- if (!html) {
17
- return { message: 'not enough body params: html', status: 400 };
18
- }
19
-
20
- const { id, name } = await pg.query(`select template_id as id, name from admin.templates where $1 in (template_id, name)`, [params.id])
21
- .then(el => el.rows?.[0] || {});
22
-
23
- if (!id) {
24
- return { message: 'template not found', status: 404 };
25
- }
26
-
27
- await pg.query(`delete from admin.templates where $1 in (template_id, name)`, [id]);
28
-
29
- const data = { name, body: html, type: 'user' };
30
- if (title) Object.assign(data, { title });
31
- if (route) Object.assign(data, { route_id: route });
32
-
33
- const res = await dataInsert({
34
- pg,
35
- table: 'admin.templates',
36
- id,
37
- data,
38
- uid: user?.uid,
39
- });
40
-
41
- return { id: res.rows?.[0]?.template_id, data: res.rows?.[0] };
42
- }
1
+ import { pgClients, dataInsert } from '@opengis/fastify-table/utils.js';
2
+
3
+ export default async function printTemplateEdit({
4
+ pg = pgClients.client, params = {}, body = {}, user = {},
5
+ }) {
6
+ if (!user?.uid) {
7
+ return { message: 'access restricted', status: 403 };
8
+ }
9
+
10
+ if (!params?.id) {
11
+ return { message: 'not enough params: id', status: 400 };
12
+ }
13
+
14
+ const { html, route, title } = body;
15
+
16
+ if (!html) {
17
+ return { message: 'not enough body params: html', status: 400 };
18
+ }
19
+
20
+ const { id, name } = await pg.query(`select template_id as id, name from admin.templates where $1 in (template_id, name)`, [params.id])
21
+ .then(el => el.rows?.[0] || {});
22
+
23
+ if (!id) {
24
+ return { message: 'template not found', status: 404 };
25
+ }
26
+
27
+ await pg.query(`delete from admin.templates where $1 in (template_id, name)`, [id]);
28
+
29
+ const data = { name, body: html, type: 'user' };
30
+ if (title) Object.assign(data, { title });
31
+ if (route) Object.assign(data, { route_id: route });
32
+
33
+ const res = await dataInsert({
34
+ pg,
35
+ table: 'admin.templates',
36
+ id,
37
+ data,
38
+ uid: user?.uid,
39
+ });
40
+
41
+ return { id: res.rows?.[0]?.template_id, data: res.rows?.[0] };
42
+ }
@@ -1,67 +1,67 @@
1
- import { createHash } from 'node:crypto';
2
-
3
- import { config, getFilterSQL, getTemplate, handlebars, pgClients } from '@opengis/fastify-table/utils.js';
4
- import { grpc } from '@opengis/fastify-file/utils.js';
5
-
6
- const { htmlToPdf } = grpc();
7
-
8
- export default async function printTemplate(req, reply) {
9
- const {
10
- pg = pgClients.client,
11
- params = {},
12
- query = {},
13
- } = req;
14
-
15
- if (!params?.name) {
16
- return { message: 'not enough params: name', status: 400 };
17
- }
18
-
19
- if (!params?.id) {
20
- return { message: 'not enough params: id', status: 400 };
21
- }
22
-
23
- const { id, route, body = '' } = await pg.query(`select template_id as id, body, route_id as route from admin.templates where $1 in (template_id,name)`, [params.name])
24
- .then(el => el.rows?.[0] || {});
25
-
26
- if (!id) {
27
- return reply.status(404).send('template not found');
28
- }
29
-
30
- /* -- params.name === document template -- */
31
- const format = query.format || (config.debug ? 'html' : 'pdf');
32
-
33
- const hash = createHash('md5')
34
- .update([params?.name, params?.id].join())
35
- .digest('hex');
36
-
37
- const headers = format === 'pdf'
38
- ? { 'Content-Disposition': `inline; filename=${hash}.pdf`, 'Content-Type': 'application/pdf' }
39
- : { 'Content-Type': 'text/html; charset=utf-8' };
40
-
41
- const table = await pg.query(`select alias from admin.routes where route_id=$1`, [route])
42
- .then(el => el.rows?.[0]?.alias);
43
-
44
- if (!table) {
45
- return { message: 'route table not found', status: 404 };
46
- }
47
-
48
- const loadTable = await getTemplate('table', table);
49
- const { optimizedSQL } = await getFilterSQL({ table, pg });
50
-
51
- const where = `${loadTable?.key || pg.pk?.[loadTable?.table || table]}=any($1::text[])`;
52
-
53
- const q = `select * from (${optimizedSQL})q where ${loadTable?.query || '1=1'} and ${where}`;
54
-
55
- const { rows = [] } = await pg.query(q, [params.id.split(',')]);
56
-
57
- const htmls = await Promise.all(rows.map(async (row) => handlebars.compile(body)(row)));
58
- const html = htmls.join('<p style="page-break-after: always;">&nbsp;</p>');
59
-
60
- if (format == 'html') {
61
- return reply.headers(headers).send(html);
62
- }
63
-
64
- const result = await htmlToPdf({ html });
65
- const buffer = Buffer.from(result.result, 'base64');
66
- return reply.headers(headers).send(buffer);
67
- }
1
+ import { createHash } from 'node:crypto';
2
+
3
+ import { config, getFilterSQL, getTemplate, handlebars, pgClients } from '@opengis/fastify-table/utils.js';
4
+ import { grpc } from '@opengis/fastify-file/utils.js';
5
+
6
+ const { htmlToPdf } = grpc();
7
+
8
+ export default async function printTemplate(req, reply) {
9
+ const {
10
+ pg = pgClients.client,
11
+ params = {},
12
+ query = {},
13
+ } = req;
14
+
15
+ if (!params?.name) {
16
+ return { message: 'not enough params: name', status: 400 };
17
+ }
18
+
19
+ if (!params?.id) {
20
+ return { message: 'not enough params: id', status: 400 };
21
+ }
22
+
23
+ const { id, route, body = '' } = await pg.query(`select template_id as id, body, route_id as route from admin.templates where $1 in (template_id,name)`, [params.name])
24
+ .then(el => el.rows?.[0] || {});
25
+
26
+ if (!id) {
27
+ return reply.status(404).send('template not found');
28
+ }
29
+
30
+ /* -- params.name === document template -- */
31
+ const format = query.format || (config.debug ? 'html' : 'pdf');
32
+
33
+ const hash = createHash('md5')
34
+ .update([params?.name, params?.id].join())
35
+ .digest('hex');
36
+
37
+ const headers = format === 'pdf'
38
+ ? { 'Content-Disposition': `inline; filename=${hash}.pdf`, 'Content-Type': 'application/pdf' }
39
+ : { 'Content-Type': 'text/html; charset=utf-8' };
40
+
41
+ const table = await pg.query(`select alias from admin.routes where route_id=$1`, [route])
42
+ .then(el => el.rows?.[0]?.alias);
43
+
44
+ if (!table) {
45
+ return { message: 'route table not found', status: 404 };
46
+ }
47
+
48
+ const loadTable = await getTemplate('table', table);
49
+ const { optimizedSQL } = await getFilterSQL({ table, pg });
50
+
51
+ const where = `${loadTable?.key || pg.pk?.[loadTable?.table || table]}=any($1::text[])`;
52
+
53
+ const q = `select * from (${optimizedSQL})q where ${loadTable?.query || '1=1'} and ${where}`;
54
+
55
+ const { rows = [] } = await pg.query(q, [params.id.split(',')]);
56
+
57
+ const htmls = await Promise.all(rows.map(async (row) => handlebars.compile(body)(row)));
58
+ const html = htmls.join('<p style="page-break-after: always;">&nbsp;</p>');
59
+
60
+ if (format == 'html') {
61
+ return reply.headers(headers).send(html);
62
+ }
63
+
64
+ const result = await htmlToPdf({ html });
65
+ const buffer = Buffer.from(result.result, 'base64');
66
+ return reply.headers(headers).send(buffer);
67
+ }
@@ -1,20 +1,20 @@
1
- import { pgClients } from "@opengis/fastify-table/utils.js";
2
-
3
- const maxLimit = 100;
4
-
5
- export default async function printTemplateList({
6
- pg = pgClients.client, query = {},
7
- }) {
8
- const { page = 1 } = query;
9
-
10
- const limit = Math.min(maxLimit, +(query.limit || 20));
11
-
12
- const offset = page && page > 0 ? (page - 1) * limit : '0';
13
-
14
- const q = `select template_id as id, name, title, route_id as route, type from admin.templates
15
- where enabled limit ${limit} offset ${offset}`;
16
-
17
- const { rows = [] } = pg.pk?.['admin.templates'] ? await pg.query(q) : {};
18
-
19
- return { page, limit, rows };
1
+ import { pgClients } from "@opengis/fastify-table/utils.js";
2
+
3
+ const maxLimit = 100;
4
+
5
+ export default async function printTemplateList({
6
+ pg = pgClients.client, query = {},
7
+ }) {
8
+ const { page = 1 } = query;
9
+
10
+ const limit = Math.min(maxLimit, +(query.limit || 20));
11
+
12
+ const offset = page && page > 0 ? (page - 1) * limit : '0';
13
+
14
+ const q = `select template_id as id, name, title, route_id as route, type from admin.templates
15
+ where enabled limit ${limit} offset ${offset}`;
16
+
17
+ const { rows = [] } = pg.pk?.['admin.templates'] ? await pg.query(q) : {};
18
+
19
+ return { page, limit, rows };
20
20
  }
@@ -1,87 +1,87 @@
1
- import { createHash } from 'node:crypto';
2
-
3
- import { config, getFilterSQL, getTemplate, handlebars, pgClients, getMeta } from '@opengis/fastify-table/utils.js';
4
- import { grpc } from '@opengis/fastify-file/utils.js';
5
-
6
- const { htmlToPdf } = grpc();
7
-
8
- export default async function printTemplate(req, reply) {
9
- const {
10
- pg = pgClients.client,
11
- params = {},
12
- query = {},
13
- } = req;
14
-
15
- if (!params?.name) {
16
- return reply.status(404).send('not enough params: name');
17
- }
18
-
19
- const { id, name, title, body = '', route } = await pg.query(`select template_id as id, name, title, body, route_id as route from admin.templates where $1 in (template_id,name)`, [params.name])
20
- .then(el => el.rows?.[0] || {});
21
-
22
- if (!id) {
23
- return reply.status(404).send('template not found');
24
- }
25
-
26
- /* -- params.name === document template -- */
27
- const format = query.format || (config.debug ? 'html' : 'pdf');
28
-
29
- const hash = createHash('md5')
30
- .update([query?.preview, query?.demo, params?.name].join())
31
- .digest('hex');
32
-
33
- const headers = format === 'pdf'
34
- ? { 'Content-Disposition': `inline; filename=${hash}.pdf`, 'Content-Type': 'application/pdf' }
35
- : { 'Content-Type': 'text/html; charset=utf-8' };
36
-
37
- if (query?.preview) {
38
- const matches = body?.match?.(/{{(?!\!)([^}]*)}}/g) || [];
39
- const preview = `<style> #toggle { background: yellow; } </style>`
40
- + matches.reduce((acc, curr) => acc.replace(curr, curr.replace(/{{(?!\!)([^}]*)}}/g, `<div id="toggle">${curr.replace(/{/g, '%7B').replace(/}/g, '%7D')}</div>`)), body);
41
-
42
- const html = await handlebars.compile(preview)({});
43
-
44
- if (format == 'html') {
45
- return reply.headers(headers).send(html.replace(/%7B/g, '{').replace(/%7D/g, '}'));
46
- }
47
-
48
- const result = await htmlToPdf({ html: html.replace(/%7B/g, '{').replace(/%7D/g, '}') });
49
- const buffer = Buffer.from(result.result, 'base64');
50
- return reply.headers(headers).send(buffer);
51
- }
52
-
53
- const { alias, table } = await pg.query(`select alias, table_name as table from admin.routes where route_id=$1`, [route])
54
- .then(el => el.rows?.[0] || {});
55
-
56
- if (!alias || !table) {
57
- return reply.status(404).send('route table not found');
58
- }
59
-
60
- if (query?.demo) {
61
- const loadTable = await getTemplate('table', alias);
62
- const { optimizedSQL } = await getFilterSQL({ pg, table: alias });
63
-
64
- if (!optimizedSQL) {
65
- return reply.status(400).send('empty query');
66
- }
67
-
68
- const q = `select * from (${optimizedSQL})q where ${loadTable?.query || '1=1'} limit 1`;
69
-
70
- const obj = await pg.query(q).then(el => el.rows?.[0] || {});
71
-
72
- const html = await handlebars.compile(body)(obj);
73
-
74
- if (format == 'html') {
75
- return reply.headers(headers).send(html);
76
- }
77
-
78
- const result = await htmlToPdf({ html });
79
- const buffer = Buffer.from(result.result, 'base64');
80
- return reply.headers(headers).send(buffer);
81
- }
82
-
83
- const meta = await getMeta({ pg, table });
84
- const columns = meta.columns?.map(el => ({ name: el.name, title: el.title, type: pg.pgType[el.dataTypeID] || 'text' }));
85
- // for body edit
86
- return { name, title, html: body, route, alias, table, columns };
87
- }
1
+ import { createHash } from 'node:crypto';
2
+
3
+ import { config, getFilterSQL, getTemplate, handlebars, pgClients, getMeta } from '@opengis/fastify-table/utils.js';
4
+ import { grpc } from '@opengis/fastify-file/utils.js';
5
+
6
+ const { htmlToPdf } = grpc();
7
+
8
+ export default async function printTemplate(req, reply) {
9
+ const {
10
+ pg = pgClients.client,
11
+ params = {},
12
+ query = {},
13
+ } = req;
14
+
15
+ if (!params?.name) {
16
+ return reply.status(404).send('not enough params: name');
17
+ }
18
+
19
+ const { id, name, title, body = '', route } = await pg.query(`select template_id as id, name, title, body, route_id as route from admin.templates where $1 in (template_id,name)`, [params.name])
20
+ .then(el => el.rows?.[0] || {});
21
+
22
+ if (!id) {
23
+ return reply.status(404).send('template not found');
24
+ }
25
+
26
+ /* -- params.name === document template -- */
27
+ const format = query.format || (config.debug ? 'html' : 'pdf');
28
+
29
+ const hash = createHash('md5')
30
+ .update([query?.preview, query?.demo, params?.name].join())
31
+ .digest('hex');
32
+
33
+ const headers = format === 'pdf'
34
+ ? { 'Content-Disposition': `inline; filename=${hash}.pdf`, 'Content-Type': 'application/pdf' }
35
+ : { 'Content-Type': 'text/html; charset=utf-8' };
36
+
37
+ if (query?.preview) {
38
+ const matches = body?.match?.(/{{(?!\!)([^}]*)}}/g) || [];
39
+ const preview = `<style> #toggle { background: yellow; } </style>`
40
+ + matches.reduce((acc, curr) => acc.replace(curr, curr.replace(/{{(?!\!)([^}]*)}}/g, `<div id="toggle">${curr.replace(/{/g, '%7B').replace(/}/g, '%7D')}</div>`)), body);
41
+
42
+ const html = await handlebars.compile(preview)({});
43
+
44
+ if (format == 'html') {
45
+ return reply.headers(headers).send(html.replace(/%7B/g, '{').replace(/%7D/g, '}'));
46
+ }
47
+
48
+ const result = await htmlToPdf({ html: html.replace(/%7B/g, '{').replace(/%7D/g, '}') });
49
+ const buffer = Buffer.from(result.result, 'base64');
50
+ return reply.headers(headers).send(buffer);
51
+ }
52
+
53
+ const { alias, table } = await pg.query(`select alias, table_name as table from admin.routes where route_id=$1`, [route])
54
+ .then(el => el.rows?.[0] || {});
55
+
56
+ if (!alias || !table) {
57
+ return reply.status(404).send('route table not found');
58
+ }
59
+
60
+ if (query?.demo) {
61
+ const loadTable = await getTemplate('table', alias);
62
+ const { optimizedSQL } = await getFilterSQL({ pg, table: alias });
63
+
64
+ if (!optimizedSQL) {
65
+ return reply.status(400).send('empty query');
66
+ }
67
+
68
+ const q = `select * from (${optimizedSQL})q where ${loadTable?.query || '1=1'} limit 1`;
69
+
70
+ const obj = await pg.query(q).then(el => el.rows?.[0] || {});
71
+
72
+ const html = await handlebars.compile(body)(obj);
73
+
74
+ if (format == 'html') {
75
+ return reply.headers(headers).send(html);
76
+ }
77
+
78
+ const result = await htmlToPdf({ html });
79
+ const buffer = Buffer.from(result.result, 'base64');
80
+ return reply.headers(headers).send(buffer);
81
+ }
82
+
83
+ const meta = await getMeta({ pg, table });
84
+ const columns = meta.columns?.map(el => ({ name: el.name, title: el.title, type: pg.pgType[el.dataTypeID] || 'text' }));
85
+ // for body edit
86
+ return { name, title, html: body, route, alias, table, columns };
87
+ }
@@ -1,19 +1,19 @@
1
- import cardPrint from './controllers/cardPrint.js';
2
- import printTemplateAdd from './controllers/printTemplate.add.js';
3
- import printTemplateEdit from './controllers/printTemplate.edit.js';
4
- import printTemplateDelete from './controllers/printTemplate.delete.js';
5
- import printTemplate from './controllers/printTemplate.js';
6
- import printTemplatePreview from './controllers/printTemplatePreview.js';
7
- import printTemplateList from './controllers/printTemplateList.js';
8
-
9
- const policy = ['user'];
10
-
11
- export default async function route(app) {
12
- app.get(`/card-print/:table/:id`, { config: { policy } }, cardPrint);
13
- app.get('/print-template/:name/:id', { config: { policy } }, printTemplate);
14
- app.get('/print-template/:name', { config: { policy } }, printTemplatePreview);
15
- app.get('/print-template', { config: { policy } }, printTemplateList);
16
- app.post('/print-template', { config: { policy } }, printTemplateAdd);
17
- app.put('/print-template/:id', { config: { policy } }, printTemplateEdit);
18
- app.delete('/print-template/:id', { config: { policy } }, printTemplateDelete);
19
- }
1
+ import cardPrint from './controllers/cardPrint.js';
2
+ import printTemplateAdd from './controllers/printTemplate.add.js';
3
+ import printTemplateEdit from './controllers/printTemplate.edit.js';
4
+ import printTemplateDelete from './controllers/printTemplate.delete.js';
5
+ import printTemplate from './controllers/printTemplate.js';
6
+ import printTemplatePreview from './controllers/printTemplatePreview.js';
7
+ import printTemplateList from './controllers/printTemplateList.js';
8
+
9
+ const policy = ['user'];
10
+
11
+ export default async function route(app) {
12
+ app.get(`/card-print/:table/:id`, { config: { policy } }, cardPrint);
13
+ app.get('/print-template/:name/:id', { config: { policy } }, printTemplate);
14
+ app.get('/print-template/:name', { config: { policy } }, printTemplatePreview);
15
+ app.get('/print-template', { config: { policy } }, printTemplateList);
16
+ app.post('/print-template', { config: { policy } }, printTemplateAdd);
17
+ app.put('/print-template/:id', { config: { policy } }, printTemplateEdit);
18
+ app.delete('/print-template/:id', { config: { policy } }, printTemplateDelete);
19
+ }
@@ -1,31 +1,31 @@
1
- const table = 'admin.properties';
2
-
3
- import { pgClients, getTemplatePath, getTemplate } from '@opengis/fastify-table/utils.js';
4
-
5
-
6
-
7
- export default async function getSettingsApp({
8
- pg = pgClients.client,
9
- }) {
10
- const time = Date.now();
11
- if (!pg.pk?.[table]) {
12
- return { message: 'table not found', status: 404 };
13
- }
14
-
15
- /*const keyCache = `${pg.options?.database}:settings:${params?.key || 'all'}:${query?.json ? 'json' : 'plain'}:${table}`;
16
- const cache = await redis.get(keyCache);
17
-
18
- if (cache && !config?.local) {
19
- return JSON.parse(cache);
20
- }*/
21
-
22
- const { rows } = await pgClients.client.query("select property_key as key,property_text as val from admin.properties /*where property_key~'^(site|map)'*/");
23
- const settings = rows.reduce((p, { key, val }) => { const [k1, k2] = key.split('.'); p[k1] = p[k1] || {}; p[k1][k2] = val; return p }, {});
24
- const settings1 = rows.reduce((p, { key, val }) => ({ ...p, [key]: val }), {});
25
-
26
- const forms = await Promise.all(getTemplatePath('setting')
27
- .map(async (el) => ({ name: el[0], body: await getTemplate('setting', el[0]) }))
28
- );
29
-
30
- return { message: { time: Date.now() - time, forms, settings: settings1 }, status: 200 };
31
- }
1
+ const table = 'admin.properties';
2
+
3
+ import { pgClients, getTemplatePath, getTemplate } from '@opengis/fastify-table/utils.js';
4
+
5
+
6
+
7
+ export default async function getSettingsApp({
8
+ pg = pgClients.client,
9
+ }) {
10
+ const time = Date.now();
11
+ if (!pg.pk?.[table]) {
12
+ return { message: 'table not found', status: 404 };
13
+ }
14
+
15
+ /*const keyCache = `${pg.options?.database}:settings:${params?.key || 'all'}:${query?.json ? 'json' : 'plain'}:${table}`;
16
+ const cache = await redis.get(keyCache);
17
+
18
+ if (cache && !config?.local) {
19
+ return JSON.parse(cache);
20
+ }*/
21
+
22
+ const { rows } = await pgClients.client.query("select property_key as key,property_text as val from admin.properties /*where property_key~'^(site|map)'*/");
23
+ const settings = rows.reduce((p, { key, val }) => { const [k1, k2] = key.split('.'); p[k1] = p[k1] || {}; p[k1][k2] = val; return p }, {});
24
+ const settings1 = rows.reduce((p, { key, val }) => ({ ...p, [key]: val }), {});
25
+
26
+ const forms = await Promise.all(getTemplatePath('setting')
27
+ .map(async (el) => ({ name: el[0], body: await getTemplate('setting', el[0]) }))
28
+ );
29
+
30
+ return { message: { time: Date.now() - time, forms, settings: settings1 }, status: 200 };
31
+ }