diff --git a/src/imgtests/reporting/excel_export.py b/src/imgtests/reporting/excel_export.py index 16b71072..1bca4f57 100644 --- a/src/imgtests/reporting/excel_export.py +++ b/src/imgtests/reporting/excel_export.py @@ -238,7 +238,7 @@ def configuration_id_from_os( ) -> int | str: distribution_name = distribution_name_from_os(os_name) - if not distribution_name: + if not distribution_name or distribution_name not in distributions: return "" return int(distributions[distribution_name]["configuration_id"]) @@ -268,23 +268,13 @@ def build_distribution_records( msg = f"Unsupported distributions: {joined_distributions}. Available: {valid_names}." raise ValueError(msg) - missing_distributions = [ - distribution_name - for distribution_name in DISTRIBUTION_DESCRIPTIONS - if distribution_name not in ids - ] - - if missing_distributions: - joined_distributions = ", ".join(missing_distributions) - msg = f"Missing configuration ids for distributions: {joined_distributions}." - raise ValueError(msg) - return { distribution_name: DistributionRecord( configuration_id=ids[distribution_name], - distribution_description=distribution_description, + distribution_description=DISTRIBUTION_DESCRIPTIONS[distribution_name], ) - for distribution_name, distribution_description in DISTRIBUTION_DESCRIPTIONS.items() + for distribution_name in ids + if distribution_name in DISTRIBUTION_DESCRIPTIONS } diff --git a/src/imgtests/web/static/js/excel_reports.js b/src/imgtests/web/static/js/excel_reports.js index 8e70bda8..cd7f0237 100644 --- a/src/imgtests/web/static/js/excel_reports.js +++ b/src/imgtests/web/static/js/excel_reports.js @@ -15,8 +15,26 @@ function getCookie(name) { return cookieValue; } +function getCheckedValues(selector) { + return Array.from(document.querySelectorAll(selector)) + .filter((cb) => cb.checked) + .map((cb) => cb.value); +} + document.getElementById("exportBtn").addEventListener("click", function () { const btn = this; + const tables = getCheckedValues(".table-checkbox"); + const distributions = getCheckedValues(".distro-checkbox"); + + if (tables.length === 0) { + alert("Please select at least one table."); + return; + } + if (distributions.length === 0) { + alert("Please select at least one distribution."); + return; + } + btn.disabled = true; btn.textContent = "Generating..."; @@ -26,6 +44,7 @@ document.getElementById("exportBtn").addEventListener("click", function () { "X-CSRFToken": getCookie("csrftoken"), "Content-Type": "application/json", }, + body: JSON.stringify({ tables: tables, distributions: distributions }), }) .then((response) => response.json()) .then((data) => { @@ -35,12 +54,12 @@ document.getElementById("exportBtn").addEventListener("click", function () { } else { alert("Error: " + data.error); btn.disabled = false; - btn.textContent = "Export to Excel"; + btn.textContent = "Generate New Excel Report"; } }) .catch((error) => { alert("Error: " + error); btn.disabled = false; - btn.textContent = "Export to Excel"; + btn.textContent = "Generate New Excel Report"; }); }); diff --git a/src/imgtests/web/tests_interface/templates/tests_interface/excel_reports.html b/src/imgtests/web/tests_interface/templates/tests_interface/excel_reports.html index 7ee7d0de..24943364 100644 --- a/src/imgtests/web/tests_interface/templates/tests_interface/excel_reports.html +++ b/src/imgtests/web/tests_interface/templates/tests_interface/excel_reports.html @@ -11,7 +11,29 @@