Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-06-22 18:20:08 +04:00
parent 74edbde327
commit fcd8edbc5d
14 changed files with 7572 additions and 145 deletions
+20
View File
File diff suppressed because one or more lines are too long
+117 -11
View File
@@ -223,6 +223,43 @@ body {
color: var(--muted);
font-size: 13px;
}
.class-note.desc {
color: var(--text);
font-size: 12px;
opacity: 0.75;
}
.class-note.warning {
color: #b45309;
background: #fffbeb;
border: 1px solid #fde68a;
border-radius: 6px;
padding: 6px 10px;
margin-top: 8px;
font-size: 13px;
}
.class-legend {
display: flex;
gap: 16px;
margin-top: 8px;
font-size: 12px;
}
.legend-item {
padding: 2px 8px;
border-radius: 4px;
}
.legend-conducted {
background: #dcfce7;
color: #166534;
}
.legend-missed {
background: #fef2f2;
color: #991b1b;
}
.legend-other {
background: #fffbeb;
color: #92400e;
}
.class-chart {
position: relative;
@@ -235,26 +272,21 @@ body {
height: 320px;
}
.class-table,
.scheme-table,
.table {
width: 100%;
border-collapse: collapse;
}
.class-table th,
.class-table td,
.scheme-table th,
.scheme-table td,
.table th,
.table td {
border-bottom: 1px solid var(--line);
padding: 10px 12px;
vertical-align: top;
text-align: left;
}
.class-table th,
.scheme-table th,
.table th {
font-size: 13px;
@@ -285,7 +317,7 @@ body {
.scheme-table th,
.scheme-table td {
padding: 6px;
padding: 3px 4px;
text-align: center;
}
@@ -294,16 +326,64 @@ body {
text-align: left;
white-space: nowrap;
}
.lesson-num {
font-size: 11px;
color: var(--muted);
font-weight: 400;
padding: 2px 6px !important;
}
.scheme-cell {
display: inline-block;
width: 18px;
height: 18px;
width: 14px;
height: 14px;
border-radius: 4px;
background: var(--empty);
border: 1px solid rgba(0, 0, 0, 0.06);
}
.class-weeks {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
}
.week-block {
border: 1px solid var(--line);
border-radius: 8px;
padding: 8px 10px;
}
.week-header {
font-weight: 600;
font-size: 13px;
margin-bottom: 4px;
}
.week-stats {
display: flex;
gap: 12px;
flex-wrap: wrap;
margin-bottom: 6px;
font-size: 12px;
}
.stat {
padding: 1px 6px;
border-radius: 3px;
}
.stat-cond {
background: #dcfce7;
color: #166534;
}
.stat-miss {
background: #fef2f2;
color: #991b1b;
}
.stat-oth {
background: #fffbeb;
color: #92400e;
}
.stat-total {
color: var(--muted);
}
.scheme-cell.code-0 {
background: var(--empty);
}
@@ -356,6 +436,13 @@ body {
}
@media print {
@page {
margin: 10mm;
}
* {
-webkit-print-color-adjust: exact !important;
print-color-adjust: exact !important;
}
body {
background: #fff;
}
@@ -381,8 +468,27 @@ body {
.print-nav {
box-shadow: none;
}
.table th,
.class-table th {
position: static;
.week-block {
break-inside: avoid;
page-break-inside: avoid;
}
.class-weeks {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 6px;
}
.class-chart {
min-height: auto;
margin-bottom: 4px;
padding: 0;
}
.class-chart img {
max-width: 100%;
width: 100% !important;
height: auto !important;
margin: 0;
}
.week-chart {
margin: 0;
}
}
+28 -18
View File
@@ -7,7 +7,7 @@
<style>
{{ css_text | safe }}
</style>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>{{ chart_js_content | safe }}</script>
</head>
<body>
<div class="page">
@@ -84,33 +84,43 @@
<div>
<div class="class-kicker">{{ section.title }}</div>
<h3>{{ item.label }}</h3>
{% if item.description %}
<div class="class-note desc">{{ item.description }}</div>
{% endif %}
{% if item.no_schedule_warning %}
<div class="class-note warning">
⚠ Нет данных о расписании в этих аудиториях
</div>
{% endif %}
{% if item.source_labels %}
<div class="class-note">
{{ item.source_labels | join(', ') }}
</div>
{% endif %}
<div class="class-legend">
<span class="legend-item legend-conducted">Проведено {{ item.pct_conducted }}%</span>
<span class="legend-item legend-missed">Пропущено {{ item.pct_missed }}%</span>
<span class="legend-item legend-other">Не по расписанию {{ item.pct_other }}%</span>
</div>
</div>
</div>
<div class="class-chart">
<canvas class="week-chart" data-chart-for="{{ item.id }}"></canvas>
</div>
<div class="class-table-wrap">
<table class="class-table">
<tbody>
{% for week in item.weeks %}
<tr>
<td class="week-label">{{ week.long }}</td>
<td class="num">{{ week.total_pairs }}</td>
<td class="num">{{ week.conducted_display }}</td>
<td class="num">{{ week.missed_display }}</td>
<td class="num">{{ week.other_display }}</td>
<td class="scheme-cell-wrap">
{{ week.scheme_html | safe }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="class-weeks">
{% for week in item.weeks %}
<div class="week-block">
<div class="week-header">{{ week.long }}</div>
<div class="week-stats">
<span class="stat stat-cond">Проведено {{ week.conducted_display }}</span>
<span class="stat stat-miss">Пропущено {{ week.missed_display }}</span>
<span class="stat stat-oth">Не по расписанию {{ week.other_display }}</span>
</div>
<div class="scheme-cell-wrap">
{{ week.scheme_html | safe }}
</div>
</div>
{% endfor %}
</div>
</article>
{% endfor %}
+79 -2
View File
@@ -56,7 +56,7 @@
borderRadius: 4,
},
{
label: "Иное",
label: "Не по расписанию",
data: other,
backgroundColor: "#f59e0b",
stack: "pairs",
@@ -74,6 +74,7 @@
options: {
responsive: true,
maintainAspectRatio: false,
animation: false,
interaction: {
mode: "index",
intersect: false,
@@ -156,8 +157,84 @@
}
}
// ---- Print support: convert canvases to static images ----
function prepareForPrint() {
var report = window.__CLASS_REPORT__ || {};
var sections = Array.isArray(report.sections) ? report.sections : [];
var allEntries = sections.flatMap(function (s) {
return s.entries || [];
});
// Activate each class one-by-one, build its chart, capture the image,
// then move on. This ensures Chart.js renders each canvas properly.
var idx = 0;
var storedImages = {};
function processNext() {
if (idx >= allEntries.length) {
// All done — replace canvases with stored images
Object.keys(storedImages).forEach(function (classId) {
var canvas = qs('.week-chart[data-chart-for="' + classId + '"]');
if (!canvas) return;
var img = document.createElement("img");
img.src = storedImages[classId];
img.alt = "Chart";
img.style.width = "100%";
img.style.height = "320px";
img.style.objectFit = "contain";
canvas.parentNode.replaceChild(img, canvas);
});
// Restore original class
if (originalClassId) {
setActiveClass(originalClassId, false, report);
}
// Short delay then open print dialog
setTimeout(function () {
window.print();
}, 50);
return;
}
var entry = allEntries[idx];
var cid = entry.id;
if (!cid) {
idx++;
processNext();
return;
}
// Switch to this class to make its canvas visible
setActiveClass(cid, false, report);
// Wait for layout + Chart.js to render
setTimeout(function () {
// Build chart if not already built
buildChartForClass(cid, report);
// Wait again for chart animation to finish
setTimeout(function () {
var chart = chartStore.get(cid);
if (chart) {
storedImages[cid] = chart.toBase64Image();
}
idx++;
processNext();
}, 100);
}, 50);
}
// Remember which class was active
var originalClassId = null;
var activeBlock = qs(".class-block.active");
if (activeBlock) originalClassId = activeBlock.dataset.classId;
// Start sequential processing from first entry
idx = 0;
processNext();
}
window.printReport = function printReport() {
window.print();
prepareForPrint();
// print dialog opens inside prepareForPrint after all charts are processed
};
if (document.readyState === "loading") {