@opengis/bi 1.0.17 → 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 +68 -76
  5. package/dist/{import-file-CJYiO_4_.js → import-file-BJjgK8Hl.js} +11072 -11065
  6. package/dist/{map-component-mixin-zHwqWXJY.js → map-component-mixin-BDeshFZi.js} +3803 -5455
  7. package/dist/style.css +1 -1
  8. package/dist/{vs-calendar-BAPnMYRd.js → vs-calendar-D98bcwCO.js} +36 -30
  9. package/dist/{vs-funnel-bar-DCK7gSj4.js → vs-funnel-bar-Ps4AevXk.js} +1 -1
  10. package/dist/{vs-heatmap-kd6FKOrT.js → vs-heatmap-DQ4l7XOD.js} +1 -1
  11. package/dist/{vs-map-BNm381mR.js → vs-map-C36n66Hj.js} +25 -24
  12. package/dist/vs-map-cluster-Bcjcul0f.js +76 -0
  13. package/dist/{vs-number-DH5bYG7m.js → vs-number-XzxJiWRu.js} +1 -1
  14. package/dist/{vs-text-DXkA7s1D.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-D3jk7J8D.js +0 -106
  63. package/server/routes/dataset/controllers/bi.dataset.import.js +0 -67
@@ -1,85 +1,85 @@
1
- import { getTemplate, pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- const pg = pgClients.client;
4
-
5
- async function getWidget({ dashboard, widget }) {
6
- if (!dashboard && !widget) {
7
- return { message: `not enough params: dashboard / widget`, status: 400 };
8
- }
9
- const dashboardData = dashboard
10
- ? await getTemplate('dashboard', dashboard)
11
- : null;
12
-
13
- const { id, tableName } =
14
- !dashboardData && pg.pk['bi.dashboard'] && dashboard
15
- ? await pg
16
- .query(
17
- `select dashboard_id as id, table_name as "tableName" from bi.dashboard where $1 in (dashboard_id, name)`,
18
- [dashboard]
19
- )
20
- .then((res1) => res1.rows?.[0] || {})
21
- : {};
22
-
23
- if (!dashboardData && dashboard && !id) {
24
- return { message: `dashboard not found: ${dashboard}`, status: 404 };
25
- }
26
-
27
- dashboardData?.forEach((el) => {
28
- el[2] = el[0].split('.')[0];
29
- });
30
- const dashboardIndex = dashboardData?.find((el) => el[2] == 'index')?.[1];
31
-
32
- const widgetData = dashboard
33
- ? dashboardData?.find((el) => el[2] === (widget || 'index'))?.[1]
34
- : await getTemplate('widget', widget);
35
- if (typeof widgetData === 'string') {
36
- return { source: widgetData, status: 200 };
37
- }
38
- if (!id && !dashboardData && !widgetData) {
39
- return { message: `not found ${widget} ${dashboard}`, status: 404 };
40
- }
41
-
42
- const q = `select *, coalesce(data::jsonb, '{}'::jsonb) || jsonb_build_object('table', table_name) as data from bi.widget where dashboard_id=$1 and name=$2`;
43
-
44
- const {
45
- type,
46
- text,
47
- data = {},
48
- controls,
49
- style,
50
- options,
51
- yml
52
- } = widgetData ||
53
- (await pg
54
- .query(q, [id || dashboard, widget])
55
- .then((res1) => res1.rows?.[0] || {}));
56
-
57
- if (!type) {
58
- return { message: `widget not found: ${widget}`, status: 404 };
59
- }
60
-
61
- Object.assign(data, {
62
- table:
63
- data.table ||
64
- tableName ||
65
- widgetData?.table_name ||
66
- dashboardIndex?.table ||
67
- dashboardIndex?.table_name,
68
- db: dashboardIndex?.db || pgClients.client?.options?.database,
69
- });
70
- const main = { ...(dashboardIndex || {}), ...widgetData, ...data, ...data?.data || {} };
71
-
72
- if (!main?.table) {
73
- return {
74
- message: /* json.error || */ `invalid ${widget ? 'widget' : 'dashboard'}: 1`,
75
- status: 404,
76
- };
77
- }
78
-
79
- const tableSQL = main?.sql?.map(
80
- (el, i) => `left join lateral(${el})t${i + 1} on 1=1`
81
- );
82
-
83
- return { ...main, tableSQL, data, type, text, controls, style, options, yml };
84
- }
85
- export default getWidget;
1
+ import { getTemplate, pgClients } from '@opengis/fastify-table/utils.js';
2
+
3
+ const pg = pgClients.client;
4
+
5
+ async function getWidget({ dashboard, widget }) {
6
+ if (!dashboard && !widget) {
7
+ return { message: `not enough params: dashboard / widget`, status: 400 };
8
+ }
9
+ const dashboardData = dashboard
10
+ ? await getTemplate('dashboard', dashboard)
11
+ : null;
12
+
13
+ const { id, tableName } =
14
+ !dashboardData && pg.pk['bi.dashboard'] && dashboard
15
+ ? await pg
16
+ .query(
17
+ `select dashboard_id as id, table_name as "tableName" from bi.dashboard where $1 in (dashboard_id, name)`,
18
+ [dashboard]
19
+ )
20
+ .then((res1) => res1.rows?.[0] || {})
21
+ : {};
22
+
23
+ if (!dashboardData && dashboard && !id) {
24
+ return { message: `dashboard not found: ${dashboard}`, status: 404 };
25
+ }
26
+
27
+ dashboardData?.forEach((el) => {
28
+ el[2] = el[0].split('.')[0];
29
+ });
30
+ const dashboardIndex = dashboardData?.find((el) => el[2] == 'index')?.[1];
31
+
32
+ const widgetData = dashboard
33
+ ? dashboardData?.find((el) => el[2] === (widget || 'index'))?.[1]
34
+ : await getTemplate('widget', widget);
35
+ if (typeof widgetData === 'string') {
36
+ return { source: widgetData, status: 200 };
37
+ }
38
+ if (!id && !dashboardData && !widgetData) {
39
+ return { message: `not found ${widget} ${dashboard}`, status: 404 };
40
+ }
41
+
42
+ const q = `select *, coalesce(data::jsonb, '{}'::jsonb) || jsonb_build_object('table', table_name) as data from bi.widget where dashboard_id=$1 and name=$2`;
43
+
44
+ const {
45
+ type,
46
+ text,
47
+ data = {},
48
+ controls,
49
+ style,
50
+ options,
51
+ yml
52
+ } = widgetData ||
53
+ (await pg
54
+ .query(q, [id || dashboard, widget])
55
+ .then((res1) => res1.rows?.[0] || {}));
56
+
57
+ if (!type) {
58
+ return { message: `widget not found: ${widget}`, status: 404 };
59
+ }
60
+
61
+ Object.assign(data, {
62
+ table:
63
+ data.table ||
64
+ tableName ||
65
+ widgetData?.table_name ||
66
+ dashboardIndex?.table ||
67
+ dashboardIndex?.table_name,
68
+ db: dashboardIndex?.db || pgClients.client?.options?.database,
69
+ });
70
+ const main = { ...(dashboardIndex || {}), ...widgetData, ...data, ...data?.data || {} };
71
+
72
+ if (!main?.table) {
73
+ return {
74
+ message: /* json.error || */ `invalid ${widget ? 'widget' : 'dashboard'}: 1`,
75
+ status: 404,
76
+ };
77
+ }
78
+
79
+ const tableSQL = main?.sql?.map(
80
+ (el, i) => `left join lateral(${el})t${i + 1} on 1=1`
81
+ );
82
+
83
+ return { ...main, tableSQL, data, type, text, controls, style, options, yml };
84
+ }
85
+ export default getWidget;
package/utils.js CHANGED
@@ -1,12 +1,12 @@
1
- // This file contains code that we reuse
2
- // between our tests.
3
-
4
- // import getTemplatePath from '@opengis/fastify-table/table/controllers/utils/getTemplatePath.js';
5
- import getWidget from './server/utils/getWidget.js';
6
- import yamlSafe from './server/routes/dashboard/controllers/utils/yaml.js';
7
-
8
- export {
9
- // getTemplatePath,
10
- yamlSafe,
11
- getWidget,
12
- };
1
+ // This file contains code that we reuse
2
+ // between our tests.
3
+
4
+ // import getTemplatePath from '@opengis/fastify-table/table/controllers/utils/getTemplatePath.js';
5
+ import getWidget from './server/utils/getWidget.js';
6
+ import yamlSafe from './server/routes/dashboard/controllers/utils/yaml.js';
7
+
8
+ export {
9
+ // getTemplatePath,
10
+ yamlSafe,
11
+ getWidget,
12
+ };
@@ -1,106 +0,0 @@
1
- import { l as V, m as v } from "./map-component-mixin-zHwqWXJY.js";
2
- import { _, c as $ } from "./import-file-CJYiO_4_.js";
3
- import { resolveComponent as d, openBlock as M, createElementBlock as L, createVNode as p, createElementVNode as w, createBlock as S, createCommentVNode as k } from "vue";
4
- function C(t, n) {
5
- t = t.replace(/^#/, ""), t.length === 3 && (t = t.split("").map((r) => r + r).join(""));
6
- const o = parseInt(t.substring(0, 2), 16) / 255, s = parseInt(t.substring(2, 4), 16) / 255, a = parseInt(t.substring(4, 6), 16) / 255, e = Math.max(o, s, a), c = Math.min(o, s, a);
7
- let i, l;
8
- const m = (e + c) / 2;
9
- if (e === c)
10
- i = l = 0;
11
- else {
12
- const r = e - c;
13
- switch (l = m > 0.5 ? r / (2 - e - c) : r / (e + c), e) {
14
- case o:
15
- i = (s - a) / r + (s < a ? 6 : 0);
16
- break;
17
- case s:
18
- i = (a - o) / r + 2;
19
- break;
20
- case a:
21
- i = (o - s) / r + 4;
22
- break;
23
- }
24
- i /= 6;
25
- }
26
- return `hsl(${Math.round(i * 360)},${Math.round(l * 100)}%,${n}%)`;
27
- }
28
- function H(t, n) {
29
- var e;
30
- const o = document.createElement("div");
31
- o.style.color = t, document.body.appendChild(o);
32
- const s = ((e = window.getComputedStyle(o)) == null ? void 0 : e.color) || [];
33
- document.body.removeChild(o);
34
- const a = s.match(/\d+/g).map(Number) || [];
35
- return this.rgbToHSL(a[0], a[1], n);
36
- }
37
- function z(t, n) {
38
- return t != null && t.includes("#") ? C(t, n) : H(t, n);
39
- }
40
- const E = {
41
- mixins: [$, V, v],
42
- async mounted() {
43
- await this.getMapData(), await this.createMap();
44
- },
45
- methods: {
46
- async getMapData() {
47
- const n = await (await fetch(
48
- `/api/bi-cluster?widget=${this.widget}&dashboard=${this.dashboard}`
49
- )).json();
50
- this.data = n;
51
- },
52
- async loadHandler() {
53
- const t = ["#2980b9", "yellow", "#FE4365", "blue", "green"], n = [90, 80, 70, 60, 50], o = ["case"];
54
- this.data.sizes.reverse().forEach((a, e) => {
55
- o.push([">", ["get", "metric"], a]), o.push(z(t[0], n[e])), e++;
56
- }), o.push("gray");
57
- const s = {
58
- type: "polygon",
59
- color: o,
60
- opacity: 0.2
61
- };
62
- Object.assign(s, this.data.style || {}), this.addVtileLayer({
63
- id: "bi",
64
- url: `${window.location.origin}/api/bi-cluster-vtile/{z}/{x}/{y}.vmt?widget=${this.widget}&dashboard=${this.dashboard}&nocache=1`,
65
- style: s
66
- });
67
- }
68
- }
69
- }, j = { class: "h-full w-full relative" }, B = ["id"], I = { class: "absolute h-[50px] flex w-[80px] justify-end rounded-[7px] bottom-[40px] right-[10px]" };
70
- function N(t, n, o, s, a, e) {
71
- var u, h, b, g, f, y;
72
- const c = d("VsList"), i = d("VsMapSetting"), l = d("VsMapSlotLayers"), m = d("VsMapGoHome"), r = d("VsMapLegend");
73
- return M(), L("div", j, [
74
- p(c, {
75
- source: (u = t.data) == null ? void 0 : u.rows,
76
- total: ((h = t.data) == null ? void 0 : h.total) || 0,
77
- count: ((b = t.data) == null ? void 0 : b.count) || 0
78
- }, null, 8, ["source", "total", "count"]),
79
- w("div", {
80
- id: t.mapId,
81
- class: "h-[96%] w-full flex items-end min-h-[250px]"
82
- }, null, 8, B),
83
- t.showSetting ? (M(), S(i, {
84
- key: 0,
85
- map: t.map,
86
- coordinates: t.coordinatesByMouse
87
- }, null, 8, ["map", "coordinates"])) : k("", !0),
88
- p(l, { map: t.map }, null, 8, ["map"]),
89
- w("div", I, [
90
- p(m, {
91
- map: t.map,
92
- bbox: (g = t.data) == null ? void 0 : g.bbox
93
- }, null, 8, ["map", "bbox"]),
94
- p(r, {
95
- colors: (f = t.data) == null ? void 0 : f.colors,
96
- sizes: (y = t.data) == null ? void 0 : y.sizes,
97
- color: t.color,
98
- cluster: !0
99
- }, null, 8, ["colors", "sizes", "color"])
100
- ])
101
- ]);
102
- }
103
- const A = /* @__PURE__ */ _(E, [["render", N]]);
104
- export {
105
- A as default
106
- };
@@ -1,67 +0,0 @@
1
- import { randomBytes } from 'node:crypto';
2
-
3
- import createTableFunc from './util/create.table.js';
4
- import prepareData from './util/prepare.data.js';
5
-
6
- /**
7
- * Імпорт даних до BI набору
8
- *
9
- * @method POST
10
- * @summary Імпорт даних до BI набору
11
- * @priority 4
12
- * @alias biDatasetPost
13
- * @type api
14
- * @tag bi
15
- * @param {Object} params.id Dashboard ID
16
- * @errors 400,500
17
- * @returns {Number} status Номер помилки
18
- * @returns {String} error Опис помилки
19
- * @returns {Object} rows Масив з колонками таблиці
20
- */
21
-
22
- export default async function biDatasetPost(req) {
23
- const {
24
- pg, params = {}, body = {}, session = {},
25
- } = req;
26
- const { uid } = session?.passport?.user || {};
27
-
28
- if (!uid) {
29
- return { message: 'access restricted', status: 403 };
30
- }
31
-
32
- if (!Array.isArray(body?.data) && body?.data?.features?.[0]?.type !== 'Feature') {
33
- return { message: 'body data param is invalid', status: 400 };
34
- }
35
-
36
- // await pg.query(`insert into bi.dataset(dataset_id,name, uid) values($1,$1,$2) on conflict (dataset_id) do update set table_name=null`, [params?.id, uid]);
37
- const dataset = await pg.query('select dataset_id as id, name, table_name as table from bi.dataset where dataset_id=$1', [params?.id]).then((res) => res.rows?.[0] || {});
38
- if (!dataset.id) {
39
- return { message: `dataset not found: ${params?.id}`, status: 404 };
40
- }
41
-
42
- const tableName = randomBytes(64).toString('hex').substring(0, 24).replace(/^\d+/, '');
43
- const pkey = tableName.concat('_id');
44
- const table = `bi_data.${tableName}`;
45
- const { columns, insertData } = await prepareData({ req, table, data: body?.data });
46
- const createTable = createTableFunc({ table, pkey, columns });
47
- const updateDataset = `update bi.dataset set table_name='${table}', editor_id='${uid}' where dataset_id='${params?.id}'`;
48
- const sqlList = [createTable, insertData, updateDataset];
49
- if (dataset.name) {
50
- sqlList.push(`comment on table ${table} is '${dataset.name}'`);
51
- }
52
- const q = sqlList.filter((el) => el).join(';');
53
- await pg.query('create extension if not exists postgis;create schema if not exists bi_data;');
54
-
55
- // await pg.query(createTable);
56
-
57
- //const result = {}
58
- const result = await pg.query(q);
59
-
60
- return {
61
- message: {
62
- id: params?.id, action: 'import', result: 'success', total: result?.find((el) => el.command === 'INSERT')?.rowCount,
63
- },
64
- status: 200,
65
- };
66
-
67
- };