@opengis/bi 1.0.18 → 1.0.19

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 (63) hide show
  1. package/README.md +110 -50
  2. package/config.js +12 -12
  3. package/dist/bi.js +1 -1
  4. package/dist/bi.umd.cjs +65 -73
  5. package/dist/{import-file-BdjSLXH1.js → import-file-BJjgK8Hl.js} +11020 -11026
  6. package/dist/{map-component-mixin-BPiLgT8e.js → map-component-mixin-BDeshFZi.js} +3803 -5455
  7. package/dist/style.css +1 -1
  8. package/dist/{vs-calendar-CQIKItUs.js → vs-calendar-D98bcwCO.js} +1 -1
  9. package/dist/{vs-funnel-bar-ChdzKfzS.js → vs-funnel-bar-Ps4AevXk.js} +1 -1
  10. package/dist/{vs-heatmap-l5NqfXmF.js → vs-heatmap-DQ4l7XOD.js} +1 -1
  11. package/dist/{vs-map-BYaGp0Cy.js → vs-map-C36n66Hj.js} +25 -24
  12. package/dist/vs-map-cluster-Bcjcul0f.js +76 -0
  13. package/dist/{vs-number-DN6VsgHi.js → vs-number-XzxJiWRu.js} +1 -1
  14. package/dist/{vs-text-7pOGGSJS.js → vs-text-DWhTWJlt.js} +2 -2
  15. package/package.json +94 -87
  16. package/plugin.js +14 -14
  17. package/server/migrations/bi.dataset.sql +32 -26
  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 -38
  23. package/server/routes/dashboard/controllers/dashboard.js +118 -118
  24. package/server/routes/dashboard/controllers/dashboard.list.js +30 -30
  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 -167
  28. package/server/routes/data/controllers/util/chartSQL.js +42 -42
  29. package/server/routes/data/controllers/util/normalizeData.js +59 -59
  30. package/server/routes/data/index.mjs +29 -29
  31. package/server/routes/dataset/controllers/bi.dataset.add.js +86 -0
  32. package/server/routes/dataset/controllers/bi.dataset.data.add.js +49 -0
  33. package/server/routes/dataset/controllers/bi.dataset.data.del.js +54 -0
  34. package/server/routes/dataset/controllers/bi.dataset.data.edit.js +55 -0
  35. package/server/routes/dataset/controllers/bi.dataset.data.list.js +71 -0
  36. package/server/routes/dataset/controllers/bi.dataset.del.js +48 -0
  37. package/server/routes/dataset/controllers/bi.dataset.demo.add.js +2 -2
  38. package/server/routes/dataset/controllers/bi.dataset.edit.js +83 -0
  39. package/server/routes/dataset/controllers/bi.dataset.list.js +29 -0
  40. package/server/routes/dataset/controllers/bi.db.list.js +19 -0
  41. package/server/routes/dataset/controllers/util/create.table.js +2 -3
  42. package/server/routes/dataset/controllers/util/prepare.data.js +5 -5
  43. package/server/routes/dataset/index.mjs +75 -19
  44. package/server/routes/db/controllers/dbTablePreview.js +63 -63
  45. package/server/routes/db/controllers/dbTables.js +36 -36
  46. package/server/routes/db/index.mjs +17 -17
  47. package/server/routes/edit/controllers/dashboard.add.js +26 -26
  48. package/server/routes/edit/controllers/dashboard.edit.js +46 -46
  49. package/server/routes/edit/controllers/widget.add.js +75 -75
  50. package/server/routes/edit/controllers/widget.del.js +69 -69
  51. package/server/routes/edit/controllers/widget.edit.js +54 -54
  52. package/server/routes/edit/index.mjs +31 -31
  53. package/server/routes/map/controllers/cluster.js +109 -109
  54. package/server/routes/map/controllers/clusterVtile.js +166 -166
  55. package/server/routes/map/controllers/geojson.js +127 -127
  56. package/server/routes/map/controllers/map.js +60 -60
  57. package/server/routes/map/controllers/utils/downloadClusterData.js +42 -42
  58. package/server/routes/map/controllers/vtile.js +183 -183
  59. package/server/routes/map/index.mjs +25 -25
  60. package/server/utils/getWidget.js +85 -85
  61. package/utils.js +12 -12
  62. package/dist/vs-map-cluster-CeVIRHf6.js +0 -106
  63. package/server/routes/dataset/controllers/bi.dataset.import.js +0 -67
@@ -1,63 +1,63 @@
1
- const q = `select nspname||'.'||relname as table, json_agg(json_build_object('name',attname, 'type', a.atttypid::regtype, 'description', coalesce(col_description(attrelid, attnum),attname))) as columns
2
- from pg_attribute a
3
- left join pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
4
- JOIN pg_class AS i
5
- ON i.oid = a.attrelid
6
- JOIN pg_namespace AS NS ON i.relnamespace = NS.OID
7
- where a.attnum > 0 and nspname||'.'||relname = $1
8
- and not a.attisdropped
9
- group by nspname||'.'||relname limit 1`;
10
-
11
- export default async function dbTablePreview({ pg, params = {}, query = {} }) {
12
- if (!params?.name) {
13
- return { message: 'not enough params: name', status: 400 };
14
- }
15
-
16
- if (query.sql) return q;
17
- try {
18
- const { table, columns } = await pg
19
- .query(q, [params.name])
20
- .then((res) => res.rows?.[0] || {});
21
- if (!table) {
22
- return { message: 'table not found', status: 404 };
23
- }
24
-
25
- const { count = 0 } = await pg
26
- .query(
27
- `select reltuples as count from pg_class where oid = to_regclass($1)`,
28
- [params.name]
29
- )
30
- .then((res) => res.rows?.[0] || {});
31
- const geom = columns.find((el) => el.type === 'geometry')?.name;
32
- const { bounds, extentStr } = geom
33
- ? await pg
34
- .query(
35
- `select count(*),
36
- st_asgeojson(st_extent(${geom}))::json as bounds,
37
- replace(regexp_replace(st_extent(${geom})::box2d::text,'BOX\\(|\\)','','g'),' ',',') as "extentStr"
38
- from ${params.name}`
39
- )
40
- .then((res) => res.rows?.[0] || {})
41
- : {};
42
- const extent = extentStr ? extentStr.split(',') : undefined;
43
-
44
- const systemColumns = [
45
- 'uid',
46
- 'files',
47
- 'editor_date',
48
- 'cdate',
49
- 'editor_id',
50
- geom,
51
- ];
52
- const columnList = columns
53
- .map((el) => el?.name)
54
- .filter((el) => !systemColumns.includes(el));
55
- const { rows = [] } = await pg.query(
56
- `select ${columnList.join(',')} ${geom ? `, st_asgeojson(geom)::json as geom` : ''} from ${table} limit 10`
57
- );
58
-
59
- return { count, geom: !!geom, bounds, extent, columns, rows };
60
- } catch (err) {
61
- return { error: err.toString(), status: 500 };
62
- }
63
- }
1
+ const q = `select nspname||'.'||relname as table, json_agg(json_build_object('name',attname, 'type', a.atttypid::regtype, 'description', coalesce(col_description(attrelid, attnum),attname))) as columns
2
+ from pg_attribute a
3
+ left join pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
4
+ JOIN pg_class AS i
5
+ ON i.oid = a.attrelid
6
+ JOIN pg_namespace AS NS ON i.relnamespace = NS.OID
7
+ where a.attnum > 0 and nspname||'.'||relname = $1
8
+ and not a.attisdropped
9
+ group by nspname||'.'||relname limit 1`;
10
+
11
+ export default async function dbTablePreview({ pg, params = {}, query = {} }) {
12
+ if (!params?.name) {
13
+ return { message: 'not enough params: name', status: 400 };
14
+ }
15
+
16
+ if (query.sql) return q;
17
+ try {
18
+ const { table, columns } = await pg
19
+ .query(q, [params.name])
20
+ .then((res) => res.rows?.[0] || {});
21
+ if (!table) {
22
+ return { message: 'table not found', status: 404 };
23
+ }
24
+
25
+ const { count = 0 } = await pg
26
+ .query(
27
+ `select reltuples as count from pg_class where oid = to_regclass($1)`,
28
+ [params.name]
29
+ )
30
+ .then((res) => res.rows?.[0] || {});
31
+ const geom = columns.find((el) => el.type === 'geometry')?.name;
32
+ const { bounds, extentStr } = geom
33
+ ? await pg
34
+ .query(
35
+ `select count(*),
36
+ st_asgeojson(st_extent(${geom}))::json as bounds,
37
+ replace(regexp_replace(st_extent(${geom})::box2d::text,'BOX\\(|\\)','','g'),' ',',') as "extentStr"
38
+ from ${params.name}`
39
+ )
40
+ .then((res) => res.rows?.[0] || {})
41
+ : {};
42
+ const extent = extentStr ? extentStr.split(',') : undefined;
43
+
44
+ const systemColumns = [
45
+ 'uid',
46
+ 'files',
47
+ 'editor_date',
48
+ 'cdate',
49
+ 'editor_id',
50
+ geom,
51
+ ];
52
+ const columnList = columns
53
+ .map((el) => el?.name)
54
+ .filter((el) => !systemColumns.includes(el));
55
+ const { rows = [] } = await pg.query(
56
+ `select ${columnList.join(',')} ${geom ? `, st_asgeojson(geom)::json as geom` : ''} from ${table} limit 10`
57
+ );
58
+
59
+ return { count, geom: !!geom, bounds, extent, columns, rows };
60
+ } catch (err) {
61
+ return { error: err.toString(), status: 500 };
62
+ }
63
+ }
@@ -1,36 +1,36 @@
1
- export default async function dbTables({ pg, query = {} }) {
2
- const q = `select
3
- t.table_schema ||'.'|| t.table_name as table,
4
- obj_description(to_regclass(t.table_schema ||'."'|| t.table_name||'"')) as description,
5
- t.table_schema as schema,
6
- (select reltuples from pg_class where oid = to_regclass(t.table_schema ||'."'|| t.table_name||'"') ) as total,
7
- coalesce(isgeom,false) as isgeom
8
-
9
- from information_schema.tables t
10
- left join lateral(
11
- select true as isgeom from information_schema.columns c
12
- where c.table_name = t.table_name
13
- and c.table_schema = t.table_schema and 'geometry'=c.udt_name limit 1
14
- )c on 1=1
15
-
16
- where t.table_type = 'BASE TABLE'
17
- and t.table_schema not in ('public','log','admin','feature_ir','gis', 'setting')
18
- and t.table_name not like '%.%'
19
- and regexp_replace(t.table_name, '^[[:digit:]]', '', 'g') = t.table_name
20
- and 1=(SELECT count(*) FROM pg_catalog.pg_constraint con
21
- INNER JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
22
- INNER JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace
23
- WHERE nsp.nspname = t.table_schema AND rel.relname = t.table_name and contype='p'
24
- )
25
- and ${query.schema ? `t.table_schema=$1` : '1=1'} order by total desc`;
26
- if (query.sql) return q;
27
- try {
28
- const { rows = [] } = await pg.query(
29
- q,
30
- [query.schema].filter((el) => el)
31
- );
32
- return { rows };
33
- } catch (err) {
34
- return { error: err.toString(), status: 500 };
35
- }
36
- }
1
+ export default async function dbTables({ pg, query = {} }) {
2
+ const q = `select
3
+ t.table_schema ||'.'|| t.table_name as table,
4
+ obj_description(to_regclass(t.table_schema ||'."'|| t.table_name||'"')) as description,
5
+ t.table_schema as schema,
6
+ (select reltuples from pg_class where oid = to_regclass(t.table_schema ||'."'|| t.table_name||'"') ) as total,
7
+ coalesce(isgeom,false) as isgeom
8
+
9
+ from information_schema.tables t
10
+ left join lateral(
11
+ select true as isgeom from information_schema.columns c
12
+ where c.table_name = t.table_name
13
+ and c.table_schema = t.table_schema and 'geometry'=c.udt_name limit 1
14
+ )c on 1=1
15
+
16
+ where t.table_type = 'BASE TABLE'
17
+ and t.table_schema not in ('public','log','admin','feature_ir','gis', 'setting')
18
+ and t.table_name not like '%.%'
19
+ and regexp_replace(t.table_name, '^[[:digit:]]', '', 'g') = t.table_name
20
+ and 1=(SELECT count(*) FROM pg_catalog.pg_constraint con
21
+ INNER JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
22
+ INNER JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace
23
+ WHERE nsp.nspname = t.table_schema AND rel.relname = t.table_name and contype='p'
24
+ )
25
+ and ${query.schema ? `t.table_schema=$1` : '1=1'} order by total desc`;
26
+ if (query.sql) return q;
27
+ try {
28
+ const { rows = [] } = await pg.query(
29
+ q,
30
+ [query.schema].filter((el) => el)
31
+ );
32
+ return { rows };
33
+ } catch (err) {
34
+ return { error: err.toString(), status: 500 };
35
+ }
36
+ }
@@ -1,17 +1,17 @@
1
- import dbTables from './controllers/dbTables.js';
2
- import dbTablePreview from './controllers/dbTablePreview.js';
3
-
4
- export default async function route(fastify, opts) {
5
- fastify.route({
6
- method: 'GET',
7
- url: '/db-tables',
8
- schema: {},
9
- handler: dbTables,
10
- });
11
- fastify.route({
12
- method: 'GET',
13
- url: '/db-tables/:name',
14
- schema: {},
15
- handler: dbTablePreview,
16
- });
17
- }
1
+ import dbTables from './controllers/dbTables.js';
2
+ import dbTablePreview from './controllers/dbTablePreview.js';
3
+
4
+ export default async function route(fastify, opts) {
5
+ fastify.route({
6
+ method: 'GET',
7
+ url: '/db-tables',
8
+ schema: {},
9
+ handler: dbTables,
10
+ });
11
+ fastify.route({
12
+ method: 'GET',
13
+ url: '/db-tables/:name',
14
+ schema: {},
15
+ handler: dbTablePreview,
16
+ });
17
+ }
@@ -1,26 +1,26 @@
1
- import { dataInsert } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function widgetAdd({ pg, body }) {
4
- try {
5
- const time = Date.now();
6
- const tableName = body.table_name;
7
- const checkTable = await pg.query(
8
- `select * from bi.dashboard where $1 in (table_name)`,
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
- });
16
-
17
- return {
18
- time: Date.now() - time,
19
- message: `Added new dashboard, ID: '${res.rows[0].title}'`,
20
- status: 200,
21
- rows: res.rows,
22
- };
23
- } catch (err) {
24
- return { error: err.toString(), status: 500 };
25
- }
26
- }
1
+ import { dataInsert } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function widgetAdd({ pg, body }) {
4
+ try {
5
+ const time = Date.now();
6
+ const tableName = body.table_name;
7
+ const checkTable = await pg.query(
8
+ `select * from bi.dashboard where $1 in (table_name)`,
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
+ });
16
+
17
+ return {
18
+ time: Date.now() - time,
19
+ message: `Added new dashboard, ID: '${res.rows[0].title}'`,
20
+ status: 200,
21
+ rows: res.rows,
22
+ };
23
+ } catch (err) {
24
+ return { error: err.toString(), status: 500 };
25
+ }
26
+ }
@@ -1,46 +1,46 @@
1
- import { dataUpdate } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function dashboardEdit(
4
- { pg, params = {}, body = {} },
5
- reply
6
- ) {
7
- try {
8
- if (!params.name) {
9
- return {
10
- message: 'not enough params: dashboard name required',
11
- status: 400,
12
- };
13
- }
14
- const tableName = body.table_name;
15
- const checkTable = await pg.query(
16
- `select * from bi.dashboard where $1 in (table_name)`,
17
- [tableName]
18
- );
19
- if (!checkTable.rows.length) return { message: 'bad params', status: 401 };
20
- const { name: dashboardName } = params;
21
- const row = await pg
22
- .query(
23
- `select dashboard_id from bi.dashboard where $1 in (dashboard_id, name)`,
24
- [dashboardName]
25
- )
26
- .then((res1) => res1.rows?.[0] || {});
27
- const { dashboard_id: dashboardId } = row;
28
-
29
- const res = await dataUpdate({
30
- table: 'bi.dashboard',
31
- id: dashboardId,
32
- data: body,
33
- });
34
- if (!Object.keys(res)?.length) {
35
- return { message: 'not found data', status: 404 };
36
- }
37
-
38
- return {
39
- message: `updated ${dashboardName}`,
40
- status: 200,
41
- rows: res,
42
- };
43
- } catch (err) {
44
- return reply.status(500).send(err.toString());
45
- }
46
- }
1
+ import { dataUpdate } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function dashboardEdit(
4
+ { pg, params = {}, body = {} },
5
+ reply
6
+ ) {
7
+ try {
8
+ if (!params.name) {
9
+ return {
10
+ message: 'not enough params: dashboard name required',
11
+ status: 400,
12
+ };
13
+ }
14
+ const tableName = body.table_name;
15
+ const checkTable = await pg.query(
16
+ `select * from bi.dashboard where $1 in (table_name)`,
17
+ [tableName]
18
+ );
19
+ if (!checkTable.rows.length) return { message: 'bad params', status: 401 };
20
+ const { name: dashboardName } = params;
21
+ const row = await pg
22
+ .query(
23
+ `select dashboard_id from bi.dashboard where $1 in (dashboard_id, name)`,
24
+ [dashboardName]
25
+ )
26
+ .then((res1) => res1.rows?.[0] || {});
27
+ const { dashboard_id: dashboardId } = row;
28
+
29
+ const res = await dataUpdate({
30
+ table: 'bi.dashboard',
31
+ id: dashboardId,
32
+ data: body,
33
+ });
34
+ if (!Object.keys(res)?.length) {
35
+ return { message: 'not found data', status: 404 };
36
+ }
37
+
38
+ return {
39
+ message: `updated ${dashboardName}`,
40
+ status: 200,
41
+ rows: res,
42
+ };
43
+ } catch (err) {
44
+ return reply.status(500).send(err.toString());
45
+ }
46
+ }
@@ -1,75 +1,75 @@
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, 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
+ 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, 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,69 +1,69 @@
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
+ 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
+ }