Spaces:
Running
Running
Upload 20 files
Browse files- js/teacherUI.js +63 -47
js/teacherUI.js
CHANGED
|
@@ -83,7 +83,7 @@ export const teacherUI = {
|
|
| 83 |
<div style="display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap;">
|
| 84 |
<h2 class="view-title">📊 Libro de Notas</h2>
|
| 85 |
<div>
|
| 86 |
-
<button class="btn-small" onclick="teacherUI.downloadGradesCSV()">📥 Descargar CSV</button>
|
| 87 |
</div>
|
| 88 |
</div>
|
| 89 |
|
|
@@ -165,53 +165,69 @@ export const teacherUI = {
|
|
| 165 |
},
|
| 166 |
|
| 167 |
downloadGradesCSV: async () => {
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
}
|
| 182 |
-
|
| 183 |
-
let csvContent = "data:text/csv;charset=utf-8,";
|
| 184 |
-
// Encabezados
|
| 185 |
-
const headers = ["ID_Registro", "Fecha_Evaluacion", "ID_Estudiante", "Nombre_Estudiante", "ID_Taller", "Nota_Digital_App", "Nota_Profe_Coop", "Nota_Profe_Math", "Feedback_Automatico"];
|
| 186 |
-
csvContent += headers.join(",") + "\r\n";
|
| 187 |
-
|
| 188 |
-
// Filas
|
| 189 |
-
notas.forEach(fila => {
|
| 190 |
-
const nombre = fila.estudiantes ? fila.estudiantes.nombre_completo.replace(/,/g, ";") : 'N/A';
|
| 191 |
-
const feedback = fila.feedback ? fila.feedback.replace(/\r\n|\n/g, ' ').replace(/,/g, ";") : '';
|
| 192 |
-
|
| 193 |
-
const row = [
|
| 194 |
-
fila.id,
|
| 195 |
-
`"${new Date(fila.fecha_evaluacion).toLocaleString()}"`,
|
| 196 |
-
fila.id_estudiante,
|
| 197 |
-
nombre,
|
| 198 |
-
fila.id_taller,
|
| 199 |
-
fila.nota_final || 0,
|
| 200 |
-
fila.criterio_coop || 0,
|
| 201 |
-
fila.criterio_math || 0,
|
| 202 |
-
`"${feedback}"`
|
| 203 |
-
];
|
| 204 |
-
csvContent += row.join(",") + "\r\n";
|
| 205 |
-
});
|
| 206 |
-
|
| 207 |
-
// Crear y descargar el archivo
|
| 208 |
-
const encodedUri = encodeURI(csvContent);
|
| 209 |
-
const link = document.createElement("a");
|
| 210 |
-
link.setAttribute("href", encodedUri);
|
| 211 |
-
link.setAttribute("download", "reporte_de_notas_cosmomente.csv");
|
| 212 |
-
document.body.appendChild(link);
|
| 213 |
-
link.click();
|
| 214 |
-
document.body.removeChild(link);
|
| 215 |
},
|
| 216 |
|
| 217 |
// --- RESTO DE VISTAS (Guías y Misiones) ---
|
|
|
|
| 83 |
<div style="display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap;">
|
| 84 |
<h2 class="view-title">📊 Libro de Notas</h2>
|
| 85 |
<div>
|
| 86 |
+
<button id="download-csv-btn" class="btn-small" onclick="teacherUI.downloadGradesCSV()">📥 Descargar CSV</button>
|
| 87 |
</div>
|
| 88 |
</div>
|
| 89 |
|
|
|
|
| 165 |
},
|
| 166 |
|
| 167 |
downloadGradesCSV: async () => {
|
| 168 |
+
const btn = document.getElementById('download-csv-btn');
|
| 169 |
+
if (!btn) return;
|
| 170 |
+
|
| 171 |
+
const originalText = btn.innerHTML;
|
| 172 |
+
btn.disabled = true;
|
| 173 |
+
btn.innerHTML = '🔄 Preparando...';
|
| 174 |
+
|
| 175 |
+
try {
|
| 176 |
+
const { data: notas, error } = await supabase
|
| 177 |
+
.from('rubricas_evaluacion')
|
| 178 |
+
.select(`
|
| 179 |
+
id, fecha_evaluacion, id_estudiante, id_taller, nota_final, criterio_coop, criterio_math, feedback,
|
| 180 |
+
estudiantes!fk_estudiante ( nombre_completo )
|
| 181 |
+
`)
|
| 182 |
+
.order('fecha_evaluacion', { ascending: true });
|
| 183 |
+
|
| 184 |
+
if (error) {
|
| 185 |
+
alert(`Error al generar el CSV: ${error.message}`);
|
| 186 |
+
console.error('Download CSV error:', error);
|
| 187 |
+
return;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
if (!notas || notas.length === 0) {
|
| 191 |
+
alert("No hay notas para exportar.");
|
| 192 |
+
return;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
let csvContent = "data:text/csv;charset=utf-8,";
|
| 196 |
+
const headers = ["ID_Registro", "Fecha_Evaluacion", "ID_Estudiante", "Nombre_Estudiante", "ID_Taller", "Nota_Digital_App", "Nota_Profe_Coop", "Nota_Profe_Math", "Feedback_Automatico"];
|
| 197 |
+
csvContent += headers.join(",") + "\r\n";
|
| 198 |
+
|
| 199 |
+
notas.forEach(fila => {
|
| 200 |
+
const nombre = fila.estudiantes ? fila.estudiantes.nombre_completo.replace(/,/g, ";") : 'N/A';
|
| 201 |
+
const feedback = fila.feedback ? fila.feedback.replace(/\r\n|\n/g, ' ').replace(/,/g, ";") : '';
|
| 202 |
+
const row = [
|
| 203 |
+
fila.id,
|
| 204 |
+
`"${new Date(fila.fecha_evaluacion).toLocaleString()}"`,
|
| 205 |
+
fila.id_estudiante,
|
| 206 |
+
nombre,
|
| 207 |
+
fila.id_taller,
|
| 208 |
+
fila.nota_final || 0,
|
| 209 |
+
fila.criterio_coop || 0,
|
| 210 |
+
fila.criterio_math || 0,
|
| 211 |
+
`"${feedback}"`
|
| 212 |
+
];
|
| 213 |
+
csvContent += row.join(",") + "\r\n";
|
| 214 |
+
});
|
| 215 |
+
|
| 216 |
+
const encodedUri = encodeURI(csvContent);
|
| 217 |
+
const link = document.createElement("a");
|
| 218 |
+
link.setAttribute("href", encodedUri);
|
| 219 |
+
link.setAttribute("download", "reporte_de_notas_cosmomente.csv");
|
| 220 |
+
document.body.appendChild(link);
|
| 221 |
+
link.click();
|
| 222 |
+
document.body.removeChild(link);
|
| 223 |
+
|
| 224 |
+
} catch (e) {
|
| 225 |
+
console.error("Error inesperado al descargar CSV:", e);
|
| 226 |
+
alert("Ocurrió un error inesperado al preparar el archivo.");
|
| 227 |
+
} finally {
|
| 228 |
+
btn.disabled = false;
|
| 229 |
+
btn.innerHTML = originalText;
|
| 230 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
},
|
| 232 |
|
| 233 |
// --- RESTO DE VISTAS (Guías y Misiones) ---
|