From 515dd8da03d07557a651718a68f58eabdd68619b Mon Sep 17 00:00:00 2001 From: Dauren777 Date: Fri, 19 Jun 2026 06:57:05 +0000 Subject: [PATCH] fix: rewrite app.js with working upload button --- app.js | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/app.js b/app.js index d82798f..026e75b 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,26 @@ -// Chart utility functions removed - using tables instead +var charts = {}; + +document.getElementById('uploadBtn').addEventListener('click', function() { + document.getElementById('excelFile').click(); +}); + +document.getElementById('excelFile').addEventListener('change', function(e) { + var file = e.target.files[0]; + if (!file) return; + document.getElementById('statusMsg').textContent = 'Загрузка: ' + file.name + '...'; + + var reader = new FileReader(); + reader.onload = function(ev) { + try { + var arr = new Uint8Array(ev.target.result); + var wb = XLSX.read(arr, {type: 'array'}); + var ws = wb.Sheets[wb.SheetNames[0]]; + var rows = XLSX.utils.sheet_to_json(ws, {defval: ''}); + if (!rows.length) { document.getElementById('statusMsg').textContent = 'Файл пуст'; return; } + build(rows); + } catch(err) { + document.getElementById('statusMsg').textContent = 'Ошибка: ' + err.message; + } }; reader.readAsArrayBuffer(file); }); @@ -47,7 +69,7 @@ function build(raw) { var c = r.course || 'Без темы'; if (!train[c]) train[c] = {all:{}, ok:{}, sc:[], tr:{}}; train[c].all[r.name] = true; - if (r.status === 'завершен' || r.status === 'пройден') train[c].ok[r.name] = true; + if (done(r.status)) train[c].ok[r.name] = true; if (!isNaN(sc) && sc > 0) train[c].sc.push(sc); if (r.trainer) train[c].tr[r.trainer] = true; @@ -98,24 +120,3 @@ function build(raw) { return ''+(r.name||'')+''+(r.division||'')+''+(r.course||'')+''+(r.status||'')+''+(r.score||'')+''+(r.trainer||'')+''; }).join(''); } - -function barH(id, labels, ds) { - if(charts[id])charts[id].destroy(); - charts[id]=new Chart(document.getElementById(id),{type:'bar',data:{labels:labels,datasets:ds.map(function(s){return{label:s.label,data:s.data,backgroundColor:s.bg,borderColor:s.bc,borderWidth:1}})}, - options:{indexAxis:'y',responsive:true,plugins:{legend:{labels:{color:'#e0e0e0'}}},scales:{x:{beginAtZero:true,ticks:{color:'#90a4ae'},grid:{color:'#1e2d3d'}},y:{ticks:{color:'#e0e0e0',font:{size:11}},grid:{color:'#1e2d3d'}}}}}); -} -function bar(id, labels, ds) { - if(charts[id])charts[id].destroy(); - charts[id]=new Chart(document.getElementById(id),{type:'bar',data:{labels:labels,datasets:ds.map(function(s){return{label:s.label,data:s.data,backgroundColor:s.bg,borderColor:s.bc,borderWidth:1}})}, - options:{responsive:true,plugins:{legend:{labels:{color:'#e0e0e0'}}},scales:{y:{beginAtZero:true,ticks:{color:'#90a4ae'},grid:{color:'#1e2d3d'}},x:{ticks:{color:'#90a4ae'},grid:{color:'#1e2d3d'}}}}}); -} -function stacked(id, labels, ds) { - if(charts[id])charts[id].destroy(); - charts[id]=new Chart(document.getElementById(id),{type:'bar',data:{labels:labels,datasets:ds.map(function(s){return{label:s.label,data:s.data,backgroundColor:s.bg,borderColor:s.bc,borderWidth:1}})}, - options:{responsive:true,plugins:{legend:{labels:{color:'#e0e0e0'}}},scales:{x:{stacked:true,ticks:{color:'#90a4ae',maxRotation:45},grid:{color:'#1e2d3d'}},y:{stacked:true,beginAtZero:true,ticks:{color:'#90a4ae'},grid:{color:'#1e2d3d'}}}}}); -} -function doughnut(id, labels, data, colors) { - if(charts[id])charts[id].destroy(); - charts[id]=new Chart(document.getElementById(id),{type:'doughnut',data:{labels:labels,datasets:[{data:data,backgroundColor:colors,borderWidth:0}]}, - options:{responsive:true,plugins:{legend:{labels:{color:'#e0e0e0'}}}}}); -}