@opengis/admin 0.3.99 → 0.3.101
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/{add-page-Dqhn198n.js → add-page-BtME1JJf.js} +1 -1
- package/dist/{admin-interface-d347ItOq.js → admin-interface-mIo1_gE2.js} +679 -651
- package/dist/{admin-view-Bde8C2zb.js → admin-view-URsx4MBX.js} +1 -1
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +33 -33
- package/dist/{card-view-BWLrtFEA.js → card-view-BPUveYDd.js} +1 -1
- package/dist/{edit-page-DeVqk6QY.js → edit-page-DVyHgdP0.js} +1 -1
- package/dist/{import-file-5z6J6maH.js → import-file-Bs86FUW3.js} +7 -7
- package/dist/{profile-page-BICBVBpI.js → profile-page-DHRxyJA_.js} +1 -1
- package/package.json +1 -1
- package/server/routes/report/controllers/data.js +106 -31
- package/server/routes/report/controllers/list.js +9 -6
@@ -1,4 +1,4 @@
|
|
1
|
-
import { _ as $, s as k, u as V, g as d } from "./import-file-
|
1
|
+
import { _ as $, s as k, u as V, g as d } from "./import-file-Bs86FUW3.js";
|
2
2
|
import { resolveComponent as j, openBlock as p, createElementBlock as g, createElementVNode as m, normalizeClass as b, createCommentVNode as x, normalizeStyle as y, createBlock as E } from "vue";
|
3
3
|
const O = {
|
4
4
|
data() {
|
@@ -3705,27 +3705,27 @@ const Z4 = [
|
|
3705
3705
|
{
|
3706
3706
|
name: "edit",
|
3707
3707
|
path: "/edit",
|
3708
|
-
component: () => import("./edit-page-
|
3708
|
+
component: () => import("./edit-page-DVyHgdP0.js")
|
3709
3709
|
},
|
3710
3710
|
{
|
3711
3711
|
name: "add",
|
3712
3712
|
path: "/add",
|
3713
|
-
component: () => import("./add-page-
|
3713
|
+
component: () => import("./add-page-BtME1JJf.js")
|
3714
3714
|
},
|
3715
3715
|
{
|
3716
3716
|
path: "/profile",
|
3717
3717
|
name: "profile",
|
3718
|
-
component: () => import("./profile-page-
|
3718
|
+
component: () => import("./profile-page-DHRxyJA_.js")
|
3719
3719
|
},
|
3720
3720
|
{
|
3721
3721
|
name: "card-view",
|
3722
3722
|
path: "/card",
|
3723
|
-
component: () => import("./card-view-
|
3723
|
+
component: () => import("./card-view-BPUveYDd.js"),
|
3724
3724
|
children: [
|
3725
3725
|
{
|
3726
3726
|
name: "table",
|
3727
3727
|
path: ":table",
|
3728
|
-
component: () => import("./card-view-
|
3728
|
+
component: () => import("./card-view-BPUveYDd.js"),
|
3729
3729
|
children: [
|
3730
3730
|
{
|
3731
3731
|
name: "card",
|
@@ -3786,14 +3786,14 @@ const eB = /* @__PURE__ */ ft(X4, [["render", Q4]]), tB = (t) => {
|
|
3786
3786
|
{
|
3787
3787
|
path: "/",
|
3788
3788
|
name: "home",
|
3789
|
-
component: () => import("./admin-view-
|
3789
|
+
component: () => import("./admin-view-URsx4MBX.js"),
|
3790
3790
|
children: [
|
3791
3791
|
...t,
|
3792
3792
|
...e,
|
3793
3793
|
// { path: '/', redirect: '/home' },
|
3794
3794
|
{
|
3795
3795
|
path: "/:catchAll(.*)",
|
3796
|
-
component: () => import("./admin-interface-
|
3796
|
+
component: () => import("./admin-interface-mIo1_gE2.js")
|
3797
3797
|
}
|
3798
3798
|
]
|
3799
3799
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { _ as n, g as m } from "./import-file-
|
1
|
+
import { _ as n, g as m } from "./import-file-Bs86FUW3.js";
|
2
2
|
import { u as p } from "./user-B_2kh6ic.js";
|
3
3
|
import { resolveComponent as d, openBlock as u, createElementBlock as f, createElementVNode as o, createBlock as h, createCommentVNode as b } from "vue";
|
4
4
|
const x = {
|
package/package.json
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
import
|
1
|
+
import path from 'node:path';
|
2
|
+
|
3
|
+
import { handlebars, pgClients, getTemplate, metaFormat } from '@opengis/fastify-table/utils.js';
|
2
4
|
|
3
5
|
import getFilterQuery from '../utils/getFilterQuery.js';
|
4
6
|
|
@@ -6,20 +8,32 @@ const maxLimit = 100;
|
|
6
8
|
|
7
9
|
export default async function reportData({
|
8
10
|
pg = pgClients.client, params = {}, query = {}, user = {},
|
9
|
-
}) {
|
11
|
+
}, reply) {
|
10
12
|
if (!params?.name) {
|
11
13
|
return { message: 'not enough params: name', status: 400 };
|
12
14
|
}
|
13
15
|
|
14
|
-
const
|
16
|
+
const body = await getTemplate('report', params.name);
|
17
|
+
const loadTemplate = Array.isArray(body) ? body?.find?.(el => el[0].replace(path.extname(el[0]), '') === 'index')?.[1] : body;
|
18
|
+
|
19
|
+
if (!loadTemplate?.sql && !loadTemplate?.table) {
|
20
|
+
return reply.status(404).send(`report not found: ${params.name}`);
|
21
|
+
}
|
22
|
+
|
23
|
+
if (loadTemplate?.table && !pg.pk?.[loadTemplate.table]) {
|
24
|
+
return reply.status(404).send(`table not found: ${loadTemplate.table}`);
|
25
|
+
}
|
15
26
|
|
16
|
-
if (
|
17
|
-
|
27
|
+
if (Array.isArray(body)) {
|
28
|
+
loadTemplate.widgets = [];
|
29
|
+
body.filter(el => el[0].replace(path.extname(el[0]), '') !== 'index').forEach((el) => {
|
30
|
+
loadTemplate.widgets.push(el[1]);
|
31
|
+
});
|
18
32
|
}
|
19
33
|
|
20
34
|
const { uid } = user;
|
21
35
|
|
22
|
-
const { kpi, sql
|
36
|
+
const { widgets = [], kpi, sql = `select * from ${loadTemplate.table} where ${loadTemplate.query || 'true'}`, meta, filters } = loadTemplate;
|
23
37
|
const { date, columns: metaColumns } = meta || {};
|
24
38
|
|
25
39
|
const granularity = query.granularity && date && false ? `date_trunc('${query.granularity}',${date})::date::text` : null;
|
@@ -31,8 +45,8 @@ export default async function reportData({
|
|
31
45
|
const limit = Math.min(maxLimit, +(query.limit || 20));
|
32
46
|
const offset = query.page && query.page > 0 ? (query.page - 1) * limit : 0;
|
33
47
|
|
34
|
-
const kpiColumns = kpi ? kpi?.map(el => `${el.
|
35
|
-
const columnsList = metaColumns
|
48
|
+
const kpiColumns = kpi ? kpi?.filter?.(el => el.agg)?.map?.(el => `${el.agg || 'count(*)'} as "${el.name}"`)?.join?.(',') : '';
|
49
|
+
const columnsList = metaColumns;
|
36
50
|
|
37
51
|
const qMeta = await handlebars.compile(sql)({ user, uid });
|
38
52
|
const { fields = [] } = await pg.query(`select * from (${qMeta})q limit 0`);
|
@@ -42,35 +56,96 @@ export default async function reportData({
|
|
42
56
|
const qAgg = `select ${kpiColumns || ''} from (${qMeta})q where ${where || '1=1'}`;
|
43
57
|
const q = `select ${columnsList || '*'} from (${qMeta})q where ${where || '1=1'} ${groupby ? `group by ${groupby}` : ''} limit ${limit} offset ${offset}`;
|
44
58
|
|
45
|
-
if (query.sql && user?.user_type?.includes('admin'))
|
46
|
-
|
47
|
-
|
48
|
-
kpi?.forEach(el => Object.assign(el, { count: kpiData[el.name] || '0' }));
|
49
|
-
|
50
|
-
const { rows = [] } = await pg.query(q);
|
51
|
-
|
52
|
-
const cls = meta?.cls || loadTemplate.columns
|
53
|
-
?.filter(el => (el.option || el.data))
|
54
|
-
?.reduce((acc, curr) => Object.assign(acc, { [curr.name]: (curr.option || curr.data) }), {});
|
55
|
-
|
56
|
-
const titles = meta?.titles
|
57
|
-
|| loadTemplate.columns?.reduce((acc, curr) => Object.assign(acc, { [curr.name]: curr.title }), {});
|
58
|
-
|
59
|
-
await metaFormat({ rows, cls, sufix: true });
|
59
|
+
if (query.sql && user?.user_type?.includes('admin')) {
|
60
|
+
return `${qAgg};${q}`;
|
61
|
+
}
|
60
62
|
|
61
|
-
const
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
const kpiData = await pg.query(qAgg).then(el => el.rows?.[0] || {}).catch(err => {
|
64
|
+
return reply.status(500).send('kpi error: ' + err.toString());
|
65
|
+
});
|
66
|
+
kpi?.filter?.(el => el.agg)?.forEach?.(el => Object.assign(el, { count: kpiData[el.name] || 0 }));
|
67
|
+
|
68
|
+
if (kpi?.filter?.(el => el.sql)?.length) {
|
69
|
+
await Promise.all(kpi.filter(el => el.sql).map(async (el) => {
|
70
|
+
const { rows = [], fields = [] } = await pg.query(el.sql).catch(err => {
|
71
|
+
Object.assign(el, { error: err.toString() });
|
72
|
+
}) || {};
|
73
|
+
Object.assign(el, { count: rows?.[0]?.[fields[0].name] || 0, sql: user?.user_type === 'admin' ? el.sql : undefined });
|
68
74
|
}));
|
75
|
+
}
|
76
|
+
if (widgets?.length) {
|
77
|
+
await Promise.all(widgets.map(async (el) => {
|
78
|
+
if (el.table && !pg.pk?.[el.table]) {
|
79
|
+
return { error: `table not found: ${el.table}` };
|
80
|
+
}
|
81
|
+
|
82
|
+
const { cls = {}, titles = {} } = (el.table ? el.meta : meta) || {};
|
83
|
+
const sql = el.sql || (el.table ? `select * from ${el.table} where ${el.query || 'true'}` : null) || q;
|
84
|
+
|
85
|
+
if (!el.agg) {
|
86
|
+
const { rows = [] } = await pg.query(sql).catch(err => {
|
87
|
+
Object.assign(el, { error: err.toString() });
|
88
|
+
}) || {};
|
89
|
+
await metaFormat({ rows, cls, sufix: false }, pg);
|
90
|
+
Object.assign(el, { rows, sql: user?.user_type === 'admin' ? sql : undefined });
|
91
|
+
} else {
|
92
|
+
const groupby = typeof el.groupby === 'string'
|
93
|
+
? { name: el.groupby }
|
94
|
+
: (el.groupby?.[0] || el.groupby);
|
95
|
+
|
96
|
+
const q1 = `select ${el.agg} ${groupby.name ? `${el.granularity ? `,date_trunc('${el.granularity}', ${groupby.name})` : `,${groupby.name}`}` : ''} as ${groupby.name} from (${sql}) t ${groupby.name ? `group by ${el.granularity ? `date_trunc('${el.granularity}', ${groupby.name})` : groupby.name}` : ''}`;
|
97
|
+
|
98
|
+
const { rows = [], fields = [] } = await pg.query(q1).catch(err => {
|
99
|
+
Object.assign(el, { error: err.toString() });
|
100
|
+
}) || {};
|
101
|
+
|
102
|
+
if (groupby.cls) {
|
103
|
+
Object.assign(cls, { [groupby.name]: groupby.cls });
|
104
|
+
}
|
105
|
+
|
106
|
+
await metaFormat({ rows, cls, sufix: false }, pg);
|
107
|
+
|
108
|
+
const types = el.table ? fields.reduce((acc, curr) => ({ ...acc, [curr.name]: pg.pgType?.[curr.dataTypeID] }), {}) : {};
|
109
|
+
|
110
|
+
const columns = el.table ? fields.map(el => ({
|
111
|
+
name: el.name,
|
112
|
+
title: titles?.[el.name] || el.name,
|
113
|
+
type: cls?.[el.name]
|
114
|
+
? 'Autocomplete'
|
115
|
+
: (
|
116
|
+
['date', 'timestamp with time zone', 'timestamp without time zone'].includes(types[el.name])
|
117
|
+
? 'Date'
|
118
|
+
: null
|
119
|
+
) || 'Text',
|
120
|
+
format: pg.pgType?.[el.dataTypeID],
|
121
|
+
data: cls?.[el.name],
|
122
|
+
})) : undefined;
|
123
|
+
|
124
|
+
Object.assign(el, { rows, columns, sql: user?.user_type === 'admin' ? q1 : undefined });
|
125
|
+
}
|
126
|
+
}));
|
127
|
+
}
|
128
|
+
|
129
|
+
const types = fields.reduce((acc, curr) => ({ ...acc, [curr.name]: pg.pgType?.[curr.dataTypeID] }), {});
|
130
|
+
|
131
|
+
const columns = fields.map(el => ({
|
132
|
+
name: el.name,
|
133
|
+
title: meta?.titles?.[el.name] || el.name,
|
134
|
+
type: meta?.cls?.[el.name]
|
135
|
+
? 'Autocomplete'
|
136
|
+
: (
|
137
|
+
['date', 'timestamp with time zone', 'timestamp without time zone'].includes(types[el.name])
|
138
|
+
? 'Date'
|
139
|
+
: null
|
140
|
+
) || 'Text',
|
141
|
+
format: pg.pgType?.[el.dataTypeID],
|
142
|
+
data: meta?.cls?.[el.name],
|
143
|
+
}));
|
69
144
|
|
70
145
|
return {
|
71
146
|
q: user?.user_type?.includes('admin') ? q : undefined,
|
72
147
|
kpi,
|
73
|
-
|
148
|
+
widgets,
|
74
149
|
columns,
|
75
150
|
};
|
76
151
|
}
|
@@ -1,17 +1,20 @@
|
|
1
|
+
import path from 'node:path';
|
2
|
+
|
1
3
|
import { getTemplatePath, getTemplate } from '@opengis/fastify-table/utils.js';
|
2
4
|
|
3
5
|
export default async function reportList({
|
4
6
|
user = {},
|
5
7
|
}) {
|
6
|
-
const arr = getTemplatePath('report')
|
8
|
+
const arr = getTemplatePath('report');
|
7
9
|
|
8
10
|
const rows = await Promise.all(arr.map(async (el) => {
|
9
|
-
const loadTemplate = await getTemplate('report', el);
|
11
|
+
const loadTemplate = await getTemplate('report', el[0]);
|
12
|
+
const item = Array.isArray(loadTemplate) ? loadTemplate?.find?.(el => el[0].replace(path.extname(el[0]), '') === 'index')[1] : loadTemplate;
|
10
13
|
return {
|
11
|
-
name: el,
|
12
|
-
filters:
|
13
|
-
title:
|
14
|
-
sql: user.user_type?.includes('admin') ?
|
14
|
+
name: el[0],
|
15
|
+
filters: item?.filters || [],
|
16
|
+
title: item?.title || el[0],
|
17
|
+
sql: user.user_type?.includes('admin') ? item?.sql : undefined,
|
15
18
|
};
|
16
19
|
}));
|
17
20
|
return { rows };
|