feat(v3.4.7): add interactive floors and classrooms panel in building edit and preselect room creation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "3.4.6",
|
||||
"version": "3.4.7",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
+3
-3
@@ -85,9 +85,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), {
|
||||
});
|
||||
|
||||
// Versiones institucionales del sistema
|
||||
const APP_VERSION = '3.4.6';
|
||||
const FRONTEND_VERSION = '3.4.6';
|
||||
const BACKEND_VERSION = '3.4.6';
|
||||
const APP_VERSION = '3.4.7';
|
||||
const FRONTEND_VERSION = '3.4.7';
|
||||
const BACKEND_VERSION = '3.4.7';
|
||||
|
||||
env.addGlobal('app_version', APP_VERSION);
|
||||
env.addGlobal('frontend_version', FRONTEND_VERSION);
|
||||
|
||||
@@ -180,36 +180,149 @@ router.get(['/view/:id', '/view_building', '/:id'], async (req, res) => {
|
||||
floors_display: is_virtual ? 'Digital' : String(building.floors ?? 1)
|
||||
};
|
||||
|
||||
// Agrupación dinámica por piso / nivel
|
||||
// Función auxiliar para agrupar y sintetizar los pisos / niveles físicos y sus aulas
|
||||
const buildFloorsList = (building, classrooms = []) => {
|
||||
const is_virtual = Boolean(building.is_virtual || (building.code && building.code.toUpperCase() === 'VIRTUAL') || (building.name && building.name.toUpperCase().includes('VIRTUAL')));
|
||||
if (is_virtual) {
|
||||
return [{
|
||||
floor_code: 'Digital',
|
||||
floor_name: 'Campus Virtual (Digital)',
|
||||
classrooms: classrooms,
|
||||
total_capacity: 0,
|
||||
classrooms_count: classrooms.length
|
||||
}];
|
||||
}
|
||||
|
||||
const floorsMap = new Map();
|
||||
|
||||
// 1. Incorporar todas las aulas reales existentes agrupadas por su piso
|
||||
classrooms.forEach(c => {
|
||||
const floorKey = c.floor_display || (c.floor === '0' || c.floor === 'PB' ? 'Planta Baja (PB)' : (c.floor ? (c.floor.toLowerCase().startsWith('piso') ? c.floor : `Piso ${c.floor}`) : 'Planta Baja (PB)'));
|
||||
if (!floorsMap.has(floorKey)) {
|
||||
floorsMap.set(floorKey, []);
|
||||
let code = String(c.floor !== undefined && c.floor !== null ? c.floor : 'PB').trim();
|
||||
let name = c.floor_display;
|
||||
if (!name) {
|
||||
const fLower = code.toLowerCase();
|
||||
if (code === '0' || code.toUpperCase() === 'PB' || fLower.includes('planta baja')) {
|
||||
name = 'Planta Baja (PB)';
|
||||
code = 'PB';
|
||||
} else if (code.toUpperCase() === 'EP' || fLower.includes('entrepiso')) {
|
||||
name = 'Entrepiso (EP)';
|
||||
code = 'EP';
|
||||
} else if (code.toUpperCase() === 'SS' || fLower.includes('subsuelo')) {
|
||||
name = 'Subsuelo (SS)';
|
||||
code = 'SS';
|
||||
} else if (fLower.startsWith('piso')) {
|
||||
name = code;
|
||||
} else if (/^\d+$/.test(code)) {
|
||||
name = `Piso ${code}`;
|
||||
} else {
|
||||
name = code;
|
||||
}
|
||||
}
|
||||
floorsMap.get(floorKey).push(c);
|
||||
if (!floorsMap.has(code)) {
|
||||
floorsMap.set(code, {
|
||||
floor_code: code,
|
||||
floor_name: name,
|
||||
classrooms: [],
|
||||
total_capacity: 0
|
||||
});
|
||||
}
|
||||
const fEntry = floorsMap.get(code);
|
||||
fEntry.classrooms.push(c);
|
||||
fEntry.total_capacity += (c.capacity || 0);
|
||||
});
|
||||
|
||||
const sortedFloorKeys = Array.from(floorsMap.keys()).sort((a, b) => {
|
||||
const fA = String(a).toUpperCase();
|
||||
const fB = String(b).toUpperCase();
|
||||
if (fA.includes('SUB') || fA.includes('SS')) return -1;
|
||||
if (fB.includes('SUB') || fB.includes('SS')) return 1;
|
||||
if (fA.includes('PB') || fA.includes('PLANTA BAJA')) return -1;
|
||||
if (fB.includes('PB') || fB.includes('PLANTA BAJA')) return 1;
|
||||
if (fA.includes('EP') || fA.includes('ENTRE')) return -1;
|
||||
if (fB.includes('EP') || fB.includes('ENTRE')) return 1;
|
||||
return fA.localeCompare(fB, undefined, { numeric: true });
|
||||
// 2. Si el edificio tiene floors > 0, asegurar niveles básicos esperados (PB y Pisos 1..N)
|
||||
const numFloors = parseInt(building.floors, 10) || 1;
|
||||
if (numFloors >= 1 && !floorsMap.has('PB') && !floorsMap.has('0')) {
|
||||
floorsMap.set('PB', {
|
||||
floor_code: 'PB',
|
||||
floor_name: 'Planta Baja (PB)',
|
||||
classrooms: [],
|
||||
total_capacity: 0
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 1; i < numFloors; i++) {
|
||||
const floorStr = String(i);
|
||||
if (!floorsMap.has(floorStr)) {
|
||||
floorsMap.set(floorStr, {
|
||||
floor_code: floorStr,
|
||||
floor_name: `Piso ${i}`,
|
||||
classrooms: [],
|
||||
total_capacity: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (numFloors === 1 && floorsMap.size === 0) {
|
||||
floorsMap.set('PB', {
|
||||
floor_code: 'PB',
|
||||
floor_name: 'Planta Baja (PB)',
|
||||
classrooms: [],
|
||||
total_capacity: 0
|
||||
});
|
||||
}
|
||||
|
||||
// Ordenar pisos: Subsuelos primero, Planta Baja, Entrepisos, luego numéricos
|
||||
const sortedFloors = Array.from(floorsMap.values()).sort((a, b) => {
|
||||
const cA = String(a.floor_code).toUpperCase();
|
||||
const cB = String(b.floor_code).toUpperCase();
|
||||
const nA = String(a.floor_name).toUpperCase();
|
||||
const nB = String(b.floor_name).toUpperCase();
|
||||
|
||||
if (cA.includes('SUB') || cA.includes('SS') || nA.includes('SUB')) return -1;
|
||||
if (cB.includes('SUB') || cB.includes('SS') || nB.includes('SUB')) return 1;
|
||||
if (cA === 'PB' || cA === '0' || nA.includes('PLANTA BAJA')) return -1;
|
||||
if (cB === 'PB' || cB === '0' || nB.includes('PLANTA BAJA')) return 1;
|
||||
if (cA === 'EP' || nA.includes('ENTRE')) return -1;
|
||||
if (cB === 'EP' || nB.includes('ENTRE')) return 1;
|
||||
|
||||
const numA = parseInt(a.floor_code, 10);
|
||||
const numB = parseInt(b.floor_code, 10);
|
||||
if (!isNaN(numA) && !isNaN(numB)) return numA - numB;
|
||||
|
||||
return a.floor_name.localeCompare(b.floor_name, undefined, { numeric: true });
|
||||
});
|
||||
|
||||
const floors_list = sortedFloorKeys.map(floorName => ({
|
||||
floor_name: floorName,
|
||||
classrooms: floorsMap.get(floorName)
|
||||
}));
|
||||
sortedFloors.forEach(f => {
|
||||
f.classrooms_count = f.classrooms.length;
|
||||
});
|
||||
|
||||
return sortedFloors;
|
||||
};
|
||||
|
||||
// 3. View Building
|
||||
router.get(['/view/:id', '/view_building', '/:id'], async (req, res) => {
|
||||
const id = parseInt(req.params.id || req.query.id, 10) || 1;
|
||||
let building = null;
|
||||
let classrooms = [];
|
||||
|
||||
try {
|
||||
const apiRes = await req.apiClient.get(`/buildings/${id}`);
|
||||
if (apiRes.data && apiRes.data.building) {
|
||||
building = apiRes.data.building;
|
||||
classrooms = apiRes.data.classrooms || [];
|
||||
}
|
||||
} catch (e) {
|
||||
building = defaultBuildings.find(b => b.id === id) || defaultBuildings[0];
|
||||
}
|
||||
|
||||
if (!building) {
|
||||
return res.redirect('/buildings/list_buildings');
|
||||
}
|
||||
|
||||
const is_virtual = Boolean(building.is_virtual || (building.code && building.code.toUpperCase() === 'VIRTUAL') || (building.name && building.name.toUpperCase().includes('VIRTUAL')));
|
||||
building = {
|
||||
...building,
|
||||
is_virtual,
|
||||
capacity_display: is_virtual ? 'Ilimitada (Virtual)' : String(building.physical_capacity || building.total_capacity || 0),
|
||||
floors_display: is_virtual ? 'Digital' : String(building.floors ?? 1)
|
||||
};
|
||||
|
||||
const floors_list = buildFloorsList(building, classrooms);
|
||||
const classrooms_by_floor = {};
|
||||
floorsMap.forEach((rooms, floorName) => {
|
||||
classrooms_by_floor[floorName] = rooms;
|
||||
floors_list.forEach(f => {
|
||||
classrooms_by_floor[f.floor_name] = f.classrooms;
|
||||
});
|
||||
|
||||
res.render('buildings/view', {
|
||||
@@ -225,11 +338,13 @@ router.get(['/view/:id', '/view_building', '/:id'], async (req, res) => {
|
||||
const handleEditBuildingGet = async (req, res) => {
|
||||
const id = parseInt(req.params.id || req.query.id, 10) || 1;
|
||||
let building = null;
|
||||
let classrooms = [];
|
||||
|
||||
try {
|
||||
const apiRes = await req.apiClient.get(`/buildings/${id}`);
|
||||
if (apiRes.data && apiRes.data.building) {
|
||||
building = apiRes.data.building;
|
||||
classrooms = apiRes.data.classrooms || [];
|
||||
}
|
||||
} catch (e) {
|
||||
building = defaultBuildings.find(b => b.id === id) || defaultBuildings[0];
|
||||
@@ -239,6 +354,17 @@ const handleEditBuildingGet = async (req, res) => {
|
||||
return res.redirect('/buildings/list_buildings');
|
||||
}
|
||||
|
||||
const is_virtual = Boolean(building.is_virtual || (building.code && building.code.toUpperCase() === 'VIRTUAL') || (building.name && building.name.toUpperCase().includes('VIRTUAL')));
|
||||
building = {
|
||||
...building,
|
||||
is_virtual,
|
||||
capacity_display: is_virtual ? 'Ilimitada (Virtual)' : String(building.physical_capacity || building.total_capacity || 0),
|
||||
floors_display: is_virtual ? 'Digital' : String(building.floors ?? 1)
|
||||
};
|
||||
|
||||
const floors_list = buildFloorsList(building, classrooms);
|
||||
const total_physical_capacity = is_virtual ? 0 : classrooms.reduce((acc, c) => acc + (c.capacity || 0), 0);
|
||||
|
||||
const form = createFormMock({
|
||||
name: building.name,
|
||||
code: building.code,
|
||||
@@ -251,6 +377,9 @@ const handleEditBuildingGet = async (req, res) => {
|
||||
res.render('buildings/form', {
|
||||
title: `Editar Edificio - ${building.name}`,
|
||||
building,
|
||||
classrooms,
|
||||
floors_list,
|
||||
total_physical_capacity,
|
||||
form
|
||||
});
|
||||
};
|
||||
|
||||
@@ -350,9 +350,14 @@ const handleAddClassroom = async (req, res) => {
|
||||
{ value: 'new', text: '+ Crear nuevo edificio / sede' }
|
||||
];
|
||||
|
||||
const preselectedBuildingId = req.query.building_id || '';
|
||||
const preselectedFloor = req.query.floor || '';
|
||||
|
||||
const form = createFormMock({
|
||||
is_active: true,
|
||||
capacity: 35
|
||||
capacity: 35,
|
||||
building_id: preselectedBuildingId,
|
||||
floor: preselectedFloor
|
||||
}, {
|
||||
building_id: buildingOptions
|
||||
});
|
||||
@@ -361,7 +366,9 @@ const handleAddClassroom = async (req, res) => {
|
||||
title: 'Add Classroom - Edu-Space Admin',
|
||||
form,
|
||||
buildings,
|
||||
building_floors: buildingFloors
|
||||
building_floors: buildingFloors,
|
||||
preselected_building_id: preselectedBuildingId,
|
||||
preselected_floor: preselectedFloor
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error rendering add classroom:', error.message);
|
||||
|
||||
@@ -1127,7 +1127,7 @@
|
||||
|
||||
<div class="sidebar-footer-text mt-3 pt-2 border-top border-secondary-subtle text-center">
|
||||
<span class="badge bg-secondary-subtle text-secondary-emphasis font-monospace px-2 py-1" style="font-size:0.68rem;" title="Versión Institucional de Edu-Space">
|
||||
<i class="bi bi-tag-fill me-1"></i>v{{ app_version or '3.4.6' }} <span class="opacity-75">(FE: {{ frontend_version or '3.4.6' }} · BE: {{ backend_version or '3.4.6' }})</span>
|
||||
<i class="bi bi-tag-fill me-1"></i>v{{ app_version or '3.4.7' }} <span class="opacity-75">(FE: {{ frontend_version or '3.4.7' }} · BE: {{ backend_version or '3.4.7' }})</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,25 +7,48 @@
|
||||
{% block content %}
|
||||
<div class="container-fluid pt-5 mt-4">
|
||||
<div class="row">
|
||||
<div class="col-lg-8 mx-auto">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="h3 mb-0">
|
||||
<i class="bi bi-buildings text-primary me-2"></i>
|
||||
{% if building %}Editar Edificio{% else %}Nuevo Edificio{% endif %}
|
||||
</h1>
|
||||
<a href="/buildings/list_buildings" class="btn btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left me-1"></i>Volver a Edificios
|
||||
</a>
|
||||
<div class="col-xl-9 col-lg-11 mx-auto">
|
||||
<!-- Breadcrumb y Encabezado Superior -->
|
||||
<div class="d-flex flex-wrap justify-content-between align-items-center mb-4 gap-2">
|
||||
<div>
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb mb-1 small">
|
||||
<li class="breadcrumb-item"><a href="/buildings/list_buildings" class="text-decoration-none">Edificios</a></li>
|
||||
{% if building %}
|
||||
<li class="breadcrumb-item"><a href="/buildings/view/{{ building.id }}" class="text-decoration-none">{{ building.name }}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Editar</li>
|
||||
{% else %}
|
||||
<li class="breadcrumb-item active" aria-current="page">Nuevo Edificio</li>
|
||||
{% endif %}
|
||||
</ol>
|
||||
</nav>
|
||||
<h1 class="h3 mb-0">
|
||||
<i class="bi bi-buildings text-primary me-2"></i>
|
||||
{% if building %}Editar Edificio: <span class="text-primary">{{ building.name }}</span>{% else %}Nuevo Edificio{% endif %}
|
||||
</h1>
|
||||
<p class="text-muted small mb-0 mt-1">Configura los datos de la sede, gestiona sus plantas físicas y administra sus aulas asociadas.</p>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
{% if building %}
|
||||
<a href="/buildings/view/{{ building.id }}" class="btn btn-outline-primary btn-sm">
|
||||
<i class="bi bi-eye me-1"></i>Ver Ficha de la Sede
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="/buildings/list_buildings" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="bi bi-arrow-left me-1"></i>Volver a Edificios
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<!-- Card 1: Formulario Principal del Edificio -->
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-header bg-body-tertiary border-0 py-3">
|
||||
<h5 class="mb-0 h6 fw-bold">
|
||||
<i class="bi bi-info-circle text-primary me-2"></i>Información del Edificio / Sede
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<form method="POST" action="{% if building %}/buildings/edit/{{ building.id }}{% else %}/buildings/add_building{% endif %}" novalidate>
|
||||
<form method="POST" action="{% if building %}/buildings/edit/{{ building.id }}{% else %}/buildings/add_building{% endif %}" id="buildingForm" novalidate>
|
||||
{% if building %}
|
||||
<input type="hidden" name="id" value="{{ building.id }}">
|
||||
{% endif %}
|
||||
@@ -33,7 +56,7 @@
|
||||
<div class="row g-3">
|
||||
<div class="col-md-8">
|
||||
{{ form.name.label(class="form-label fw-semibold") }}
|
||||
{{ form.name(class="form-control" + (" is-invalid" if form.name.errors else ""), placeholder="ej. Edificio Central, Pabellón de Ciencias, Sede Norte") }}
|
||||
{{ form.name(class="form-control" + (" is-invalid" if form.name.errors else ""), id="buildingNameInput", placeholder="ej. Edificio Central, Pabellón de Ciencias, Sede Norte") }}
|
||||
{% if form.name.errors %}
|
||||
<div class="invalid-feedback">{{ form.name.errors[0] }}</div>
|
||||
{% endif %}
|
||||
@@ -41,28 +64,61 @@
|
||||
|
||||
<div class="col-md-4">
|
||||
{{ form.code.label(class="form-label fw-semibold") }}
|
||||
{{ form.code(class="form-control" + (" is-invalid" if form.code.errors else ""), placeholder="ej. CENTRAL, VIRTUAL, PAB-A") }}
|
||||
{{ form.code(class="form-control" + (" is-invalid" if form.code.errors else ""), id="buildingCodeInput", placeholder="ej. CENTRAL, VIRTUAL, PAB-A") }}
|
||||
{% if form.code.errors %}
|
||||
<div class="invalid-feedback">{{ form.code.errors[0] }}</div>
|
||||
{% endif %}
|
||||
<small class="text-muted">Código identificador corto</small>
|
||||
</div>
|
||||
|
||||
<div class="col-md-8">
|
||||
<div class="col-md-7">
|
||||
{{ form.address.label(class="form-label fw-semibold") }}
|
||||
{{ form.address(class="form-control" + (" is-invalid" if form.address.errors else ""), placeholder="ej. Av. Paseo Colón 255, CABA o campus.unicaba.edu.ar") }}
|
||||
{{ form.address(class="form-control" + (" is-invalid" if form.address.errors else ""), placeholder="ej. Tte. Gral. Juan Domingo Perón 802, CABA o campus.unicaba.edu.ar") }}
|
||||
{% if form.address.errors %}
|
||||
<div class="invalid-feedback">{{ form.address.errors[0] }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{{ form.floors.label(class="form-label fw-semibold") }}
|
||||
{{ form.floors(class="form-control" + (" is-invalid" if form.floors.errors else ""), min=0, max=100) }}
|
||||
<!-- Selector / Configurador de Pisos enriquecido -->
|
||||
<div class="col-md-5">
|
||||
<label for="floorsInput" class="form-label fw-semibold d-flex justify-content-between align-items-center mb-1">
|
||||
<span><i class="bi bi-layers me-1 text-primary"></i>Plantas Físicas (Floors)</span>
|
||||
<span class="badge bg-secondary-subtle text-secondary" id="floorModeBadge">
|
||||
{% if building and building.is_virtual %}Campus Virtual{% else %}Presencial{% endif %}
|
||||
</span>
|
||||
</label>
|
||||
<div class="input-group">
|
||||
<button class="btn btn-outline-secondary" type="button" id="btnFloorDec" title="Disminuir planta">-</button>
|
||||
{{ form.floors(class="form-control text-center fw-bold" + (" is-invalid" if form.floors.errors else ""), id="floorsInput", min=0, max=100) }}
|
||||
<button class="btn btn-outline-secondary" type="button" id="btnFloorInc" title="Aumentar planta">+</button>
|
||||
</div>
|
||||
{% if form.floors.errors %}
|
||||
<div class="invalid-feedback">{{ form.floors.errors[0] }}</div>
|
||||
<div class="invalid-feedback d-block">{{ form.floors.errors[0] }}</div>
|
||||
{% endif %}
|
||||
<small class="text-muted">Plantas físicas (0 para Campus Virtual)</small>
|
||||
<small class="text-muted d-block mt-1">Cantidad de niveles estructurales (0 para Campus Virtual)</small>
|
||||
</div>
|
||||
|
||||
<!-- Panel de Configuración Rápida de Niveles (Presets & Acciones) -->
|
||||
<div class="col-12">
|
||||
<div class="p-3 bg-body-tertiary rounded border border-light-subtle">
|
||||
<div class="d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2">
|
||||
<div class="small fw-bold text-secondary">
|
||||
<i class="bi bi-diagram-3 me-1"></i>Configurador Rápido de Plantas y Niveles
|
||||
</div>
|
||||
<div class="d-flex flex-wrap gap-1">
|
||||
<button type="button" class="btn btn-outline-primary btn-sm py-0 px-2" id="presetPB">Preset PB (1)</button>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm py-0 px-2" id="presetPBplus1">PB + 1 (2)</button>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm py-0 px-2" id="presetPBplus3">PB + 3 (4)</button>
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm py-0 px-2" id="presetVirtual">Virtual (0)</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap align-items-center gap-1" id="floorLevelChips">
|
||||
<!-- Generado dinámicamente según floorsInput -->
|
||||
</div>
|
||||
<small class="text-muted mt-2 d-block" style="font-size: 0.78rem;">
|
||||
<i class="bi bi-info-circle me-1"></i>Puedes usar los botones de acceso rápido para ajustar las plantas del edificio. Cada nivel admitirá creación y vinculación de aulas específicas.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
@@ -75,7 +131,7 @@
|
||||
|
||||
<div class="col-12">
|
||||
<div class="form-check form-switch pt-2">
|
||||
{{ form.is_active(class="form-check-input", role="switch") }}
|
||||
{{ form.is_active(class="form-check-input", role="switch", id="isActiveInput") }}
|
||||
{{ form.is_active.label(class="form-check-label fw-semibold") }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -91,7 +147,304 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Card 2: Panel Interactivo de Plantas y Aulas de la Sede -->
|
||||
{% if building %}
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-header bg-body-tertiary border-0 py-3 d-flex flex-wrap justify-content-between align-items-center gap-2">
|
||||
<div>
|
||||
<h5 class="mb-0 h6 fw-bold">
|
||||
<i class="bi bi-layers-fill text-primary me-2"></i>Plantas Físicas y Distribución de Aulas
|
||||
</h5>
|
||||
<small class="text-muted">Gestiona los pisos del edificio, visualiza sus aulas asignadas o crea nuevos espacios por nivel</small>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap align-items-center gap-2">
|
||||
<span class="badge bg-primary-subtle text-primary border border-primary-subtle px-2 py-1">
|
||||
<i class="bi bi-building me-1"></i>{{ floors_list|length }} Niveles
|
||||
</span>
|
||||
<span class="badge bg-info-subtle text-info border border-info-subtle px-2 py-1">
|
||||
<i class="bi bi-door-open me-1"></i>{{ classrooms|length }} Aulas
|
||||
</span>
|
||||
<span class="badge bg-success-subtle text-success border border-success-subtle px-2 py-1">
|
||||
<i class="bi bi-people me-1"></i>{{ total_physical_capacity }} Plazas Físicas
|
||||
</span>
|
||||
{% if not building.is_virtual %}
|
||||
<a href="/classrooms/add_classroom?building_id={{ building.id }}" class="btn btn-sm btn-success">
|
||||
<i class="bi bi-plus-circle me-1"></i>Crear Nueva Aula
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body p-4">
|
||||
{% if building.is_virtual %}
|
||||
<!-- Caso Sede Virtual -->
|
||||
<div class="alert alert-info border-0 shadow-sm d-flex align-items-center justify-content-between">
|
||||
<div>
|
||||
<i class="bi bi-cloud-check fs-4 me-2"></i>
|
||||
<strong>Sede Virtual:</strong> Las aulas de esta sede operan en el Campus Digital institucional (Moodle, Meet y MS Teams).
|
||||
</div>
|
||||
<a href="/classrooms/add_classroom?building_id={{ building.id }}&floor=Digital" class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-plus-lg me-1"></i>Nueva Sala Virtual
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if floors_list and floors_list|length > 0 %}
|
||||
<div class="d-flex flex-column gap-3">
|
||||
{% for f in floors_list %}
|
||||
<div class="card border border-light-subtle shadow-none">
|
||||
<!-- Cabecera de la Planta -->
|
||||
<div class="card-header bg-body py-2 px-3 d-flex flex-wrap justify-content-between align-items-center gap-2">
|
||||
<div class="d-flex align-items-center">
|
||||
{% if 'SUB' in f.floor_code|upper or 'SS' in f.floor_code|upper %}
|
||||
<i class="bi bi-box-arrow-in-down text-warning fs-5 me-2"></i>
|
||||
{% elif 'PB' in f.floor_code|upper or 'PLANTA' in f.floor_name|upper %}
|
||||
<i class="bi bi-door-closed text-primary fs-5 me-2"></i>
|
||||
{% elif 'EP' in f.floor_code|upper or 'ENTRE' in f.floor_name|upper %}
|
||||
<i class="bi bi-stack text-info fs-5 me-2"></i>
|
||||
{% elif f.floor_code == 'Digital' %}
|
||||
<i class="bi bi-cloud text-info fs-5 me-2"></i>
|
||||
{% else %}
|
||||
<i class="bi bi-layers text-secondary fs-5 me-2"></i>
|
||||
{% endif %}
|
||||
<div>
|
||||
<span class="fw-bold fs-6">{{ f.floor_name }}</span>
|
||||
<span class="badge bg-body-secondary text-secondary border ms-2">Código: {{ f.floor_code }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge bg-light text-dark border">
|
||||
<i class="bi bi-door-open me-1"></i>{{ f.classrooms|length }} aulas
|
||||
</span>
|
||||
<span class="badge bg-light text-dark border">
|
||||
<i class="bi bi-people me-1"></i>{{ f.total_capacity }} pers. cap.
|
||||
</span>
|
||||
<a href="/classrooms/add_classroom?building_id={{ building.id }}&floor={{ f.floor_code }}"
|
||||
class="btn btn-sm btn-outline-success py-1 px-2"
|
||||
title="Crear un aula directamente en {{ f.floor_name }}">
|
||||
<i class="bi bi-plus-lg me-1"></i>+ Nueva Aula en este Piso
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Listado de Aulas en esta Planta -->
|
||||
<div class="card-body p-0">
|
||||
{% if f.classrooms and f.classrooms|length > 0 %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0 table-sm">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th class="ps-3" style="width: 30%;">Aula / Espacio</th>
|
||||
<th style="width: 20%;">Capacidad</th>
|
||||
<th style="width: 25%;">Estado</th>
|
||||
<th class="text-end pe-3" style="width: 25%;">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for c in f.classrooms %}
|
||||
<tr>
|
||||
<td class="ps-3">
|
||||
<a href="/classrooms/view_classroom?id={{ c.id }}" class="fw-semibold text-decoration-none">
|
||||
<i class="bi bi-door-open text-primary me-1"></i>{{ c.code_display or c.code or c.room_number }}
|
||||
</a>
|
||||
{% if c.description %}
|
||||
<small class="text-muted d-block" style="font-size: 0.75rem;">{{ c.description }}</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-primary-subtle text-primary border border-primary-subtle">
|
||||
{{ c.capacity }} alumnos
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
{% if c.is_active %}
|
||||
<span class="badge bg-success-subtle text-success border border-success-subtle">
|
||||
<i class="bi bi-check-circle me-1"></i>Activa
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="badge bg-secondary-subtle text-secondary border border-secondary-subtle">
|
||||
<i class="bi bi-pause-circle me-1"></i>Inactiva
|
||||
</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-end pe-3">
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="/classrooms/edit/{{ c.id }}" class="btn btn-outline-secondary py-0 px-2" title="Editar detalles del aula">
|
||||
<i class="bi bi-pencil me-1"></i>Editar
|
||||
</a>
|
||||
<a href="/schedule/add_reservation?classroom_id={{ c.id }}" class="btn btn-outline-primary py-0 px-2" title="Reservar espacio">
|
||||
<i class="bi bi-calendar-plus me-1"></i>Reservar
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="p-3 text-center bg-body-tertiary text-muted small">
|
||||
<i class="bi bi-inbox me-1"></i>Este nivel aún no tiene aulas asignadas.
|
||||
<a href="/classrooms/add_classroom?building_id={{ building.id }}&floor={{ f.floor_code }}" class="fw-semibold text-primary ms-1 text-decoration-none">
|
||||
+ Añadir la primera aula aquí →
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-center py-4 bg-body-tertiary rounded border border-dashed text-muted">
|
||||
<i class="bi bi-building-slash fs-3 d-block mb-2 text-secondary"></i>
|
||||
No se han registrado plantas físicas aún para esta sede.
|
||||
<div class="mt-2">
|
||||
<a href="/classrooms/add_classroom?building_id={{ building.id }}" class="btn btn-sm btn-primary">
|
||||
<i class="bi bi-plus-circle me-1"></i>Crear Primera Aula
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<!-- Card Informativa para Edificio Nuevo -->
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-header bg-body-tertiary border-0 py-3">
|
||||
<h5 class="mb-0 h6 fw-bold">
|
||||
<i class="bi bi-layers-fill text-primary me-2"></i>Estructura Proyectada de Plantas
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body p-4 text-center">
|
||||
<div class="py-3">
|
||||
<i class="bi bi-diagram-3 fs-1 text-primary mb-2 d-block"></i>
|
||||
<h6 class="fw-bold mb-1">Previsualización de Niveles Físicos</h6>
|
||||
<p class="text-muted small mb-3">
|
||||
Ajusta el número de plantas arriba para previsualizar los niveles que compondrán este edificio. Al guardar la sede, podrás incorporar aulas directamente en cada una de sus plantas.
|
||||
</p>
|
||||
<div class="d-inline-flex flex-wrap gap-2 justify-content-center p-3 bg-body-tertiary rounded border border-light-subtle" id="newBuildingFloorsPreview">
|
||||
<!-- Poblado dinámicamente -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const floorsInput = document.getElementById('floorsInput');
|
||||
const btnFloorInc = document.getElementById('btnFloorInc');
|
||||
const btnFloorDec = document.getElementById('btnFloorDec');
|
||||
const floorModeBadge = document.getElementById('floorModeBadge');
|
||||
const floorLevelChips = document.getElementById('floorLevelChips');
|
||||
const newBuildingPreview = document.getElementById('newBuildingFloorsPreview');
|
||||
const buildingCodeInput = document.getElementById('buildingCodeInput');
|
||||
const buildingNameInput = document.getElementById('buildingNameInput');
|
||||
|
||||
function isVirtualTarget() {
|
||||
const c = (buildingCodeInput ? buildingCodeInput.value : '').toUpperCase();
|
||||
const n = (buildingNameInput ? buildingNameInput.value : '').toUpperCase();
|
||||
return c.includes('VIRTUAL') || n.includes('VIRTUAL');
|
||||
}
|
||||
|
||||
function renderLevelChips(val) {
|
||||
if (!floorLevelChips) return;
|
||||
floorLevelChips.innerHTML = '';
|
||||
const count = parseInt(val, 10) || 0;
|
||||
|
||||
if (count === 0 || isVirtualTarget()) {
|
||||
if (floorModeBadge) floorModeBadge.textContent = 'Campus Virtual';
|
||||
const chip = document.createElement('span');
|
||||
chip.className = 'badge bg-info-subtle text-info border border-info-subtle px-2 py-1';
|
||||
chip.innerHTML = '<i class="bi bi-cloud-check me-1"></i>Campus Virtual (Nivel Digital)';
|
||||
floorLevelChips.appendChild(chip);
|
||||
if (newBuildingPreview) {
|
||||
newBuildingPreview.innerHTML = '<span class="badge bg-info-subtle text-info border px-3 py-2"><i class="bi bi-cloud me-1"></i>Campus Virtual (100% Remoto)</span>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (floorModeBadge) floorModeBadge.textContent = 'Presencial (' + count + ' pisos)';
|
||||
|
||||
const levels = [];
|
||||
// Standard levels
|
||||
levels.push({ code: 'PB', name: 'Planta Baja (PB)' });
|
||||
for (let i = 1; i < count; i++) {
|
||||
levels.push({ code: String(i), name: 'Piso ' + i });
|
||||
}
|
||||
|
||||
levels.forEach(function(lvl) {
|
||||
const chip = document.createElement('span');
|
||||
chip.className = 'badge bg-primary-subtle text-primary border border-primary-subtle px-2 py-1';
|
||||
chip.innerHTML = '<i class="bi bi-layers me-1"></i>' + lvl.name;
|
||||
floorLevelChips.appendChild(chip);
|
||||
});
|
||||
|
||||
if (newBuildingPreview) {
|
||||
newBuildingPreview.innerHTML = '';
|
||||
levels.forEach(function(lvl) {
|
||||
const bChip = document.createElement('div');
|
||||
bChip.className = 'p-2 rounded bg-body border text-center';
|
||||
bChip.style.minWidth = '110px';
|
||||
bChip.innerHTML = '<i class="bi bi-layers text-primary d-block mb-1"></i><small class="fw-bold d-block">' + lvl.name + '</small><span class="badge bg-light text-muted border" style="font-size: 0.7rem;">Nivel ' + lvl.code + '</span>';
|
||||
newBuildingPreview.appendChild(bChip);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (floorsInput) {
|
||||
floorsInput.addEventListener('input', function() {
|
||||
renderLevelChips(this.value);
|
||||
});
|
||||
|
||||
if (btnFloorInc) {
|
||||
btnFloorInc.addEventListener('click', function() {
|
||||
let v = parseInt(floorsInput.value, 10) || 0;
|
||||
floorsInput.value = v + 1;
|
||||
renderLevelChips(floorsInput.value);
|
||||
});
|
||||
}
|
||||
|
||||
if (btnFloorDec) {
|
||||
btnFloorDec.addEventListener('click', function() {
|
||||
let v = parseInt(floorsInput.value, 10) || 0;
|
||||
if (v > 0) {
|
||||
floorsInput.value = v - 1;
|
||||
renderLevelChips(floorsInput.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Presets
|
||||
const pPB = document.getElementById('presetPB');
|
||||
const pPB1 = document.getElementById('presetPBplus1');
|
||||
const pPB3 = document.getElementById('presetPBplus3');
|
||||
const pVirt = document.getElementById('presetVirtual');
|
||||
|
||||
if (pPB) pPB.addEventListener('click', function() { floorsInput.value = 1; renderLevelChips(1); });
|
||||
if (pPB1) pPB1.addEventListener('click', function() { floorsInput.value = 2; renderLevelChips(2); });
|
||||
if (pPB3) pPB3.addEventListener('click', function() { floorsInput.value = 4; renderLevelChips(4); });
|
||||
if (pVirt) pVirt.addEventListener('click', function() { floorsInput.value = 0; renderLevelChips(0); });
|
||||
|
||||
// Initial render
|
||||
renderLevelChips(floorsInput.value);
|
||||
}
|
||||
|
||||
if (buildingCodeInput) {
|
||||
buildingCodeInput.addEventListener('input', function() {
|
||||
if (isVirtualTarget() && floorsInput) {
|
||||
floorsInput.value = 0;
|
||||
}
|
||||
if (floorsInput) renderLevelChips(floorsInput.value);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<a href="/buildings/edit/{{ building.id }}" class="btn btn-outline-secondary me-2">
|
||||
<i class="bi bi-pencil me-1"></i>Editar Edificio
|
||||
</a>
|
||||
<a href="/classrooms/add_classroom" class="btn btn-primary">
|
||||
<a href="/classrooms/add_classroom?building_id={{ building.id }}" class="btn btn-primary">
|
||||
<i class="bi bi-plus-circle me-1"></i>Nueva Aula
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
@@ -241,9 +241,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
}
|
||||
|
||||
if (newBuildingNameInput) newBuildingNameInput.addEventListener('input', updatePreview);
|
||||
if (floorInput) floorInput.addEventListener('input', updatePreview);
|
||||
if (roomInput) roomInput.addEventListener('input', updatePreview);
|
||||
// Preselección de edificio y piso desde URL o backend
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var targetBId = urlParams.get('building_id') || '{{ preselected_building_id or "" }}';
|
||||
var targetFloor = urlParams.get('floor') || '{{ preselected_floor or "" }}';
|
||||
|
||||
if (targetBId && buildingSelect) {
|
||||
buildingSelect.value = targetBId;
|
||||
updateFloorsDatalist(targetBId);
|
||||
}
|
||||
if (targetFloor && floorInput) {
|
||||
floorInput.value = targetFloor;
|
||||
}
|
||||
|
||||
updatePreview();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user