@opengis/gis 0.1.77 → 0.1.79
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/index.js +577 -577
- package/dist/index.umd.cjs +4 -4
- package/module/test/cls/doc_status.json +31 -31
- package/module/test/select/core.user_uid.sql +1 -1
- package/package.json +61 -58
- package/server/plugins/mapnik/funcs/map.proto +241 -241
- package/server/routes/gis/index.mjs +6 -0
- package/server/routes/gis/registers/add.registry.js +36 -0
- package/server/routes/gis/registers/del.registry.js +15 -0
- package/server/routes/gis/registers/funcs/classifiers.js +47 -1
- package/server/routes/gis/registers/funcs/handleRegistryRequest.js +34 -11
|
@@ -12,12 +12,18 @@ import getServices from './services/get.services.js';
|
|
|
12
12
|
import deleteService from './services/del.service.js';
|
|
13
13
|
import addService from './services/add.service.js';
|
|
14
14
|
|
|
15
|
+
import addGisRegistry from './registers/add.registry.js';
|
|
16
|
+
import deleteGisRegistry from './registers/del.registry.js';
|
|
17
|
+
|
|
15
18
|
async function route(app) {
|
|
16
19
|
app.put('/insert-columns/:token', insertColumns);
|
|
17
20
|
app.put('/insert-filters/:token', insertFilters);
|
|
18
21
|
app.get('/gis-registry/:slug', { config: { policy: ['public'] } }, gisRegistry);
|
|
19
22
|
app.get('/gis-registry/:slug/:objectId', { config: { policy: ['public'] } }, gisRegistry);
|
|
20
23
|
app.get('/gis-registry', { config: { policy: ['public'] } }, gisRegistryList);
|
|
24
|
+
app.post('/gis-registry', { config: { policy: ['public'] } }, addGisRegistry);
|
|
25
|
+
app.put('/gis-registry/:slug', { config: { policy: ['public'] } }, addGisRegistry);
|
|
26
|
+
app.delete('/gis-registry/:slug', { config: { policy: ['public'] } }, deleteGisRegistry);
|
|
21
27
|
app.get('/map-registry/:slug/:id', { config: { policy: ['public'] } }, mapRegistry);
|
|
22
28
|
|
|
23
29
|
app.get('/xml/:id', { config: { policy: ['public'] } }, metadataXML);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { dataInsert, dataUpdate, pgClients } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function addGisRegistry({
|
|
4
|
+
method, params = {}, body, pg = pgClients.client, user = {},
|
|
5
|
+
}, reply) {
|
|
6
|
+
if (method === 'POST') {
|
|
7
|
+
|
|
8
|
+
if (!body?.register_key) {
|
|
9
|
+
return reply.status(400).send('not enough body params: register_key');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { rows = [] } = await dataInsert({
|
|
13
|
+
pg,
|
|
14
|
+
table: 'gis.registers',
|
|
15
|
+
data: body,
|
|
16
|
+
uid: user?.uid,
|
|
17
|
+
});
|
|
18
|
+
return reply.status(200).send(rows[0]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!params.slug) {
|
|
22
|
+
return reply.status(400).send('not enough params: slug');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const id = await pg.query('select register_id from gis.registers where register_key=$1', [params.slug]).then(el => el.rows?.[0]?.register_id) || params.slug;
|
|
26
|
+
|
|
27
|
+
const row = await dataUpdate({
|
|
28
|
+
pg,
|
|
29
|
+
id,
|
|
30
|
+
table: 'gis.registers',
|
|
31
|
+
data: body,
|
|
32
|
+
uid: user?.uid,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return reply.status(200).send(row);
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { dataDelete, pgClients } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function deleteGisRegistry({
|
|
4
|
+
params = {}, pg = pgClients.client, user = {},
|
|
5
|
+
}, reply) {
|
|
6
|
+
const id = await pg.query('select register_id from gis.registers where register_key=$1', [params.slug]).then(el => el.rows?.[0]?.register_id) || params.slug;
|
|
7
|
+
|
|
8
|
+
const row = await dataDelete({
|
|
9
|
+
pg,
|
|
10
|
+
id,
|
|
11
|
+
table: 'gis.registers',
|
|
12
|
+
uid: user?.uid,
|
|
13
|
+
});
|
|
14
|
+
return reply.status(200).send(row);
|
|
15
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSelectVal } from '@opengis/fastify-table/utils.js';
|
|
1
|
+
import { getSelectVal, getSelect } from '@opengis/fastify-table/utils.js';
|
|
2
2
|
|
|
3
3
|
export async function attachClassifiers(rowOrRows, classifiers = []) {
|
|
4
4
|
const rows = Array.isArray(rowOrRows) ? rowOrRows : [rowOrRows];
|
|
@@ -35,3 +35,49 @@ export async function attachClassifiers(rowOrRows, classifiers = []) {
|
|
|
35
35
|
|
|
36
36
|
return rowOrRows;
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
export async function populateFilterOptions({ pg, table, filters, columns, whereConditions }) {
|
|
40
|
+
if (!filters?.length || !table || !columns?.length) return;
|
|
41
|
+
|
|
42
|
+
const optimizedSQL = `select * from ${table} where ${whereConditions || '1=1'}`;
|
|
43
|
+
|
|
44
|
+
await Promise.all(
|
|
45
|
+
filters
|
|
46
|
+
.filter(
|
|
47
|
+
(el) =>
|
|
48
|
+
el.id &&
|
|
49
|
+
el.type !== "Autocomplete" &&
|
|
50
|
+
!el.sql &&
|
|
51
|
+
!el.options?.find?.((item) => item.sql)
|
|
52
|
+
)
|
|
53
|
+
.map(async (el) => {
|
|
54
|
+
const cls = el.data ? await getSelect(el.data, pg) : null;
|
|
55
|
+
|
|
56
|
+
if (!cls && !el.type?.includes?.("Check")) return;
|
|
57
|
+
const { dataTypeID } = (columns || []).find((item) => item.name === el.id) || {};
|
|
58
|
+
|
|
59
|
+
const q = pg.pgType[dataTypeID || '']?.includes("[]")
|
|
60
|
+
? `select unnest(${el.id})::text as id,count(*) from (${optimizedSQL})q group by unnest(${el.id}) limit 100`
|
|
61
|
+
: `select ${el.id}::text as id,count(*) from (${optimizedSQL})q group by ${el.id} limit 100`;
|
|
62
|
+
|
|
63
|
+
const countArr = await pg.queryCache(q, { table });
|
|
64
|
+
|
|
65
|
+
if (countArr.timeout) {
|
|
66
|
+
Object.assign(el, { timeout: countArr.timeout });
|
|
67
|
+
console.warn("timeout filter", table, el.id);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const ids = countArr.rows.map((el1) => el1.id);
|
|
71
|
+
|
|
72
|
+
const clsData = await getSelectVal({ pg, values: ids, name: el.data });
|
|
73
|
+
|
|
74
|
+
const options = countArr.rows.map((cel) => {
|
|
75
|
+
const data = cls?.arr?.find?.(
|
|
76
|
+
(c) => c.id?.toString?.() === cel.id?.toString?.()
|
|
77
|
+
) || { text: clsData?.[cel.id]?.text || clsData?.[cel.id] || cel.id };
|
|
78
|
+
return { ...cel, id: cel.id === null ? "null" : cel.id, ...data };
|
|
79
|
+
});
|
|
80
|
+
Object.assign(el, { options });
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import { attachClassifiers } from './classifiers.js';
|
|
1
|
+
import { attachClassifiers, populateFilterOptions } from './classifiers.js';
|
|
2
2
|
import { extractVisibleColumns } from './columns.js';
|
|
3
3
|
import { getMeta, getFilterSQL } from "@opengis/fastify-table/utils.js";
|
|
4
4
|
|
|
5
|
+
const columnType = {
|
|
6
|
+
text: 'text',
|
|
7
|
+
date: 'date',
|
|
8
|
+
bool: 'yes/no',
|
|
9
|
+
numeric: 'number',
|
|
10
|
+
integer: 'number',
|
|
11
|
+
'timestamp without time zone': 'date',
|
|
12
|
+
'timestamp with time zone': 'date',
|
|
13
|
+
};
|
|
14
|
+
|
|
5
15
|
export async function handleRegistryRequest({ settings, query, object_id, offset = 0, limit = 16, page = 1, pg }) {
|
|
6
16
|
const { name, table_name, columns, filters, query: whereQuery, order, pk, register_id, is_files, view } = settings;
|
|
7
17
|
const parsedColumns = Array.isArray(columns) ? columns : JSON.parse(columns);
|
|
8
18
|
const filtersParsed = Array.isArray(filters) ? filters : JSON.parse(filters);
|
|
9
|
-
const activeFilters = filtersParsed.filter((f) => f.disabled !== true);
|
|
10
|
-
const { geom } = await getMeta({ pg, table: table_name });
|
|
19
|
+
const activeFilters = (filtersParsed || []).filter((f) => f.disabled !== true);
|
|
20
|
+
const { columns: fields1, geom } = await getMeta({ pg, table: table_name });
|
|
21
|
+
|
|
22
|
+
const fields = fields1?.map?.(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'] || 'text', label: title || name }));
|
|
11
23
|
|
|
12
24
|
const mode = object_id ? "card" : "table";
|
|
13
|
-
const visibleColumns = extractVisibleColumns(parsedColumns, mode);
|
|
25
|
+
const visibleColumns = parsedColumns ? extractVisibleColumns(parsedColumns, mode) : [];
|
|
14
26
|
const selectColumns = visibleColumns.map((col) => col.name);
|
|
15
27
|
/*const columnsInfo = visibleColumns.map((col) => ({
|
|
16
28
|
name: col.name,
|
|
@@ -26,7 +38,7 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
26
38
|
|
|
27
39
|
if (object_id) {
|
|
28
40
|
const sql = `
|
|
29
|
-
SELECT "${pk}" as id,*
|
|
41
|
+
SELECT "${pk}" as id,* ${selectColumns.length ? `, ${selectColumns.join(", ")}` : ''} ${geom ? `, st_asgeojson(${geom})::json as geom` : ''}
|
|
30
42
|
FROM ${table_name}
|
|
31
43
|
WHERE ${pk} = $1
|
|
32
44
|
`;
|
|
@@ -60,13 +72,12 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
60
72
|
: { q: '1=1' };
|
|
61
73
|
|
|
62
74
|
const whereConditions = [whereQuery, sqlFilter].filter(Boolean).join(' AND ');
|
|
63
|
-
const whereClause = whereConditions ? `WHERE ${whereConditions}` : '';
|
|
64
75
|
|
|
65
|
-
const sqlBase = `FROM ${table_name} ${
|
|
76
|
+
const sqlBase = `FROM ${table_name} WHERE ${whereConditions || 'true'}`;
|
|
66
77
|
const sqlOrder = order ? `ORDER BY ${order}` : "";
|
|
67
78
|
const sqlLimit = `LIMIT $1 OFFSET $2`;
|
|
68
79
|
|
|
69
|
-
const sqlSelect = `SELECT "${pk}" as id
|
|
80
|
+
const sqlSelect = `SELECT "${pk}" as id ${selectColumns.length ? `, ${selectColumns.join(", ")}` : ''} ${geom ? `, st_asgeojson(${geom})::json as geom` : ''} ${sqlBase}`;
|
|
70
81
|
const dataQuery = `${sqlSelect} ${sqlOrder} ${sqlLimit}`;
|
|
71
82
|
const totalQuery = `SELECT COUNT(*) ${sqlBase}`;
|
|
72
83
|
|
|
@@ -79,11 +90,22 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
79
90
|
const total = parseInt(countRes.rows[0]?.count || 0, 10);
|
|
80
91
|
|
|
81
92
|
const listConfig = {};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
|
|
94
|
+
if (parsedColumns?.length) {
|
|
95
|
+
for (const col of parsedColumns) {
|
|
96
|
+
if (col.view_type === 'title') listConfig.title = col.name;
|
|
97
|
+
if (col.view_type === 'subtitle') listConfig.subtitle = col.name;
|
|
98
|
+
}
|
|
85
99
|
}
|
|
86
100
|
|
|
101
|
+
await populateFilterOptions({
|
|
102
|
+
pg,
|
|
103
|
+
table: table_name,
|
|
104
|
+
filters: activeFilters,
|
|
105
|
+
columns,
|
|
106
|
+
whereConditions
|
|
107
|
+
});
|
|
108
|
+
|
|
87
109
|
return {
|
|
88
110
|
register_id,
|
|
89
111
|
name,
|
|
@@ -91,6 +113,7 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
91
113
|
total,
|
|
92
114
|
columns: visibleColumns,
|
|
93
115
|
filters: activeFilters,
|
|
116
|
+
fields,
|
|
94
117
|
limit,
|
|
95
118
|
page,
|
|
96
119
|
view,
|