@datalabz_/dashboard-kit 6.0.4 → 6.0.6
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 +63 -6
- package/package.json +1 -1
- package/v4.js +1 -1
- package/v5.js +1 -1
- package/v6.js +933 -41
- package/wrapper.css +47 -0
- package/wrapper.js +58 -2
package/v6.js
CHANGED
|
@@ -20,11 +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 = 'cc1be64'; // replaced at deploy: sed -i "s/cc1be64/$(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
|
+
let _pendingFilters = {}; // header filters a parent sent before boot, applied at boot
|
|
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
|
|
28
37
|
|
|
29
38
|
// ── Inject CSS ───────────────────────────────────────────────────────────────
|
|
30
39
|
// The kit carries its own CSS: Claude artifacts may load scripts from jsDelivr but not
|
|
@@ -754,6 +763,185 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
754
763
|
color: var(--muted);
|
|
755
764
|
font-style: italic;
|
|
756
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
|
+
}
|
|
757
945
|
/*# sourceURL=dashboard-kit-v6.css */`;
|
|
758
946
|
if (!document.getElementById('dk-kit-css')) {
|
|
759
947
|
const style = document.createElement('style');
|
|
@@ -937,11 +1125,12 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
937
1125
|
// the list follows that flow and nothing else: a control it cannot fill is not listed (radio,
|
|
938
1126
|
// file, hidden, password, buttons; no id; a second control with an id already listed), a select
|
|
939
1127
|
// lists only options a value may name, since an empty value is refused, and a select with none
|
|
940
|
-
// is
|
|
941
|
-
//
|
|
942
|
-
//
|
|
1128
|
+
// is dynamic: its options come later, so it is listed with dynamicOptions: true and takes any value.
|
|
1129
|
+
// What exists when the dashboard boots is what counts: once it has booted, the list is the one
|
|
1130
|
+
// taken at that moment, so options a section loads later by query are not in it, as they were not
|
|
1131
|
+
// there for the fill. Nothing is read again. It needs no token or
|
|
943
1132
|
// period, so a parent can ask as soon as the frame has loaded.
|
|
944
|
-
const UNFILLABLE_TYPES = ['
|
|
1133
|
+
const UNFILLABLE_TYPES = ['file', 'hidden', 'password', 'button', 'submit', 'reset', 'image'];
|
|
945
1134
|
let _bootFilters = null; // the list as it was when the dashboard booted
|
|
946
1135
|
const FILTER_MAX_OPTIONS = 100;
|
|
947
1136
|
const FILTER_MAX_TEXT = 500;
|
|
@@ -962,9 +1151,36 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
962
1151
|
return _clip(el.getAttribute('aria-label') || el.getAttribute('placeholder') || '', 200);
|
|
963
1152
|
}
|
|
964
1153
|
|
|
1154
|
+
// A radio group is one filter, keyed by its name: the radios share the name and each has its own
|
|
1155
|
+
// value. Filling it checks the radio with the value; listing it is one entry with the radios as options.
|
|
1156
|
+
function _radioGroup(header, name) {
|
|
1157
|
+
return Array.from(header.querySelectorAll('input[type="radio"]')).filter(function (r) { return r.name === name; });
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
function _radioInfo(header, name) {
|
|
1161
|
+
const group = _radioGroup(header, name);
|
|
1162
|
+
const legend = group[0].closest('fieldset') && group[0].closest('fieldset').querySelector('legend');
|
|
1163
|
+
const checked = group.find(function (r) { return r.checked; });
|
|
1164
|
+
const f = {
|
|
1165
|
+
id: name,
|
|
1166
|
+
label: _clip((legend && legend.textContent.replace(/\s+/g, ' ').trim()) || name, 200),
|
|
1167
|
+
type: 'radio',
|
|
1168
|
+
required: group.some(function (r) { return r.required; }),
|
|
1169
|
+
optionsTotal: group.length,
|
|
1170
|
+
options: group.slice(0, FILTER_MAX_OPTIONS).map(function (r) {
|
|
1171
|
+
return { value: _clip(r.value, 200), label: _filterLabel(r) || _clip(r.value, 200) };
|
|
1172
|
+
}),
|
|
1173
|
+
defaultValue: checked ? checked.value : '',
|
|
1174
|
+
};
|
|
1175
|
+
if (group.every(function (r) { return r.disabled; })) f.disabled = true;
|
|
1176
|
+
return f;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
965
1179
|
function _controlValue(el) {
|
|
966
1180
|
if (el.tagName === 'SELECT') {
|
|
967
|
-
return el.multiple
|
|
1181
|
+
return el.multiple
|
|
1182
|
+
? Array.from(el.selectedOptions).slice(0, FILTER_MAX_OPTIONS).map(function (o) { return _clip(o.value, 200); })
|
|
1183
|
+
: _clip(el.value, 200);
|
|
968
1184
|
}
|
|
969
1185
|
return el.type === 'checkbox' ? el.checked : _clip(el.value, FILTER_MAX_TEXT);
|
|
970
1186
|
}
|
|
@@ -973,13 +1189,19 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
973
1189
|
const header = document.querySelector('[data-dk-header]');
|
|
974
1190
|
const out = [];
|
|
975
1191
|
if (!header) return out;
|
|
976
|
-
const seen =
|
|
1192
|
+
const seen = new Set();
|
|
1193
|
+
const seenRadio = new Set();
|
|
977
1194
|
header.querySelectorAll('input, select, textarea').forEach(function (el) {
|
|
978
|
-
if (
|
|
1195
|
+
if (el.type === 'radio') {
|
|
1196
|
+
if (!el.name || seenRadio.has(el.name)) return;
|
|
1197
|
+
seenRadio.add(el.name);
|
|
1198
|
+
out.push(_radioInfo(header, el.name));
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
if (!el.id || seen.has(el.id) || UNFILLABLE_TYPES.indexOf(el.type) >= 0) return;
|
|
979
1202
|
const isSelect = el.tagName === 'SELECT';
|
|
980
1203
|
const named = isSelect ? Array.from(el.options).filter(function (o) { return o.value !== ''; }) : null;
|
|
981
|
-
|
|
982
|
-
seen[el.id] = true;
|
|
1204
|
+
seen.add(el.id);
|
|
983
1205
|
const f = {
|
|
984
1206
|
id: el.id,
|
|
985
1207
|
label: _filterLabel(el),
|
|
@@ -994,40 +1216,59 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
994
1216
|
}
|
|
995
1217
|
if (isSelect) {
|
|
996
1218
|
f.multiple = el.multiple;
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1219
|
+
if (named.length) {
|
|
1220
|
+
f.optionsTotal = named.length;
|
|
1221
|
+
f.options = named.slice(0, FILTER_MAX_OPTIONS).map(function (o) {
|
|
1222
|
+
return { value: _clip(o.value, 200), label: _clip(o.textContent.trim(), 200) };
|
|
1223
|
+
});
|
|
1224
|
+
} else {
|
|
1225
|
+
// Its options come later and differ from one time to the next, so none are listed: the
|
|
1226
|
+
// select takes any value.
|
|
1227
|
+
f.dynamicOptions = true;
|
|
1228
|
+
}
|
|
1001
1229
|
}
|
|
1002
|
-
f.
|
|
1230
|
+
f.defaultValue = _controlValue(el);
|
|
1003
1231
|
out.push(f);
|
|
1004
1232
|
});
|
|
1005
1233
|
return out;
|
|
1006
1234
|
}
|
|
1007
1235
|
|
|
1008
|
-
// What DK_FILTERS_INFO carries: the
|
|
1236
|
+
// What DK_FILTERS_INFO carries: the dashboard as it starts, not as it is now. Once it has booted
|
|
1237
|
+
// that is the list taken then, before the fill wrote or locked anything, so what a reader typed
|
|
1238
|
+
// since is never in it, and what a host stores with the dashboard does not depend on who asked.
|
|
1009
1239
|
function _filtersInfo() {
|
|
1010
|
-
|
|
1011
|
-
const header = document.querySelector('[data-dk-header]');
|
|
1012
|
-
list.forEach(function (f) {
|
|
1013
|
-
const el = header ? header.querySelector('#' + CSS.escape(f.id)) : null;
|
|
1014
|
-
if (!el) return;
|
|
1015
|
-
f.value = _controlValue(el);
|
|
1016
|
-
if (el.disabled) f.disabled = true; else delete f.disabled;
|
|
1017
|
-
});
|
|
1018
|
-
return list;
|
|
1240
|
+
return (_bootFilters || _dashboardFilters()).map(function (f) { return Object.assign({}, f); });
|
|
1019
1241
|
}
|
|
1020
1242
|
|
|
1021
|
-
|
|
1022
1243
|
function _onMessage(e) {
|
|
1023
1244
|
if (!e.data || typeof e.data !== 'object') return;
|
|
1024
1245
|
if (e.data.type === 'DK_GET_FILTERS_INFO') {
|
|
1025
|
-
|
|
1246
|
+
let reply;
|
|
1247
|
+
try { reply = { type: 'DK_FILTERS_INFO', filters: _filtersInfo() }; }
|
|
1248
|
+
catch (err) {
|
|
1249
|
+
console.error('[DashboardKit] could not describe the filters:', err);
|
|
1250
|
+
reply = { type: 'DK_FILTERS_INFO', filters: [], error: String((err && err.message) || err) };
|
|
1251
|
+
}
|
|
1252
|
+
window.parent.postMessage(reply, '*');
|
|
1253
|
+
return;
|
|
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);
|
|
1026
1266
|
return;
|
|
1027
1267
|
}
|
|
1028
1268
|
if (e.data.type === 'RK_SNAPSHOT') { _snapshot(); return; }
|
|
1029
1269
|
if (e.data.type === 'CHAT_MODE') { document.documentElement.dataset.chatMode = 'true'; return; }
|
|
1030
1270
|
if (e.data.type !== 'CUSTOM_DASHBOARDS_PARAMS') return;
|
|
1271
|
+
if (_filtersRefused) return;
|
|
1031
1272
|
|
|
1032
1273
|
if (typeof e.data.token === 'string') _authToken = e.data.token;
|
|
1033
1274
|
|
|
@@ -1042,6 +1283,19 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1042
1283
|
if (e.data.theme === 'light' || e.data.theme === 'dark')
|
|
1043
1284
|
document.documentElement.dataset.theme = e.data.theme;
|
|
1044
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());
|
|
1045
1299
|
const f = e.data.filters;
|
|
1046
1300
|
if (f && typeof f === 'object') {
|
|
1047
1301
|
if (typeof f.dateFrom === 'string') _dateFromIso = f.dateFrom;
|
|
@@ -1049,11 +1303,26 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1049
1303
|
if (typeof f.timezone === 'string') _timezone = f.timezone;
|
|
1050
1304
|
if ('hierarchyId' in f)
|
|
1051
1305
|
_hierarchyId = f.hierarchyId == null ? null : Number(f.hierarchyId);
|
|
1306
|
+
// Any other key is a header filter. It is applied once, at boot, never by a later message.
|
|
1307
|
+
if (!_hasBooted) Object.keys(f).forEach(function (k) {
|
|
1308
|
+
if (CONTEXT_KEYS.indexOf(k) < 0) _pendingFilters[k] = f[k];
|
|
1309
|
+
});
|
|
1052
1310
|
}
|
|
1053
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
|
+
|
|
1054
1317
|
if (!_hasBooted && _authToken && _dateFromIso && _dateToIso && _timezone) {
|
|
1055
|
-
|
|
1318
|
+
// Before the fill locks anything and before a section runs. A fault in describing the filters
|
|
1319
|
+
// must never keep the dashboard from booting, so it only costs the list.
|
|
1320
|
+
try { _bootFilters = _dashboardFilters(); }
|
|
1321
|
+
catch (err) { console.error('[DashboardKit] could not describe the filters:', err); _bootFilters = null; }
|
|
1322
|
+
const refusal = _fillHeaderFilters(_pendingFilters);
|
|
1323
|
+
if (refusal) { _refuseFilters(refusal); return; }
|
|
1056
1324
|
_hasBooted = true;
|
|
1325
|
+
_schedulePoints();
|
|
1057
1326
|
const wait = document.getElementById('dk-wait');
|
|
1058
1327
|
if (wait) wait.hidden = true;
|
|
1059
1328
|
_buildTabNav();
|
|
@@ -1064,6 +1333,126 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1064
1333
|
}
|
|
1065
1334
|
}
|
|
1066
1335
|
|
|
1336
|
+
// ── Filters a parent passes ───────────────────────────────────────────────────
|
|
1337
|
+
// dateFrom, dateTo, timezone and hierarchyId are context the host owns. Any other key in
|
|
1338
|
+
// `filters` is a header filter: written into the control with that id, read back, and locked.
|
|
1339
|
+
// What the control kept was valid; what the browser dropped (an <option> that is not there, a
|
|
1340
|
+
// date in the wrong format, text in a number field) was not. Anything else is a refusal and the
|
|
1341
|
+
// dashboard does not boot — it never opens unfiltered. No input or change event is fired:
|
|
1342
|
+
// a section reads its filters from the controls when it loads.
|
|
1343
|
+
const CONTEXT_KEYS = ['dateFrom', 'dateTo', 'timezone', 'hierarchyId'];
|
|
1344
|
+
|
|
1345
|
+
function _show(v) {
|
|
1346
|
+
let s;
|
|
1347
|
+
try { s = JSON.stringify(v); } catch { s = String(v); }
|
|
1348
|
+
if (s === undefined) s = 'undefined';
|
|
1349
|
+
return s.length > 60 ? s.slice(0, 57) + '…' : s;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// null when the control took the value, otherwise why not.
|
|
1353
|
+
// A select with no option but the empty one gets its options from a query that runs after the
|
|
1354
|
+
// boot, so nothing can be checked against them. The value goes in as an option of its own, selected,
|
|
1355
|
+
// and stays selected while the dashboard fills in the rest: whatever replaces the options, the
|
|
1356
|
+
// filter is still the one asked for, so the dashboard never opens unfiltered.
|
|
1357
|
+
function _fillLateSelect(el, v) {
|
|
1358
|
+
if (el.multiple ? (!Array.isArray(v) || !v.length) : (typeof v !== 'string' && typeof v !== 'number'))
|
|
1359
|
+
return el.multiple ? 'a multiple select takes a non-empty array' : 'a filter takes a string or a number';
|
|
1360
|
+
const values = (el.multiple ? v : [v]).map(String);
|
|
1361
|
+
if (values.indexOf('') >= 0) return 'there is no value';
|
|
1362
|
+
function apply() {
|
|
1363
|
+
values.forEach(function (s) {
|
|
1364
|
+
if (!Array.from(el.options).some(function (o) { return o.value === s; })) el.appendChild(new Option(s, s));
|
|
1365
|
+
});
|
|
1366
|
+
Array.from(el.options).forEach(function (o) { o.selected = values.indexOf(o.value) >= 0; });
|
|
1367
|
+
}
|
|
1368
|
+
apply();
|
|
1369
|
+
const watch = { childList: true };
|
|
1370
|
+
let repairs = 0;
|
|
1371
|
+
const keep = new MutationObserver(function () {
|
|
1372
|
+
const got = Array.from(el.selectedOptions).map(function (o) { return o.value; });
|
|
1373
|
+
if (got.length === values.length && values.every(function (s) { return got.indexOf(s) >= 0; })) return;
|
|
1374
|
+
// A dashboard that rebuilds the options each time it sees them change would trade blows with
|
|
1375
|
+
// this forever and freeze the page; past this many repairs the kit stops.
|
|
1376
|
+
// Then it says so and shows no data: a filter it could not keep must not leave figures on screen.
|
|
1377
|
+
if (++repairs > 100) {
|
|
1378
|
+
keep.disconnect();
|
|
1379
|
+
_refuseFilters('The filter "' + el.id + '" keeps being reset by the dashboard.');
|
|
1380
|
+
document.querySelectorAll('.dk-panel, nav.dk-tabs').forEach(function (n) { n.hidden = true; });
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
keep.disconnect();
|
|
1384
|
+
apply();
|
|
1385
|
+
keep.takeRecords();
|
|
1386
|
+
keep.observe(el, watch);
|
|
1387
|
+
});
|
|
1388
|
+
keep.observe(el, watch);
|
|
1389
|
+
return null;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
function _writeControl(el, v) {
|
|
1393
|
+
if (v === null || v === undefined || v === '') return 'there is no value';
|
|
1394
|
+
if (el.tagName === 'SELECT' && !Array.from(el.options).some(function (o) { return o.value !== ''; }))
|
|
1395
|
+
return _fillLateSelect(el, v);
|
|
1396
|
+
if (el.tagName === 'SELECT' && el.multiple) {
|
|
1397
|
+
if (!Array.isArray(v) || !v.length) return 'a multiple select takes a non-empty array';
|
|
1398
|
+
const want = v.map(String);
|
|
1399
|
+
Array.from(el.options).forEach(function (o) { o.selected = want.indexOf(o.value) >= 0; });
|
|
1400
|
+
const got = Array.from(el.selectedOptions).map(function (o) { return o.value; });
|
|
1401
|
+
return got.length === want.length ? null : 'not every value is one of its options';
|
|
1402
|
+
}
|
|
1403
|
+
if (el.type === 'checkbox') {
|
|
1404
|
+
if (typeof v !== 'boolean') return 'a checkbox takes true or false';
|
|
1405
|
+
el.checked = v;
|
|
1406
|
+
return null;
|
|
1407
|
+
}
|
|
1408
|
+
if (el.type === 'radio') return 'a radio group is filled by the name its radios share';
|
|
1409
|
+
if (UNFILLABLE_TYPES.indexOf(el.type) >= 0)
|
|
1410
|
+
return 'this kind of control cannot be filled';
|
|
1411
|
+
if (typeof v !== 'string' && typeof v !== 'number') return 'a filter takes a string or a number';
|
|
1412
|
+
const s = String(v);
|
|
1413
|
+
el.value = s;
|
|
1414
|
+
return el.value === s ? null : 'the control does not accept it';
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// null when every key found its control and was accepted, otherwise the refusal in words.
|
|
1418
|
+
function _fillHeaderFilters(values) {
|
|
1419
|
+
const keys = Object.keys(values);
|
|
1420
|
+
if (!keys.length) return null;
|
|
1421
|
+
const header = document.querySelector('[data-dk-header]');
|
|
1422
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1423
|
+
const k = keys[i];
|
|
1424
|
+
const el = header ? header.querySelector('#' + CSS.escape(k)) : null;
|
|
1425
|
+
// A radio group is named, not identified: the key is the name the radios share.
|
|
1426
|
+
const group = header && !(el && el.type !== 'radio') ? _radioGroup(header, k) : [];
|
|
1427
|
+
if (group.length) {
|
|
1428
|
+
const v = values[k];
|
|
1429
|
+
if (v === null || v === undefined || v === '') return 'The filter "' + k + '" cannot take ' + _show(v) + ': there is no value.';
|
|
1430
|
+
const hit = (typeof v === 'string' || typeof v === 'number') ? group.find(function (r) { return r.value === String(v); }) : null;
|
|
1431
|
+
if (!hit) return 'The filter "' + k + '" cannot take ' + _show(v) + ': it is not one of its options.';
|
|
1432
|
+
hit.checked = true;
|
|
1433
|
+
group.forEach(function (r) { r.disabled = true; });
|
|
1434
|
+
continue;
|
|
1435
|
+
}
|
|
1436
|
+
if (!el || !/^(INPUT|SELECT|TEXTAREA)$/.test(el.tagName)) return 'The dashboard has no filter "' + k + '".';
|
|
1437
|
+
const why = _writeControl(el, values[k]);
|
|
1438
|
+
if (why) return 'The filter "' + k + '" cannot take ' + _show(values[k]) + ': ' + why + '.';
|
|
1439
|
+
el.disabled = true;
|
|
1440
|
+
}
|
|
1441
|
+
return null;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
function _refuseFilters(message) {
|
|
1445
|
+
_filtersRefused = true;
|
|
1446
|
+
const wait = document.getElementById('dk-wait');
|
|
1447
|
+
if (wait) {
|
|
1448
|
+
wait.hidden = false;
|
|
1449
|
+
wait.textContent = message;
|
|
1450
|
+
wait.style.color = 'var(--err)';
|
|
1451
|
+
wait.style.fontStyle = 'normal';
|
|
1452
|
+
}
|
|
1453
|
+
window.parent.postMessage({ type: 'DK_FILTERS_REFUSED', message: message }, '*');
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1067
1456
|
// ── Tab state machine ─────────────────────────────────────────────────────────
|
|
1068
1457
|
function _buildTabNav() {
|
|
1069
1458
|
const nav = document.getElementById('dk-tabs');
|
|
@@ -1145,6 +1534,9 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1145
1534
|
_sectionErrors[sec.id] = 0;
|
|
1146
1535
|
setSectionState(panel, 'loading');
|
|
1147
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() };
|
|
1148
1540
|
try {
|
|
1149
1541
|
await sec.load({
|
|
1150
1542
|
runQuery,
|
|
@@ -1153,11 +1545,11 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1153
1545
|
formatInteger: fmtInt,
|
|
1154
1546
|
formatDate: fmtDate,
|
|
1155
1547
|
formatDatetime: fmtDatetime,
|
|
1156
|
-
renderTable,
|
|
1157
|
-
renderKpiCard,
|
|
1158
|
-
renderKpiStrip,
|
|
1159
|
-
renderInfoGrid,
|
|
1160
|
-
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); },
|
|
1161
1553
|
escHtml: esc,
|
|
1162
1554
|
colorClass,
|
|
1163
1555
|
filters: DashboardKit.filters,
|
|
@@ -1391,6 +1783,7 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1391
1783
|
if (state === 'loading') {
|
|
1392
1784
|
container.innerHTML =
|
|
1393
1785
|
'<div class="dk-loading"><span class="dk-spinner"></span>Loading…</div>';
|
|
1786
|
+
_schedulePoints();
|
|
1394
1787
|
} else if (state === 'error') {
|
|
1395
1788
|
// A caller can be the section panel itself or, from a dashboard's own
|
|
1396
1789
|
// load(), an arbitrary sub-container inside it — either way the nearest
|
|
@@ -1455,13 +1848,467 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1455
1848
|
return title ? '<div class="dk-toolbar"><span class="dk-table-title">' + esc(title) + '</span></div>' : '';
|
|
1456
1849
|
}
|
|
1457
1850
|
|
|
1851
|
+
// ── Drillthrough click points ────────────────────────────────────────────────────
|
|
1852
|
+
// A table column or a card a user can set a drillthrough on (docs/drillthrough-setup.md). Each render
|
|
1853
|
+
// call registers what it drew under its container's id, and the key is read from the call itself:
|
|
1854
|
+
// container id + column key, or container id + card label, each part encoded so that no id or key
|
|
1855
|
+
// can run into the other. A container without an id names nothing, so it registers nothing and gets
|
|
1856
|
+
// no button. A column key used twice in one table, or a label twice in one strip, names none of
|
|
1857
|
+
// them: a setup on one would silently apply to the other.
|
|
1858
|
+
// ctx is the section whose load() made the call: its id, and the header filters and the context
|
|
1859
|
+
// (period, time zone, hierarchy) as that load started.
|
|
1860
|
+
function _contextSnapshot() {
|
|
1861
|
+
return { dateFrom: _dateFromIso, dateTo: _dateToIso, timezone: _timezone, hierarchyId: _hierarchyId };
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function _headerSnapshot() {
|
|
1865
|
+
try {
|
|
1866
|
+
// defaultValue is the control's value at the moment of the call.
|
|
1867
|
+
return _dashboardFilters().map(function (f) {
|
|
1868
|
+
return { id: f.id, label: f.label, value: f.defaultValue };
|
|
1869
|
+
});
|
|
1870
|
+
} catch (err) {
|
|
1871
|
+
console.error('[DashboardKit] could not read the header filters:', err);
|
|
1872
|
+
return [];
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
function _forgetPoints(container) {
|
|
1877
|
+
if (container.id) delete _pointsByContainer[container.id];
|
|
1878
|
+
_schedulePoints();
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// The host learns which points exist, and that this kit can set them up, from DK_POINTS: after the
|
|
1882
|
+
// renders of a moment have settled, and again whenever the list changes. A point it holds a setup
|
|
1883
|
+
// for that is not listed is not on screen.
|
|
1884
|
+
let _pointsSent = null;
|
|
1885
|
+
let _pointsQueued = false;
|
|
1886
|
+
|
|
1887
|
+
function _postPoints() {
|
|
1888
|
+
const list = [];
|
|
1889
|
+
Object.keys(_pointsByContainer).forEach(function (id) {
|
|
1890
|
+
// A section that draws again replaces its content, and the containers it held go with it.
|
|
1891
|
+
if (!_pointsByContainer[id].el.isConnected) {
|
|
1892
|
+
delete _pointsByContainer[id];
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
_pointsByContainer[id].points.forEach(function (p) {
|
|
1896
|
+
const item = { point: p.key, section: p.section, configurable: p.configurable };
|
|
1897
|
+
if (p.title) item.title = p.title;
|
|
1898
|
+
list.push(item);
|
|
1899
|
+
});
|
|
1900
|
+
});
|
|
1901
|
+
const json = JSON.stringify(list);
|
|
1902
|
+
if (json === _pointsSent) return;
|
|
1903
|
+
_pointsSent = json;
|
|
1904
|
+
window.parent.postMessage({ type: 'DK_POINTS', points: list }, '*');
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
function _schedulePoints() {
|
|
1908
|
+
if (_pointsQueued) return;
|
|
1909
|
+
_pointsQueued = true;
|
|
1910
|
+
Promise.resolve().then(function () {
|
|
1911
|
+
_pointsQueued = false;
|
|
1912
|
+
_postPoints();
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
// spec: { kind: 'column'|'card', names: [..one per element..], title?, columns?, row?, rowAt?, valueSelector? }
|
|
1917
|
+
// valueSelector (cards): the part of an element that is the value, the only part that is a link.
|
|
1918
|
+
// selector finds, inside the container, the elements the names belong to, in the same order.
|
|
1919
|
+
// rowAt(i) is the row a table shows at position i now, sorted or not.
|
|
1920
|
+
// A fault here must never cost a dashboard its table or its cards, so it only costs their points.
|
|
1921
|
+
function _registerPoints(container, selector, ctx, spec) {
|
|
1922
|
+
try {
|
|
1923
|
+
_registerPointsUnsafe(container, selector, ctx, spec);
|
|
1924
|
+
} catch (err) {
|
|
1925
|
+
console.error('[DashboardKit] could not register drillthrough points:', err);
|
|
1926
|
+
if (container.id) delete _pointsByContainer[container.id];
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
function _registerPointsUnsafe(container, selector, ctx, spec) {
|
|
1931
|
+
if (!container.id) return;
|
|
1932
|
+
const count = {};
|
|
1933
|
+
spec.names.forEach(function (n) { count[n] = (count[n] || 0) + 1; });
|
|
1934
|
+
const localFilters = ctx ? ctx.localFilters : _headerSnapshot();
|
|
1935
|
+
const context = ctx ? ctx.context : _contextSnapshot();
|
|
1936
|
+
// The container outlives its content, so one listener serves every render into it.
|
|
1937
|
+
if (!container.dataset.dkPoints) {
|
|
1938
|
+
container.dataset.dkPoints = '1';
|
|
1939
|
+
container.addEventListener('click', function (e) { _onPointClick(container, e); });
|
|
1940
|
+
}
|
|
1941
|
+
const ownCols = spec.kind === 'column' ? _ownClickColumns(container) : null;
|
|
1942
|
+
_pointsByContainer[container.id] = {
|
|
1943
|
+
el: container,
|
|
1944
|
+
kind: spec.kind,
|
|
1945
|
+
valueSelector: spec.valueSelector,
|
|
1946
|
+
rowAt: spec.rowAt,
|
|
1947
|
+
selector: selector,
|
|
1948
|
+
points: spec.names.map(function (name, i) {
|
|
1949
|
+
const unique = count[name] === 1;
|
|
1950
|
+
const ownClick = ownCols ? ownCols.has(i) : _cardHoldsOwnClick(container, selector, spec, i);
|
|
1951
|
+
const p = {
|
|
1952
|
+
key: encodeURIComponent(container.id) + '|' + encodeURIComponent(name),
|
|
1953
|
+
index: i,
|
|
1954
|
+
// unique: no other column or label of the container has this key, so a setup on it is about it alone.
|
|
1955
|
+
// configurable: it can be set up. Not when one of its cells or its value answers its own click: there
|
|
1956
|
+
// the kit would only be a second action on the same click, so it offers no button.
|
|
1957
|
+
unique: unique,
|
|
1958
|
+
ownClick: ownClick,
|
|
1959
|
+
configurable: unique && !ownClick,
|
|
1960
|
+
section: ctx ? ctx.id : '',
|
|
1961
|
+
localFilters: localFilters,
|
|
1962
|
+
context: context,
|
|
1963
|
+
};
|
|
1964
|
+
if (spec.title) p.title = spec.title;
|
|
1965
|
+
if (spec.columns) p.columns = spec.columns;
|
|
1966
|
+
if (spec.row) p.row = spec.row;
|
|
1967
|
+
return p;
|
|
1968
|
+
}),
|
|
1969
|
+
};
|
|
1970
|
+
_decoratePoints(container);
|
|
1971
|
+
_schedulePoints();
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
// The table cells that hold something answering a click by itself, in one pass over the container: a
|
|
1975
|
+
// table can have ten thousand rows, and asking every cell of every column was most of a render's time.
|
|
1976
|
+
function _ownClickCells(container) {
|
|
1977
|
+
const cells = new Set();
|
|
1978
|
+
container.querySelectorAll(OWN_CLICK).forEach(function (el) {
|
|
1979
|
+
const td = el.closest('td');
|
|
1980
|
+
if (td) cells.add(td);
|
|
1981
|
+
});
|
|
1982
|
+
return cells;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
function _ownClickColumns(container) {
|
|
1986
|
+
const cols = new Set();
|
|
1987
|
+
_ownClickCells(container).forEach(function (td) { cols.add(td.cellIndex); });
|
|
1988
|
+
return cols;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
// Whether the value of card i holds an element that answers a click by itself.
|
|
1992
|
+
function _cardHoldsOwnClick(container, selector, spec, i) {
|
|
1993
|
+
const el = container.querySelectorAll(selector)[i];
|
|
1994
|
+
const value = el && el.querySelector(spec.valueSelector);
|
|
1995
|
+
return !!value && _hasOwnClick(value);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
function _pointSetup(p) {
|
|
1999
|
+
const msg = { type: 'DK_POINT_SETUP', point: p.key, section: p.section, localFilters: p.localFilters };
|
|
2000
|
+
['title', 'row', 'columns'].forEach(function (k) { if (p[k] !== undefined) msg[k] = p[k]; });
|
|
2001
|
+
try {
|
|
2002
|
+
window.parent.postMessage(msg, '*');
|
|
2003
|
+
} catch (err) {
|
|
2004
|
+
// The sample row held something postMessage cannot copy: send what JSON keeps of it, or none.
|
|
2005
|
+
if (msg.row !== undefined) {
|
|
2006
|
+
try { msg.row = JSON.parse(JSON.stringify(msg.row)); } catch { delete msg.row; }
|
|
2007
|
+
}
|
|
2008
|
+
window.parent.postMessage(msg, '*');
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// What answers a click by itself: a link, a button, a control, anything with an onclick or a tab stop.
|
|
2013
|
+
// A cell or a card value that holds one is that element's: it is never made a drillthrough link, so two
|
|
2014
|
+
// actions never meet on one click. The kit cannot see a listener a dashboard adds with addEventListener
|
|
2015
|
+
// to a plain element, only these markers.
|
|
2016
|
+
const OWN_CLICK = 'a, button, input, select, textarea, label, summary, [role="button"], [onclick], [tabindex]:not([tabindex="-1"])';
|
|
2017
|
+
|
|
2018
|
+
function _hasOwnClick(el) {
|
|
2019
|
+
return el.matches(OWN_CLICK) || !!el.querySelector(OWN_CLICK);
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
function _drillActive() {
|
|
2023
|
+
return !!_dashboardsApi && _depth < MAX_DEPTH;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
// In setup mode every configurable point carries a button (filled when it already has a setup);
|
|
2027
|
+
// otherwise the points that have one look like links. The buttons live inside the elements the
|
|
2028
|
+
// render call drew; a table sorting rebuilds only its tbody, so the header ones stay, but its
|
|
2029
|
+
// cells are new and are marked again. A click on a button must not reach the header's sort handler.
|
|
2030
|
+
function _decoratePoints(container) {
|
|
2031
|
+
container.querySelectorAll('.dk-pt-btn').forEach(function (b) { b.remove(); });
|
|
2032
|
+
container.querySelectorAll('.dk-od-cell, .dk-od-value').forEach(function (n) {
|
|
2033
|
+
n.classList.remove('dk-od-cell', 'dk-od-value', 'dk-od-keep');
|
|
2034
|
+
});
|
|
2035
|
+
const reg = container.id && _pointsByContainer[container.id];
|
|
2036
|
+
if (!reg) return;
|
|
2037
|
+
const els = container.querySelectorAll(reg.selector);
|
|
2038
|
+
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
|
|
2039
|
+
let ownCells = null;
|
|
2040
|
+
reg.points.forEach(function (p) {
|
|
2041
|
+
const has = !!_drillPoints[p.key];
|
|
2042
|
+
if (_setupMode) {
|
|
2043
|
+
const el = els[p.index];
|
|
2044
|
+
if (!p.configurable) return;
|
|
2045
|
+
if (!el) return;
|
|
2046
|
+
const btn = document.createElement('button');
|
|
2047
|
+
btn.type = 'button';
|
|
2048
|
+
btn.className = 'dk-pt-btn' + (has ? ' dk-pt-on' : '');
|
|
2049
|
+
btn.innerHTML = LINK_ICON;
|
|
2050
|
+
btn.title = 'Set up a drillthrough';
|
|
2051
|
+
btn.setAttribute('aria-label', 'Set up a drillthrough');
|
|
2052
|
+
btn.addEventListener('click', function (e) {
|
|
2053
|
+
e.preventDefault();
|
|
2054
|
+
e.stopPropagation();
|
|
2055
|
+
_pointSetup(p);
|
|
2056
|
+
});
|
|
2057
|
+
// A column holds its button beside the header label; a card beside its value, the part that becomes the link.
|
|
2058
|
+
const host = reg.kind === 'column'
|
|
2059
|
+
? el.querySelector('.dk-th-inner') || el
|
|
2060
|
+
: el.querySelector(reg.valueSelector) || el;
|
|
2061
|
+
// An info row's sub line sits inside its value: the button goes before it, on the value's line.
|
|
2062
|
+
host.insertBefore(btn, host.querySelector(':scope > .dk-sub'));
|
|
2063
|
+
} else if (has && p.unique && _drillActive()) {
|
|
2064
|
+
if (reg.kind === 'column') {
|
|
2065
|
+
if (!rowEls) {
|
|
2066
|
+
rowEls = container.querySelectorAll('tbody tr[data-dk-row]');
|
|
2067
|
+
ownCells = _ownClickCells(container);
|
|
2068
|
+
}
|
|
2069
|
+
rowEls.forEach(function (tr) {
|
|
2070
|
+
const td = tr.children[p.index];
|
|
2071
|
+
if (td && !ownCells.has(td)) td.classList.add('dk-od-cell');
|
|
2072
|
+
});
|
|
2073
|
+
} else {
|
|
2074
|
+
const value = els[p.index] && els[p.index].querySelector(reg.valueSelector);
|
|
2075
|
+
if (value && !_hasOwnClick(value)) {
|
|
2076
|
+
// More than its own class means a colorClass: keep that colour.
|
|
2077
|
+
const keepsColour = value.classList.length > 1;
|
|
2078
|
+
value.classList.add('dk-od-value');
|
|
2079
|
+
if (keepsColour) value.classList.add('dk-od-keep');
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
// The link icon (Lucide "link", ISC): it follows the button's colour and needs no font, unlike a glyph.
|
|
2087
|
+
const LINK_ICON = '<svg viewBox="0 0 24 24" width="10" height="10" fill="none" stroke="currentColor" stroke-width="2.6" ' +
|
|
2088
|
+
'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"/>' +
|
|
2089
|
+
'<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>';
|
|
2090
|
+
|
|
2091
|
+
function _refreshPoints() {
|
|
2092
|
+
Object.keys(_pointsByContainer).forEach(function (id) {
|
|
2093
|
+
const el = document.getElementById(id);
|
|
2094
|
+
if (el) _decoratePoints(el);
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
function _setSetupMode(on) {
|
|
2099
|
+
_setupMode = on;
|
|
2100
|
+
document.documentElement.dataset.dkSetup = on ? 'true' : 'false';
|
|
2101
|
+
_refreshPoints();
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
// ── Drillthrough: the setup the host sends, and the click ────────────────────────
|
|
2105
|
+
// drillPoints: [{ point, dashboardId, pass: { "<B filter id>": { from: 'row'|'filter', name } |
|
|
2106
|
+
// { from: 'value', value } } }]. The kit reads them as sent; the host alone keeps them.
|
|
2107
|
+
const MAX_DEPTH = 3;
|
|
2108
|
+
|
|
2109
|
+
function _setDrillPoints(list) {
|
|
2110
|
+
const next = {};
|
|
2111
|
+
if (!Array.isArray(list)) {
|
|
2112
|
+
console.error('[DashboardKit] drillPoints ignored: it must be an array');
|
|
2113
|
+
} else {
|
|
2114
|
+
list.forEach(function (s, i) {
|
|
2115
|
+
if (!s || typeof s !== 'object' || typeof s.point !== 'string' ||
|
|
2116
|
+
!Number.isInteger(s.dashboardId) || s.dashboardId <= 0 ||
|
|
2117
|
+
!s.pass || typeof s.pass !== 'object' || Array.isArray(s.pass)) {
|
|
2118
|
+
console.error('[DashboardKit] drillPoints[' + i + '] ignored: it must be { point, dashboardId, pass }');
|
|
2119
|
+
return;
|
|
2120
|
+
}
|
|
2121
|
+
next[s.point] = { dashboardId: s.dashboardId, pass: s.pass };
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
_drillPoints = next;
|
|
2125
|
+
if (Object.keys(next).length && !_dashboardsApi)
|
|
2126
|
+
console.warn('[DashboardKit] drillPoints were sent without dashboardsApi: the cells stay plain text');
|
|
2127
|
+
_refreshPoints();
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
function _onPointClick(container, e) {
|
|
2131
|
+
const reg = _pointsByContainer[container.id];
|
|
2132
|
+
if (_setupMode || !reg || !_drillActive()) return;
|
|
2133
|
+
// A click something else has handled, or that landed on an element with a click of its own, is not ours.
|
|
2134
|
+
if (e.defaultPrevented || e.target.closest(OWN_CLICK)) return;
|
|
2135
|
+
let index;
|
|
2136
|
+
let row;
|
|
2137
|
+
if (reg.kind === 'column') {
|
|
2138
|
+
const td = e.target.closest('td');
|
|
2139
|
+
const tr = td && td.closest('tr[data-dk-row]');
|
|
2140
|
+
if (!tr || !container.contains(tr) || !td.classList.contains('dk-od-cell')) return;
|
|
2141
|
+
index = td.cellIndex;
|
|
2142
|
+
row = reg.rowAt(+tr.dataset.dkRow);
|
|
2143
|
+
} else {
|
|
2144
|
+
const cards = Array.from(container.querySelectorAll(reg.selector));
|
|
2145
|
+
index = cards.findIndex(function (el) { return el.contains(e.target); });
|
|
2146
|
+
const value = cards[index] && cards[index].querySelector(reg.valueSelector);
|
|
2147
|
+
if (!value || !value.classList.contains('dk-od-value') || !value.contains(e.target)) return;
|
|
2148
|
+
}
|
|
2149
|
+
const p = reg.points[index];
|
|
2150
|
+
const setup = p && p.unique && _drillPoints[p.key];
|
|
2151
|
+
if (setup) _openDashboard(setup, row, p, e.target);
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
// B's filters from the setup, the clicked row and A's header filters as the section loaded.
|
|
2155
|
+
// A row without the key the setup names, or a filter A does not have, stops the click: B must never
|
|
2156
|
+
// open unfiltered on a link that was meant to narrow it.
|
|
2157
|
+
function _drillValues(pass, row, localFilters) {
|
|
2158
|
+
const out = {};
|
|
2159
|
+
Object.keys(pass).forEach(function (id) {
|
|
2160
|
+
if (CONTEXT_KEYS.indexOf(id) >= 0) throw new Error('The setup passes "' + id + '", which the host owns.');
|
|
2161
|
+
const src = pass[id];
|
|
2162
|
+
if (!src || typeof src !== 'object') throw new Error('The setup gives "' + id + '" no source.');
|
|
2163
|
+
let v;
|
|
2164
|
+
if (src.from === 'row') {
|
|
2165
|
+
v = row ? row[src.name] : undefined;
|
|
2166
|
+
if (v === null || v === undefined || v === '')
|
|
2167
|
+
throw new Error('The clicked row has no "' + src.name + '" to give "' + id + '".');
|
|
2168
|
+
} else if (src.from === 'filter') {
|
|
2169
|
+
const f = localFilters.find(function (x) { return x.id === src.name; });
|
|
2170
|
+
if (!f) throw new Error('The dashboard has no filter "' + src.name + '" to give "' + id + '".');
|
|
2171
|
+
v = f.value;
|
|
2172
|
+
// A filter nobody has filled in is not narrowing anything: B keeps its own default, the same
|
|
2173
|
+
// wide view the page shows. (A row without its key is different: that would open B on nobody.)
|
|
2174
|
+
if (v === null || v === undefined || v === '' || (Array.isArray(v) && !v.length)) return;
|
|
2175
|
+
} else if (src.from === 'value') {
|
|
2176
|
+
v = src.value;
|
|
2177
|
+
} else {
|
|
2178
|
+
throw new Error('The setup gives "' + id + '" a source that is none of row, filter or value.');
|
|
2179
|
+
}
|
|
2180
|
+
out[id] = v;
|
|
2181
|
+
});
|
|
2182
|
+
return out;
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
// The dashboards service answers with keys, not sentences; the reader gets sentences.
|
|
2186
|
+
function _dashboardProblem(status, body) {
|
|
2187
|
+
const m = body && body.message;
|
|
2188
|
+
const key = (m && m.key) || (typeof m === 'string' ? m : '') || (body && typeof body.error === 'string' ? body.error : '');
|
|
2189
|
+
if (key === 'document_not_found') return 'There is no such dashboard.';
|
|
2190
|
+
if (key === 'permission_denied' || status === 403) return 'This dashboard is not available to you.';
|
|
2191
|
+
if (status === 401) return 'Your session has expired. Reload and sign in again.';
|
|
2192
|
+
return 'The dashboard could not be opened (HTTP ' + status + ').';
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
async function _fetchDashboard(id) {
|
|
2196
|
+
const headers = { 'x-access-token': _authToken };
|
|
2197
|
+
if (_dashboardsPermissionKey) headers['x-permission-key'] = _dashboardsPermissionKey;
|
|
2198
|
+
let res;
|
|
2199
|
+
try {
|
|
2200
|
+
res = await fetch(_dashboardsApi + '/getCustomDashboard?id=' + encodeURIComponent(id), { headers: headers });
|
|
2201
|
+
} catch {
|
|
2202
|
+
throw new Error('The dashboards service could not be reached.');
|
|
2203
|
+
}
|
|
2204
|
+
let body = null;
|
|
2205
|
+
try { body = await res.json(); } catch { /* not JSON: the status says what it can */ }
|
|
2206
|
+
if (!res.ok || !body || body.success === false) throw new Error(_dashboardProblem(res.status, body));
|
|
2207
|
+
const doc = body.result;
|
|
2208
|
+
if (!doc || typeof doc.html !== 'string' || !doc.html) throw new Error('The dashboard has no document.');
|
|
2209
|
+
return doc;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
function _closePopup() {
|
|
2213
|
+
const p = _popup;
|
|
2214
|
+
if (!p) return;
|
|
2215
|
+
_popup = null;
|
|
2216
|
+
p.el.remove();
|
|
2217
|
+
document.body.style.overflow = p.overflow;
|
|
2218
|
+
if (p.trigger && p.trigger.isConnected && p.trigger.focus) p.trigger.focus();
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
function _showPopup(trigger) {
|
|
2222
|
+
_closePopup();
|
|
2223
|
+
const el = document.createElement('div');
|
|
2224
|
+
el.className = 'dk-od';
|
|
2225
|
+
el.setAttribute('role', 'dialog');
|
|
2226
|
+
el.setAttribute('aria-modal', 'true');
|
|
2227
|
+
el.innerHTML =
|
|
2228
|
+
'<div class="dk-od-box"><div class="dk-od-head"><span class="dk-od-title"></span>' +
|
|
2229
|
+
'<button type="button" class="dk-od-close">Close</button></div><div class="dk-od-body"></div></div>';
|
|
2230
|
+
document.body.appendChild(el);
|
|
2231
|
+
const p = {
|
|
2232
|
+
el: el,
|
|
2233
|
+
trigger: trigger,
|
|
2234
|
+
overflow: document.body.style.overflow,
|
|
2235
|
+
title: el.querySelector('.dk-od-title'),
|
|
2236
|
+
body: el.querySelector('.dk-od-body'),
|
|
2237
|
+
};
|
|
2238
|
+
p.title.textContent = 'Opening dashboard…';
|
|
2239
|
+
document.body.style.overflow = 'hidden';
|
|
2240
|
+
el.addEventListener('mousedown', function (e) { if (e.target === el) _closePopup(); });
|
|
2241
|
+
const close = el.querySelector('.dk-od-close');
|
|
2242
|
+
close.addEventListener('click', _closePopup);
|
|
2243
|
+
close.focus();
|
|
2244
|
+
_popup = p;
|
|
2245
|
+
return p;
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
// A key pressed inside the frame of an opened dashboard never reaches the dashboard that opened
|
|
2249
|
+
// it, so that one asks: Esc closes the innermost popup, and with none of its own it is passed up.
|
|
2250
|
+
document.addEventListener('keydown', function (e) {
|
|
2251
|
+
if (e.key !== 'Escape') return;
|
|
2252
|
+
if (_popup) _closePopup();
|
|
2253
|
+
else if (_depth > 0) window.parent.postMessage({ type: 'DK_CLOSE_REQUEST' }, '*');
|
|
2254
|
+
});
|
|
2255
|
+
|
|
2256
|
+
// The link was made by a user, not a model: no "Ask AI to fix" here, only what went wrong.
|
|
2257
|
+
function _popupError(p, message) {
|
|
2258
|
+
if (_popup !== p) return;
|
|
2259
|
+
const box = document.createElement('div');
|
|
2260
|
+
box.className = 'dk-error';
|
|
2261
|
+
box.textContent = message;
|
|
2262
|
+
p.body.textContent = '';
|
|
2263
|
+
p.body.appendChild(box);
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
async function _openDashboard(setup, row, point, trigger) {
|
|
2267
|
+
const p = _showPopup(trigger);
|
|
2268
|
+
try {
|
|
2269
|
+
const values = _drillValues(setup.pass, row, point.localFilters);
|
|
2270
|
+
const doc = await _fetchDashboard(setup.dashboardId);
|
|
2271
|
+
if (_popup !== p) return;
|
|
2272
|
+
p.title.textContent = doc.name || 'Dashboard';
|
|
2273
|
+
|
|
2274
|
+
// What the host sent this dashboard, with this dashboard's own values. B gets its own setup
|
|
2275
|
+
// and one level more depth; at MAX_DEPTH it gets none and its cells stay plain text.
|
|
2276
|
+
const message = {
|
|
2277
|
+
type: 'CUSTOM_DASHBOARDS_PARAMS',
|
|
2278
|
+
token: _authToken,
|
|
2279
|
+
endpoint: _endpoint,
|
|
2280
|
+
filters: Object.assign({}, point.context, values),
|
|
2281
|
+
dashboardsApi: _dashboardsApi,
|
|
2282
|
+
depth: _depth + 1,
|
|
2283
|
+
};
|
|
2284
|
+
if (_dashboardsPermissionKey) message.dashboardsPermissionKey = _dashboardsPermissionKey;
|
|
2285
|
+
if (Array.isArray(doc.drillThroughInfo)) message.drillPoints = doc.drillThroughInfo;
|
|
2286
|
+
const theme = document.documentElement.dataset.theme;
|
|
2287
|
+
if (theme === 'light' || theme === 'dark') message.theme = theme;
|
|
2288
|
+
|
|
2289
|
+
const frame = document.createElement('iframe');
|
|
2290
|
+
frame.title = doc.name || 'Dashboard';
|
|
2291
|
+
frame.setAttribute('sandbox', 'allow-scripts allow-downloads');
|
|
2292
|
+
frame.addEventListener('load', function () {
|
|
2293
|
+
if (_popup === p) frame.contentWindow.postMessage(message, '*');
|
|
2294
|
+
});
|
|
2295
|
+
frame.srcdoc = doc.html;
|
|
2296
|
+
p.frame = frame;
|
|
2297
|
+
p.body.textContent = '';
|
|
2298
|
+
p.body.appendChild(frame);
|
|
2299
|
+
} catch (err) {
|
|
2300
|
+
_popupError(p, (err && err.message) || String(err));
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
|
|
1458
2304
|
// ── renderTable ───────────────────────────────────────────────────────────────
|
|
1459
2305
|
// columns: [{ key, label, format?, sortable?, tooltip? }]
|
|
1460
2306
|
// format receives (value, row) — read row.<key> for per-row currency, etc.
|
|
1461
2307
|
// totalsRow: [label|{key,agg}] matching columns length — optional
|
|
1462
2308
|
// title: table heading; also the CSV filename — omit to hide title + CSV button
|
|
1463
|
-
function renderTable(containerOrSelector, rows, options) {
|
|
2309
|
+
function renderTable(containerOrSelector, rows, options, _ctx) {
|
|
1464
2310
|
const container = resolveContainer('renderTable', containerOrSelector);
|
|
2311
|
+
_forgetPoints(container);
|
|
1465
2312
|
|
|
1466
2313
|
const { columns = [], totalsRow, title } = options || {};
|
|
1467
2314
|
|
|
@@ -1476,8 +2323,8 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1476
2323
|
// format returns a string (escaped) or an element.
|
|
1477
2324
|
function buildBodyRows(data) {
|
|
1478
2325
|
slots = _slots();
|
|
1479
|
-
return data.map(function (row) {
|
|
1480
|
-
return '<tr>' + columns.map(function (col) {
|
|
2326
|
+
return data.map(function (row, i) {
|
|
2327
|
+
return '<tr data-dk-row="' + i + '">' + columns.map(function (col) {
|
|
1481
2328
|
const raw = row[col.key];
|
|
1482
2329
|
const out = col.format ? col.format(raw, row) : raw;
|
|
1483
2330
|
if (col.format) _refuseHtmlString(out, 'renderTable: column "' + col.label + '" format');
|
|
@@ -1546,6 +2393,14 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1546
2393
|
container.innerHTML = html;
|
|
1547
2394
|
slots.apply(container);
|
|
1548
2395
|
if (totalsSlots) totalsSlots.apply(container);
|
|
2396
|
+
_registerPoints(container, 'thead th', _ctx, {
|
|
2397
|
+
kind: 'column',
|
|
2398
|
+
names: columns.map(function (c) { return c.key; }),
|
|
2399
|
+
title: title,
|
|
2400
|
+
columns: columns.map(function (c) { return { key: c.key, label: c.label }; }),
|
|
2401
|
+
row: rows[0],
|
|
2402
|
+
rowAt: function (i) { return sortedRows()[i]; },
|
|
2403
|
+
});
|
|
1549
2404
|
|
|
1550
2405
|
// Sort handler
|
|
1551
2406
|
const tblEl = container.querySelector('#' + tblId);
|
|
@@ -1560,6 +2415,7 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1560
2415
|
body.innerHTML = buildTotalsHtml() + rebuilt;
|
|
1561
2416
|
slots.apply(body);
|
|
1562
2417
|
if (totalsSlots) totalsSlots.apply(body);
|
|
2418
|
+
_decoratePoints(container);
|
|
1563
2419
|
tblEl.querySelectorAll('thead th[data-dk-sort-key]').forEach(function (h) {
|
|
1564
2420
|
h.classList.remove('dk-sort-asc', 'dk-sort-desc');
|
|
1565
2421
|
if (h.dataset.dkSortKey === sortKey) h.classList.add('dk-sort-' + sortDir);
|
|
@@ -1610,18 +2466,21 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1610
2466
|
'</div>';
|
|
1611
2467
|
}
|
|
1612
2468
|
|
|
1613
|
-
function renderKpiCard(containerOrSelector, item) {
|
|
2469
|
+
function renderKpiCard(containerOrSelector, item, _ctx) {
|
|
1614
2470
|
const container = resolveContainer('renderKpiCard', containerOrSelector);
|
|
2471
|
+
_forgetPoints(container);
|
|
1615
2472
|
_checkItems('renderKpiCard', [item]);
|
|
1616
2473
|
const slots = _slots();
|
|
1617
2474
|
container.innerHTML = _kpiCardHtml(item, slots);
|
|
1618
2475
|
slots.apply(container);
|
|
2476
|
+
_registerPoints(container, '.dk-kpi', _ctx, { kind: 'card', names: [item.label], valueSelector: '.dk-kpi-value' });
|
|
1619
2477
|
}
|
|
1620
2478
|
|
|
1621
2479
|
// ── renderKpiStrip ────────────────────────────────────────────────────────────
|
|
1622
2480
|
// options: { title? }
|
|
1623
|
-
function renderKpiStrip(containerOrSelector, items, options) {
|
|
2481
|
+
function renderKpiStrip(containerOrSelector, items, options, _ctx) {
|
|
1624
2482
|
const container = resolveContainer('renderKpiStrip', containerOrSelector);
|
|
2483
|
+
_forgetPoints(container);
|
|
1625
2484
|
const { title } = options || {};
|
|
1626
2485
|
if (!items || !items.length) {
|
|
1627
2486
|
container.innerHTML = _titleHtml(title) + EMPTY_HTML;
|
|
@@ -1635,13 +2494,20 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1635
2494
|
'</div>';
|
|
1636
2495
|
container.innerHTML = html;
|
|
1637
2496
|
slots.apply(container);
|
|
2497
|
+
_registerPoints(container, '.dk-kpi', _ctx, {
|
|
2498
|
+
kind: 'card',
|
|
2499
|
+
valueSelector: '.dk-kpi-value',
|
|
2500
|
+
names: items.map(function (i) { return i.label; }),
|
|
2501
|
+
title: title,
|
|
2502
|
+
});
|
|
1638
2503
|
}
|
|
1639
2504
|
|
|
1640
2505
|
// ── renderInfoGrid ────────────────────────────────────────────────────────────
|
|
1641
2506
|
// renders a responsive key/value grid
|
|
1642
2507
|
// options: { title? }
|
|
1643
|
-
function renderInfoGrid(containerOrSelector, items, options) {
|
|
2508
|
+
function renderInfoGrid(containerOrSelector, items, options, _ctx) {
|
|
1644
2509
|
const container = resolveContainer('renderInfoGrid', containerOrSelector);
|
|
2510
|
+
_forgetPoints(container);
|
|
1645
2511
|
const { title } = options || {};
|
|
1646
2512
|
if (!items || !items.length) {
|
|
1647
2513
|
container.innerHTML = _titleHtml(title) + EMPTY_HTML;
|
|
@@ -1661,13 +2527,20 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1661
2527
|
'</div>';
|
|
1662
2528
|
container.innerHTML = html;
|
|
1663
2529
|
slots.apply(container);
|
|
2530
|
+
_registerPoints(container, '.dk-info-row', _ctx, {
|
|
2531
|
+
kind: 'card',
|
|
2532
|
+
valueSelector: '.dk-val',
|
|
2533
|
+
names: items.map(function (i) { return i.label; }),
|
|
2534
|
+
title: title,
|
|
2535
|
+
});
|
|
1664
2536
|
}
|
|
1665
2537
|
|
|
1666
2538
|
// ── renderTotalsStrip ─────────────────────────────────────────────────────────
|
|
1667
2539
|
// renders a horizontal totals bar
|
|
1668
2540
|
// options: { title? }
|
|
1669
|
-
function renderTotalsStrip(containerOrSelector, items, options) {
|
|
2541
|
+
function renderTotalsStrip(containerOrSelector, items, options, _ctx) {
|
|
1670
2542
|
const container = resolveContainer('renderTotalsStrip', containerOrSelector);
|
|
2543
|
+
_forgetPoints(container);
|
|
1671
2544
|
const { title } = options || {};
|
|
1672
2545
|
if (!items || !items.length) {
|
|
1673
2546
|
container.innerHTML = _titleHtml(title) + EMPTY_HTML;
|
|
@@ -1688,6 +2561,12 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1688
2561
|
'</div>';
|
|
1689
2562
|
container.innerHTML = html;
|
|
1690
2563
|
slots.apply(container);
|
|
2564
|
+
_registerPoints(container, '.dk-field', _ctx, {
|
|
2565
|
+
kind: 'card',
|
|
2566
|
+
valueSelector: '.dk-field-value',
|
|
2567
|
+
names: items.map(function (i) { return i.label; }),
|
|
2568
|
+
title: title,
|
|
2569
|
+
});
|
|
1691
2570
|
}
|
|
1692
2571
|
|
|
1693
2572
|
// ── CSV download ──────────────────────────────────────────────────────────────
|
|
@@ -1695,7 +2574,15 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1695
2574
|
const rows = [];
|
|
1696
2575
|
tableEl.querySelectorAll('tr').forEach(function (tr) {
|
|
1697
2576
|
const cells = Array.from(tr.querySelectorAll('th, td')).map(function (td) {
|
|
1698
|
-
|
|
2577
|
+
let v = td.dataset.csvValue;
|
|
2578
|
+
if (v === undefined) {
|
|
2579
|
+
let cell = td;
|
|
2580
|
+
if (td.querySelector('.dk-pt-btn')) {
|
|
2581
|
+
cell = td.cloneNode(true);
|
|
2582
|
+
cell.querySelectorAll('.dk-pt-btn').forEach(function (b) { b.remove(); });
|
|
2583
|
+
}
|
|
2584
|
+
v = cell.textContent.trim();
|
|
2585
|
+
}
|
|
1699
2586
|
const safe = /^[=+\-@]/.test(String(v)) && !/^-\d/.test(String(v)) ? "'" + String(v) : String(v);
|
|
1700
2587
|
return '"' + safe.replace(/"/g, '""') + '"';
|
|
1701
2588
|
});
|
|
@@ -1722,6 +2609,11 @@ details.dk-call summary::-webkit-details-marker {
|
|
|
1722
2609
|
});
|
|
1723
2610
|
|
|
1724
2611
|
const clone = document.documentElement.cloneNode(true);
|
|
2612
|
+
clone.querySelectorAll('.dk-pt-btn, .dk-od').forEach(function (n) { n.remove(); });
|
|
2613
|
+
clone.querySelectorAll('.dk-od-cell, .dk-od-value').forEach(function (n) {
|
|
2614
|
+
n.classList.remove('dk-od-cell', 'dk-od-value', 'dk-od-keep');
|
|
2615
|
+
});
|
|
2616
|
+
clone.removeAttribute('data-dk-setup');
|
|
1725
2617
|
|
|
1726
2618
|
// A canvas clones blank — its pixels aren't part of the DOM — so each chart
|
|
1727
2619
|
// goes into the snapshot as an image of what it currently shows. The size
|