@datalabz_/dashboard-kit 6.0.9 → 6.0.11
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 +1 -1
- package/v4.js +1 -1
- package/v5.js +1 -1
- package/v6.js +85 -8
package/package.json
CHANGED
package/v4.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
let _activeTabId = '';
|
|
21
21
|
let _sections = []; // { id, label, load, loaded, errors }
|
|
22
22
|
let _title = '';
|
|
23
|
-
let _gitVer = '
|
|
23
|
+
let _gitVer = '679acd7'; // replaced at deploy: sed -i "s/679acd7/$(git rev-parse --short HEAD)/g" v4.js
|
|
24
24
|
let _calls = []; // System Info call log
|
|
25
25
|
let _sectionErrors = {}; // sectionId → error count
|
|
26
26
|
let _generation = 0;
|
package/v5.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
let _activeTabId = '';
|
|
21
21
|
let _sections = []; // { id, label, load, loaded, errors }
|
|
22
22
|
let _title = '';
|
|
23
|
-
let _gitVer = '
|
|
23
|
+
let _gitVer = '679acd7'; // replaced at deploy: sed -i "s/679acd7/$(git rev-parse --short HEAD)/g" v4.js
|
|
24
24
|
let _calls = []; // System Info call log
|
|
25
25
|
let _sectionErrors = {}; // sectionId → error count
|
|
26
26
|
let _generation = 0;
|
package/v6.js
CHANGED
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
let _activeTabId = '';
|
|
21
21
|
let _sections = []; // { id, label, load, loaded, errors }
|
|
22
22
|
let _title = '';
|
|
23
|
-
let _gitVer = '
|
|
23
|
+
let _gitVer = '679acd7'; // replaced at deploy: sed -i "s/679acd7/$(git rev-parse --short HEAD)/g" v6.js
|
|
24
24
|
let _calls = []; // System Info call log
|
|
25
|
+
let _pageErrors = []; // System Info: errors no load() caught (a handler's, a timer's, the page script's)
|
|
25
26
|
let _sectionErrors = {}; // sectionId → error count
|
|
26
27
|
let _generation = 0;
|
|
28
|
+
let _abort = new AbortController(); // this generation's requests; _invalidateAll aborts them
|
|
27
29
|
let _ttEl = null;
|
|
28
30
|
let _pendingFilters = {}; // header filters a parent sent before boot, applied at boot
|
|
29
31
|
let _filtersRefused = false;
|
|
@@ -1583,6 +1585,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1583
1585
|
|
|
1584
1586
|
function _invalidateAll() {
|
|
1585
1587
|
_generation++;
|
|
1588
|
+
_abort.abort();
|
|
1589
|
+
_abort = new AbortController();
|
|
1586
1590
|
_sections.forEach(function (s) { s.loaded = false; s.errors = 0; });
|
|
1587
1591
|
_sectionErrors = {};
|
|
1588
1592
|
_calls = [];
|
|
@@ -1600,6 +1604,18 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1600
1604
|
// its own, so without this reset a section that fails once, then succeeds
|
|
1601
1605
|
// on retry, would keep showing its old error badge forever.
|
|
1602
1606
|
_sectionErrors[sec.id] = 0;
|
|
1607
|
+
// Chart.js keeps every chart in its registry, data and all, until destroy(). The spinner below
|
|
1608
|
+
// replaces the panel's canvases, so their charts go first: a dashboard that forgot its own
|
|
1609
|
+
// Chart.getChart(id)?.destroy() would keep one dead chart per reload. One that did not forget
|
|
1610
|
+
// then finds none, as on a first load.
|
|
1611
|
+
const Chart = global.Chart;
|
|
1612
|
+
if (Chart && Chart.instances) {
|
|
1613
|
+
Object.keys(Chart.instances).forEach(function (k) {
|
|
1614
|
+
const chart = Chart.instances[k];
|
|
1615
|
+
if (!chart || !chart.canvas || !panel.contains(chart.canvas)) return;
|
|
1616
|
+
try { chart.destroy(); } catch (err) { console.error('[DashboardKit] could not destroy a chart:', err); }
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1603
1619
|
setSectionState(panel, 'loading');
|
|
1604
1620
|
_setPill('loading', 'loading…');
|
|
1605
1621
|
// What a click point drawn by this load reports: this section, and the header filters and the
|
|
@@ -1607,27 +1623,34 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1607
1623
|
const ctx = { id: sec.id, localFilters: _headerSnapshot(), context: _contextSnapshot() };
|
|
1608
1624
|
// Kept on the section for a render call that arrives without it (_ctxOf).
|
|
1609
1625
|
sec.ctx = ctx;
|
|
1626
|
+
// A replaced load must not draw (see _superseded). It stops at its next query; these stop one that
|
|
1627
|
+
// was awaiting something else when it was replaced and draws on its return. Only while the load
|
|
1628
|
+
// runs: a handler it leaves behind calls and draws as it always has.
|
|
1629
|
+
let running = true;
|
|
1630
|
+
const replaced = function () { return running && gen !== _generation; };
|
|
1610
1631
|
try {
|
|
1611
1632
|
await sec.load({
|
|
1612
|
-
runQuery,
|
|
1633
|
+
runQuery: function (s, l, q, a, p) { return runQuery(s, l, q, a, p, running ? gen : null); },
|
|
1613
1634
|
formatCurrency,
|
|
1614
1635
|
formatPercent,
|
|
1615
1636
|
formatInteger: fmtInt,
|
|
1616
1637
|
formatDate: fmtDate,
|
|
1617
1638
|
formatDatetime: fmtDatetime,
|
|
1618
|
-
renderTable: function (c, r, o) { return renderTable(c, r, o, ctx); },
|
|
1619
|
-
renderKpiCard: function (c, i) { return renderKpiCard(c, i, ctx); },
|
|
1620
|
-
renderKpiStrip: function (c, i, o) { return renderKpiStrip(c, i, o, ctx); },
|
|
1621
|
-
renderInfoGrid: function (c, i, o) { return renderInfoGrid(c, i, o, ctx); },
|
|
1622
|
-
renderTotalsStrip: function (c, i, o) { return renderTotalsStrip(c, i, o, ctx); },
|
|
1639
|
+
renderTable: function (c, r, o) { if (!replaced()) return renderTable(c, r, o, ctx); },
|
|
1640
|
+
renderKpiCard: function (c, i) { if (!replaced()) return renderKpiCard(c, i, ctx); },
|
|
1641
|
+
renderKpiStrip: function (c, i, o) { if (!replaced()) return renderKpiStrip(c, i, o, ctx); },
|
|
1642
|
+
renderInfoGrid: function (c, i, o) { if (!replaced()) return renderInfoGrid(c, i, o, ctx); },
|
|
1643
|
+
renderTotalsStrip: function (c, i, o) { if (!replaced()) return renderTotalsStrip(c, i, o, ctx); },
|
|
1623
1644
|
escHtml: esc,
|
|
1624
1645
|
colorClass,
|
|
1625
1646
|
filters: DashboardKit.filters,
|
|
1626
1647
|
});
|
|
1648
|
+
running = false;
|
|
1627
1649
|
if (gen !== _generation) return;
|
|
1628
1650
|
sec.loaded = true;
|
|
1629
1651
|
sec.errors = _sectionErrors[sec.id] || 0;
|
|
1630
1652
|
} catch (e) {
|
|
1653
|
+
running = false;
|
|
1631
1654
|
// The real exception, stack and dkCall included — the panel and the report only get a phrase.
|
|
1632
1655
|
console.error('[DashboardKit] section "' + sec.id + '" failed:', e);
|
|
1633
1656
|
console.log('[DashboardKit] section "' + sec.id + '" failed:', e);
|
|
@@ -1698,8 +1721,30 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1698
1721
|
}
|
|
1699
1722
|
|
|
1700
1723
|
// ── runQuery ──────────────────────────────────────────────────────────────────
|
|
1724
|
+
// A load that Refresh or new host params replaced must not draw: its rows are for the old period or
|
|
1725
|
+
// filters, and would land over the newer load's, with drillthrough points reporting either load's
|
|
1726
|
+
// filters. So a query a replaced load made is aborted and never settles: the load stays on its
|
|
1727
|
+
// await and runs nothing after it. Not a throw: a dashboard that wraps its queries in try/catch
|
|
1728
|
+
// would draw its own "No data" or error text over the newer load's. A fresh promise each time:
|
|
1729
|
+
// one shared never-settling promise would hold every load ever left on it. A query no running
|
|
1730
|
+
// load made — a handler's — is left as it always was: replacing its section's load never touched
|
|
1731
|
+
// it, so it must not start failing now (README → Rules).
|
|
1732
|
+
function _superseded() {
|
|
1733
|
+
return new Promise(function () {});
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1701
1736
|
// One retry, only where _isRetryable says the same request may succeed.
|
|
1702
|
-
|
|
1737
|
+
// _gen: the generation of the running load() that handed this runQuery over, or null when that
|
|
1738
|
+
// load had finished. A call by the global name belongs to its section's load if that is running.
|
|
1739
|
+
async function runQuery(sectionId, callLabel, sql, args, params, _gen) {
|
|
1740
|
+
let gen = _gen;
|
|
1741
|
+
if (gen === undefined) {
|
|
1742
|
+
const sec = _sections.find(function (s) { return s.id === sectionId; });
|
|
1743
|
+
gen = sec && sec.pending && sec.runGen === _generation ? _generation : null;
|
|
1744
|
+
}
|
|
1745
|
+
const replaced = function () { return gen !== null && gen !== _generation; };
|
|
1746
|
+
if (replaced()) return _superseded();
|
|
1747
|
+
const signal = gen === null ? undefined : _abort.signal;
|
|
1703
1748
|
const t0 = performance.now();
|
|
1704
1749
|
const entry = {
|
|
1705
1750
|
index: _calls.length + 1,
|
|
@@ -1730,9 +1775,11 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1730
1775
|
method: 'POST',
|
|
1731
1776
|
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + _authToken },
|
|
1732
1777
|
body: JSON.stringify(body),
|
|
1778
|
+
signal: signal,
|
|
1733
1779
|
});
|
|
1734
1780
|
entry.status = res.status;
|
|
1735
1781
|
const text = await res.text();
|
|
1782
|
+
if (replaced()) return _superseded();
|
|
1736
1783
|
entry.bytes = text.length;
|
|
1737
1784
|
let data;
|
|
1738
1785
|
try { data = JSON.parse(text); } catch { data = { _raw: text }; }
|
|
@@ -1766,6 +1813,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
1766
1813
|
entry.state = 'ok';
|
|
1767
1814
|
return data.rows;
|
|
1768
1815
|
} catch (err) {
|
|
1816
|
+
// Before anything is counted: an aborted fetch is no network error, and a replaced load no failure.
|
|
1817
|
+
if (replaced()) return _superseded();
|
|
1769
1818
|
// The failed-response throw lands here too — already built.
|
|
1770
1819
|
if (err && err.dkCall) throw err;
|
|
1771
1820
|
entry.clientMs = Math.round(performance.now() - t0);
|
|
@@ -3029,6 +3078,15 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
3029
3078
|
'<tr><td>Client duration</td><td>' + totMs + ' ms</td></tr>' +
|
|
3030
3079
|
'<tr><td>Bytes received</td><td>' + fmtInt(totB) + '</td></tr>' +
|
|
3031
3080
|
'</table></div>' +
|
|
3081
|
+
(_pageErrors.length
|
|
3082
|
+
? '<div><h3>Page errors</h3>' + _pageErrors.map(function (p) {
|
|
3083
|
+
return '<details class="dk-call"><summary>' +
|
|
3084
|
+
'<span class="dk-s-err">' + (p.kind === 'rejection' ? 'REJECTED' : 'ERROR') + '</span>' +
|
|
3085
|
+
'<span style="flex:1">' + esc(p.message) + '</span>' +
|
|
3086
|
+
'<span style="color:var(--muted);font-size:10px">' + p.ts.slice(11, 19) + '</span>' +
|
|
3087
|
+
'</summary><div class="dk-call-body"><pre>' + esc(p.stack || p.message) + '</pre></div></details>';
|
|
3088
|
+
}).join('') + '</div>'
|
|
3089
|
+
: '') +
|
|
3032
3090
|
'<div><h3>Calls <button id="dk-sysinfo-export" style="margin-left:8px;background:transparent;color:var(--brand);border:1px solid var(--brand);border-radius:3px;padding:0 8px;height:22px;font-size:11px;cursor:pointer">Export JSON ↓</button></h3>' +
|
|
3033
3091
|
callsHtml + '</div>' +
|
|
3034
3092
|
'</div>';
|
|
@@ -3052,6 +3110,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
3052
3110
|
return Object.assign({}, c, { requestHeaders: { 'Content-Type': 'application/json', Authorization: 'Bearer ***' } });
|
|
3053
3111
|
}),
|
|
3054
3112
|
};
|
|
3113
|
+
if (_pageErrors.length) payload.pageErrors = _pageErrors;
|
|
3055
3114
|
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });
|
|
3056
3115
|
const a = document.createElement('a');
|
|
3057
3116
|
a.href = URL.createObjectURL(blob);
|
|
@@ -3189,6 +3248,24 @@ html[data-dk-setup="true"] .dk-resp-toggle {
|
|
|
3189
3248
|
return div;
|
|
3190
3249
|
}
|
|
3191
3250
|
|
|
3251
|
+
// ── Errors no load() caught ── a section's load() failing shows in its panel; a click or change
|
|
3252
|
+
// handler, a timer or the page's own script failing showed nowhere but the browser console, so a
|
|
3253
|
+
// dead control looked like a working one in System Info. Recorded only: the page and the browser's
|
|
3254
|
+
// own reporting are left as they are. Capped, so a handler failing on every mousemove stays cheap.
|
|
3255
|
+
const PAGE_ERRORS_MAX = 50;
|
|
3256
|
+
function _pageError(kind, err, fallback) {
|
|
3257
|
+
if (_pageErrors.length >= PAGE_ERRORS_MAX) return;
|
|
3258
|
+
_pageErrors.push({
|
|
3259
|
+
ts: new Date().toISOString(),
|
|
3260
|
+
kind: kind,
|
|
3261
|
+
message: String((err && err.message) || fallback || err),
|
|
3262
|
+
stack: err && err.stack ? String(err.stack).slice(0, 2000) : null,
|
|
3263
|
+
});
|
|
3264
|
+
_renderSystemInfo();
|
|
3265
|
+
}
|
|
3266
|
+
global.addEventListener('error', function (e) { _pageError('error', e.error, e.message); });
|
|
3267
|
+
global.addEventListener('unhandledrejection', function (e) { _pageError('rejection', e.reason); });
|
|
3268
|
+
|
|
3192
3269
|
// ── Number-input guard ── a focused type=number takes the wheel. { passive: false }
|
|
3193
3270
|
// is required for preventDefault; v4.css hides the spinners.
|
|
3194
3271
|
document.addEventListener(
|