Refactor report templates and styles
- Updated CSS styles in report.css for improved readability and consistency. - Removed deprecated report_class.html and report_group.html files. - Introduced new Jinja2 templates: report_class.jinja and report_group.jinja for better maintainability. - Enhanced JavaScript functionality in report_class.js to support dynamic chart rendering using Chart.js. - Updated report_group.js to streamline print functionality.
This commit is contained in:
+153
-58
@@ -1,73 +1,168 @@
|
||||
(function () {
|
||||
function qs(selector, root) {
|
||||
return (root || document).querySelector(selector);
|
||||
}
|
||||
const chartStore = new Map();
|
||||
|
||||
function qsa(selector, root) {
|
||||
return Array.from((root || document).querySelectorAll(selector));
|
||||
}
|
||||
function qs(selector, root) {
|
||||
return (root || document).querySelector(selector);
|
||||
}
|
||||
|
||||
function setActiveSection(sectionId) {
|
||||
qsa('.section-nav .nav-btn[data-section]').forEach((btn) => {
|
||||
btn.classList.toggle('active', btn.dataset.section === sectionId);
|
||||
});
|
||||
function qsa(selector, root) {
|
||||
return Array.from((root || document).querySelectorAll(selector));
|
||||
}
|
||||
|
||||
qsa('.class-nav-group').forEach((group) => {
|
||||
group.classList.toggle('active', group.dataset.section === sectionId);
|
||||
});
|
||||
function buildChartForClass(classId, report) {
|
||||
if (!classId || chartStore.has(classId) || typeof Chart === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
const firstButton = qs(`.class-nav-group.active .class-btn[data-class-id]`);
|
||||
if (firstButton) {
|
||||
setActiveClass(firstButton.dataset.classId, false);
|
||||
}
|
||||
}
|
||||
const sections = Array.isArray(report.sections) ? report.sections : [];
|
||||
const entry = sections
|
||||
.flatMap((section) => section.entries || [])
|
||||
.find((item) => item.id === classId);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
function setActiveClass(classId, scrollIntoView) {
|
||||
qsa('.class-btn[data-class-id]').forEach((btn) => {
|
||||
btn.classList.toggle('active', btn.dataset.classId === classId);
|
||||
});
|
||||
const canvas = qs(`.week-chart[data-chart-for="${classId}"]`);
|
||||
if (!canvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
qsa('.class-block[data-class-id]').forEach((block) => {
|
||||
const active = block.dataset.classId === classId;
|
||||
block.classList.toggle('active', active);
|
||||
if (active && scrollIntoView) {
|
||||
block.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
});
|
||||
}
|
||||
const chartData = entry.chart_data || {};
|
||||
const labels = Array.isArray(chartData.labels) ? chartData.labels : [];
|
||||
const missed = Array.isArray(chartData.missed) ? chartData.missed : [];
|
||||
const other = Array.isArray(chartData.other) ? chartData.other : [];
|
||||
const conducted = Array.isArray(chartData.conducted)
|
||||
? chartData.conducted
|
||||
: [];
|
||||
|
||||
function init() {
|
||||
const report = window.__CLASS_REPORT__ || {};
|
||||
const activeSection = report.active_section || '';
|
||||
const activeClass = report.active_class || '';
|
||||
if (!labels.length) {
|
||||
const container = canvas.parentElement;
|
||||
if (container) {
|
||||
container.innerHTML = "<div class='muted'>Нет данных.</div>";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
qsa('.section-nav .nav-btn[data-section]').forEach((btn) => {
|
||||
btn.addEventListener('click', () => setActiveSection(btn.dataset.section));
|
||||
});
|
||||
const chart = new Chart(canvas, {
|
||||
type: "bar",
|
||||
data: {
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: "Пропущено",
|
||||
data: missed,
|
||||
backgroundColor: "#ef4444",
|
||||
stack: "pairs",
|
||||
borderRadius: 4,
|
||||
},
|
||||
{
|
||||
label: "Иное",
|
||||
data: other,
|
||||
backgroundColor: "#f59e0b",
|
||||
stack: "pairs",
|
||||
borderRadius: 4,
|
||||
},
|
||||
{
|
||||
label: "Проведено",
|
||||
data: conducted,
|
||||
backgroundColor: "#22c55e",
|
||||
stack: "pairs",
|
||||
borderRadius: 4,
|
||||
},
|
||||
],
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
interaction: {
|
||||
mode: "index",
|
||||
intersect: false,
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
stacked: true,
|
||||
grid: {
|
||||
display: false,
|
||||
},
|
||||
},
|
||||
y: {
|
||||
stacked: true,
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
precision: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
qsa('.class-btn[data-class-id]').forEach((btn) => {
|
||||
btn.addEventListener('click', () => setActiveClass(btn.dataset.classId, true));
|
||||
});
|
||||
chartStore.set(classId, chart);
|
||||
}
|
||||
|
||||
if (activeSection) {
|
||||
setActiveSection(activeSection);
|
||||
}
|
||||
function setActiveSection(sectionId, report) {
|
||||
qsa(".section-nav .nav-btn[data-section]").forEach((btn) => {
|
||||
btn.classList.toggle("active", btn.dataset.section === sectionId);
|
||||
});
|
||||
|
||||
if (activeClass) {
|
||||
setActiveClass(activeClass, false);
|
||||
}
|
||||
}
|
||||
qsa(".class-nav-group").forEach((group) => {
|
||||
group.classList.toggle("active", group.dataset.section === sectionId);
|
||||
});
|
||||
|
||||
window.printReport = function printReport() {
|
||||
window.print();
|
||||
};
|
||||
const firstButton = qs(`.class-nav-group.active .class-btn[data-class-id]`);
|
||||
if (firstButton) {
|
||||
setActiveClass(firstButton.dataset.classId, false, report);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
function setActiveClass(classId, scrollIntoView, report) {
|
||||
qsa(".class-btn[data-class-id]").forEach((btn) => {
|
||||
btn.classList.toggle("active", btn.dataset.classId === classId);
|
||||
});
|
||||
|
||||
qsa(".class-block[data-class-id]").forEach((block) => {
|
||||
const active = block.dataset.classId === classId;
|
||||
block.classList.toggle("active", active);
|
||||
if (active && scrollIntoView) {
|
||||
block.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
}
|
||||
});
|
||||
|
||||
buildChartForClass(classId, report);
|
||||
}
|
||||
|
||||
function init() {
|
||||
const report = window.__CLASS_REPORT__ || {};
|
||||
const activeSection = report.active_section || "";
|
||||
const activeClass = report.active_class || "";
|
||||
|
||||
qsa(".section-nav .nav-btn[data-section]").forEach((btn) => {
|
||||
btn.addEventListener("click", () =>
|
||||
setActiveSection(btn.dataset.section, report),
|
||||
);
|
||||
});
|
||||
|
||||
qsa(".class-btn[data-class-id]").forEach((btn) => {
|
||||
btn.addEventListener("click", () =>
|
||||
setActiveClass(btn.dataset.classId, true, report),
|
||||
);
|
||||
});
|
||||
|
||||
if (activeSection) {
|
||||
setActiveSection(activeSection, report);
|
||||
}
|
||||
|
||||
if (activeClass) {
|
||||
setActiveClass(activeClass, false, report);
|
||||
}
|
||||
}
|
||||
|
||||
window.printReport = function printReport() {
|
||||
window.print();
|
||||
};
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
function printReport() {
|
||||
window.print();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user