@opengis/bi 1.0.13 → 1.0.15
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 +50 -52
- package/config.js +12 -12
- package/dist/bi.js +1 -1
- package/dist/bi.umd.cjs +120 -134
- package/dist/{import-file-1T7kpSzt.js → import-file-CRC0sYYT.js} +11974 -11522
- package/dist/{map-component-mixin-BLM9iEWA.js → map-component-mixin-BCtWEvzv.js} +4830 -3150
- package/dist/style.css +1 -1
- package/dist/vs-calendar-5ot79n0N.js +110 -0
- package/dist/vs-funnel-bar-CLo6gXI_.js +105 -0
- package/dist/vs-heatmap-DHGA8dRk.js +97 -0
- package/dist/{vs-map-cluster-Dfe9INqE.js → vs-map-cluster-CNgX6JVF.js} +28 -25
- package/dist/vs-map-pIn5wS4G.js +74 -0
- package/dist/vs-number-DYfok8VU.js +55 -0
- package/dist/{vs-text-DcrAdQ40.js → vs-text-Dckykz09.js} +19 -13
- package/package.json +107 -72
- package/plugin.js +14 -13
- package/server/migrations/bi.dataset.sql +26 -0
- package/server/migrations/bi.sql +93 -27
- package/server/plugins/docs.js +48 -47
- package/server/plugins/hook.js +89 -86
- package/server/plugins/vite.js +69 -55
- package/server/routes/dashboard/controllers/dashboard.delete.js +38 -35
- package/server/routes/dashboard/controllers/dashboard.js +118 -80
- package/server/routes/dashboard/controllers/dashboard.list.js +30 -39
- package/server/routes/dashboard/controllers/utils/yaml.js +11 -12
- package/server/routes/dashboard/index.mjs +25 -24
- package/server/routes/data/controllers/data.js +168 -97
- package/server/routes/data/controllers/util/chartSQL.js +42 -25
- package/server/routes/data/controllers/util/normalizeData.js +59 -34
- package/server/routes/data/index.mjs +29 -26
- package/server/routes/dataset/controllers/bi.dataset.demo.add.js +97 -0
- package/server/routes/dataset/controllers/bi.dataset.import.js +67 -0
- package/server/routes/dataset/controllers/util/create.table.js +22 -0
- package/server/routes/dataset/controllers/util/prepare.data.js +49 -0
- package/server/routes/dataset/index.mjs +19 -0
- package/server/routes/db/controllers/dbTablePreview.js +63 -0
- package/server/routes/db/controllers/dbTables.js +36 -0
- package/server/routes/db/index.mjs +17 -0
- package/server/routes/edit/controllers/dashboard.add.js +26 -23
- package/server/routes/edit/controllers/dashboard.edit.js +46 -37
- package/server/routes/edit/controllers/widget.add.js +75 -49
- package/server/routes/edit/controllers/widget.del.js +69 -63
- package/server/routes/edit/controllers/widget.edit.js +52 -82
- package/server/routes/edit/index.mjs +31 -27
- package/server/routes/map/controllers/cluster.js +109 -75
- package/server/routes/map/controllers/clusterVtile.js +166 -143
- package/server/routes/map/controllers/geojson.js +127 -101
- package/server/routes/map/controllers/map.js +60 -57
- package/server/routes/map/controllers/utils/downloadClusterData.js +43 -0
- package/server/routes/map/controllers/vtile.js +183 -161
- package/server/routes/map/index.mjs +25 -25
- package/server/utils/getWidget.js +85 -56
- package/utils.js +12 -11
- package/dist/vs-calendar-WiK1hcHS.js +0 -96
- package/dist/vs-funnel-bar-CpPbYZ0_.js +0 -92
- package/dist/vs-heatmap-BG4eIROH.js +0 -83
- package/dist/vs-map-BRk6Fmks.js +0 -66
- package/dist/vs-number-CJq-vi95.js +0 -39
package/server/plugins/hook.js
CHANGED
|
@@ -1,86 +1,89 @@
|
|
|
1
|
-
import fp from 'fastify-plugin';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
1
|
+
import fp from 'fastify-plugin';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
// the use of fastify-plugin is required to be able
|
|
5
|
+
// to export the decorators to the outer scope
|
|
6
|
+
|
|
7
|
+
async function plugin(fastify) {
|
|
8
|
+
// preSerialization
|
|
9
|
+
fastify.addHook('preSerialization', async (req, reply, payload) => {
|
|
10
|
+
if (!req.session?.passport?.user?.uid) {
|
|
11
|
+
// return reply.redirect('/login');
|
|
12
|
+
}
|
|
13
|
+
if (req.url.includes('/suggest/') && !req.query.json) {
|
|
14
|
+
return payload?.data;
|
|
15
|
+
}
|
|
16
|
+
if (payload.redirect) {
|
|
17
|
+
return reply.redirect(payload.redirect);
|
|
18
|
+
}
|
|
19
|
+
if (reply.sent) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (payload.status) {
|
|
24
|
+
reply.status(payload.status);
|
|
25
|
+
}
|
|
26
|
+
/* if (payload.headers) {
|
|
27
|
+
reply.headers(payload.headers);
|
|
28
|
+
} */
|
|
29
|
+
if (payload.buffer) {
|
|
30
|
+
return payload.buffer;
|
|
31
|
+
}
|
|
32
|
+
if (payload.file) {
|
|
33
|
+
// const buffer = await readFile(payload.file);
|
|
34
|
+
// return reply.send(buffer);
|
|
35
|
+
const stream = fs.createReadStream(payload.file);
|
|
36
|
+
return stream;
|
|
37
|
+
// return reply.send(stream);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (payload.message) {
|
|
41
|
+
return payload.message;
|
|
42
|
+
}
|
|
43
|
+
return payload;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// preValidation
|
|
47
|
+
fastify.addHook('preValidation', async (req) => {
|
|
48
|
+
const parseRawBody =
|
|
49
|
+
['POST', 'PUT'].includes(req.method) &&
|
|
50
|
+
req.body &&
|
|
51
|
+
typeof req.body === 'string' &&
|
|
52
|
+
req.body.trim(/\r\n/g).startsWith('{') &&
|
|
53
|
+
req.body.trim(/\r\n/g).endsWith('}');
|
|
54
|
+
if (parseRawBody) {
|
|
55
|
+
try {
|
|
56
|
+
req.body = JSON.parse(req.body || '{}');
|
|
57
|
+
} catch (err) {
|
|
58
|
+
// throw new Error('invalid body');
|
|
59
|
+
// return { error: 'invalid body', status: 400 };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// allow upload file
|
|
65
|
+
const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
|
|
66
|
+
fastify.addContentTypeParser('multipart', (request, _, done) => {
|
|
67
|
+
request[kIsMultipart] = true;
|
|
68
|
+
done(null);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// parse Body
|
|
72
|
+
function contentParser(req, body, done) {
|
|
73
|
+
const parseBody = decodeURIComponent(body.toString())
|
|
74
|
+
.split('&')
|
|
75
|
+
.reduce((acc, el) => {
|
|
76
|
+
const [key, val] = el.split('=');
|
|
77
|
+
return { ...acc, [key]: val };
|
|
78
|
+
}, {});
|
|
79
|
+
done(null, parseBody);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
fastify.addContentTypeParser(
|
|
83
|
+
'application/x-www-form-urlencoded',
|
|
84
|
+
{ parseAs: 'buffer' },
|
|
85
|
+
contentParser
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default fp(plugin);
|
package/server/plugins/vite.js
CHANGED
|
@@ -1,55 +1,69 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import config from '../../config.js';
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import config from '../../config.js';
|
|
4
|
+
|
|
5
|
+
const { disableAuth } = config;
|
|
6
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
7
|
+
|
|
8
|
+
async function plugin(fastify) {
|
|
9
|
+
// vite server
|
|
10
|
+
if (!isProduction) {
|
|
11
|
+
const vite = await import('vite');
|
|
12
|
+
|
|
13
|
+
const viteServer = await vite.createServer({
|
|
14
|
+
server: {
|
|
15
|
+
middlewareMode: true,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
// hot reload
|
|
19
|
+
viteServer.watcher.on('all', (d, t) => {
|
|
20
|
+
if (!t.includes('module') && !t.includes('templates')) return;
|
|
21
|
+
// console.log(d, t);
|
|
22
|
+
viteServer.ws.send({ type: 'full-reload' });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// this is middleware for vite's dev servert
|
|
26
|
+
fastify.addHook('onRequest', async (req, reply) => {
|
|
27
|
+
// const { user } = req.session?.passport || {};
|
|
28
|
+
const next = () => new Promise((resolve) => {
|
|
29
|
+
viteServer.middlewares(req.raw, reply.raw, () => resolve());
|
|
30
|
+
});
|
|
31
|
+
await next();
|
|
32
|
+
});
|
|
33
|
+
fastify.get('*', async () => {});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// From Build
|
|
38
|
+
fastify.get('*', async (req, reply) => {
|
|
39
|
+
// console.log(disableAuth)
|
|
40
|
+
if (!req.user && !disableAuth) return reply.redirect('/login');
|
|
41
|
+
const stream = fs.createReadStream('dist/index.html');
|
|
42
|
+
return reply
|
|
43
|
+
.headers({ 'Cache-Control': 'public, no-cache' })
|
|
44
|
+
.type('text/html')
|
|
45
|
+
.send(stream);
|
|
46
|
+
});
|
|
47
|
+
fastify.get('/assets/:file', async (req, reply) => {
|
|
48
|
+
const stream = fs.createReadStream(`dist/assets/${req.params.file}`);
|
|
49
|
+
const ext = path.extname(req.params.file);
|
|
50
|
+
const mime = {
|
|
51
|
+
'.js': 'text/javascript',
|
|
52
|
+
'.css': 'text/css',
|
|
53
|
+
'.woff2': 'application/font-woff',
|
|
54
|
+
'.png': 'image/png',
|
|
55
|
+
}[ext];
|
|
56
|
+
// reply.cacheControl('max-age', '1d');
|
|
57
|
+
return mime
|
|
58
|
+
? reply
|
|
59
|
+
.headers({
|
|
60
|
+
'Cache-Control': 'public, max-age=3600',
|
|
61
|
+
'Content-Encoding': 'identity',
|
|
62
|
+
})
|
|
63
|
+
.type(mime)
|
|
64
|
+
.send(stream)
|
|
65
|
+
: stream;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default plugin;
|
|
@@ -1,35 +1,38 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
await pg.query(`delete from bi.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
1
|
+
import { existsSync, readdirSync } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import { pgClients } 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 data({ pg = pgClients.client, params = {} }) {
|
|
10
|
+
const { id } = params;
|
|
11
|
+
|
|
12
|
+
if (!id) {
|
|
13
|
+
return { message: 'not enough params: id', status: 400 };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const dirContent = existsSync(dashboardDir) ? readdirSync(dashboardDir) : [];
|
|
17
|
+
|
|
18
|
+
if (dirContent.includes(id)) {
|
|
19
|
+
return { message: `access restricted: ${id}`, status: 403 };
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const { rowCount } = await pg.query(
|
|
23
|
+
`select * from bi.dashboard where $1 in (dashboard_id,name)`,
|
|
24
|
+
[id]
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (rowCount === 0) {
|
|
28
|
+
return { message: `not found ${id}`, status: 404 };
|
|
29
|
+
}
|
|
30
|
+
await pg.query(`delete from bi.widget where $1 in (dashboard_id)`, [id]);
|
|
31
|
+
await pg.query(`delete from bi.dashboard where $1 in (dashboard_id,name)`, [
|
|
32
|
+
id,
|
|
33
|
+
]);
|
|
34
|
+
return { message: 'successfully deleted', status: 200 };
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return { error: err.toString(), status: 500 };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,80 +1,118 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export default async function
|
|
10
|
-
pg = pgClients.client,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
data
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const columns = fields.map(({ name, dataTypeID }) => ({
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
1
|
+
import yaml from 'js-yaml';
|
|
2
|
+
import {
|
|
3
|
+
pgClients,
|
|
4
|
+
getTemplatePath,
|
|
5
|
+
getTemplate,
|
|
6
|
+
getPGAsync,
|
|
7
|
+
} from '@opengis/fastify-table/utils.js';
|
|
8
|
+
|
|
9
|
+
export default async function dashboard({
|
|
10
|
+
pg = pgClients.client,
|
|
11
|
+
params = {},
|
|
12
|
+
}) {
|
|
13
|
+
const time = Date.now();
|
|
14
|
+
const { id } = params;
|
|
15
|
+
|
|
16
|
+
if (!id) {
|
|
17
|
+
return { message: 'not enough params: dashboard required', status: 400 };
|
|
18
|
+
}
|
|
19
|
+
const dashboards = await getTemplatePath('dashboard');
|
|
20
|
+
|
|
21
|
+
const fileDashboard = dashboards.find((el) => el[0] === id);
|
|
22
|
+
if (!fileDashboard) {
|
|
23
|
+
const sql = `select title, description, table_name, panels, grid, widgets, filters, style
|
|
24
|
+
from bi.dashboard where $1 in (dashboard_id, name)`;
|
|
25
|
+
|
|
26
|
+
const data = await pg.query(sql, [id]).then((res) => res.rows?.[0] || {});
|
|
27
|
+
data.type = 'bd';
|
|
28
|
+
const { table_name: table } = data;
|
|
29
|
+
|
|
30
|
+
if (!table) {
|
|
31
|
+
return { message: 'not enough params: table required', status: 400 };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { fields = [] } =
|
|
35
|
+
table && pg.pk?.[table]
|
|
36
|
+
? await pg.query(`select * from ${table} limit 0`)
|
|
37
|
+
: {};
|
|
38
|
+
|
|
39
|
+
const columns = table
|
|
40
|
+
? fields.map(({ name, dataTypeID }) => ({
|
|
41
|
+
name,
|
|
42
|
+
type: pg.pgType?.[dataTypeID],
|
|
43
|
+
}))
|
|
44
|
+
: [];
|
|
45
|
+
data?.widgets?.forEach?.(el => {
|
|
46
|
+
const { style, data = {}, type, title, x, metrics } = el;
|
|
47
|
+
el.yml = yaml.dump({ title, type, data: { x, metrics, ...data }, style, })
|
|
48
|
+
// el.yml = yaml.dump({ style, data, type, title });
|
|
49
|
+
})
|
|
50
|
+
return {
|
|
51
|
+
...data || {},
|
|
52
|
+
error:
|
|
53
|
+
table && !pg.pk?.[table] ? `table pkey not found: ${table}` : undefined,
|
|
54
|
+
table_name: table,
|
|
55
|
+
time: Date.now() - time,
|
|
56
|
+
columns,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const fileData = await getTemplate('dashboard', id);
|
|
61
|
+
const index = fileData.find((el) => el[0] === 'index.yml')[1];
|
|
62
|
+
|
|
63
|
+
if (!index) {
|
|
64
|
+
return { message: `not found ${id}`, status: 404 };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const data = index;
|
|
68
|
+
data.type = 'file';
|
|
69
|
+
const { table } = data?.data || { table: data?.table_name };
|
|
70
|
+
|
|
71
|
+
const pg1 = data.db ? await getPGAsync(data.db) : pg;
|
|
72
|
+
|
|
73
|
+
const { fields = [] } = table
|
|
74
|
+
? await pg1.query(`select * from ${table} limit 0`)
|
|
75
|
+
: {};
|
|
76
|
+
|
|
77
|
+
const columns = fields.map(({ name, dataTypeID }) => ({
|
|
78
|
+
name,
|
|
79
|
+
type: pg.pgType?.[dataTypeID],
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
const checks = index?.filters?.filter((el) => el?.id && columns.map((el) => el?.name).includes(el?.id) && el?.type === 'Check');
|
|
83
|
+
if (checks?.length) {
|
|
84
|
+
await Promise.all(checks.map(async (el) => {
|
|
85
|
+
if (el?.data) {
|
|
86
|
+
const options = await getTemplate('cls', el.data);
|
|
87
|
+
Object.assign(el, { options });
|
|
88
|
+
} else if (index?.table_name || index?.table) {
|
|
89
|
+
const { rows = [] } = await pg.query(`select "${el.id}" as id, count(*) from ${index?.table_name || index?.table} group by "${el.id}"`);
|
|
90
|
+
Object.assign(el, { options: rows });
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// console.log(fileData)
|
|
96
|
+
const widgets = fileData
|
|
97
|
+
.filter((el) => el[0] !== 'index.yml')
|
|
98
|
+
.map((el) =>
|
|
99
|
+
el[1].data
|
|
100
|
+
? {
|
|
101
|
+
name: el[0].split('.')[0],
|
|
102
|
+
type: el[1].type,
|
|
103
|
+
title: el[1].title,
|
|
104
|
+
style: el[1].style,
|
|
105
|
+
data: el[1].data,
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
: { name: el[0].split('.')[0], title: el[1] }
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
...data,
|
|
113
|
+
table_name: table,
|
|
114
|
+
time: Date.now() - time,
|
|
115
|
+
columns,
|
|
116
|
+
widgets,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -1,39 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const list = dir.concat(rows);
|
|
33
|
-
|
|
34
|
-
const res = {
|
|
35
|
-
time: Date.now() - time,
|
|
36
|
-
rows: list,
|
|
37
|
-
};
|
|
38
|
-
return res;
|
|
39
|
-
}
|
|
1
|
+
import { pgClients, getTemplate, getTemplatePath } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
// import yaml from './utils/yaml.js';
|
|
4
|
+
// const cwd = process.cwd();
|
|
5
|
+
|
|
6
|
+
const q = `select dashboard_id as name, 'db' as type, title, description, table_name from bi.dashboard`;
|
|
7
|
+
|
|
8
|
+
export default async function data({ pg = pgClients.client }) {
|
|
9
|
+
const time = Date.now();
|
|
10
|
+
const data = await getTemplatePath('dashboard');
|
|
11
|
+
const dir = await Promise.all(
|
|
12
|
+
data.map(async ([filename]) => {
|
|
13
|
+
const data = await getTemplate('dashboard', filename);
|
|
14
|
+
const index = data.find((el) => el[0] === 'index.yml')[1];
|
|
15
|
+
const { table_name, description, title } = index || {};
|
|
16
|
+
|
|
17
|
+
return { name: filename, type: 'file', title, description, table_name };
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const { rows = [] } = await pg.query(q);
|
|
22
|
+
|
|
23
|
+
const list = dir.concat(rows);
|
|
24
|
+
|
|
25
|
+
const res = {
|
|
26
|
+
time: Date.now() - time,
|
|
27
|
+
rows: list,
|
|
28
|
+
};
|
|
29
|
+
return res;
|
|
30
|
+
}
|