@opengis/admin 0.3.118 → 0.3.119

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 (37) hide show
  1. package/dist/{add-page-DavTwzVm.js → add-page-fdr6t9-i.js} +4 -4
  2. package/dist/{admin-interface-CkP3cmKh.js → admin-interface-bYzTXuVs.js} +12 -12
  3. package/dist/{admin-view-BZGbVVk5.js → admin-view-3hBO0cXK.js} +6 -6
  4. package/dist/admin.js +1 -1
  5. package/dist/admin.umd.cjs +53 -53
  6. package/dist/{card-view-DucsmPGl.js → card-view-Dfgoq-T0.js} +3 -3
  7. package/dist/{edit-page-BWDgRNIM.js → edit-page-pykfh5fh.js} +8 -8
  8. package/dist/{import-file-CyxfCvxQ.js → import-file-DPcs2POV.js} +16373 -16503
  9. package/dist/{profile-page-CQvE2X4u.js → profile-page-UeVwkn5K.js} +4 -4
  10. package/package.json +3 -3
  11. package/plugin.js +3 -3
  12. package/server/plugins/hook.js +1 -2
  13. package/server/routes/data/controllers/cardData.js +0 -132
  14. package/server/routes/data/controllers/cardTabData.js +0 -50
  15. package/server/routes/data/controllers/funcs/getFilterSQL/index.js +0 -92
  16. package/server/routes/data/controllers/funcs/getFilterSQL/util/formatValue.js +0 -170
  17. package/server/routes/data/controllers/funcs/getFilterSQL/util/getCustomQuery.js +0 -13
  18. package/server/routes/data/controllers/funcs/getFilterSQL/util/getFilterQuery.js +0 -64
  19. package/server/routes/data/controllers/funcs/getFilterSQL/util/getOptimizedQuery.js +0 -12
  20. package/server/routes/data/controllers/funcs/getFilterSQL/util/getTableSql.js +0 -34
  21. package/server/routes/data/controllers/tableData.js +0 -45
  22. package/server/routes/data/controllers/tableDataId.js +0 -28
  23. package/server/routes/data/controllers/tableFilter.js +0 -10
  24. package/server/routes/data/controllers/tableInfo.js +0 -112
  25. package/server/routes/data/controllers/tokenInfo.js +0 -10
  26. package/server/routes/data/controllers/utils/assignTokens.js +0 -31
  27. package/server/routes/data/controllers/utils/conditions.js +0 -21
  28. package/server/routes/data/controllers/utils/getColumns.js +0 -9
  29. package/server/routes/data/index.mjs +0 -20
  30. package/server/routes/data/schema.js +0 -54
  31. package/server/routes/menu/controllers/getMenu.js +0 -81
  32. package/server/routes/menu/controllers/interfaces.js +0 -21
  33. package/server/routes/menu/index.mjs +0 -7
  34. package/server/routes/menu/schema.js +0 -0
  35. package/server/routes/templates/controllers/getTemplate.js +0 -45
  36. package/server/routes/templates/index.mjs +0 -16
  37. package/server/routes/templates/schema.js +0 -9
@@ -1,45 +0,0 @@
1
- import { getOpt, getMeta, getTemplate, getData, pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function getTableData(req) {
4
- const { user = {}, params = {}, query = {}, pg = pgClients.client } = req;
5
- const { filter, limit, page, search, sql, state, order } = query || {};
6
- const { id } = params || {};
7
-
8
- const tokenData = await getOpt(params.table, user?.uid);
9
-
10
- if (tokenData?.table) {
11
- const loadTable = await getTemplate('table', tokenData.table);
12
-
13
- if (!loadTable) {
14
- // const resp = await getData({ id, table: params.table, pg, filter, state, limit, page, search, order, user, sql, contextQuery: tokenData.query, sufix: false });
15
- // return resp;
16
- const { rows = [], fields = [] } = await pg.query(`select ${tokenData.columns || '*'} from ${tokenData.table} where ${tokenData.query || 'true'} limit 10`);
17
- const meta = await getMeta({ pg, table: tokenData.table });
18
- const columns = (meta?.columns || fields).map(el => ({ name: el.name, type: pg.pgType?.[el.dataTypeID], title: el.title }));
19
- return { rows, columns };
20
- }
21
-
22
- const resp = await getData({ id, table: tokenData.table, pg, filter, state, limit, page, search, order, user, sql, contextQuery: tokenData.query });
23
- return resp;
24
- }
25
-
26
- // Це можна 1 раз на старті
27
- const interfaceName = req.headers?.referer?.match(/.*\/([^?]+)/)?.[1];
28
- const { query: interfaceQuery } = interfaceName ?
29
- await pg.query(`select query from admin.routes where route_id=$1`, [interfaceName])
30
- .then(el => el.rows?.[0] || {}) : {};
31
-
32
- // це можна від користувача
33
- const { rows = [] } = pg.pk?.['admin.rules'] ? await 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)`, [params.table, user.uid]) : {};
34
-
35
- const context = rows.filter(el => el.rule_values).map(el => `${el.attr} = any ('{${el.rule_values}}')`).join(' and ');
36
- const contextQuery = [interfaceQuery, context].filter(el => el).join(' and ') || ' 2=2 ';
37
-
38
- const res = await getData({
39
- id, table: params.table, pg, filter, state, limit, page, search, order, user, sql, contextQuery,
40
- });
41
- // console.log('contextQuery', contextQuery);
42
-
43
- return res;
44
-
45
- }
@@ -1,28 +0,0 @@
1
- import { handlebars } from "@opengis/fastify-table/utils.js";
2
-
3
- import getTemplate from "../../templates/funcs/getTemplate.js";
4
- import getTableData from "./tableData.js";
5
-
6
- export default async function tableDataId({ pg, params = {}, session = {}, user }, reply) {
7
- const { name, id } = params;
8
-
9
- const data = await getTemplate('pt', `${name}.pt`);
10
-
11
-
12
- if (!data) {
13
- return { message: `invalid template: ${name}.pt`, status: 400 };
14
- }
15
- debugger;
16
- const { message, status = 500, rows = [] } = await getTableData({ pg, params: { name, id }, session, user });
17
- if (message) {
18
- return { message, status };
19
- }
20
-
21
- if (!rows.length) {
22
- return { message: `data not found: ${name}/${id}`, status: 404 };
23
- }
24
-
25
- const htmlContent = await handlebars.compile(data)(rows[0]);
26
-
27
- return reply.headers({ 'Content-Type': 'text/html; charset=utf-8' }).send(htmlContent);
28
- }
@@ -1,10 +0,0 @@
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
- }
@@ -1,112 +0,0 @@
1
- import {
2
- getTemplate, getMeta, metaFormat, applyHook, handlebars, pgClients,
3
- } from '@opengis/fastify-table/utils.js';
4
-
5
- export default async function tableInfo(req) {
6
- const {
7
- pg = pgClients.client, params = {}, query = {}, user = {},
8
- } = req;
9
-
10
- const time = Date.now();
11
-
12
- const { uid } = user;
13
-
14
- if (!uid) {
15
- return { message: 'access restricted: uid', status: 403 };
16
- }
17
-
18
- if (!params?.id || !params?.table) {
19
- return { message: 'not enougn params', status: 400 };
20
- }
21
-
22
- const loadTable = await getTemplate('table', params.table);
23
-
24
- if (!loadTable) {
25
- return { message: 'template not found', status: 404 };
26
- }
27
-
28
- const {
29
- table, columns = [], sql, cardSql, filters, form, meta, public: ispublic,
30
- } = loadTable;
31
-
32
- if (!meta?.info) {
33
- return { message: 'empty meta info', status: 400 };
34
- }
35
-
36
- const tableMeta = await getMeta(table);
37
-
38
- if (tableMeta?.view) {
39
- if (!loadTable?.key) {
40
- return { message: `key not found: ${table}`, status: 404 };
41
- }
42
- Object.assign(tableMeta, { pk: loadTable?.key });
43
- }
44
-
45
- const { pk } = tableMeta || {};
46
-
47
- if (!pk) {
48
- return { message: `table not found: ${table}`, status: 404 };
49
- }
50
-
51
- const sqlTable = sql
52
- ?.filter?.((el) => !el?.disabled && el?.sql?.replace)
53
- ?.map((el, i) => ` left join lateral (${el.sql.replace('{{uid}}', uid)}) ${el.name || `t${i}`} on 1=1 `)
54
- ?.join('') || '';
55
-
56
- const cardSqlFiltered = params.id ? (cardSql?.filter?.((el) => !el?.disabled && el?.name && el?.sql?.replace) || []) : [];
57
- const cardSqlTable = cardSqlFiltered.length ? cardSqlFiltered.map((el, i) => ` left join lateral (${el.sql.replace('{{uid}}', uid)}) ct${i} on 1=1 `).join('\n') || '' : '';
58
-
59
- const interfaceQuery = params?.query ? await handlebars.compile(params?.query)({ user, uid }) : undefined;
60
- const where = [params.id ? `"${pk}" = $1` : null, loadTable.query, interfaceQuery].filter((el) => el).filter((el) => (user?.user_type === 'superadmin' ? !el.includes('{{uid}}') : true));
61
-
62
- const { fields = [] } = await pg.query(`select * from ${table} where ${sqlTable ? 'true' : (where.join(' and ') || 'true')} limit 0`, ([sqlTable ? null : params.id].filter(el => el)) );
63
- const columnList = fields.map(el => el.name);
64
-
65
- const metaInfoCols = meta.info.split(',').filter(el => columnList.includes(el)).map((el) => `"${el}"`);
66
-
67
- if (!metaInfoCols.length) {
68
- return { message: 'invalid meta info: columns not found', status: 400 };
69
- }
70
-
71
- const q = `select ${pk ? `"${pk}" as id,` : ''}
72
- ${metaInfoCols.join(',')}
73
- from (select * from ${table} where ${sqlTable ? 'true' : (where.join(' and ') || 'true')}) t
74
- ${sqlTable}
75
- ${cardSqlTable}
76
- where ${where.join(' and ') || 'true'}
77
- limit 1`
78
- .replace(/{{uid}}/g, uid);
79
-
80
- // if (user?.user_type === 'superadmin') console.log(q);
81
-
82
- if (query.sql === '1') { return q; }
83
-
84
- const { rows } = await pg.query(q, [params.id]);
85
-
86
- const qCount = `select
87
- count(*)::int as total,
88
- count(*) FILTER(WHERE ${[interfaceQuery].filter(el => el).join(' and ') || 'true'})::int as filtered
89
- from ${table} t ${sqlTable}
90
- where ${[loadTable.query].filter(el => el).join(' and ') || 'true'} `
91
- .replace(/{{uid}}/g, uid);
92
-
93
- const { total, filtered } = params.id ? rows.length
94
- : await pg.queryCache(qCount, { table: loadTable.table, time: 5 }).then((el) => el?.rows[0]);
95
-
96
- const cls = meta.info.split(',').filter(el => columnList.includes(el))
97
- .map(el => ({ name: el, data: columns.find(col => col.name === el)?.data }))
98
- .filter(el => el.data)
99
- .reduce((acc, curr) => Object.assign(acc, { [curr.name]: curr.data }), {});
100
-
101
- await metaFormat({ rows, cls /* , sufix: false */ });
102
-
103
- const res = {
104
- time: Date.now() - time, public: ispublic, card: loadTable.card, total, filtered, count: rows.length, pk, form, rows, meta, columns, filters,
105
- };
106
-
107
- const result = await applyHook('afterData', {
108
- table: loadTable.table, payload: res, user,
109
- });
110
-
111
- return result || res;
112
- }
@@ -1,10 +0,0 @@
1
- import { getOpt, getToken } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function tokenInfo(req) {
4
-
5
- const { params = {}, user } = req;
6
- if (user.user_type !== 'admin') return { status: 403, message: 'access restricted' }
7
- const tokenData = await getToken({ uid: user.uid, token: params.token, }) || await getOpt(params.token, user.uid)
8
- return tokenData;
9
-
10
- }
@@ -1,31 +0,0 @@
1
- import { config, setToken } from "@opengis/fastify-table/utils.js";
2
-
3
- export default function assignTokens({
4
- rows = [], ispublic, uid, loadTable = {},
5
- }) {
6
- if (config?.security?.disableToken) return;
7
-
8
- if (!config?.auth?.disable && !ispublic && !uid) throw new Error('empty user');
9
- if (!loadTable?.table || !(loadTable?.form || loadTable?.add_form)) return null;
10
-
11
- const form = loadTable?.form || loadTable?.add_form;
12
- const addTokens = setToken({
13
- ids: [JSON.stringify({ add: loadTable.table, form })],
14
- mode: 'a',
15
- uid: config?.auth?.disable || ispublic ? '1' : uid,
16
- array: 1,
17
- });
18
- if (!rows.length) return addTokens[0];
19
-
20
- rows.forEach((row) => {
21
- const editTokens = setToken({
22
- ids: [JSON.stringify({ id: row.id, table: loadTable.table, form })],
23
- mode: 'w',
24
- uid: config?.auth?.disable || ispublic ? '1' : uid,
25
- array: 1,
26
- });
27
- Object.assign(row, { token: editTokens[0] });
28
- });
29
- return addTokens[0];
30
-
31
- }
@@ -1,21 +0,0 @@
1
- function onCheck(rule, data) {
2
- const val = data[rule[0]];
3
- // console.log(val, rule[1], rule[2])
4
- if (rule[1] === '==') return val === rule[2];
5
- if (rule[1] === '!=') return val !== rule[2];
6
- if (rule[1] === 'in' && rule[2].split) return rule[2].split(',').includes(val);
7
- if (rule[1] === 'in' && rule[2].includes) return rule[2].includes(val);
8
-
9
- if (rule[1] === 'not in' && rule[2].split) return !rule[2].split(',').includes(val);
10
- if (rule[1] === 'not in' && rule[2].includes) return !rule[2].includes(val);
11
-
12
- if (rule[1] === '>') return val > rule[2];
13
- if (rule[1] === '<') return val < rule[2];
14
- }
15
- export default function conditions(rules, data) {
16
- if (!rules?.length) return true;
17
- const result = Array.isArray(rules[0]) ? !rules.filter(el => !onCheck(el, data)).length : onCheck(rules, data)
18
- // console.log(rules, result)
19
- return result;
20
-
21
- }
@@ -1,9 +0,0 @@
1
- import { getTemplate } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function getColumns({
4
- columns = [], params = {}, opt = {}, loadTable = {}, form, table, dbColumns = [], mode = 'table',
5
- }) {
6
- const columnList = dbColumns.map((el) => el.name || el).join(',');
7
- const cols = columns.filter((el) => columnList.includes(el?.name) && el?.name !== 'geom').map((el) => el?.name || el).join(',');
8
- return { cols, columnList };
9
- }
@@ -1,20 +0,0 @@
1
-
2
- import tableData from "./controllers/tableData.js";
3
- import tokenInfo from "./controllers/tokenInfo.js";
4
- // import tableDataId from "./controllers/tableDataId.js";
5
- import cardData from "./controllers/cardData.js";
6
- import cardTabData from './controllers/cardTabData.js';
7
- import tableFilter from "./controllers/tableFilter.js";
8
-
9
- import { tableDataSchema, tableDataIdSchema, tableFilterSchema, cardTabDataSchema } from './schema.js';
10
- import tableInfo from "./controllers/tableInfo.js";
11
-
12
- export default async function route(fastify) {
13
- const policy = ['user'];
14
- fastify.get(`/token-info/:token`, { config: { policy: ['admin'] } }, tokenInfo);
15
- fastify.get(`/table-data/:table`, { config: { policy: ['user', 'no-sql'] }, schema: tableDataSchema }, tableData);
16
- fastify.get(`/card-data/:token`, { config: { policy }, scheme: cardTabDataSchema }, cardTabData);
17
- fastify.get(`/table-data/:table/:id`, { config: { policy }, schema: tableDataIdSchema }, cardData);
18
- fastify.get(`/table-filter/:table`, { config: { policy }, schema: tableFilterSchema }, tableFilter);
19
- fastify.get(`/table-info/:table/:id?`, { config: { policy }, schema: tableDataSchema }, tableInfo);
20
- }
@@ -1,54 +0,0 @@
1
- const tableDataSchema = {
2
- querystring: {
3
- limit: { type: 'string', pattern: '^(\\d+)$' },
4
- page: { type: 'string', pattern: '^(\\d+)$' },
5
- // filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
6
- // search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
7
- order: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
8
- desc: { type: 'string', pattern: '^(\\d+)$' },
9
- state: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
10
- custom: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
11
- bbox: { type: 'string', pattern: '^([\\d\\s,.-]+)$' },
12
- polyline: { type: 'string', pattern: '^([\\d\\w|@{}~_`]+)$' },
13
- // key: { type: 'string', pattern: '^([\\d\\w_]+)$' },
14
- sql: { type: 'string', pattern: '^(\\d)$' },
15
- },
16
- params: {
17
- id: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
18
- table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
19
- }
20
- };
21
-
22
- const tableDataIdSchema = {
23
- params: {
24
- id: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
25
- name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
26
- }
27
- };
28
-
29
- const tableFilterSchema = {
30
- params: {
31
- name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
32
- }
33
- };
34
-
35
- const cardDataSchema = {
36
- params: {
37
- id: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
38
- table: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
39
- }
40
- };
41
-
42
- const cardTabDataSchema = {
43
- querystring: {
44
- sql: { type: 'string', pattern: '^(\\d)$' }
45
- },
46
- params: {
47
- token: { type: 'string', pattern: '^([\\d\\w]+)$' },
48
- }
49
- };
50
- export {
51
- tableDataSchema, tableDataIdSchema, tableFilterSchema,
52
- cardDataSchema, cardTabDataSchema
53
- }
54
- export default null;
@@ -1,81 +0,0 @@
1
-
2
- import { join } from 'path';
3
- import { userTemplateDir, pgClients, applyHook, config } from '@opengis/fastify-table/utils.js';
4
-
5
- import { existsSync, readdirSync, readFileSync } from 'fs';
6
- const menuCache = [];
7
- // check module dir
8
- const moduleDir = join(process.cwd(), 'module');
9
- const dirs = existsSync(moduleDir) ?
10
- readdirSync(moduleDir).map(el => join(moduleDir, el)) : [];
11
-
12
- // all menu files module + user
13
-
14
-
15
-
16
- const isProduction = process.env.NODE_ENV === 'production';
17
- // readMenu();
18
-
19
- async function readMenu() {
20
- const menuList = dirs.concat(userTemplateDir)
21
- .map(el => join(el, 'menu.json'))
22
- .filter(el => existsSync(el))
23
- // const list = menuList.map(el => readFileSync(el, 'utf-8')); // sync
24
- const list = menuList.filter((el, idx, arr) => el && arr.indexOf(el) === idx).map(el => readFileSync(el, 'utf-8')); // sync
25
- const menus = list.reduce((p, el) => p.concat(JSON.parse(el)), [])
26
- .map(el => ({ order: 0, ...el }))
27
- .sort((a, b) => (a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0))
28
-
29
- if (!menuCache.length) menus.forEach(el => menuCache.push(el))
30
- return menus;
31
- }
32
- export default async function adminMenu({ user = {}, session, pg = pgClients.client }) {
33
- const time = Date.now();
34
- if (!user.uid) return { status: 403, message: 'access restricted' }
35
-
36
- const menus = isProduction && menuCache.length ? menuCache : await readMenu();
37
-
38
- const { rows } = await pgClients.client.query(`select property_key as key,property_text as val from admin.properties where property_key~'^(${config.settingKeys || 'site|map|admin'})'`);
39
- const settings = rows.reduce((p, { key, val }) => { const [k1, k2] = key.split('.'); p[k1] = p[k1] || {}; p[k1][k2] = val; return p }, {});
40
-
41
- if (config.settings) Object.assign(settings, config.settings);
42
-
43
- // update user access
44
- const { user_name, sur_name, father_name, email, phone, uid } = user;
45
- const result = { settings, user: { uid, user_name, sur_name, father_name, email, phone } };
46
- await applyHook('userMenu', result);
47
-
48
- if (session && user?.uid && !user.user_type?.includes?.('admin') && !user.type?.includes?.('admin') && pg.pk['admin.role_access']) {
49
- const { type, gl = [], routes = [] } = await pg.query(`select user_type as type, b.gl,routes from admin.users a
50
- left join lateral (
51
- select array_agg(role_id) as gl from admin.user_roles
52
- where user_uid=a.uid
53
- and role_id in ( select role_id from admin.roles where enabled)
54
- )b on 1=1
55
- left join lateral (
56
- select array_agg(route_id) as routes from admin.role_access where role_id=any(b.gl)
57
- )r on 1=1
58
- where uid=$1`, [user.uid]).then(el => el.rows[0] || {});
59
- /* const { interfaces = [] } = await pg.query(`select array_agg(route_id) as interfaces from admin.role_access
60
- where user_uid=$1 or role_id=any($2::text[])`, [user.uid, gl]).then((res) => res.rows?.[0] || {}); */
61
-
62
- Object.assign(user, { type, group_list: gl, routes });
63
- session?.set?.('passport', { user });
64
-
65
- if (type?.includes?.('admin')) {
66
- return { time: Date.now() - time, menus, ...result };
67
- }
68
-
69
- const userMenus = menus.map(el => (el.menu ? { ...el, menu: el.menu.filter(item => routes?.includes(item.path)) } : el))
70
- const filtered = userMenus.filter(el => el.menu?.length || routes?.includes(el.path));
71
- return { time: Date.now() - time, menus: filtered, ...result }
72
- // .filter((el, idx, arr) => arr.map((el) => el?.ua || el?.en || el?.name).indexOf(el?.ua || el?.en || el?.name) === idx)
73
- }
74
-
75
- // skip dupes?
76
- // .filter((el, idx, arr) => arr.map((el) => el?.ua || el?.en || el?.name).indexOf(el?.ua || el?.en || el?.name) === idx)
77
-
78
- return { time: Date.now() - time, menus, ...result };
79
-
80
-
81
- }
@@ -1,21 +0,0 @@
1
- import { pgClients, getTemplatePath } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function adminMenu({ pg = pgClients.client }) {
4
- const { rows = [] } = await pg.query(`select route_id, alias, table_name, title, enabled from admin.routes`);
5
-
6
- const interfaces = rows
7
- .filter((el, idx, arr) => el.table_name && arr.findIndex(item => item.route_id === el.route_id) === idx)
8
- .filter(el => pg.pk?.[el.table_name || ''])
9
- .filter(el => !['log.', 'admin.', 'setting.'].find(item => el.table_name.startsWith(item)))
10
- .map(el => ({
11
- title: el.title,
12
- alias: el.alias,
13
- table: el.table_name,
14
- route: el.route_id,
15
- enabled: el.enabled,
16
- }));
17
-
18
- const all = getTemplatePath('table').map(el => el[0]);
19
-
20
- return interfaces.filter(el => el.alias && all.includes(el.alias));
21
- }
@@ -1,7 +0,0 @@
1
- import getMenu from './controllers/getMenu.js';
2
- import interfaces from './controllers/interfaces.js';
3
-
4
- export default async function (fastify, opts) {
5
- fastify.get(`/user-menu`, getMenu);
6
- fastify.get(`/interfaces`, { config: { policy: ['admin'] } }, interfaces);
7
- }
File without changes
@@ -1,45 +0,0 @@
1
- import { config, applyHook, getTemplate, getToken, setToken, handlebarsSync } from "@opengis/fastify-table/utils.js";
2
-
3
- function formatSchema(schema, user, opt) {
4
- function parseDataTables(obj) {
5
- if (obj?.add) {
6
- const obj1 = obj.add?.obj?.includes('{{') && opt ? handlebarsSync.compile(obj.add.obj)(opt) : obj.add?.obj;
7
- if (obj.add?.obj) obj.add.obj = obj1;
8
- const [token] = setToken({
9
- ids: [JSON.stringify({ ...obj.add, table: obj.add?.table || obj.add?.model })],
10
- uid: user.uid,
11
- array: 1,
12
- });
13
- Object.assign(obj.add, { token, api: `${config.prefix || '/api'}/table/${token}` });
14
- } else if (obj?.type === 'DataTable' && obj.colModel?.length) {
15
- obj.colModel.forEach(parseDataTables);
16
- }
17
- }
18
- Object.keys(schema || {}).map(key => ({ key, ...schema[key] })).forEach(parseDataTables);
19
- }
20
-
21
- export default async function getTemplateApi(req) {
22
- const { user } = req || {};
23
- const { params = {} } = req;
24
- const { type, name } = params;
25
-
26
- const tokenData = await getToken({ token: name, uid: user?.uid, json: 1 }) || {};
27
-
28
- const hookData = await applyHook('preTemplate', { name: tokenData.name || name, type, user });
29
- if (hookData?.message && hookData?.status) return hookData;
30
-
31
- const data = await getTemplate(type, hookData?.name || tokenData.form || name);
32
-
33
- if (tokenData.obj) {
34
- const obj = tokenData.obj.split('#').reduce((p, el) => ({ ...p, [el.split('=')[0]]: el.split('=')[1] }), {})
35
- Object.assign(data, { obj });
36
- }
37
-
38
- if (type === 'form' && user?.uid) {
39
- const schema = data?.schema || data;
40
- formatSchema(schema, user, data?.obj);
41
- }
42
-
43
- await applyHook('afterTemplate', { name, type, data, user });
44
- return data?.html || data || `template not found "${name}"`;
45
- }
@@ -1,16 +0,0 @@
1
- import getTemplateApi from './controllers/getTemplate.js';
2
-
3
- import getTemplateSchema from './schema.js'
4
-
5
- export default async function route(fastify) {
6
- //fastify.decorate('addTempateFolder', addTempateFolder); // call from funcs
7
- fastify.get(`/template/:type/:name`, { config: { policy: ['public'] }, scheme: getTemplateSchema }, getTemplateApi);
8
-
9
- /*fastify.addHook('onListen', async () => {
10
- await addTempateFolder(path.join(process.cwd(), '/module/itree'));
11
- await addTempateFolder(path.join(process.cwd(), '/module/test'));
12
- });*/
13
-
14
-
15
-
16
- }
@@ -1,9 +0,0 @@
1
- const getTemplateSchema = {
2
- params: {
3
- name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
4
- // type: { type: 'string' },
5
- }
6
- };
7
-
8
- export default null;
9
- export { getTemplateSchema }