@opengis/admin 0.2.86 → 0.2.88

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 (24) hide show
  1. package/dist/{add-page-D1o3UElp.js → add-page-2HtfoXYW.js} +1 -1
  2. package/dist/{admin-interface-CX9gUQPl.js → admin-interface-BPr6jXSM.js} +714 -570
  3. package/dist/{admin-view-BItQEdb1.js → admin-view-CQ3W9LX4.js} +1 -1
  4. package/dist/admin.js +1 -1
  5. package/dist/admin.umd.cjs +55 -55
  6. package/dist/{card-view-CXouK5bH.js → card-view-zTn40qzk.js} +1 -1
  7. package/dist/{edit-page-UiEicOwd.js → edit-page-Bd3RRgti.js} +1 -1
  8. package/dist/{import-file-CrwXBa6w.js → import-file-BRBKwVL4.js} +12854 -12514
  9. package/dist/style.css +1 -1
  10. package/module/settings/menu.json +63 -59
  11. package/package.json +2 -2
  12. package/server/routes/properties/controllers/admin.properties.get.js +17 -14
  13. package/server/routes/properties/controllers/admin.properties.post.js +1 -1
  14. package/server/routes/properties/controllers/table.properties.get.js +120 -0
  15. package/server/routes/properties/controllers/table.properties.post.js +115 -0
  16. package/server/routes/properties/controllers/user.properties.get.js +2 -2
  17. package/server/routes/properties/controllers/user.properties.post.js +1 -1
  18. package/server/routes/properties/funcs/setSettings.js +1 -1
  19. package/server/routes/properties/index.mjs +15 -8
  20. package/server/routes/properties/utils/getColumnMetaData.js +17 -0
  21. package/server/routes/properties/utils/refreshData.js +128 -0
  22. package/server/routes/widget/controllers/widget.get.js +2 -1
  23. package/server/templates/setting/test.json +20 -0
  24. /package/server/routes/properties/{funcs/utils → utils}/dataInsert.js +0 -0
@@ -1,60 +1,64 @@
1
1
  [
2
- {
3
- "ua": "Доступ",
4
- "en": "Management",
5
- "name": "administration",
6
- "icon": "IconLockCode",
7
- "order": 9,
8
- "menu": [
9
- {
10
- "path": "admin.users",
11
- "table": "admin.users.table",
12
- "ua": "Користувачі",
13
- "en": "Users"
14
- },
15
- {
16
- "path": "admin.roles",
17
- "table": "admin.roles.table",
18
- "ua": "Ролі/Групи",
19
- "en": "Roles"
20
- },
21
- {
22
- "path": "admin.routes",
23
- "table": "admin.routes.table",
24
- "ua": "Інтерфейси",
25
- "en": "Routes"
26
- },
27
- {
28
- "path": "auth.logs",
29
- "table": "auth.logs.table",
30
- "ua": "Логи інтерфейсів"
31
- }
32
- ]
33
- },
34
- {
35
- "ua": "Управління",
36
- "en": "Management",
37
- "name": "administration",
38
- "order": 10,
39
- "icon": "IconSettingsCog",
40
- "menu": [
41
- {
42
- "path": "admin.user-cls",
43
- "ua": "Довідники ",
44
- "component": "user-cls-page"
45
- },
46
- {
47
- "path": "admin.properties",
48
- "table": "admin.properties.table",
49
- "ua": "Налаштування",
50
- "en": "Settings"
51
- },
52
- {
53
- "path": "admin.table_properties",
54
- "table": "admin.table_properties.table",
55
- "ua": "Налаштування таблиць (test)",
56
- "en": "Table settings"
57
- }
58
- ]
59
- }
60
- ]
2
+ {
3
+ "ua": "Доступ",
4
+ "en": "Management",
5
+ "name": "administration",
6
+ "icon": "IconLockCode",
7
+ "order": 9,
8
+ "menu": [
9
+ {
10
+ "path": "admin.users",
11
+ "table": "admin.users.table",
12
+ "ua": "Користувачі",
13
+ "en": "Users"
14
+ },
15
+ {
16
+ "path": "admin.roles",
17
+ "table": "admin.roles.table",
18
+ "ua": "Ролі/Групи",
19
+ "en": "Roles"
20
+ },
21
+ {
22
+ "path": "admin.routes",
23
+ "table": "admin.routes.table",
24
+ "ua": "Інтерфейси",
25
+ "en": "Routes"
26
+ },
27
+ {
28
+ "path": "auth.logs",
29
+ "table": "auth.logs.table",
30
+ "ua": "Логи інтерфейсів"
31
+ }
32
+ ]
33
+ },
34
+ {
35
+ "ua": "Управління",
36
+ "en": "Management",
37
+ "name": "administration",
38
+ "order": 10,
39
+ "icon": "IconSettingsCog",
40
+ "menu": [
41
+ {
42
+ "path": "admin.user-cls",
43
+ "ua": "Довідники ",
44
+ "component": "user-cls-page"
45
+ },
46
+ {
47
+ "path": "admin.properties",
48
+ "table": "admin.properties.table",
49
+ "ua": "Налаштування",
50
+ "en": "Settings"
51
+ },
52
+ {
53
+ "path": "admin.table_settings",
54
+ "ua": "Налаштування таблиць",
55
+ "component": "table-settings-page"
56
+ },
57
+ {
58
+ "path": "admin.admin_properties",
59
+ "ua": "Налаштування адміна",
60
+ "component": "admin-properties-page"
61
+ }
62
+ ]
63
+ }
64
+ ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.2.86",
3
+ "version": "0.2.88",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -49,7 +49,7 @@
49
49
  "@opengis/admin": "^0.2.82",
50
50
  "@opengis/fastify-auth": "^1.0.61",
51
51
  "@opengis/fastify-file": "^1.0.40",
52
- "@opengis/fastify-table": "^1.1.146",
52
+ "@opengis/fastify-table": "^1.1.148",
53
53
  "@opengis/v3-core": "^0.3.33",
54
54
  "@opengis/v3-filter": "^0.0.62",
55
55
  "@tabler/icons-vue": "^3.28.1",
@@ -1,29 +1,32 @@
1
1
  const table = 'admin.properties';
2
2
 
3
- import { config, getRedis } from '@opengis/fastify-table/utils.js';
3
+ import { config, getRedis, pgClients, getTemplatePath, getTemplate } from '@opengis/fastify-table/utils.js';
4
4
 
5
5
  import { getSettings } from '../../../../utils.js';
6
6
 
7
- export default async function getSettingsAPI({
8
- pg = {}, params = {}, query = {},
7
+ const redis = getRedis();
8
+
9
+ export default async function getSettingsApp({
10
+ pg = pgClients.client, params = {}, query = {},
9
11
  }) {
10
12
  if (!pg.pk?.[table]) {
11
13
  return { message: 'table not found', status: 404 };
12
14
  }
13
15
 
14
- const redis = getRedis();
15
16
  const keyCache = `${pg.options?.database}:settings:${params?.key || 'all'}:${query?.json ? 'json' : 'plain'}:${table}`;
16
-
17
17
  const cache = await redis.get(keyCache);
18
- if (cache && !config?.local) return JSON.parse(cache);
19
18
 
20
- try {
21
- const res = await getSettings({
22
- pg, key: params.key, json: query.json, redis, table,
23
- });
24
- return { message: res, status: 200 };
25
- }
26
- catch (err) {
27
- return { error: err.toString(), status: 500 };
19
+ if (cache && !config?.local) {
20
+ return JSON.parse(cache);
28
21
  }
22
+
23
+ const settings = await getSettings({
24
+ pg, key: params.key, json: query.json, redis, table,
25
+ });
26
+
27
+ const forms = await Promise.all(getTemplatePath('setting')
28
+ .map(async (el) => ({ name: el[0], body: await getTemplate('setting', el[0]) }))
29
+ );
30
+
31
+ return { message: { forms, settings }, status: 200 };
29
32
  }
@@ -2,7 +2,7 @@ const table = 'admin.properties';
2
2
 
3
3
  import { setSettings } from '../../../../utils.js';
4
4
 
5
- export default async function postSettingsAPI({
5
+ export default async function postSettingsApp({
6
6
  pg, session = {}, body = {},
7
7
  }) {
8
8
  if (session.passport?.user?.user_type !== 'superadmin') {
@@ -0,0 +1,120 @@
1
+ import { pgClients, getMeta, getTemplate } from '@opengis/fastify-table/utils.js';
2
+
3
+ import getColumnMetaData from '../utils/getColumnMetaData.js';
4
+
5
+ /**
6
+ *
7
+ * @method GET
8
+ * @priority 4
9
+ * @alias getSettingsTable
10
+ * @type api
11
+ * @tag custom
12
+
13
+ * @returns {String} message and status
14
+ */
15
+
16
+ export default async function getSettingsTable({
17
+ pg = pgClients.client, params = {}, user = {}, query = {},
18
+ }) {
19
+ const { table, entity } = params;
20
+ const { uid } = user;
21
+ const time = [];
22
+
23
+ if (!uid) {
24
+ return { message: 'access restricted', status: 401 };
25
+ }
26
+
27
+ if (!table) {
28
+ return { message: 'not enough params: table', status: 400 };
29
+ }
30
+
31
+ const loadTable = await getTemplate('table', table);
32
+
33
+ const tableName = loadTable?.table || table;
34
+ const meta = await getMeta({ pg, table: tableName });
35
+ const { view, pk } = meta || {};
36
+ time.push(Date.now());
37
+
38
+ if (!pk && !view) {
39
+ return {
40
+ message: `table primary key not found: ${tableName}`,
41
+ status: 400,
42
+ };
43
+ }
44
+
45
+ const { rows: geometry } = meta?.geom
46
+ ? await pg.queryCache(`select st_geometrytype(${meta?.geom}) as type ,count(*)
47
+ from ${tableName} group by st_geometrytype(${meta?.geom})`, { table: tableName }) : [];
48
+ time.push(Date.now());
49
+
50
+ const stat = !view ? await getColumnMetaData({ pg, table: tableName }) : {};
51
+ time.push(Date.now());
52
+
53
+ const { total = 0 } = await pg.queryCache(`select count(*) as total from ${tableName}`, { table: tableName })
54
+ .then(el => el.rows?.[0] || {});
55
+ time.push(Date.now());
56
+
57
+ const { property_json: customColumns = [] } = await pg.query(`select property_json::json from setting.property
58
+ where property_entity='customColumn' and object_id=$1`, [table]).then(el => el.rows?.[0] || {});
59
+
60
+ const { property_json: tableSettingColumns } = await pg.query(`select property_json::json from setting.property
61
+ where property_entity='column' and object_id=$1`, [table]).then(el => el.rows?.[0] || {});
62
+
63
+ const columns = (tableSettingColumns || loadTable?.columns || meta?.columns)?.map((el) => ({ ...el, title: el.title || el.name }))
64
+ ?.filter((value, index, array) => array?.map((el) => el.name).indexOf(value.name) === index); // get unique columns
65
+
66
+ const cls = columns?.filter((el) => ['badge', 'select'].includes(el.format) && (el.option || el.data))
67
+ ?.map((el) => (el.option || el.data))
68
+ ?.filter((value, index, array) => array.indexOf(value) === index); // get unique cls
69
+
70
+ const { property_json: userFilterList } = await pg.query(`select property_json::json from setting.property
71
+ where property_entity='filter' and object_id=$1`, [table]).then(el => el.rows?.[0] || {});
72
+
73
+ const { property_json: customQuery } = await pg.query(`select json_agg(json_build_object('id',property_id,'name', property_key,
74
+ 'query', property_text, 'disabled', coalesce((property_json::json->>'disabled')::boolean,false) )) as property_json
75
+ from setting.property where 1=1 and property_entity='customQuery' and object_id=$1`, [table]).then(el => el.rows?.[0] || {});
76
+
77
+ time.push(Date.now());
78
+
79
+ const debug = user?.user_type?.includes('admin') && query?.debug
80
+ ? {
81
+ view,
82
+ tableName,
83
+ opt,
84
+ colModel,
85
+ metaColumns: meta?.columns,
86
+ columnProperties: tableSettingColumns,
87
+ }
88
+ : undefined;
89
+
90
+ const res = {
91
+ message: {
92
+ time: {
93
+ geom: time[1] - time[0],
94
+ stat: time[2] - time[1],
95
+ count: time[3] - time[2],
96
+ total: time[4] - time[0],
97
+ },
98
+ debug,
99
+ model: tableName,
100
+ total,
101
+ geometry,
102
+ stat,
103
+ cls,
104
+ columns,
105
+ filters: userFilterList?.length
106
+ ? userFilterList
107
+ : loadTable?.filters?.map((el) => ({ ...el, title: el.title || el.ua })),
108
+ customQuery: customQuery?.length ? customQuery : [],
109
+ customColumns,
110
+ customFilters: userFilterList || [],
111
+ },
112
+ status: 200,
113
+ };
114
+
115
+ if (entity) {
116
+ return { [entity]: res.message[entity] };
117
+ }
118
+
119
+ return res;
120
+ };
@@ -0,0 +1,115 @@
1
+ import { getRedis, pgClients } from '@opengis/fastify-table/utils.js';
2
+
3
+ import refreshData from '../utils/refreshData.js';
4
+
5
+ const rclient = getRedis();
6
+
7
+ /**
8
+ *
9
+ * @method POST
10
+ * @priority 4
11
+ * @alias postSettingsTable
12
+ * @type api
13
+ * @tag custom
14
+ * @returns {String} message and status
15
+ */
16
+
17
+ export default async function postTablpostSettingsTableeProperties({
18
+ pg = pgClients.client, params = {}, body = {}, user = {},
19
+ }) {
20
+ const { table } = params;
21
+ const { uid } = user;
22
+
23
+ if (!uid) {
24
+ return { message: 'access restricted', status: 401 };
25
+ }
26
+
27
+ if (!table) {
28
+ return { message: 'not enough params: table', status: 400 };
29
+ }
30
+
31
+ const {
32
+ deleted = [],
33
+ columns = [],
34
+ filters = [],
35
+ customColumns = [],
36
+ customQuery = [],
37
+ } = body;
38
+
39
+ const cacheKey = `${pg.options?.database}:filter-list:${table}`;
40
+
41
+ if (Array.isArray(deleted) && deleted?.length) {
42
+ const sqlList = {
43
+ columns: `delete from setting.property where property_entity='column' and object_id=$1`,
44
+ filters: `delete from setting.property where property_entity='filter' and object_id=$1`,
45
+ customColumns: `delete from setting.custom_data where attr in (select cf_id from setting.custom_field where object_id=$1);
46
+ delete from setting.custom_field where object_id=$1;
47
+ delete from setting.property where property_entity='customColumn' and object_id=$1;`,
48
+ customQuery: `delete from setting.property where property_entity='customQuery' and object_id=$1;`,
49
+ };
50
+ const q = deleted.map((item) => sqlList[item])?.filter((el) => el)?.join(' ');
51
+ const { rowCount = 0 } = await pg.query(q, [table]);
52
+
53
+ if (['customColumn', 'column'].find((el) => deleted.includes(el))) {
54
+ // await funcs.applyHook('preTemplate', { pg, name: table, type: 'table' });
55
+ }
56
+ if (['customQuery', 'filter'].find((el) => deleted.includes(el))) {
57
+ await rclient.del(cacheKey);
58
+ }
59
+
60
+ if (rowCount === 0) {
61
+ return { message: 'nothing to restore', status: 200 };
62
+ }
63
+
64
+ return {
65
+ message: {
66
+ command: 'DELETE',
67
+ deleted,
68
+ table,
69
+ result: 'success',
70
+ },
71
+ status: 200,
72
+ };
73
+ }
74
+
75
+ const result = {};
76
+ // custom filter query (sql)
77
+ if (customQuery?.length) {
78
+ const res = await refreshData({ pg, entity: 'customQuery', table, uid, data: customQuery });
79
+ if (res?.error) return res;
80
+ Object.assign(result, { customQuery: res });
81
+ }
82
+
83
+ // columns
84
+ if (columns?.length) {
85
+ const res = await refreshData({ pg, entity: 'column', table, uid, data: columns });
86
+ if (res?.error) return res;
87
+ Object.assign(result, { columns: res });
88
+ }
89
+
90
+ // custom columns
91
+ if (customColumns?.length) {
92
+ const colModel = await pg.query(`select property_json::json from setting.property
93
+ where property_entity='customColumn' and object_id=$1`, [table]).then((el) => el.rows?.[0]?.property_json);
94
+
95
+ const res = await refreshData({ pg, entity: 'customColumn', table, uid, data: customColumns, colModel });
96
+ if (res?.error) return res;
97
+ Object.assign(result, { customColumns: res });
98
+ }
99
+
100
+ // filters
101
+ if (filters?.length) {
102
+ const res = await refreshData({ pg, entity: 'filter', table, uid, data: filters });
103
+ if (res?.error) return res;
104
+ Object.assign(result, { filters: res });
105
+ }
106
+
107
+ if (columns?.length || customColumns?.length) {
108
+ // await funcs.applyHook('preTemplate', { pg, type: 'table', name: table });
109
+ }
110
+ if (filters?.length || customQuery?.length) {
111
+ await rclient.del(cacheKey);
112
+ }
113
+
114
+ return { message: result, status: 200 };
115
+ };
@@ -4,7 +4,7 @@ import { getRedis } from '@opengis/fastify-table/utils.js';
4
4
 
5
5
  import { getSettings } from '../../../../utils.js';
6
6
 
7
- export default async function getUserProperties({
7
+ export default async function getSettingsUser({
8
8
  pg = {}, params = {}, query = {}, session = {},
9
9
  }) {
10
10
  const { uid } = session.passport?.user || {};
@@ -25,6 +25,6 @@ export default async function getUserProperties({
25
25
  const res = await getSettings({
26
26
  pg, key: params.key, json: query.json, redis, table, uid,
27
27
  });
28
-
28
+
29
29
  return { message: res, status: 200 };
30
30
  }
@@ -2,7 +2,7 @@ const table = 'admin.user_properties';
2
2
 
3
3
  import { setSettings } from '../../../../utils.js';
4
4
 
5
- export default async function postUserProperties({
5
+ export default async function postSettingsUser({
6
6
  pg, session = {}, body = {},
7
7
  }) {
8
8
  const { uid } = session.passport?.user || {};
@@ -1,7 +1,7 @@
1
1
  import { getRedis } from '@opengis/fastify-table/utils.js';
2
2
 
3
3
  import { getSettings } from '../../../../utils.js';
4
- import dataInsert from './utils/dataInsert.js';
4
+ import dataInsert from '../utils/dataInsert.js';
5
5
 
6
6
  function checkValueType(val) {
7
7
  if (val) {
@@ -1,14 +1,21 @@
1
- import getAdminProperties from './controllers/admin.properties.get.js';
2
- import postAdminProperties from './controllers/admin.properties.post.js';
1
+ import getSettingsApp from './controllers/admin.properties.get.js';
2
+ import postSettingsApp from './controllers/admin.properties.post.js';
3
3
 
4
- import getUserProperties from './controllers/user.properties.get.js';
5
- import postUserProperties 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
+
7
+ import getSettingsTable from './controllers/table.properties.get.js';
8
+ import postSettingsTable from './controllers/table.properties.post.js';
6
9
 
7
10
  import { propertiesSchema } from './schema.js';
8
11
 
9
12
  export default async function route(fastify) {
10
- fastify.get('/admin-properties/:key?', { scheme: propertiesSchema }, getAdminProperties);
11
- fastify.get('/user-properties/:key?', { scheme: propertiesSchema }, getUserProperties);
12
- fastify.post('/admin-properties', { config: { policy: ['superadmin'] } }, postAdminProperties);
13
- fastify.post('/user-properties', postUserProperties);
13
+ fastify.get('/settings-app/:key?', { scheme: propertiesSchema }, getSettingsApp);
14
+ fastify.post('/settings-app', { config: { policy: ['superadmin'] } }, postSettingsApp);
15
+
16
+ fastify.get('/settings-user/:key?', { scheme: propertiesSchema }, getSettingsUser);
17
+ fastify.post('/settings-user', {}, postSettingsUser);
18
+
19
+ fastify.get('/settings-table/:table/:entity?', {}, getSettingsTable);
20
+ fastify.post('/settings-table/:table', {}, postSettingsTable);
14
21
  }
@@ -0,0 +1,17 @@
1
+ import { pgClients, getMeta } from '@opengis/fastify-table/utils.js';
2
+
3
+ export default async function getColumnMetaData({
4
+ pg = pgClients.client, table,
5
+ }) {
6
+ if (!table) return null;
7
+
8
+ const { columns = [] } = await getMeta({ pg, table });
9
+ const columnList = columns.filter(el => !['files', 'uid', 'editor_date', 'editor_id', 'cdate'].includes(el.name)).map(el => el.name);
10
+
11
+ const sql = `select count(*) as total, ${columnList.map((item) => `(count(*) filter(where ${item} is not null)) as "${item}"`).join(',')} from ${table}`;
12
+ const res = await pg.queryCache(sql, { table }).then(el => el.rows?.[0] || {});
13
+
14
+ return columns
15
+ .filter(el => !['files', 'uid', 'editor_date', 'editor_id', 'cdate'].includes(el.name))
16
+ .map((row) => Object.assign(row, { percent: ((+res[row.name] / +res.total) * 100).toFixed(0) }));
17
+ };
@@ -0,0 +1,128 @@
1
+ import { randomUUID, createHash } from 'crypto';
2
+
3
+ import { dataInsert, pgClients } from '@opengis/fastify-table/utils.js';
4
+
5
+ function prepareResult(res) {
6
+ const arr = (res.rows || (Array.isArray(res) ? res : Object.values(res || {})));
7
+ return {
8
+ command: 'INSERT',
9
+ count: arr.filter((el) => el.command === 'INSERT')
10
+ ?.map((el) => ({ result: 'success', count: el.rowCount }))
11
+ ?.reduce((acc, curr) => acc + curr.count, 0),
12
+ };
13
+ }
14
+
15
+ export default async function refreshData({
16
+ pg = pgClients.client, entity, table, uid, data,
17
+ }) {
18
+ if (!['filter', 'column', 'customQuery', 'customColumn'].includes(entity)) {
19
+ return { message: 'invalid params: entity', status: 400 };
20
+ }
21
+
22
+ const client = await pg.connect();
23
+
24
+ /* getMeta support */
25
+ client.options = pg.options;
26
+ client.tlist = pg.tlist;
27
+ client.pgType = pg.pgType;
28
+ client.pk = pg.pk;
29
+ client.relkinds = pg.relkinds;
30
+
31
+ const result = {};
32
+
33
+ try {
34
+ await client.query('BEGIN');
35
+
36
+ if (['filter', 'column'].includes(entity)) {
37
+ data?.forEach((el) => Object.assign(el, { id: el.id || randomUUID() }));
38
+ await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
39
+
40
+ const res = dataInsert({
41
+ pg: client,
42
+ table: 'setting.property',
43
+ data: {
44
+ property_entity: entity,
45
+ object_id: table,
46
+ property_json: JSON.stringify(data)?.replace(/'/g, "''"),
47
+ },
48
+ uid,
49
+ });
50
+ Object.assign(result, res);
51
+ }
52
+
53
+ if (['customQuery'].includes(entity)) {
54
+ await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
55
+
56
+ const res = await Promise.all(data?.map(async (el) => dataInsert({
57
+ pg: client,
58
+ table: 'setting.property',
59
+ data: {
60
+ property_entity: entity,
61
+ object_id: table,
62
+ property_key: el.name,
63
+ property_text: el.query,
64
+ property_json: { disabled: el.disabled },
65
+ },
66
+ uid,
67
+ })));
68
+ Object.assign(result, res);
69
+ }
70
+
71
+ if (entity === 'customColumn') {
72
+ const prefix = createHash('md5').update(table).digest('hex').substr(0, 10);
73
+ const data1 = [];
74
+
75
+ await Promise.all(data.map(async (el, index) => {
76
+ const obj = {
77
+ cf_id: `col_${prefix}_${index}`,
78
+ cf_name: el.title || el.ua || el.name,
79
+ cf_type: el.format || el.type,
80
+ cf_default: el.default,
81
+ cf_notnull: el.notnull,
82
+ object_id: table,
83
+ tablename: table,
84
+ };
85
+
86
+ data1.push({
87
+ name: obj.cf_id,
88
+ title: obj.cf_name,
89
+ format: obj.cf_type,
90
+ option: data[index]?.option,
91
+ hidden: data[index]?.hidden,
92
+ custom: true,
93
+ });
94
+
95
+ await dataInsert({
96
+ pg: client,
97
+ table: 'setting.custom_field',
98
+ data: obj,
99
+ uid,
100
+ });
101
+ }));
102
+
103
+ await client.query('delete from setting.custom_field where $1 in (tablename, object_id)', [table]);
104
+ await client.query('delete from setting.property where object_id=$1 and property_entity=$2', [table, entity]);
105
+
106
+ const data2 = JSON.stringify(data1?.filter((value, index, array) => array.indexOf(value) === index))?.replace(/'/g, "''");
107
+ const res = await dataInsert({
108
+ pg: client,
109
+ table: 'setting.property',
110
+ data: {
111
+ property_entity: 'customColumn',
112
+ object_id: table,
113
+ property_json: data2,
114
+ },
115
+ uid,
116
+ });
117
+ Object.assign(result, res);
118
+ }
119
+ await client.query('COMMIT');
120
+ return prepareResult(result);
121
+ } catch (err) {
122
+ await client.query('ROLLBACK');
123
+ return { error: err.toString(), status: 500 };
124
+ }
125
+ finally {
126
+ client.release();
127
+ }
128
+ };
@@ -1,7 +1,7 @@
1
1
  import { getMeta, getToken, pgClients } from '@opengis/fastify-table/utils.js';
2
2
 
3
3
  const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
4
- const username = `coalesce(u.sur_name,'')||coalesce(' '||u.user_name,'') ||coalesce(' '||u.father_name,'') as username`;
4
+ const username = `coalesce(u.sur_name,'')||coalesce(' '||u.user_name,'') ||coalesce(' '||u.father_name,'')`;
5
5
 
6
6
  /**
7
7
  * Дістає CRM для widget
@@ -85,6 +85,7 @@ export default async function widgetGet({
85
85
 
86
86
  const q = tableName && pg.pk['admin.users'] ? `select ${username} as author, u.login, a.cdate, a.editor_date from ${tableName} a
87
87
  left join admin.users u on a.uid=u.uid where a.${pk}=$1 limit 1` : undefined;
88
+
88
89
  const data = pk && q ? await pg.one(q, [objectid]) : {};
89
90
 
90
91
  if (query.debug && user?.user_type === 'admin') {