@opengis/bi 1.0.13 → 1.0.14

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 (50) hide show
  1. package/README.md +2 -4
  2. package/config.js +5 -5
  3. package/dist/bi.js +1 -1
  4. package/dist/bi.umd.cjs +116 -130
  5. package/dist/{import-file-1T7kpSzt.js → import-file-DUp3rsNI.js} +11132 -10748
  6. package/dist/{map-component-mixin-BLM9iEWA.js → map-component-mixin-CGM0P5ub.js} +1135 -1134
  7. package/dist/style.css +1 -1
  8. package/dist/{vs-calendar-WiK1hcHS.js → vs-calendar-cOoinEwc.js} +33 -30
  9. package/dist/vs-funnel-bar-kLkPoIhJ.js +105 -0
  10. package/dist/vs-heatmap-3XAVGTSo.js +98 -0
  11. package/dist/vs-map-B1tr6V5_.js +74 -0
  12. package/dist/{vs-map-cluster-Dfe9INqE.js → vs-map-cluster-BWJPx7wE.js} +28 -25
  13. package/dist/vs-number-CrU7LmkV.js +48 -0
  14. package/dist/{vs-text-DcrAdQ40.js → vs-text-DRPx3aID.js} +2 -1
  15. package/package.json +37 -12
  16. package/plugin.js +4 -4
  17. package/server/migrations/bi.sql +66 -0
  18. package/server/plugins/docs.js +36 -35
  19. package/server/plugins/hook.js +72 -69
  20. package/server/plugins/vite.js +22 -8
  21. package/server/routes/dashboard/controllers/dashboard.delete.js +5 -3
  22. package/server/routes/dashboard/controllers/dashboard.js +66 -32
  23. package/server/routes/dashboard/controllers/dashboard.list.js +2 -5
  24. package/server/routes/dashboard/controllers/utils/yaml.js +1 -2
  25. package/server/routes/dashboard/index.mjs +5 -4
  26. package/server/routes/data/controllers/data.js +94 -34
  27. package/server/routes/data/controllers/util/chartSQL.js +24 -10
  28. package/server/routes/data/controllers/util/normalizeData.js +51 -29
  29. package/server/routes/data/index.mjs +1 -3
  30. package/server/routes/db/controllers/dbTablePreview.js +63 -0
  31. package/server/routes/db/controllers/dbTables.js +36 -0
  32. package/server/routes/db/index.mjs +17 -0
  33. package/server/routes/edit/controllers/dashboard.add.js +6 -5
  34. package/server/routes/edit/controllers/dashboard.edit.js +16 -9
  35. package/server/routes/edit/controllers/widget.add.js +43 -19
  36. package/server/routes/edit/controllers/widget.del.js +13 -6
  37. package/server/routes/edit/controllers/widget.edit.js +34 -13
  38. package/server/routes/edit/index.mjs +14 -10
  39. package/server/routes/map/controllers/cluster.js +89 -60
  40. package/server/routes/map/controllers/clusterVtile.js +154 -84
  41. package/server/routes/map/controllers/geojson.js +48 -22
  42. package/server/routes/map/controllers/map.js +51 -51
  43. package/server/routes/map/controllers/vtile.js +61 -40
  44. package/server/routes/map/index.mjs +1 -1
  45. package/server/utils/getWidget.js +67 -40
  46. package/utils.js +5 -4
  47. package/dist/vs-funnel-bar-CpPbYZ0_.js +0 -92
  48. package/dist/vs-heatmap-BG4eIROH.js +0 -83
  49. package/dist/vs-map-BRk6Fmks.js +0 -66
  50. package/dist/vs-number-CJq-vi95.js +0 -39
package/plugin.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import fp from 'fastify-plugin';
2
2
  import config from './config.js';
3
- config.prefix = config.prefix || '/api'
4
- async function plugin(fastify, opts = config) {
5
3
 
4
+ config.prefix = config.prefix || '/api';
5
+ async function plugin(fastify, opts = config) {
6
6
  // API
7
7
  fastify.register(import('./server/routes/dashboard/index.mjs'), config);
8
+ fastify.register(import('./server/routes/db/index.mjs'), config);
8
9
  fastify.register(import('./server/routes/data/index.mjs'), config);
9
10
  fastify.register(import('./server/routes/edit/index.mjs'), config);
10
-
11
11
  }
12
12
 
13
- export default fp(plugin)
13
+ export default fp(plugin);
@@ -1,3 +1,69 @@
1
+ create schema if not exists bi;
2
+
3
+ CREATE TABLE if not exists bi.dashboard ();
4
+ alter table bi.dashboard drop constraint if exists dashboard_id_pkey cascade;
5
+
6
+ alter table bi.dashboard add column if not exists dashboard_id text;
7
+ alter table bi.dashboard alter column dashboard_id set not null;
8
+ alter table bi.dashboard alter column dashboard_id set default next_id();
9
+
10
+ alter table bi.dashboard add column if not exists title text;
11
+ alter table bi.dashboard add column if not exists description text;
12
+ alter table bi.dashboard add column if not exists widgets json;
13
+ alter table bi.dashboard add column if not exists table_name text;
14
+ alter table bi.dashboard add column if not exists style json;
15
+ alter table bi.dashboard add column if not exists name text;
16
+ alter table bi.dashboard alter column name set not null;
17
+ alter table bi.dashboard add column if not exists panels json;
18
+ alter table bi.dashboard add column if not exists grid json;
19
+ alter table bi.dashboard add column if not exists filters json;
20
+
21
+ alter table bi.dashboard add CONSTRAINT dashboard_id_pkey PRIMARY KEY (dashboard_id);
22
+
23
+ COMMENT ON TABLE bi.dashboard IS 'Дашборди';
24
+ COMMENT ON COLUMN bi.dashboard.dashboard_id IS 'PK';
25
+ COMMENT ON COLUMN bi.dashboard.title IS 'Заголовок';
26
+ COMMENT ON COLUMN bi.dashboard.description IS 'Опис';
27
+ COMMENT ON COLUMN bi.dashboard.widgets IS 'Віджети';
28
+ COMMENT ON COLUMN bi.dashboard.table_name IS 'Назва таблиці';
29
+ COMMENT ON COLUMN bi.dashboard.style IS 'Стилі';
30
+ COMMENT ON COLUMN bi.dashboard.name IS 'Назва';
31
+ COMMENT ON COLUMN bi.dashboard.panels IS 'Панелі віджетів';
32
+ COMMENT ON COLUMN bi.dashboard.grid IS 'Сітка';
33
+ COMMENT ON COLUMN bi.dashboard.filters IS 'Фільтри';
34
+
35
+ CREATE TABLE if not exists bi.widget ();
36
+ alter table bi.widget drop constraint if exists widget_id_pk;
37
+ alter table bi.widget drop constraint if exists widget_id_fkey;
38
+
39
+ alter table bi.widget add column if not exists widget_id text;
40
+ alter table bi.widget alter column widget_id set not null;
41
+ alter table bi.widget alter column widget_id set default next_id();
42
+ alter table bi.widget add column if not exists type text;
43
+ alter table bi.widget add column if not exists title text;
44
+ alter table bi.widget add column if not exists style json;
45
+ alter table bi.widget add column if not exists data json;
46
+ alter table bi.widget add column if not exists table_name text;
47
+ alter table bi.widget add column if not exists dashboard_id text;
48
+ alter table bi.widget add column if not exists name text;
49
+ alter table bi.widget add column if not exists x text;
50
+ alter table bi.widget add column if not exists col numeric;
51
+ alter table bi.widget add column if not exists metrics text;
52
+ alter table bi.widget add column if not exists yml text;
53
+
54
+ alter table bi.widget add CONSTRAINT widget_id_pk PRIMARY KEY (widget_id);
55
+ alter table bi.widget add CONSTRAINT widget_id_fkey FOREIGN KEY (dashboard_id) REFERENCES bi.dashboard (dashboard_id);
56
+
57
+ COMMENT ON TABLE bi.widget IS 'Віджети';
58
+ COMMENT ON COLUMN bi.widget.widget_id IS 'PK';
59
+ COMMENT ON COLUMN bi.widget.type IS 'Тип';
60
+ COMMENT ON COLUMN bi.widget.title IS 'Назва';
61
+ COMMENT ON COLUMN bi.widget.style IS 'Стилі';
62
+ COMMENT ON COLUMN bi.widget.yml IS 'Yml';
63
+ COMMENT ON COLUMN bi.widget.data IS 'Дані';
64
+ COMMENT ON COLUMN bi.widget.table_name IS 'Назва таблиці';
65
+ COMMENT ON COLUMN bi.widget.dashboard_id IS 'Ідентифікатор дашборду';
66
+
1
67
  create table if not exists bi.cluster();
2
68
  alter table bi.cluster drop constraint if exists bi_cluster_cluster_id_pkey;
3
69
  alter table bi.cluster drop constraint if exists bi_cluster_title_type_unique;
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import path, { dirname } from 'path';
4
2
  import { fileURLToPath } from 'url';
5
3
  import fs from 'fs';
@@ -8,40 +6,43 @@ const dir = dirname(fileURLToPath(import.meta.url));
8
6
  const root = `${dir}/../../`;
9
7
 
10
8
  async function plugin(fastify, opts) {
11
- fastify.get('/docs-dev*', async (req, reply) => {
12
- if (!fs.existsSync(path.join(root, 'docs-dev/.vitepress/dist/'))) {
13
- return reply.status(404).send('docs not exists');
14
- }
15
-
16
- const { params } = req;
17
- const url = params['*'];
18
-
19
- const filePath = url && url[url.length - 1] !== '/' ? path.join(root, 'docs-dev/.vitepress/dist/', url) : path.join(root, 'docs-dev/.vitepress/dist/', url, 'index.html');
20
-
21
- if (!fs.existsSync(filePath)) {
22
- return reply.status(404).send('File not found');
23
- }
24
-
25
- const ext = path.extname(filePath);
26
- const mime = {
27
- '.js': 'text/javascript',
28
- '.css': 'text/css',
29
- '.woff2': 'application/font-woff',
30
- '.png': 'image/png',
31
- '.svg': 'image/svg+xml',
32
- '.jpg': 'image/jpg',
33
- '.html': 'text/html',
34
- '.json': 'application/json',
35
- '.pdf': 'application/pdf'
36
- }[ext];
37
-
38
- const stream = fs.createReadStream(filePath);
39
- stream.on('error', (err) => {
40
- reply.status(500).send('Error reading file');
41
- });
42
-
43
- return mime ? reply.type(mime).send(stream) : reply.send(stream);
9
+ fastify.get('/docs-dev*', async (req, reply) => {
10
+ if (!fs.existsSync(path.join(root, 'docs-dev/.vitepress/dist/'))) {
11
+ return reply.status(404).send('docs not exists');
12
+ }
13
+
14
+ const { params } = req;
15
+ const url = params['*'];
16
+
17
+ const filePath =
18
+ url && url[url.length - 1] !== '/'
19
+ ? path.join(root, 'docs-dev/.vitepress/dist/', url)
20
+ : path.join(root, 'docs-dev/.vitepress/dist/', url, 'index.html');
21
+
22
+ if (!fs.existsSync(filePath)) {
23
+ return reply.status(404).send('File not found');
24
+ }
25
+
26
+ const ext = path.extname(filePath);
27
+ const mime = {
28
+ '.js': 'text/javascript',
29
+ '.css': 'text/css',
30
+ '.woff2': 'application/font-woff',
31
+ '.png': 'image/png',
32
+ '.svg': 'image/svg+xml',
33
+ '.jpg': 'image/jpg',
34
+ '.html': 'text/html',
35
+ '.json': 'application/json',
36
+ '.pdf': 'application/pdf',
37
+ }[ext];
38
+
39
+ const stream = fs.createReadStream(filePath);
40
+ stream.on('error', (err) => {
41
+ reply.status(500).send('Error reading file');
44
42
  });
43
+
44
+ return mime ? reply.type(mime).send(stream) : reply.send(stream);
45
+ });
45
46
  }
46
47
 
47
48
  export default plugin;
@@ -1,86 +1,89 @@
1
1
  import fp from 'fastify-plugin';
2
2
  import fs from 'fs';
3
3
 
4
-
5
4
  // the use of fastify-plugin is required to be able
6
5
  // to export the decorators to the outer scope
7
6
 
8
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
+ }
9
22
 
10
-
11
-
12
-
13
- // preSerialization
14
- fastify.addHook('preSerialization', async (req, reply, payload) => {
15
- if (!req.session?.passport?.user?.uid) {
16
- // return reply.redirect('/login');
17
- }
18
- if (req.url.includes('/suggest/') && !req.query.json) {
19
- return payload?.data;
20
- }
21
- if (payload.redirect) {
22
- return reply.redirect(payload.redirect);
23
- }
24
- if (reply.sent) {
25
- return null;
26
- }
27
-
28
- if (payload.status) {
29
- reply.status(payload.status);
30
- }
31
- /*if (payload.headers) {
23
+ if (payload.status) {
24
+ reply.status(payload.status);
25
+ }
26
+ /* if (payload.headers) {
32
27
  reply.headers(payload.headers);
33
- }*/
34
- if (payload.buffer) {
35
- return payload.buffer;
36
- }
37
- if (payload.file) {
38
- // const buffer = await readFile(payload.file);
39
- // return reply.send(buffer);
40
- const stream = fs.createReadStream(payload.file);
41
- return stream;
42
- // return reply.send(stream);
43
- }
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
+ }
44
39
 
45
- if (payload.message) {
46
- return payload.message;
47
- }
48
- return payload;
49
- });
40
+ if (payload.message) {
41
+ return payload.message;
42
+ }
43
+ return payload;
44
+ });
50
45
 
51
- // preValidation
52
- fastify.addHook('preValidation', async (req) => {
53
- const parseRawBody = ['POST', 'PUT'].includes(req.method) && req.body && typeof req.body === 'string'
54
- && req.body.trim(/\r\n/g).startsWith('{')
55
- && req.body.trim(/\r\n/g).endsWith('}');
56
- if (parseRawBody) {
57
- try {
58
- req.body = JSON.parse(req.body || '{}');
59
- }
60
- catch (err) {
61
- // throw new Error('invalid body');
62
- // return { error: 'invalid body', status: 400 };
63
- }
64
- }
65
- });
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
+ });
66
63
 
67
- // allow upload file
68
- const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
69
- fastify.addContentTypeParser('multipart', (request, _, done) => {
70
- request[kIsMultipart] = true;
71
- done(null);
72
- });
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
+ });
73
70
 
74
- // parse Body
75
- function contentParser(req, body, done) {
76
- const parseBody = decodeURIComponent(body.toString()).split('&').reduce((acc, el) => {
77
- const [key, val] = el.split('=');
78
- return { ...acc, [key]: val };
79
- }, {});
80
- done(null, parseBody);
81
- }
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
+ }
82
81
 
83
- fastify.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'buffer' }, contentParser);
82
+ fastify.addContentTypeParser(
83
+ 'application/x-www-form-urlencoded',
84
+ { parseAs: 'buffer' },
85
+ contentParser
86
+ );
84
87
  }
85
88
 
86
89
  export default fp(plugin);
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import config from '../../config.js';
4
+
4
5
  const { disableAuth } = config;
5
6
  const isProduction = process.env.NODE_ENV === 'production';
6
7
 
@@ -15,9 +16,9 @@ async function plugin(fastify) {
15
16
  },
16
17
  });
17
18
  // hot reload
18
- viteServer.watcher.on('all', function (d, t) {
19
+ viteServer.watcher.on('all', (d, t) => {
19
20
  if (!t.includes('module') && !t.includes('templates')) return;
20
- console.log(d, t);
21
+ // console.log(d, t);
21
22
  viteServer.ws.send({ type: 'full-reload' });
22
23
  });
23
24
 
@@ -29,7 +30,7 @@ async function plugin(fastify) {
29
30
  });
30
31
  await next();
31
32
  });
32
- fastify.get('*', async () => { });
33
+ fastify.get('*', async () => {});
33
34
  return;
34
35
  }
35
36
 
@@ -38,17 +39,30 @@ async function plugin(fastify) {
38
39
  // console.log(disableAuth)
39
40
  if (!req.user && !disableAuth) return reply.redirect('/login');
40
41
  const stream = fs.createReadStream('dist/index.html');
41
- return reply.headers({ 'Cache-Control': 'public, no-cache' }).type('text/html').send(stream);
42
+ return reply
43
+ .headers({ 'Cache-Control': 'public, no-cache' })
44
+ .type('text/html')
45
+ .send(stream);
42
46
  });
43
47
  fastify.get('/assets/:file', async (req, reply) => {
44
48
  const stream = fs.createReadStream(`dist/assets/${req.params.file}`);
45
49
  const ext = path.extname(req.params.file);
46
50
  const mime = {
47
- '.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png',
51
+ '.js': 'text/javascript',
52
+ '.css': 'text/css',
53
+ '.woff2': 'application/font-woff',
54
+ '.png': 'image/png',
48
55
  }[ext];
49
- //reply.cacheControl('max-age', '1d');
50
- return mime ? reply.headers({ 'Cache-Control': 'public, max-age=3600' }).type(mime).send(stream) : stream;
51
-
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;
52
66
  });
53
67
  }
54
68
 
@@ -15,7 +15,7 @@ export default async function data({ pg = pgClients.client, params = {} }) {
15
15
  const dirContent = existsSync(dashboardDir) ? readdirSync(dashboardDir) : [];
16
16
 
17
17
  if (dirContent.includes(id)) {
18
- return { message: 'access restricted: ' + id, status: 403 };
18
+ return { message: `access restricted: ${id}`, status: 403 };
19
19
  }
20
20
  try {
21
21
  const { rowCount } = await pg.query(
@@ -24,10 +24,12 @@ export default async function data({ pg = pgClients.client, params = {} }) {
24
24
  );
25
25
 
26
26
  if (rowCount === 0) {
27
- return { message: 'not found ' + id, status: 404 };
27
+ return { message: `not found ${id}`, status: 404 };
28
28
  }
29
29
  await pg.query(`delete from bi.widget where $1 in (dashboard_id)`, [id]);
30
- await pg.query(`delete from bi.dashboard where $1 in (dashboard_id,name)`, [id]);
30
+ await pg.query(`delete from bi.dashboard where $1 in (dashboard_id,name)`, [
31
+ id,
32
+ ]);
31
33
  return { message: 'successfully deleted', status: 200 };
32
34
  } catch (err) {
33
35
  return { error: err.toString(), status: 500 };
@@ -1,13 +1,14 @@
1
- import path from 'path';
2
- import { existsSync, readFileSync, readdirSync } from 'fs';
3
-
4
- import pgClients from '@opengis/fastify-table/pg/pgClients.js';
5
- import getTemplatePath from '@opengis/fastify-table/table/controllers/utils/getTemplatePath.js';
6
- import { getTemplate } from '@opengis/fastify-table/utils.js';
7
- import { getPGAsync } from '@opengis/fastify-table/utils.js';
8
-
9
- export default async function data({
10
- pg = pgClients.client, params = {},
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 = {},
11
12
  }) {
12
13
  const time = Date.now();
13
14
  const { id } = params;
@@ -17,7 +18,7 @@ export default async function data({
17
18
  }
18
19
  const dashboards = await getTemplatePath('dashboard');
19
20
 
20
- const fileDashboard = dashboards.find(el => el[0] === id)
21
+ const fileDashboard = dashboards.find((el) => el[0] === id);
21
22
  if (!fileDashboard) {
22
23
  const sql = `select title, description, table_name, panels, grid, widgets, filters, style
23
24
  from bi.dashboard where $1 in (dashboard_id, name)`;
@@ -30,29 +31,50 @@ export default async function data({
30
31
  return { message: 'not enough params: table required', status: 400 };
31
32
  }
32
33
 
33
- const { fields = [] } = table && pg.pk?.[table] ? await pg.query(`select * from ${table} limit 1`) : {};
34
-
35
- const columns = table ? fields.map(({ name, dataTypeID }) => ({ name, type: pg.pgType?.[dataTypeID] })) : [];
36
- return { ...data, error: table && !pg.pk?.[table] ? `table pkey not found: ${table}` : undefined, table_name: table, time: Date.now() - time, columns };
34
+ const { fields = [] } =
35
+ table && pg.pk?.[table]
36
+ ? await pg.query(`select * from ${table} limit 1`)
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
+ };
37
58
  }
38
59
 
39
-
40
-
41
60
  const fileData = await getTemplate('dashboard', id);
42
- const index = fileData.find(el => el[0] === 'index.yml')[1]
61
+ const index = fileData.find((el) => el[0] === 'index.yml')[1];
43
62
 
44
63
  if (!index) {
45
- return { message: 'not found ' + id, status: 404 };
64
+ return { message: `not found ${id}`, status: 404 };
46
65
  }
47
66
 
48
67
  if (index?.filters?.filter((el) => el?.type === 'Check')?.length) {
49
- await Promise.all(index.filters.filter((el) => el?.type === 'Check' && el?.data).map(async (el) => {
50
- const options = await getTemplate('cls', el.data);
51
- Object.assign(el, { options });
52
- }));
68
+ await Promise.all(
69
+ index.filters
70
+ .filter((el) => el?.type === 'Check' && el?.data)
71
+ .map(async (el) => {
72
+ const options = await getTemplate('cls', el.data);
73
+ Object.assign(el, { options });
74
+ })
75
+ );
53
76
  }
54
77
 
55
-
56
78
  const data = index;
57
79
  data.type = 'file';
58
80
  const { table } = data?.data || { table: data?.table_name };
@@ -66,15 +88,27 @@ export default async function data({
66
88
  type: el[1].type,
67
89
  title: el[1].title,
68
90
  style: el[1].style,
69
- data: el[1].data
91
+ data: el[1].data,
92
+
70
93
  }
71
94
  : { name: el[0].split('.')[0], title: el[1] }
72
95
  );
73
- const pg1 = data.db ? await getPGAsync(data.db) : pg
74
-
75
- const { fields = [] } = table ? await pg1.query(`select * from ${table} limit 1`) : {};
76
-
77
- const columns = fields.map(({ name, dataTypeID }) => ({ name, type: pg.pgType?.[dataTypeID] }));
78
-
79
- return { ...data, table_name: table, time: Date.now() - time, columns, widgets };
96
+ const pg1 = data.db ? await getPGAsync(data.db) : pg;
97
+
98
+ const { fields = [] } = table
99
+ ? await pg1.query(`select * from ${table} limit 1`)
100
+ : {};
101
+
102
+ const columns = fields.map(({ name, dataTypeID }) => ({
103
+ name,
104
+ type: pg.pgType?.[dataTypeID],
105
+ }));
106
+
107
+ return {
108
+ ...data,
109
+ table_name: table,
110
+ time: Date.now() - time,
111
+ columns,
112
+ widgets,
113
+ };
80
114
  }
@@ -5,12 +5,10 @@ import { getTemplate } from '@opengis/fastify-table/utils.js';
5
5
  import getTemplatePath from '@opengis/fastify-table/table/controllers/utils/getTemplatePath.js';
6
6
 
7
7
  import yaml from './utils/yaml.js';
8
- //import getTemplate from '@opengis/fastify-table/table/controllers/utils/getTemplate.js';
9
-
8
+ // import getTemplate from '@opengis/fastify-table/table/controllers/utils/getTemplate.js';
10
9
 
11
10
  const cwd = process.cwd();
12
11
 
13
-
14
12
  const q = `select dashboard_id as name, 'db' as type, title, description, table_name from bi.dashboard`;
15
13
 
16
14
  export default async function data({ pg = pgClients.client }) {
@@ -18,9 +16,8 @@ export default async function data({ pg = pgClients.client }) {
18
16
  const data = await getTemplatePath('dashboard');
19
17
  const dir = await Promise.all(
20
18
  data.map(async ([filename]) => {
21
-
22
19
  const data = await getTemplate('dashboard', filename);
23
- const index = data.find(el => el[0] === 'index.yml')[1]
20
+ const index = data.find((el) => el[0] === 'index.yml')[1];
24
21
  const { table_name, description, title } = index || {};
25
22
 
26
23
  return { name: filename, type: 'file', title, description, table_name };
@@ -3,8 +3,7 @@ import yaml from 'js-yaml';
3
3
  yaml.loadSafe = (yml) => {
4
4
  try {
5
5
  return yaml.load(yml);
6
- }
7
- catch (err) {
6
+ } catch (err) {
8
7
  return { error: err.toString() };
9
8
  }
10
9
  };
@@ -8,17 +8,18 @@ const biSchema = {
8
8
  widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
9
9
  dashboard: { type: 'string', pattern: '^([\\d\\w]+)$' },
10
10
  list: { type: 'string', pattern: '^([\\d])$' },
11
- sql: { type: 'string', pattern: '^([\\d])$' }
11
+ sql: { type: 'string', pattern: '^([\\d])$' },
12
12
  },
13
13
  params: {
14
14
  id: { type: 'string', pattern: '^([\\d\\w]+)$' },
15
15
  },
16
16
  };
17
17
 
18
-
19
18
  export default async function route(fastify) {
20
19
  fastify.get(`/bi-dashboard/:id`, { schema: biSchema }, dashboard);
21
20
  fastify.get(`/bi-dashboard`, dashboardList);
22
21
  fastify.delete(`/bi-dashboard/:id`, dashboardDelete);
23
- fastify.get(`/bi-test`, () => { return { test: '2' }});
24
- }
22
+ fastify.get(`/bi-test`, () => {
23
+ return { test: '2' };
24
+ });
25
+ }