feat: alcance temporal configurable en importador y fix multi-carrera en ORM (v3.8.3)

This commit is contained in:
2026-10-19 17:27:36 -03:00
parent 4dd3e30698
commit c14ab0d49f
17 changed files with 682 additions and 39 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "3.8.2",
"version": "3.8.3",
"description": "",
"main": "index.js",
"scripts": {
+3 -3
View File
@@ -85,9 +85,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), {
});
// Versiones institucionales del sistema
const APP_VERSION = '3.8.2';
const FRONTEND_VERSION = '3.8.2';
const BACKEND_VERSION = '3.8.2';
const APP_VERSION = '3.8.3';
const FRONTEND_VERSION = '3.8.3';
const BACKEND_VERSION = '3.8.3';
env.addGlobal('app_version', APP_VERSION);
env.addGlobal('frontend_version', FRONTEND_VERSION);
+8
View File
@@ -98,6 +98,11 @@ const handleGoogleSheetsImport = async (req, res, justSynced = false) => {
if (req.body.single_date_only === 'true' || req.body.single_date_only === true || req.body.single_date_only === 'on') {
syncPayload.single_date_only = true;
}
if (req.body.weeks_to_generate) {
syncPayload.weeks_to_generate = parseInt(req.body.weeks_to_generate, 10);
}
if (req.body.date_from) syncPayload.date_from = req.body.date_from.trim();
if (req.body.date_to) syncPayload.date_to = req.body.date_to.trim();
// Toggles granulares de entidades
syncPayload.import_careers = req.body.import_careers === 'true' || req.body.import_careers === true || req.body.import_careers === 'on';
syncPayload.import_subjects = req.body.import_subjects === 'true' || req.body.import_subjects === true || req.body.import_subjects === 'on';
@@ -164,6 +169,9 @@ const handleGoogleSheetsImport = async (req, res, justSynced = false) => {
filter_days: req.body?.filter_days || ['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
manual_date: req.body?.manual_date || '',
single_date_only: req.body?.single_date_only === 'true' || req.body?.single_date_only === 'on',
weeks_to_generate: req.body?.weeks_to_generate || 16,
date_from: req.body?.date_from || '',
date_to: req.body?.date_to || '',
flash_msg: flashMsg,
flash_type: flashType
});
+240 -8
View File
@@ -310,15 +310,127 @@
</div>
</div>
<!-- 4. Alcance Temporal de la Cursada y Generación de Reservas -->
<div class="mb-4">
<div class="p-3 border rounded bg-body-tertiary">
<div class="d-flex flex-wrap justify-content-between align-items-center mb-3 gap-2">
<div>
<label class="form-label fw-bold small text-uppercase text-secondary mb-0">
<i class="bi bi-clock-history text-primary me-1"></i>3. Alcance Temporal de la Cursada (Generación de Reservas):
</label>
<span class="d-block text-muted small">Elija el número de semanas a importar, un rango de fechas (Desde - Hasta) o importe para una fecha puntual.</span>
</div>
<div class="btn-group btn-group-sm" role="group" aria-label="Modo de Alcance Temporal">
<input type="radio" class="btn-check" name="temporal_mode_selector" id="mode_weeks" autocomplete="off" {% if not single_date_only and not date_from %}checked{% endif %} onchange="onTemporalModeChange('weeks')">
<label class="btn btn-outline-primary py-1 px-3 fw-semibold" for="mode_weeks">
<i class="bi bi-calendar-week me-1"></i>Por Semanas
</label>
<input type="radio" class="btn-check" name="temporal_mode_selector" id="mode_range" autocomplete="off" {% if not single_date_only and date_from %}checked{% endif %} onchange="onTemporalModeChange('range')">
<label class="btn btn-outline-primary py-1 px-3 fw-semibold" for="mode_range">
<i class="bi bi-calendar-range me-1"></i>Rango de Fechas
</label>
<input type="radio" class="btn-check" name="temporal_mode_selector" id="mode_single" autocomplete="off" {% if single_date_only %}checked{% endif %} onchange="onTemporalModeChange('single')">
<label class="btn btn-outline-primary py-1 px-3 fw-semibold" for="mode_single">
<i class="bi bi-pin-angle-fill me-1"></i>Fecha Puntual Única
</label>
</div>
</div>
<!-- Panel: Por Semanas -->
<div id="panel_temporal_weeks" class="p-3 bg-white border rounded shadow-sm {% if single_date_only or date_from %}d-none{% endif %}">
<div class="row g-3 align-items-center">
<div class="col-md-4">
<label for="weeks_to_generate" class="form-label fw-semibold small mb-1">
Número de Semanas Consecutivas a Generar:
</label>
<div class="input-group input-group-sm">
<span class="input-group-text bg-body-secondary"><i class="bi bi-hash"></i></span>
<input type="number" class="form-control" id="weeks_to_generate" name="weeks_to_generate"
value="{{ weeks_to_generate or 16 }}" min="1" max="30" step="1" oninput="onWeeksInputChange(this.value)">
<span class="input-group-text">semanas</span>
</div>
</div>
<div class="col-md-8">
<label class="form-label fw-semibold small mb-1 text-muted">Accesos Rápidos:</label>
<div class="d-flex flex-wrap gap-2">
<button type="button" class="btn btn-sm btn-outline-secondary py-1 px-2" onclick="setWeeksValue(1)">1 sem (Corte semanal)</button>
<button type="button" class="btn btn-sm btn-outline-secondary py-1 px-2" onclick="setWeeksValue(4)">4 sem (1 Mes)</button>
<button type="button" class="btn btn-sm btn-outline-secondary py-1 px-2" onclick="setWeeksValue(8)">8 sem (Medio Cuat.)</button>
<button type="button" class="btn btn-sm btn-outline-primary py-1 px-2 fw-semibold" onclick="setWeeksValue(16)">16 sem (Cuatrimestre Regular)</button>
</div>
</div>
</div>
<div class="form-text small mt-2">
<i class="bi bi-info-circle me-1"></i>Genera $N$ clases consecutivas para el día de cursada a partir de la fecha base de cuatrimestre o la fecha manual sugerida.
</div>
</div>
<!-- Panel: Rango de Fechas (Desde - Hasta) -->
<div id="panel_temporal_range" class="p-3 bg-white border rounded shadow-sm {% if single_date_only or not date_from %}d-none{% endif %}">
<div class="row g-3 align-items-center">
<div class="col-md-5">
<label for="date_from" class="form-label fw-semibold small mb-1">
<i class="bi bi-calendar-event text-success me-1"></i>Fecha de Inicio (Desde):
</label>
<input type="date" class="form-control form-control-sm" id="date_from" name="date_from" value="{{ date_from }}" onchange="onRangeInputChange()">
</div>
<div class="col-md-5">
<label for="date_to" class="form-label fw-semibold small mb-1">
<i class="bi bi-calendar-check text-danger me-1"></i>Fecha de Fin (Hasta):
</label>
<input type="date" class="form-control form-control-sm" id="date_to" name="date_to" value="{{ date_to }}" onchange="onRangeInputChange()">
</div>
<div class="col-md-2 d-flex align-items-end">
<button type="button" class="btn btn-sm btn-outline-secondary w-100" onclick="clearDateRange()">
<i class="bi bi-eraser me-1"></i>Limpiar
</button>
</div>
</div>
<div class="form-text small mt-2">
<i class="bi bi-info-circle me-1"></i>El sistema calcula automáticamente todos los días de cursada correspondientes a cada comisión dentro del intervalo cerrado [Desde, Hasta].
</div>
</div>
<!-- Panel: Fecha Puntual Única -->
<div id="panel_temporal_single" class="p-3 bg-white border rounded shadow-sm {% if not single_date_only %}d-none{% endif %}">
<div class="d-flex flex-wrap align-items-center justify-content-between gap-3">
<div>
<div class="form-check form-switch mb-1">
<input class="form-check-input" type="checkbox" role="switch" id="single_date_only" name="single_date_only" value="true" {% if single_date_only %}checked{% endif %} onchange="onSingleDateSwitchChange()">
<label class="form-check-label fw-bold text-dark small" for="single_date_only">
<i class="bi bi-pin-angle-fill text-warning me-1"></i>Importar ÚNICAMENTE para fecha puntual
</label>
</div>
<span class="d-block text-muted small ms-4">
Crea exactamente 1 sola asignación por fila en lugar del cuatrimestre regular (16 semanas).
</span>
</div>
<div style="min-width: 220px;">
<label for="single_punctual_date" class="form-label fw-semibold small mb-1 text-secondary">
Fecha Puntual Asignada:
</label>
<input type="date" class="form-control form-control-sm" id="single_punctual_date" value="{{ manual_date }}" onchange="syncSingleDateToManualDate(this.value)">
</div>
</div>
</div>
</div>
</div>
<!-- Opciones de Cursada y Acciones Principales -->
<div class="p-3 bg-body-tertiary rounded border mb-4">
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3">
<div class="form-check form-switch mb-0">
<input class="form-check-input" type="checkbox" role="switch" id="single_date_only" name="single_date_only" value="true" {% if single_date_only %}checked{% endif %}>
<label class="form-check-label fw-semibold small" for="single_date_only">
<i class="bi bi-pin-angle-fill text-warning me-1"></i>Importar ÚNICAMENTE para fecha puntual
</label>
<span class="d-block text-muted small">Crea 1 sola asignación por fila en lugar del cuatrimestre regular (16 semanas).</span>
<div class="d-flex align-items-center gap-2">
<span class="badge bg-secondary-subtle text-secondary border px-3 py-2 fw-semibold" id="temporalSummaryBadge">
{% if single_date_only %}
<i class="bi bi-pin-angle-fill me-1 text-warning"></i>Alcance: 1 sola asignación puntual {{ '(' + manual_date + ')' if manual_date else '' }}
{% elif date_from and date_to %}
<i class="bi bi-calendar-range me-1 text-info"></i>Alcance: Rango {{ date_from }} a {{ date_to }}
{% else %}
<i class="bi bi-calendar-week me-1 text-primary"></i>Alcance: {{ weeks_to_generate or 16 }} semanas regulares
{% endif %}
</span>
</div>
<div class="d-flex gap-2">
<button type="button" class="btn btn-outline-primary px-3 shadow-sm fw-semibold" id="btnInspectSheet" onclick="inspectOnlineSheets()">
@@ -477,8 +589,14 @@
</div>
<div>
<strong class="text-secondary"><i class="bi bi-clock-history me-1"></i>Generación:</strong>
<span class="badge {% if stats.filters_applied.single_date_only %}bg-warning-subtle text-warning border border-warning-subtle{% else %}bg-success-subtle text-success border border-success-subtle{% endif %}">
{{ 'Fecha puntual única (1 asignación)' if stats.filters_applied.single_date_only else 'Cuatrimestre regular (16 semanas)' }}
<span class="badge {% if stats.filters_applied.temporal_scope == 'single_date' or stats.filters_applied.single_date_only %}bg-warning-subtle text-warning border border-warning-subtle{% elif stats.filters_applied.temporal_scope == 'date_range' %}bg-info-subtle text-info border border-info-subtle{% else %}bg-success-subtle text-success border border-success-subtle{% endif %}">
{% if stats.filters_applied.temporal_scope == 'single_date' or stats.filters_applied.single_date_only %}
Fecha puntual única (1 asignación)
{% elif stats.filters_applied.temporal_scope == 'date_range' %}
Rango de fechas ({{ stats.filters_applied.date_from }} al {{ stats.filters_applied.date_to }})
{% else %}
Semanas regulares ({{ stats.filters_applied.weeks_to_generate or 16 }} semanas)
{% endif %}
</span>
</div>
<div>
@@ -849,6 +967,15 @@
if (m) m.value = '';
const single = document.getElementById('single_date_only');
if (single) single.checked = false;
const df = document.getElementById('date_from');
if (df) df.value = '';
const dt = document.getElementById('date_to');
if (dt) dt.value = '';
const w = document.getElementById('weeks_to_generate');
if (w) w.value = 16;
const radWeeks = document.getElementById('mode_weeks');
if (radWeeks) radWeeks.checked = true;
if (typeof onTemporalModeChange === 'function') onTemporalModeChange('weeks');
setDaysSelection('all');
}
@@ -1186,6 +1313,89 @@
alert('Se aplicó la fecha ' + val + ' a ' + updatedCount + ' fila(s) seleccionada(s).');
}
// Gestión de Alcance Temporal (Por Semanas, Rango de Fechas, Fecha Puntual)
function onTemporalModeChange(mode) {
const pWeeks = document.getElementById('panel_temporal_weeks');
const pRange = document.getElementById('panel_temporal_range');
const pSingle = document.getElementById('panel_temporal_single');
const chkSingle = document.getElementById('single_date_only');
const badge = document.getElementById('temporalSummaryBadge');
if (pWeeks) pWeeks.classList.add('d-none');
if (pRange) pRange.classList.add('d-none');
if (pSingle) pSingle.classList.add('d-none');
if (mode === 'weeks') {
if (pWeeks) pWeeks.classList.remove('d-none');
if (chkSingle) chkSingle.checked = false;
const w = document.getElementById('weeks_to_generate')?.value || 16;
if (badge) badge.innerHTML = '<i class="bi bi-calendar-week me-1 text-primary"></i>Alcance: ' + w + ' semanas regulares';
} else if (mode === 'range') {
if (pRange) pRange.classList.remove('d-none');
if (chkSingle) chkSingle.checked = false;
const df = document.getElementById('date_from')?.value;
const dt = document.getElementById('date_to')?.value;
if (badge) badge.innerHTML = '<i class="bi bi-calendar-range me-1 text-info"></i>Alcance: Rango ' + (df && dt ? (df + ' a ' + dt) : 'personalizado');
} else if (mode === 'single') {
if (pSingle) pSingle.classList.remove('d-none');
if (chkSingle) chkSingle.checked = true;
const mDate = document.getElementById('manual_date')?.value;
const sDate = document.getElementById('single_punctual_date');
if (sDate && mDate) sDate.value = mDate;
if (badge) badge.innerHTML = '<i class="bi bi-pin-angle-fill me-1 text-warning"></i>Alcance: 1 sola asignación puntual' + (mDate ? ' (' + mDate + ')' : '');
}
}
function setWeeksValue(val) {
const input = document.getElementById('weeks_to_generate');
if (input) {
input.value = val;
const badge = document.getElementById('temporalSummaryBadge');
if (badge) badge.innerHTML = '<i class="bi bi-calendar-week me-1 text-primary"></i>Alcance: ' + val + ' semanas regulares';
}
}
function onWeeksInputChange(val) {
const badge = document.getElementById('temporalSummaryBadge');
if (badge) badge.innerHTML = '<i class="bi bi-calendar-week me-1 text-primary"></i>Alcance: ' + (val || 16) + ' semanas regulares';
}
function onRangeInputChange() {
const df = document.getElementById('date_from')?.value;
const dt = document.getElementById('date_to')?.value;
const badge = document.getElementById('temporalSummaryBadge');
if (badge) badge.innerHTML = '<i class="bi bi-calendar-range me-1 text-info"></i>Alcance: Rango ' + (df && dt ? (df + ' a ' + dt) : 'personalizado');
}
function clearDateRange() {
const df = document.getElementById('date_from');
const dt = document.getElementById('date_to');
if (df) df.value = '';
if (dt) dt.value = '';
const badge = document.getElementById('temporalSummaryBadge');
if (badge) badge.innerHTML = '<i class="bi bi-calendar-range me-1 text-info"></i>Alcance: Rango personalizado';
}
function onSingleDateSwitchChange() {
const chk = document.getElementById('single_date_only');
const badge = document.getElementById('temporalSummaryBadge');
if (chk && !chk.checked) {
const radWeeks = document.getElementById('mode_weeks');
if (radWeeks) radWeeks.checked = true;
onTemporalModeChange('weeks');
} else {
const mDate = document.getElementById('manual_date')?.value;
if (badge) badge.innerHTML = '<i class="bi bi-pin-angle-fill me-1 text-warning"></i>Alcance: 1 sola asignación puntual' + (mDate ? ' (' + mDate + ')' : '');
}
}
function syncSingleDateToManualDate(val) {
const mDate = document.getElementById('manual_date');
if (mDate) mDate.value = val;
const badge = document.getElementById('temporalSummaryBadge');
if (badge) badge.innerHTML = '<i class="bi bi-pin-angle-fill me-1 text-warning"></i>Alcance: 1 sola asignación puntual' + (val ? ' (' + val + ')' : '');
}
// Modal de Confirmación de Sincronización
function openSyncConfirmModal() {
const hasInspected = (window.inspectedRows && window.inspectedRows.length > 0);
@@ -1196,6 +1406,15 @@
return;
}
// Validación de Rango de Fechas
const modeRange = document.getElementById('mode_range')?.checked;
const dateFrom = document.getElementById('date_from')?.value;
const dateTo = document.getElementById('date_to')?.value;
if (modeRange && dateFrom && dateTo && dateFrom > dateTo) {
alert('Error: La fecha de inicio (Desde: ' + dateFrom + ') no puede ser posterior a la fecha de fin (Hasta: ' + dateTo + ').');
return;
}
// Resumen de entidades marcadas
const chkRes = document.getElementById('chk_import_reservations')?.checked;
const chkCls = document.getElementById('chk_import_classrooms')?.checked;
@@ -1212,6 +1431,19 @@
html += '<li class="mb-1"><i class="bi bi-layers text-primary me-2"></i>Sincronización completa de las pestañas de días seleccionadas.</li>';
}
// Resumen de alcance temporal
const chkSingle = document.getElementById('single_date_only')?.checked;
const weeks = document.getElementById('weeks_to_generate')?.value || 16;
const manualDate = document.getElementById('manual_date')?.value;
if (chkSingle) {
html += '<li class="mt-2 text-warning fw-semibold"><i class="bi bi-pin-angle-fill me-2"></i>Alcance Temporal: 1 sola asignación puntual' + (manualDate ? ' (' + manualDate + ')' : '') + '</li>';
} else if (dateFrom && dateTo) {
html += '<li class="mt-2 text-info fw-semibold"><i class="bi bi-calendar-range me-2"></i>Alcance Temporal: Rango de fechas del ' + dateFrom + ' al ' + dateTo + '</li>';
} else {
html += '<li class="mt-2 text-primary fw-semibold"><i class="bi bi-calendar-week me-2"></i>Alcance Temporal: ' + weeks + ' semanas consecutivas</li>';
}
html += '<li class="mt-2 text-muted fw-semibold">Entidades a crear / sincronizar:</li>';
if (chkRes) html += '<li class="ms-3"><i class="bi bi-calendar-check text-danger me-2"></i>Asignaciones de aulas (Reservas en Calendario)</li>';
if (chkCls) html += '<li class="ms-3"><i class="bi bi-door-open text-success me-2"></i>Aulas físicas y virtuales</li>';