diff --git a/backend/app/routes/api/admin.py b/backend/app/routes/api/admin.py index 67e18bb..1cd9e38 100644 --- a/backend/app/routes/api/admin.py +++ b/backend/app/routes/api/admin.py @@ -213,6 +213,8 @@ def get_commissions(): elif active == 'false': query = query.filter(Commission.active == False) + unassigned_room = request.args.get('unassigned_room', '').strip().lower() + commissions = query.order_by(Commission.id.asc()).all() subjects = Subject.query.order_by(Subject.name.asc()).all() @@ -220,6 +222,13 @@ def get_commissions(): careers = Career.query.order_by(Career.name.asc()).all() careers_data = [{'id': cr.id, 'name': cr.name, 'code': cr.code} for cr in careers] + # Pre-cargar reservas activas para enriquecer con asignación de aula + reservations_by_comm = {} + all_res = Reservation.query.filter(Reservation.commission_id.isnot(None)).order_by(Reservation.start_time.asc()).all() + for r in all_res: + if r.commission_id not in reservations_by_comm: + reservations_by_comm[r.commission_id] = r + commissions_data = [] for c in commissions: if search: @@ -228,11 +237,25 @@ def get_commissions(): if search not in s_name and search not in c_code: continue + res = reservations_by_comm.get(c.id) + c_room = res.classroom if res else None + c_code_val = c_room.code if c_room else None + is_virt_room = bool(c_room.is_virtual or 'virtual' in (c_room.code or '').lower() or 'virtual' in (c_room.building or '').lower()) if c_room else False + has_v_link = bool(c.virtual_link and c.virtual_link.strip()) + has_classroom = bool(c_code_val or has_v_link) + + if unassigned_room in ['true', '1'] and has_classroom: + continue + if unassigned_room in ['false', '0'] and not has_classroom: + continue + career_name = c.career_name if hasattr(c, 'career_name') else 'Carrera General' career_names = c.career_names if hasattr(c, 'career_names') else career_name careers_list = c.careers if hasattr(c, 'careers') else [] career_id_val = c.career_id if hasattr(c, 'career_id') else (c.subject.career_id if c.subject else None) + display_room = c_code_val or ('Campus Virtual' if has_v_link else 'Sin Aula') + commissions_data.append({ 'id': c.id, 'code': c.code, @@ -256,7 +279,11 @@ def get_commissions(): 'max_students': c.max_students or 35, 'current_students': getattr(c, 'current_students', 0) or 0, 'active': c.active, - 'virtual_link': getattr(c, 'virtual_link', '') or '' + 'virtual_link': getattr(c, 'virtual_link', '') or '', + 'has_classroom': has_classroom, + 'classroom_name': display_room, + 'classroom_code': c_code_val, + 'is_virtual': is_virt_room or has_v_link }) subjects_data = [] diff --git a/backend/app/routes/api/dashboard.py b/backend/app/routes/api/dashboard.py index e7763ae..a040dfd 100644 --- a/backend/app/routes/api/dashboard.py +++ b/backend/app/routes/api/dashboard.py @@ -150,7 +150,7 @@ def get_stats(): upcoming_reservations = [serialize_reservation(r) for r in upcoming_reservations_q] milestones = [serialize_milestone(m) for m in milestones_q] - # ---- Bedelía: Comisiones sin aula asignada (semana y mes) ---- + # ---- Bedelía: Comisiones sin aula asignada (semana, mes y general) ---- import calendar # Calcular rango de semana actual (lunes a domingo) today_dt = datetime.utcnow() @@ -158,6 +158,13 @@ def get_stats(): week_start = week_start.replace(hour=0, minute=0, second=0, microsecond=0) week_end = week_start + timedelta(days=6, hours=23, minutes=59, seconds=59) + # Reservas de la semana actual completa para Bedelía + week_reservations_q = Reservation.query.filter( + Reservation.start_time >= week_start, + Reservation.start_time <= week_end + ).order_by(Reservation.start_time.asc()).all() + week_schedule_list = [serialize_reservation(r) for r in week_reservations_q] + # Calcular rango del mes actual month_start = today_dt.replace(day=1, hour=0, minute=0, second=0, microsecond=0) last_day = calendar.monthrange(today_dt.year, today_dt.month)[1] @@ -183,10 +190,18 @@ def get_stats(): Reservation.start_time <= month_end ).distinct().all() ) + # IDs de comisiones que tienen AL MENOS una reserva en general + comm_ids_with_any_res = set( + r[0] for r in db.session.query(Reservation.commission_id).filter( + Reservation.commission_id.isnot(None) + ).distinct().all() + ) unassigned_commissions_week = [] unassigned_commissions_month = [] + unassigned_commissions_general = [] for comm in all_active_commissions: + has_v_link = bool(comm.virtual_link and comm.virtual_link.strip()) comm_data = { 'id': comm.id, 'code': comm.code, @@ -197,14 +212,24 @@ def get_stats(): 'schedule': comm.schedule or 'Sin horario', 'shift': comm.shift or 'Sin turno', 'max_students': comm.max_students, - 'current_students': comm.current_students + 'current_students': comm.current_students, + 'virtual_link': comm.virtual_link or '', + 'has_virtual_link': has_v_link } if comm.id not in comm_ids_with_res_week: unassigned_commissions_week.append(comm_data) if comm.id not in comm_ids_with_res_month: unassigned_commissions_month.append(comm_data) + if comm.id not in comm_ids_with_any_res and not has_v_link: + unassigned_commissions_general.append(comm_data) - # ---- Bedelía: Aulas disponibles (sin reservas) en la semana y mes ---- + # ---- Bedelía: Aulas disponibles (sin reservas) hoy, semana y mes ---- + classroom_ids_used_today = set( + r[0] for r in db.session.query(Reservation.classroom_id).filter( + Reservation.classroom_id.isnot(None), + func.date(Reservation.start_time) == today + ).distinct().all() + ) classroom_ids_used_week = set( r[0] for r in db.session.query(Reservation.classroom_id).filter( Reservation.classroom_id.isnot(None), @@ -220,6 +245,7 @@ def get_stats(): ).distinct().all() ) + available_classrooms_today = [] available_classrooms_week = [] available_classrooms_month = [] for c in all_active_classrooms: @@ -231,6 +257,8 @@ def get_stats(): 'capacity': c.capacity, 'is_virtual': getattr(c, 'is_virtual', False) or 'virtual' in (c.building or '').lower() or 'virtual' in (c.code or '').lower() } + if c.id not in classroom_ids_used_today: + available_classrooms_today.append(c_data) if c.id not in classroom_ids_used_week: available_classrooms_week.append(c_data) if c.id not in classroom_ids_used_month: @@ -257,9 +285,12 @@ def get_stats(): audit_data = [] pending_reservations = [] today_schedule_list = [] + week_schedule_list = [] upcoming_reservations = [] unassigned_commissions_week = [] unassigned_commissions_month = [] + unassigned_commissions_general = [] + available_classrooms_today = [] available_classrooms_week = [] available_classrooms_month = [] total_active_commissions = 0 @@ -306,6 +337,7 @@ def get_stats(): 'monthly_data': monthly_data, 'pending_reservations': pending_reservations, 'today_schedule_list': today_schedule_list, + 'week_schedule_list': week_schedule_list, 'upcoming_reservations': upcoming_reservations, 'milestones': milestones, 'ui': { @@ -314,6 +346,8 @@ def get_stats(): 'bedelia': { 'unassigned_commissions_week': unassigned_commissions_week, 'unassigned_commissions_month': unassigned_commissions_month, + 'unassigned_commissions_general': unassigned_commissions_general, + 'available_classrooms_today': available_classrooms_today, 'available_classrooms_week': available_classrooms_week, 'available_classrooms_month': available_classrooms_month } diff --git a/backend/app/services/sheets_importer.py b/backend/app/services/sheets_importer.py index 4f4987b..e747865 100644 --- a/backend/app/services/sheets_importer.py +++ b/backend/app/services/sheets_importer.py @@ -426,7 +426,7 @@ class GoogleSheetsImporter: # Calculate current semester dates (anchored on academic year 2026) base_monday = date(2026, 8, 31) - weeks_to_generate = 4 # Generar reservas para 4 semanas consecutivas + weeks_to_generate = 16 # Generar reservas para 16 semanas (cuatrimestre completo Ago - Dic 2026) for rec, day_idx in all_raw_records: try: diff --git a/frontend/src/routes/admin.js b/frontend/src/routes/admin.js index 64c3519..dad7f91 100644 --- a/frontend/src/routes/admin.js +++ b/frontend/src/routes/admin.js @@ -833,6 +833,7 @@ const handleCommissionsList = async (req, res) => { const career_id = req.query.career_id || ''; const shift = req.query.shift || ''; const active = req.query.active || ''; + const unassigned_room = req.query.unassigned_room || ''; const created = req.query.created === '1'; let commissions = []; @@ -843,7 +844,7 @@ const handleCommissionsList = async (req, res) => { try { const [cRes, uRes] = await Promise.allSettled([ - req.apiClient.get('/commissions', { params: { search, subject_id, career_id, shift, active } }), + req.apiClient.get('/commissions', { params: { search, subject_id, career_id, shift, active, unassigned_room } }), req.apiClient.get('/users') ]); @@ -853,6 +854,11 @@ const handleCommissionsList = async (req, res) => { get_full_code: () => c.full_code || c.code, career_id: c.career_id, career_name: c.career_name || 'Carrera General', + classroom_name: c.classroom_name || 'Sin Aula Asignada', + has_classroom: Boolean(c.has_classroom), + is_virtual: Boolean(c.is_virtual), + virtual_link: c.virtual_link || '', + schedule: c.schedule || 'Sin horario', subject: { id: c.subject_id, name: c.subject_name, @@ -907,6 +913,7 @@ const handleCommissionsList = async (req, res) => { career_filter: career_id ? parseInt(career_id, 10) : '', shift_filter: shift, active_filter: active, + unassigned_room_filter: unassigned_room, created, msg: req.query.msg || (created ? 'created' : ''), error: req.query.error || '', diff --git a/frontend/src/routes/dashboard.js b/frontend/src/routes/dashboard.js index a14daa7..80de430 100644 --- a/frontend/src/routes/dashboard.js +++ b/frontend/src/routes/dashboard.js @@ -107,11 +107,15 @@ router.get('/', async (req, res) => { ] }; } else if (role === 'bedelia') { + const apiWeekSchedule = Array.isArray(apiData.week_schedule_list) ? apiData.week_schedule_list : []; role_data = { pending_reservations: apiPending || [], today_schedule_list: apiTodaySchedule || [], + week_schedule_list: apiWeekSchedule, unassigned_commissions_week: bedeliaData.unassigned_commissions_week || [], unassigned_commissions_month: bedeliaData.unassigned_commissions_month || [], + unassigned_commissions_general: bedeliaData.unassigned_commissions_general || [], + available_classrooms_today: bedeliaData.available_classrooms_today || [], available_classrooms_week: bedeliaData.available_classrooms_week || [], available_classrooms_month: bedeliaData.available_classrooms_month || [] }; diff --git a/frontend/src/routes/schedule.js b/frontend/src/routes/schedule.js index cbd76b6..6352822 100644 --- a/frontend/src/routes/schedule.js +++ b/frontend/src/routes/schedule.js @@ -164,11 +164,21 @@ router.get('/list_reservations', handleReservationsList); // 4. Vista de Hoy (Cartelera del Día) const handleTodaySchedule = async (req, res) => { try { - const todayStr = req.query.date || '2026-09-18'; + const defaultTodayStr = new Date().toISOString().split('T')[0]; + const todayStr = req.query.date || defaultTodayStr; const hide_virtual = req.query.hide_virtual === '1' || req.query.hide_virtual === 'true'; const floor_filter = req.query.floor || ''; const shift_filter = req.query.shift || ''; + // Fechas anterior y siguiente para navegación + const currentDateObj = new Date(todayStr + 'T00:00:00'); + const prevDateObj = new Date(currentDateObj); + prevDateObj.setDate(prevDateObj.getDate() - 1); + const nextDateObj = new Date(currentDateObj); + nextDateObj.setDate(nextDateObj.getDate() + 1); + const prevDateStr = prevDateObj.toISOString().split('T')[0]; + const nextDateStr = nextDateObj.toISOString().split('T')[0]; + const params = { start_date: todayStr, end_date: todayStr @@ -238,6 +248,9 @@ const handleTodaySchedule = async (req, res) => { time_blocks, stats, today: todayStr, + prev_date: prevDateStr, + next_date: nextDateStr, + default_today: defaultTodayStr, hide_virtual, floor_filter, shift_filter, @@ -246,12 +259,16 @@ const handleTodaySchedule = async (req, res) => { }); } catch (error) { console.error('Error fetching today reservations:', error.message); + const fallbackToday = new Date().toISOString().split('T')[0]; res.render('schedule/today', { title: 'Cartelera del Día (Offline)', reservations: [], time_blocks: {}, stats: { total_reservations: 0, confirmed: 0, pending: 0, occupied_classrooms: 0, total_classrooms: 59 }, - today: '2026-09-18', + today: fallbackToday, + prev_date: fallbackToday, + next_date: fallbackToday, + default_today: fallbackToday, hide_virtual: false, floor_filter: '', shift_filter: '', diff --git a/frontend/views/admin/commissions/list.html b/frontend/views/admin/commissions/list.html index bed7154..1395cfa 100644 --- a/frontend/views/admin/commissions/list.html +++ b/frontend/views/admin/commissions/list.html @@ -134,6 +134,16 @@ {% endfor %} +