Database-BI
view release on metacpan or search on metacpan
templates/web/en-us/dashboard.html.tt view on Meta::CPAN
'delta-panel': 'btn-delta', 'export-panel': 'btn-export-open' };
function biClosePanels(keep) {
BI_PANELS.forEach(function (id) {
var p = document.getElementById(id);
if (!p || p === keep || p.hidden) return;
p.hidden = true;
var b = BI_PANEL_OPENERS[id] && document.getElementById(BI_PANEL_OPENERS[id]);
if (b) b.disabled = false;
// An open Combine panel takes over file drops; a closed one gives them back.
if (id === 'combine-panel') {
window.__biDropLabel = null;
window.__biDropCallback = null;
}
});
}
// parseAccounting is defined at module scope (outside any IIFE) so it is
// accessible from all script blocks on this page -- the sort block uses it for
// numeric column detection, and the graph panel's isNumericVal delegates to it.
[% PROCESS "web/en/layouts/parse_accounting.html.tt" %]
// Returns a YYYYMMDD integer sort key for recognized date strings, else null.
// Handles YYYY-MM-DD (ISO) and M/D/YYYY or D/M/YYYY slash formats.
// monthFirst: true = M/D/YYYY, false = D/M/YYYY.
function biDateKey(s, monthFirst) {
var m;
m = s.match(/^(\d{4})-(\d{2})-(\d{2})$/);
if (m) return +m[1] * 10000 + +m[2] * 100 + +m[3];
m = s.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
if (m) {
var p1 = +m[1], p2 = +m[2], yr = +m[3];
return monthFirst ? yr * 10000 + p1 * 100 + p2
: yr * 10000 + p2 * 100 + p1;
}
return null;
}
// biValueComparator(values, asc) -> function (a, b)
// How a column of cell texts sorts: as dates when every non-empty value is
// one, else as numbers when every one is, else as text. The table's own sort
// and Print both use it, so a print is in the order the table shows.
function biValueComparator(values, asc) {
var nonEmpty = values.filter(function (v) { return v !== ''; });
// Detect date columns: every non-empty value must match a known date pattern.
var isDate = nonEmpty.length > 0 && nonEmpty.every(function (v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
});
var monthFirst = true;
if (isDate) {
// Auto-detect M/D/YYYY vs D/M/YYYY: scan for a value that disambiguates.
for (var di = 0; di < nonEmpty.length; di++) {
var dm = nonEmpty[di].match(/^(\d{1,2})\/(\d{1,2})\/\d{4}$/);
if (!dm) continue;
if (+dm[1] > 12) { monthFirst = false; break; }
if (+dm[2] > 12) { monthFirst = true; break; }
}
}
var numeric = !isDate && nonEmpty.length > 0 && nonEmpty.every(function (v) {
return !isNaN(parseAccounting(v));
});
return function (av, bv) {
var cmp;
if (isDate) {
var ak = biDateKey(av, monthFirst), bk = biDateKey(bv, monthFirst);
cmp = (ak === null ? -Infinity : ak) - (bk === null ? -Infinity : bk);
} else if (numeric) {
var an = parseAccounting(av), bn = parseAccounting(bv);
cmp = (isNaN(an) ? -Infinity : an) - (isNaN(bn) ? -Infinity : bn);
} else {
cmp = av.localeCompare(bv, undefined, { numeric: true, sensitivity: 'base' });
}
return asc ? cmp : -cmp;
};
}
// biViewParams() -> URLSearchParams
// The parameters that make this view, for a request that reads its rows
// (Export saves them, Print prints them). l= comes from the join form, since
// /view/<table> has none in its URL; the rest reflect the rendered view, so
// they are read from the URL. A new view parameter is added here.
function biViewParams() {
var params = new URLSearchParams();
var lInp = document.querySelector('#join-form input[name="l"]');
if (lInp) params.set('l', lInp.value);
var urlP = new URLSearchParams(location.search);
urlP.getAll('j').forEach(function (v) { params.append('j', v); });
if (urlP.get('jtype')) params.set('jtype', urlP.get('jtype'));
urlP.getAll('c').forEach(function (v) { params.append('c', v); });
urlP.getAll('f').forEach(function (v) { params.append('f', v); });
if (urlP.get('d')) params.set('d', '1');
if (urlP.get('srccol')) params.set('srccol', urlP.get('srccol'));
// A relative range travels as itself, so the rows are the ones this view is
// showing rather than the ones a frozen date pair would match.
if (urlP.get('range')) params.set('range', urlP.get('range'));
if (urlP.get('rcol')) params.set('rcol', urlP.get('rcol'));
// The time bucket an aggregated view was showing travels the same way, so
// the rows hold the bucket column the page drew rather than the raw
// timestamps behind it.
['span', 'tcol', 'as'].forEach(function (k) {
if (urlP.get(k)) params.set(k, urlP.get(k));
});
// A cross-row column is part of the view too, so the rows hold the column
// the table is showing rather than the rows it was worked out from. All
// three repeat (several columns, one order each), so they travel as lists.
// So is a lookup turned on or off for this view (lk=, nolk=).
['cs', 'order', 'by', 'lk', 'nolk'].forEach(function (k) {
urlP.getAll(k).forEach(function (v) { params.append(k, v); });
});
return params;
}
// Scan the rendered rows of a named column and return {min, max} ISO dates,
// or null when the column has no parseable date values.
// Used as an instant first estimate; /api/range supplies the full-dataset answer.
function biDateRangeDOM(colName) {
var tbl = document.getElementById('bi-table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return null;
var headers = Array.from(tbl.tHead.rows[0].cells);
var colIdx = -1;
for (var i = 0; i < headers.length; i++) {
if (headers[i].textContent.trim() === colName) { colIdx = i; break; }
}
if (colIdx < 0) return null;
var isoRE = /^(\d{4})-(\d{2})-(\d{2})$/;
var mdyRE = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
var dates = [];
Array.from(tbl.tBodies[0].rows).forEach(function (r) {
templates/web/en-us/dashboard.html.tt view on Meta::CPAN
// Switching type drops the bounds the other type set, which mean nothing in
// the new one; a box that already has its type is left alone, value and all.
function biRangeInputs(inputs, colType) {
var type = colType === 'numeric' ? 'number' : 'date';
inputs.forEach(function (inp, i) {
if (inp.type === type) return;
inp.value = '';
inp.removeAttribute('min');
inp.removeAttribute('max');
inp.type = type;
inp.placeholder = type === 'number' ? (i ? 'to' : 'from') : '';
inp.setAttribute('aria-label', (i ? 'To ' : 'From ') + (type === 'number' ? 'number' : 'date'));
});
}
// Set min/max on date inputs for colName: disable inputs while fetching the
// full-dataset range from /api/range so the calendar can't open with a
// page-only estimate; re-enable (with correct min/max) when the response
// arrives. Falls back to the DOM estimate on fetch error.
function biSetDateRange(colName, inputs) {
var domRange = biDateRangeDOM(colName);
var spec = (document.getElementById('dash-add-filter') || {}).dataset;
var lSpec = spec ? (spec.spec || '') : '';
var viewQs = spec ? (spec.rangeQs || '') : '';
if (!lSpec || !colName) {
biApplyRange(inputs, domRange);
return;
}
inputs.forEach(function (inp) { inp.disabled = true; inp.title = 'Loading date range\u2026'; });
fetch('/api/range?l=' + encodeURIComponent(lSpec) + '&col=' + encodeURIComponent(colName) + viewQs)
.then(function (r) { return r.ok ? r.json() : null; })
.then(function (d) {
biApplyRange(inputs, (d && d.min && d.max) ? d : domRange);
inputs.forEach(function (inp) { inp.disabled = false; inp.title = ''; });
})
.catch(function () {
biApplyRange(inputs, domRange);
inputs.forEach(function (inp) { inp.disabled = false; inp.title = ''; });
});
}
// Detect the data type of a named column by sampling the rendered table rows.
// Returns 'date', 'numeric', or 'string'.
function biDetectColType(colName) {
var tbl = document.getElementById('bi-table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return 'string';
var headers = Array.from(tbl.tHead.rows[0].cells);
var colIdx = -1;
for (var i = 0; i < headers.length; i++) {
if (headers[i].textContent.trim() === colName) { colIdx = i; break; }
}
if (colIdx < 0) return 'string';
var rows = Array.from(tbl.tBodies[0].rows).slice(0, 30);
var vals = rows.map(function (r) {
return r.cells[colIdx] ? r.cells[colIdx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return 'string';
var dateRE = /^\d{4}-\d{2}-\d{2}$|^\d{1,2}\/\d{1,2}\/\d{4}$|^\d{1,2}-[A-Za-z]{3}-\d{4}$/;
var dateCnt = vals.filter(function (v) { return dateRE.test(v); }).length;
if (dateCnt / vals.length >= 0.7) return 'date';
var numCnt = vals.filter(function (v) { return !isNaN(parseAccounting(v)); }).length;
if (numCnt / vals.length >= 0.7) return 'numeric';
return 'string';
}
(function () {
var table = document.getElementById('bi-table');
if (!table) return;
var chkTotals = document.getElementById('chk-totals');
// SEL = 1: the checkbox column we inject is always cell 0 in each row, so
// every data-column DOM cell index = headers-array index + SEL.
var SEL = 1;
// Inject the checkbox selector column into every existing row.
(function injectSelCol() {
var theadRow = table.querySelector('thead tr');
var selTh = document.createElement('th');
selTh.className = 'sel-th';
theadRow.insertBefore(selTh, theadRow.firstChild);
Array.from(table.querySelectorAll('tbody tr')).forEach(function (tr) {
var selTd = document.createElement('td');
selTd.className = 'sel-td';
var chk = document.createElement('input');
chk.type = 'checkbox';
chk.className = 'row-chk';
chk.title = 'Select this row';
selTd.appendChild(chk);
tr.insertBefore(selTd, tr.firstChild);
});
}());
var headers = Array.from(table.querySelectorAll('thead th:not(.sel-th)'));
var dragSrcIdx = null;
var sortColIdx = -1;
var sortAsc = true;
var STORE_KEY = 'bi:' + (table.dataset.table || '');
// --- Selection state ---
var selectedRows = new Set(); // Set of <tr> elements
var selectedCols = new Set(); // Set of header indices (into headers[])
var btnDel = document.getElementById('btn-delete-sel');
// --- Persistence ---
function loadState() {
try { return JSON.parse(localStorage.getItem(STORE_KEY)) || {}; }
catch (e) { return {}; }
}
function saveState() {
try {
localStorage.setItem(STORE_KEY, JSON.stringify({
columns: headers.map(function (h) { return h.textContent.trim(); }),
sortCol: sortColIdx >= 0 ? headers[sortColIdx].textContent.trim() : null,
sortAsc: sortAsc,
totals: chkTotals ? chkTotals.checked : false
}));
} catch (e) {}
}
// --- Totals row ---
// Builds (or rebuilds) a <tfoot> row with the sum of each all-numeric column.
// Non-numeric columns are left blank; the first non-numeric cell shows "Total".
// moveCol() operates on table.rows (which includes tfoot), so cell reordering
// keeps the totals aligned automatically without requiring a rebuild on drag.
function buildTotals() {
var tbody = table.tBodies[0];
var rows = Array.from(tbody.rows);
var tfoot = table.tFoot || table.createTFoot();
while (tfoot.firstChild) tfoot.removeChild(tfoot.firstChild);
var tr = tfoot.insertRow();
// Placeholder cell for the selector column
tr.insertCell().className = 'sel-td';
headers.forEach(function (h, i) {
var td = tr.insertCell();
var vals = rows.map(function (r) {
return r.cells[i + SEL] ? r.cells[i + SEL].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
var isDate = vals.length > 0 && vals.every(function (v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
});
var numeric = !isDate && vals.length > 0 && vals.every(function (v) {
return !isNaN(parseAccounting(v));
});
if (numeric) {
var sum = vals.reduce(function (acc, v) { return acc + parseAccounting(v); }, 0);
var hasDec = vals.some(function (v) { return /\.\d+/.test(v.replace(/[^0-9.]/g, '')); });
td.textContent = hasDec ? sum.toFixed(2) : String(Math.round(sum));
td.className = 'totals-sum';
}
// Re-apply col-selected highlight to tfoot cells when totals are rebuilt
if (selectedCols.has(i)) td.classList.add('col-selected');
});
}
function removeTotals() {
if (table.tFoot) table.deleteTFoot();
}
// --- Selection helpers ---
function updateDeleteBtn() {
if (!btnDel) return;
var rCount = selectedRows.size;
var cCount = selectedCols.size;
if (rCount + cCount === 0) {
btnDel.hidden = true;
return;
}
btnDel.hidden = false;
var parts = [];
if (rCount) parts.push(rCount + ' row' + (rCount > 1 ? 's' : ''));
if (cCount) parts.push(cCount + ' column' + (cCount > 1 ? 's' : ''));
btnDel.title = 'Remove ' + parts.join(' and ') + ' from this view';
}
function setColHighlight(idx, on) {
// Apply or remove col-selected class on body/foot cells only (not the header).
Array.from(table.querySelectorAll('tbody tr, tfoot tr')).forEach(function (row) {
var cell = row.cells[idx + SEL];
if (cell) on ? cell.classList.add('col-selected') : cell.classList.remove('col-selected');
});
}
function toggleColSel(idx) {
if (selectedCols.has(idx)) {
selectedCols.delete(idx);
setColHighlight(idx, false);
} else {
selectedCols.add(idx);
setColHighlight(idx, true);
}
updateDeleteBtn();
}
// The name a column is known by, for an announcement.
function columnName(idx) {
return headers[idx] ? headers[idx].textContent.trim() : '';
}
// A header is a control now, so what it does from the keyboard is said the
// same way the canvas grips say what they did. It is a live region rather
// than a title: a title is read on hover, which a keyboard reader is not
templates/web/en-us/dashboard.html.tt view on Meta::CPAN
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
panel.hidden = false;
btnOpen.disabled = true;
sameWidth();
check();
});
btnCancel.addEventListener('click', function () {
panel.hidden = true;
btnOpen.disabled = false;
selA.value = '';
selB.value = '';
check();
});
btnDo.addEventListener('click', function () {
if (btnDo.disabled) return;
var u = new URL(location.href);
u.searchParams.append('f', selA.value + ':differ:' + selB.value);
// The rows change, so the old page number may not exist any more.
u.searchParams.delete('page');
location.href = u.toString();
});
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Graph panel -- line chart of X vs Y using HTML::D3 / D3.js
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-graph');
var panel = document.getElementById('graph-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-graph');
var btnDo = document.getElementById('btn-do-graph');
var xSel = document.getElementById('graph-x-sel');
var ySel = document.getElementById('graph-y-sel');
var backInp = document.getElementById('graph-back-inp');
var back2Inp = document.getElementById('graph-back2-inp');
var back2LabelInp = document.getElementById('graph-back2-label-inp');
var graphForm = document.getElementById('graph-form');
function checkPlot() {
btnDo.disabled = !(xSel.value && ySel.value);
}
// Returns true if v looks like a date (excluded from numeric Y axis).
function isDateVal(v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
}
// Returns true if v is plottable as a number (mirrors the server's strip logic).
// Recognizes accounting negatives: (1,234.56) counts as a valid number.
function isNumericVal(v) {
if (v === '') return true;
return !isNaN(parseAccounting(v));
}
var yTextInput = document.getElementById('graph-y-text');
var yLabel = document.getElementById('graph-y-label');
// Rebuild the Y-axis select to show only columns whose non-empty values are
// all numeric (after stripping currency symbols etc.) and not date-shaped.
// Returns the number of numeric options added (excluding the placeholder).
function buildYSelect() {
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return 0;
var headers = Array.from(tbl.tHead.rows[0].cells);
var rows = Array.from(tbl.tBodies[0].rows);
var prev = ySel.value;
while (ySel.options.length > 1) ySel.remove(1);
headers.forEach(function (th, idx) {
var name = th.textContent.trim();
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return;
if (vals.every(isDateVal)) return;
if (!vals.every(isNumericVal)) return;
var opt = document.createElement('option');
opt.value = name; opt.textContent = name;
if (name === prev) opt.selected = true;
ySel.appendChild(opt);
});
return ySel.options.length - 1; // subtract placeholder
}
// Apply the single-column shortcut: hide the dropdown and show a read-only
// label when exactly one numeric column exists, so the user only picks X.
function applyYAutoSelect(numericCount) {
if (numericCount === 1) {
ySel.options[1].selected = true;
ySel.hidden = true;
if (yTextInput) { yTextInput.value = ySel.options[1].value; yTextInput.hidden = false; }
if (yLabel) { yLabel.textContent = 'Y axis (auto-selected)'; }
} else {
ySel.hidden = false;
if (yTextInput) yTextInput.hidden = true;
if (yLabel) yLabel.textContent = 'Y axis (vertical, must be numeric)';
}
}
// Check for numeric columns once on page load; gray out the button when
// none exist so the user knows immediately without opening the panel.
(function initGraphBtn() {
var n = buildYSelect();
applyYAutoSelect(n);
if (n === 0) {
btnOpen.disabled = true;
btnOpen.title = 'Line graphs need a numeric column';
}
}());
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
templates/web/en-us/dashboard.html.tt view on Meta::CPAN
inp.setAttribute('data-graph-dyn', '1');
graphForm.appendChild(inp);
});
xSel.addEventListener('change', checkPlot);
ySel.addEventListener('change', checkPlot);
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Pie chart panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-pie');
var panel = document.getElementById('pie-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-pie');
var btnDo = document.getElementById('btn-do-pie');
var catSel = document.getElementById('pie-cat-sel');
var valSel = document.getElementById('pie-val-sel');
var backInp = document.getElementById('pie-back-inp');
var back2Inp = document.getElementById('pie-back2-inp');
var back2LabelInp = document.getElementById('pie-back2-label-inp');
var pieForm = document.getElementById('pie-form');
function checkPie() {
btnDo.disabled = !(catSel.value && valSel.value);
}
// Rebuild the value select: Count option first (always), then numeric columns.
function buildPieValSelect() {
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return;
var headers = Array.from(tbl.tHead.rows[0].cells);
var rows = Array.from(tbl.tBodies[0].rows);
var prev = valSel.value;
while (valSel.options.length > 1) valSel.remove(1);
// Count option always appears first, bold to distinguish it from column names.
var countOpt = document.createElement('option');
countOpt.value = '__count__';
countOpt.textContent = 'Count (rows)';
countOpt.style.fontWeight = 'bold';
if (prev === '__count__') countOpt.selected = true;
valSel.appendChild(countOpt);
headers.forEach(function (th, idx) {
var name = th.textContent.trim();
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return;
// Exclude date-shaped columns.
if (vals.every(function (v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
})) return;
// Only show columns whose non-empty values are all numeric.
if (!vals.every(function (v) {
if (v === '') return true;
return !isNaN(parseAccounting(v));
})) return;
var opt = document.createElement('option');
opt.value = name; opt.textContent = name;
if (name === prev) opt.selected = true;
valSel.appendChild(opt);
});
}
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && pieForm) {
var pb = pieForm.getAttribute('data-parent-back') || '';
back2Inp.value = pb;
if (back2LabelInp) back2LabelInp.value = pb ? (pieForm.getAttribute('data-parent-back-label') || '') : '';
}
buildPieValSelect();
panel.hidden = !panel.hidden;
checkPie();
});
btnCancel && btnCancel.addEventListener('click', function () {
panel.hidden = true;
});
catSel.addEventListener('change', checkPie);
valSel.addEventListener('change', checkPie);
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Heatmap panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-heatmap');
var panel = document.getElementById('heatmap-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-heatmap');
var btnDo = document.getElementById('btn-do-heatmap');
var xSel = document.getElementById('heatmap-x-sel');
var ySel = document.getElementById('heatmap-y-sel');
var backInp = document.getElementById('heatmap-back-inp');
var back2Inp = document.getElementById('heatmap-back2-inp');
var back2LabelInp = document.getElementById('heatmap-back2-label-inp');
var heatmapForm = document.getElementById('heatmap-form');
// Rebuild val select to show only numeric columns (plus the Count placeholder).
function buildHeatmapValSelect() {
var valSel = document.getElementById('heatmap-val-sel');
if (!valSel) return;
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return;
var headers = Array.from(tbl.tHead.rows[0].cells);
var rows = Array.from(tbl.tBodies[0].rows);
var prev = valSel.value;
while (valSel.options.length > 1) valSel.remove(1);
headers.forEach(function (th, idx) {
var name = th.textContent.trim();
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return;
if (vals.every(function (v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
})) return;
if (!vals.every(function (v) { return !isNaN(parseAccounting(v)); })) return;
var opt = document.createElement('option');
opt.value = name; opt.textContent = name;
if (name === prev) opt.selected = true;
valSel.appendChild(opt);
});
}
function checkHeatmap() {
btnDo.disabled = !(xSel.value && ySel.value);
}
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && heatmapForm) {
var pb = heatmapForm.getAttribute('data-parent-back') || '';
back2Inp.value = pb;
if (back2LabelInp) back2LabelInp.value = pb ? (heatmapForm.getAttribute('data-parent-back-label') || '') : '';
}
buildHeatmapValSelect();
panel.hidden = !panel.hidden;
checkHeatmap();
});
btnCancel && btnCancel.addEventListener('click', function () {
panel.hidden = true;
});
xSel.addEventListener('change', checkHeatmap);
ySel.addEventListener('change', checkHeatmap);
}());
// Bar chart panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-bar');
var panel = document.getElementById('bar-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-bar');
var btnDo = document.getElementById('btn-do-bar');
var catSel = document.getElementById('bar-cat-sel');
var backInp = document.getElementById('bar-back-inp');
var back2Inp = document.getElementById('bar-back2-inp');
var back2LabelInp = document.getElementById('bar-back2-label-inp');
var barForm = document.getElementById('bar-form');
// Rebuild val select to show only numeric columns (plus the Count placeholder).
function buildBarValSelect() {
var valSel = document.getElementById('bar-val-sel');
if (!valSel) return;
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return;
var headers = Array.from(tbl.tHead.rows[0].cells);
var rows = Array.from(tbl.tBodies[0].rows);
var prev = valSel.value;
while (valSel.options.length > 1) valSel.remove(1);
headers.forEach(function (th, idx) {
var name = th.textContent.trim();
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return;
if (vals.every(function (v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
})) return;
if (!vals.every(function (v) { return !isNaN(parseAccounting(v)); })) return;
var opt = document.createElement('option');
opt.value = name; opt.textContent = name;
if (name === prev) opt.selected = true;
valSel.appendChild(opt);
});
}
function checkBar() {
btnDo.disabled = !catSel.value;
}
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && barForm) {
var pb = barForm.getAttribute('data-parent-back') || '';
back2Inp.value = pb;
if (back2LabelInp) back2LabelInp.value = pb ? (barForm.getAttribute('data-parent-back-label') || '') : '';
}
buildBarValSelect();
panel.hidden = !panel.hidden;
checkBar();
});
btnCancel && btnCancel.addEventListener('click', function () {
panel.hidden = true;
});
catSel.addEventListener('change', checkBar);
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Stacked bar chart panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-stacked');
var panel = document.getElementById('stacked-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-stacked');
var btnDo = document.getElementById('btn-do-stacked');
var catSel = document.getElementById('stacked-cat-sel');
var segSel = document.getElementById('stacked-seg-sel');
var backInp = document.getElementById('stacked-back-inp');
var back2Inp = document.getElementById('stacked-back2-inp');
var back2LabelInp = document.getElementById('stacked-back2-label-inp');
var stackedForm = document.getElementById('stacked-form');
function checkStacked() {
btnDo.disabled = !(catSel.value && segSel.value);
}
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && stackedForm) {
var pb = stackedForm.getAttribute('data-parent-back') || '';
templates/web/en-us/dashboard.html.tt view on Meta::CPAN
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Scatter plot panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-scatter');
var panel = document.getElementById('scatter-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-scatter');
var btnDo = document.getElementById('btn-do-scatter');
var xSel = document.getElementById('scatter-x-sel');
var ySel = document.getElementById('scatter-y-sel');
var yTextInput = document.getElementById('scatter-y-text');
var yLabel = document.getElementById('scatter-y-label');
var seriesSel = document.getElementById('scatter-series-sel');
var sizeSel = document.getElementById('scatter-size-sel');
var schemeSel = document.getElementById('scatter-scheme-sel');
var minRInp = document.getElementById('scatter-min-r');
var maxRInp = document.getElementById('scatter-max-r');
var backInp = document.getElementById('scatter-back-inp');
var back2Inp = document.getElementById('scatter-back2-inp');
var back2LabelInp = document.getElementById('scatter-back2-label-inp');
var scatterForm = document.getElementById('scatter-form');
function checkScatter() {
btnDo.disabled = !(xSel.value && ySel.value);
}
function updateScatterState() {
if (schemeSel) schemeSel.disabled = !(seriesSel && seriesSel.value);
var hasSize = sizeSel && sizeSel.value;
if (minRInp) minRInp.disabled = !hasSize;
if (maxRInp) maxRInp.disabled = !hasSize;
}
// Populate X, Y, and size selects with numeric-only columns.
function buildScatterSelects() {
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return;
var headers = Array.from(tbl.tHead.rows[0].cells);
var rows = Array.from(tbl.tBodies[0].rows);
var prevX = xSel.value;
var prevY = ySel.value;
var prevSize = sizeSel ? sizeSel.value : '';
[xSel, ySel].forEach(function (sel) {
while (sel.options.length > 1) sel.remove(1);
});
if (sizeSel) { while (sizeSel.options.length > 1) sizeSel.remove(1); }
headers.forEach(function (th, idx) {
var name = th.textContent.trim();
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return;
if (vals.every(function (v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
})) return;
if (!vals.every(function (v) { return v === '' || !isNaN(parseAccounting(v)); })) return;
var optX = document.createElement('option');
optX.value = name; optX.textContent = name;
if (name === prevX) optX.selected = true;
xSel.appendChild(optX);
var optY = document.createElement('option');
optY.value = name; optY.textContent = name;
if (name === prevY) optY.selected = true;
ySel.appendChild(optY);
if (sizeSel) {
var optS = document.createElement('option');
optS.value = name; optS.textContent = name;
if (name === prevSize) optS.selected = true;
sizeSel.appendChild(optS);
}
});
var n = ySel.options.length - 1;
if (n === 1 && yTextInput && yLabel) {
ySel.options[1].selected = true;
ySel.hidden = true;
yTextInput.value = ySel.options[1].value; yTextInput.hidden = false;
yLabel.textContent = 'Y axis (auto-selected)';
} else {
ySel.hidden = false;
if (yTextInput) yTextInput.hidden = true;
if (yLabel) yLabel.textContent = 'Y axis (vertical, numeric)';
}
if (n === 0) {
btnOpen.disabled = true;
btnOpen.title = 'Scatter plots need at least one numeric column';
}
updateScatterState();
return n;
}
(function initScatterBtn() {
var n = buildScatterSelects();
if (!n) {
btnOpen.disabled = true;
btnOpen.title = 'Scatter plots need numeric columns';
}
}());
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && scatterForm) {
var pb = scatterForm.getAttribute('data-parent-back') || '';
back2Inp.value = pb;
if (back2LabelInp) back2LabelInp.value = pb ? (scatterForm.getAttribute('data-parent-back-label') || '') : '';
}
buildScatterSelects();
panel.hidden = !panel.hidden;
checkScatter();
});
btnCancel && btnCancel.addEventListener('click', function () {
panel.hidden = true;
});
xSel.addEventListener('change', checkScatter);
ySel.addEventListener('change', checkScatter);
seriesSel && seriesSel.addEventListener('change', updateScatterState);
sizeSel && sizeSel.addEventListener('change', updateScatterState);
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Combo bar+line chart panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-combo');
var panel = document.getElementById('combo-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-combo');
var btnDo = document.getElementById('btn-do-combo');
var xSel = document.getElementById('combo-x-sel');
var barSel = document.getElementById('combo-bar-sel');
var lineSel = document.getElementById('combo-line-sel');
var backInp = document.getElementById('combo-back-inp');
var back2Inp = document.getElementById('combo-back2-inp');
var back2LabelInp = document.getElementById('combo-back2-label-inp');
var comboForm = document.getElementById('combo-form');
function checkCombo() {
btnDo.disabled = !(xSel.value && barSel.value && lineSel.value);
}
function buildComboNumericSelects() {
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return;
var headers = Array.from(tbl.tHead.rows[0].cells);
var rows = Array.from(tbl.tBodies[0].rows);
var prevBar = barSel.value;
var prevLine = lineSel.value;
[barSel, lineSel].forEach(function (sel) {
while (sel.options.length > 1) sel.remove(1);
});
headers.forEach(function (th, idx) {
var name = th.textContent.trim();
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return;
if (vals.every(function (v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
})) return;
if (!vals.every(function (v) { return v === '' || !isNaN(parseAccounting(v)); })) return;
var optBar = document.createElement('option');
optBar.value = name; optBar.textContent = name;
if (name === prevBar) optBar.selected = true;
barSel.appendChild(optBar);
var optLine = document.createElement('option');
optLine.value = name; optLine.textContent = name;
if (name === prevLine) optLine.selected = true;
lineSel.appendChild(optLine);
});
}
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && comboForm) {
var pb = comboForm.getAttribute('data-parent-back') || '';
back2Inp.value = pb;
if (back2LabelInp) back2LabelInp.value = pb ? (comboForm.getAttribute('data-parent-back-label') || '') : '';
}
buildComboNumericSelects();
panel.hidden = !panel.hidden;
checkCombo();
});
btnCancel && btnCancel.addEventListener('click', function () {
panel.hidden = true;
});
xSel.addEventListener('change', checkCombo);
barSel.addEventListener('change', checkCombo);
lineSel.addEventListener('change', checkCombo);
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Treemap panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-treemap');
var panel = document.getElementById('treemap-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-treemap');
var btnDo = document.getElementById('btn-do-treemap');
var catSel = document.getElementById('treemap-cat-sel');
var backInp = document.getElementById('treemap-back-inp');
var back2Inp = document.getElementById('treemap-back2-inp');
var back2LabelInp = document.getElementById('treemap-back2-label-inp');
var treemapForm = document.getElementById('treemap-form');
function checkTreemap() {
btnDo.disabled = !catSel.value;
}
// How the color is folded and its scale mean nothing without a color
// column, and a disabled field is not sent.
var colorSel = document.getElementById('treemap-color-sel');
var colorAggSel = document.getElementById('treemap-color-agg-sel');
templates/web/en-us/dashboard.html.tt view on Meta::CPAN
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && treemapForm) {
var pb = treemapForm.getAttribute('data-parent-back') || '';
back2Inp.value = pb;
if (back2LabelInp) back2LabelInp.value = pb ? (treemapForm.getAttribute('data-parent-back-label') || '') : '';
}
panel.hidden = !panel.hidden;
checkTreemap();
});
btnCancel && btnCancel.addEventListener('click', function () {
panel.hidden = true;
});
catSel.addEventListener('change', checkTreemap);
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Histogram panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-histogram');
var panel = document.getElementById('histogram-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-histogram');
var btnDo = document.getElementById('btn-do-histogram');
var colSel = document.getElementById('histogram-col-sel');
var backInp = document.getElementById('histogram-back-inp');
var back2Inp = document.getElementById('histogram-back2-inp');
var back2LabelInp = document.getElementById('histogram-back2-label-inp');
var histogramForm = document.getElementById('histogram-form');
function checkHistogram() {
btnDo.disabled = !colSel.value;
}
// Populate col select with numeric-only columns.
function buildHistogramColSelect() {
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return;
var headers = Array.from(tbl.tHead.rows[0].cells);
var rows = Array.from(tbl.tBodies[0].rows);
var prev = colSel.value;
while (colSel.options.length > 1) colSel.remove(1);
headers.forEach(function (th, idx) {
var name = th.textContent.trim();
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return;
if (vals.every(function (v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
})) return;
if (!vals.every(function (v) { return v === '' || !isNaN(parseAccounting(v)); })) return;
var opt = document.createElement('option');
opt.value = name; opt.textContent = name;
if (name === prev) opt.selected = true;
colSel.appendChild(opt);
});
var n = colSel.options.length - 1;
if (n === 0) {
btnOpen.disabled = true;
btnOpen.title = 'Histogram needs a numeric column';
}
return n;
}
(function initHistogramBtn() {
var n = buildHistogramColSelect();
if (!n) {
btnOpen.disabled = true;
btnOpen.title = 'Histogram needs a numeric column';
}
}());
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && histogramForm) {
var pb = histogramForm.getAttribute('data-parent-back') || '';
back2Inp.value = pb;
if (back2LabelInp) back2LabelInp.value = pb ? (histogramForm.getAttribute('data-parent-back-label') || '') : '';
}
buildHistogramColSelect();
panel.hidden = !panel.hidden;
checkHistogram();
});
btnCancel && btnCancel.addEventListener('click', function () {
panel.hidden = true;
});
colSel.addEventListener('change', checkHistogram);
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Word cloud panel
// ---------------------------------------------------------------------------
(function () {
var btnOpen = document.getElementById('btn-wordcloud');
var panel = document.getElementById('wordcloud-panel');
if (!btnOpen || !panel) return;
var btnCancel = document.getElementById('btn-cancel-wordcloud');
var btnDo = document.getElementById('btn-do-wordcloud');
var colSel = document.getElementById('wordcloud-col-sel');
var backInp = document.getElementById('wordcloud-back-inp');
var back2Inp = document.getElementById('wordcloud-back2-inp');
var back2LabelInp = document.getElementById('wordcloud-back2-label-inp');
var cloudForm = document.getElementById('wordcloud-form');
function checkWordCloud() {
btnDo.disabled = !colSel.value;
}
function isDate(v) {
return /^\d{4}-\d{2}-\d{2}$/.test(v) || /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(v);
}
// A cloud of a number column would be a cloud of "1", "2" and "3", so only
// columns that hold something to read are offered: not all-number and not
// all-date, and at least one value with a character that is not a digit or
// punctuation.
function buildWordCloudColSelect() {
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return;
var headers = Array.from(tbl.tHead.rows[0].cells);
var rows = Array.from(tbl.tBodies[0].rows);
var prev = colSel.value;
while (colSel.options.length > 1) colSel.remove(1);
headers.forEach(function (th, idx) {
var name = th.textContent.trim();
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
if (vals.length === 0) return;
if (vals.every(function (v) { return !isNaN(parseAccounting(v)); })) return;
if (vals.every(isDate)) return;
if (!vals.some(function (v) { return /[^\d\s.,%$()+\-]/.test(v); })) return;
var opt = document.createElement('option');
opt.value = name; opt.textContent = name;
if (name === prev) opt.selected = true;
colSel.appendChild(opt);
});
var n = colSel.options.length - 1;
if (n === 0) {
btnOpen.disabled = true;
btnOpen.title = 'Word cloud needs a text column';
}
return n;
}
(function initWordCloudBtn() {
var n = buildWordCloudColSelect();
if (!n) {
btnOpen.disabled = true;
btnOpen.title = 'Word cloud needs a text column';
}
}());
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
backInp.value = window.location.href;
if (back2Inp && cloudForm) {
var pb = cloudForm.getAttribute('data-parent-back') || '';
back2Inp.value = pb;
if (back2LabelInp) back2LabelInp.value = pb ? (cloudForm.getAttribute('data-parent-back-label') || '') : '';
}
buildWordCloudColSelect();
panel.hidden = !panel.hidden;
checkWordCloud();
});
btnCancel && btnCancel.addEventListener('click', function () {
panel.hidden = true;
});
colSel.addEventListener('change', checkWordCloud);
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Cross-row columns panel
// ---------------------------------------------------------------------------
//
// The reader picks a number column, a function, a name and the order the rows
// are read in; the script composes the one cs= spec the URL takes and submits
// the view with it. The columns already computed stay in the form as hidden
// inputs, so adding a second one adds to the view rather than replacing it.
(function () {
var btnOpen = document.getElementById('btn-cross-row');
var panel = document.getElementById('cross-row-panel');
if (!btnOpen || !panel) return;
var form = document.getElementById('cross-row-form');
var btnDo = document.getElementById('btn-do-cross-row');
var btnCancel = document.getElementById('btn-cancel-cross-row');
var colSel = document.getElementById('cross-row-col-sel');
var fnSel = document.getElementById('cross-row-fn-sel');
var winField = document.getElementById('cross-row-window-field');
var winInp = document.getElementById('cross-row-window-inp');
var aliasInp = document.getElementById('cross-row-alias-inp');
var orderSel = document.getElementById('cross-row-order-sel');
var dirSel = document.getElementById('cross-row-dir-sel');
var bySel = document.getElementById('cross-row-by-sel');
var aliasTouched = false;
function fnMeta() {
var opt = fnSel.options[fnSel.selectedIndex];
return {
arg: !!opt && opt.getAttribute('data-arg') === '1',
order: !!opt && opt.getAttribute('data-order') === '1'
};
}
// A column name has to be usable in an expression and in a URL, and the
// column it comes from may hold anything at all ("Unit price ($)"), so the
// suggestion is reduced to letters, digits and underscores.
function slug(text) {
var s = String(text || '').toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '');
if (!s) return 'value';
if (/^[0-9]/.test(s)) s = 'c_' + s;
return s;
}
function check() {
var m = fnMeta();
winField.hidden = !m.arg;
winInp.required = m.arg;
if (!aliasTouched) aliasInp.value = colSel.value ? slug(colSel.value + '_' + fnSel.value) : '';
var ok = !!colSel.value
&& /^[A-Za-z_][A-Za-z0-9_]*$/.test(aliasInp.value)
&& (!m.arg || parseInt(winInp.value, 10) > 0)
&& (!m.order || !!orderSel.value);
btnDo.disabled = !ok;
btnDo.title = ok ? '' : 'Choose a number column, a function and a column name';
}
// The pass reads numbers, so a column of names is offered but off. The
// options are rendered by the server, which is what the panel has without
// this script; the table decides which of them can be read.
function markNumericColumns() {
var tbl = document.querySelector('table[data-table]') || document.querySelector('table');
if (!tbl || !tbl.tHead || !tbl.tBodies[0]) return;
var headers = Array.from(tbl.tHead.rows[0].cells).map(function (th) { return th.textContent.trim(); });
var rows = Array.from(tbl.tBodies[0].rows);
var numeric = {};
headers.forEach(function (name, idx) {
if (!name) return;
var vals = rows.map(function (r) {
return r.cells[idx] ? r.cells[idx].textContent.trim() : '';
}).filter(function (v) { return v !== ''; });
numeric[name] = vals.length > 0 && vals.every(function (v) {
return !isNaN(parseAccounting(v));
});
});
Array.from(colSel.options).forEach(function (opt) {
if (opt.value) opt.disabled = !numeric[opt.value];
});
}
// The panel edits parameters of the view it is open on, so its controls start
// where the view already is: the partition and the read order it is using.
// A partition of several columns has no matching option, so it is shown as a
// value of its own rather than silently replaced by the first column.
function initFromView() {
var currentBy = bySel.getAttribute('data-current') || '';
if (currentBy) {
var known = Array.from(bySel.options).some(function (o) { return o.value === currentBy; });
if (!known) {
var extra = document.createElement('option');
extra.value = currentBy;
extra.textContent = currentBy + ' (current)';
bySel.appendChild(extra);
}
bySel.value = currentBy;
}
var currentOrder = orderSel.getAttribute('data-current') || '';
if (currentOrder) {
var parts = currentOrder.split(':');
var column = parts[0] || '';
var matches = Array.from(orderSel.options).some(function (o) { return o.value === column; });
// Same reason as by=: a view can be ordered by a column that is not in
// this list -- a calculated one, say -- and reopening the panel must not
// quietly reorder it.
if (!matches && column) {
var ord = document.createElement('option');
ord.value = column;
ord.textContent = column + ' (current)';
orderSel.appendChild(ord);
matches = true;
}
if (matches) {
orderSel.value = column;
dirSel.value = (parts[1] === 'desc') ? 'desc' : 'asc';
}
}
}
function addHidden(name, val) {
var inp = document.createElement('input');
inp.type = 'hidden';
inp.name = name;
inp.value = val;
inp.setAttribute('data-cross-row-dyn', '1');
form.appendChild(inp);
}
btnOpen.addEventListener('click', function () {
biClosePanels(panel);
panel.hidden = !panel.hidden;
if (!panel.hidden) {
markNumericColumns();
templates/web/en-us/dashboard.html.tt view on Meta::CPAN
// Tell the overlay what label to show based on current UI state.
window.__biDropLabel = function () {
return (panel && !panel.hidden)
? 'Drop to set as join database'
: 'Drop to open database';
};
// Called by the overlay after a successful upload.
window.__biDropCallback = function (data) {
if (panel && !panel.hidden && data.path && rightPathInp) {
// Join panel is open: populate the path field and trigger column fetch.
rightPathInp.value = data.path;
if (rightTblSel) rightTblSel.value = '';
rightPathInp.dispatchEvent(new Event('input', { bubbles: true }));
} else if (data.url) {
// Panel is closed (or no path returned): navigate to the opened file.
window.location = data.url;
}
};
}());
</script>
<script nonce="[% csp_nonce | html %]">
// ---------------------------------------------------------------------------
// Row highlight: applied when ?hl_col=, ?hl_op=, ?hl_val= are present in the
// URL. Used by the insights drill-down so the specific outlier row stands out
// within the category group (which may be 75+ rows).
// hl_op must be one of: gt ge lt le eq (default gt)
// ---------------------------------------------------------------------------
(function () {
var params = new URLSearchParams(window.location.search);
var hlCol = params.get('hl_col');
var hlOp = params.get('hl_op') || 'gt';
var hlVal = params.get('hl_val');
if (!hlCol || hlVal === null) return;
var table = document.querySelector('table[data-table]');
if (!table || !table.tHead || !table.tBodies[0]) return;
// Locate the column index by scanning the current header row (which includes
// the injected sel-th at index 0 -- but that cell has no text, so it won't
// match any column name). Using the found index directly on row.cells is
// correct because both the header and body are shifted identically.
var headers = Array.from(table.tHead.rows[0].cells);
var colIdx = -1;
for (var i = 0; i < headers.length; i++) {
if (headers[i].textContent.trim() === hlCol) { colIdx = i; break; }
}
if (colIdx < 0) return;
var refNum = parseFloat(hlVal);
var firstHl = null;
Array.from(table.tBodies[0].rows).forEach(function (row) {
var cell = row.cells[colIdx];
if (!cell) return;
var raw = cell.textContent.trim();
var cellNum = parseAccounting(raw);
var match;
if (isNaN(cellNum) || isNaN(refNum)) {
match = (hlOp === 'eq' && raw === hlVal);
} else {
if (hlOp === 'gt') match = cellNum > refNum;
else if (hlOp === 'ge') match = cellNum >= refNum;
else if (hlOp === 'lt') match = cellNum < refNum;
else if (hlOp === 'le') match = cellNum <= refNum;
else match = Math.abs(cellNum - refNum) < 1e-9;
}
if (match) {
row.classList.add('hl-row');
if (!firstHl) firstHl = row;
}
});
if (firstHl) {
firstHl.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}());
</script>
[%- IF file_path -%]
<div id="bi-open-meta"
data-name="[% title | html %]"
data-path="[% file_path | html %]"
hidden></div>
<script nonce="[% csp_nonce | html %]">
(function () {
try {
var u = new URL(location.href);
var fromSaved = u.searchParams.get('from') === 'saved';
// Remove the from= marker from the address bar so the URL stays clean.
if (fromSaved) {
u.searchParams.delete('from');
history.replaceState(null, '', u.toString());
}
// Files opened from the "recently saved" list are not also tracked as
// "recently opened" -- they already have their own section on the home page.
if (!fromSaved) {
var el = document.getElementById('bi-open-meta');
// For drag-and-drop uploads the server stores the file under a random
// .uploads/<tempdir>/ path. Prefer the original local path stashed by
// the drop handler in sessionStorage (from text/uri-list). Fall back to
// the upload path when the browser does not supply a file:// URI -- an
// imperfect but functional link is better than a missing entry.
var filePath = el.dataset.path;
var fileHref = '/open?path=' + encodeURIComponent(filePath);
if (/[/\\]\.uploads[/\\]/.test(filePath)) {
// Drag-and-drop uploads land under a random .uploads/ temp path.
// Only add to recently opened when the drop handler stashed the
// original file:// URI in sessionStorage (from text/uri-list).
// If that stash is absent (Firefox, email attachment, etc.) there
// is no stable path to record, so skip the entry entirely rather
// than adding a useless .uploads/ link.
var origPath = null;
try {
origPath = sessionStorage.getItem('bi:pending-original-path');
sessionStorage.removeItem('bi:pending-original-path');
} catch (ex) {}
if (!origPath) { return; }
filePath = origPath;
( run in 1.138 second using v1.01-cache-2.11-cpan-60884a8df76 )