aboutsummaryrefslogtreecommitdiff
path: root/web/frontend/data-quality.ts
blob: 32c356339e0d32279f47151d489e88a028585a0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

function initDataQuality(): void {
  const form = document.getElementById("data-quality-form") as HTMLFormElement | null;
  const selectAll = document.getElementById("data-quality-select-all") as HTMLInputElement | null;
  const counter = document.getElementById("data-quality-selected");
  if (!form || !selectAll) return;
  const checkboxes = Array.from(form.querySelectorAll<HTMLInputElement>("input.data-quality-checkbox"));

  function updateCount(): void {
    const selected = checkboxes.filter((c) => c.checked).length;
    if (counter) counter.textContent = `${selected} selected`;
    const allChecked = selected === checkboxes.length && checkboxes.length > 0;
    const noneChecked = selected === 0;
    selectAll!.checked = allChecked;
    selectAll!.indeterminate = !allChecked && !noneChecked;
  }

  selectAll!.addEventListener("change", () => {
    for (const cb of checkboxes) cb.checked = selectAll!.checked;
    updateCount();
  });

  for (const cb of checkboxes) cb.addEventListener("change", updateCount);

  updateCount();
}

if (document.readyState === "loading") {
  document.addEventListener("DOMContentLoaded", initDataQuality);
} else {
  initDataQuality();
}