feat(dashboard): add commissions pagination, career filter, unassigned KPI card, and occupancy pie charts v3.8.19
This commit is contained in:
+293
-45
@@ -179,8 +179,131 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Inicialización de Gráficos de Torta (Doughnut) para Aulas y Comisiones
|
||||
initDoughnutCharts();
|
||||
|
||||
// Poblar dinámicamente opciones de carrera si faltaran en el selector
|
||||
const careerSelect = document.getElementById('commCareerFilter');
|
||||
if (careerSelect) {
|
||||
const existingValues = new Set(Array.from(careerSelect.options).map(o => o.value));
|
||||
document.querySelectorAll('tr[data-career]').forEach(function(tr) {
|
||||
const cName = tr.getAttribute('data-career');
|
||||
if (cName && !existingValues.has(cName)) {
|
||||
existingValues.add(cName);
|
||||
const opt = document.createElement('option');
|
||||
opt.value = cName;
|
||||
opt.textContent = cName;
|
||||
careerSelect.appendChild(opt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Inicializar la paginación y filtrado de comisiones
|
||||
applyCommPaginationAndFilter();
|
||||
});
|
||||
|
||||
// Referencias globales a los gráficos Doughnut
|
||||
let classroomsPieChart = null;
|
||||
let commissionsPieChart = null;
|
||||
|
||||
function initDoughnutCharts() {
|
||||
const classCanvas = document.getElementById('bedeliaClassroomsPieChart') || document.getElementById('adminClassroomsPieChart');
|
||||
const commCanvas = document.getElementById('bedeliaCommissionsPieChart') || document.getElementById('adminCommissionsPieChart');
|
||||
|
||||
if (classCanvas && FILTER_STATS_DATA && FILTER_STATS_DATA.today) {
|
||||
const todayClass = FILTER_STATS_DATA.today.classrooms || {};
|
||||
const assigned = todayClass.assigned_count || 0;
|
||||
const unassigned = todayClass.unassigned_count || 0;
|
||||
|
||||
classroomsPieChart = new Chart(classCanvas.getContext('2d'), {
|
||||
type: 'doughnut',
|
||||
data: {
|
||||
labels: ['Aulas Asignadas', 'Aulas Libres'],
|
||||
datasets: [{
|
||||
data: [assigned, unassigned],
|
||||
backgroundColor: ['#198754', '#ffc107'],
|
||||
borderColor: 'transparent',
|
||||
borderWidth: 2,
|
||||
hoverOffset: 4
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
cutout: '68%',
|
||||
plugins: {
|
||||
legend: { display: false },
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: function(ctx) {
|
||||
const val = ctx.raw || 0;
|
||||
const total = ctx.dataset.data.reduce((a, b) => a + b, 0);
|
||||
const pct = total > 0 ? Math.round((val / total) * 100) : 0;
|
||||
return ` ${ctx.label}: ${val} (${pct}%)`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (commCanvas && FILTER_STATS_DATA && FILTER_STATS_DATA.today) {
|
||||
const todayComm = FILTER_STATS_DATA.today.commissions || {};
|
||||
const assigned = todayComm.assigned_count || 0;
|
||||
const unassigned = todayComm.unassigned_count || 0;
|
||||
|
||||
commissionsPieChart = new Chart(commCanvas.getContext('2d'), {
|
||||
type: 'doughnut',
|
||||
data: {
|
||||
labels: ['Con Aula Asignada', 'Sin Asignar (Pendientes)'],
|
||||
datasets: [{
|
||||
data: [assigned, unassigned],
|
||||
backgroundColor: ['#0d6efd', '#dc3545'],
|
||||
borderColor: 'transparent',
|
||||
borderWidth: 2,
|
||||
hoverOffset: 4
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
cutout: '68%',
|
||||
plugins: {
|
||||
legend: { display: false },
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: function(ctx) {
|
||||
const val = ctx.raw || 0;
|
||||
const total = ctx.dataset.data.reduce((a, b) => a + b, 0);
|
||||
const pct = total > 0 ? Math.round((val / total) * 100) : 0;
|
||||
return ` ${ctx.label}: ${val} (${pct}%)`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updateDoughnutCharts(period) {
|
||||
if (!FILTER_STATS_DATA || !FILTER_STATS_DATA[period]) return;
|
||||
const periodData = FILTER_STATS_DATA[period];
|
||||
const classData = periodData.classrooms || {};
|
||||
const commData = periodData.commissions || {};
|
||||
|
||||
if (classroomsPieChart) {
|
||||
classroomsPieChart.data.datasets[0].data = [classData.assigned_count || 0, classData.unassigned_count || 0];
|
||||
classroomsPieChart.update();
|
||||
}
|
||||
if (commissionsPieChart) {
|
||||
commissionsPieChart.data.datasets[0].data = [commData.assigned_count || 0, commData.unassigned_count || 0];
|
||||
commissionsPieChart.update();
|
||||
}
|
||||
}
|
||||
|
||||
// Apply dynamic colors from data-color attributes (milestone type badges)
|
||||
document.querySelectorAll('[data-color]').forEach(function(el) {
|
||||
const color = el.getAttribute('data-color');
|
||||
@@ -222,15 +345,19 @@ function switchBedeliaPercentiles(period) {
|
||||
if (!FILTER_STATS_DATA || !FILTER_STATS_DATA[period]) return;
|
||||
const periodData = FILTER_STATS_DATA[period];
|
||||
const classData = periodData.classrooms || {};
|
||||
const commData = periodData.commissions || {};
|
||||
|
||||
const dateText = document.getElementById('bedeliaPctDateText');
|
||||
if (dateText) dateText.innerText = periodData.label || '';
|
||||
|
||||
const periodTitle = document.getElementById('bedeliaPctPeriodTitle');
|
||||
if (periodTitle) {
|
||||
periodTitle.innerText = period === 'today' ? 'Día (Hoy)' : (period === 'tomorrow' ? 'Mañana' : (period === 'week' ? 'Semana' : 'Mes'));
|
||||
}
|
||||
const periodName = period === 'today' ? 'Día (Hoy)' : (period === 'tomorrow' ? 'Mañana' : (period === 'week' ? 'Semana' : 'Mes'));
|
||||
|
||||
const classPieTitle = document.getElementById('bedeliaClassPiePeriodTitle');
|
||||
const commPieTitle = document.getElementById('bedeliaCommPiePeriodTitle');
|
||||
if (classPieTitle) classPieTitle.innerText = periodName;
|
||||
if (commPieTitle) commPieTitle.innerText = periodName;
|
||||
|
||||
// Tarjetas KPI Aulas
|
||||
const assignedCount = document.getElementById('bedeliaPctAssignedCount');
|
||||
const assignedPct = document.getElementById('bedeliaPctAssignedPct');
|
||||
const unassignedCount = document.getElementById('bedeliaPctUnassignedCount');
|
||||
@@ -245,28 +372,30 @@ function switchBedeliaPercentiles(period) {
|
||||
assignedLabel.innerText = period === 'today' ? 'Con cursada activa hoy' : (period === 'tomorrow' ? 'Con cursada activa mañana' : (period === 'week' ? 'Con cursada activa esta semana' : 'Con cursada activa este mes'));
|
||||
}
|
||||
|
||||
// Actualizar leyendas y barras
|
||||
const legendAssigned = document.getElementById('bedeliaPctLegendAssigned');
|
||||
const legendUnassigned = document.getElementById('bedeliaPctLegendUnassigned');
|
||||
if (legendAssigned) legendAssigned.innerText = (classData.assigned_count ?? 0) + ' asignadas (' + (classData.assigned_pct ?? 0) + '%)';
|
||||
if (legendUnassigned) legendUnassigned.innerText = (classData.unassigned_count ?? 0) + ' libres (' + (classData.unassigned_pct ?? 0) + '%)';
|
||||
// Tarjetas KPI Comisiones
|
||||
const commUnassignedCount = document.getElementById('bedeliaPctCommUnassignedCount');
|
||||
const commUnassignedPct = document.getElementById('bedeliaPctCommUnassignedPct');
|
||||
const commAssignedCount = document.getElementById('bedeliaPctCommAssignedCount');
|
||||
const commAssignedPct = document.getElementById('bedeliaPctCommAssignedPct');
|
||||
|
||||
const barAssigned = document.getElementById('bedeliaPctProgressBarAssigned');
|
||||
const barUnassigned = document.getElementById('bedeliaPctProgressBarUnassigned');
|
||||
const barTextAssigned = document.getElementById('bedeliaPctBarTextAssigned');
|
||||
const barTextUnassigned = document.getElementById('bedeliaPctBarTextUnassigned');
|
||||
if (commUnassignedCount) commUnassignedCount.innerText = commData.unassigned_count ?? 0;
|
||||
if (commUnassignedPct) commUnassignedPct.innerText = (commData.unassigned_pct ?? 0) + '%';
|
||||
if (commAssignedCount) commAssignedCount.innerText = commData.assigned_count ?? 0;
|
||||
if (commAssignedPct) commAssignedPct.innerText = (commData.assigned_pct ?? 0) + '%';
|
||||
|
||||
if (barAssigned) {
|
||||
barAssigned.style.width = (classData.assigned_pct ?? 0) + '%';
|
||||
barAssigned.setAttribute('aria-valuenow', classData.assigned_pct ?? 0);
|
||||
}
|
||||
if (barTextAssigned) barTextAssigned.innerText = (classData.assigned_pct ?? 0) + '%';
|
||||
// Leyendas de los gráficos de torta
|
||||
const classLegendAssigned = document.getElementById('bedeliaClassPieLegendAssigned');
|
||||
const classLegendUnassigned = document.getElementById('bedeliaClassPieLegendUnassigned');
|
||||
const commLegendAssigned = document.getElementById('bedeliaCommPieLegendAssigned');
|
||||
const commLegendUnassigned = document.getElementById('bedeliaCommPieLegendUnassigned');
|
||||
|
||||
if (barUnassigned) {
|
||||
barUnassigned.style.width = (classData.unassigned_pct ?? 0) + '%';
|
||||
barUnassigned.setAttribute('aria-valuenow', classData.unassigned_pct ?? 0);
|
||||
}
|
||||
if (barTextUnassigned) barTextUnassigned.innerText = (classData.unassigned_pct ?? 0) + '%';
|
||||
if (classLegendAssigned) classLegendAssigned.innerText = 'Asignadas: ' + (classData.assigned_count ?? 0) + ' (' + (classData.assigned_pct ?? 0) + '%)';
|
||||
if (classLegendUnassigned) classLegendUnassigned.innerText = 'Libres: ' + (classData.unassigned_count ?? 0) + ' (' + (classData.unassigned_pct ?? 0) + '%)';
|
||||
if (commLegendAssigned) commLegendAssigned.innerText = 'Con Aula: ' + (commData.assigned_count ?? 0) + ' (' + (commData.assigned_pct ?? 0) + '%)';
|
||||
if (commLegendUnassigned) commLegendUnassigned.innerText = 'Sin Asignar: ' + (commData.unassigned_count ?? 0) + ' (' + (commData.unassigned_pct ?? 0) + '%)';
|
||||
|
||||
// Actualizar gráficos Doughnut
|
||||
updateDoughnutCharts(period);
|
||||
|
||||
// Botones activos
|
||||
document.querySelectorAll('#bedeliaPctPeriodSwitcher button').forEach(function(btn) {
|
||||
@@ -279,15 +408,19 @@ function switchAdminPercentiles(period) {
|
||||
if (!FILTER_STATS_DATA || !FILTER_STATS_DATA[period]) return;
|
||||
const periodData = FILTER_STATS_DATA[period];
|
||||
const classData = periodData.classrooms || {};
|
||||
const commData = periodData.commissions || {};
|
||||
|
||||
const dateText = document.getElementById('adminPctDateText');
|
||||
if (dateText) dateText.innerText = periodData.label || '';
|
||||
|
||||
const periodTitle = document.getElementById('adminPctPeriodTitle');
|
||||
if (periodTitle) {
|
||||
periodTitle.innerText = period === 'today' ? 'Día (Hoy)' : (period === 'tomorrow' ? 'Mañana' : (period === 'week' ? 'Semana' : 'Mes'));
|
||||
}
|
||||
const periodName = period === 'today' ? 'Día (Hoy)' : (period === 'tomorrow' ? 'Mañana' : (period === 'week' ? 'Semana' : 'Mes'));
|
||||
|
||||
const classPieTitle = document.getElementById('adminClassPiePeriodTitle');
|
||||
const commPieTitle = document.getElementById('adminCommPiePeriodTitle');
|
||||
if (classPieTitle) classPieTitle.innerText = periodName;
|
||||
if (commPieTitle) commPieTitle.innerText = periodName;
|
||||
|
||||
// Tarjetas KPI Aulas
|
||||
const assignedCount = document.getElementById('adminPctAssignedCount');
|
||||
const assignedPct = document.getElementById('adminPctAssignedPct');
|
||||
const unassignedCount = document.getElementById('adminPctUnassignedCount');
|
||||
@@ -298,33 +431,145 @@ function switchAdminPercentiles(period) {
|
||||
if (unassignedCount) unassignedCount.innerText = classData.unassigned_count ?? 0;
|
||||
if (unassignedPct) unassignedPct.innerText = (classData.unassigned_pct ?? 0) + '%';
|
||||
|
||||
const legendAssigned = document.getElementById('adminPctLegendAssigned');
|
||||
const legendUnassigned = document.getElementById('adminPctLegendUnassigned');
|
||||
if (legendAssigned) legendAssigned.innerText = (classData.assigned_count ?? 0) + ' asignadas (' + (classData.assigned_pct ?? 0) + '%)';
|
||||
if (legendUnassigned) legendUnassigned.innerText = (classData.unassigned_count ?? 0) + ' libres (' + (classData.unassigned_pct ?? 0) + '%)';
|
||||
// Tarjetas KPI Comisiones
|
||||
const commUnassignedCount = document.getElementById('adminPctCommUnassignedCount');
|
||||
const commUnassignedPct = document.getElementById('adminPctCommUnassignedPct');
|
||||
const commAssignedCount = document.getElementById('adminPctCommAssignedCount');
|
||||
const commAssignedPct = document.getElementById('adminPctCommAssignedPct');
|
||||
|
||||
const barAssigned = document.getElementById('adminPctProgressBarAssigned');
|
||||
const barUnassigned = document.getElementById('adminPctProgressBarUnassigned');
|
||||
const barTextAssigned = document.getElementById('adminPctBarTextAssigned');
|
||||
const barTextUnassigned = document.getElementById('adminPctBarTextUnassigned');
|
||||
if (commUnassignedCount) commUnassignedCount.innerText = commData.unassigned_count ?? 0;
|
||||
if (commUnassignedPct) commUnassignedPct.innerText = (commData.unassigned_pct ?? 0) + '%';
|
||||
if (commAssignedCount) commAssignedCount.innerText = commData.assigned_count ?? 0;
|
||||
if (commAssignedPct) commAssignedPct.innerText = (commData.assigned_pct ?? 0) + '%';
|
||||
|
||||
if (barAssigned) {
|
||||
barAssigned.style.width = (classData.assigned_pct ?? 0) + '%';
|
||||
barAssigned.setAttribute('aria-valuenow', classData.assigned_pct ?? 0);
|
||||
}
|
||||
if (barTextAssigned) barTextAssigned.innerText = (classData.assigned_pct ?? 0) + '%';
|
||||
// Leyendas de los gráficos de torta
|
||||
const classLegendAssigned = document.getElementById('adminClassPieLegendAssigned');
|
||||
const classLegendUnassigned = document.getElementById('adminClassPieLegendUnassigned');
|
||||
const commLegendAssigned = document.getElementById('adminCommPieLegendAssigned');
|
||||
const commLegendUnassigned = document.getElementById('adminCommPieLegendUnassigned');
|
||||
|
||||
if (barUnassigned) {
|
||||
barUnassigned.style.width = (classData.unassigned_pct ?? 0) + '%';
|
||||
barUnassigned.setAttribute('aria-valuenow', classData.unassigned_pct ?? 0);
|
||||
}
|
||||
if (barTextUnassigned) barTextUnassigned.innerText = (classData.unassigned_pct ?? 0) + '%';
|
||||
if (classLegendAssigned) classLegendAssigned.innerText = 'Asignadas: ' + (classData.assigned_count ?? 0) + ' (' + (classData.assigned_pct ?? 0) + '%)';
|
||||
if (classLegendUnassigned) classLegendUnassigned.innerText = 'Libres: ' + (classData.unassigned_count ?? 0) + ' (' + (classData.unassigned_pct ?? 0) + '%)';
|
||||
if (commLegendAssigned) commLegendAssigned.innerText = 'Con Aula: ' + (commData.assigned_count ?? 0) + ' (' + (commData.assigned_pct ?? 0) + '%)';
|
||||
if (commLegendUnassigned) commLegendUnassigned.innerText = 'Sin Asignar: ' + (commData.unassigned_count ?? 0) + ' (' + (commData.unassigned_pct ?? 0) + '%)';
|
||||
|
||||
// Actualizar gráficos Doughnut
|
||||
updateDoughnutCharts(period);
|
||||
|
||||
document.querySelectorAll('#adminPctPeriodSwitcher button').forEach(function(btn) {
|
||||
btn.classList.toggle('active', btn.getAttribute('data-period') === period);
|
||||
});
|
||||
}
|
||||
|
||||
// ======================== Paginación y Filtro de Carrera para Comisiones ========================
|
||||
let commCurrentPage = 1;
|
||||
const commPageSize = 10;
|
||||
let commSelectedCareer = '';
|
||||
|
||||
function onCommCareerFilterChange(career) {
|
||||
commSelectedCareer = (career || '').trim();
|
||||
commCurrentPage = 1;
|
||||
applyCommPaginationAndFilter();
|
||||
}
|
||||
|
||||
function goToCommPage(page) {
|
||||
commCurrentPage = page;
|
||||
applyCommPaginationAndFilter();
|
||||
}
|
||||
|
||||
function applyCommPaginationAndFilter() {
|
||||
const activeBlock = document.getElementById('commBlock-' + currentCommPeriod + '-' + currentCommStatus);
|
||||
const paginationContainer = document.getElementById('commPaginationContainer');
|
||||
if (!activeBlock) {
|
||||
if (paginationContainer) paginationContainer.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
const table = activeBlock.querySelector('table');
|
||||
const tableContainer = activeBlock.querySelector('.table-responsive');
|
||||
const noMatchAlert = activeBlock.querySelector('.comm-no-match-alert');
|
||||
|
||||
if (!table) {
|
||||
if (paginationContainer) paginationContainer.style.display = 'none';
|
||||
if (noMatchAlert) noMatchAlert.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
const rows = Array.from(table.querySelectorAll('tbody tr'));
|
||||
if (rows.length === 0) {
|
||||
if (paginationContainer) paginationContainer.style.display = 'none';
|
||||
if (noMatchAlert) noMatchAlert.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
// Filtrar por carrera seleccionada
|
||||
const filterLower = commSelectedCareer.toLowerCase();
|
||||
const filteredRows = rows.filter(function(row) {
|
||||
if (!filterLower) return true;
|
||||
const career = (row.getAttribute('data-career') || '').toLowerCase();
|
||||
const careerNames = (row.getAttribute('data-career-names') || '').toLowerCase();
|
||||
return career.includes(filterLower) || careerNames.includes(filterLower);
|
||||
});
|
||||
|
||||
if (filteredRows.length === 0) {
|
||||
rows.forEach(function(r) { r.style.display = 'none'; });
|
||||
if (tableContainer) tableContainer.style.display = 'none';
|
||||
if (noMatchAlert) noMatchAlert.style.display = 'block';
|
||||
if (paginationContainer) paginationContainer.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
if (noMatchAlert) noMatchAlert.style.display = 'none';
|
||||
if (tableContainer) tableContainer.style.display = 'block';
|
||||
|
||||
// Calcular páginas
|
||||
const totalItems = filteredRows.length;
|
||||
const totalPages = Math.ceil(totalItems / commPageSize);
|
||||
if (commCurrentPage > totalPages) commCurrentPage = totalPages;
|
||||
if (commCurrentPage < 1) commCurrentPage = 1;
|
||||
|
||||
const startIndex = (commCurrentPage - 1) * commPageSize;
|
||||
const endIndex = Math.min(startIndex + commPageSize, totalItems);
|
||||
|
||||
// Ocultar todas las filas
|
||||
rows.forEach(function(r) { r.style.display = 'none'; });
|
||||
|
||||
// Mostrar únicamente las filas de la página actual
|
||||
for (let i = startIndex; i < endIndex; i++) {
|
||||
filteredRows[i].style.display = '';
|
||||
}
|
||||
|
||||
// Actualizar resumen
|
||||
const startEl = document.getElementById('commPageStart');
|
||||
const endEl = document.getElementById('commPageEnd');
|
||||
const totalEl = document.getElementById('commPageTotal');
|
||||
if (startEl) startEl.innerText = startIndex + 1;
|
||||
if (endEl) endEl.innerText = endIndex;
|
||||
if (totalEl) totalEl.innerText = totalItems;
|
||||
|
||||
// Renderizar botones de paginación
|
||||
const navEl = document.getElementById('commPaginationNav');
|
||||
if (navEl) {
|
||||
let navHtml = '';
|
||||
const prevDisabled = commCurrentPage === 1 ? 'disabled' : '';
|
||||
navHtml += `<li class="page-item ${prevDisabled}"><a class="page-link" href="javascript:void(0)" onclick="goToCommPage(${commCurrentPage - 1})"><i class="bi bi-chevron-left"></i></a></li>`;
|
||||
|
||||
for (let p = 1; p <= totalPages; p++) {
|
||||
const activeClass = p === commCurrentPage ? 'active' : '';
|
||||
navHtml += `<li class="page-item ${activeClass}"><a class="page-link" href="javascript:void(0)" onclick="goToCommPage(${p})">${p}</a></li>`;
|
||||
}
|
||||
|
||||
const nextDisabled = commCurrentPage === totalPages ? 'disabled' : '';
|
||||
navHtml += `<li class="page-item ${nextDisabled}"><a class="page-link" href="javascript:void(0)" onclick="goToCommPage(${commCurrentPage + 1})"><i class="bi bi-chevron-right"></i></a></li>`;
|
||||
|
||||
navEl.innerHTML = navHtml;
|
||||
}
|
||||
|
||||
if (paginationContainer) {
|
||||
paginationContainer.style.display = totalItems > 0 ? 'block' : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Bedelía: Switcher de Período para Comisiones (Día / Semana / Mes)
|
||||
function switchCommFilterPeriod(period) {
|
||||
currentCommPeriod = period;
|
||||
@@ -364,6 +609,9 @@ function renderActiveCommBlock() {
|
||||
});
|
||||
const target = document.getElementById('commBlock-' + currentCommPeriod + '-' + currentCommStatus);
|
||||
if (target) target.style.display = 'block';
|
||||
|
||||
commCurrentPage = 1;
|
||||
applyCommPaginationAndFilter();
|
||||
}
|
||||
|
||||
// Bedelía: Switcher de Período para Aulas (Día / Semana / Mes)
|
||||
|
||||
Reference in New Issue
Block a user