@opengis/admin 0.4.3 → 0.4.5
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/config.js +3 -3
- package/dist/{add-page-fdr6t9-i.js → add-page-DCJ-Yp0v.js} +1 -1
- package/dist/{admin-interface-bYzTXuVs.js → admin-interface-BZK7WQza.js} +1 -1
- package/dist/{admin-view-3hBO0cXK.js → admin-view-B0_hyDn5.js} +3 -3
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +72 -72
- package/dist/{card-view-Dfgoq-T0.js → card-view-DXKWi1Ty.js} +1 -1
- package/dist/{edit-page-pykfh5fh.js → edit-page-DO8gx1TX.js} +1 -1
- package/dist/{import-file-DPcs2POV.js → import-file-BlI2DAMT.js} +12172 -12157
- package/dist/{profile-page-UeVwkn5K.js → profile-page-9oNOPlYV.js} +1 -1
- package/dist/style.css +1 -1
- package/module/settings/card/admin.users.table/routes.hbs +1 -1
- package/package.json +1 -1
- package/plugin.js +2 -2
- package/server/plugins/hook.js +0 -27
- package/server/routes/print/controllers/cardPrint.js +0 -136
- package/server/routes/print/controllers/printTemplate.add.js +0 -37
- package/server/routes/print/controllers/printTemplate.delete.js +0 -29
- package/server/routes/print/controllers/printTemplate.edit.js +0 -42
- package/server/routes/print/controllers/printTemplate.js +0 -67
- package/server/routes/print/controllers/printTemplateList.js +0 -20
- package/server/routes/print/controllers/printTemplatePreview.js +0 -87
- package/server/routes/print/controllers/printTemplates.js +0 -1
- package/server/routes/print/index.mjs +0 -20
- package/server/routes/report/controllers/list.js +0 -23
- package/server/routes/report/controllers/tableData.js +0 -142
- package/server/routes/report/controllers/widgetData.js +0 -108
- package/server/routes/report/index.mjs +0 -9
- package/server/routes/report/utils/formatValue.js +0 -179
- package/server/routes/report/utils/getFilterQuery.js +0 -68
@@ -1,108 +0,0 @@
|
|
1
|
-
import path from 'node:path';
|
2
|
-
|
3
|
-
import { pgClients, getTemplate, metaFormat } from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
const maxLimit = 100;
|
6
|
-
|
7
|
-
const matches = {
|
8
|
-
16: 'yes/no', // boolean
|
9
|
-
701: 'number', // double precision
|
10
|
-
1082: 'date', // date
|
11
|
-
1184: 'date', // timestamp w/ time zone
|
12
|
-
1114: 'date', // timestamp w/o time zone
|
13
|
-
1700: 'number', // numeric
|
14
|
-
};
|
15
|
-
|
16
|
-
function normalizeData(widget, limit = maxLimit, offset = 0) {
|
17
|
-
const groupby = typeof widget.groupby === 'string'
|
18
|
-
? { name: widget.groupby }
|
19
|
-
: (widget.groupby?.[0] || widget.groupby);
|
20
|
-
|
21
|
-
const agg = groupby.name
|
22
|
-
? `${widget.granularity ? `date_trunc('${widget.granularity}', ${groupby.name})` : `${groupby.name}`}`
|
23
|
-
: 'count(*)';
|
24
|
-
|
25
|
-
const xCol = widget.granularity
|
26
|
-
? `date_trunc('${widget.granularity}', ${groupby.name})`
|
27
|
-
: groupby.name;
|
28
|
-
|
29
|
-
const sql = `select * from ${widget.table} where ${widget.query || 'true'} limit ${limit} offset ${offset}`;
|
30
|
-
|
31
|
-
const q = `select ${agg} as ${groupby.name}, ${widget.agg} as metric from (${sql}) t
|
32
|
-
${groupby.name ? `group by ${xCol}` : ''}
|
33
|
-
${widget.orderby || xCol ? `order by ${widget.orderby || xCol}` : ''}`;
|
34
|
-
|
35
|
-
return { groupby, agg, xCol, q };
|
36
|
-
}
|
37
|
-
|
38
|
-
export default async function widgetData({
|
39
|
-
pg = pgClients.client, params = {}, query = {}, user = {},
|
40
|
-
}, reply) {
|
41
|
-
if (!params?.name) {
|
42
|
-
return { message: 'not enough params: name', status: 400 };
|
43
|
-
}
|
44
|
-
|
45
|
-
if (!params?.widget) {
|
46
|
-
return reply.status(400).send('not enough params: widget');
|
47
|
-
}
|
48
|
-
|
49
|
-
const body = await getTemplate('report', params.name);
|
50
|
-
const loadTemplate = Array.isArray(body) ? body?.find?.(el => el[0].replace(path.extname(el[0]), '') === 'index')?.[1] : body;
|
51
|
-
|
52
|
-
if (!loadTemplate) {
|
53
|
-
return reply.status(404).send(`report not found: ${params.name}`);
|
54
|
-
}
|
55
|
-
|
56
|
-
if (Array.isArray(body)) {
|
57
|
-
loadTemplate.widgets = [];
|
58
|
-
body.filter(el => el[0].replace(path.extname(el[0]), '') !== 'index').forEach((el) => {
|
59
|
-
loadTemplate.widgets.push(el[1]);
|
60
|
-
});
|
61
|
-
}
|
62
|
-
|
63
|
-
const { widgets = [] } = loadTemplate;
|
64
|
-
|
65
|
-
const widget = widgets.find(el => el.name === params.widget);
|
66
|
-
|
67
|
-
if (!widget) {
|
68
|
-
return reply.status(404).send(`widget not found: ${params.widget}`);
|
69
|
-
}
|
70
|
-
|
71
|
-
if (!widget.table || !pg.pk?.[widget.table]) {
|
72
|
-
return reply.status(404).send(`widget table not found: ${widget.table}`);
|
73
|
-
}
|
74
|
-
|
75
|
-
const { cls = {}, titles = {} } = widget.meta || {};
|
76
|
-
|
77
|
-
const limit = Math.min(query.limit || maxLimit, maxLimit);
|
78
|
-
const offset = query.page && query.page > 0 ? (query.page - 1) * limit : 0;
|
79
|
-
|
80
|
-
const { groupby, q } = normalizeData(widget, limit, offset);
|
81
|
-
|
82
|
-
if (groupby.cls) {
|
83
|
-
Object.assign(cls, { [groupby.name]: groupby.cls });
|
84
|
-
}
|
85
|
-
|
86
|
-
if (query.sql) return q;
|
87
|
-
|
88
|
-
const { rows = [], fields = [] } = await pg.query(q).catch(err => {
|
89
|
-
Object.assign(widget, { error: err.toString() });
|
90
|
-
}) || {};
|
91
|
-
await metaFormat({ rows, cls, sufix: false }, pg);
|
92
|
-
|
93
|
-
const columns = fields.map(el => ({
|
94
|
-
name: el.name,
|
95
|
-
title: titles?.[el.name] || el.name,
|
96
|
-
format: cls?.[el.name] ? 'select' : (matches[el.dataTypeID] || 'text'),
|
97
|
-
data: cls?.[el.name],
|
98
|
-
}));
|
99
|
-
|
100
|
-
Object.assign(widget, {
|
101
|
-
source: rows,
|
102
|
-
columns,
|
103
|
-
agg: user?.user_type === 'admin' ? widget.agg : undefined,
|
104
|
-
sql: user?.user_type === 'admin' ? q : undefined,
|
105
|
-
});
|
106
|
-
|
107
|
-
return widget;
|
108
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import tableData from './controllers/tableData.js';
|
2
|
-
import widgetData from './controllers/widgetData.js';
|
3
|
-
import reportList from './controllers/list.js';
|
4
|
-
|
5
|
-
export default async function route(app) {
|
6
|
-
app.get('/reports', {}, reportList);
|
7
|
-
app.get('/reports/:name', {}, tableData);
|
8
|
-
app.get('/reports/:name/:widget', {}, widgetData);
|
9
|
-
}
|
@@ -1,179 +0,0 @@
|
|
1
|
-
const dateTypeList = ['date', 'timestamp', 'timestamp without time zone', 'timestamp with time zone'];
|
2
|
-
const numberTypeList = ['float8', 'int4', 'int8', 'numeric', 'double precision', 'integer'];
|
3
|
-
const isValidDate = (dateStr) => {
|
4
|
-
const [dd, mm, yyyy] = dateStr.split('.');
|
5
|
-
return new Date(mm + '/' + dd + '/' + yyyy).toString() !== 'Invalid Date';
|
6
|
-
};
|
7
|
-
|
8
|
-
function dt(y, m, d) {
|
9
|
-
return new Date(Date.UTC(y, m, d)).toISOString().slice(0, 10);
|
10
|
-
}
|
11
|
-
const dp = {
|
12
|
-
d: new Date().getDate(),
|
13
|
-
w: new Date().getDate() - (new Date().getDay() || 7) + 1,
|
14
|
-
m: new Date().getMonth(),
|
15
|
-
q: (new Date().getMonth() / 4).toFixed() * 3,
|
16
|
-
y: new Date().getFullYear(),
|
17
|
-
};
|
18
|
-
|
19
|
-
function formatDateISOString(date) {
|
20
|
-
if (!date?.includes('.')) return date;
|
21
|
-
const [day, month, year] = date.split('.');
|
22
|
-
return `${year}-${month}-${day}`;
|
23
|
-
}
|
24
|
-
|
25
|
-
function formatValue({
|
26
|
-
pg, filter = {}, name, value, operator = '=', dataTypeID, uid = 1, optimize,
|
27
|
-
}) {
|
28
|
-
const { data, sql, extra } = filter;
|
29
|
-
const pk = false;
|
30
|
-
|
31
|
-
if (!dataTypeID && !extra) return {};
|
32
|
-
const fieldType = extra ? pg.pgType?.[{ Date: 1114 }[filter?.type] || 25] : pg.pgType?.[dataTypeID];
|
33
|
-
if (!name || !value || !fieldType) return {};
|
34
|
-
const filterType = filter.type?.toLowerCase();
|
35
|
-
|
36
|
-
// current day, week, month, year etc.
|
37
|
-
if (dateTypeList.includes(fieldType) && !value?.includes('_') && ['cd', 'cw', 'cm', 'cq', 'cy'].includes(value)) {
|
38
|
-
const query = {
|
39
|
-
cd: `${name}::date = '${dt(dp.y, dp.m, dp.d)}'::date`,
|
40
|
-
cw: `${name}::date >= '${dt(dp.y, dp.m, dp.w)}'::date and ${name} <= '${dt(dp.y, dp.m, dp.w + 6)}'::date`,
|
41
|
-
cm: `${name}::date >= '${dt(dp.y, dp.m, 1)}'::date and ${name} <= '${dt(dp.y, dp.m + 1, 0)}'::date`,
|
42
|
-
cq: `${name}::date >= '${dt(dp.y, dp.q, 1)}'::date and ${name} <= '${dt(dp.y, dp.q + 3, 0)}'::date`,
|
43
|
-
cy: `${name}::date >= '${dt(dp.y, 0, 1)}'::date and ${name}::date <= '${dt(dp.y, 11, 31)}'::date`,
|
44
|
-
}[value];
|
45
|
-
return { op: '=', query, extra };
|
46
|
-
}
|
47
|
-
|
48
|
-
// date range
|
49
|
-
if (dateTypeList.includes(fieldType) && value?.includes('_')) {
|
50
|
-
const [min, max] = value.split('_');
|
51
|
-
const query = `${name} >= '${min}'::date and ${name} <= '${max}'::date`;
|
52
|
-
return { op: 'between', query, extra };
|
53
|
-
}
|
54
|
-
|
55
|
-
// v3 filter date range, example - "01.01.2024-31.12.2024"
|
56
|
-
if (dateTypeList.includes(fieldType) && value?.includes('.') && value?.indexOf('-') === 10 && value?.length === 21) {
|
57
|
-
const [startDate, endDate] = value.split('-');
|
58
|
-
const min = formatDateISOString(startDate);
|
59
|
-
const max = formatDateISOString(endDate);
|
60
|
-
|
61
|
-
if (!isValidDate(startDate) || !isValidDate(endDate)) {
|
62
|
-
return { op: 'between', query: 'false', extra };
|
63
|
-
}
|
64
|
-
const query = extra && pk
|
65
|
-
? `${pk} in (select object_id from crm.extra_data where property_key='${name}' and value_date::date >= '${min}'::date and value_date::date <= '${max}'::date)`
|
66
|
-
: `${name}::date >= '${min}'::date and ${name}::date <= '${max}'::date`;
|
67
|
-
return { op: 'between', query, extra };
|
68
|
-
}
|
69
|
-
|
70
|
-
// my rows
|
71
|
-
if (value === 'me' && uid && fieldType === 'text') {
|
72
|
-
return { op: '=', query: extra ? `uid = '${uid}'` : `${name}::text = '${uid}'`, extra };
|
73
|
-
}
|
74
|
-
|
75
|
-
const formatType = {
|
76
|
-
float8: 'numeric',
|
77
|
-
int4: 'numeric',
|
78
|
-
int8: 'numeric',
|
79
|
-
varchar: 'text',
|
80
|
-
bool: 'boolean',
|
81
|
-
geometry: 'geom',
|
82
|
-
}[fieldType] || 'text';
|
83
|
-
|
84
|
-
if (optimize && optimize.name !== optimize.pk) {
|
85
|
-
const val = filterType === 'text' ? `ilike '%${value}%'` : `= any('{${value}}')`;
|
86
|
-
return {
|
87
|
-
op: '~',
|
88
|
-
query: fieldType?.includes('[]')
|
89
|
-
? `${optimize.pk} && (select array_agg(${optimize.pk}) from ${optimize.table} where ${name} ${val} )`
|
90
|
-
: `${optimize.pk} in (select ${optimize.pk} from ${optimize.table} where ${name} ${val} )`,
|
91
|
-
extra,
|
92
|
-
};
|
93
|
-
}
|
94
|
-
|
95
|
-
if (fieldType?.includes('[]')) {
|
96
|
-
return { op: 'in', query: `'{${value}}'::text[] && ${name}::text[]`, extra };
|
97
|
-
}
|
98
|
-
|
99
|
-
// multiple items of 1 param
|
100
|
-
if (value?.indexOf(',') !== -1) {
|
101
|
-
const values = value.split(',').filter((el) => el !== 'null');
|
102
|
-
if (extra && pk) {
|
103
|
-
const query = value?.indexOf('null') !== -1
|
104
|
-
? `${pk} in (select object_id from crm.extra_data where property_key='${name}' and ( value_text is null or value_text in (${values?.map((el) => `'"${el}"'`).join(',')}) ) )`
|
105
|
-
: `${pk} in (select object_id from crm.extra_data where property_key='${name}' and value_text in (${values?.map((el) => `'"${el}"'`).join(',')}) )`;
|
106
|
-
return { op: 'in', query, extra };
|
107
|
-
}
|
108
|
-
const query = value?.indexOf('null') !== -1
|
109
|
-
? `( ${name} is null or ${name}::text in (${values?.map((el) => `'${el}'`).join(',')}) )`
|
110
|
-
: `${name}::text in (${value.split(',')?.map((el) => `'${el}'`).join(',')})`;
|
111
|
-
return { op: 'in', query, extra };
|
112
|
-
}
|
113
|
-
|
114
|
-
// v3 filter number range, example - "100_500"
|
115
|
-
if (numberTypeList.includes(fieldType) && value?.indexOf('_') !== -1) {
|
116
|
-
const [min, max] = value.split('_');
|
117
|
-
const query = (max === 'max' ? `${name} > ${min}` : null) || (min === 'min' ? `${name} <= ${max}` : null) || `${name} between ${min} and ${max}`;
|
118
|
-
return { op: 'between', query, extra };
|
119
|
-
}
|
120
|
-
|
121
|
-
// number range
|
122
|
-
if (numberTypeList.includes(fieldType) && value?.indexOf('-') !== -1) {
|
123
|
-
const [min, max] = value.split('-');
|
124
|
-
if (min === 'min' && max === 'max') return {};
|
125
|
-
const query = (max === 'max' ? `${name} > ${min}` : null) || (min === 'min' ? `${name} < ${max}` : null) || `${name} between ${min} and ${max}`;
|
126
|
-
return { op: 'between', query, extra };
|
127
|
-
}
|
128
|
-
|
129
|
-
if (['<', '>'].includes(operator)) {
|
130
|
-
const query = `${name} ${operator} '${value}'::${formatType}`;
|
131
|
-
return { op: operator, query, extra };
|
132
|
-
}
|
133
|
-
|
134
|
-
if (operator === '=' && filterType !== 'text' && !filter?.data) {
|
135
|
-
const query = {
|
136
|
-
null: `${name} is null`,
|
137
|
-
notnull: `${name} is not null`,
|
138
|
-
}[value] || `${name}::${formatType}='${value}'::${formatType}`;
|
139
|
-
return { op: '=', query, extra };
|
140
|
-
}
|
141
|
-
|
142
|
-
if (['~', '='].includes(operator)) {
|
143
|
-
const operator1 = (filterType === 'text' && (filter?.id || filter?.name) && operator === '=' ? '~' : operator);
|
144
|
-
const matchNull = { null: 'is null', notnull: 'is not null' }[value];
|
145
|
-
const match = matchNull || ((operator1 === '=' || filterType === 'autocomplete') ? `='${value}'` : `ilike '%${value}%'`);
|
146
|
-
if (extra && pk) {
|
147
|
-
const query = data && sql
|
148
|
-
? `${pk} in (select object_id from crm.extra_data where property_key='${name}' and value_text in ( ( with q(id,name) as (${sql}) select id from q where ${filterType === 'autocomplete' ? 'id' : 'name'} ${match})))`
|
149
|
-
: `${pk} in (select object_id from crm.extra_data where property_key='${name}' and value_text ${match})`;
|
150
|
-
return { op: 'ilike', query, extra };
|
151
|
-
}
|
152
|
-
|
153
|
-
const query = filter?.data && filter?.sql
|
154
|
-
? `${filter?.name || filter?.id} in ( ( with q(id,name) as (${filter?.sql}) select id from q where ${filterType === 'autocomplete' ? 'id' : 'name'}::text ${match}) )` // filter with cls
|
155
|
-
: `${name}::text ${match}`; // simple filter
|
156
|
-
// console.log(query);
|
157
|
-
return { op: 'ilike', query };
|
158
|
-
}
|
159
|
-
|
160
|
-
// json
|
161
|
-
if (name.includes('.')) {
|
162
|
-
const [col, prop] = name.split('.');
|
163
|
-
const query = ` ${col}->>'${prop}' in ('${value.join("','")}')`;
|
164
|
-
return { op: 'in', query, extra };
|
165
|
-
}
|
166
|
-
|
167
|
-
// geometry
|
168
|
-
if (['geometry'].includes(fieldType)) {
|
169
|
-
const bbox = value[0].split('_');
|
170
|
-
|
171
|
-
if (bbox?.length === 4) {
|
172
|
-
const query = ` ${name} && 'box(${bbox[0]} ${bbox[1]},${bbox[2]} ${bbox[3]})'::box2d `;
|
173
|
-
return { op: '&&', query, extra };
|
174
|
-
}
|
175
|
-
}
|
176
|
-
return {};
|
177
|
-
}
|
178
|
-
|
179
|
-
export default formatValue;
|
@@ -1,68 +0,0 @@
|
|
1
|
-
/* eslint-disable no-continue */
|
2
|
-
|
3
|
-
import { pgClients } from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
import formatValue from './formatValue.js';
|
6
|
-
|
7
|
-
export default function getFilterQuery({ pg = pgClients.client, filter: filterStr, fields, filterList, searchColumns, search }) {
|
8
|
-
if (!filterStr && !search) return null;
|
9
|
-
|
10
|
-
const mainOperators = ['=', '~', '>', '<'];
|
11
|
-
|
12
|
-
const filterQueryArray = decodeURIComponent(filterStr?.replace(/%/g, '%25').replace(/%/g, '\\%')?.replace(/(^,)|(,$)/g, '')).replace(/'/g, '').split(/[;|]/);
|
13
|
-
|
14
|
-
const resultList = [];
|
15
|
-
const searchwith = searchColumns || fields?.filter?.((el) => pg.pgType?.[el.dataTypeID] === 'text')?.map?.((el) => el.name)?.join?.(',');
|
16
|
-
|
17
|
-
const sval = `ilike '%${decodeURIComponent(search?.replace(/%/g, '%25')).replace(/'/g, "''").replace(/%/g, '\\%')}%'`;
|
18
|
-
const searchQuery = search && searchwith ? ` (${searchwith.split(',')?.map((name) => `${name} ${sval}`).join(' or ')} )` : '';
|
19
|
-
|
20
|
-
for (let i = 0; i < filterQueryArray.length; i += 1) {
|
21
|
-
const item = filterQueryArray[i];
|
22
|
-
const operator = mainOperators?.find((el) => item.indexOf(el) !== -1) || '=';
|
23
|
-
const [name] = item.split(operator);
|
24
|
-
|
25
|
-
// skip already added filter
|
26
|
-
if (resultList.find((el) => el.name === name)) {
|
27
|
-
continue;
|
28
|
-
}
|
29
|
-
|
30
|
-
// filter
|
31
|
-
const filter = filterList?.find((el) => [el.id, el.name].includes(name)) || { type: 'text' };
|
32
|
-
|
33
|
-
// find all value
|
34
|
-
const value = filterQueryArray.filter((el) => el.startsWith(name)).map((el) => el.substring(name.length + 1)).join(',');
|
35
|
-
|
36
|
-
if (filter?.query) {
|
37
|
-
resultList.push({
|
38
|
-
name, value, query: filter?.query, operator: '=', filterType: filter.type, type: 'text',
|
39
|
-
});
|
40
|
-
continue;
|
41
|
-
}
|
42
|
-
|
43
|
-
// find field and skip not exists
|
44
|
-
const { dataTypeID } = fields?.find((el) => el.name === name) || {};
|
45
|
-
|
46
|
-
// format query
|
47
|
-
const {
|
48
|
-
op, query, filterType, fieldType,
|
49
|
-
} = formatValue({
|
50
|
-
pg,
|
51
|
-
filter,
|
52
|
-
name,
|
53
|
-
value,
|
54
|
-
operator,
|
55
|
-
dataTypeID,
|
56
|
-
}) || {};
|
57
|
-
if (!query) continue;
|
58
|
-
|
59
|
-
resultList.push({
|
60
|
-
name, value, query, operator: op, filterType, type: fieldType,
|
61
|
-
});
|
62
|
-
}
|
63
|
-
|
64
|
-
const where = [searchQuery].concat(resultList?.map?.(el => el.query) || []).filter(el => el).join(' and ');
|
65
|
-
|
66
|
-
return where;
|
67
|
-
}
|
68
|
-
|