@opengis/bi 1.0.23 → 1.0.25
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/dist/bi.js +1 -1
- package/dist/bi.umd.cjs +109 -135
- package/dist/{import-file-DgBd_UN1.js → import-file-D1BXgBLh.js} +11571 -11431
- package/dist/{map-component-mixin-NewmNy_M.js → map-component-mixin-DVK92yIp.js} +218 -217
- package/dist/style.css +1 -1
- package/dist/vs-donut-DFofoWWE.js +148 -0
- package/dist/{vs-funnel-bar-B3DpbtUl.js → vs-funnel-bar-CUEOqNnJ.js} +22 -11
- package/dist/{vs-map-DwyQHLpN.js → vs-map-DxaSAhZH.js} +3 -3
- package/dist/{vs-map-cluster-CnZ9g6k-.js → vs-map-cluster-BqOHAVDj.js} +2 -2
- package/dist/{vs-number-LwROg9Oe.js → vs-number-C1s9pa7F.js} +1 -1
- package/dist/vs-table-DCBSLb1s.js +71 -0
- package/dist/{vs-text-DgAf3Ids.js → vs-text-SoIN8Lt8.js} +33 -28
- package/package.json +9 -8
- package/server/migrations/bi.dataset.sql +1 -0
- package/server/migrations/bi.sql +10 -0
- package/server/plugins/hook.js +1 -1
- package/server/routes/dashboard/controllers/dashboard.import.js +103 -0
- package/server/routes/dashboard/controllers/dashboard.js +45 -26
- package/server/routes/dashboard/controllers/dashboard.list.js +10 -9
- package/server/routes/dashboard/index.mjs +7 -9
- package/server/routes/data/controllers/data.js +14 -7
- package/server/routes/data/controllers/util/chartSQL.js +2 -1
- package/server/routes/data/controllers/util/normalizeData.js +7 -5
- package/server/routes/data/index.mjs +3 -1
- package/server/routes/dataset/controllers/bi.dataset.list.js +2 -4
- package/server/routes/dataset/controllers/createDatasetPost.js +8 -5
- package/server/routes/dataset/controllers/data.js +10 -6
- package/server/routes/dataset/controllers/dbTablePreview.js +3 -1
- package/server/routes/dataset/controllers/dbTables.js +3 -1
- package/server/routes/dataset/controllers/delete.js +1 -0
- package/server/routes/dataset/controllers/deleteDataset.js +52 -0
- package/server/routes/dataset/controllers/editDataset.js +2 -1
- package/server/routes/dataset/controllers/format.js +3 -1
- package/server/routes/dataset/controllers/insert.js +1 -0
- package/server/routes/dataset/controllers/table.js +58 -59
- package/server/routes/dataset/controllers/update.js +1 -0
- package/server/routes/dataset/index.mjs +25 -13
- package/server/routes/dataset/utils/createTableQuery.js +1 -1
- package/server/routes/dataset/utils/executeQuery.js +2 -2
- package/server/routes/edit/controllers/dashboard.add.js +32 -22
- package/server/routes/edit/controllers/dashboard.delete.js +39 -0
- package/server/routes/edit/controllers/dashboard.edit.js +56 -41
- package/server/routes/edit/controllers/widget.add.js +48 -57
- package/server/routes/edit/controllers/widget.del.js +40 -51
- package/server/routes/edit/controllers/widget.edit.js +30 -16
- package/server/routes/edit/index.mjs +4 -5
- package/server/routes/map/controllers/cluster.js +3 -2
- package/server/routes/map/controllers/clusterVtile.js +1 -1
- package/server/routes/map/controllers/geojson.js +2 -2
- package/server/routes/map/controllers/heatmap.js +2 -2
- package/server/routes/map/controllers/map.js +3 -2
- package/server/routes/map/controllers/vtile.js +1 -1
- package/server/routes/map/index.mjs +8 -6
- package/server/templates/page/login.html +59 -0
- package/server/utils/getWidget.js +34 -21
- package/dist/vs-calendar-CPXj4hBh.js +0 -116
- package/dist/vs-donut-CUmi2ir5.js +0 -148
- package/dist/vs-heatmap-COwT3bHE.js +0 -97
- package/dist/vs-table-Dt_MSaCC.js +0 -68
- package/server/routes/dashboard/controllers/dashboard.delete.js +0 -38
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { dataDelete, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Видалення набору даних
|
|
5
|
+
*
|
|
6
|
+
* @method DELETE
|
|
7
|
+
* @summary Видалення набору даних
|
|
8
|
+
* @priority 4
|
|
9
|
+
* @alias deleteDataset
|
|
10
|
+
* @type api
|
|
11
|
+
* @tag bi
|
|
12
|
+
* @param {Object} query.id Dataset ID
|
|
13
|
+
* @errors 400,500
|
|
14
|
+
* @returns {Number} status Номер помилки
|
|
15
|
+
* @returns {String} error Опис помилки
|
|
16
|
+
* @returns {Object} rows Масив з колонками таблиці
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export default async function deleteDataset({
|
|
20
|
+
pg = pgClients.client, query = {}, user = {},
|
|
21
|
+
}) {
|
|
22
|
+
if (!user?.uid) {
|
|
23
|
+
return { message: 'access restricted', status: 403 };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!query?.id) {
|
|
27
|
+
return { message: 'not enough params: id', status: 404 };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const dataset = await pg.query('select dataset_id as id, table_name as table from bi.dataset where dataset_id=$1', [query.id])
|
|
31
|
+
.then(el => el.rows[0] || {});
|
|
32
|
+
|
|
33
|
+
if (!dataset.id) {
|
|
34
|
+
return { message: 'dataset not found', status: 404 };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const table = dataset.table && pg.pk[dataset.table] ? dataset.table : dataset.table?.replace(/"/g, '');
|
|
38
|
+
|
|
39
|
+
const dropTable = table && pg.pk?.[table] && table.startsWith('data_user.');
|
|
40
|
+
if (dropTable) {
|
|
41
|
+
await pg.query(`drop table if exists ${table}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await dataDelete({
|
|
45
|
+
pg,
|
|
46
|
+
table: 'bi.dataset',
|
|
47
|
+
id: dataset.id,
|
|
48
|
+
uid: user.uid,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return { message: { id: dataset?.id, table: dropTable ? dataset.table : undefined }, status: 200 };
|
|
52
|
+
}
|
|
@@ -20,7 +20,7 @@ const columnTypeMatch = {
|
|
|
20
20
|
* @alias editDataset
|
|
21
21
|
* @type api
|
|
22
22
|
* @tag bi
|
|
23
|
-
* @param {Object}
|
|
23
|
+
* @param {Object} query.id Видалення ID
|
|
24
24
|
* @errors 400,500
|
|
25
25
|
* @returns {Number} status Номер помилки
|
|
26
26
|
* @returns {String} error Опис помилки
|
|
@@ -70,6 +70,7 @@ export default async function editDataset(req) {
|
|
|
70
70
|
}));
|
|
71
71
|
|
|
72
72
|
await dataUpdate({
|
|
73
|
+
pg,
|
|
73
74
|
table: 'bi.dataset',
|
|
74
75
|
data: { column_list: columns },
|
|
75
76
|
id: dataset.id,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { pgClients } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
1
3
|
import getTableData from "../utils/getTableData.js";
|
|
2
4
|
import getLayersData from "../utils/getLayersData.js";
|
|
3
5
|
|
|
4
|
-
export default async function gisFormat({ query = {}, pg }) {
|
|
6
|
+
export default async function gisFormat({ query = {}, pg = pgClients.client }) {
|
|
5
7
|
const time = [Date.now()];
|
|
6
8
|
const { layer, table, id, lat, lng } = query;
|
|
7
9
|
|
|
@@ -1,69 +1,68 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
config, pgClients, getMeta, setToken, getToken,
|
|
3
3
|
} from '@opengis/fastify-table/utils.js';
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
export default async function datasetFormData({
|
|
6
|
-
|
|
7
|
-
}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
pg = pgClients.client, params = {}, query = {}, user = {},
|
|
7
|
+
}) {
|
|
8
|
+
if (!params?.id) {
|
|
9
|
+
return { message: 'not enough params: id', status: 400 };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!user?.uid) {
|
|
13
|
+
return { message: 'access restricted', status: 403 };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { user_type: userType = 'regular' } = user;
|
|
17
|
+
|
|
18
|
+
const tokenData = await getToken({
|
|
19
|
+
uid: user?.uid,
|
|
20
|
+
token: params.id,
|
|
21
|
+
mode: 'w',
|
|
22
|
+
json: 1,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!tokenData && !params?.object_id) {
|
|
26
|
+
return { message: 'not enough params: object_id', status: 400 };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const dataset = await pg.query(`select dataset_id as id, table_name as table, column_list as columns, filter_list as filters,
|
|
30
30
|
sql_list as sql, style, form_setting, pk, access_level from bi.dataset where dataset_id=$1`, [tokenData?.dataset || params.id]).then(el => el.rows[0] || {});
|
|
31
|
-
|
|
32
|
-
if (!dataset?.id) {
|
|
33
|
-
return { message: 'dataset not found', status: 404 };
|
|
34
|
-
}
|
|
35
31
|
|
|
36
|
-
|
|
32
|
+
if (!dataset?.id) {
|
|
33
|
+
return { message: 'dataset not found', status: 404 };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const tlist = await pg.query(`select array_agg((select nspname from pg_namespace where oid=relnamespace)||'.'||relname) tlist
|
|
37
37
|
from pg_class where relkind in ('r','v')`).then(el => el.rows[0]?.tlist || []);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
|
|
39
|
+
if (!dataset.table || !tlist.includes(dataset.table.replace(/"/g, '')) || (!pg.pk?.[dataset.table.replace(/"/g, '')] && !dataset.pk)) {
|
|
40
|
+
return { message: `table not found: ${dataset.table}`, status: 404 };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { pk = dataset.pk, columns: dbColumns = [] } = await getMeta(dataset.table) || {};
|
|
44
|
+
const cols = dataset.columns?.filter((el) => el.name !== 'geom')?.map((el) => el.name || el)?.join(',');
|
|
45
|
+
|
|
46
|
+
const where = [`"${pk}" = $1`, dataset.query].filter((el) => el);
|
|
47
47
|
|
|
48
48
|
const geom = dbColumns.find((el) => el.name === 'geom' && pg.pgType[el.dataTypeID] === 'geometry') ? ',st_asgeojson(geom)::json as geom' : '';
|
|
49
49
|
const files = dbColumns.find((el) => el.name === 'files' && pg.pgType[el.dataTypeID] === 'text') ? ',files' : '';
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
const q = `select "${pk}" as id, ${cols || '*'} ${files} ${geom} from ${dataset.table} t where ${where.join(' and ') || 'true'} limit 1`;
|
|
51
|
+
|
|
52
|
+
if (query.sql === '1' && (config.debug || userType.includes('admin'))) { return q; }
|
|
53
|
+
|
|
54
|
+
const data = await pg.query(q, [tokenData?.id || params.object_id]).then(el => el.rows?.[0] || {});
|
|
55
|
+
|
|
56
|
+
data.token = setToken({
|
|
57
|
+
ids: [JSON.stringify({
|
|
58
|
+
id: data.id,
|
|
59
|
+
table: dataset.table,
|
|
60
|
+
form: `${dataset.id}.form`,
|
|
61
|
+
dataset: dataset.id,
|
|
62
|
+
})],
|
|
63
|
+
uid: user?.uid,
|
|
64
|
+
array: 1,
|
|
65
|
+
})[0];
|
|
66
|
+
|
|
67
|
+
return data;
|
|
68
68
|
}
|
|
69
|
-
|
|
@@ -3,6 +3,7 @@ import dbTablePreview from './controllers/dbTablePreview.js';
|
|
|
3
3
|
|
|
4
4
|
import createDatasetPost from './controllers/createDatasetPost.js';
|
|
5
5
|
import editDataset from './controllers/editDataset.js';
|
|
6
|
+
import deleteDataset from './controllers/deleteDataset.js';
|
|
6
7
|
import datasetData from './controllers/data.js';
|
|
7
8
|
import datasetFormData from './controllers/table.js';
|
|
8
9
|
import datasetDataInsert from './controllers/insert.js';
|
|
@@ -15,106 +16,117 @@ import datasetEditComment from './controllers/comment.js';
|
|
|
15
16
|
import biDbList from './controllers/bi.db.list.js'; // list db
|
|
16
17
|
import biDatasetList from './controllers/bi.dataset.list.js'; // list datasets
|
|
17
18
|
|
|
19
|
+
const policy = ['public'];
|
|
20
|
+
|
|
18
21
|
export default async function route(fastify, opts) {
|
|
19
22
|
fastify.route({
|
|
20
23
|
method: 'GET',
|
|
21
24
|
url: '/bi-db-list',
|
|
22
25
|
schema: {},
|
|
26
|
+
config: { policy },
|
|
23
27
|
handler: biDbList,
|
|
24
28
|
});
|
|
25
29
|
fastify.route({
|
|
26
30
|
method: 'GET',
|
|
27
31
|
url: '/bi-datasets',
|
|
28
32
|
schema: {},
|
|
33
|
+
config: { policy },
|
|
29
34
|
handler: biDatasetList,
|
|
30
35
|
});
|
|
31
36
|
fastify.route({
|
|
32
37
|
method: 'GET',
|
|
33
38
|
url: '/gis-format',
|
|
34
|
-
config: { policy
|
|
39
|
+
config: { policy },
|
|
35
40
|
handler: format,
|
|
36
41
|
});
|
|
37
42
|
fastify.route({
|
|
38
43
|
method: 'GET',
|
|
39
44
|
url: '/db-tables',
|
|
40
45
|
schema: {},
|
|
41
|
-
config: { policy
|
|
46
|
+
config: { policy },
|
|
42
47
|
handler: dbTables,
|
|
43
48
|
});
|
|
44
49
|
fastify.route({
|
|
45
50
|
method: 'GET',
|
|
46
51
|
url: '/db-tables/:name',
|
|
47
52
|
schema: {},
|
|
48
|
-
config: { policy
|
|
53
|
+
config: { policy },
|
|
49
54
|
handler: dbTablePreview,
|
|
50
55
|
});
|
|
51
56
|
fastify.route({
|
|
52
57
|
method: 'POST',
|
|
53
58
|
url: '/dataset',
|
|
54
59
|
schema: {},
|
|
55
|
-
config: { policy
|
|
60
|
+
config: { policy },
|
|
56
61
|
handler: createDatasetPost,
|
|
57
62
|
});
|
|
58
63
|
fastify.route({
|
|
59
64
|
method: 'PUT',
|
|
60
65
|
url: '/dataset',
|
|
61
66
|
schema: {},
|
|
62
|
-
config: { policy
|
|
67
|
+
config: { policy },
|
|
63
68
|
handler: editDataset,
|
|
64
69
|
});
|
|
70
|
+
fastify.route({
|
|
71
|
+
method: 'DELETE',
|
|
72
|
+
url: '/dataset',
|
|
73
|
+
schema: {},
|
|
74
|
+
config: { policy },
|
|
75
|
+
handler: deleteDataset,
|
|
76
|
+
});
|
|
65
77
|
fastify.route({
|
|
66
78
|
method: 'GET',
|
|
67
79
|
url: '/dataset-data/:id',
|
|
68
80
|
schema: {},
|
|
69
|
-
config: { policy
|
|
81
|
+
config: { policy },
|
|
70
82
|
handler: datasetData,
|
|
71
83
|
});
|
|
72
84
|
fastify.route({
|
|
73
85
|
method: 'GET',
|
|
74
86
|
url: '/dataset-data/:id/:object_id',
|
|
75
87
|
schema: {},
|
|
76
|
-
config: { policy
|
|
88
|
+
config: { policy },
|
|
77
89
|
handler: datasetFormData,
|
|
78
90
|
});
|
|
79
91
|
fastify.route({
|
|
80
92
|
method: 'POST',
|
|
81
93
|
url: '/dataset-data/:id',
|
|
82
94
|
schema: {},
|
|
83
|
-
config: { policy
|
|
95
|
+
config: { policy },
|
|
84
96
|
handler: datasetDataInsert,
|
|
85
97
|
});
|
|
86
98
|
fastify.route({
|
|
87
99
|
method: 'PUT',
|
|
88
100
|
url: '/dataset-data/:id/:object_id?',
|
|
89
101
|
schema: {},
|
|
90
|
-
config: { policy
|
|
102
|
+
config: { policy },
|
|
91
103
|
handler: datasetDataUpdate,
|
|
92
104
|
});
|
|
93
105
|
fastify.route({
|
|
94
106
|
method: 'DELETE',
|
|
95
107
|
url: '/dataset-data/:id/:object_id?',
|
|
96
108
|
schema: {},
|
|
97
|
-
config: { policy
|
|
109
|
+
config: { policy },
|
|
98
110
|
handler: datasetDataDelete,
|
|
99
111
|
});
|
|
100
112
|
fastify.route({
|
|
101
113
|
method: 'GET',
|
|
102
114
|
url: '/dataset-form/:id',
|
|
103
115
|
schema: {},
|
|
104
|
-
config: { policy
|
|
116
|
+
config: { policy },
|
|
105
117
|
handler: datasetForm,
|
|
106
118
|
});
|
|
107
119
|
fastify.route({
|
|
108
120
|
method: 'GET',
|
|
109
121
|
url: '/dataset-export/:id',
|
|
110
122
|
schema: {},
|
|
111
|
-
config: { policy
|
|
123
|
+
config: { policy },
|
|
112
124
|
handler: datasetDataExport,
|
|
113
125
|
});
|
|
114
126
|
fastify.route({
|
|
115
127
|
method: 'POST',
|
|
116
128
|
url: '/dataset-comment/:id',
|
|
117
|
-
config: { policy
|
|
129
|
+
config: { policy },
|
|
118
130
|
handler: datasetEditComment,
|
|
119
131
|
});
|
|
120
132
|
}
|
|
@@ -36,7 +36,7 @@ export default function createTable(columns, name) {
|
|
|
36
36
|
?.join(';');
|
|
37
37
|
|
|
38
38
|
const createQuery = `create table if not exists ${table} (
|
|
39
|
-
${pkey} text not null default public.
|
|
39
|
+
${pkey} text not null default encode(public.gen_random_bytes(6), 'hex'),
|
|
40
40
|
geom public.geometry, ${columns ? `
|
|
41
41
|
${columns?.map?.((el) => `${el.name} ${el.type}`).join(', ')},` : ''}
|
|
42
42
|
cdate timestamp without time zone not null default now(),
|
|
@@ -9,9 +9,9 @@ values($1,$2,$3,$4,$5,$6,$7) returning dataset_id`;
|
|
|
9
9
|
const updateAppeal = 'update datasets_appeal.appeal set dataset_id=$1, data_key=$2 where ap_id=$3';
|
|
10
10
|
|
|
11
11
|
export default async function executeQuery({
|
|
12
|
-
sql, data, name, id, table, relPath, columns, pkey, source, user, url, dataKey,
|
|
12
|
+
pg = pgClients.client, sql, data, name, id, table, relPath, columns, pkey, source, user, url, dataKey,
|
|
13
13
|
}) {
|
|
14
|
-
const client = await
|
|
14
|
+
const client = await pg.connect();
|
|
15
15
|
try {
|
|
16
16
|
await client.query('BEGIN');
|
|
17
17
|
|
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import { dataInsert } from "@opengis/fastify-table/utils.js";
|
|
1
|
+
import { pgClients, dataInsert, getPGAsync } from "@opengis/fastify-table/utils.js";
|
|
2
2
|
|
|
3
|
-
export default async function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[tableName]
|
|
10
|
-
);
|
|
11
|
-
if (!checkTable.rows.length) return { message: 'bad params', status: 401 };
|
|
12
|
-
const res = await dataInsert({
|
|
13
|
-
table: 'bi.dashboard',
|
|
14
|
-
data: body,
|
|
15
|
-
});
|
|
3
|
+
export default async function dashboardAdd(req, reply) {
|
|
4
|
+
const {
|
|
5
|
+
pg = pgClients.client,
|
|
6
|
+
body = {},
|
|
7
|
+
} = req;
|
|
8
|
+
const time = Date.now();
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return { error: err.toString(), status: 500 };
|
|
10
|
+
if (body?.db) {
|
|
11
|
+
try {
|
|
12
|
+
const pg1 = await getPGAsync(body.db);
|
|
13
|
+
await pg1.query('select 1');
|
|
14
|
+
} catch (err) {
|
|
15
|
+
return reply.status(400).send('Некоректна база даних');
|
|
16
|
+
}
|
|
25
17
|
}
|
|
18
|
+
|
|
19
|
+
const res = await dataInsert({
|
|
20
|
+
pg,
|
|
21
|
+
table: 'bi.dashboard',
|
|
22
|
+
data: body,
|
|
23
|
+
}).then(el => el.rows?.[0] || {});
|
|
24
|
+
|
|
25
|
+
if (res.dashboard_id && body.dataset) {
|
|
26
|
+
await pg.query(`update bi.dataset set dashboard_list=coalesce(dashboard_list, '{}'::text[]) || array[$1]
|
|
27
|
+
where dataset_id=$2`, [res.dashboard_id, body.dataset]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
time: Date.now() - time,
|
|
32
|
+
id: res.dashboard_id,
|
|
33
|
+
title: res.title,
|
|
34
|
+
name: res.name,
|
|
35
|
+
};
|
|
26
36
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
import { pgClients, dataDelete } from '@opengis/fastify-table/utils.js';
|
|
5
|
+
|
|
6
|
+
const cwd = process.cwd();
|
|
7
|
+
const dashboardDir = path.join(cwd, 'server/templates/dashboard');
|
|
8
|
+
|
|
9
|
+
export default async function dashboardDelete({ pg = pgClients.client, params = {}, user }, reply) {
|
|
10
|
+
if (!params?.id) {
|
|
11
|
+
return reply.status(400).send('not enough params: id');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const dirContent = existsSync(dashboardDir)
|
|
15
|
+
? readdirSync(dashboardDir)
|
|
16
|
+
: [];
|
|
17
|
+
|
|
18
|
+
if (dirContent.includes(params.id)) {
|
|
19
|
+
return reply.status(403).send(`access restricted: ${params.id}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { rowCount = 0 } = pg.pk?.['bi.dashboard']
|
|
23
|
+
? await pg.query('select * from bi.dashboard where $1 in (dashboard_id,name)', [params.id])
|
|
24
|
+
: {};
|
|
25
|
+
|
|
26
|
+
if (rowCount === 0) {
|
|
27
|
+
return reply.status(404).send(`not found ${params.id}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
await pg.query(`delete from bi.widget where $1 in (dashboard_id)`, [params.id]);
|
|
31
|
+
await dataDelete({
|
|
32
|
+
pg,
|
|
33
|
+
table: 'bi.dashboard',
|
|
34
|
+
id: params.id,
|
|
35
|
+
uid: user?.uid,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return reply.status(200).send('successfully deleted');
|
|
39
|
+
}
|
|
@@ -1,46 +1,61 @@
|
|
|
1
|
-
import { dataUpdate } from "@opengis/fastify-table/utils.js";
|
|
2
|
-
|
|
3
|
-
export default async function dashboardEdit(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { dataUpdate, pgClients, getPGAsync } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function dashboardEdit({
|
|
4
|
+
pg = pgClients.client, params = {}, body = {},
|
|
5
|
+
}, reply) {
|
|
6
|
+
const { name: dashboardName } = params;
|
|
7
|
+
const { panels, widgets, table_name: tableName } = body;
|
|
8
|
+
|
|
9
|
+
if (body?.db) {
|
|
10
|
+
try {
|
|
11
|
+
const pg1 = await getPGAsync(body.db);
|
|
12
|
+
await pg1.query('select 1');
|
|
13
|
+
} catch (err) {
|
|
14
|
+
return reply.status(400).send('Некоректна база даних');
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!dashboardName) {
|
|
19
|
+
return reply.status(400).send('not enough params: name');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!tableName) {
|
|
23
|
+
return reply.status(400).send('not enough params: table_name');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const row = await pg.query('select dashboard_id, widgets, panels from bi.dashboard where $1 in (dashboard_id, name)', [dashboardName])
|
|
27
|
+
.then(el => el.rows?.[0] || {});
|
|
28
|
+
const { dashboard_id: dashboardId } = row;
|
|
29
|
+
|
|
30
|
+
if (!dashboardId) {
|
|
31
|
+
return reply.status(400).send('dashboard not found');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (panels?.length && !widgets?.length) {
|
|
35
|
+
row.widgets.forEach((el) => {
|
|
36
|
+
const { title } = panels?.find?.(item => item.widget === el.name) || {};
|
|
37
|
+
if (el.data) {
|
|
38
|
+
// console.log('el.title', el.title, 'title', title);
|
|
39
|
+
el.data.title = title;
|
|
40
|
+
}
|
|
33
41
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
Object.assign(body, { widgets: row.widgets });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const res = await dataUpdate({
|
|
46
|
+
pg,
|
|
47
|
+
table: 'bi.dashboard',
|
|
48
|
+
id: dashboardId,
|
|
49
|
+
data: body,
|
|
50
|
+
});
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
status: 200,
|
|
41
|
-
rows: res,
|
|
42
|
-
};
|
|
43
|
-
} catch (err) {
|
|
44
|
-
return reply.status(500).send(err.toString());
|
|
52
|
+
if (!Object.keys(res)?.length) {
|
|
53
|
+
return reply.status(404).send('not found data');
|
|
45
54
|
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
message: `updated ${dashboardName}`,
|
|
58
|
+
status: 200,
|
|
59
|
+
rows: res,
|
|
60
|
+
};
|
|
46
61
|
}
|