@opengis/bi 1.0.30 → 1.0.32
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/package.json
CHANGED
package/plugin.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import fp from 'fastify-plugin';
|
|
2
|
-
import
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { config, addTemplateDir, execMigrations } from '@opengis/fastify-table/utils.js';
|
|
6
|
+
|
|
7
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
8
|
+
const dirName = path.dirname(fileName);
|
|
9
|
+
|
|
10
|
+
async function plugin(fastify, opt) {
|
|
7
11
|
fastify.register(import('./server/routes/dashboard/index.mjs'), config);
|
|
8
12
|
fastify.register(import('./server/routes/dataset/index.mjs'), config);
|
|
9
13
|
|
|
10
14
|
fastify.register(import('./server/routes/data/index.mjs'), config);
|
|
11
15
|
fastify.register(import('./server/routes/edit/index.mjs'), config);
|
|
12
|
-
|
|
16
|
+
fastify.register(import('./server/routes/map/index.mjs'), config);
|
|
17
|
+
config.templates?.forEach(el => addTemplateDir(el));
|
|
13
18
|
|
|
19
|
+
const dir = path.join(dirName, 'server/migrations');
|
|
20
|
+
execMigrations(dir).catch(err => console.log(err));
|
|
21
|
+
}
|
|
14
22
|
export default fp(plugin);
|
|
@@ -141,7 +141,7 @@ export default async function dataAPI(req, reply) {
|
|
|
141
141
|
rows
|
|
142
142
|
.filter((row) => row[x])
|
|
143
143
|
.forEach((row) => {
|
|
144
|
-
Object.assign(row, { [x]: vals?.[row[x]] || row[x] });
|
|
144
|
+
Object.assign(row, { [x]: vals?.[row[x]]?.text || vals?.[row[x]] || row[x] });
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
|
|
@@ -82,10 +82,10 @@ export default async function cluster(req) {
|
|
|
82
82
|
? await getFilterSQL({ pg, table, filter, search })
|
|
83
83
|
: {};
|
|
84
84
|
|
|
85
|
-
const q = `select
|
|
85
|
+
const q = `select b.*, ${clusterTable?.operator || 'sum'}("${metrics[0]}")::float as metric
|
|
86
86
|
from ${optimizedSQL ? `(${optimizedSQL})` : table} q
|
|
87
|
-
left join lateral (select "${pg.pk?.[clusterTable?.name]}" as id from ${clusterTable?.name} where ${clusterTable?.
|
|
88
|
-
where ${where} group by
|
|
87
|
+
left join lateral (select "${pg.pk?.[clusterTable?.name]}" as id, ${clusterTable?.column || cluster} as name, ${clusterTable?.title} as title from ${clusterTable?.name} where ${clusterTable?.codifierColumn || 'codifier'}=q."${clusterTable?.column || cluster}" limit 1)b on 1=1
|
|
88
|
+
where ${where} group by b.id, b.name, b.title order by ${clusterTable?.operator || 'sum'}("${metrics[0]}")::float desc`;
|
|
89
89
|
|
|
90
90
|
if (query.sql === '1') return q;
|
|
91
91
|
|
|
@@ -4,7 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import { createHash } from 'crypto';
|
|
5
5
|
import { writeFile, mkdir } from 'fs/promises';
|
|
6
6
|
|
|
7
|
-
import { getFolder, getFilterSQL, autoIndex, pgClients } from '@opengis/fastify-table/utils.js';
|
|
7
|
+
import { logger, getFolder, getFilterSQL, autoIndex, pgClients } from '@opengis/fastify-table/utils.js';
|
|
8
8
|
|
|
9
9
|
import { getWidget } from '../../../../utils.js';
|
|
10
10
|
|
|
@@ -105,14 +105,14 @@ export default async function clusterVtile(req, reply) {
|
|
|
105
105
|
? await getFilterSQL({ pg, table, filter, search })
|
|
106
106
|
: {};
|
|
107
107
|
|
|
108
|
-
const q = `select
|
|
108
|
+
const q = `select ${clusterTable?.column || cluster} as name, ${clusterTable?.operator || 'sum'}("${metrics[0]}")::float as metric, b.*
|
|
109
109
|
from ${optimizedSQL ? `(${optimizedSQL})` : table} q
|
|
110
|
-
left join lateral (select "${pg.pk?.[clusterTable?.name]}" as id,
|
|
110
|
+
left join lateral (select "${pg.pk?.[clusterTable?.name]}" as id, ${clusterTable?.title} as title,
|
|
111
111
|
${clusterTable?.geom || 'geom'} as geom from ${clusterTable?.name}
|
|
112
|
-
where ${clusterTable?.query || '1=1'} and ${clusterTable?.
|
|
112
|
+
where ${clusterTable?.query || '1=1'} and ${clusterTable?.codifierColumn || 'codifier'}=q."${clusterTable?.column || cluster}" limit 1
|
|
113
113
|
)b on 1=1
|
|
114
114
|
where ${where} group by
|
|
115
|
-
${cluster}, b.id, b
|
|
115
|
+
q."${clusterTable?.column || cluster}", b.id, b.title, b.geom`;
|
|
116
116
|
|
|
117
117
|
if (query.sql === '1') return q;
|
|
118
118
|
|
|
@@ -129,7 +129,7 @@ export default async function clusterVtile(req, reply) {
|
|
|
129
129
|
SELECT
|
|
130
130
|
floor(random() * 100000 + 1)::int + row_number() over() as row,
|
|
131
131
|
|
|
132
|
-
${pg.pk?.[clusterTable?.name] ? 'id,' : ''} name, metric,
|
|
132
|
+
${pg.pk?.[clusterTable?.name] ? 'id,' : ''} name, metric, title,
|
|
133
133
|
|
|
134
134
|
ST_AsMVTGeom(st_transform(${geomCol}, 3857),ST_TileEnvelope(${z},${y},${x})::box2d,4096,256,false) as geom
|
|
135
135
|
|