139 lines
5.7 KiB
JavaScript
139 lines
5.7 KiB
JavaScript
import { fetchData } from "./utils/ajaxUtils.js";
|
|
import { renderPieChart } from "./charts/pieChart.js";
|
|
import { renderBarChart } from "./charts/barChart.js";
|
|
import { renderHorizontalBarChart } from "./charts/horizontalBarChart.js";
|
|
import { renderWorstSuppliersChart } from "./charts/worstSuppliersChart.js";
|
|
import { renderProductBySupplierChart } from "./charts/productBySupplierChart.js";
|
|
import { renderAnalysisDistributionChart } from "./charts/analysisDistributionChart.js";
|
|
import { renderWorstTenAnalysisChart } from "./charts/worsttenanalysis.js";
|
|
import { renderAnalytesFailChart } from "./charts/analytesFailChart.js";
|
|
import { renderPhasePieChart } from "./charts/phasePieChart.js";
|
|
import { renderPhaseBarChart } from "./charts/phaseBarChart.js";
|
|
|
|
$(document).ready(function () {
|
|
function getFilters() {
|
|
return {
|
|
startDate: $("#startDate").val(),
|
|
endDate: $("#endDate").val(),
|
|
supplier: $("#supplierFilter").val(),
|
|
productsRefnumber: $("#productsRefnumber").val(),
|
|
productsSeason: $("#productsSeason").val(),
|
|
ageRange: $("#ageRange").val(),
|
|
reportsLabName: $("#reportsLabName").val(),
|
|
reportsTestType: $("#reportsTestType").val(),
|
|
reportsNumberLab: $("#reportsNumberLab").val(),
|
|
groupingField: $("#groupingField").val(),
|
|
};
|
|
}
|
|
|
|
function updateCharts() {
|
|
const filters = getFilters();
|
|
|
|
// Aggiorna il titolo dinamicamente
|
|
const groupingText = $("#groupingField option:selected").text();
|
|
$("#dynamicChartTitle").text(
|
|
`Rating Distribution by Group: ${groupingText}`,
|
|
);
|
|
|
|
fetchData("parsedatachart.php", filters).then((data) => {
|
|
if (data) {
|
|
console.log("Dati ricevuti dal backend:", data); // Aggiungi log qui
|
|
console.log("topFailingAnalysis:", data.topFailingAnalysis);
|
|
console.log("failedAnalytes:", data.failedAnalytes);
|
|
|
|
// Aggiorna le card
|
|
$("#totalProducts").text(data.totalProducts);
|
|
$("#totalReports").text(data.totalReports);
|
|
$("#failedReports").text(data.failedReports);
|
|
$("#failedReportsPercent").text(
|
|
`(${data.failedReportsPercent.toFixed(2)}%)`,
|
|
);
|
|
$("#totalTests").text(data.totalTests);
|
|
$("#failedTests").text(data.failedTests);
|
|
$("#failedTestsPercent").text(
|
|
`(${data.failedTestsPercent.toFixed(2)}%)`,
|
|
);
|
|
|
|
// Renderizza i grafici
|
|
renderPieChart(data, "reportPieChart", "tableChart2");
|
|
renderBarChart(data, "reportBarChart", "tableChart3");
|
|
renderHorizontalBarChart(
|
|
data.horizontalBarData,
|
|
"horizontalBarChart",
|
|
"tableHorizontalBarChart",
|
|
);
|
|
renderHorizontalBarChart(
|
|
data.horizontalBarAnalysisData,
|
|
"horizontalBarAnalysisChart",
|
|
"tableHorizontalBarAnalysisChart",
|
|
);
|
|
renderWorstSuppliersChart(
|
|
data.worstSuppliers,
|
|
"worstSuppliersChart",
|
|
"tableChartWorstSuppliers",
|
|
);
|
|
renderProductBySupplierChart(
|
|
data.productBySupplier,
|
|
"productBySupplierChart",
|
|
"tableChartProductsBySupplier",
|
|
);
|
|
renderAnalysisDistributionChart(
|
|
data.analysisDistribution,
|
|
"analysisDistributionChart",
|
|
"tableChartAnalysisDistribution",
|
|
);
|
|
renderWorstTenAnalysisChart(
|
|
data.topFailingAnalysis,
|
|
"worsttenanalysis",
|
|
"tableChartWorst",
|
|
);
|
|
renderAnalytesFailChart(
|
|
data.failedAnalytes,
|
|
"analytesFailChart",
|
|
"tableChartAnalytesFail",
|
|
);
|
|
renderPhasePieChart(
|
|
data.phaseData,
|
|
"phasePieChart",
|
|
"tableChartPhasePie",
|
|
);
|
|
renderPhaseBarChart(
|
|
data.phaseRatingsData,
|
|
"phaseBarChart",
|
|
"tableChartPhaseBar",
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
function setupEventListeners() {
|
|
$(
|
|
"#startDate, #endDate, #supplierFilter, #productsRefnumber, #productsSeason, #ageRange, #reportsLabName, #reportsTestType, #reportsNumberLab, #groupingField",
|
|
).on("change", updateCharts);
|
|
$("#clearFilters").on("click", () => {
|
|
$("#startDate").val("");
|
|
$("#endDate").val("");
|
|
$("#supplierFilter").val("").trigger("change");
|
|
$("#productsRefnumber").val("").trigger("change");
|
|
$("#productsSeason").val("").trigger("change");
|
|
$("#ageRange").val("").trigger("change");
|
|
$("#reportsLabName").val("").trigger("change");
|
|
$("#reportsTestType").val("").trigger("change");
|
|
$("#reportsNumberLab").val("").trigger("change");
|
|
updateCharts();
|
|
});
|
|
|
|
// Evento per togglare la tabella con delegazione
|
|
$(document).on("click", ".toggle-table", function () {
|
|
const target = $(this).data("target");
|
|
console.log("Toggle table clicked, target:", target);
|
|
setTimeout(() => {
|
|
$(target).toggleClass("hidden");
|
|
}, 200);
|
|
});
|
|
}
|
|
|
|
setupEventListeners();
|
|
updateCharts(); // Caricamento iniziale
|
|
});
|