@opengis/bi 1.0.14 → 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.
Files changed (53) hide show
  1. package/README.md +50 -50
  2. package/config.js +12 -12
  3. package/dist/bi.js +1 -1
  4. package/dist/bi.umd.cjs +63 -63
  5. package/dist/{import-file-DUp3rsNI.js → import-file-CRC0sYYT.js} +8055 -7987
  6. package/dist/{map-component-mixin-CGM0P5ub.js → map-component-mixin-BCtWEvzv.js} +3795 -2116
  7. package/dist/style.css +1 -1
  8. package/dist/{vs-calendar-cOoinEwc.js → vs-calendar-5ot79n0N.js} +20 -9
  9. package/dist/{vs-funnel-bar-kLkPoIhJ.js → vs-funnel-bar-CLo6gXI_.js} +2 -2
  10. package/dist/{vs-heatmap-3XAVGTSo.js → vs-heatmap-DHGA8dRk.js} +3 -4
  11. package/dist/{vs-map-cluster-BWJPx7wE.js → vs-map-cluster-CNgX6JVF.js} +2 -2
  12. package/dist/{vs-map-B1tr6V5_.js → vs-map-pIn5wS4G.js} +2 -2
  13. package/dist/{vs-number-CrU7LmkV.js → vs-number-DYfok8VU.js} +19 -12
  14. package/dist/{vs-text-DRPx3aID.js → vs-text-Dckykz09.js} +19 -14
  15. package/package.json +107 -97
  16. package/plugin.js +14 -13
  17. package/server/migrations/bi.dataset.sql +26 -0
  18. package/server/migrations/bi.sql +93 -93
  19. package/server/plugins/docs.js +48 -48
  20. package/server/plugins/hook.js +89 -89
  21. package/server/plugins/vite.js +69 -69
  22. package/server/routes/dashboard/controllers/dashboard.delete.js +38 -37
  23. package/server/routes/dashboard/controllers/dashboard.js +118 -114
  24. package/server/routes/dashboard/controllers/dashboard.list.js +30 -36
  25. package/server/routes/dashboard/controllers/utils/yaml.js +11 -11
  26. package/server/routes/dashboard/index.mjs +25 -25
  27. package/server/routes/data/controllers/data.js +167 -156
  28. package/server/routes/data/controllers/util/chartSQL.js +42 -39
  29. package/server/routes/data/controllers/util/normalizeData.js +59 -56
  30. package/server/routes/data/index.mjs +29 -24
  31. package/server/routes/dataset/controllers/bi.dataset.demo.add.js +97 -0
  32. package/server/routes/dataset/controllers/bi.dataset.import.js +67 -0
  33. package/server/routes/dataset/controllers/util/create.table.js +22 -0
  34. package/server/routes/dataset/controllers/util/prepare.data.js +49 -0
  35. package/server/routes/dataset/index.mjs +19 -0
  36. package/server/routes/db/controllers/dbTablePreview.js +63 -63
  37. package/server/routes/db/controllers/dbTables.js +36 -36
  38. package/server/routes/db/index.mjs +17 -17
  39. package/server/routes/edit/controllers/dashboard.add.js +26 -24
  40. package/server/routes/edit/controllers/dashboard.edit.js +46 -44
  41. package/server/routes/edit/controllers/widget.add.js +75 -73
  42. package/server/routes/edit/controllers/widget.del.js +69 -70
  43. package/server/routes/edit/controllers/widget.edit.js +52 -103
  44. package/server/routes/edit/index.mjs +31 -31
  45. package/server/routes/map/controllers/cluster.js +109 -104
  46. package/server/routes/map/controllers/clusterVtile.js +166 -213
  47. package/server/routes/map/controllers/geojson.js +127 -127
  48. package/server/routes/map/controllers/map.js +60 -57
  49. package/server/routes/map/controllers/utils/downloadClusterData.js +43 -0
  50. package/server/routes/map/controllers/vtile.js +183 -182
  51. package/server/routes/map/index.mjs +25 -25
  52. package/server/utils/getWidget.js +85 -83
  53. package/utils.js +12 -12
@@ -1,73 +1,75 @@
1
- /* eslint-disable import/extensions */
2
- import { yamlSafe } from '../../../../utils.js';
3
-
4
- function generateUniqueName(prefix = 'bar') {
5
- const randomPart = Math.floor(Math.random() * 10000);
6
- const timestamp = Date.now();
7
- return `${prefix}_${randomPart}_${timestamp}`;
8
- }
9
-
10
- export default async function widgetAdd({ pg, funcs, params = {}, body = {} }) {
11
- const { name: dashboardName } = params;
12
- if (!dashboardName) {
13
- return { message: 'not enough params: id', status: 400 };
14
- }
15
- const data = body.yml ? yamlSafe.load(body.yml) : body;
16
- try {
17
- const row = await pg
18
- .query(
19
- 'select dashboard_id, widgets, panels, table_name from bi.dashboard where $1 in (dashboard_id,name)',
20
- [dashboardName]
21
- )
22
- .then((res) => res.rows?.[0] || {});
23
-
24
- const tableName =
25
- data.data?.table || data?.table || data.table_name || row.table_name;
26
-
27
- // const checkTable = await pg.query(
28
- // 'select * from bi.widget where $1 in (table_name)',
29
- // [tableName]
30
- // );
31
- // if (!checkTable.rows.length) {
32
- // return { message: 'bad params', status: 400 };
33
- // }
34
- if (!tableName || !pg.pk?.[tableName]) {
35
- return { message: 'bad params: table', status: 400 };
36
- }
37
-
38
- const { dashboard_id: dashboardId } = row;
39
-
40
- Object.assign(data, {
41
- name: generateUniqueName(data.type),
42
- table_name: tableName,
43
- metrics:
44
- (data.data?.metrics || data?.metrics)?.[0] ||
45
- data.data?.metrics ||
46
- data?.metrics,
47
- });
48
-
49
- const res = await funcs.dataUpdate({
50
- table: 'bi.dashboard',
51
- id: dashboardId,
52
- data: {
53
- widgets: [data].concat(row.widgets || []),
54
- panels: [{ widget: data.name, col: data.col || 3 }].concat(
55
- row.panels || []
56
- ),
57
- },
58
- });
59
- const widgetData = { ...data, data, dashboard_id: dashboardId };
60
- if (body?.yml) Object.assign(widgetData, { yml: body.yml });
61
- await funcs.dataInsert({
62
- table: 'bi.widget',
63
- data: widgetData,
64
- });
65
- return {
66
- message: `Added widget to ${dashboardName}`,
67
- status: 200,
68
- rows: res,
69
- };
70
- } catch (err) {
71
- return { error: err.toString(), status: 500 };
72
- }
73
- }
1
+ import { dataInsert, dataUpdate } from "@opengis/fastify-table/utils.js";
2
+
3
+ /* eslint-disable import/extensions */
4
+ import { yamlSafe } from '../../../../utils.js';
5
+
6
+ function generateUniqueName(prefix = 'bar') {
7
+ const randomPart = Math.floor(Math.random() * 10000);
8
+ const timestamp = Date.now();
9
+ return `${prefix}_${randomPart}_${timestamp}`;
10
+ }
11
+
12
+ export default async function widgetAdd({ pg, funcs, params = {}, body = {} }) {
13
+ const { name: dashboardName } = params;
14
+ if (!dashboardName) {
15
+ return { message: 'not enough params: id', status: 400 };
16
+ }
17
+ const data = body.yml ? yamlSafe.load(body.yml) : body;
18
+ try {
19
+ const row = await pg
20
+ .query(
21
+ 'select dashboard_id, widgets, panels, table_name from bi.dashboard where $1 in (dashboard_id,name)',
22
+ [dashboardName]
23
+ )
24
+ .then((res) => res.rows?.[0] || {});
25
+
26
+ const tableName =
27
+ data.data?.table || data?.table || data.table_name || row.table_name;
28
+
29
+ // const checkTable = await pg.query(
30
+ // 'select * from bi.widget where $1 in (table_name)',
31
+ // [tableName]
32
+ // );
33
+ // if (!checkTable.rows.length) {
34
+ // return { message: 'bad params', status: 400 };
35
+ // }
36
+ if (!tableName || !pg.pk?.[tableName]) {
37
+ return { message: 'bad params: table', status: 400 };
38
+ }
39
+
40
+ const { dashboard_id: dashboardId } = row;
41
+
42
+ Object.assign(data, {
43
+ name: generateUniqueName(data.type),
44
+ table_name: tableName,
45
+ metrics:
46
+ (data.data?.metrics || data?.metrics)?.[0] ||
47
+ data.data?.metrics ||
48
+ data?.metrics,
49
+ });
50
+
51
+ const res = await dataUpdate({
52
+ table: 'bi.dashboard',
53
+ id: dashboardId,
54
+ data: {
55
+ widgets: [data].concat(row.widgets || []),
56
+ panels: [{ widget: data.name, col: data.col || 3 }].concat(
57
+ row.panels || []
58
+ ),
59
+ },
60
+ });
61
+ const widgetData = { ...data, data, dashboard_id: dashboardId };
62
+ if (body?.yml) Object.assign(widgetData, { yml: body.yml });
63
+ await dataInsert({
64
+ table: 'bi.widget',
65
+ data: widgetData,
66
+ });
67
+ return {
68
+ message: `Added widget to ${dashboardName}`,
69
+ status: 200,
70
+ rows: res,
71
+ };
72
+ } catch (err) {
73
+ return { error: err.toString(), status: 500 };
74
+ }
75
+ }
@@ -1,70 +1,69 @@
1
- import dataDelete from '@opengis/fastify-table/crud/funcs/dataDelete.js';
2
- import dataUpdate from '@opengis/fastify-table/crud/funcs/dataUpdate.js';
3
-
4
- export default async function widgetDel({ pg = {}, params = {} }) {
5
- const { widget: widgetName, name: dashboardName } = params;
6
-
7
- if (!widgetName || !dashboardName) {
8
- return {
9
- message: 'not enough params: dashboard and widget name',
10
- status: 400,
11
- };
12
- }
13
-
14
- try {
15
- const row = await pg
16
- .query(
17
- `select a.widget_id, b.dashboard_id from bi.widget a, bi.dashboard b
18
- where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`,
19
- [dashboardName, widgetName]
20
- )
21
- .then((res1) => res1.rows?.[0] || {});
22
-
23
- const { widget_id: widgetId, dashboard_id: dashboardId } = row || {};
24
-
25
- if (!widgetId) {
26
- return { message: `widget not found ${widgetName}`, status: 404 };
27
- }
28
-
29
- const res = await dataDelete({
30
- table: 'bi.widget',
31
- id: widgetId,
32
- });
33
-
34
- const currentDashboard = await pg
35
- .query(
36
- `select * from bi.dashboard
37
- where $1 in (dashboard_id, name)`,
38
- [dashboardName]
39
- )
40
- .then((res1) => res1.rows?.[0] || {});
41
-
42
- const body = currentDashboard;
43
-
44
- if (!currentDashboard) {
45
- return { message: `dashboard not found ${dashboardName}`, status: 404 };
46
- }
47
- body.panels =
48
- Array.isArray(body.panels) && body.panels?.length
49
- ? body.panels?.filter((panel) => panel.widget !== widgetName)
50
- : undefined;
51
- body.widgets =
52
- Array.isArray(body.widgets) && body?.widgets?.length
53
- ? body.widgets?.filter((widget) => widget.name !== widgetName)
54
- : undefined;
55
-
56
- const res1 = await dataUpdate({
57
- table: 'bi.dashboard',
58
- id: dashboardId,
59
- data: body,
60
- });
61
-
62
- return {
63
- message: `Deleted widget ${widgetName}`,
64
- status: 200,
65
- rows: res1,
66
- };
67
- } catch (err) {
68
- return { error: err.toString(), status: 500 };
69
- }
70
- }
1
+ import { dataDelete, dataUpdate } from '@opengis/fastify-table/utils.js';
2
+
3
+ export default async function widgetDel({ pg = {}, params = {} }) {
4
+ const { widget: widgetName, name: dashboardName } = params;
5
+
6
+ if (!widgetName || !dashboardName) {
7
+ return {
8
+ message: 'not enough params: dashboard and widget name',
9
+ status: 400,
10
+ };
11
+ }
12
+
13
+ try {
14
+ const row = await pg
15
+ .query(
16
+ `select a.widget_id, b.dashboard_id from bi.widget a, bi.dashboard b
17
+ where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`,
18
+ [dashboardName, widgetName]
19
+ )
20
+ .then((res1) => res1.rows?.[0] || {});
21
+
22
+ const { widget_id: widgetId, dashboard_id: dashboardId } = row || {};
23
+
24
+ if (!widgetId) {
25
+ return { message: `widget not found ${widgetName}`, status: 404 };
26
+ }
27
+
28
+ const res = await dataDelete({
29
+ table: 'bi.widget',
30
+ id: widgetId,
31
+ });
32
+
33
+ const currentDashboard = await pg
34
+ .query(
35
+ `select * from bi.dashboard
36
+ where $1 in (dashboard_id, name)`,
37
+ [dashboardName]
38
+ )
39
+ .then((res1) => res1.rows?.[0] || {});
40
+
41
+ const body = currentDashboard;
42
+
43
+ if (!currentDashboard) {
44
+ return { message: `dashboard not found ${dashboardName}`, status: 404 };
45
+ }
46
+ body.panels =
47
+ Array.isArray(body.panels) && body.panels?.length
48
+ ? body.panels?.filter((panel) => panel.widget !== widgetName)
49
+ : undefined;
50
+ body.widgets =
51
+ Array.isArray(body.widgets) && body?.widgets?.length
52
+ ? body.widgets?.filter((widget) => widget.name !== widgetName)
53
+ : undefined;
54
+
55
+ const res1 = await dataUpdate({
56
+ table: 'bi.dashboard',
57
+ id: dashboardId,
58
+ data: body,
59
+ });
60
+
61
+ return {
62
+ message: `Deleted widget ${widgetName}`,
63
+ status: 200,
64
+ rows: res1,
65
+ };
66
+ } catch (err) {
67
+ return { error: err.toString(), status: 500 };
68
+ }
69
+ }
@@ -1,103 +1,52 @@
1
- import { dataUpdate } from '@opengis/fastify-table/utils.js';
2
-
3
- import { yamlSafe } from '../../../../utils.js';
4
-
5
- export default async function widgetEdit({
6
- pg = {},
7
- funcs = {},
8
- body = {},
9
- params = {},
10
- }) {
11
- const { widget: widgetName, name: dashboardName } = params;
12
- const data = body.yml ? yamlSafe.load(body.yml) : body;
13
- const tableName =
14
- data.data?.table || data?.table || data.table_name || body.table_name;
15
-
16
- if (!widgetName || !dashboardName) {
17
- return {
18
- message: 'not enough params: dashboard and widget name',
19
- status: 400,
20
- };
21
- }
22
-
23
- try {
24
- const row = await pg
25
- .query(
26
- `select a.widget_id, b.dashboard_id from bi.widget a, bi.dashboard b
27
- where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`,
28
- [dashboardName, widgetName]
29
- )
30
- .then((res1) => res1.rows?.[0] || {});
31
- const { widget_id: widgetId, dashboard_id: dashboardId } = row || {};
32
-
33
- // const checkTable = await pg.query(
34
- // `select * from bi.widget where $1 in (table_name)`,
35
- // [tableName]
36
- // );
37
- // if (!checkTable.rows.length) {
38
- // return { message: 'bad params', status: 401 };
39
- // }
40
-
41
- if (!tableName || !pg.pk?.[tableName]) {
42
- return { message: 'bad params: table', status: 400 };
43
- }
44
-
45
- if (!widgetId) {
46
- return { message: `widget not found ${widgetName}`, status: 404 };
47
- }
48
-
49
- const widgetData = { ...data, data };
50
- if (body?.yml) Object.assign(widgetData, { yml: body.yml });
51
- await funcs.dataUpdate({
52
- table: 'bi.widget',
53
- id: widgetId,
54
- data: widgetData,
55
- });
56
-
57
- // \====================
58
- const currentDashboard = await pg
59
- .query(
60
- `select * from bi.dashboard
61
- where $1 in (dashboard_id, name)`,
62
- [dashboardName]
63
- )
64
- .then((res1) => res1.rows?.[0] || {});
65
- const bodyDashboard = currentDashboard;
66
-
67
- if (!currentDashboard) {
68
- return { message: `dashboard not found ${dashboardName}`, status: 404 };
69
- }
70
- bodyDashboard.panels =
71
- Array.isArray(bodyDashboard.panels) && bodyDashboard.panels?.length
72
- ? bodyDashboard.panels?.map((panel) => {
73
- if (panel.widget === widgetName) {
74
- panel.col = body.col;
75
- }
76
- return panel;
77
- })
78
- : undefined;
79
- bodyDashboard.widgets =
80
- Array.isArray(bodyDashboard.widgets) && bodyDashboard?.widgets?.length
81
- ? bodyDashboard.widgets?.map((widget) => {
82
- if (widget.name === widgetName) {
83
- return body;
84
- }
85
- return widget;
86
- })
87
- : undefined;
88
-
89
- const res1 = await dataUpdate({
90
- table: 'bi.dashboard',
91
- id: dashboardId,
92
- data: bodyDashboard,
93
- });
94
-
95
- return {
96
- message: `Edited widget ${widgetName}`,
97
- status: 200,
98
- rows: res1,
99
- };
100
- } catch (err) {
101
- return { error: err.toString(), status: 500 };
102
- }
103
- }
1
+ import { dataUpdate } from '@opengis/fastify-table/utils.js';
2
+
3
+ import { yamlSafe } from '../../../../utils.js';
4
+
5
+ export default async function widgetEdit({ pg, body, params, }) {
6
+ const { widget: widgetName, name: dashboardName } = params;
7
+ const data = body.yml && !body.style ? yamlSafe.load(body.yml) : body;
8
+
9
+ const tableName =
10
+ data.data?.table || data?.table || data.table_name || body.table_name;
11
+
12
+ if (!widgetName || !dashboardName) {
13
+ return {
14
+ message: 'not enough params: dashboard and widget name',
15
+ status: 400,
16
+ };
17
+ }
18
+
19
+
20
+ const { widget_id: widgetId } = await pg.query(
21
+ `select a.widget_id , b.dashboard_id from bi.widget a, bi.dashboard b
22
+ where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`,
23
+ [dashboardName, widgetName]
24
+ ).then((res1) => res1.rows?.[0] || {});
25
+
26
+ if (!widgetId) {
27
+ return { message: `widget not found ${widgetName}`, status: 404 };
28
+ }
29
+
30
+ if (!tableName || !pg.pk?.[tableName]) {
31
+ return { message: 'bad params: table', status: 400 };
32
+ }
33
+
34
+
35
+
36
+ // const widgetData = { ...data, data };
37
+ const widgetData = body.yml && !body.style ? data : { style: data.style, data: { x: data.x, metrics: data.metrics }, controls: data.controls, type: data.type, title: data.title, table_name: data.table_name };
38
+ // console.log(widgetId, widgetData)
39
+ if (body?.yml) Object.assign(widgetData, { yml: body.yml });
40
+ const rows = await dataUpdate({
41
+ table: 'bi.widget',
42
+ id: widgetId,
43
+ data: widgetData,
44
+ });
45
+
46
+ return {
47
+ message: rows,
48
+ status: 200,
49
+
50
+ };
51
+
52
+ }
@@ -1,31 +1,31 @@
1
- /* eslint-disable import/extensions */
2
- import widgetAdd from './controllers/widget.add.js';
3
- import widgetEdit from './controllers/widget.edit.js';
4
- import widgetDel from './controllers/widget.del.js';
5
- import dashboardEdit from './controllers/dashboard.edit.js';
6
- import dashboardAdd from './controllers/dashboard.add.js';
7
-
8
- const biSchema = {
9
- querystring: {
10
- widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
11
- dashboard: { type: 'string', pattern: '^([\\d\\w]+)$' },
12
- list: { type: 'string', pattern: '^([\\d])$' },
13
- sql: { type: 'string', pattern: '^([\\d])$' },
14
- },
15
- params: {
16
- name: { type: 'string', pattern: '^([\\d\\w]+)$' },
17
- widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
18
- },
19
- };
20
-
21
- export default async function route(fastify) {
22
- fastify.post(`/bi-dashboard/:name`, { schema: biSchema }, widgetAdd);
23
- fastify.put(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetEdit);
24
- fastify.delete(
25
- `/bi-dashboard/:name/:widget`,
26
- { schema: biSchema },
27
- widgetDel
28
- );
29
- fastify.post(`/bi-dashboard`, { schema: biSchema }, dashboardAdd);
30
- fastify.put(`/bi-dashboard/:name`, { schema: biSchema }, dashboardEdit);
31
- }
1
+ /* eslint-disable import/extensions */
2
+ import widgetAdd from './controllers/widget.add.js';
3
+ import widgetEdit from './controllers/widget.edit.js';
4
+ import widgetDel from './controllers/widget.del.js';
5
+ import dashboardEdit from './controllers/dashboard.edit.js';
6
+ import dashboardAdd from './controllers/dashboard.add.js';
7
+
8
+ const biSchema = {
9
+ querystring: {
10
+ widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
11
+ dashboard: { type: 'string', pattern: '^([\\d\\w]+)$' },
12
+ list: { type: 'string', pattern: '^([\\d])$' },
13
+ sql: { type: 'string', pattern: '^([\\d])$' },
14
+ },
15
+ params: {
16
+ name: { type: 'string', pattern: '^([\\d\\w]+)$' },
17
+ widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
18
+ },
19
+ };
20
+
21
+ export default async function route(fastify) {
22
+ fastify.post(`/bi-dashboard/:name`, { schema: biSchema }, widgetAdd);
23
+ fastify.put(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetEdit);
24
+ fastify.delete(
25
+ `/bi-dashboard/:name/:widget`,
26
+ { schema: biSchema },
27
+ widgetDel
28
+ );
29
+ fastify.post(`/bi-dashboard`, { schema: biSchema }, dashboardAdd);
30
+ fastify.put(`/bi-dashboard/:name`, { schema: biSchema }, dashboardEdit);
31
+ }