@opengis/bi 1.2.32 → 1.2.34

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 (74) hide show
  1. package/README.md +92 -92
  2. package/dist/bi.js +1 -1
  3. package/dist/bi.umd.cjs +68 -68
  4. package/dist/{import-file-D-ISqB7l.js → import-file-BwxPX622.js} +1132 -1079
  5. package/dist/style.css +1 -1
  6. package/dist/{vs-funnel-bar-aoZzvriV.js → vs-funnel-bar-BV18EA4K.js} +3 -3
  7. package/dist/{vs-list-CBkyJSBj.js → vs-list-WrrWQ5KF.js} +32 -53
  8. package/dist/{vs-map-C3C11qmT.js → vs-map-CYd9vdrd.js} +3 -3
  9. package/dist/{vs-map-cluster-BsPmHIMx.js → vs-map-cluster-5TnGPuBH.js} +3 -3
  10. package/dist/{vs-number-d58ftpH5.js → vs-number-DUeRr7uz.js} +3 -3
  11. package/dist/{vs-table-BHa5Velm.js → vs-table-CZJnXfUv.js} +6 -6
  12. package/dist/{vs-text-Bq87gMTx.js → vs-text-D3nCPkgk.js} +4 -4
  13. package/package.json +77 -77
  14. package/plugin.js +21 -21
  15. package/server/helpers/mdToHTML.js +17 -17
  16. package/server/migrations/bi.dataset.sql +46 -46
  17. package/server/migrations/bi.sql +114 -114
  18. package/server/plugins/docs.js +48 -48
  19. package/server/plugins/hook.js +89 -89
  20. package/server/routes/dashboard/controllers/dashboard.import.js +103 -103
  21. package/server/routes/dashboard/controllers/dashboard.js +158 -158
  22. package/server/routes/dashboard/controllers/dashboard.list.js +60 -60
  23. package/server/routes/dashboard/controllers/utils/yaml.js +11 -11
  24. package/server/routes/dashboard/index.mjs +26 -26
  25. package/server/routes/data/controllers/data.js +230 -230
  26. package/server/routes/data/controllers/util/chartSQL.js +49 -49
  27. package/server/routes/data/controllers/util/normalizeData.js +65 -65
  28. package/server/routes/data/index.mjs +38 -38
  29. package/server/routes/dataset/controllers/bi.dataset.list.js +29 -29
  30. package/server/routes/dataset/controllers/bi.db.list.js +19 -19
  31. package/server/routes/dataset/controllers/comment.js +55 -55
  32. package/server/routes/dataset/controllers/createDatasetPost.js +134 -134
  33. package/server/routes/dataset/controllers/data.js +149 -149
  34. package/server/routes/dataset/controllers/dbTablePreview.js +58 -58
  35. package/server/routes/dataset/controllers/dbTables.js +34 -34
  36. package/server/routes/dataset/controllers/delete.js +40 -40
  37. package/server/routes/dataset/controllers/deleteDataset.js +52 -52
  38. package/server/routes/dataset/controllers/editDataset.js +90 -90
  39. package/server/routes/dataset/controllers/export.js +214 -214
  40. package/server/routes/dataset/controllers/form.js +99 -99
  41. package/server/routes/dataset/controllers/format.js +46 -46
  42. package/server/routes/dataset/controllers/insert.js +47 -47
  43. package/server/routes/dataset/controllers/table.js +68 -68
  44. package/server/routes/dataset/controllers/update.js +43 -43
  45. package/server/routes/dataset/index.mjs +132 -132
  46. package/server/routes/dataset/utils/convertJSONToCSV.js +17 -17
  47. package/server/routes/dataset/utils/convertJSONToXls.js +47 -47
  48. package/server/routes/dataset/utils/createTableQuery.js +59 -59
  49. package/server/routes/dataset/utils/datasetForms.js +1 -1
  50. package/server/routes/dataset/utils/descriptionList.js +45 -45
  51. package/server/routes/dataset/utils/downloadRemoteFile.js +58 -58
  52. package/server/routes/dataset/utils/executeQuery.js +46 -46
  53. package/server/routes/dataset/utils/getLayersData.js +106 -106
  54. package/server/routes/dataset/utils/getTableData.js +46 -46
  55. package/server/routes/dataset/utils/insertDataQuery.js +12 -12
  56. package/server/routes/dataset/utils/metaFormat.js +24 -24
  57. package/server/routes/edit/controllers/dashboard.add.js +36 -36
  58. package/server/routes/edit/controllers/dashboard.delete.js +39 -39
  59. package/server/routes/edit/controllers/dashboard.edit.js +61 -61
  60. package/server/routes/edit/controllers/widget.add.js +78 -78
  61. package/server/routes/edit/controllers/widget.del.js +58 -58
  62. package/server/routes/edit/controllers/widget.edit.js +115 -115
  63. package/server/routes/edit/index.mjs +33 -33
  64. package/server/routes/map/controllers/cluster.js +125 -125
  65. package/server/routes/map/controllers/clusterVtile.js +166 -166
  66. package/server/routes/map/controllers/geojson.js +127 -127
  67. package/server/routes/map/controllers/heatmap.js +118 -118
  68. package/server/routes/map/controllers/map.js +69 -69
  69. package/server/routes/map/controllers/utils/downloadClusterData.js +44 -44
  70. package/server/routes/map/controllers/vtile.js +183 -183
  71. package/server/routes/map/index.mjs +32 -32
  72. package/server/templates/page/login.html +58 -58
  73. package/server/utils/getWidget.js +118 -118
  74. package/utils.js +12 -12
@@ -1,78 +1,78 @@
1
- import { createHash } from 'node:crypto';
2
- import { dataInsert, dataUpdate, getPGAsync, pgClients } from "@opengis/fastify-table/utils.js";
3
-
4
- /* eslint-disable import/extensions */
5
- import { yamlSafe } from '../../../../utils.js';
6
-
7
- function generateUniqueName(prefix = 'bar') {
8
- const randomPart = Math.floor(Math.random() * 10000);
9
- const timestamp = Date.now();
10
- return `${prefix}_${randomPart}_${timestamp}`;
11
- }
12
-
13
- export default async function widgetAdd({ pg = pgClients.client, params = {}, body = {} }) {
14
- const { name: dashboardName } = params;
15
- if (!dashboardName) {
16
- return { message: 'not enough params: id', status: 400 };
17
- }
18
- const data = body.yml ? yamlSafe.load(body.yml) : body;
19
-
20
- const row = await pg.query(`select dashboard_id, widgets, panels, table_name, db from bi.dashboard
21
- where $1 in (dashboard_id,name)`, [dashboardName]).then(el => el.rows?.[0] || {});
22
-
23
- const pg1 = row?.db ? await getPGAsync(row.db) : pg;
24
-
25
- const tableName = data.data?.table
26
- || data?.table
27
- || data.table_name
28
- || row.table_name;
29
-
30
- const loadTemplate = pg1.pk?.['admin.doc_template'] ? await pg1.query(
31
- 'select body from admin.doc_template where doc_type=5 and title=$1',
32
- [tableName]
33
- ).then(el => el.rows?.[0]?.body) : null;
34
-
35
- if (!tableName || !(pg.pk?.[loadTemplate?.table || tableName] || pgClients[data.db || row.db || 'client']?.pk?.[loadTemplate?.table || tableName])) {
36
- return { message: 'bad params: table', status: 400 };
37
- }
38
-
39
- const { dashboard_id: dashboardId } = row;
40
-
41
- const metric = data.data?.metrics || data.data?.metric || data?.metrics || data?.metric;
42
- Object.assign(data, {
43
- name: generateUniqueName(data.type),
44
- table_name: tableName,
45
- metrics: Array.isArray(metric) ? metric[0] : metric,
46
- });
47
-
48
- data.widget_id = createHash('md5').update([data?.name, dashboardId].join()).digest('hex').substr(0, 10);
49
-
50
- const res = await dataUpdate({
51
- pg,
52
- table: 'bi.dashboard',
53
- id: dashboardId,
54
- data: {
55
- widgets: [data].concat(row.widgets || []),
56
- panels: [{ widget: data.name, col: data.col || 3, height: data.data?.height }].concat(
57
- row.panels || []
58
- ),
59
- },
60
- });
61
-
62
- const widgetData = { ...data, data, dashboard_id: dashboardId };
63
- if (body?.yml) Object.assign(widgetData, { yml: body.yml });
64
-
65
- await dataInsert({
66
- pg,
67
- table: 'bi.widget',
68
- data: widgetData,
69
- });
70
-
71
- return {
72
- dashboard: dashboardName,
73
- widgetId: data.widget_id,
74
- widgetName: data.name,
75
- status: 200,
76
- rows: res,
77
- };
78
- }
1
+ import { createHash } from 'node:crypto';
2
+ import { dataInsert, dataUpdate, getPGAsync, pgClients } from "@opengis/fastify-table/utils.js";
3
+
4
+ /* eslint-disable import/extensions */
5
+ import { yamlSafe } from '../../../../utils.js';
6
+
7
+ function generateUniqueName(prefix = 'bar') {
8
+ const randomPart = Math.floor(Math.random() * 10000);
9
+ const timestamp = Date.now();
10
+ return `${prefix}_${randomPart}_${timestamp}`;
11
+ }
12
+
13
+ export default async function widgetAdd({ pg = pgClients.client, params = {}, body = {} }) {
14
+ const { name: dashboardName } = params;
15
+ if (!dashboardName) {
16
+ return { message: 'not enough params: id', status: 400 };
17
+ }
18
+ const data = body.yml ? yamlSafe.load(body.yml) : body;
19
+
20
+ const row = await pg.query(`select dashboard_id, widgets, panels, table_name, db from bi.dashboard
21
+ where $1 in (dashboard_id,name)`, [dashboardName]).then(el => el.rows?.[0] || {});
22
+
23
+ const pg1 = row?.db ? await getPGAsync(row.db) : pg;
24
+
25
+ const tableName = data.data?.table
26
+ || data?.table
27
+ || data.table_name
28
+ || row.table_name;
29
+
30
+ const loadTemplate = pg1.pk?.['admin.doc_template'] ? await pg1.query(
31
+ 'select body from admin.doc_template where doc_type=5 and title=$1',
32
+ [tableName]
33
+ ).then(el => el.rows?.[0]?.body) : null;
34
+
35
+ if (!tableName || !(pg.pk?.[loadTemplate?.table || tableName] || pgClients[data.db || row.db || 'client']?.pk?.[loadTemplate?.table || tableName])) {
36
+ return { message: 'bad params: table', status: 400 };
37
+ }
38
+
39
+ const { dashboard_id: dashboardId } = row;
40
+
41
+ const metric = data.data?.metrics || data.data?.metric || data?.metrics || data?.metric;
42
+ Object.assign(data, {
43
+ name: generateUniqueName(data.type),
44
+ table_name: tableName,
45
+ metrics: Array.isArray(metric) ? metric[0] : metric,
46
+ });
47
+
48
+ data.widget_id = createHash('md5').update([data?.name, dashboardId].join()).digest('hex').substr(0, 10);
49
+
50
+ const res = await dataUpdate({
51
+ pg,
52
+ table: 'bi.dashboard',
53
+ id: dashboardId,
54
+ data: {
55
+ widgets: [data].concat(row.widgets || []),
56
+ panels: [{ widget: data.name, col: data.col || 3, height: data.data?.height }].concat(
57
+ row.panels || []
58
+ ),
59
+ },
60
+ });
61
+
62
+ const widgetData = { ...data, data, dashboard_id: dashboardId };
63
+ if (body?.yml) Object.assign(widgetData, { yml: body.yml });
64
+
65
+ await dataInsert({
66
+ pg,
67
+ table: 'bi.widget',
68
+ data: widgetData,
69
+ });
70
+
71
+ return {
72
+ dashboard: dashboardName,
73
+ widgetId: data.widget_id,
74
+ widgetName: data.name,
75
+ status: 200,
76
+ rows: res,
77
+ };
78
+ }
@@ -1,58 +1,58 @@
1
- import { dataDelete, dataUpdate, pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function widgetDel({ pg = pgClients.client, 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
- const row = await pg.query(`select a.widget_id, b.dashboard_id from bi.widget a, bi.dashboard b
14
- where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`, [dashboardName, widgetName])
15
- .then(el => el.rows?.[0] || {});
16
-
17
- const { widget_id: widgetId, dashboard_id: dashboardId } = row || {};
18
-
19
- if (!widgetId) {
20
- return { message: `widget not found ${widgetName}`, status: 404 };
21
- }
22
-
23
- await dataDelete({
24
- pg,
25
- table: 'bi.widget',
26
- id: widgetId,
27
- });
28
-
29
- const currentDashboard = await pg.query('select * from bi.dashboard where $1 in (dashboard_id, name)', [dashboardName])
30
- .then(el => el.rows?.[0] || {});
31
-
32
- const body = currentDashboard;
33
-
34
- if (!currentDashboard) {
35
- return { message: `dashboard not found ${dashboardName}`, status: 404 };
36
- }
37
- body.panels =
38
- Array.isArray(body.panels) && body.panels?.length
39
- ? body.panels?.filter((panel) => panel.widget !== widgetName)
40
- : undefined;
41
- body.widgets =
42
- Array.isArray(body.widgets) && body?.widgets?.length
43
- ? body.widgets?.filter((widget) => widget.name !== widgetName)
44
- : undefined;
45
-
46
- const res1 = await dataUpdate({
47
- pg,
48
- table: 'bi.dashboard',
49
- id: dashboardId,
50
- data: body,
51
- });
52
-
53
- return {
54
- message: `Deleted widget ${widgetName}`,
55
- status: 200,
56
- rows: res1,
57
- };
58
- }
1
+ import { dataDelete, dataUpdate, pgClients } from '@opengis/fastify-table/utils.js';
2
+
3
+ export default async function widgetDel({ pg = pgClients.client, 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
+ const row = await pg.query(`select a.widget_id, b.dashboard_id from bi.widget a, bi.dashboard b
14
+ where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`, [dashboardName, widgetName])
15
+ .then(el => el.rows?.[0] || {});
16
+
17
+ const { widget_id: widgetId, dashboard_id: dashboardId } = row || {};
18
+
19
+ if (!widgetId) {
20
+ return { message: `widget not found ${widgetName}`, status: 404 };
21
+ }
22
+
23
+ await dataDelete({
24
+ pg,
25
+ table: 'bi.widget',
26
+ id: widgetId,
27
+ });
28
+
29
+ const currentDashboard = await pg.query('select * from bi.dashboard where $1 in (dashboard_id, name)', [dashboardName])
30
+ .then(el => el.rows?.[0] || {});
31
+
32
+ const body = currentDashboard;
33
+
34
+ if (!currentDashboard) {
35
+ return { message: `dashboard not found ${dashboardName}`, status: 404 };
36
+ }
37
+ body.panels =
38
+ Array.isArray(body.panels) && body.panels?.length
39
+ ? body.panels?.filter((panel) => panel.widget !== widgetName)
40
+ : undefined;
41
+ body.widgets =
42
+ Array.isArray(body.widgets) && body?.widgets?.length
43
+ ? body.widgets?.filter((widget) => widget.name !== widgetName)
44
+ : undefined;
45
+
46
+ const res1 = await dataUpdate({
47
+ pg,
48
+ table: 'bi.dashboard',
49
+ id: dashboardId,
50
+ data: body,
51
+ });
52
+
53
+ return {
54
+ message: `Deleted widget ${widgetName}`,
55
+ status: 200,
56
+ rows: res1,
57
+ };
58
+ }
@@ -1,115 +1,115 @@
1
- import { dataUpdate, pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- import { getWidget, yamlSafe } from '../../../../utils.js';
4
-
5
- export default async function widgetEdit({ pg = pgClients.client, body, params }, reply) {
6
- const { widget: widgetName, name: dashboardName } = params;
7
- const data = body.yml && !body.style ? yamlSafe.load(body.yml) : body;
8
- const yml = body.yml ?? yamlSafe.dump(body.data);
9
- // console.log(body.data, data, body.yml, yml);
10
-
11
- if (!widgetName || !dashboardName) {
12
- return reply.status(400).send({
13
- error: 'not enough params: dashboard and widget name',
14
- code: 400,
15
- });
16
- }
17
-
18
- const { widget_id: widgetId, dashboard_id: dashboardId, widgets } = await pg.query(
19
- `select a.widget_id , b.dashboard_id, b.widgets from bi.widget a, bi.dashboard b
20
- where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`,
21
- [dashboardName, widgetName]).then(res1 => res1.rows?.[0] || {});
22
-
23
- // get Data
24
- const templateData = await getWidget({ pg, dashboard: dashboardName, widget: widgetName });
25
- if (!templateData) {
26
- return reply.status(404).send({
27
- error: `widget not found ${widgetName}`,
28
- code: 404,
29
- });
30
- }
31
-
32
- if (data?.data) {
33
- Object.assign(data, {
34
- data: Object.keys(data.data || {})
35
- ?.reduce?.((acc, curr) => ({ ...acc, [curr]: data.data[curr] === 'null' ? null : data.data[curr] }), {})
36
- });
37
- }
38
- const widgetData = ['style', 'data', 'type', 'title', 'controls', 'query', 'cls', 'x']
39
- .filter(el => data[el])
40
- .reduce((p, el) => ({ ...p, [el]: data[el] }), {});
41
-
42
- // get table
43
- const tableName = body.table
44
- || widgetData.data?.table_name
45
- || widgetData.data?.table
46
- || widgetData?.table_name
47
- || templateData.table;
48
-
49
- const loadTemplate = pg?.pk?.['admin.doc_template'] ? await pg.query(
50
- 'select body from admin.doc_template where doc_type=5 and title=$1',
51
- [tableName]
52
- ).then(el => el.rows?.[0]?.body) : null;
53
-
54
- if (!pg || !tableName || !(pg.pk?.[loadTemplate?.table || tableName] || pgClients[widgetData?.data?.db || templateData?.db || 'client']?.pk?.[loadTemplate?.table || tableName])) {
55
- return reply.status(400).send({
56
- error: 'bad params: table ' + tableName,
57
- code: 400,
58
- });
59
- }
60
-
61
- if (yml) {
62
- Object.assign(widgetData, { yml })
63
- }
64
-
65
- if (widgetData?.data) {
66
- Object.assign(widgetData, { data: { ...widgetData?.data || {}, table_name: tableName } });
67
- }
68
- Object.assign(widgetData, { table_name: tableName });
69
- // console.log(widgetData);
70
- const row = await dataUpdate({
71
- pg,
72
- table: 'bi.widget',
73
- id: widgetId,
74
- data: widgetData,
75
- });
76
-
77
- const idx = widgets?.findIndex?.(el => el.name === widgetName)?.toString?.() || -1;
78
- if (widgetData.hasOwnProperty('table_name') && idx > -1) {
79
- widgets[idx].table_name = tableName;
80
- widgets[idx].table = tableName;
81
- }
82
- if (widgetData.hasOwnProperty('data') && idx > -1) {
83
- widgets[idx].data = widgetData.data
84
- }
85
- if (widgetData.hasOwnProperty('yml') && idx > -1) {
86
- widgets[idx].yml = widgetData.yml;
87
- }
88
- if (widgetData.hasOwnProperty('style') && idx > -1) {
89
- widgets[idx].style = widgetData.style;
90
- }
91
- if (widgetData.hasOwnProperty('type') && idx > -1) {
92
- widgets[idx].type = widgetData.type;
93
- }
94
- if (widgetData.data?.type === 'text' && idx > -1) {
95
- widgets[idx].data.text = widgetData.data?.text;
96
- }
97
- if (typeof widgetData?.query === 'string' && idx > -1) {
98
- widgets[idx].data.query = widgetData.query;
99
- }
100
- if (typeof widgetData?.cls === 'string' && idx > -1) {
101
- widgets[idx].data.cls = widgetData.cls;
102
- }
103
- if (typeof widgetData?.x === 'string' && idx > -1) {
104
- widgets[idx].data.x = widgetData.x;
105
- }
106
-
107
- await dataUpdate({
108
- pg,
109
- table: 'bi.dashboard',
110
- id: dashboardId,
111
- data: { widgets },
112
- });
113
-
114
- return row;
115
- }
1
+ import { dataUpdate, pgClients } from '@opengis/fastify-table/utils.js';
2
+
3
+ import { getWidget, yamlSafe } from '../../../../utils.js';
4
+
5
+ export default async function widgetEdit({ pg = pgClients.client, body, params }, reply) {
6
+ const { widget: widgetName, name: dashboardName } = params;
7
+ const data = body.yml && !body.style ? yamlSafe.load(body.yml) : body;
8
+ const yml = body.yml ?? yamlSafe.dump(body.data);
9
+ // console.log(body.data, data, body.yml, yml);
10
+
11
+ if (!widgetName || !dashboardName) {
12
+ return reply.status(400).send({
13
+ error: 'not enough params: dashboard and widget name',
14
+ code: 400,
15
+ });
16
+ }
17
+
18
+ const { widget_id: widgetId, dashboard_id: dashboardId, widgets } = await pg.query(
19
+ `select a.widget_id , b.dashboard_id, b.widgets from bi.widget a, bi.dashboard b
20
+ where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`,
21
+ [dashboardName, widgetName]).then(res1 => res1.rows?.[0] || {});
22
+
23
+ // get Data
24
+ const templateData = await getWidget({ pg, dashboard: dashboardName, widget: widgetName });
25
+ if (!templateData) {
26
+ return reply.status(404).send({
27
+ error: `widget not found ${widgetName}`,
28
+ code: 404,
29
+ });
30
+ }
31
+
32
+ if (data?.data) {
33
+ Object.assign(data, {
34
+ data: Object.keys(data.data || {})
35
+ ?.reduce?.((acc, curr) => ({ ...acc, [curr]: data.data[curr] === 'null' ? null : data.data[curr] }), {})
36
+ });
37
+ }
38
+ const widgetData = ['style', 'data', 'type', 'title', 'controls', 'query', 'cls', 'x']
39
+ .filter(el => data[el])
40
+ .reduce((p, el) => ({ ...p, [el]: data[el] }), {});
41
+
42
+ // get table
43
+ const tableName = body.table
44
+ || widgetData.data?.table_name
45
+ || widgetData.data?.table
46
+ || widgetData?.table_name
47
+ || templateData.table;
48
+
49
+ const loadTemplate = pg?.pk?.['admin.doc_template'] ? await pg.query(
50
+ 'select body from admin.doc_template where doc_type=5 and title=$1',
51
+ [tableName]
52
+ ).then(el => el.rows?.[0]?.body) : null;
53
+
54
+ if (!pg || !tableName || !(pg.pk?.[loadTemplate?.table || tableName] || pgClients[widgetData?.data?.db || templateData?.db || 'client']?.pk?.[loadTemplate?.table || tableName])) {
55
+ return reply.status(400).send({
56
+ error: 'bad params: table ' + tableName,
57
+ code: 400,
58
+ });
59
+ }
60
+
61
+ if (yml) {
62
+ Object.assign(widgetData, { yml })
63
+ }
64
+
65
+ if (widgetData?.data) {
66
+ Object.assign(widgetData, { data: { ...widgetData?.data || {}, table_name: tableName } });
67
+ }
68
+ Object.assign(widgetData, { table_name: tableName });
69
+ // console.log(widgetData);
70
+ const row = await dataUpdate({
71
+ pg,
72
+ table: 'bi.widget',
73
+ id: widgetId,
74
+ data: widgetData,
75
+ });
76
+
77
+ const idx = widgets?.findIndex?.(el => el.name === widgetName)?.toString?.() || -1;
78
+ if (widgetData.hasOwnProperty('table_name') && idx > -1) {
79
+ widgets[idx].table_name = tableName;
80
+ widgets[idx].table = tableName;
81
+ }
82
+ if (widgetData.hasOwnProperty('data') && idx > -1) {
83
+ widgets[idx].data = widgetData.data
84
+ }
85
+ if (widgetData.hasOwnProperty('yml') && idx > -1) {
86
+ widgets[idx].yml = widgetData.yml;
87
+ }
88
+ if (widgetData.hasOwnProperty('style') && idx > -1) {
89
+ widgets[idx].style = widgetData.style;
90
+ }
91
+ if (widgetData.hasOwnProperty('type') && idx > -1) {
92
+ widgets[idx].type = widgetData.type;
93
+ }
94
+ if (widgetData.data?.type === 'text' && idx > -1) {
95
+ widgets[idx].data.text = widgetData.data?.text;
96
+ }
97
+ if (typeof widgetData?.query === 'string' && idx > -1) {
98
+ widgets[idx].data.query = widgetData.query;
99
+ }
100
+ if (typeof widgetData?.cls === 'string' && idx > -1) {
101
+ widgets[idx].data.cls = widgetData.cls;
102
+ }
103
+ if (typeof widgetData?.x === 'string' && idx > -1) {
104
+ widgets[idx].data.x = widgetData.x;
105
+ }
106
+
107
+ await dataUpdate({
108
+ pg,
109
+ table: 'bi.dashboard',
110
+ id: dashboardId,
111
+ data: { widgets },
112
+ });
113
+
114
+ return row;
115
+ }
@@ -1,33 +1,33 @@
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
- import dashboardDelete from './controllers/dashboard.delete.js';
8
-
9
- const biSchema = {
10
- type: 'object',
11
- properties: {
12
- querystring: {
13
- widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
14
- dashboard: { type: 'string', pattern: '^([\\d\\w]+)$' },
15
- list: { type: 'string', pattern: '^([\\d])$' },
16
- sql: { type: 'string', pattern: '^([\\d])$' },
17
- },
18
- params: {
19
- name: { type: 'string', pattern: '^([\\d\\w]+)$' },
20
- widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
21
- },
22
- },
23
- };
24
-
25
- export default async function route(fastify) {
26
- fastify.post(`/bi-dashboard/:name`, { schema: biSchema }, widgetAdd);
27
- fastify.put(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetEdit);
28
- fastify.delete(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetDel);
29
-
30
- fastify.post(`/bi-dashboard`, { schema: biSchema }, dashboardAdd);
31
- fastify.put(`/bi-dashboard/:name`, { schema: biSchema }, dashboardEdit);
32
- fastify.delete(`/bi-dashboard/:id`, {}, dashboardDelete);
33
- }
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
+ import dashboardDelete from './controllers/dashboard.delete.js';
8
+
9
+ const biSchema = {
10
+ type: 'object',
11
+ properties: {
12
+ querystring: {
13
+ widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
14
+ dashboard: { type: 'string', pattern: '^([\\d\\w]+)$' },
15
+ list: { type: 'string', pattern: '^([\\d])$' },
16
+ sql: { type: 'string', pattern: '^([\\d])$' },
17
+ },
18
+ params: {
19
+ name: { type: 'string', pattern: '^([\\d\\w]+)$' },
20
+ widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
21
+ },
22
+ },
23
+ };
24
+
25
+ export default async function route(fastify) {
26
+ fastify.post(`/bi-dashboard/:name`, { schema: biSchema }, widgetAdd);
27
+ fastify.put(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetEdit);
28
+ fastify.delete(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetDel);
29
+
30
+ fastify.post(`/bi-dashboard`, { schema: biSchema }, dashboardAdd);
31
+ fastify.put(`/bi-dashboard/:name`, { schema: biSchema }, dashboardEdit);
32
+ fastify.delete(`/bi-dashboard/:id`, {}, dashboardDelete);
33
+ }