diff --git a/CHANGELOG.md b/CHANGELOG.md index df8bd05..6b0345f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,24 @@ El formato está basado en [Keep a Changelog](https://keepachangelog.com/es-ES/1 - **Sincronización Continua Moodle (Fase 6):** Automatización de workers persistentes en background para el procesamiento continuo de la cola de Web Services Moodle 4.1. - **Pruebas de Carga y Hardening (Fase 6):** Pruebas de estrés de concurrencia y validación final de producción. +## [3.4.3] - 2026-10-07 +### Añadido & Refactorizado (Sincronización Google Sheets) +- **Selección Granular de Entidades a Importar:** + - Adopción del patrón visual de tarjetas checkbox (idéntico a la Herramienta de Reinicio y Purga Académica) con accesos rápidos "Marcar Todo" y "Desmarcar Todo". + - Toggles individuales para Asignaciones de aulas (`import_reservations`), Aulas físicas y virtuales (`import_classrooms`), Comisiones de cursada (`import_commissions`), Asignaturas / Materias (`import_subjects`) y Carreras académicas (`import_careers`). +- **Selector de Días de la Semana con Checkboxes Múltiples:** + - Sistema de checkboxes para procesar concurrentemente múltiples días de la semana (Lunes a Sábado) con selectores rápidos ("Todos", "Lun a Vie", "Limpiar"). +- **Grilla de Previsualización Interactiva e Inspección Previa:** + - El botón "Inspeccionar Sheet Online" no importa directamente; extrae y presenta una grilla interactiva completa (`preview_rows`) de registros online. + - Selección por fila mediante checkboxes individuales y checkbox maestro superior. + - Modificación manual inline de fechas de cursada por fila mediante Datepicker (``) y aplicador de fecha masiva a seleccionados. + - Resaltado visual con badges de alerta y error ante registros incompletos o aulas no reconocidas. + - Buscador en vivo multi-criterio y paginación fluida (25 filas por página) para evitar bloqueos del navegador. + - Modal de confirmación previa con desglose exacto de filas y entidades antes de iniciar la sincronización. +- **Backend & BFF Endpoints:** + - `POST /api/v1/dashboard/sheets-inspect` retorna metadatos y `preview_rows` con inferencia de fechas, estados de validación y carreras compartidas. + - `POST /api/v1/dashboard/sync-sheets` procesa opcionalmente `selected_rows` con fechas editadas respetando la granularidad de entidades activadas. + ## [3.4.2] - 2026-10-07 ### Corregido & Mejorado (UX/UI) - **Agrupación Cronológica de Reservas en Cartelera del Día (`/schedule/today_schedule`):** diff --git a/MEMORY.md b/MEMORY.md index aefa72b..b85e280 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -99,7 +99,26 @@ Memoria del proyecto entre sesiones para la rama `dev`. - **Bump Semántico y Despliegue Obligatorio (Principio 9)**: - Versión incrementada a `v3.4.2` en Frontend y Backend. - Despliegue inmediato al servidor institucional `10.0.0.217` y verificación en caliente. +- **Sprint Importador Google Sheets: Selección Granular y Grilla Interactiva (v3.4.3)**: + - **Selección Granular de Entidades (Tarjetas Checkbox)**: + - Réplica del diseño visual de la Herramienta de Purga con botones "Marcar Todo" y "Desmarcar Todo". + - Toggles individuales para Asignaciones de aulas (`import_reservations`), Aulas físicas y virtuales (`import_classrooms`), Comisiones (`import_commissions`), Asignaturas (`import_subjects`) y Carreras (`import_careers`). + - **Selector de Días de la Semana con Checkboxes Múltiples**: + - Reemplazo del selector simple por checkboxes individuales para Lunes a Sábado con accesos rápidos ("Todos", "Lun a Vie", "Limpiar"). + - **Grilla de Previsualización Interactiva e Inspección Previa**: + - El botón "Inspeccionar Sheet Online" no importa directamente; extrae y presenta una grilla interactiva completa (`preview_rows`) de registros online. + - Selección individual por fila y checkbox maestro superior. + - Modificación manual inline de fechas de cursada por fila mediante Datepicker (``) y aplicador de fecha masiva a seleccionados. + - Resaltado visual con badges de alerta y error ante registros incompletos o aulas no reconocidas. + - Buscador en vivo multi-criterio y paginación fluida (25 filas por página) para evitar bloqueos del navegador. + - Modal de confirmación previa con desglose exacto de filas y entidades antes de iniciar la sincronización. + - **Backend y BFF REST**: + - `sheets_importer.py` ampliado para retornar `preview_rows` y procesar `selected_rows` con granularidad de entidades. + - Endpoints `POST /api/v1/dashboard/sheets-inspect` y `POST /api/v1/dashboard/sync-sheets`. + - **Bump Semántico y Despliegue Obligatorio (Principio 9)**: + - Versión incrementada a `v3.4.3` en Frontend y Backend. + - Despliegue y verificación en caliente en el servidor institucional `10.0.0.217` (`https://eduspace.oemspot.com.ar`). ## Próximos pasos -1. Continuar con los objetivos de la Fase 6 del Roadmap institucional. -2. Monitoreo continuo de la experiencia de usuario en Bedelía y Cartelera del Día. \ No newline at end of file +1. Continuar con los objetivos de la Fase 6 del Roadmap institucional (Docker-compose productivo, Nginx con SSL y automatización de workers continuos Moodle). +2. Monitoreo continuo de la experiencia de usuario en Bedelía, Cartelera del Día y Sincronización Académica. \ No newline at end of file diff --git a/ROADMAP.md b/ROADMAP.md index 9517e6f..ba5164e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,7 +2,7 @@ ## Gestión de Espacios Áulicos, Asignación de Comisiones y Operatoria de Bedelía **Institución:** Universidad de la Ciudad de Buenos Aires (UniCABA) -**Versión:** 3.4.2 (Sprint UX/UI: Agrupación Cronológica de Reservas y Formato Limpio de Fechas) +**Versión:** 3.4.3 (Refactorización del Importador Google Sheets: Selección Granular y Grilla Interactiva) **Fecha de Actualización:** 07 de Octubre de 2026 **Rama Base:** `dev` diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 63f2099..e0dfa44 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -6,7 +6,7 @@ from flask_babel import Babel, gettext as _ from config.config import Config # Initialize extensions -__version__ = "3.4.2" +__version__ = "3.4.3" db = SQLAlchemy() migrate = Migrate() cors = CORS() diff --git a/backend/app/routes/api/dashboard.py b/backend/app/routes/api/dashboard.py index ef3c896..ffb13fb 100644 --- a/backend/app/routes/api/dashboard.py +++ b/backend/app/routes/api/dashboard.py @@ -530,7 +530,7 @@ def get_stats(): @api_dashboard_bp.route('/sync-sheets', methods=['POST']) @jwt_required def sync_google_sheets(): - """Ejecuta la sincronización real con las hojas de cálculo de Google Sheets con soporte de filtros.""" + """Ejecuta la sincronización real con las hojas de cálculo de Google Sheets con soporte de filtros y entidades.""" from app.services.sheets_importer import GoogleSheetsImporter try: data = request.get_json(silent=True) or {} @@ -538,16 +538,32 @@ def sync_google_sheets(): filter_career = data.get('filter_career') filter_subject = data.get('filter_subject') filter_day = data.get('filter_day') + filter_days = data.get('filter_days') manual_date = data.get('manual_date') single_date_only = bool(data.get('single_date_only', False)) + + # Opciones granulares de entidades + import_careers = data.get('import_careers', True) + import_subjects = data.get('import_subjects', True) + import_commissions = data.get('import_commissions', True) + import_classrooms = data.get('import_classrooms', True) + import_reservations = data.get('import_reservations', True) + selected_rows = data.get('selected_rows') importer = GoogleSheetsImporter(base_url=custom_url) stats = importer.sync( filter_career=filter_career, filter_subject=filter_subject, filter_day=filter_day, + filter_days=filter_days, manual_date=manual_date, - single_date_only=single_date_only + single_date_only=single_date_only, + import_careers=import_careers, + import_subjects=import_subjects, + import_commissions=import_commissions, + import_classrooms=import_classrooms, + import_reservations=import_reservations, + selected_rows=selected_rows ) return jsonify({ 'status': 'success', @@ -563,13 +579,25 @@ def sync_google_sheets(): @api_dashboard_bp.route('/sheets-inspect', methods=['GET', 'POST']) @jwt_required def inspect_google_sheets(): - """Devuelve metadatos, carreras y materias del Google Sheet online para filtros interactivos.""" + """Devuelve metadatos, carreras, materias y previsualización de registros según los filtros aplicados.""" from app.services.sheets_importer import GoogleSheetsImporter try: data = request.get_json(silent=True) or {} custom_url = data.get('sheets_url') or request.args.get('sheets_url') + filter_career = data.get('filter_career') or request.args.get('filter_career') + filter_subject = data.get('filter_subject') or request.args.get('filter_subject') + filter_day = data.get('filter_day') or request.args.get('filter_day') + filter_days = data.get('filter_days') or request.args.get('filter_days') + manual_date = data.get('manual_date') or request.args.get('manual_date') + importer = GoogleSheetsImporter(base_url=custom_url) - metadata = importer.inspect_sheet_content() + metadata = importer.inspect_sheet_content( + filter_career=filter_career, + filter_subject=filter_subject, + filter_day=filter_day, + filter_days=filter_days, + manual_date=manual_date + ) return jsonify({ 'status': 'success', 'metadata': metadata, diff --git a/backend/app/routes/api/openapi.py b/backend/app/routes/api/openapi.py index 9e3d8ee..cfad23d 100644 --- a/backend/app/routes/api/openapi.py +++ b/backend/app/routes/api/openapi.py @@ -7,7 +7,7 @@ OPENAPI_SPEC = { "info": { "title": "Edu-Space REST API", "description": "Enterprise Academic & Physical Space Management REST API with JWT Authentication and Role-Based Access Control.", - "version": "3.4.2" + "version": "3.4.3" }, "servers": [ { diff --git a/backend/app/services/sheets_importer.py b/backend/app/services/sheets_importer.py index fa657b2..345e8d4 100644 --- a/backend/app/services/sheets_importer.py +++ b/backend/app/services/sheets_importer.py @@ -352,21 +352,55 @@ class GoogleSheetsImporter: except Exception: return None, None - def inspect_sheet_content(self): + def inspect_sheet_content(self, filter_career=None, filter_subject=None, filter_day=None, filter_days=None, manual_date=None): """ Descarga e inspecciona las hojas del Sheet online para extraer: - Días disponibles con cantidad de filas - Carreras únicas - Materias únicas con sus códigos, nombres y carreras + - Grilla de pre-visualización interactiva (preview_rows) según los filtros aplicados """ sheets_to_process = self.get_sheets_config() days_info = [] careers_set = set() subjects_map = {} total_rows = 0 + preview_rows = [] + # Normalizar días seleccionados + allowed_days = None + if filter_days: + if isinstance(filter_days, str): + allowed_days = [normalize_day_name(d) for d in filter_days.split(',') if d.strip()] + elif isinstance(filter_days, (list, set)): + allowed_days = [normalize_day_name(d) for d in filter_days if d] + elif filter_day: + nd = normalize_day_name(filter_day) + if nd and nd.upper() not in ['ALL', 'TODOS', 'TODOS LOS DÍAS', 'TODOS LOS DIAS', '']: + allowed_days = [nd] + + # Normalizar fecha manual para fecha inferida base + manual_dt = None + if manual_date: + try: + if isinstance(manual_date, (datetime, date)): + manual_dt = manual_date if isinstance(manual_date, date) else manual_date.date() + elif isinstance(manual_date, str) and manual_date.strip(): + manual_dt = datetime.strptime(manual_date.strip(), '%Y-%m-%d').date() + except Exception: + pass + + # Referencia de semana base: lunes 5 de octubre de 2026 (semana activa del 2° cuatrimestre) + ref_monday = date(2026, 10, 5) + if manual_dt: + ref_monday = manual_dt - timedelta(days=manual_dt.weekday()) + + row_counter = 0 for sheet_cfg in sheets_to_process: day_name = sheet_cfg['name'] + norm_day = normalize_day_name(day_name) + day_idx = sheet_cfg.get('day_idx', 0) + try: csv_data = self.fetch_sheet_csv(sheet_cfg['gid']) rows = self.parse_sheet_rows(csv_data, day_name) @@ -374,10 +408,15 @@ class GoogleSheetsImporter: days_info.append({ 'name': day_name, 'gid': sheet_cfg['gid'], - 'day_idx': sheet_cfg['day_idx'], + 'day_idx': day_idx, 'rows_count': len(rows), 'status': 'OK' }) + + # Si este día no está entre los permitidos, no lo agregamos a preview_rows + if allowed_days and norm_day not in allowed_days: + continue + for r in rows: carreras = parse_careers_list(r.get('carrera', '')) for c in carreras: @@ -394,11 +433,67 @@ class GoogleSheetsImporter: 'careers': carreras, 'day': day_name } + + # Evaluar coincidencia de filtros de Carrera y Materia para la pre-visualización + if filter_career: + fc = filter_career.strip().upper() + match_c = any(fc in c.upper() or c.upper() in fc for c in carreras) or (fc in r.get('carrera', '').upper()) + if not match_c: + continue + + if filter_subject: + fs = filter_subject.strip().upper() + sub_codes = parse_subject_codes(code) + match_s = (fs in code.upper()) or (fs in name.upper()) or any(fs in sc.upper() for sc in sub_codes) + if not match_s: + continue + + row_counter += 1 + aula_raw = r.get('aula', '').strip() + room_info = self.normalize_room(aula_raw) + is_virtual = bool(room_info and ('VIRTUAL' in room_info.get('code', '').upper() or room_info.get('building') == 'Campus Virtual')) + + # Calcular fecha tentativa + target_date = ref_monday + timedelta(days=day_idx) + if manual_dt and norm_day == normalize_day_name(['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'][manual_dt.weekday()]): + target_date = manual_dt + + # Validaciones + is_valid = True + has_warning = False + warning_msg = None + + if not code or not name: + is_valid = False + warning_msg = "Falta código o nombre de asignatura" + elif not room_info or not aula_raw or any(x in aula_raw.upper() for x in ['FERIADO', 'SIN ACTIVIDAD', 'CONSULTAR']): + has_warning = True + warning_msg = f"Aula pendiente o sin asignar ({aula_raw or 'Vacía'})" + + preview_rows.append({ + 'id': row_counter, + 'dia': norm_day, + 'day_idx': day_idx, + 'codigo': code, + 'asignatura': name, + 'aula': aula_raw or (room_info['code'] if room_info else 'Sin Aula'), + 'aula_normalizada': room_info['code'] if room_info else 'Sin Aula', + 'is_virtual': is_virtual, + 'carrera': r.get('carrera', 'General'), + 'carreras_list': carreras, + 'horario': r.get('horario', ''), + 'turno': r.get('turno', 'Mañana'), + 'inferred_date': target_date.strftime('%Y-%m-%d'), + 'is_valid': is_valid, + 'has_warning': has_warning, + 'warning_msg': warning_msg + }) + except Exception as e: days_info.append({ 'name': day_name, 'gid': sheet_cfg['gid'], - 'day_idx': sheet_cfg.get('day_idx', 0), + 'day_idx': day_idx, 'rows_count': 0, 'status': 'Error', 'error': str(e) @@ -406,19 +501,28 @@ class GoogleSheetsImporter: return { 'total_rows': total_rows, + 'matching_rows': len(preview_rows), 'days': days_info, 'careers': sorted(list(careers_set)), - 'subjects': sorted(list(subjects_map.values()), key=lambda x: x['code']) + 'subjects': sorted(list(subjects_map.values()), key=lambda x: x['code']), + 'preview_rows': preview_rows } - def sync(self, filter_career=None, filter_subject=None, filter_day=None, manual_date=None, single_date_only=False): + def sync(self, filter_career=None, filter_subject=None, filter_day=None, filter_days=None, manual_date=None, single_date_only=False, import_careers=True, import_subjects=True, import_commissions=True, import_classrooms=True, import_reservations=True, selected_rows=None): """ - Proceso principal de sincronización con soporte de filtros y fechas manuales: + Proceso principal de sincronización con soporte de filtros, entidades granulares y filas seleccionadas: :param filter_career: Filtrar por carrera específica (ej. 'DATOS (CCC)') :param filter_subject: Filtrar por código o nombre de materia (ej. 'ASIG00113') :param filter_day: Filtrar por día específico ('Lunes'..'Sábado' o 'ALL') + :param filter_days: Lista o cadena de días específicos (ej. ['Lunes', 'Martes']) :param manual_date: Fecha manual específica (YYYY-MM-DD o objeto date) :param single_date_only: Si es True y hay manual_date, crea reserva solo para esa fecha puntual + :param import_careers: Booleano para importar/crear carreras + :param import_subjects: Booleano para importar/crear asignaturas + :param import_commissions: Booleano para importar/crear comisiones + :param import_classrooms: Booleano para importar/crear aulas + :param import_reservations: Booleano para importar/crear reservas + :param selected_rows: Lista de filas específicas pre-seleccionadas desde la grilla interactiva """ dias_esp = ['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo'] @@ -430,19 +534,26 @@ class GoogleSheetsImporter: manual_dt = manual_date if isinstance(manual_date, date) else manual_date.date() elif isinstance(manual_date, str) and manual_date.strip(): manual_dt = datetime.strptime(manual_date.strip(), '%Y-%m-%d').date() - except Exception as e: + except Exception: pass - # Normalizar día filtro si fue provisto - norm_filter_day = normalize_day_name(filter_day) if filter_day else None - if norm_filter_day and norm_filter_day.upper() in ['ALL', 'TODOS', 'TODOS LOS DÍAS', 'TODOS LOS DIAS', '']: - norm_filter_day = None + # Normalizar días permitidos + allowed_days = None + if filter_days: + if isinstance(filter_days, str): + allowed_days = [normalize_day_name(d) for d in filter_days.split(',') if d.strip()] + elif isinstance(filter_days, (list, set)): + allowed_days = [normalize_day_name(d) for d in filter_days if d] + elif filter_day: + nd = normalize_day_name(filter_day) + if nd and nd.upper() not in ['ALL', 'TODOS', 'TODOS LOS DÍAS', 'TODOS LOS DIAS', '']: + allowed_days = [nd] - # Si el usuario no especificó filter_day pero ingresó fecha manual puntual, inferir día - if not norm_filter_day and manual_dt and single_date_only: + # Si el usuario no especificó días pero ingresó fecha manual puntual, inferir día + if not allowed_days and manual_dt and single_date_only: manual_w = manual_dt.weekday() if manual_w < 6: - norm_filter_day = dias_esp[manual_w] + allowed_days = [dias_esp[manual_w]] stats = { 'total_rows_processed': 0, @@ -461,39 +572,56 @@ class GoogleSheetsImporter: 'filters_applied': { 'career': filter_career.strip() if filter_career else None, 'subject': filter_subject.strip() if filter_subject else None, - 'day': norm_filter_day or 'Todos los Días', + 'days': allowed_days or ['Todos los Días'], 'manual_date': manual_dt.strftime('%Y-%m-%d') if manual_dt else None, - 'single_date_only': bool(single_date_only and manual_dt) + 'single_date_only': bool(single_date_only and manual_dt), + 'entities': { + 'careers': bool(import_careers), + 'subjects': bool(import_subjects), + 'commissions': bool(import_commissions), + 'classrooms': bool(import_classrooms), + 'reservations': bool(import_reservations) + } } } all_raw_records = [] - sheets_to_process = self.get_sheets_config() - # Filtrar pestañas si se especificó un día específico - if norm_filter_day: - sheets_to_process = [s for s in sheets_to_process if normalize_day_name(s['name']) == norm_filter_day] + if selected_rows and isinstance(selected_rows, list) and len(selected_rows) > 0: + # Modo grilla interactiva: se procesan las filas explícitamente seleccionadas por el usuario + for r in selected_rows: + d_name = r.get('dia') or 'Lunes' + d_idx = map_day_to_idx(d_name) + all_raw_records.append((r, d_idx)) + if d_name not in stats['by_day']: + stats['by_day'][d_name] = {'rows_count': 0, 'status': 'OK'} + stats['by_day'][d_name]['rows_count'] += 1 + else: + # Modo descarga general desde Google Sheets + sheets_to_process = self.get_sheets_config() + if allowed_days: + sheets_to_process = [s for s in sheets_to_process if normalize_day_name(s['name']) in allowed_days] - for sheet_cfg in sheets_to_process: - day_name = sheet_cfg['name'] - try: - csv_data = self.fetch_sheet_csv(sheet_cfg['gid']) - rows = self.parse_sheet_rows(csv_data, day_name) - all_raw_records.extend([(r, sheet_cfg['day_idx']) for r in rows]) - stats['by_day'][day_name] = { - 'gid': sheet_cfg['gid'], - 'rows_count': len(rows), - 'status': 'OK' - } - except Exception as e: - err_msg = f"Error al descargar o procesar la hoja de {day_name}: {str(e)}" - stats['errors'].append(err_msg) - stats['by_day'][day_name] = { - 'gid': sheet_cfg['gid'], - 'rows_count': 0, - 'status': 'Error', - 'error': str(e) - } + for sheet_cfg in sheets_to_process: + day_name = sheet_cfg['name'] + try: + csv_data = self.fetch_sheet_csv(sheet_cfg['gid']) + rows = self.parse_sheet_rows(csv_data, day_name) + all_raw_records.extend([(r, sheet_cfg['day_idx']) for r in rows]) + stats['by_day'][day_name] = { + 'gid': sheet_cfg['gid'], + 'rows_count': len(rows), + 'status': 'OK' + } + except Exception as e: + err_msg = f"Error al descargar o procesar la hoja de {day_name}: {str(e)}" + stats['errors'].append(err_msg) + stats['by_day'][day_name] = { + 'gid': sheet_cfg['gid'], + 'rows_count': 0, + 'status': 'Error', + 'error': str(e) + } stats['total_rows_processed'] = len(all_raw_records) if not all_raw_records: @@ -581,13 +709,15 @@ class GoogleSheetsImporter: career = careers_cache.get(c_key) if not career: career = Career.query.filter(Career.name.ilike(c_name)).first() - if not career: + if not career and import_careers: career = Career(name=c_name) db.session.add(career) db.session.flush() stats['careers_created'] += 1 - careers_cache[c_key] = career - career_objs.append(career) + if career: + careers_cache[c_key] = career + if career: + career_objs.append(career) primary_career = career_objs[0] if career_objs else None @@ -599,23 +729,27 @@ class GoogleSheetsImporter: classroom = classrooms_cache.get(room_key) b_entity = buildings_cache.get(room_info['building'].upper()) if not classroom: - classroom = Classroom( - building=room_info['building'], - building_id=b_entity.id if b_entity else None, - floor=room_info['floor'], - capacity=room_info['capacity'], - description=room_info['description'], - is_active=True - ) - classroom.code = room_info['code'] - db.session.add(classroom) - db.session.flush() - classrooms_cache[room_key] = classroom - stats['classrooms_created'] += 1 + if import_classrooms: + classroom = Classroom( + building=room_info['building'], + building_id=b_entity.id if b_entity else None, + floor=room_info['floor'], + capacity=room_info['capacity'], + description=room_info['description'], + is_active=True + ) + classroom.code = room_info['code'] + db.session.add(classroom) + db.session.flush() + classrooms_cache[room_key] = classroom + stats['classrooms_created'] += 1 + else: + classroom = Classroom.query.filter_by(code=room_info['code']).first() else: - classroom.capacity = max(classroom.capacity, room_info['capacity']) - if not classroom.building_id and b_entity: - classroom.building_id = b_entity.id + if import_classrooms: + classroom.capacity = max(classroom.capacity, room_info['capacity']) + if not classroom.building_id and b_entity: + classroom.building_id = b_entity.id # 3. Upsert Subject (Soporte Many-to-Many con múltiples carreras y subcódigos) subject_key = codigo.upper() @@ -638,76 +772,84 @@ class GoogleSheetsImporter: department_str = ", ".join([c.name for c in career_objs]) if career_objs else (primary_career.name if primary_career else 'General') if not subject: - subject = Subject( - code=codigo, - name=asignatura, - career_id=primary_career.id if primary_career else None, - department=department_str, - credits=4, - is_active=True - ) - subject.careers = career_objs - db.session.add(subject) - db.session.flush() - stats['subjects_created'] += 1 + if import_subjects: + subject = Subject( + code=codigo, + name=asignatura, + career_id=primary_career.id if primary_career else None, + department=department_str, + credits=4, + is_active=True + ) + if career_objs: + subject.careers = career_objs + db.session.add(subject) + db.session.flush() + stats['subjects_created'] += 1 else: - if subject.name != asignatura: - subject.name = asignatura - stats['subjects_updated'] += 1 - # Vincular todas las carreras a la asignatura sin duplicados - for c_obj in career_objs: - if c_obj not in subject.careers: - subject.careers.append(c_obj) - if not subject.career_id and primary_career: - subject.career_id = primary_career.id - subject.department = ", ".join([c.name for c in subject.careers]) if subject.careers else department_str + if import_subjects: + if subject.name != asignatura: + subject.name = asignatura + stats['subjects_updated'] += 1 + # Vincular todas las carreras a la asignatura sin duplicados + for c_obj in career_objs: + if c_obj not in subject.careers: + subject.careers.append(c_obj) + if not subject.career_id and primary_career: + subject.career_id = primary_career.id + subject.department = ", ".join([c.name for c in subject.careers]) if subject.careers else department_str - # Registrar en caché con código completo y con subcódigos individuales - subjects_cache[subject_key] = subject - for sc in sub_codes: - subjects_cache[sc.upper()] = subject + # Registrar en caché con código completo y con subcódigos individuales si existe + if subject: + subjects_cache[subject_key] = subject + for sc in sub_codes: + subjects_cache[sc.upper()] = subject # 4. Upsert Commission - comm_code = 'C1' - if '-E' in codigo: - comm_code = codigo.split('-')[-1] - elif '-0' in codigo: - comm_code = 'C' + codigo.split('-')[-1] - - commission = Commission.query.filter_by( - subject_id=subject.id, - code=comm_code, - semester='2026-2', - year=2026 - ).first() - - if not commission: - commission = Commission( + commission = None + if subject: + comm_code = 'C1' + if '-E' in codigo: + comm_code = codigo.split('-')[-1] + elif '-0' in codigo: + comm_code = 'C' + codigo.split('-')[-1] + + commission = Commission.query.filter_by( subject_id=subject.id, code=comm_code, semester='2026-2', - year=2026, - teacher_id=default_user_id, - max_students=classroom.capacity if classroom else 35, - current_students=0, - schedule=f"{dia} {horario_raw}", - shift=turno, - active=True - ) - db.session.add(commission) - db.session.flush() - stats['commissions_created'] += 1 - else: - commission.schedule = f"{dia} {horario_raw}" - commission.shift = turno - if classroom: - commission.max_students = max(commission.max_students or 0, classroom.capacity) + year=2026 + ).first() + + if not commission: + if import_commissions: + commission = Commission( + subject_id=subject.id, + code=comm_code, + semester='2026-2', + year=2026, + teacher_id=default_user_id, + max_students=classroom.capacity if classroom else 35, + current_students=0, + schedule=f"{dia} {horario_raw}", + shift=turno, + active=True + ) + db.session.add(commission) + db.session.flush() + stats['commissions_created'] += 1 + else: + if import_commissions: + commission.schedule = f"{dia} {horario_raw}" + commission.shift = turno + if classroom: + commission.max_students = max(commission.max_students or 0, classroom.capacity) # 5. Generar Reservas de Calendario t_start, t_end = self.parse_time_range(horario_raw) effective_day_idx = day_idx if day_idx is not None else (manual_dt.weekday() if manual_dt else 0) - if classroom and t_start and t_end: + if import_reservations and classroom and subject and commission and t_start and t_end: is_room_virtual = bool(classroom.is_virtual or 'VIRTUAL' in (classroom.code or '').upper()) v_link = None @@ -718,9 +860,22 @@ class GoogleSheetsImporter: if not commission.virtual_link: commission.virtual_link = v_link - # Determinar fechas a generar: puntual o 16 semanas + # Determinar fechas a generar: específica de la fila (datepicker), puntual o 16 semanas dates_to_generate = [] - if single_date_only and manual_dt: + row_specific_date = None + raw_row_date = rec.get('date') or rec.get('inferred_date') + if raw_row_date: + try: + if isinstance(raw_row_date, (datetime, date)): + row_specific_date = raw_row_date if isinstance(raw_row_date, date) else raw_row_date.date() + elif isinstance(raw_row_date, str) and raw_row_date.strip(): + row_specific_date = datetime.strptime(raw_row_date.strip(), '%Y-%m-%d').date() + except Exception: + pass + + if row_specific_date: + dates_to_generate = [row_specific_date] + elif single_date_only and manual_dt: dates_to_generate = [manual_dt] else: dates_to_generate = [base_monday + timedelta(days=effective_day_idx, weeks=w) for w in range(weeks_to_generate)] diff --git a/backend/setup.py b/backend/setup.py index 53b3077..3d46df7 100644 --- a/backend/setup.py +++ b/backend/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="edu-space-admin", - version="3.4.2", + version="3.4.3", description="Administrative interface for Edu-Space Classroom Management System", author="Edu-Space Development Team", author_email="admin@edu-space.com", diff --git a/frontend/package.json b/frontend/package.json index 567eabd..cbd1669 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "3.4.2", + "version": "3.4.3", "description": "", "main": "index.js", "scripts": { diff --git a/frontend/src/app.js b/frontend/src/app.js index 55c7d12..9fab616 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -85,9 +85,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), { }); // Versiones institucionales del sistema -const APP_VERSION = '3.4.2'; -const FRONTEND_VERSION = '3.4.2'; -const BACKEND_VERSION = '3.4.2'; +const APP_VERSION = '3.4.3'; +const FRONTEND_VERSION = '3.4.3'; +const BACKEND_VERSION = '3.4.3'; env.addGlobal('app_version', APP_VERSION); env.addGlobal('frontend_version', FRONTEND_VERSION); diff --git a/frontend/src/routes/admin.js b/frontend/src/routes/admin.js index ab35287..59e74c1 100644 --- a/frontend/src/routes/admin.js +++ b/frontend/src/routes/admin.js @@ -91,10 +91,28 @@ const handleGoogleSheetsImport = async (req, res, justSynced = false) => { if (req.body.filter_career) syncPayload.filter_career = req.body.filter_career.trim(); if (req.body.filter_subject) syncPayload.filter_subject = req.body.filter_subject.trim(); if (req.body.filter_day) syncPayload.filter_day = req.body.filter_day.trim(); + if (req.body.filter_days) { + syncPayload.filter_days = Array.isArray(req.body.filter_days) ? req.body.filter_days : [req.body.filter_days]; + } if (req.body.manual_date) syncPayload.manual_date = req.body.manual_date.trim(); if (req.body.single_date_only === 'true' || req.body.single_date_only === true || req.body.single_date_only === 'on') { syncPayload.single_date_only = true; } + // 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'; + syncPayload.import_commissions = req.body.import_commissions === 'true' || req.body.import_commissions === true || req.body.import_commissions === 'on'; + syncPayload.import_classrooms = req.body.import_classrooms === 'true' || req.body.import_classrooms === true || req.body.import_classrooms === 'on'; + syncPayload.import_reservations = req.body.import_reservations === 'true' || req.body.import_reservations === true || req.body.import_reservations === 'on'; + + // Filas preseleccionadas desde la grilla interactiva + if (req.body.selected_rows_json) { + try { + syncPayload.selected_rows = JSON.parse(req.body.selected_rows_json); + } catch (e) { + console.warn('Could not parse selected_rows_json:', e.message); + } + } } const syncRes = await req.apiClient.post('/dashboard/sync-sheets', syncPayload, { timeout: 90000 }); if (syncRes.data && syncRes.data.stats) { @@ -143,6 +161,7 @@ const handleGoogleSheetsImport = async (req, res, justSynced = false) => { filter_career: req.body?.filter_career || '', filter_subject: req.body?.filter_subject || '', filter_day: req.body?.filter_day || '', + 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', flash_msg: flashMsg, @@ -161,10 +180,15 @@ router.post(['/google_sheets_import', '/import'], (req, res) => handleGoogleShee router.post('/sheets_inspect', async (req, res) => { try { const payload = {}; - if (req.body && req.body.sheets_url) { - payload.sheets_url = req.body.sheets_url; + if (req.body) { + if (req.body.sheets_url) payload.sheets_url = req.body.sheets_url; + if (req.body.filter_career) payload.filter_career = req.body.filter_career; + if (req.body.filter_subject) payload.filter_subject = req.body.filter_subject; + if (req.body.filter_day) payload.filter_day = req.body.filter_day; + if (req.body.filter_days) payload.filter_days = req.body.filter_days; + if (req.body.manual_date) payload.manual_date = req.body.manual_date; } - const resp = await req.apiClient.post('/dashboard/sheets-inspect', payload, { timeout: 35000 }); + const resp = await req.apiClient.post('/dashboard/sheets-inspect', payload, { timeout: 45000 }); res.json(resp.data); } catch (err) { console.error('Error inspecting sheets in BFF:', err.response?.data || err.message); diff --git a/frontend/views/admin/import.html b/frontend/views/admin/import.html index 4cdb635..2bde095 100644 --- a/frontend/views/admin/import.html +++ b/frontend/views/admin/import.html @@ -168,29 +168,107 @@ -
+ + -
- -
-