@opengis/bi 1.2.31 → 1.2.34

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.
@@ -20,14 +20,15 @@ export default async function dashboard({
20
20
 
21
21
  const fileDashboard = dashboards.find((el) => el[0] === id);
22
22
  if (!fileDashboard) {
23
- const sql = `select title, description, table_name, panels, grid, widgets, filters, style, words, db, public
23
+ const sql = `select title, description, table_name, panels, grid, widgets, filters, style, words, db, public, updated_at as last_update
24
24
  from bi.dashboard where $1 in (dashboard_id, name)`;
25
25
 
26
26
  const data = await pg1.query(sql, [id]).then(el => el.rows?.[0] || {});
27
27
 
28
28
  let pg = pg1;
29
29
  try {
30
- pg = data.pg || (data.db ? await getPGAsync(data.db) : null) || pg1;
30
+ const db = typeof data.db === 'string' && data.db.startsWith('{') ? JSON.parse(data.db) : { database: data.db };
31
+ pg = data.pg || (data.db ? await getPGAsync(db) : null) || pg1;
31
32
  } catch (err) {
32
33
  data.error = err.toString();
33
34
  }
@@ -24,7 +24,7 @@ export default async function dashboardList({
24
24
  const where = [search ? `lower(title) ~ $1` : null, type === 'viewer' ? `left(table_name,5)='demo.'` : null].filter(Boolean).join(' and ') || 'true';
25
25
  const q1 = `select count(*)::int as total, count(*) filter(where ${where})::int as filtered from bi.dashboard`;
26
26
 
27
- const q = `select dashboard_id as name, 'db' as type, title, description, table_name, words, public from bi.dashboard where ${where} limit ${limit} offset ${offset}`;
27
+ const q = `select dashboard_id as name, 'db' as type, title, description, table_name, words, public, updated_at as last_update from bi.dashboard where ${where} limit ${limit} offset ${offset}`;
28
28
 
29
29
  if (user?.user_type?.includes('admin') && ['db', 'viewer'].includes(type) && sql) {
30
30
  return `${q1};${q}`;
@@ -189,6 +189,7 @@ export default async function dataAPI(req, reply) {
189
189
 
190
190
  const res = {
191
191
  time: Date.now() - time,
192
+ last_update: widgetData?.last_update,
192
193
  error: error || errorSql || (!widgetData.sql ? widgetData.error : undefined),
193
194
  dimensions,
194
195
  filter: xName,
@@ -10,7 +10,7 @@ async function getWidget({ pg: pg1 = pgClients.client, dashboard, widget }) {
10
10
  ? await getTemplate('dashboard', dashboard)
11
11
  : null;
12
12
 
13
- const dashboardData1 = await pg1.query(`select db, table_name, widgets as "dashboardWidgets" from bi.dashboard where dashboard_id=$1`, [dashboard])
13
+ const dashboardData1 = await pg1.query(`select db, table_name, widgets as "dashboardWidgets", updated_at as "updatedAt" from bi.dashboard where dashboard_id=$1`, [dashboard])
14
14
  .then(el => el.rows?.[0] || {});
15
15
  const { dashboardWidgets = [] } = dashboardData1;
16
16
  const dashboardDb = typeof dashboardData1?.db === 'string' && dashboardData1?.db?.startsWith('{') ? JSON.parse(dashboardData1?.db) : dashboardData1?.db;
@@ -18,9 +18,9 @@ async function getWidget({ pg: pg1 = pgClients.client, dashboard, widget }) {
18
18
  const dashboardIndex = dashboardData?.find((el) => el[0] == 'index.yml')?.[1]; // dashboardData?.find((el) => el[2] == 'index')?.[1]
19
19
  const pg = dashboardDb || dashboardIndex?.db ? await getPGAsync(dashboardDb || dashboardIndex?.db) : pg1;
20
20
 
21
- const { id, tableName } =
21
+ const { id, tableName, updatedAt } =
22
22
  !dashboardData && !dashboardData1 && pg.pk['bi.dashboard'] && dashboard
23
- ? await pg1.query(`select dashboard_id as id, table_name as "tableName" from bi.dashboard where $1 in (dashboard_id, name)`, [dashboard])
23
+ ? await pg1.query(`select dashboard_id as id, table_name as "tableName", updated_at as "updatedAt" from bi.dashboard where $1 in (dashboard_id, name)`, [dashboard])
24
24
  .then(el => el.rows?.[0] || {})
25
25
  : {};
26
26
 
@@ -55,7 +55,8 @@ async function getWidget({ pg: pg1 = pgClients.client, dashboard, widget }) {
55
55
  controls,
56
56
  style,
57
57
  options,
58
- yml
58
+ yml,
59
+ updated_at: widgetUpdatedAt,
59
60
  } = widgetData ||
60
61
  (await pg
61
62
  .query(q, [id || dashboard, widget])
@@ -104,7 +105,7 @@ async function getWidget({ pg: pg1 = pgClients.client, dashboard, widget }) {
104
105
 
105
106
  const columnList = columns.map(col => col.name);
106
107
 
107
- const res = { ...main, pg: widgetDb, sql: widgetData?.sql, limit: widgetData?.limit, tableSQL, data, type, text, controls, style, options, yml };
108
+ const res = { ...main, pg: widgetDb, sql: widgetData?.sql, limit: widgetData?.limit, tableSQL, data, type, text, controls, style, options, yml, last_update: { dashboard: dashboardData1?.updatedAt || updatedAt, widget: widgetUpdatedAt || dashboardData1?.updatedAt || updatedAt } };
108
109
  if (res.x && !columnList.includes(res.x) && !loadTemplate?.table && !tableSQL?.includes?.(res.x)) {
109
110
  Object.assign(res, { x: null, error: `column does not exists: ${res.x} at table ${res.table}` });
110
111
  }