@opengis/admin 0.1.38 → 0.1.39
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/README.md +29 -29
- package/config.js +4 -4
- package/dist/{add-page-C5g2yN5N.js → add-page-CYAz9FdO.js} +1 -1
- package/dist/{admin-interface-zpEN5ODZ.js → admin-interface-BfY0EPQi.js} +1 -1
- package/dist/{admin-view-DD8_bEjC.js → admin-view-CcyuPjSQ.js} +2 -2
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +5 -5
- package/dist/{card-page-BpMHxKbw.js → card-page-DV3pe4fv.js} +21 -21
- package/dist/{card-view-Ddro0nc4.js → card-view-pwoN8ZHo.js} +1 -1
- package/dist/{edit-page-BL9SogVY.js → edit-page-PNY_GQBC.js} +1 -1
- package/dist/{import-file-DBSDU17c.js → import-file-aqrl_bc7.js} +20 -13
- package/dist/style.css +1 -1
- package/module/settings/card/admin.roles.table/access.hbs +27 -27
- package/module/settings/card/admin.roles.table/general_info.hbs +16 -16
- package/module/settings/card/admin.roles.table/index.yml +14 -14
- package/module/settings/card/admin.roles.table/users.hbs +27 -27
- package/module/settings/card/admin.routes.table/general_info.hbs +40 -40
- package/module/settings/card/admin.routes.table/index.yml +8 -8
- package/module/settings/card/admin.routes.table/users.hbs +33 -33
- package/module/settings/card/admin.users.table/general_info.hbs +25 -25
- package/module/settings/card/admin.users.table/index.yml +12 -12
- package/module/settings/card/admin.users.table/logs.hbs +30 -30
- package/module/settings/card/admin.users.table/user_roles.hbs +24 -24
- package/module/settings/cls/core.actions.json +13 -13
- package/module/settings/cls/core.scope.json +13 -13
- package/module/settings/cls/properties.site_status.json +13 -13
- package/module/settings/cls/properties.widget_status.json +13 -13
- package/module/settings/cls/users.user_type.json +13 -13
- package/module/settings/form/admin.access.form.json +36 -36
- package/module/settings/form/admin.properties.form.json +15 -15
- package/module/settings/form/admin.roles.form.json +19 -19
- package/module/settings/form/admin.routes.form.json +25 -25
- package/module/settings/form/admin.table_properties.form.json +70 -70
- package/module/settings/form/admin.user_properties.form.json +15 -15
- package/module/settings/form/admin.user_roles.form.json +21 -21
- package/module/settings/form/admin.users.form.json +150 -150
- package/module/settings/form/user.user_roles.form.json +13 -13
- package/module/settings/interface/admin.properties.json +4 -4
- package/module/settings/interface/admin.roles.json +4 -4
- package/module/settings/interface/admin.routes.json +4 -4
- package/module/settings/interface/admin.users.json +4 -4
- package/module/settings/menu.json +50 -50
- package/module/settings/select/core.roles.json +2 -2
- package/module/settings/select/core.user_uid.sql +1 -1
- package/module/settings/table/admin.access.table.json +77 -77
- package/module/settings/table/admin.properties.table.json +33 -33
- package/module/settings/table/admin.roles.table.json +58 -58
- package/module/settings/table/admin.routes.table.json +55 -55
- package/module/settings/table/admin.table_properties.table.json +81 -81
- package/module/settings/table/admin.user_properties.table.json +28 -28
- package/module/settings/table/admin.user_roles.table.json +66 -66
- package/module/settings/table/admin.users.table.json +119 -119
- package/package.json +74 -74
- package/plugin.js +101 -101
- package/server/helpers/controllers/badge.js +11 -11
- package/server/helpers/controllers/hb.js +2 -2
- package/server/helpers/controllers/map.js +2 -2
- package/server/helpers/controllers/mls.js +2 -2
- package/server/helpers/controllers/vue.js +2 -2
- package/server/helpers/index.mjs +13 -13
- package/server/plugins/docs.js +28 -28
- package/server/plugins/hook.js +166 -166
- package/server/plugins/vite.js +69 -69
- package/server/routes/data/controllers/cardData.js +56 -56
- package/server/routes/data/controllers/cardTabData.js +39 -39
- package/server/routes/data/controllers/funcs/getFilterSQL/index.js +85 -85
- package/server/routes/data/controllers/funcs/getFilterSQL/util/formatValue.js +145 -142
- package/server/routes/data/controllers/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/server/routes/data/controllers/funcs/getFilterSQL/util/getFilterQuery.js +67 -67
- package/server/routes/data/controllers/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/server/routes/data/controllers/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/server/routes/data/controllers/tableData.js +121 -121
- package/server/routes/data/controllers/tableDataId.js +27 -27
- package/server/routes/data/controllers/tableFilter.js +55 -55
- package/server/routes/data/controllers/utils/assignTokens.js +30 -30
- package/server/routes/data/controllers/utils/getColumns.js +21 -21
- package/server/routes/data/index.mjs +12 -12
- package/server/routes/menu/controllers/getMenu.js +33 -33
- package/server/routes/menu/index.mjs +5 -5
- package/server/routes/properties/controllers/admin.properties.get.js +29 -29
- package/server/routes/properties/controllers/user.properties.get.js +34 -34
- package/server/routes/properties/controllers/user.properties.post.js +30 -30
- package/server/routes/properties/funcs/getSettings.js +56 -56
- package/server/routes/properties/funcs/setSettings.js +44 -44
- package/server/routes/properties/funcs/utils/dataInsert.js +26 -26
- package/server/routes/properties/index.mjs +26 -26
- package/server/routes/root.mjs +3 -3
- package/server/routes/templates/controllers/getTemplate.js +14 -14
- package/server/routes/templates/index.mjs +14 -14
- package/server/templates/cls/itree.recrzone_category.json +73 -73
- package/server/templates/cls/test.json +9 -9
- package/server/templates/form/admin.user_cls.data.form.json +49 -49
- package/server/templates/form/admin.user_group_rel.form.json +21 -21
- package/server/templates/form/cp_building.form.json +32 -32
- package/server/templates/form/form-user-pass.json +10 -10
- package/server/templates/form/form-user_group.json +39 -39
- package/server/templates/form/form-users.json +156 -156
- package/server/templates/form/user_group_access.form.json +22 -22
- package/server/templates/select/account_id.json +2 -2
- package/server/templates/table/gis.dataset.table.json +43 -43
- package/server/templates/table/management.user_group.table.json +112 -112
- package/server/templates/table/management.users.table.json +126 -126
- package/utils.js +8 -8
package/package.json
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@opengis/admin",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "This project Softpro Admin",
|
|
5
|
-
"main": "dist/admin.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"directories": {
|
|
8
|
-
"test": "test"
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"dist/*",
|
|
12
|
-
"module/*",
|
|
13
|
-
"server/*",
|
|
14
|
-
"plugin.js",
|
|
15
|
-
"utils.js",
|
|
16
|
-
"config.js"
|
|
17
|
-
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"test": "node --test test/**/*.test.js",
|
|
20
|
-
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
21
|
-
"build": "vite build",
|
|
22
|
-
"build-app": "cross-env APP=true vite build",
|
|
23
|
-
"admin": "cross-env NODE_ENV=admin npm run start",
|
|
24
|
-
"admin1": "cross-env NODE_ENV=admin1 npm run start",
|
|
25
|
-
"prod": "cross-env NODE_ENV=production npm run start",
|
|
26
|
-
"start": "node --watch-path=server server vite ",
|
|
27
|
-
"docs:dev": "vitepress dev docs",
|
|
28
|
-
"docs:build": "vitepress build docs",
|
|
29
|
-
"docs:preview": "vitepress preview docs"
|
|
30
|
-
},
|
|
31
|
-
"keywords": [],
|
|
32
|
-
"author": "Softpro",
|
|
33
|
-
"license": "ISC",
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@opengis/fastify-auth": "^1.0.35",
|
|
36
|
-
"@opengis/fastify-file": "^1.0.17",
|
|
37
|
-
"@opengis/fastify-table": "^1.1.27",
|
|
38
|
-
"@opengis/v3-core": "^0.1.105",
|
|
39
|
-
"@opengis/v3-filter": "^0.0.31",
|
|
40
|
-
"@tiptap/core": "^2.8.0",
|
|
41
|
-
"@tiptap/extension-mention": "^2.8.0",
|
|
42
|
-
"@tiptap/extension-placeholder": "^2.8.0",
|
|
43
|
-
"@tiptap/pm": "^2.8.0",
|
|
44
|
-
"@tiptap/starter-kit": "^2.8.0",
|
|
45
|
-
"@tiptap/suggestion": "^2.8.0",
|
|
46
|
-
"@tiptap/vue-3": "^2.8.0",
|
|
47
|
-
"@turf/turf": "^7.1.0",
|
|
48
|
-
"@vitejs/plugin-vue": "^5.0.4",
|
|
49
|
-
"close-with-grace": "^1.3.0",
|
|
50
|
-
"cross-env": "^7.0.3",
|
|
51
|
-
"fastify": "^4.26.1",
|
|
52
|
-
"fastify-plugin": "^4.0.0",
|
|
53
|
-
"maplibre-gl": "^4.7.0",
|
|
54
|
-
"moment": "^2.30.1",
|
|
55
|
-
"vite": "^5.1.4",
|
|
56
|
-
"vue": "^3.4.21",
|
|
57
|
-
"vue-router": "^4.3.0"
|
|
58
|
-
},
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"@panzoom/panzoom": "^4.5.1",
|
|
61
|
-
"@vue/eslint-config-typescript": "^12.0.0",
|
|
62
|
-
"eslint": "^8.49.0",
|
|
63
|
-
"eslint-config-airbnb": "^19.0.4",
|
|
64
|
-
"eslint-plugin-import": "^2.25.3",
|
|
65
|
-
"eslint-plugin-vue": "^9.17.0",
|
|
66
|
-
"markdown-it-abbr": "^2.0.0",
|
|
67
|
-
"mermaid": "^10.9.0",
|
|
68
|
-
"sass-embedded": "^1.79.1",
|
|
69
|
-
"vitepress": "^1.1.3",
|
|
70
|
-
"vitepress-plugin-mermaid": "^2.0.16",
|
|
71
|
-
"vitepress-plugin-tabs": "^0.5.0",
|
|
72
|
-
"vitepress-sidebar": "^1.22.0"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@opengis/admin",
|
|
3
|
+
"version": "0.1.39",
|
|
4
|
+
"description": "This project Softpro Admin",
|
|
5
|
+
"main": "dist/admin.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"directories": {
|
|
8
|
+
"test": "test"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/*",
|
|
12
|
+
"module/*",
|
|
13
|
+
"server/*",
|
|
14
|
+
"plugin.js",
|
|
15
|
+
"utils.js",
|
|
16
|
+
"config.js"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node --test test/**/*.test.js",
|
|
20
|
+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"build-app": "cross-env APP=true vite build",
|
|
23
|
+
"admin": "cross-env NODE_ENV=admin npm run start",
|
|
24
|
+
"admin1": "cross-env NODE_ENV=admin1 npm run start",
|
|
25
|
+
"prod": "cross-env NODE_ENV=production npm run start",
|
|
26
|
+
"start": "node --watch-path=server server vite ",
|
|
27
|
+
"docs:dev": "vitepress dev docs",
|
|
28
|
+
"docs:build": "vitepress build docs",
|
|
29
|
+
"docs:preview": "vitepress preview docs"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [],
|
|
32
|
+
"author": "Softpro",
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@opengis/fastify-auth": "^1.0.35",
|
|
36
|
+
"@opengis/fastify-file": "^1.0.17",
|
|
37
|
+
"@opengis/fastify-table": "^1.1.27",
|
|
38
|
+
"@opengis/v3-core": "^0.1.105",
|
|
39
|
+
"@opengis/v3-filter": "^0.0.31",
|
|
40
|
+
"@tiptap/core": "^2.8.0",
|
|
41
|
+
"@tiptap/extension-mention": "^2.8.0",
|
|
42
|
+
"@tiptap/extension-placeholder": "^2.8.0",
|
|
43
|
+
"@tiptap/pm": "^2.8.0",
|
|
44
|
+
"@tiptap/starter-kit": "^2.8.0",
|
|
45
|
+
"@tiptap/suggestion": "^2.8.0",
|
|
46
|
+
"@tiptap/vue-3": "^2.8.0",
|
|
47
|
+
"@turf/turf": "^7.1.0",
|
|
48
|
+
"@vitejs/plugin-vue": "^5.0.4",
|
|
49
|
+
"close-with-grace": "^1.3.0",
|
|
50
|
+
"cross-env": "^7.0.3",
|
|
51
|
+
"fastify": "^4.26.1",
|
|
52
|
+
"fastify-plugin": "^4.0.0",
|
|
53
|
+
"maplibre-gl": "^4.7.0",
|
|
54
|
+
"moment": "^2.30.1",
|
|
55
|
+
"vite": "^5.1.4",
|
|
56
|
+
"vue": "^3.4.21",
|
|
57
|
+
"vue-router": "^4.3.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@panzoom/panzoom": "^4.5.1",
|
|
61
|
+
"@vue/eslint-config-typescript": "^12.0.0",
|
|
62
|
+
"eslint": "^8.49.0",
|
|
63
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
64
|
+
"eslint-plugin-import": "^2.25.3",
|
|
65
|
+
"eslint-plugin-vue": "^9.17.0",
|
|
66
|
+
"markdown-it-abbr": "^2.0.0",
|
|
67
|
+
"mermaid": "^10.9.0",
|
|
68
|
+
"sass-embedded": "^1.79.1",
|
|
69
|
+
"vitepress": "^1.1.3",
|
|
70
|
+
"vitepress-plugin-mermaid": "^2.0.16",
|
|
71
|
+
"vitepress-plugin-tabs": "^0.5.0",
|
|
72
|
+
"vitepress-sidebar": "^1.22.0"
|
|
73
|
+
}
|
|
74
|
+
}
|
package/plugin.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import fp from 'fastify-plugin';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { getTemplatePath, getTemplate, pgClients } from '@opengis/fastify-table/utils.js';
|
|
5
|
-
|
|
6
|
-
import config from './config.js';
|
|
7
|
-
import getMenu from './server/routes/menu/controllers/getMenu.js';
|
|
8
|
-
|
|
9
|
-
config.prefix = config.prefix || '/api';
|
|
10
|
-
|
|
11
|
-
async function plugin(fastify, opts = config) {
|
|
12
|
-
// const prefix = config.prefix || '/api';
|
|
13
|
-
|
|
14
|
-
// core
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
fastify.register(import('./server/helpers/index.mjs'), opts);
|
|
18
|
-
// fastify.register(import('@opengis/fastify-auth'), config);
|
|
19
|
-
|
|
20
|
-
fastify.addHook('onListen', async () => {
|
|
21
|
-
const { client } = pgClients;
|
|
22
|
-
const json = await getMenu();
|
|
23
|
-
// insert interface list to db (user access management)
|
|
24
|
-
if (client?.pk?.['admin.routes'] && json?.length) {
|
|
25
|
-
const menuList = json.filter((el) => el?.menu?.length && el?.ua || el?.en || el?.name);
|
|
26
|
-
const interfaces = menuList.reduce((acc, curr) => { curr.menu.forEach((el) => acc.push(el.path)); return acc; }, []);
|
|
27
|
-
await client.query('update admin.routes set enabled=false where not array[route_id] <@ $1::text[]', [interfaces]);
|
|
28
|
-
|
|
29
|
-
const q = `insert into admin.menu(name, ord) values${
|
|
30
|
-
menuList.map((el, i) => `('${(el?.ua || el?.en || el?.name).replace(/'/g, '’')}', ${i}) `).join(',')
|
|
31
|
-
} on conflict (name) do update set ord=excluded.ord, enabled=true returning name, menu_id`;
|
|
32
|
-
const { rows = [] } = await client.query(q);
|
|
33
|
-
await client.query('update admin.menu set enabled=false where not array[menu_id] <@ $1::text[]', [rows.map((el) => el.menu_id)]);
|
|
34
|
-
|
|
35
|
-
const menus = rows.reduce((acc, curr) => Object.assign(acc, { [curr.menu_id]: menuList.find((item) => (item?.ua || item?.en || item?.name) === curr.name) }), {});
|
|
36
|
-
const values = Object.entries(menus).reduce((acc, curr) => { curr[1]?.menu?.forEach((el) => acc.push({ ...el, menuId: curr[0] })); return acc; }, []);
|
|
37
|
-
|
|
38
|
-
await Promise.all(values.filter((el) => el?.table).map(async (el) => Object.assign(el, { table: (await getTemplate('table', el.table))?.table || el.table })));
|
|
39
|
-
|
|
40
|
-
const q1 = `insert into admin.routes(route_id, alias, title, menu_id, table_name) values ${values.map((el) => `('${el.path}', '${el.path}', '${el.title}', '${el.menuId}', '${el.table}')`).join(',')}
|
|
41
|
-
on conflict (route_id) do update set menu_id=excluded.menu_id, title=excluded.title, enabled=true,
|
|
42
|
-
table_name=excluded.table_name returning route_id, table_name`;
|
|
43
|
-
try {
|
|
44
|
-
const { rowCount } = await client.query(q1);
|
|
45
|
-
console.log('interface insert ok', values, rowCount);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.log('interface insert error', values, q1, err);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
fastify.addHook('onListen', async () => {
|
|
53
|
-
const { client: pg } = pgClients;
|
|
54
|
-
const clsQuery = [];
|
|
55
|
-
if (!pg.pk?.['admin.cls']) return;
|
|
56
|
-
|
|
57
|
-
const selectList = await getTemplatePath('select');
|
|
58
|
-
const clsList = (await getTemplatePath('cls'))?.filter((el) => !(selectList?.map((el) => el?.[0]) || []).includes(el[0]));
|
|
59
|
-
const cls = (selectList || []).concat(clsList || [])
|
|
60
|
-
?.map((el) => ({ name: el[0], module: path.basename(path.dirname(path.dirname(el[1]))), type: { 'json': 'cls', 'sql': 'select' }[el[2]] }))
|
|
61
|
-
if (!cls?.length) return;
|
|
62
|
-
|
|
63
|
-
const dupes = cls.filter((el, idx, arr) => arr.map((item) => item.name).indexOf(el.name) !== idx);
|
|
64
|
-
console.log('cls insert skip dupes', dupes.map((el) => el.name));
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
await Promise.all(cls.filter((el, idx, arr) => arr.map((item) => item.name).indexOf(el.name) === idx).map(async (el) => {
|
|
68
|
-
const { name, module, type } = el;
|
|
69
|
-
const loadTemplate = await getTemplate(type, name);
|
|
70
|
-
console.log(name, type);
|
|
71
|
-
if (type === 'select') {
|
|
72
|
-
clsQuery.push(`insert into admin.cls(name,type,data,module) values('${name}','sql','${(loadTemplate?.sql || loadTemplate)?.replace(/'/g, "''")}', '${module?.replace(/'/g, "''")}')`);
|
|
73
|
-
} else if (type === 'cls' && loadTemplate?.length) {
|
|
74
|
-
clsQuery.push(`insert into admin.cls(name,type, module) values('${name}','json', '${module?.replace(/'/g, "''")}');
|
|
75
|
-
insert into admin.cls(code,name,parent,icon)
|
|
76
|
-
select value->>'id',value->>'text','${name}',value->>'icon'
|
|
77
|
-
from json_array_elements('${JSON.stringify(loadTemplate).replace(/'/g, "''")}'::json)`);
|
|
78
|
-
} else {
|
|
79
|
-
console.log(name, type, 'empty');
|
|
80
|
-
}
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
await pg.query('truncate admin.cls');
|
|
84
|
-
if (clsQuery.filter((el) => el).length) {
|
|
85
|
-
await pg.query(clsQuery.filter((el) => el).join(';'));
|
|
86
|
-
console.log('cls insert ok', clsQuery?.length);
|
|
87
|
-
}
|
|
88
|
-
} catch (err) {
|
|
89
|
-
console.error('cls insert error', err.toString());
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// API
|
|
95
|
-
|
|
96
|
-
fastify.register(import('./server/routes/properties/index.mjs'), opts);
|
|
97
|
-
fastify.register(import('./server/routes/templates/index.mjs'), opts);
|
|
98
|
-
fastify.register(import('./server/routes/menu/index.mjs'), opts);
|
|
99
|
-
fastify.register(import('./server/routes/data/index.mjs'), opts);
|
|
100
|
-
|
|
101
|
-
}
|
|
1
|
+
import fp from 'fastify-plugin';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { getTemplatePath, getTemplate, pgClients } from '@opengis/fastify-table/utils.js';
|
|
5
|
+
|
|
6
|
+
import config from './config.js';
|
|
7
|
+
import getMenu from './server/routes/menu/controllers/getMenu.js';
|
|
8
|
+
|
|
9
|
+
config.prefix = config.prefix || '/api';
|
|
10
|
+
|
|
11
|
+
async function plugin(fastify, opts = config) {
|
|
12
|
+
// const prefix = config.prefix || '/api';
|
|
13
|
+
|
|
14
|
+
// core
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
fastify.register(import('./server/helpers/index.mjs'), opts);
|
|
18
|
+
// fastify.register(import('@opengis/fastify-auth'), config);
|
|
19
|
+
|
|
20
|
+
fastify.addHook('onListen', async () => {
|
|
21
|
+
const { client } = pgClients;
|
|
22
|
+
const json = await getMenu();
|
|
23
|
+
// insert interface list to db (user access management)
|
|
24
|
+
if (client?.pk?.['admin.routes'] && json?.length) {
|
|
25
|
+
const menuList = json.filter((el) => el?.menu?.length && el?.ua || el?.en || el?.name);
|
|
26
|
+
const interfaces = menuList.reduce((acc, curr) => { curr.menu.forEach((el) => acc.push(el.path)); return acc; }, []);
|
|
27
|
+
await client.query('update admin.routes set enabled=false where not array[route_id] <@ $1::text[]', [interfaces]);
|
|
28
|
+
|
|
29
|
+
const q = `insert into admin.menu(name, ord) values${
|
|
30
|
+
menuList.map((el, i) => `('${(el?.ua || el?.en || el?.name).replace(/'/g, '’')}', ${i}) `).join(',')
|
|
31
|
+
} on conflict (name) do update set ord=excluded.ord, enabled=true returning name, menu_id`;
|
|
32
|
+
const { rows = [] } = await client.query(q);
|
|
33
|
+
await client.query('update admin.menu set enabled=false where not array[menu_id] <@ $1::text[]', [rows.map((el) => el.menu_id)]);
|
|
34
|
+
|
|
35
|
+
const menus = rows.reduce((acc, curr) => Object.assign(acc, { [curr.menu_id]: menuList.find((item) => (item?.ua || item?.en || item?.name) === curr.name) }), {});
|
|
36
|
+
const values = Object.entries(menus).reduce((acc, curr) => { curr[1]?.menu?.forEach((el) => acc.push({ ...el, menuId: curr[0] })); return acc; }, []);
|
|
37
|
+
|
|
38
|
+
await Promise.all(values.filter((el) => el?.table).map(async (el) => Object.assign(el, { table: (await getTemplate('table', el.table))?.table || el.table })));
|
|
39
|
+
|
|
40
|
+
const q1 = `insert into admin.routes(route_id, alias, title, menu_id, table_name) values ${values.map((el) => `('${el.path}', '${el.path}', '${el.title}', '${el.menuId}', '${el.table}')`).join(',')}
|
|
41
|
+
on conflict (route_id) do update set menu_id=excluded.menu_id, title=excluded.title, enabled=true,
|
|
42
|
+
table_name=excluded.table_name returning route_id, table_name`;
|
|
43
|
+
try {
|
|
44
|
+
const { rowCount } = await client.query(q1);
|
|
45
|
+
console.log('interface insert ok', values, rowCount);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.log('interface insert error', values, q1, err);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
fastify.addHook('onListen', async () => {
|
|
53
|
+
const { client: pg } = pgClients;
|
|
54
|
+
const clsQuery = [];
|
|
55
|
+
if (!pg.pk?.['admin.cls']) return;
|
|
56
|
+
|
|
57
|
+
const selectList = await getTemplatePath('select');
|
|
58
|
+
const clsList = (await getTemplatePath('cls'))?.filter((el) => !(selectList?.map((el) => el?.[0]) || []).includes(el[0]));
|
|
59
|
+
const cls = (selectList || []).concat(clsList || [])
|
|
60
|
+
?.map((el) => ({ name: el[0], module: path.basename(path.dirname(path.dirname(el[1]))), type: { 'json': 'cls', 'sql': 'select' }[el[2]] }))
|
|
61
|
+
if (!cls?.length) return;
|
|
62
|
+
|
|
63
|
+
const dupes = cls.filter((el, idx, arr) => arr.map((item) => item.name).indexOf(el.name) !== idx);
|
|
64
|
+
console.log('cls insert skip dupes', dupes.map((el) => el.name));
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
await Promise.all(cls.filter((el, idx, arr) => arr.map((item) => item.name).indexOf(el.name) === idx).map(async (el) => {
|
|
68
|
+
const { name, module, type } = el;
|
|
69
|
+
const loadTemplate = await getTemplate(type, name);
|
|
70
|
+
console.log(name, type);
|
|
71
|
+
if (type === 'select') {
|
|
72
|
+
clsQuery.push(`insert into admin.cls(name,type,data,module) values('${name}','sql','${(loadTemplate?.sql || loadTemplate)?.replace(/'/g, "''")}', '${module?.replace(/'/g, "''")}')`);
|
|
73
|
+
} else if (type === 'cls' && loadTemplate?.length) {
|
|
74
|
+
clsQuery.push(`insert into admin.cls(name,type, module) values('${name}','json', '${module?.replace(/'/g, "''")}');
|
|
75
|
+
insert into admin.cls(code,name,parent,icon)
|
|
76
|
+
select value->>'id',value->>'text','${name}',value->>'icon'
|
|
77
|
+
from json_array_elements('${JSON.stringify(loadTemplate).replace(/'/g, "''")}'::json)`);
|
|
78
|
+
} else {
|
|
79
|
+
console.log(name, type, 'empty');
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
await pg.query('truncate admin.cls');
|
|
84
|
+
if (clsQuery.filter((el) => el).length) {
|
|
85
|
+
await pg.query(clsQuery.filter((el) => el).join(';'));
|
|
86
|
+
console.log('cls insert ok', clsQuery?.length);
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
console.error('cls insert error', err.toString());
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// API
|
|
95
|
+
|
|
96
|
+
fastify.register(import('./server/routes/properties/index.mjs'), opts);
|
|
97
|
+
fastify.register(import('./server/routes/templates/index.mjs'), opts);
|
|
98
|
+
fastify.register(import('./server/routes/menu/index.mjs'), opts);
|
|
99
|
+
fastify.register(import('./server/routes/data/index.mjs'), opts);
|
|
100
|
+
|
|
101
|
+
}
|
|
102
102
|
export default fp(plugin)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export default async function badge(data, options = {}) {
|
|
2
|
-
if (!data) return '-';
|
|
3
|
-
//const cls = await getSelect(options.data, { val: data, full: 1 });
|
|
4
|
-
|
|
5
|
-
return data;
|
|
6
|
-
/*const html = cls?.map((el) => {
|
|
7
|
-
const color = bscolor[el.color] || el.color || '#aaa';
|
|
8
|
-
return `<span class="el-tag el-tag--mini" style="color:${color || '#aaa'};border-color:${color || '#aaa'};background:unset;">
|
|
9
|
-
${funcs.locale(el.id, { lang: root.lang, prefix: opt.data, type: 'cls' }) || el.text}</span>`;
|
|
10
|
-
}).join(', ');
|
|
11
|
-
return html;*/
|
|
1
|
+
export default async function badge(data, options = {}) {
|
|
2
|
+
if (!data) return '-';
|
|
3
|
+
//const cls = await getSelect(options.data, { val: data, full: 1 });
|
|
4
|
+
|
|
5
|
+
return data;
|
|
6
|
+
/*const html = cls?.map((el) => {
|
|
7
|
+
const color = bscolor[el.color] || el.color || '#aaa';
|
|
8
|
+
return `<span class="el-tag el-tag--mini" style="color:${color || '#aaa'};border-color:${color || '#aaa'};background:unset;">
|
|
9
|
+
${funcs.locale(el.id, { lang: root.lang, prefix: opt.data, type: 'cls' }) || el.text}</span>`;
|
|
10
|
+
}).join(', ');
|
|
11
|
+
return html;*/
|
|
12
12
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default async function _hb() {
|
|
2
|
-
return '';
|
|
1
|
+
export default async function _hb() {
|
|
2
|
+
return '';
|
|
3
3
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default async function map() {
|
|
2
|
-
return '';
|
|
1
|
+
export default async function map() {
|
|
2
|
+
return '';
|
|
3
3
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default async function _mls(data, options={}) {
|
|
2
|
-
return data.hash?.ua || options?.hash?.ua || '';
|
|
1
|
+
export default async function _mls(data, options={}) {
|
|
2
|
+
return data.hash?.ua || options?.hash?.ua || '';
|
|
3
3
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default async function _vue() {
|
|
2
|
-
return '';
|
|
1
|
+
export default async function _vue() {
|
|
2
|
+
return '';
|
|
3
3
|
}
|
package/server/helpers/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import _hb from "./controllers/hb.js";
|
|
2
|
-
import _vue from "./controllers/vue.js";
|
|
3
|
-
import map from "./controllers/map.js";
|
|
4
|
-
import _mls from "./controllers/mls.js";
|
|
5
|
-
import badge from "./controllers/badge.js";
|
|
6
|
-
|
|
7
|
-
export default async function route(fastify) {
|
|
8
|
-
fastify.handlebars.registerHelper('_hb', _hb);
|
|
9
|
-
fastify.handlebars.registerHelper('_vue', _vue);
|
|
10
|
-
fastify.handlebars.registerHelper('map', map);
|
|
11
|
-
fastify.handlebars.registerHelper('mls', _mls);
|
|
12
|
-
fastify.handlebars.registerHelper('badge', badge);
|
|
13
|
-
}
|
|
1
|
+
import _hb from "./controllers/hb.js";
|
|
2
|
+
import _vue from "./controllers/vue.js";
|
|
3
|
+
import map from "./controllers/map.js";
|
|
4
|
+
import _mls from "./controllers/mls.js";
|
|
5
|
+
import badge from "./controllers/badge.js";
|
|
6
|
+
|
|
7
|
+
export default async function route(fastify) {
|
|
8
|
+
fastify.handlebars.registerHelper('_hb', _hb);
|
|
9
|
+
fastify.handlebars.registerHelper('_vue', _vue);
|
|
10
|
+
fastify.handlebars.registerHelper('map', map);
|
|
11
|
+
fastify.handlebars.registerHelper('mls', _mls);
|
|
12
|
+
fastify.handlebars.registerHelper('badge', badge);
|
|
13
|
+
}
|
package/server/plugins/docs.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import path, { dirname } from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
|
|
7
|
-
const dir = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const root = `${dir}/../../`;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async function plugin(fastify, opts) {
|
|
12
|
-
fastify.get('/docs*', async (req, reply) => {
|
|
13
|
-
if (!fs.existsSync(path.join(root, 'docs/.vitepress/dist/'))) {
|
|
14
|
-
return reply.status(404).send('docs not exists');
|
|
15
|
-
}
|
|
16
|
-
const { params } = req;
|
|
17
|
-
const url = params['*']
|
|
18
|
-
const filePath = url && url[url.length - 1] !== '/' ? path.join(root, 'docs/.vitepress/dist/', url) : path.join(root, 'docs/.vitepress/dist/', url, 'index.html')
|
|
19
|
-
const ext = path.extname(filePath);
|
|
20
|
-
const mime = {
|
|
21
|
-
'.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg'
|
|
22
|
-
}[ext];
|
|
23
|
-
const stream = fs.createReadStream(filePath);
|
|
24
|
-
return mime ? reply.type(mime).send(stream) : stream;
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
export default plugin;
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import path, { dirname } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
|
|
7
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const root = `${dir}/../../`;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async function plugin(fastify, opts) {
|
|
12
|
+
fastify.get('/docs*', async (req, reply) => {
|
|
13
|
+
if (!fs.existsSync(path.join(root, 'docs/.vitepress/dist/'))) {
|
|
14
|
+
return reply.status(404).send('docs not exists');
|
|
15
|
+
}
|
|
16
|
+
const { params } = req;
|
|
17
|
+
const url = params['*']
|
|
18
|
+
const filePath = url && url[url.length - 1] !== '/' ? path.join(root, 'docs/.vitepress/dist/', url) : path.join(root, 'docs/.vitepress/dist/', url, 'index.html')
|
|
19
|
+
const ext = path.extname(filePath);
|
|
20
|
+
const mime = {
|
|
21
|
+
'.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg'
|
|
22
|
+
}[ext];
|
|
23
|
+
const stream = fs.createReadStream(filePath);
|
|
24
|
+
return mime ? reply.type(mime).send(stream) : stream;
|
|
25
|
+
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
export default plugin;
|