@datalabz_/dashboard-kit 6.0.5 → 6.0.7
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/README.md +36 -0
- package/package.json +1 -1
- package/v4.js +1 -1
- package/v5.js +1 -1
- package/v6.js +742 -17
- package/wrapper.css +47 -0
- package/wrapper.js +58 -2
package/README.md
CHANGED
|
@@ -103,6 +103,42 @@ The list follows the fill, so it holds only what a filter can actually be given:
|
|
|
103
103
|
|
|
104
104
|
The answer always goes to the dashboard's parent, whoever asked.
|
|
105
105
|
|
|
106
|
+
## Drillthrough
|
|
107
|
+
|
|
108
|
+
A click on a table column or a card opens another dashboard in a popup over this one, filtered to the
|
|
109
|
+
clicked value. The user sets it up in the host (spec: [../docs/drillthrough-setup.md](../docs/drillthrough-setup.md));
|
|
110
|
+
the kit shows the points, reports them, and does the opening.
|
|
111
|
+
|
|
112
|
+
The host sends, in `CUSTOM_DASHBOARDS_PARAMS` (and `{ type: 'DK_DRILL_POINTS', drillPoints }` to change the
|
|
113
|
+
setup without the reload that message causes), only from the parent frame:
|
|
114
|
+
|
|
115
|
+
| Field | Meaning |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| `dashboardsApi` | where the dashboards live; https, or http for localhost. Without it the cells stay plain text. |
|
|
118
|
+
| `dashboardsPermissionKey` | sent as `x-permission-key` |
|
|
119
|
+
| `drillPoints` | `[{ point, dashboardId, pass }]`; `pass` maps a header filter id of B to `{ from: 'row', name }`, `{ from: 'filter', name }` or `{ from: 'value', value }` |
|
|
120
|
+
| `depth` | how deep this dashboard is opened; set by the kit for the dashboard it opens. At 3 the cells stay plain text. |
|
|
121
|
+
|
|
122
|
+
A point is a column (`renderTable`) or a card (`renderKpiCard`, `renderKpiStrip`, `renderInfoGrid`,
|
|
123
|
+
`renderTotalsStrip`), keyed by the container's `id` and the column `key` or the card label, each URI-encoded
|
|
124
|
+
and joined by `|`. A container with no `id`, a column key used twice in one table and a label used twice in
|
|
125
|
+
one strip are not points that can be set up.
|
|
126
|
+
|
|
127
|
+
| Message | From → to | Carries |
|
|
128
|
+
| --- | --- | --- |
|
|
129
|
+
| `DK_POINTS` | kit → parent | `{ points: [{ point, section, title?, configurable }] }`, sent when the list changes |
|
|
130
|
+
| `DK_SETUP_MODE` | parent → kit | `{ on }`: a button on every point that can be set up; no hover highlight and no pointer cursor except on those buttons and the tabs, and the page behind faintly blurred and dimmed (the set-up buttons and the tabs stay sharp) |
|
|
131
|
+
| `DK_CLOSE_REQUEST` | opened dashboard → parent | Esc pressed inside it with no popup of its own; the parent closes the popup only if the message came from that popup's frame |
|
|
132
|
+
| `DK_POINT_SETUP` | kit → parent | a click on such a button: `{ point, section, title?, row?, columns?, localFilters }` |
|
|
133
|
+
|
|
134
|
+
On a click the kit builds B's filters from the clicked row, the header filters and the period as the section
|
|
135
|
+
last loaded with, fetches B with the viewer's token, and opens it. A `pass` key may be a header filter of B
|
|
136
|
+
only: a context key (`dateFrom`, `dateTo`, `timezone`, `hierarchyId`) is refused. An open popup closes when the host changes the period, time zone or hierarchy; a theme change does not close it.
|
|
137
|
+
A table cell or card value that holds a link, a button, a control, an `onclick` or a tab stop is not made a
|
|
138
|
+
drillthrough link: it answers its own click. A column in which any cell does, and a card whose value does, get no
|
|
139
|
+
set-up button either (`configurable: false`). A row without the key a setup names, a filter the dashboard does not have, or a dashboard the viewer cannot open shows
|
|
140
|
+
its reason in the popup and opens nothing. A header filter that exists but is empty is simply not passed.
|
|
141
|
+
|
|
106
142
|
## Rules
|
|
107
143
|
|
|
108
144
|
- **Where a change lands — the current `vN` or a new major — is decided by
|
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 = '35ea6ab'; // replaced at deploy: sed -i "s/35ea6ab/$(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 = '35ea6ab'; // replaced at deploy: sed -i "s/35ea6ab/$(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,13 +20,20 @@
|
|
|
20
20
|
let _activeTabId = '';
|
|
21
21
|
let _sections = []; // { id, label, load, loaded, errors }
|
|
22
22
|
let _title = '';
|
|
23
|
-
let _gitVer = '
|
|
23
|
+
let _gitVer = '35ea6ab'; // replaced at deploy: sed -i "s/35ea6ab/$(git rev-parse --short HEAD)/g" v6.js
|
|
24
24
|
let _calls = []; // System Info call log
|
|
25
25
|
let _sectionErrors = {}; // sectionId → error count
|
|
26
26
|
let _generation = 0;
|
|
27
27
|
let _ttEl = null;
|
|
28
28
|
let _pendingFilters = {}; // header filters a parent sent before boot, applied at boot
|
|
29
29
|
let _filtersRefused = false;
|
|
30
|
+
let _pointsByContainer = {}; // container id → the drillthrough click points its render call drew
|
|
31
|
+
let _setupMode = false; // the parent asked for the set-up buttons
|
|
32
|
+
let _dashboardsApi = ''; // where the host's dashboards live; empty = no drillthrough here
|
|
33
|
+
let _dashboardsPermissionKey = ''; // sent as x-permission-key when the host names one
|
|
34
|
+
let _drillPoints = {}; // point key → { dashboardId, pass }
|
|
35
|
+
let _depth = 0; // how many dashboards deep this one is opened
|
|
36
|
+
let _popup = null; // the open drillthrough popup
|
|
30
37
|
|
|
31
38
|
// ── Inject CSS ───────────────────────────────────────────────────────────────
|
|
32
39
|
// The kit carries its own CSS: Claude artifacts may load scripts from jsDelivr but not
|
|
@@ -756,6 +763,185 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
756
763
|
color: var(--muted);
|
|
757
764
|
font-style: italic;
|
|
758
765
|
}
|
|
766
|
+
/* ── Drillthrough set-up buttons ────────────────────────────────────────────────── */
|
|
767
|
+
/* Blue while a point has no setup, green once it has one; both pulse softly so the eye finds them.
|
|
768
|
+
Blue reads as "you can click this" and does not shout the way the warning colour did. */
|
|
769
|
+
.dk-pt-btn {
|
|
770
|
+
flex: 0 0 auto;
|
|
771
|
+
display: inline-flex;
|
|
772
|
+
align-items: center;
|
|
773
|
+
justify-content: center;
|
|
774
|
+
width: 18px;
|
|
775
|
+
height: 18px;
|
|
776
|
+
margin-left: 8px;
|
|
777
|
+
padding: 0;
|
|
778
|
+
vertical-align: middle;
|
|
779
|
+
font: inherit;
|
|
780
|
+
font-size: 11px;
|
|
781
|
+
font-weight: 700;
|
|
782
|
+
line-height: 1;
|
|
783
|
+
color: #fff;
|
|
784
|
+
background: var(--info);
|
|
785
|
+
border: 0;
|
|
786
|
+
border-radius: 50%;
|
|
787
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
|
|
788
|
+
cursor: pointer;
|
|
789
|
+
animation: dk-pt-pulse 2.4s ease-out infinite;
|
|
790
|
+
transition: transform 0.12s ease;
|
|
791
|
+
}
|
|
792
|
+
.dk-pt-btn:hover {
|
|
793
|
+
transform: scale(1.12);
|
|
794
|
+
animation-play-state: paused;
|
|
795
|
+
}
|
|
796
|
+
.dk-pt-btn:focus-visible {
|
|
797
|
+
outline: 2px solid var(--text);
|
|
798
|
+
outline-offset: 2px;
|
|
799
|
+
}
|
|
800
|
+
.dk-pt-btn.dk-pt-on {
|
|
801
|
+
background: var(--ok);
|
|
802
|
+
animation-name: dk-pt-pulse-on;
|
|
803
|
+
}
|
|
804
|
+
@keyframes dk-pt-pulse {
|
|
805
|
+
0% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(52, 152, 219, 0.5); }
|
|
806
|
+
70% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 0 0 7px rgba(52, 152, 219, 0); }
|
|
807
|
+
100% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(52, 152, 219, 0); }
|
|
808
|
+
}
|
|
809
|
+
@keyframes dk-pt-pulse-on {
|
|
810
|
+
0% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(46, 160, 67, 0.5); }
|
|
811
|
+
70% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 0 0 7px rgba(46, 160, 67, 0); }
|
|
812
|
+
100% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(46, 160, 67, 0); }
|
|
813
|
+
}
|
|
814
|
+
@media (prefers-reduced-motion: reduce) {
|
|
815
|
+
.dk-pt-btn { animation: none; }
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/* Setup mode: the page behind is faintly blurred and dimmed by a layer over the window, which lets clicks
|
|
819
|
+
through. The set-up buttons are lifted above it and stay sharp, and so do the tabs (the other sections
|
|
820
|
+
have points to set up too) and the headers of the columns that have one: a sticky header is a stacking
|
|
821
|
+
context of its own, so its button can only rise with it. Everything else, cards included, is blurred
|
|
822
|
+
like the cells of a table. The popup (1000) and the tooltip (9999) stay above. */
|
|
823
|
+
html[data-dk-setup="true"]::after {
|
|
824
|
+
content: "";
|
|
825
|
+
position: fixed;
|
|
826
|
+
inset: 0;
|
|
827
|
+
z-index: 900;
|
|
828
|
+
pointer-events: none;
|
|
829
|
+
-webkit-backdrop-filter: blur(0.5px);
|
|
830
|
+
backdrop-filter: blur(0.5px);
|
|
831
|
+
background: color-mix(in srgb, var(--bg) 35%, transparent);
|
|
832
|
+
}
|
|
833
|
+
html[data-dk-setup="true"] .dk-pt-btn {
|
|
834
|
+
position: relative;
|
|
835
|
+
z-index: 901;
|
|
836
|
+
}
|
|
837
|
+
html[data-dk-setup="true"] th:has(.dk-pt-btn) {
|
|
838
|
+
z-index: 901;
|
|
839
|
+
}
|
|
840
|
+
html[data-dk-setup="true"] nav.dk-tabs {
|
|
841
|
+
z-index: 901;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/* ── Setup mode: the page stops answering the mouse ──────────────────────────── */
|
|
845
|
+
/* No hover highlight and no pointer cursor, except on the set-up buttons and the tabs: what the user can act on
|
|
846
|
+
is then what still reacts. Clicks still work; only the cues are taken away. */
|
|
847
|
+
html[data-dk-setup="true"] table.dk-table tbody tr:nth-child(even):hover td {
|
|
848
|
+
background: var(--row_even);
|
|
849
|
+
}
|
|
850
|
+
html[data-dk-setup="true"] table.dk-table tbody tr:nth-child(odd):hover td {
|
|
851
|
+
background: var(--row_odd);
|
|
852
|
+
}
|
|
853
|
+
html[data-dk-setup="true"] table.dk-table tbody tr.dk-totals-row:hover td {
|
|
854
|
+
background: color-mix(in srgb, var(--brand) 25%, var(--surface));
|
|
855
|
+
}
|
|
856
|
+
html[data-dk-setup="true"] table.dk-table thead th[data-dk-sort-key]:hover {
|
|
857
|
+
color: var(--muted);
|
|
858
|
+
background: var(--raised);
|
|
859
|
+
}
|
|
860
|
+
html[data-dk-setup="true"] .dk-csv-btn:hover {
|
|
861
|
+
color: var(--muted);
|
|
862
|
+
border-color: var(--border);
|
|
863
|
+
}
|
|
864
|
+
html[data-dk-setup="true"] header button:hover:not(:disabled),
|
|
865
|
+
html[data-dk-setup="true"] .dk-error-report-btn:hover:not(:disabled) {
|
|
866
|
+
background: var(--brand);
|
|
867
|
+
}
|
|
868
|
+
html[data-dk-setup="true"] table.dk-table thead th[data-dk-sort-key],
|
|
869
|
+
html[data-dk-setup="true"] .dk-csv-btn,
|
|
870
|
+
html[data-dk-setup="true"] header button,
|
|
871
|
+
html[data-dk-setup="true"] .dk-error-report-btn,
|
|
872
|
+
html[data-dk-setup="true"] details.dk-call summary,
|
|
873
|
+
html[data-dk-setup="true"] .dk-resp-toggle {
|
|
874
|
+
cursor: default;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/* ── Drillthrough: a set-up cell or card, and the popup that opens B ────────────── */
|
|
878
|
+
.dk-od-cell,
|
|
879
|
+
.dk-od-value {
|
|
880
|
+
cursor: pointer;
|
|
881
|
+
text-decoration: underline;
|
|
882
|
+
}
|
|
883
|
+
/* A card value that has its own colour (a colorClass such as pos / neg) keeps it and only gets the underline. */
|
|
884
|
+
.dk-od-cell,
|
|
885
|
+
.dk-od-value:not(.dk-od-keep) {
|
|
886
|
+
color: var(--brand);
|
|
887
|
+
}
|
|
888
|
+
.dk-od {
|
|
889
|
+
position: fixed;
|
|
890
|
+
inset: 0;
|
|
891
|
+
z-index: 1000;
|
|
892
|
+
display: flex;
|
|
893
|
+
align-items: center;
|
|
894
|
+
justify-content: center;
|
|
895
|
+
padding: 8px;
|
|
896
|
+
background: rgba(10, 14, 20, 0.6);
|
|
897
|
+
}
|
|
898
|
+
.dk-od-box {
|
|
899
|
+
display: flex;
|
|
900
|
+
flex-direction: column;
|
|
901
|
+
width: 100%;
|
|
902
|
+
height: 100%;
|
|
903
|
+
background: var(--bg);
|
|
904
|
+
color: var(--text);
|
|
905
|
+
border: 1px solid var(--border);
|
|
906
|
+
border-radius: 10px;
|
|
907
|
+
overflow: hidden;
|
|
908
|
+
}
|
|
909
|
+
.dk-od-head {
|
|
910
|
+
display: flex;
|
|
911
|
+
align-items: center;
|
|
912
|
+
justify-content: space-between;
|
|
913
|
+
gap: 12px;
|
|
914
|
+
padding: 12px 16px;
|
|
915
|
+
background: var(--surface);
|
|
916
|
+
border-bottom: 1px solid var(--border);
|
|
917
|
+
}
|
|
918
|
+
.dk-od-title {
|
|
919
|
+
font-weight: 600;
|
|
920
|
+
font-size: 16px;
|
|
921
|
+
}
|
|
922
|
+
.dk-od-close {
|
|
923
|
+
padding: 4px 12px;
|
|
924
|
+
background: transparent;
|
|
925
|
+
color: var(--text);
|
|
926
|
+
border: 1px solid var(--border);
|
|
927
|
+
border-radius: 4px;
|
|
928
|
+
cursor: pointer;
|
|
929
|
+
}
|
|
930
|
+
.dk-od-body {
|
|
931
|
+
flex: 1;
|
|
932
|
+
min-height: 0;
|
|
933
|
+
position: relative;
|
|
934
|
+
}
|
|
935
|
+
.dk-od-body iframe {
|
|
936
|
+
position: absolute;
|
|
937
|
+
inset: 0;
|
|
938
|
+
width: 100%;
|
|
939
|
+
height: 100%;
|
|
940
|
+
border: 0;
|
|
941
|
+
}
|
|
942
|
+
.dk-od-body .dk-error {
|
|
943
|
+
margin: 16px;
|
|
944
|
+
}
|
|
759
945
|
/*# sourceURL=dashboard-kit-v6.css */`;
|
|
760
946
|
if (!document.getElementById('dk-kit-css')) {
|
|
761
947
|
const style = document.createElement('style');
|
|
@@ -1066,6 +1252,19 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1066
1252
|
window.parent.postMessage(reply, '*');
|
|
1067
1253
|
return;
|
|
1068
1254
|
}
|
|
1255
|
+
if (e.data.type === 'DK_CLOSE_REQUEST') {
|
|
1256
|
+
if (_popup && _popup.frame && e.source === _popup.frame.contentWindow) _closePopup();
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
if (e.data.type === 'DK_SETUP_MODE') {
|
|
1260
|
+
if (e.source === window.parent) _setSetupMode(e.data.on === true);
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
// A new setup without a reload: CUSTOM_DASHBOARDS_PARAMS reloads every section.
|
|
1264
|
+
if (e.data.type === 'DK_DRILL_POINTS') {
|
|
1265
|
+
if (e.source === window.parent) _setDrillPoints(e.data.drillPoints);
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1069
1268
|
if (e.data.type === 'RK_SNAPSHOT') { _snapshot(); return; }
|
|
1070
1269
|
if (e.data.type === 'CHAT_MODE') { document.documentElement.dataset.chatMode = 'true'; return; }
|
|
1071
1270
|
if (e.data.type !== 'CUSTOM_DASHBOARDS_PARAMS') return;
|
|
@@ -1084,6 +1283,19 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1084
1283
|
if (e.data.theme === 'light' || e.data.theme === 'dark')
|
|
1085
1284
|
document.documentElement.dataset.theme = e.data.theme;
|
|
1086
1285
|
|
|
1286
|
+
// Drillthrough: where the dashboards live, the permission key, how deep this one is, the setup.
|
|
1287
|
+
// Only the parent may name them: the token rides on every call to the address.
|
|
1288
|
+
if (e.source === window.parent) {
|
|
1289
|
+
if (e.data.dashboardsApi !== undefined) {
|
|
1290
|
+
if (_isGatewayUrl(e.data.dashboardsApi)) _dashboardsApi = e.data.dashboardsApi.replace(/\/+$/, '');
|
|
1291
|
+
else console.warn('[DashboardKit] dashboardsApi ignored:', e.data.dashboardsApi);
|
|
1292
|
+
}
|
|
1293
|
+
if (typeof e.data.dashboardsPermissionKey === 'string') _dashboardsPermissionKey = e.data.dashboardsPermissionKey;
|
|
1294
|
+
if (Number.isInteger(e.data.depth) && e.data.depth >= 0) _depth = e.data.depth;
|
|
1295
|
+
if (e.data.drillPoints !== undefined) _setDrillPoints(e.data.drillPoints);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
const contextBefore = JSON.stringify(_contextSnapshot());
|
|
1087
1299
|
const f = e.data.filters;
|
|
1088
1300
|
if (f && typeof f === 'object') {
|
|
1089
1301
|
if (typeof f.dateFrom === 'string') _dateFromIso = f.dateFrom;
|
|
@@ -1097,6 +1309,11 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1097
1309
|
});
|
|
1098
1310
|
}
|
|
1099
1311
|
|
|
1312
|
+
// An open popup was opened with the context this dashboard had: its period, time zone and hierarchy.
|
|
1313
|
+
// When the host moves any of them the popup is showing another period than the page under it, so
|
|
1314
|
+
// it closes. A theme or token change does not move what it shows.
|
|
1315
|
+
if (_popup && JSON.stringify(_contextSnapshot()) !== contextBefore) _closePopup();
|
|
1316
|
+
|
|
1100
1317
|
if (!_hasBooted && _authToken && _dateFromIso && _dateToIso && _timezone) {
|
|
1101
1318
|
// Before the fill locks anything and before a section runs. A fault in describing the filters
|
|
1102
1319
|
// must never keep the dashboard from booting, so it only costs the list.
|
|
@@ -1105,6 +1322,7 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1105
1322
|
const refusal = _fillHeaderFilters(_pendingFilters);
|
|
1106
1323
|
if (refusal) { _refuseFilters(refusal); return; }
|
|
1107
1324
|
_hasBooted = true;
|
|
1325
|
+
_schedulePoints();
|
|
1108
1326
|
const wait = document.getElementById('dk-wait');
|
|
1109
1327
|
if (wait) wait.hidden = true;
|
|
1110
1328
|
_buildTabNav();
|
|
@@ -1316,6 +1534,9 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1316
1534
|
_sectionErrors[sec.id] = 0;
|
|
1317
1535
|
setSectionState(panel, 'loading');
|
|
1318
1536
|
_setPill('loading', 'loading…');
|
|
1537
|
+
// What a click point drawn by this load reports: this section, and the header filters and the
|
|
1538
|
+
// context as the load started, not edits made since.
|
|
1539
|
+
const ctx = { id: sec.id, localFilters: _headerSnapshot(), context: _contextSnapshot() };
|
|
1319
1540
|
try {
|
|
1320
1541
|
await sec.load({
|
|
1321
1542
|
runQuery,
|
|
@@ -1324,11 +1545,11 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1324
1545
|
formatInteger: fmtInt,
|
|
1325
1546
|
formatDate: fmtDate,
|
|
1326
1547
|
formatDatetime: fmtDatetime,
|
|
1327
|
-
renderTable,
|
|
1328
|
-
renderKpiCard,
|
|
1329
|
-
renderKpiStrip,
|
|
1330
|
-
renderInfoGrid,
|
|
1331
|
-
renderTotalsStrip,
|
|
1548
|
+
renderTable: function (c, r, o) { return renderTable(c, r, o, ctx); },
|
|
1549
|
+
renderKpiCard: function (c, i) { return renderKpiCard(c, i, ctx); },
|
|
1550
|
+
renderKpiStrip: function (c, i, o) { return renderKpiStrip(c, i, o, ctx); },
|
|
1551
|
+
renderInfoGrid: function (c, i, o) { return renderInfoGrid(c, i, o, ctx); },
|
|
1552
|
+
renderTotalsStrip: function (c, i, o) { return renderTotalsStrip(c, i, o, ctx); },
|
|
1332
1553
|
escHtml: esc,
|
|
1333
1554
|
colorClass,
|
|
1334
1555
|
filters: DashboardKit.filters,
|
|
@@ -1562,6 +1783,7 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1562
1783
|
if (state === 'loading') {
|
|
1563
1784
|
container.innerHTML =
|
|
1564
1785
|
'<div class="dk-loading"><span class="dk-spinner"></span>Loading…</div>';
|
|
1786
|
+
_schedulePoints();
|
|
1565
1787
|
} else if (state === 'error') {
|
|
1566
1788
|
// A caller can be the section panel itself or, from a dashboard's own
|
|
1567
1789
|
// load(), an arbitrary sub-container inside it — either way the nearest
|
|
@@ -1573,10 +1795,14 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1573
1795
|
const sec = _sections.find(function (s) { return s.id === sectionId; });
|
|
1574
1796
|
// failedCall is err.dkCall from runQuery; without one the rejection didn't
|
|
1575
1797
|
// come from a gateway call at all — that's kind 'script'. The operator gets
|
|
1576
|
-
// a fixed phrase
|
|
1577
|
-
// System Info. No panel Retry: the
|
|
1798
|
+
// a fixed phrase, with the wait when no response arrived; the raw text goes to
|
|
1799
|
+
// the parent via "Ask AI to fix" and to System Info. No panel Retry: the
|
|
1800
|
+
// header's Refresh covers it.
|
|
1801
|
+
const cause = failedCall && failedCall.kind === 'transport'
|
|
1802
|
+
? ': Network error after ' + (failedCall.clientMs / 1000).toFixed(2) + 's.'
|
|
1803
|
+
: '';
|
|
1578
1804
|
container.innerHTML =
|
|
1579
|
-
'<div class="dk-error"><span>This view couldn\'t load</span>' +
|
|
1805
|
+
'<div class="dk-error"><span>This view couldn\'t load' + cause + '</span>' +
|
|
1580
1806
|
'<button class="dk-error-report-btn" type="button">Ask AI to fix</button></div>';
|
|
1581
1807
|
|
|
1582
1808
|
const reportBtn = container.querySelector('.dk-error-report-btn');
|
|
@@ -1626,13 +1852,467 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1626
1852
|
return title ? '<div class="dk-toolbar"><span class="dk-table-title">' + esc(title) + '</span></div>' : '';
|
|
1627
1853
|
}
|
|
1628
1854
|
|
|
1855
|
+
// ── Drillthrough click points ────────────────────────────────────────────────────
|
|
1856
|
+
// A table column or a card a user can set a drillthrough on (docs/drillthrough-setup.md). Each render
|
|
1857
|
+
// call registers what it drew under its container's id, and the key is read from the call itself:
|
|
1858
|
+
// container id + column key, or container id + card label, each part encoded so that no id or key
|
|
1859
|
+
// can run into the other. A container without an id names nothing, so it registers nothing and gets
|
|
1860
|
+
// no button. A column key used twice in one table, or a label twice in one strip, names none of
|
|
1861
|
+
// them: a setup on one would silently apply to the other.
|
|
1862
|
+
// ctx is the section whose load() made the call: its id, and the header filters and the context
|
|
1863
|
+
// (period, time zone, hierarchy) as that load started.
|
|
1864
|
+
function _contextSnapshot() {
|
|
1865
|
+
return { dateFrom: _dateFromIso, dateTo: _dateToIso, timezone: _timezone, hierarchyId: _hierarchyId };
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
function _headerSnapshot() {
|
|
1869
|
+
try {
|
|
1870
|
+
// defaultValue is the control's value at the moment of the call.
|
|
1871
|
+
return _dashboardFilters().map(function (f) {
|
|
1872
|
+
return { id: f.id, label: f.label, value: f.defaultValue };
|
|
1873
|
+
});
|
|
1874
|
+
} catch (err) {
|
|
1875
|
+
console.error('[DashboardKit] could not read the header filters:', err);
|
|
1876
|
+
return [];
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
function _forgetPoints(container) {
|
|
1881
|
+
if (container.id) delete _pointsByContainer[container.id];
|
|
1882
|
+
_schedulePoints();
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
// The host learns which points exist, and that this kit can set them up, from DK_POINTS: after the
|
|
1886
|
+
// renders of a moment have settled, and again whenever the list changes. A point it holds a setup
|
|
1887
|
+
// for that is not listed is not on screen.
|
|
1888
|
+
let _pointsSent = null;
|
|
1889
|
+
let _pointsQueued = false;
|
|
1890
|
+
|
|
1891
|
+
function _postPoints() {
|
|
1892
|
+
const list = [];
|
|
1893
|
+
Object.keys(_pointsByContainer).forEach(function (id) {
|
|
1894
|
+
// A section that draws again replaces its content, and the containers it held go with it.
|
|
1895
|
+
if (!_pointsByContainer[id].el.isConnected) {
|
|
1896
|
+
delete _pointsByContainer[id];
|
|
1897
|
+
return;
|
|
1898
|
+
}
|
|
1899
|
+
_pointsByContainer[id].points.forEach(function (p) {
|
|
1900
|
+
const item = { point: p.key, section: p.section, configurable: p.configurable };
|
|
1901
|
+
if (p.title) item.title = p.title;
|
|
1902
|
+
list.push(item);
|
|
1903
|
+
});
|
|
1904
|
+
});
|
|
1905
|
+
const json = JSON.stringify(list);
|
|
1906
|
+
if (json === _pointsSent) return;
|
|
1907
|
+
_pointsSent = json;
|
|
1908
|
+
window.parent.postMessage({ type: 'DK_POINTS', points: list }, '*');
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
function _schedulePoints() {
|
|
1912
|
+
if (_pointsQueued) return;
|
|
1913
|
+
_pointsQueued = true;
|
|
1914
|
+
Promise.resolve().then(function () {
|
|
1915
|
+
_pointsQueued = false;
|
|
1916
|
+
_postPoints();
|
|
1917
|
+
});
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
// spec: { kind: 'column'|'card', names: [..one per element..], title?, columns?, row?, rowAt?, valueSelector? }
|
|
1921
|
+
// valueSelector (cards): the part of an element that is the value, the only part that is a link.
|
|
1922
|
+
// selector finds, inside the container, the elements the names belong to, in the same order.
|
|
1923
|
+
// rowAt(i) is the row a table shows at position i now, sorted or not.
|
|
1924
|
+
// A fault here must never cost a dashboard its table or its cards, so it only costs their points.
|
|
1925
|
+
function _registerPoints(container, selector, ctx, spec) {
|
|
1926
|
+
try {
|
|
1927
|
+
_registerPointsUnsafe(container, selector, ctx, spec);
|
|
1928
|
+
} catch (err) {
|
|
1929
|
+
console.error('[DashboardKit] could not register drillthrough points:', err);
|
|
1930
|
+
if (container.id) delete _pointsByContainer[container.id];
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
function _registerPointsUnsafe(container, selector, ctx, spec) {
|
|
1935
|
+
if (!container.id) return;
|
|
1936
|
+
const count = {};
|
|
1937
|
+
spec.names.forEach(function (n) { count[n] = (count[n] || 0) + 1; });
|
|
1938
|
+
const localFilters = ctx ? ctx.localFilters : _headerSnapshot();
|
|
1939
|
+
const context = ctx ? ctx.context : _contextSnapshot();
|
|
1940
|
+
// The container outlives its content, so one listener serves every render into it.
|
|
1941
|
+
if (!container.dataset.dkPoints) {
|
|
1942
|
+
container.dataset.dkPoints = '1';
|
|
1943
|
+
container.addEventListener('click', function (e) { _onPointClick(container, e); });
|
|
1944
|
+
}
|
|
1945
|
+
const ownCols = spec.kind === 'column' ? _ownClickColumns(container) : null;
|
|
1946
|
+
_pointsByContainer[container.id] = {
|
|
1947
|
+
el: container,
|
|
1948
|
+
kind: spec.kind,
|
|
1949
|
+
valueSelector: spec.valueSelector,
|
|
1950
|
+
rowAt: spec.rowAt,
|
|
1951
|
+
selector: selector,
|
|
1952
|
+
points: spec.names.map(function (name, i) {
|
|
1953
|
+
const unique = count[name] === 1;
|
|
1954
|
+
const ownClick = ownCols ? ownCols.has(i) : _cardHoldsOwnClick(container, selector, spec, i);
|
|
1955
|
+
const p = {
|
|
1956
|
+
key: encodeURIComponent(container.id) + '|' + encodeURIComponent(name),
|
|
1957
|
+
index: i,
|
|
1958
|
+
// unique: no other column or label of the container has this key, so a setup on it is about it alone.
|
|
1959
|
+
// configurable: it can be set up. Not when one of its cells or its value answers its own click: there
|
|
1960
|
+
// the kit would only be a second action on the same click, so it offers no button.
|
|
1961
|
+
unique: unique,
|
|
1962
|
+
ownClick: ownClick,
|
|
1963
|
+
configurable: unique && !ownClick,
|
|
1964
|
+
section: ctx ? ctx.id : '',
|
|
1965
|
+
localFilters: localFilters,
|
|
1966
|
+
context: context,
|
|
1967
|
+
};
|
|
1968
|
+
if (spec.title) p.title = spec.title;
|
|
1969
|
+
if (spec.columns) p.columns = spec.columns;
|
|
1970
|
+
if (spec.row) p.row = spec.row;
|
|
1971
|
+
return p;
|
|
1972
|
+
}),
|
|
1973
|
+
};
|
|
1974
|
+
_decoratePoints(container);
|
|
1975
|
+
_schedulePoints();
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
// The table cells that hold something answering a click by itself, in one pass over the container: a
|
|
1979
|
+
// table can have ten thousand rows, and asking every cell of every column was most of a render's time.
|
|
1980
|
+
function _ownClickCells(container) {
|
|
1981
|
+
const cells = new Set();
|
|
1982
|
+
container.querySelectorAll(OWN_CLICK).forEach(function (el) {
|
|
1983
|
+
const td = el.closest('td');
|
|
1984
|
+
if (td) cells.add(td);
|
|
1985
|
+
});
|
|
1986
|
+
return cells;
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
function _ownClickColumns(container) {
|
|
1990
|
+
const cols = new Set();
|
|
1991
|
+
_ownClickCells(container).forEach(function (td) { cols.add(td.cellIndex); });
|
|
1992
|
+
return cols;
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
// Whether the value of card i holds an element that answers a click by itself.
|
|
1996
|
+
function _cardHoldsOwnClick(container, selector, spec, i) {
|
|
1997
|
+
const el = container.querySelectorAll(selector)[i];
|
|
1998
|
+
const value = el && el.querySelector(spec.valueSelector);
|
|
1999
|
+
return !!value && _hasOwnClick(value);
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
function _pointSetup(p) {
|
|
2003
|
+
const msg = { type: 'DK_POINT_SETUP', point: p.key, section: p.section, localFilters: p.localFilters };
|
|
2004
|
+
['title', 'row', 'columns'].forEach(function (k) { if (p[k] !== undefined) msg[k] = p[k]; });
|
|
2005
|
+
try {
|
|
2006
|
+
window.parent.postMessage(msg, '*');
|
|
2007
|
+
} catch (err) {
|
|
2008
|
+
// The sample row held something postMessage cannot copy: send what JSON keeps of it, or none.
|
|
2009
|
+
if (msg.row !== undefined) {
|
|
2010
|
+
try { msg.row = JSON.parse(JSON.stringify(msg.row)); } catch { delete msg.row; }
|
|
2011
|
+
}
|
|
2012
|
+
window.parent.postMessage(msg, '*');
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
// What answers a click by itself: a link, a button, a control, anything with an onclick or a tab stop.
|
|
2017
|
+
// A cell or a card value that holds one is that element's: it is never made a drillthrough link, so two
|
|
2018
|
+
// actions never meet on one click. The kit cannot see a listener a dashboard adds with addEventListener
|
|
2019
|
+
// to a plain element, only these markers.
|
|
2020
|
+
const OWN_CLICK = 'a, button, input, select, textarea, label, summary, [role="button"], [onclick], [tabindex]:not([tabindex="-1"])';
|
|
2021
|
+
|
|
2022
|
+
function _hasOwnClick(el) {
|
|
2023
|
+
return el.matches(OWN_CLICK) || !!el.querySelector(OWN_CLICK);
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
function _drillActive() {
|
|
2027
|
+
return !!_dashboardsApi && _depth < MAX_DEPTH;
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
// In setup mode every configurable point carries a button (filled when it already has a setup);
|
|
2031
|
+
// otherwise the points that have one look like links. The buttons live inside the elements the
|
|
2032
|
+
// render call drew; a table sorting rebuilds only its tbody, so the header ones stay, but its
|
|
2033
|
+
// cells are new and are marked again. A click on a button must not reach the header's sort handler.
|
|
2034
|
+
function _decoratePoints(container) {
|
|
2035
|
+
container.querySelectorAll('.dk-pt-btn').forEach(function (b) { b.remove(); });
|
|
2036
|
+
container.querySelectorAll('.dk-od-cell, .dk-od-value').forEach(function (n) {
|
|
2037
|
+
n.classList.remove('dk-od-cell', 'dk-od-value', 'dk-od-keep');
|
|
2038
|
+
});
|
|
2039
|
+
const reg = container.id && _pointsByContainer[container.id];
|
|
2040
|
+
if (!reg) return;
|
|
2041
|
+
const els = container.querySelectorAll(reg.selector);
|
|
2042
|
+
let rowEls = null; // the body rows and the cells with a click of their own, looked up once, and only if a column is linked
|
|
2043
|
+
let ownCells = null;
|
|
2044
|
+
reg.points.forEach(function (p) {
|
|
2045
|
+
const has = !!_drillPoints[p.key];
|
|
2046
|
+
if (_setupMode) {
|
|
2047
|
+
const el = els[p.index];
|
|
2048
|
+
if (!p.configurable) return;
|
|
2049
|
+
if (!el) return;
|
|
2050
|
+
const btn = document.createElement('button');
|
|
2051
|
+
btn.type = 'button';
|
|
2052
|
+
btn.className = 'dk-pt-btn' + (has ? ' dk-pt-on' : '');
|
|
2053
|
+
btn.innerHTML = LINK_ICON;
|
|
2054
|
+
btn.title = 'Set up a drillthrough';
|
|
2055
|
+
btn.setAttribute('aria-label', 'Set up a drillthrough');
|
|
2056
|
+
btn.addEventListener('click', function (e) {
|
|
2057
|
+
e.preventDefault();
|
|
2058
|
+
e.stopPropagation();
|
|
2059
|
+
_pointSetup(p);
|
|
2060
|
+
});
|
|
2061
|
+
// A column holds its button beside the header label; a card beside its value, the part that becomes the link.
|
|
2062
|
+
const host = reg.kind === 'column'
|
|
2063
|
+
? el.querySelector('.dk-th-inner') || el
|
|
2064
|
+
: el.querySelector(reg.valueSelector) || el;
|
|
2065
|
+
// An info row's sub line sits inside its value: the button goes before it, on the value's line.
|
|
2066
|
+
host.insertBefore(btn, host.querySelector(':scope > .dk-sub'));
|
|
2067
|
+
} else if (has && p.unique && _drillActive()) {
|
|
2068
|
+
if (reg.kind === 'column') {
|
|
2069
|
+
if (!rowEls) {
|
|
2070
|
+
rowEls = container.querySelectorAll('tbody tr[data-dk-row]');
|
|
2071
|
+
ownCells = _ownClickCells(container);
|
|
2072
|
+
}
|
|
2073
|
+
rowEls.forEach(function (tr) {
|
|
2074
|
+
const td = tr.children[p.index];
|
|
2075
|
+
if (td && !ownCells.has(td)) td.classList.add('dk-od-cell');
|
|
2076
|
+
});
|
|
2077
|
+
} else {
|
|
2078
|
+
const value = els[p.index] && els[p.index].querySelector(reg.valueSelector);
|
|
2079
|
+
if (value && !_hasOwnClick(value)) {
|
|
2080
|
+
// More than its own class means a colorClass: keep that colour.
|
|
2081
|
+
const keepsColour = value.classList.length > 1;
|
|
2082
|
+
value.classList.add('dk-od-value');
|
|
2083
|
+
if (keepsColour) value.classList.add('dk-od-keep');
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
// The link icon (Lucide "link", ISC): it follows the button's colour and needs no font, unlike a glyph.
|
|
2091
|
+
const LINK_ICON = '<svg viewBox="0 0 24 24" width="10" height="10" fill="none" stroke="currentColor" stroke-width="2.6" ' +
|
|
2092
|
+
'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/>' +
|
|
2093
|
+
'<path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>';
|
|
2094
|
+
|
|
2095
|
+
function _refreshPoints() {
|
|
2096
|
+
Object.keys(_pointsByContainer).forEach(function (id) {
|
|
2097
|
+
const el = document.getElementById(id);
|
|
2098
|
+
if (el) _decoratePoints(el);
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
function _setSetupMode(on) {
|
|
2103
|
+
_setupMode = on;
|
|
2104
|
+
document.documentElement.dataset.dkSetup = on ? 'true' : 'false';
|
|
2105
|
+
_refreshPoints();
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
// ── Drillthrough: the setup the host sends, and the click ────────────────────────
|
|
2109
|
+
// drillPoints: [{ point, dashboardId, pass: { "<B filter id>": { from: 'row'|'filter', name } |
|
|
2110
|
+
// { from: 'value', value } } }]. The kit reads them as sent; the host alone keeps them.
|
|
2111
|
+
const MAX_DEPTH = 3;
|
|
2112
|
+
|
|
2113
|
+
function _setDrillPoints(list) {
|
|
2114
|
+
const next = {};
|
|
2115
|
+
if (!Array.isArray(list)) {
|
|
2116
|
+
console.error('[DashboardKit] drillPoints ignored: it must be an array');
|
|
2117
|
+
} else {
|
|
2118
|
+
list.forEach(function (s, i) {
|
|
2119
|
+
if (!s || typeof s !== 'object' || typeof s.point !== 'string' ||
|
|
2120
|
+
!Number.isInteger(s.dashboardId) || s.dashboardId <= 0 ||
|
|
2121
|
+
!s.pass || typeof s.pass !== 'object' || Array.isArray(s.pass)) {
|
|
2122
|
+
console.error('[DashboardKit] drillPoints[' + i + '] ignored: it must be { point, dashboardId, pass }');
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
next[s.point] = { dashboardId: s.dashboardId, pass: s.pass };
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
_drillPoints = next;
|
|
2129
|
+
if (Object.keys(next).length && !_dashboardsApi)
|
|
2130
|
+
console.warn('[DashboardKit] drillPoints were sent without dashboardsApi: the cells stay plain text');
|
|
2131
|
+
_refreshPoints();
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
function _onPointClick(container, e) {
|
|
2135
|
+
const reg = _pointsByContainer[container.id];
|
|
2136
|
+
if (_setupMode || !reg || !_drillActive()) return;
|
|
2137
|
+
// A click something else has handled, or that landed on an element with a click of its own, is not ours.
|
|
2138
|
+
if (e.defaultPrevented || e.target.closest(OWN_CLICK)) return;
|
|
2139
|
+
let index;
|
|
2140
|
+
let row;
|
|
2141
|
+
if (reg.kind === 'column') {
|
|
2142
|
+
const td = e.target.closest('td');
|
|
2143
|
+
const tr = td && td.closest('tr[data-dk-row]');
|
|
2144
|
+
if (!tr || !container.contains(tr) || !td.classList.contains('dk-od-cell')) return;
|
|
2145
|
+
index = td.cellIndex;
|
|
2146
|
+
row = reg.rowAt(+tr.dataset.dkRow);
|
|
2147
|
+
} else {
|
|
2148
|
+
const cards = Array.from(container.querySelectorAll(reg.selector));
|
|
2149
|
+
index = cards.findIndex(function (el) { return el.contains(e.target); });
|
|
2150
|
+
const value = cards[index] && cards[index].querySelector(reg.valueSelector);
|
|
2151
|
+
if (!value || !value.classList.contains('dk-od-value') || !value.contains(e.target)) return;
|
|
2152
|
+
}
|
|
2153
|
+
const p = reg.points[index];
|
|
2154
|
+
const setup = p && p.unique && _drillPoints[p.key];
|
|
2155
|
+
if (setup) _openDashboard(setup, row, p, e.target);
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
// B's filters from the setup, the clicked row and A's header filters as the section loaded.
|
|
2159
|
+
// A row without the key the setup names, or a filter A does not have, stops the click: B must never
|
|
2160
|
+
// open unfiltered on a link that was meant to narrow it.
|
|
2161
|
+
function _drillValues(pass, row, localFilters) {
|
|
2162
|
+
const out = {};
|
|
2163
|
+
Object.keys(pass).forEach(function (id) {
|
|
2164
|
+
if (CONTEXT_KEYS.indexOf(id) >= 0) throw new Error('The setup passes "' + id + '", which the host owns.');
|
|
2165
|
+
const src = pass[id];
|
|
2166
|
+
if (!src || typeof src !== 'object') throw new Error('The setup gives "' + id + '" no source.');
|
|
2167
|
+
let v;
|
|
2168
|
+
if (src.from === 'row') {
|
|
2169
|
+
v = row ? row[src.name] : undefined;
|
|
2170
|
+
if (v === null || v === undefined || v === '')
|
|
2171
|
+
throw new Error('The clicked row has no "' + src.name + '" to give "' + id + '".');
|
|
2172
|
+
} else if (src.from === 'filter') {
|
|
2173
|
+
const f = localFilters.find(function (x) { return x.id === src.name; });
|
|
2174
|
+
if (!f) throw new Error('The dashboard has no filter "' + src.name + '" to give "' + id + '".');
|
|
2175
|
+
v = f.value;
|
|
2176
|
+
// A filter nobody has filled in is not narrowing anything: B keeps its own default, the same
|
|
2177
|
+
// wide view the page shows. (A row without its key is different: that would open B on nobody.)
|
|
2178
|
+
if (v === null || v === undefined || v === '' || (Array.isArray(v) && !v.length)) return;
|
|
2179
|
+
} else if (src.from === 'value') {
|
|
2180
|
+
v = src.value;
|
|
2181
|
+
} else {
|
|
2182
|
+
throw new Error('The setup gives "' + id + '" a source that is none of row, filter or value.');
|
|
2183
|
+
}
|
|
2184
|
+
out[id] = v;
|
|
2185
|
+
});
|
|
2186
|
+
return out;
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
// The dashboards service answers with keys, not sentences; the reader gets sentences.
|
|
2190
|
+
function _dashboardProblem(status, body) {
|
|
2191
|
+
const m = body && body.message;
|
|
2192
|
+
const key = (m && m.key) || (typeof m === 'string' ? m : '') || (body && typeof body.error === 'string' ? body.error : '');
|
|
2193
|
+
if (key === 'document_not_found') return 'There is no such dashboard.';
|
|
2194
|
+
if (key === 'permission_denied' || status === 403) return 'This dashboard is not available to you.';
|
|
2195
|
+
if (status === 401) return 'Your session has expired. Reload and sign in again.';
|
|
2196
|
+
return 'The dashboard could not be opened (HTTP ' + status + ').';
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
async function _fetchDashboard(id) {
|
|
2200
|
+
const headers = { 'x-access-token': _authToken };
|
|
2201
|
+
if (_dashboardsPermissionKey) headers['x-permission-key'] = _dashboardsPermissionKey;
|
|
2202
|
+
let res;
|
|
2203
|
+
try {
|
|
2204
|
+
res = await fetch(_dashboardsApi + '/getCustomDashboard?id=' + encodeURIComponent(id), { headers: headers });
|
|
2205
|
+
} catch {
|
|
2206
|
+
throw new Error('The dashboards service could not be reached.');
|
|
2207
|
+
}
|
|
2208
|
+
let body = null;
|
|
2209
|
+
try { body = await res.json(); } catch { /* not JSON: the status says what it can */ }
|
|
2210
|
+
if (!res.ok || !body || body.success === false) throw new Error(_dashboardProblem(res.status, body));
|
|
2211
|
+
const doc = body.result;
|
|
2212
|
+
if (!doc || typeof doc.html !== 'string' || !doc.html) throw new Error('The dashboard has no document.');
|
|
2213
|
+
return doc;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
function _closePopup() {
|
|
2217
|
+
const p = _popup;
|
|
2218
|
+
if (!p) return;
|
|
2219
|
+
_popup = null;
|
|
2220
|
+
p.el.remove();
|
|
2221
|
+
document.body.style.overflow = p.overflow;
|
|
2222
|
+
if (p.trigger && p.trigger.isConnected && p.trigger.focus) p.trigger.focus();
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
function _showPopup(trigger) {
|
|
2226
|
+
_closePopup();
|
|
2227
|
+
const el = document.createElement('div');
|
|
2228
|
+
el.className = 'dk-od';
|
|
2229
|
+
el.setAttribute('role', 'dialog');
|
|
2230
|
+
el.setAttribute('aria-modal', 'true');
|
|
2231
|
+
el.innerHTML =
|
|
2232
|
+
'<div class="dk-od-box"><div class="dk-od-head"><span class="dk-od-title"></span>' +
|
|
2233
|
+
'<button type="button" class="dk-od-close">Close</button></div><div class="dk-od-body"></div></div>';
|
|
2234
|
+
document.body.appendChild(el);
|
|
2235
|
+
const p = {
|
|
2236
|
+
el: el,
|
|
2237
|
+
trigger: trigger,
|
|
2238
|
+
overflow: document.body.style.overflow,
|
|
2239
|
+
title: el.querySelector('.dk-od-title'),
|
|
2240
|
+
body: el.querySelector('.dk-od-body'),
|
|
2241
|
+
};
|
|
2242
|
+
p.title.textContent = 'Opening dashboard…';
|
|
2243
|
+
document.body.style.overflow = 'hidden';
|
|
2244
|
+
el.addEventListener('mousedown', function (e) { if (e.target === el) _closePopup(); });
|
|
2245
|
+
const close = el.querySelector('.dk-od-close');
|
|
2246
|
+
close.addEventListener('click', _closePopup);
|
|
2247
|
+
close.focus();
|
|
2248
|
+
_popup = p;
|
|
2249
|
+
return p;
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
// A key pressed inside the frame of an opened dashboard never reaches the dashboard that opened
|
|
2253
|
+
// it, so that one asks: Esc closes the innermost popup, and with none of its own it is passed up.
|
|
2254
|
+
document.addEventListener('keydown', function (e) {
|
|
2255
|
+
if (e.key !== 'Escape') return;
|
|
2256
|
+
if (_popup) _closePopup();
|
|
2257
|
+
else if (_depth > 0) window.parent.postMessage({ type: 'DK_CLOSE_REQUEST' }, '*');
|
|
2258
|
+
});
|
|
2259
|
+
|
|
2260
|
+
// The link was made by a user, not a model: no "Ask AI to fix" here, only what went wrong.
|
|
2261
|
+
function _popupError(p, message) {
|
|
2262
|
+
if (_popup !== p) return;
|
|
2263
|
+
const box = document.createElement('div');
|
|
2264
|
+
box.className = 'dk-error';
|
|
2265
|
+
box.textContent = message;
|
|
2266
|
+
p.body.textContent = '';
|
|
2267
|
+
p.body.appendChild(box);
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
async function _openDashboard(setup, row, point, trigger) {
|
|
2271
|
+
const p = _showPopup(trigger);
|
|
2272
|
+
try {
|
|
2273
|
+
const values = _drillValues(setup.pass, row, point.localFilters);
|
|
2274
|
+
const doc = await _fetchDashboard(setup.dashboardId);
|
|
2275
|
+
if (_popup !== p) return;
|
|
2276
|
+
p.title.textContent = doc.name || 'Dashboard';
|
|
2277
|
+
|
|
2278
|
+
// What the host sent this dashboard, with this dashboard's own values. B gets its own setup
|
|
2279
|
+
// and one level more depth; at MAX_DEPTH it gets none and its cells stay plain text.
|
|
2280
|
+
const message = {
|
|
2281
|
+
type: 'CUSTOM_DASHBOARDS_PARAMS',
|
|
2282
|
+
token: _authToken,
|
|
2283
|
+
endpoint: _endpoint,
|
|
2284
|
+
filters: Object.assign({}, point.context, values),
|
|
2285
|
+
dashboardsApi: _dashboardsApi,
|
|
2286
|
+
depth: _depth + 1,
|
|
2287
|
+
};
|
|
2288
|
+
if (_dashboardsPermissionKey) message.dashboardsPermissionKey = _dashboardsPermissionKey;
|
|
2289
|
+
if (Array.isArray(doc.drillThroughInfo)) message.drillPoints = doc.drillThroughInfo;
|
|
2290
|
+
const theme = document.documentElement.dataset.theme;
|
|
2291
|
+
if (theme === 'light' || theme === 'dark') message.theme = theme;
|
|
2292
|
+
|
|
2293
|
+
const frame = document.createElement('iframe');
|
|
2294
|
+
frame.title = doc.name || 'Dashboard';
|
|
2295
|
+
frame.setAttribute('sandbox', 'allow-scripts allow-downloads');
|
|
2296
|
+
frame.addEventListener('load', function () {
|
|
2297
|
+
if (_popup === p) frame.contentWindow.postMessage(message, '*');
|
|
2298
|
+
});
|
|
2299
|
+
frame.srcdoc = doc.html;
|
|
2300
|
+
p.frame = frame;
|
|
2301
|
+
p.body.textContent = '';
|
|
2302
|
+
p.body.appendChild(frame);
|
|
2303
|
+
} catch (err) {
|
|
2304
|
+
_popupError(p, (err && err.message) || String(err));
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
|
|
1629
2308
|
// ── renderTable ───────────────────────────────────────────────────────────────
|
|
1630
2309
|
// columns: [{ key, label, format?, sortable?, tooltip? }]
|
|
1631
2310
|
// format receives (value, row) — read row.<key> for per-row currency, etc.
|
|
1632
2311
|
// totalsRow: [label|{key,agg}] matching columns length — optional
|
|
1633
2312
|
// title: table heading; also the CSV filename — omit to hide title + CSV button
|
|
1634
|
-
function renderTable(containerOrSelector, rows, options) {
|
|
2313
|
+
function renderTable(containerOrSelector, rows, options, _ctx) {
|
|
1635
2314
|
const container = resolveContainer('renderTable', containerOrSelector);
|
|
2315
|
+
_forgetPoints(container);
|
|
1636
2316
|
|
|
1637
2317
|
const { columns = [], totalsRow, title } = options || {};
|
|
1638
2318
|
|
|
@@ -1647,8 +2327,8 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1647
2327
|
// format returns a string (escaped) or an element.
|
|
1648
2328
|
function buildBodyRows(data) {
|
|
1649
2329
|
slots = _slots();
|
|
1650
|
-
return data.map(function (row) {
|
|
1651
|
-
return '<tr>' + columns.map(function (col) {
|
|
2330
|
+
return data.map(function (row, i) {
|
|
2331
|
+
return '<tr data-dk-row="' + i + '">' + columns.map(function (col) {
|
|
1652
2332
|
const raw = row[col.key];
|
|
1653
2333
|
const out = col.format ? col.format(raw, row) : raw;
|
|
1654
2334
|
if (col.format) _refuseHtmlString(out, 'renderTable: column "' + col.label + '" format');
|
|
@@ -1717,6 +2397,14 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1717
2397
|
container.innerHTML = html;
|
|
1718
2398
|
slots.apply(container);
|
|
1719
2399
|
if (totalsSlots) totalsSlots.apply(container);
|
|
2400
|
+
_registerPoints(container, 'thead th', _ctx, {
|
|
2401
|
+
kind: 'column',
|
|
2402
|
+
names: columns.map(function (c) { return c.key; }),
|
|
2403
|
+
title: title,
|
|
2404
|
+
columns: columns.map(function (c) { return { key: c.key, label: c.label }; }),
|
|
2405
|
+
row: rows[0],
|
|
2406
|
+
rowAt: function (i) { return sortedRows()[i]; },
|
|
2407
|
+
});
|
|
1720
2408
|
|
|
1721
2409
|
// Sort handler
|
|
1722
2410
|
const tblEl = container.querySelector('#' + tblId);
|
|
@@ -1731,6 +2419,7 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1731
2419
|
body.innerHTML = buildTotalsHtml() + rebuilt;
|
|
1732
2420
|
slots.apply(body);
|
|
1733
2421
|
if (totalsSlots) totalsSlots.apply(body);
|
|
2422
|
+
_decoratePoints(container);
|
|
1734
2423
|
tblEl.querySelectorAll('thead th[data-dk-sort-key]').forEach(function (h) {
|
|
1735
2424
|
h.classList.remove('dk-sort-asc', 'dk-sort-desc');
|
|
1736
2425
|
if (h.dataset.dkSortKey === sortKey) h.classList.add('dk-sort-' + sortDir);
|
|
@@ -1781,18 +2470,21 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1781
2470
|
'</div>';
|
|
1782
2471
|
}
|
|
1783
2472
|
|
|
1784
|
-
function renderKpiCard(containerOrSelector, item) {
|
|
2473
|
+
function renderKpiCard(containerOrSelector, item, _ctx) {
|
|
1785
2474
|
const container = resolveContainer('renderKpiCard', containerOrSelector);
|
|
2475
|
+
_forgetPoints(container);
|
|
1786
2476
|
_checkItems('renderKpiCard', [item]);
|
|
1787
2477
|
const slots = _slots();
|
|
1788
2478
|
container.innerHTML = _kpiCardHtml(item, slots);
|
|
1789
2479
|
slots.apply(container);
|
|
2480
|
+
_registerPoints(container, '.dk-kpi', _ctx, { kind: 'card', names: [item.label], valueSelector: '.dk-kpi-value' });
|
|
1790
2481
|
}
|
|
1791
2482
|
|
|
1792
2483
|
// ── renderKpiStrip ────────────────────────────────────────────────────────────
|
|
1793
2484
|
// options: { title? }
|
|
1794
|
-
function renderKpiStrip(containerOrSelector, items, options) {
|
|
2485
|
+
function renderKpiStrip(containerOrSelector, items, options, _ctx) {
|
|
1795
2486
|
const container = resolveContainer('renderKpiStrip', containerOrSelector);
|
|
2487
|
+
_forgetPoints(container);
|
|
1796
2488
|
const { title } = options || {};
|
|
1797
2489
|
if (!items || !items.length) {
|
|
1798
2490
|
container.innerHTML = _titleHtml(title) + EMPTY_HTML;
|
|
@@ -1806,13 +2498,20 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1806
2498
|
'</div>';
|
|
1807
2499
|
container.innerHTML = html;
|
|
1808
2500
|
slots.apply(container);
|
|
2501
|
+
_registerPoints(container, '.dk-kpi', _ctx, {
|
|
2502
|
+
kind: 'card',
|
|
2503
|
+
valueSelector: '.dk-kpi-value',
|
|
2504
|
+
names: items.map(function (i) { return i.label; }),
|
|
2505
|
+
title: title,
|
|
2506
|
+
});
|
|
1809
2507
|
}
|
|
1810
2508
|
|
|
1811
2509
|
// ── renderInfoGrid ────────────────────────────────────────────────────────────
|
|
1812
2510
|
// renders a responsive key/value grid
|
|
1813
2511
|
// options: { title? }
|
|
1814
|
-
function renderInfoGrid(containerOrSelector, items, options) {
|
|
2512
|
+
function renderInfoGrid(containerOrSelector, items, options, _ctx) {
|
|
1815
2513
|
const container = resolveContainer('renderInfoGrid', containerOrSelector);
|
|
2514
|
+
_forgetPoints(container);
|
|
1816
2515
|
const { title } = options || {};
|
|
1817
2516
|
if (!items || !items.length) {
|
|
1818
2517
|
container.innerHTML = _titleHtml(title) + EMPTY_HTML;
|
|
@@ -1832,13 +2531,20 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1832
2531
|
'</div>';
|
|
1833
2532
|
container.innerHTML = html;
|
|
1834
2533
|
slots.apply(container);
|
|
2534
|
+
_registerPoints(container, '.dk-info-row', _ctx, {
|
|
2535
|
+
kind: 'card',
|
|
2536
|
+
valueSelector: '.dk-val',
|
|
2537
|
+
names: items.map(function (i) { return i.label; }),
|
|
2538
|
+
title: title,
|
|
2539
|
+
});
|
|
1835
2540
|
}
|
|
1836
2541
|
|
|
1837
2542
|
// ── renderTotalsStrip ─────────────────────────────────────────────────────────
|
|
1838
2543
|
// renders a horizontal totals bar
|
|
1839
2544
|
// options: { title? }
|
|
1840
|
-
function renderTotalsStrip(containerOrSelector, items, options) {
|
|
2545
|
+
function renderTotalsStrip(containerOrSelector, items, options, _ctx) {
|
|
1841
2546
|
const container = resolveContainer('renderTotalsStrip', containerOrSelector);
|
|
2547
|
+
_forgetPoints(container);
|
|
1842
2548
|
const { title } = options || {};
|
|
1843
2549
|
if (!items || !items.length) {
|
|
1844
2550
|
container.innerHTML = _titleHtml(title) + EMPTY_HTML;
|
|
@@ -1859,6 +2565,12 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1859
2565
|
'</div>';
|
|
1860
2566
|
container.innerHTML = html;
|
|
1861
2567
|
slots.apply(container);
|
|
2568
|
+
_registerPoints(container, '.dk-field', _ctx, {
|
|
2569
|
+
kind: 'card',
|
|
2570
|
+
valueSelector: '.dk-field-value',
|
|
2571
|
+
names: items.map(function (i) { return i.label; }),
|
|
2572
|
+
title: title,
|
|
2573
|
+
});
|
|
1862
2574
|
}
|
|
1863
2575
|
|
|
1864
2576
|
// ── CSV download ──────────────────────────────────────────────────────────────
|
|
@@ -1866,7 +2578,15 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1866
2578
|
const rows = [];
|
|
1867
2579
|
tableEl.querySelectorAll('tr').forEach(function (tr) {
|
|
1868
2580
|
const cells = Array.from(tr.querySelectorAll('th, td')).map(function (td) {
|
|
1869
|
-
|
|
2581
|
+
let v = td.dataset.csvValue;
|
|
2582
|
+
if (v === undefined) {
|
|
2583
|
+
let cell = td;
|
|
2584
|
+
if (td.querySelector('.dk-pt-btn')) {
|
|
2585
|
+
cell = td.cloneNode(true);
|
|
2586
|
+
cell.querySelectorAll('.dk-pt-btn').forEach(function (b) { b.remove(); });
|
|
2587
|
+
}
|
|
2588
|
+
v = cell.textContent.trim();
|
|
2589
|
+
}
|
|
1870
2590
|
const safe = /^[=+\-@]/.test(String(v)) && !/^-\d/.test(String(v)) ? "'" + String(v) : String(v);
|
|
1871
2591
|
return '"' + safe.replace(/"/g, '""') + '"';
|
|
1872
2592
|
});
|
|
@@ -1893,6 +2613,11 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1893
2613
|
});
|
|
1894
2614
|
|
|
1895
2615
|
const clone = document.documentElement.cloneNode(true);
|
|
2616
|
+
clone.querySelectorAll('.dk-pt-btn, .dk-od').forEach(function (n) { n.remove(); });
|
|
2617
|
+
clone.querySelectorAll('.dk-od-cell, .dk-od-value').forEach(function (n) {
|
|
2618
|
+
n.classList.remove('dk-od-cell', 'dk-od-value', 'dk-od-keep');
|
|
2619
|
+
});
|
|
2620
|
+
clone.removeAttribute('data-dk-setup');
|
|
1896
2621
|
|
|
1897
2622
|
// A canvas clones blank — its pixels aren't part of the DOM — so each chart
|
|
1898
2623
|
// goes into the snapshot as an image of what it currently shows. The size
|
package/wrapper.css
CHANGED
|
@@ -259,6 +259,53 @@ iframe#iframe {
|
|
|
259
259
|
color: var(--err);
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
+
.drill-panel {
|
|
263
|
+
position: fixed;
|
|
264
|
+
top: 52px;
|
|
265
|
+
right: 12px;
|
|
266
|
+
width: 380px;
|
|
267
|
+
max-height: calc(100% - 64px);
|
|
268
|
+
overflow: auto;
|
|
269
|
+
display: flex;
|
|
270
|
+
flex-direction: column;
|
|
271
|
+
gap: 8px;
|
|
272
|
+
padding: 10px;
|
|
273
|
+
background: var(--surface);
|
|
274
|
+
border: 1px solid var(--border);
|
|
275
|
+
border-radius: 6px;
|
|
276
|
+
font-size: 12px;
|
|
277
|
+
z-index: 150;
|
|
278
|
+
}
|
|
279
|
+
.drill-panel textarea {
|
|
280
|
+
width: 100%;
|
|
281
|
+
background: var(--bg);
|
|
282
|
+
color: var(--text);
|
|
283
|
+
border: 1px solid var(--border);
|
|
284
|
+
border-radius: 4px;
|
|
285
|
+
font: 11px/1.4 ui-monospace, monospace;
|
|
286
|
+
}
|
|
287
|
+
.drill-panel .btn {
|
|
288
|
+
align-self: flex-start;
|
|
289
|
+
}
|
|
290
|
+
.drill-err {
|
|
291
|
+
color: var(--err);
|
|
292
|
+
}
|
|
293
|
+
.drill-log-title {
|
|
294
|
+
color: var(--muted);
|
|
295
|
+
}
|
|
296
|
+
.drill-log {
|
|
297
|
+
margin: 0;
|
|
298
|
+
padding: 6px;
|
|
299
|
+
max-height: 260px;
|
|
300
|
+
overflow: auto;
|
|
301
|
+
background: var(--bg);
|
|
302
|
+
border: 1px solid var(--border);
|
|
303
|
+
border-radius: 4px;
|
|
304
|
+
font: 11px/1.4 ui-monospace, monospace;
|
|
305
|
+
white-space: pre-wrap;
|
|
306
|
+
word-break: break-all;
|
|
307
|
+
}
|
|
308
|
+
|
|
262
309
|
.modal-backdrop {
|
|
263
310
|
position: fixed;
|
|
264
311
|
inset: 0;
|
package/wrapper.js
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
// No data-platform means igaming, as before. An unknown name is an error, never a guess.
|
|
6
6
|
// apiBase — sign-in (the BackOffice's own API)
|
|
7
7
|
// gatewayEndpoint — the SQL gateway a dashboard's queries go to, sent as `endpoint`
|
|
8
|
+
// dashboardsApi — where the BackOffice's dashboards live, sent so a drillthrough can open another one;
|
|
9
|
+
// absent = none is sent and drillthroughs stay plain text on that platform
|
|
10
|
+
// dashboardsPermissionKey — sent with it, as the BackOffice sends it
|
|
8
11
|
// storagePrefix — localStorage key prefix, so the two keep their own sign-in on one origin
|
|
9
12
|
// label — the name in the top bar, before the word "Platform", that says which BackOffice this page talks to
|
|
10
13
|
const PLATFORMS = {
|
|
@@ -12,6 +15,8 @@
|
|
|
12
15
|
label: "iGaming",
|
|
13
16
|
apiBase: "https://bcproxy.draftplaza.com",
|
|
14
17
|
gatewayEndpoint: "https://aidqgateway.draftplaza.com/aidq",
|
|
18
|
+
dashboardsApi: "https://bcproxy.draftplaza.com/dashboards",
|
|
19
|
+
dashboardsPermissionKey: "CUSTOM_DASHBOARDS",
|
|
15
20
|
storagePrefix: "iqg.harness.",
|
|
16
21
|
},
|
|
17
22
|
poker: {
|
|
@@ -29,6 +34,7 @@
|
|
|
29
34
|
const LS_TOKEN = CFG.storagePrefix + "token";
|
|
30
35
|
const LS_USER = CFG.storagePrefix + "user";
|
|
31
36
|
const LS_THEME = CFG.storagePrefix + "theme";
|
|
37
|
+
const LS_DRILL = CFG.storagePrefix + "drillPoints";
|
|
32
38
|
|
|
33
39
|
// Capture srcdoc from the inline iframe before DOM rebuild.
|
|
34
40
|
const _srcdoc = document.getElementById("iframe")?.getAttribute("srcdoc") || "";
|
|
@@ -77,6 +83,7 @@
|
|
|
77
83
|
</div>
|
|
78
84
|
</label>
|
|
79
85
|
<button class="btn btn-sm" id="snapshotBtn">Export snapshot</button>
|
|
86
|
+
<button class="btn btn-sm btn-ghost" id="drillBtn">Drillthrough</button>
|
|
80
87
|
</div>
|
|
81
88
|
<div class="user-badge">
|
|
82
89
|
<span class="name" id="userName">Not signed in</span>
|
|
@@ -115,6 +122,14 @@
|
|
|
115
122
|
</div>
|
|
116
123
|
</div>
|
|
117
124
|
</div>
|
|
125
|
+
<aside class="drill-panel" id="drillPanel" hidden>
|
|
126
|
+
<label><input type="checkbox" id="drillSetup"> Setup mode</label>
|
|
127
|
+
<label>drillPoints (JSON) <textarea id="drillJson" rows="6" spellcheck="false" placeholder='[{"point":"t1|username","dashboardId":7,"pass":{"player_id":{"from":"row","name":"player_id"}}}]'></textarea></label>
|
|
128
|
+
<div class="drill-err" id="drillErr" hidden></div>
|
|
129
|
+
<button class="btn btn-sm" id="drillApply">Apply</button>
|
|
130
|
+
<div class="drill-log-title">Reported by the kit</div>
|
|
131
|
+
<pre class="drill-log" id="drillLog"></pre>
|
|
132
|
+
</aside>
|
|
118
133
|
<div class="toast" id="toast"></div>`;
|
|
119
134
|
|
|
120
135
|
document.getElementById("iframe").setAttribute("srcdoc", _srcdoc);
|
|
@@ -136,6 +151,8 @@
|
|
|
136
151
|
},
|
|
137
152
|
user: lsGet(LS_USER, null), token: lsGet(LS_TOKEN, ""),
|
|
138
153
|
theme: lsGet(LS_THEME, "dark"), pendingUsername: null,
|
|
154
|
+
// Drillthrough, for trying the kit without a BackOffice: the setups typed in, and what the kit reported.
|
|
155
|
+
setupMode: false, drillPoints: lsGet(LS_DRILL, []), points: null, lastSetup: null,
|
|
139
156
|
};
|
|
140
157
|
|
|
141
158
|
function todayYmd() {
|
|
@@ -205,7 +222,7 @@
|
|
|
205
222
|
? { dateFromIso: dayStart(State.filters.manualFrom, tz), dateToIso: dayEnd(State.filters.manualTo, tz) }
|
|
206
223
|
: (presetDates(State.filters.datePreset, tz) || { dateFromIso: dayStart(todayYmd(), tz), dateToIso: dayEnd(todayYmd(), tz) });
|
|
207
224
|
const hid = State.filters.hierarchyId;
|
|
208
|
-
|
|
225
|
+
const msg = {
|
|
209
226
|
type: "CUSTOM_DASHBOARDS_PARAMS", token: State.token, theme: State.theme,
|
|
210
227
|
// The SQL gateway of this BackOffice; the kit would otherwise use its own default.
|
|
211
228
|
endpoint: CFG.gatewayEndpoint,
|
|
@@ -214,12 +231,21 @@
|
|
|
214
231
|
hierarchyId: hid == null || Number.isNaN(hid) ? null : Number(hid)
|
|
215
232
|
}
|
|
216
233
|
};
|
|
234
|
+
if (CFG.dashboardsApi) {
|
|
235
|
+
msg.dashboardsApi = CFG.dashboardsApi;
|
|
236
|
+
if (CFG.dashboardsPermissionKey) msg.dashboardsPermissionKey = CFG.dashboardsPermissionKey;
|
|
237
|
+
msg.drillPoints = State.drillPoints;
|
|
238
|
+
}
|
|
239
|
+
return msg;
|
|
217
240
|
}
|
|
218
241
|
function maybeSend() {
|
|
219
242
|
if (!State.token || tokenStatus(State.token).state === "err") return;
|
|
220
243
|
const f = document.getElementById("iframe");
|
|
221
244
|
if (!f || f.hidden || !f.contentWindow) return;
|
|
222
|
-
try {
|
|
245
|
+
try {
|
|
246
|
+
f.contentWindow.postMessage(buildMsg(), "*");
|
|
247
|
+
if (State.setupMode) f.contentWindow.postMessage({ type: "DK_SETUP_MODE", on: true }, "*");
|
|
248
|
+
} catch (e) { toast(`postMessage failed: ${e?.message || e}`, true); }
|
|
223
249
|
}
|
|
224
250
|
|
|
225
251
|
// ── Render ───────────────────────────────────────────────────────────────────
|
|
@@ -326,6 +352,36 @@
|
|
|
326
352
|
});
|
|
327
353
|
$("themeToggle").addEventListener("click", e => { const b = e.target.closest("button[data-theme]"); if (b) setTheme(b.dataset.theme); });
|
|
328
354
|
$("iframe").addEventListener("load", () => maybeSend());
|
|
355
|
+
wireDrill();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// The kit reports its points (DK_POINTS) and a click on a set-up button (DK_POINT_SETUP); a real BackOffice
|
|
359
|
+
// would open a dialog on the latter. Here both are shown as they came, and the setups are typed in.
|
|
360
|
+
function renderDrillLog() {
|
|
361
|
+
$("drillLog").textContent = JSON.stringify({ points: State.points, lastSetup: State.lastSetup }, null, 2);
|
|
362
|
+
}
|
|
363
|
+
function wireDrill() {
|
|
364
|
+
const frame = () => $("iframe").contentWindow;
|
|
365
|
+
$("drillJson").value = JSON.stringify(State.drillPoints, null, 2);
|
|
366
|
+
$("drillBtn").addEventListener("click", () => { $("drillPanel").hidden = !$("drillPanel").hidden; renderDrillLog(); });
|
|
367
|
+
$("drillSetup").addEventListener("change", e => {
|
|
368
|
+
State.setupMode = e.target.checked;
|
|
369
|
+
frame()?.postMessage({ type: "DK_SETUP_MODE", on: State.setupMode }, "*");
|
|
370
|
+
});
|
|
371
|
+
$("drillApply").addEventListener("click", () => {
|
|
372
|
+
let list;
|
|
373
|
+
try { list = JSON.parse($("drillJson").value || "[]"); } catch (e) { $("drillErr").textContent = "Not JSON: " + e.message; $("drillErr").hidden = false; return; }
|
|
374
|
+
if (!Array.isArray(list)) { $("drillErr").textContent = "drillPoints must be an array"; $("drillErr").hidden = false; return; }
|
|
375
|
+
$("drillErr").hidden = true;
|
|
376
|
+
State.drillPoints = list;
|
|
377
|
+
lsSet(LS_DRILL, list);
|
|
378
|
+
frame()?.postMessage({ type: "DK_DRILL_POINTS", drillPoints: list }, "*");
|
|
379
|
+
});
|
|
380
|
+
window.addEventListener("message", e => {
|
|
381
|
+
if (e.source !== frame() || !e.data) return;
|
|
382
|
+
if (e.data.type === "DK_POINTS") { State.points = e.data.points; renderDrillLog(); }
|
|
383
|
+
if (e.data.type === "DK_POINT_SETUP") { State.lastSetup = e.data; renderDrillLog(); $("drillPanel").hidden = false; toast("Set up: " + e.data.point); }
|
|
384
|
+
});
|
|
329
385
|
}
|
|
330
386
|
|
|
331
387
|
function boot() {
|