@opengis/bi 1.0.4 → 1.0.6
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.
- package/dist/bi.js +2 -48551
- package/dist/bi.umd.cjs +39 -47
- package/dist/import-file-BUM1yt3h.js +46921 -0
- package/dist/style.css +1 -1
- package/dist/vs-number-C84Yg_fA.js +34 -0
- package/dist/vs-text-C2i7Vs8y.js +1517 -0
- package/package.json +1 -1
- package/server/routes/dashboard/controllers/dashboard.js +1 -1
- package/server/routes/dashboard/index.mjs +3 -3
- package/server/routes/data/controllers/data.js +23 -23
- package/server/routes/data/index.mjs +1 -1
- package/server/routes/edit/index.mjs +5 -5
- package/server/templates/widget/product_line.yml +3 -3
package/package.json
CHANGED
|
@@ -50,7 +50,7 @@ export default async function data({
|
|
|
50
50
|
data.type = 'file';
|
|
51
51
|
const { table } = data?.data || { table: data?.table_name };
|
|
52
52
|
// console.log(fileData)
|
|
53
|
-
const widgets = fileData.filter(el => el[0] !== 'index.yml').map(el => el[1]
|
|
53
|
+
const widgets = fileData.filter(el => el[0] !== 'index.yml').map(el => el[1].data ? ({ name: el[0].split('.')[0], type: el[1].type, text: el[1].text, style: el[1].style, data: el[1].data }) : { name: el[0].split('.')[0], text: el[1] });
|
|
54
54
|
|
|
55
55
|
const { fields = [] } = table ? await pg.query(`select * from ${table} limit 1`) : {};
|
|
56
56
|
|
|
@@ -17,7 +17,7 @@ const biSchema = {
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
export default async function route(fastify) {
|
|
20
|
-
fastify.get(`/
|
|
21
|
-
fastify.get(`/
|
|
22
|
-
fastify.delete(`/
|
|
20
|
+
fastify.get(`/bi-dashboard/:id`, { schema: biSchema }, dashboard);
|
|
21
|
+
fastify.get(`/bi-dashboard`, dashboardList);
|
|
22
|
+
fastify.delete(`/bi-dashboard/:id`, dashboardDelete);
|
|
23
23
|
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
// import getTemplate from '@opengis/fastify-table/table/controllers/utils/getTemplate.js';
|
|
3
3
|
import autoIndex from '@opengis/fastify-table/pg/funcs/autoIndex.js';
|
|
4
4
|
import pgClients from '@opengis/fastify-table/pg/pgClients.js';
|
|
5
5
|
import chartSQL from './util/chartSQL.js';
|
|
6
6
|
import normalizeData from './util/normalizeData.js';
|
|
7
7
|
|
|
8
|
-
const cwd = process.cwd();
|
|
9
|
-
const dashboardDir = path.join(cwd, 'server/templates/dashboard');
|
|
10
|
-
const widgetDir = path.join(cwd, 'server/templates/widget');
|
|
11
|
-
|
|
12
|
-
import { existsSync, readdirSync, readFileSync } from 'fs';
|
|
13
8
|
|
|
14
|
-
import
|
|
9
|
+
import { getTemplate } from '@opengis/fastify-table/utils.js';
|
|
15
10
|
|
|
16
11
|
export default async function data({
|
|
17
12
|
pg = pgClients.client, funcs = {}, query = {},
|
|
@@ -23,29 +18,32 @@ export default async function data({
|
|
|
23
18
|
if (!widget && !dashboard) {
|
|
24
19
|
return { message: 'not enough params: widget or dashboard required', status: 400 };
|
|
25
20
|
}
|
|
21
|
+
const dashboardData = dashboard ? await getTemplate('dashboard', dashboard) : null;
|
|
26
22
|
|
|
27
|
-
const
|
|
28
|
-
|
|
23
|
+
const { id, tableName } = !dashboardData && pg.pk['bi.dashboard'] && dashboard ?
|
|
24
|
+
await pg.query(`select dashboard_id as id, table_name as "tableName" from bi.dashboard where $1 in (dashboard_id, name)`, [dashboard]).then((res1) => res1.rows?.[0] || {}) : {};
|
|
29
25
|
|
|
30
|
-
const { id, tableName } = !existsSync(filePath) ? await pg.query(`select dashboard_id as id, table_name as "tableName" from bi.dashboard where $1 in (dashboard_id, name)`, [dashboard]).then((res1) => res1.rows?.[0] || {}) : {};
|
|
31
26
|
|
|
32
|
-
if (!
|
|
33
|
-
return { message: { root: config?.local ? dashboardDir : undefined, error: `not found`, widget, dashboard }, status: 404 };
|
|
34
|
-
}
|
|
27
|
+
if (!dashboardData && dashboard && !id) return 'dashboard not found';
|
|
35
28
|
|
|
36
|
-
|
|
29
|
+
// return { t: 111, data: dashboardData, dashboard }
|
|
37
30
|
|
|
38
|
-
const
|
|
31
|
+
const widgetData = dashboard ? dashboardData?.find(el => el[0]?.includes(widget))?.[1] : await getTemplate('widget', widget);
|
|
39
32
|
|
|
40
|
-
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`;
|
|
41
|
-
const { type, text, data, options, controls, style } = existsSync(filePath)
|
|
42
|
-
? jsonData
|
|
43
|
-
: await pg.query(q, [id || dashboard, widget])
|
|
44
|
-
.then((res1) => res1.rows?.[0] || {});
|
|
45
33
|
|
|
46
|
-
if (
|
|
34
|
+
if (dashboardData && !widgetData) {
|
|
35
|
+
return widgetData
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!id && !dashboardData && !widgetData) {
|
|
39
|
+
return { message: { root: config?.local ? dashboardDir : undefined, error: `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
|
+
const { type, text, data, controls, style, options } = widgetData || await pg.query(q, [id || dashboard, widget]).then((res1) => res1.rows?.[0] || {});
|
|
47
44
|
|
|
48
|
-
|
|
45
|
+
if (typeof widgetData === 'string') {
|
|
46
|
+
return widgetData;
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
if (!data?.table && tableName) {
|
|
@@ -60,7 +58,9 @@ export default async function data({
|
|
|
60
58
|
const { x, metric, table, where, groupby, xName } = normalizeData(data, query);
|
|
61
59
|
|
|
62
60
|
// auto Index
|
|
63
|
-
|
|
61
|
+
if (pg.pk[data.table]) {
|
|
62
|
+
autoIndex({ table: data.table, columns: [data?.time].concat([xName]).concat([groupby]).filter(el => el) }).catch(err => console.log(err))
|
|
63
|
+
}
|
|
64
64
|
|
|
65
65
|
// get group
|
|
66
66
|
const groupData = groupby ? await pg.query(`select ${groupby} as name ,count(*) from ${table} group by ${groupby} order by count(*) desc limit 20`).then(el => el.rows) : null;
|
|
@@ -19,9 +19,9 @@ const biSchema = {
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
export default async function route(fastify) {
|
|
22
|
-
fastify.post(`/
|
|
23
|
-
fastify.put(`/
|
|
24
|
-
fastify.delete(`/
|
|
25
|
-
fastify.post(`/
|
|
26
|
-
fastify.put(`/
|
|
22
|
+
fastify.post(`/bi-dashboard/:name`, { schema: biSchema }, widgetAdd);
|
|
23
|
+
fastify.put(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetEdit);
|
|
24
|
+
fastify.delete(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetDel);
|
|
25
|
+
fastify.post(`/bi-dashboard`, { schema: biSchema }, dashboardAdd);
|
|
26
|
+
fastify.put(`/bi-dashboard/:name`, { schema: biSchema }, dashboardEdit);
|
|
27
27
|
}
|