@opengis/admin 0.2.131 → 0.2.133
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/add-page-DQ70Si9f.js +104 -0
- package/dist/{admin-interface-CFR2WRun.js → admin-interface-CgXFerXl.js} +348 -323
- package/dist/{admin-view-CE-4P8V-.js → admin-view-t-gzhVnl.js} +231 -291
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +82 -82
- package/dist/{card-view-BbBU9cWN.js → card-view-Dtf6Ap9G.js} +1 -1
- package/dist/edit-page-BWRXfML4.js +125 -0
- package/dist/{import-file-C1vBdCEv.js → import-file-CztGvKRc.js} +25610 -26789
- package/dist/style.css +1 -1
- package/package.json +5 -5
- package/server/helpers/list/utils/button.js +5 -5
- package/server/routes/data/controllers/utils/conditions.js +20 -20
- package/server/routes/menu/controllers/getMenu.js +11 -3
- package/server/routes/menu/controllers/interfaces.js +19 -0
- package/server/routes/menu/index.mjs +2 -0
- package/server/routes/print/controllers/printTemplate.js +4 -3
- package/server/routes/print/controllers/printTemplatePreview.js +15 -9
- package/server/routes/properties/controllers/admin.properties.get.js +6 -8
- package/server/routes/properties/controllers/admin.properties.post.js +28 -7
- package/server/routes/properties/controllers/user.properties.get.js +2 -13
- package/server/routes/properties/controllers/user.properties.post.js +2 -22
- package/server/routes/properties/index.mjs +4 -4
- package/server/routes/properties/utils/refreshData.js +4 -4
- package/utils.js +2 -5
- package/dist/add-page-B5Yx_gil.js +0 -119
- package/dist/edit-page-D3q9Dp_D.js +0 -138
- package/dist/profile-page-CVV-ZW1M.js +0 -78
- package/dist/user-B_2kh6ic.js +0 -5
- package/module/settings/setting/test.json +0 -6
- package/server/routes/properties/funcs/getSettings.js +0 -56
- package/server/routes/properties/funcs/setSettings.js +0 -44
@@ -1,21 +1,21 @@
|
|
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
|
-
|
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
21
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
import { join } from 'path';
|
3
|
-
import { userTemplateDir,
|
3
|
+
import { userTemplateDir, pgClients, applyHook, config } from '@opengis/fastify-table/utils.js';
|
4
4
|
|
5
5
|
import { existsSync, readdirSync, readFileSync } from 'fs';
|
6
6
|
const menuCache = [];
|
@@ -30,11 +30,17 @@ async function readMenu() {
|
|
30
30
|
return menus;
|
31
31
|
}
|
32
32
|
export default async function adminMenu({ user = {}, session, pg = pgClients.client }) {
|
33
|
+
const time = Date.now();
|
33
34
|
if (!user.uid) return { status: 403, message: 'access restricted' }
|
34
35
|
|
35
36
|
const menus = isProduction && menuCache.length ? menuCache : await readMenu();
|
36
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 }, {});
|
37
40
|
// update user access
|
41
|
+
const { user_name, sur_name, father_name, email, phone, uid } = user;
|
42
|
+
const result = { settings, user: { uid, user_name, sur_name, father_name, email, phone } };
|
43
|
+
await applyHook('userMenu', result);
|
38
44
|
|
39
45
|
if (session && user?.uid && !user.user_type?.includes?.('admin') && !user.type?.includes?.('admin') && pg.pk['admin.role_access']) {
|
40
46
|
const { type, gl = [], routes = [] } = await pg.query(`select user_type as type, b.gl,routes from admin.users a
|
@@ -54,13 +60,15 @@ export default async function adminMenu({ user = {}, session, pg = pgClients.cli
|
|
54
60
|
session?.set?.('passport', { user });
|
55
61
|
if (type === 'admin') return menus;
|
56
62
|
const userMenus = menus.map(el => (el.menu ? { ...el, menu: el.menu.filter(item => routes?.includes(item.path)) } : el))
|
57
|
-
|
63
|
+
const menus = userMenus.filter(el => el.menu?.length || routes?.includes(el.path));
|
64
|
+
return { time: Date.now() - time, menus, ...result }
|
58
65
|
// .filter((el, idx, arr) => arr.map((el) => el?.ua || el?.en || el?.name).indexOf(el?.ua || el?.en || el?.name) === idx)
|
59
66
|
}
|
60
67
|
|
61
68
|
// skip dupes?
|
62
69
|
// .filter((el, idx, arr) => arr.map((el) => el?.ua || el?.en || el?.name).indexOf(el?.ua || el?.en || el?.name) === idx)
|
63
|
-
|
70
|
+
|
71
|
+
return { time: Date.now() - time, menus, ...result };
|
64
72
|
|
65
73
|
|
66
74
|
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { pgClients } 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
|
+
return interfaces;
|
19
|
+
}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import getMenu from './controllers/getMenu.js';
|
2
|
+
import interfaces from './controllers/interfaces.js';
|
2
3
|
|
3
4
|
export default async function (fastify, opts) {
|
4
5
|
fastify.get(`/user-menu`, getMenu);
|
6
|
+
fastify.get(`/interfaces`, { config: { policy: ['admin'] } }, interfaces);
|
5
7
|
}
|
@@ -48,13 +48,14 @@ export default async function printTemplate(req, reply) {
|
|
48
48
|
const loadTable = await getTemplate('table', table);
|
49
49
|
const { optimizedSQL } = await getFilterSQL({ table, pg });
|
50
50
|
|
51
|
-
const where = `${loadTable?.key || pg.pk?.[loadTable?.table || table]}
|
51
|
+
const where = `${loadTable?.key || pg.pk?.[loadTable?.table || table]}=any($1::text[])`;
|
52
52
|
|
53
53
|
const q = `select * from (${optimizedSQL})q where ${loadTable?.query || '1=1'} and ${where}`;
|
54
54
|
|
55
|
-
const
|
55
|
+
const { rows = [] } = await pg.query(q, [params.id.split(',')]);
|
56
56
|
|
57
|
-
const
|
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;"> </p>');
|
58
59
|
|
59
60
|
if (format == 'html') {
|
60
61
|
return reply.headers(headers).send(html);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createHash } from 'node:crypto';
|
2
2
|
|
3
|
-
import { config, getFilterSQL, getTemplate, handlebars, pgClients } from '@opengis/fastify-table/utils.js';
|
3
|
+
import { config, getFilterSQL, getTemplate, handlebars, pgClients, getMeta } from '@opengis/fastify-table/utils.js';
|
4
4
|
import { grpc } from '@opengis/fastify-file/utils.js';
|
5
5
|
|
6
6
|
const { htmlToPdf } = grpc();
|
@@ -50,17 +50,21 @@ export default async function printTemplate(req, reply) {
|
|
50
50
|
return reply.headers(headers).send(buffer);
|
51
51
|
}
|
52
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
|
+
|
53
60
|
if (query?.demo) {
|
54
|
-
const
|
55
|
-
|
61
|
+
const loadTable = await getTemplate('table', alias);
|
62
|
+
const { optimizedSQL } = await getFilterSQL({ pg, table: alias });
|
56
63
|
|
57
|
-
if (!
|
58
|
-
return reply.status(
|
64
|
+
if (!optimizedSQL) {
|
65
|
+
return reply.status(400).send('empty query');
|
59
66
|
}
|
60
67
|
|
61
|
-
const loadTable = await getTemplate('table', table);
|
62
|
-
const { optimizedSQL } = await getFilterSQL({ table, pg });
|
63
|
-
|
64
68
|
const q = `select * from (${optimizedSQL})q where ${loadTable?.query || '1=1'} limit 1`;
|
65
69
|
|
66
70
|
const obj = await pg.query(q).then(el => el.rows?.[0] || {});
|
@@ -76,6 +80,8 @@ export default async function printTemplate(req, reply) {
|
|
76
80
|
return reply.headers(headers).send(buffer);
|
77
81
|
}
|
78
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' }));
|
79
85
|
// for body edit
|
80
|
-
return { name, title, html: body, route };
|
86
|
+
return { name, title, html: body, route, alias, table, columns };
|
81
87
|
}
|
@@ -1,13 +1,11 @@
|
|
1
1
|
const table = 'admin.properties';
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { pgClients, getTemplatePath, getTemplate } from '@opengis/fastify-table/utils.js';
|
4
4
|
|
5
|
-
import { getSettings } from '../../../../utils.js';
|
6
5
|
|
7
|
-
const redis = getRedis();
|
8
6
|
|
9
7
|
export default async function getSettingsApp({
|
10
|
-
pg = pgClients.client,
|
8
|
+
pg = pgClients.client,
|
11
9
|
}) {
|
12
10
|
const time = Date.now();
|
13
11
|
if (!pg.pk?.[table]) {
|
@@ -21,13 +19,13 @@ export default async function getSettingsApp({
|
|
21
19
|
return JSON.parse(cache);
|
22
20
|
}*/
|
23
21
|
|
24
|
-
const
|
25
|
-
|
26
|
-
});
|
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 }), {});
|
27
25
|
|
28
26
|
const forms = await Promise.all(getTemplatePath('setting')
|
29
27
|
.map(async (el) => ({ name: el[0], body: await getTemplate('setting', el[0]) }))
|
30
28
|
);
|
31
29
|
|
32
|
-
return { message: { time: Date.now() - time, forms, settings }, status: 200 };
|
30
|
+
return { message: { time: Date.now() - time, forms, settings: settings1 }, status: 200 };
|
33
31
|
}
|
@@ -1,9 +1,21 @@
|
|
1
1
|
const table = 'admin.properties';
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { dataInsert } from '@opengis/fastify-table/utils.js';
|
4
|
+
|
5
|
+
function checkValueType(val) {
|
6
|
+
if (val) {
|
7
|
+
if (typeof val === 'object') {
|
8
|
+
return 'property_json';
|
9
|
+
}
|
10
|
+
if (typeof val === 'number' && (!/\D/.test(val.toString()) && val.toString().length < 10)) {
|
11
|
+
return 'property_int';
|
12
|
+
}
|
13
|
+
}
|
14
|
+
return 'property_text';
|
15
|
+
}
|
4
16
|
|
5
17
|
export default async function postSettingsApp({
|
6
|
-
pg, user = {}, body = {},
|
18
|
+
pg, user = {}, body = {}, uid
|
7
19
|
}) {
|
8
20
|
if (!user?.user_type?.includes?.('admin')) {
|
9
21
|
return { message: 'access restricted', status: 403 };
|
@@ -16,11 +28,20 @@ export default async function postSettingsApp({
|
|
16
28
|
if (!pg?.pk?.[table]) {
|
17
29
|
return { message: 'table not found', status: 404 };
|
18
30
|
}
|
31
|
+
const keys = Object.keys(body);
|
32
|
+
await pg.query(`delete from ${table} where property_key=any($1)`, [keys]);
|
33
|
+
|
34
|
+
await Promise.all(keys.map(async (el) => {
|
35
|
+
const columnType = table === 'admin.user_properties' ? 'property_json' : checkValueType(body[el]);
|
36
|
+
const data = { property_key: el, [columnType]: body[el], uid };
|
37
|
+
if (!body[el]) return;
|
38
|
+
await dataInsert({
|
39
|
+
pg, table, data, uid,
|
40
|
+
});
|
41
|
+
|
42
|
+
}));
|
43
|
+
|
19
44
|
|
20
|
-
const res = await setSettings({
|
21
|
-
pg, key, val, body,
|
22
|
-
});
|
23
|
-
if (res?.error) return res;
|
24
45
|
|
25
|
-
return { message:
|
46
|
+
return { message: 'ok', status: 200 };
|
26
47
|
}
|
@@ -1,11 +1,8 @@
|
|
1
1
|
const table = 'admin.user_properties';
|
2
2
|
|
3
|
-
import { getRedis } from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
import { getSettings } from '../../../../utils.js';
|
6
3
|
|
7
4
|
export default async function getSettingsUser({
|
8
|
-
pg = {},
|
5
|
+
pg = {}, session = {},
|
9
6
|
}) {
|
10
7
|
const { uid } = session.passport?.user || {};
|
11
8
|
if (!uid) {
|
@@ -16,15 +13,7 @@ export default async function getSettingsUser({
|
|
16
13
|
return { message: 'table not found', status: 404 };
|
17
14
|
}
|
18
15
|
|
19
|
-
const redis = getRedis();
|
20
|
-
const keyCache = `${pg.options?.database}:settings:${params?.key || 'all'}:${query?.json ? 'json' : 'plain'}:user`;
|
21
|
-
|
22
|
-
const cache = await redis.get(keyCache);
|
23
|
-
if (cache) return JSON.parse(cache);
|
24
16
|
|
25
|
-
const res = await getSettings({
|
26
|
-
pg, key: params.key, json: query.json, redis, table, uid,
|
27
|
-
});
|
28
17
|
|
29
|
-
return { message:
|
18
|
+
return { message: 'user', status: 200 };
|
30
19
|
}
|
@@ -1,30 +1,10 @@
|
|
1
1
|
const table = 'admin.user_properties';
|
2
2
|
|
3
|
-
|
3
|
+
|
4
4
|
|
5
5
|
export default async function postSettingsUser({
|
6
6
|
pg, session = {}, body = {},
|
7
7
|
}) {
|
8
|
-
const { uid } = session.passport?.user || {};
|
9
|
-
|
10
|
-
if (!uid) {
|
11
|
-
return { message: 'access restricted', status: 403 };
|
12
|
-
}
|
13
|
-
|
14
|
-
const { key, val } = body;
|
15
|
-
|
16
|
-
if ((!key || !val) && !Object.keys(body).length) {
|
17
|
-
return { message: 'not enough params', status: 400 };
|
18
|
-
}
|
19
|
-
|
20
|
-
if (!pg?.pk?.[table]) {
|
21
|
-
return { message: 'table not found', status: 404 };
|
22
|
-
}
|
23
|
-
|
24
|
-
const res = await setSettings({
|
25
|
-
pg, key, val, body, table, uid,
|
26
|
-
});
|
27
|
-
if (res?.error) return res;
|
28
8
|
|
29
|
-
return { message:
|
9
|
+
return { message: 'ok', status: 200 };
|
30
10
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import getSettingsApp from './controllers/admin.properties.get.js';
|
2
2
|
import postSettingsApp from './controllers/admin.properties.post.js';
|
3
3
|
|
4
|
-
import getSettingsUser from './controllers/user.properties.get.js';
|
5
|
-
import postSettingsUser from './controllers/user.properties.post.js';
|
4
|
+
//import getSettingsUser from './controllers/user.properties.get.js';
|
5
|
+
//import postSettingsUser from './controllers/user.properties.post.js';
|
6
6
|
|
7
7
|
import getSettingsTable from './controllers/table.properties.get.js';
|
8
8
|
import postSettingsTable from './controllers/table.properties.post.js';
|
@@ -13,8 +13,8 @@ export default async function route(fastify) {
|
|
13
13
|
fastify.get('/settings-app/:key?', { scheme: propertiesSchema }, getSettingsApp);
|
14
14
|
fastify.post('/settings-app', { config: { policy: ['admin'] } }, postSettingsApp);
|
15
15
|
|
16
|
-
fastify.get('/settings-user/:key?', { scheme: propertiesSchema }, getSettingsUser);
|
17
|
-
fastify.post('/settings-user', {}, postSettingsUser);
|
16
|
+
//fastify.get('/settings-user/:key?', { scheme: propertiesSchema }, getSettingsUser);
|
17
|
+
// fastify.post('/settings-user', {}, postSettingsUser);
|
18
18
|
|
19
19
|
fastify.get('/settings-table/:table/:entity?', {}, getSettingsTable);
|
20
20
|
fastify.post('/settings-table/:table', {}, postSettingsTable);
|
@@ -6,7 +6,7 @@ function prepareResult(res) {
|
|
6
6
|
const arr = (res.rows || (Array.isArray(res) ? res : Object.values(res || {})));
|
7
7
|
return {
|
8
8
|
command: 'INSERT',
|
9
|
-
count: arr.filter((el) => el.command === 'INSERT')
|
9
|
+
count: res?.rowCount || arr.filter((el) => el.command === 'INSERT')
|
10
10
|
?.map((el) => ({ result: 'success', count: el.rowCount }))
|
11
11
|
?.reduce((acc, curr) => acc + curr.count, 0),
|
12
12
|
};
|
@@ -37,13 +37,13 @@ export default async function refreshData({
|
|
37
37
|
data?.forEach((el) => Object.assign(el, { id: el.id || randomUUID() }));
|
38
38
|
await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
|
39
39
|
|
40
|
-
const res = dataInsert({
|
40
|
+
const res = await dataInsert({
|
41
41
|
pg: client,
|
42
42
|
table: 'setting.property',
|
43
43
|
data: {
|
44
44
|
property_entity: entity,
|
45
45
|
object_id: table,
|
46
|
-
property_json: JSON.stringify(data)?.replace(/'/g, "''")
|
46
|
+
property_json: JSON.stringify(data), // ?.replace(/'+/g, "'")?.replace(/'/g, "''")
|
47
47
|
},
|
48
48
|
uid,
|
49
49
|
});
|
@@ -103,7 +103,7 @@ export default async function refreshData({
|
|
103
103
|
await client.query('delete from setting.custom_field where $1 in (tablename, object_id)', [table]);
|
104
104
|
await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
|
105
105
|
|
106
|
-
const data2 = JSON.stringify(data1?.filter((value, index, array) => array.indexOf(value) === index))?.replace(/'/g, "''")
|
106
|
+
const data2 = JSON.stringify(data1?.filter((value, index, array) => array.indexOf(value) === index)); // ?.replace(/'+/g, "'")?.replace(/'/g, "''")
|
107
107
|
const res = await dataInsert({
|
108
108
|
pg: client,
|
109
109
|
table: 'setting.property',
|
package/utils.js
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
import yamlSafe from 'js-yaml';
|
2
2
|
|
3
|
-
|
4
|
-
import setSettings from './server/routes/properties/funcs/setSettings.js';
|
3
|
+
|
5
4
|
|
6
5
|
import addNotification from './server/routes/notifications/funcs/addNotification.js';
|
7
6
|
import sendNotification from './server/routes/notifications/funcs/sendNotification.js';
|
8
7
|
|
9
8
|
import getAdminAccess from './server/plugins/access/funcs/getAdminAccess.js';
|
10
9
|
|
11
|
-
function loadSafe
|
10
|
+
function loadSafe(yml) {
|
12
11
|
try {
|
13
12
|
return yamlSafe.load(yml);
|
14
13
|
} catch (err) {
|
@@ -21,8 +20,6 @@ Object.assign(yamlSafe, { loadSafe });
|
|
21
20
|
export default null;
|
22
21
|
export {
|
23
22
|
yamlSafe,
|
24
|
-
getSettings,
|
25
|
-
setSettings,
|
26
23
|
addNotification,
|
27
24
|
sendNotification,
|
28
25
|
getAdminAccess,
|
@@ -1,119 +0,0 @@
|
|
1
|
-
import { _ as h, u as p, e as u } from "./import-file-C1vBdCEv.js";
|
2
|
-
import { resolveComponent as d, openBlock as b, createElementBlock as g, createElementVNode as n, createBlock as f, normalizeStyle as x, createCommentVNode as w } from "vue";
|
3
|
-
const y = {
|
4
|
-
data() {
|
5
|
-
return {
|
6
|
-
formValues: {},
|
7
|
-
scheme: null,
|
8
|
-
table: "",
|
9
|
-
token: "",
|
10
|
-
api: "",
|
11
|
-
style: null
|
12
|
-
};
|
13
|
-
},
|
14
|
-
mounted() {
|
15
|
-
this.getFormScheme();
|
16
|
-
},
|
17
|
-
methods: {
|
18
|
-
flattenMenu(t) {
|
19
|
-
const e = [];
|
20
|
-
return t.forEach((o) => {
|
21
|
-
o.menu ? e.push(...this.flattenMenu(o.menu)) : e.push(o);
|
22
|
-
}), e;
|
23
|
-
},
|
24
|
-
async getFormScheme() {
|
25
|
-
var i, a;
|
26
|
-
const t = this.flattenMenu(p.value);
|
27
|
-
t != null && t.length || this.$router.replace("/404");
|
28
|
-
const e = t == null ? void 0 : t.find((r) => {
|
29
|
-
var s, l;
|
30
|
-
return (r == null ? void 0 : r.path) == ((l = (s = this.$route) == null ? void 0 : s.query) == null ? void 0 : l.table);
|
31
|
-
});
|
32
|
-
e || this.$router.replace("/404");
|
33
|
-
const o = e == null ? void 0 : e.table;
|
34
|
-
this.table = o;
|
35
|
-
try {
|
36
|
-
const r = await u.get(`/api/table-data/${o}`), { data: s } = await u.get(
|
37
|
-
`/api/template/form/${(i = r == null ? void 0 : r.data) == null ? void 0 : i.form}`
|
38
|
-
);
|
39
|
-
this.scheme = (s == null ? void 0 : s.schema) || s, this.style = (s == null ? void 0 : s.style) || null, this.api = (s == null ? void 0 : s.api) || "", this.token = (a = r == null ? void 0 : r.data) == null ? void 0 : a.addToken;
|
40
|
-
} catch {
|
41
|
-
}
|
42
|
-
},
|
43
|
-
getGroupedErrorNotification(t, e) {
|
44
|
-
debugger;
|
45
|
-
if (!t || !e) return "";
|
46
|
-
const o = {};
|
47
|
-
return Object.entries(t).forEach(([a, r]) => {
|
48
|
-
var l;
|
49
|
-
const s = ((l = e[a]) == null ? void 0 : l.ua) || a;
|
50
|
-
r.forEach((m) => {
|
51
|
-
const c = m.message;
|
52
|
-
o[c] || (o[c] = []), o[c].push(`"${s}"`);
|
53
|
-
});
|
54
|
-
}), Object.entries(o).map(([a, r]) => `<b>${a}:</b> ${r.join(", ")}`).join("<br>") || "Сталася помилка валідації";
|
55
|
-
},
|
56
|
-
async createObject() {
|
57
|
-
var e;
|
58
|
-
const t = this.$refs.form;
|
59
|
-
try {
|
60
|
-
await t.doValidation(), await u.post(
|
61
|
-
this.api || `/api/table/${this.token}`,
|
62
|
-
this.formValues
|
63
|
-
), await this.$router.back(), await this.$notify({
|
64
|
-
title: "Успішно!",
|
65
|
-
message: "Об'єкт успішно створено",
|
66
|
-
type: "success"
|
67
|
-
});
|
68
|
-
} catch (o) {
|
69
|
-
const i = this.getGroupedErrorNotification(
|
70
|
-
t == null ? void 0 : t.formErrors,
|
71
|
-
t == null ? void 0 : t.scheme
|
72
|
-
);
|
73
|
-
this.$notify({
|
74
|
-
title: "Помилка!",
|
75
|
-
message: ((e = o == null ? void 0 : o.response) == null ? void 0 : e.data) || i,
|
76
|
-
type: "error"
|
77
|
-
});
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
81
|
-
}, k = { class: "bg-gray-50 lg:w-[calc(100vw-260px)] w-[100vw]" }, v = { class: "h-[76px] mt-[15px] flex items-center justify-between mx-[20px] px-[20px] bg-white border rounded-xl" }, V = { class: "flex items-center gap-[6px]" }, _ = {
|
82
|
-
style: { height: "calc(100vh - 165px)" },
|
83
|
-
class: "bg-gray-50 p-[20px] flex lg:w-[calc(100vw-260px)] w-[100vw]"
|
84
|
-
}, $ = { class: "bg-white w-full rounded-xl border p-[20px] overflow-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar:horizontal]:h-[8px] [&::-webkit-scrollbar-track]:bg-gray-100 [&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-track]:bg-neutral-700 dark:[&::-webkit-scrollbar-thumb]:bg-neutral-500" };
|
85
|
-
function j(t, e, o, i, a, r) {
|
86
|
-
const s = d("VsForm");
|
87
|
-
return b(), g("div", k, [
|
88
|
-
n("div", v, [
|
89
|
-
e[3] || (e[3] = n("h2", { class: "text-xl font-medium" }, "Створити", -1)),
|
90
|
-
n("div", V, [
|
91
|
-
n("button", {
|
92
|
-
onClick: e[0] || (e[0] = (l) => t.$router.back()),
|
93
|
-
class: "flex items-center px-3 py-2 text-sm font-medium text-gray-800 duration-300 bg-white border border-gray-100 rounded-lg shadow gap-x-2 focus:outline-none hover:bg-gray-50 hover:border-gray-100"
|
94
|
-
}, " Скасувати "),
|
95
|
-
n("button", {
|
96
|
-
onClick: e[1] || (e[1] = (...l) => r.createObject && r.createObject(...l)),
|
97
|
-
class: "inline-flex items-center px-3 py-2 text-sm font-medium text-white duration-300 bg-blue-600 border border-transparent rounded-lg gap-x-2 hover:bg-blue-700 hover:text-white"
|
98
|
-
}, " Зберегти ")
|
99
|
-
])
|
100
|
-
]),
|
101
|
-
n("div", _, [
|
102
|
-
n("div", $, [
|
103
|
-
a.scheme ? (b(), f(s, {
|
104
|
-
key: 0,
|
105
|
-
ref: "form",
|
106
|
-
scheme: a.scheme,
|
107
|
-
style: x(a.style),
|
108
|
-
modelValue: a.formValues,
|
109
|
-
"onUpdate:modelValue": e[2] || (e[2] = (l) => a.formValues = l),
|
110
|
-
class: "p-0 mt-[20px]"
|
111
|
-
}, null, 8, ["scheme", "style", "modelValue"])) : w("", !0)
|
112
|
-
])
|
113
|
-
])
|
114
|
-
]);
|
115
|
-
}
|
116
|
-
const O = /* @__PURE__ */ h(y, [["render", j]]);
|
117
|
-
export {
|
118
|
-
O as default
|
119
|
-
};
|