feat(academic): allow subjects to be associated with multiple careers (v3.8.21)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "3.8.20",
|
||||
"version": "3.8.21",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
+3
-3
@@ -86,9 +86,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), {
|
||||
});
|
||||
|
||||
// Versiones institucionales del sistema
|
||||
const APP_VERSION = '3.8.20';
|
||||
const FRONTEND_VERSION = '3.8.20';
|
||||
const BACKEND_VERSION = '3.8.20';
|
||||
const APP_VERSION = '3.8.21';
|
||||
const FRONTEND_VERSION = '3.8.21';
|
||||
const BACKEND_VERSION = '3.8.21';
|
||||
|
||||
env.addGlobal('app_version', APP_VERSION);
|
||||
env.addGlobal('frontend_version', FRONTEND_VERSION);
|
||||
|
||||
@@ -962,14 +962,24 @@ const handleSubjectsList = async (req, res) => {
|
||||
};
|
||||
|
||||
const handleSubjectAdd = async (req, res) => {
|
||||
const { code, name, department, credits, career_id, description, is_active } = req.body;
|
||||
const { code, name, department, credits, description, is_active } = req.body;
|
||||
let careerIds = [];
|
||||
if (Array.isArray(req.body.career_ids)) {
|
||||
careerIds = req.body.career_ids.map(id => parseInt(id, 10)).filter(id => !isNaN(id));
|
||||
} else if (req.body.career_ids) {
|
||||
careerIds = [parseInt(req.body.career_ids, 10)].filter(id => !isNaN(id));
|
||||
} else if (req.body.career_id) {
|
||||
careerIds = [parseInt(req.body.career_id, 10)].filter(id => !isNaN(id));
|
||||
}
|
||||
|
||||
try {
|
||||
await req.apiClient.post('/subjects', {
|
||||
code,
|
||||
name,
|
||||
department,
|
||||
credits: parseInt(credits, 10) || 4,
|
||||
career_id: career_id ? parseInt(career_id, 10) : null,
|
||||
career_id: careerIds.length > 0 ? careerIds[0] : null,
|
||||
career_ids: careerIds,
|
||||
description,
|
||||
is_active: is_active === 'on' || is_active === 'true' || is_active === true
|
||||
});
|
||||
@@ -983,14 +993,24 @@ const handleSubjectAdd = async (req, res) => {
|
||||
|
||||
const handleSubjectEdit = async (req, res) => {
|
||||
const id = req.params.id || req.body.id;
|
||||
const { code, name, department, credits, career_id, description, is_active } = req.body;
|
||||
const { code, name, department, credits, description, is_active } = req.body;
|
||||
let careerIds = [];
|
||||
if (Array.isArray(req.body.career_ids)) {
|
||||
careerIds = req.body.career_ids.map(cid => parseInt(cid, 10)).filter(cid => !isNaN(cid));
|
||||
} else if (req.body.career_ids) {
|
||||
careerIds = [parseInt(req.body.career_ids, 10)].filter(cid => !isNaN(cid));
|
||||
} else if (req.body.career_id) {
|
||||
careerIds = [parseInt(req.body.career_id, 10)].filter(cid => !isNaN(cid));
|
||||
}
|
||||
|
||||
try {
|
||||
await req.apiClient.put(`/subjects/${id}`, {
|
||||
code,
|
||||
name,
|
||||
department,
|
||||
credits: parseInt(credits, 10) || 4,
|
||||
career_id: career_id ? parseInt(career_id, 10) : null,
|
||||
career_id: careerIds.length > 0 ? careerIds[0] : null,
|
||||
career_ids: careerIds,
|
||||
description,
|
||||
is_active: is_active === 'on' || is_active === 'true' || is_active === true
|
||||
});
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
data-name="{{ s.name }}"
|
||||
data-credits="{{ s.credits }}"
|
||||
data-career-id="{{ s.career_id or '' }}"
|
||||
data-career-ids="{% if s.careers %}{% for c in s.careers %}{{ c.id }}{% if not loop.last %},{% endif %}{% endfor %}{% elif s.career_id %}{{ s.career_id }}{% endif %}"
|
||||
data-department="{{ s.department or '' }}"
|
||||
data-description="{{ s.description or '' }}"
|
||||
data-active="{{ 'true' if s.is_active else 'false' }}"
|
||||
@@ -291,13 +292,33 @@
|
||||
<input type="text" name="name" class="form-control form-control-sm" placeholder="ej. Álgebra Lineal" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold">Carrera Vinculada</label>
|
||||
<select name="career_id" class="form-select form-select-sm">
|
||||
<option value="">Sin carrera específica (General)</option>
|
||||
<div class="d-flex justify-content-between align-items-center mb-1">
|
||||
<label class="form-label small fw-semibold mb-0">
|
||||
<i class="bi bi-mortarboard text-primary me-1"></i>Carreras Vinculadas
|
||||
</label>
|
||||
<span class="badge bg-secondary-subtle text-secondary border rounded-pill" id="addSubjectCareerCount">0 seleccionadas</span>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center mb-2 gap-2">
|
||||
<input type="text" class="form-control form-control-sm career-filter-input" placeholder="Filtrar carreras..." data-target="addSubjectCareerList">
|
||||
<div class="btn-group btn-group-sm flex-shrink-0">
|
||||
<button type="button" class="btn btn-outline-secondary select-all-careers" data-target="addSubjectCareerList" title="Seleccionar todas las visibles">Todas</button>
|
||||
<button type="button" class="btn btn-outline-secondary deselect-all-careers" data-target="addSubjectCareerList" title="Deseleccionar todas">Ninguna</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="border rounded p-2 bg-body-tertiary" style="max-height: 170px; overflow-y: auto;" id="addSubjectCareerList">
|
||||
{% for c in careers %}
|
||||
<option value="{{ c.id }}">{{ c.name }}</option>
|
||||
<div class="form-check career-item py-1 px-2 mb-1 rounded">
|
||||
<input class="form-check-input career-checkbox" type="checkbox" name="career_ids" value="{{ c.id }}" id="add_career_{{ c.id }}">
|
||||
<label class="form-check-label small d-flex justify-content-between align-items-center w-100 cursor-pointer" for="add_career_{{ c.id }}">
|
||||
<span class="career-label-text fw-medium">{{ c.name }}</span>
|
||||
<span class="badge bg-secondary-subtle text-secondary font-monospace ms-2">{{ c.code or ('ID ' + c.id) }}</span>
|
||||
</label>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted small mb-0 p-2 text-center">No hay carreras registradas.</p>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<small class="text-muted d-block mt-1">Podés seleccionar una o más carreras para asociar esta asignatura a múltiples planes de estudio.</small>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold">Departamento / Área</label>
|
||||
@@ -345,13 +366,33 @@
|
||||
<input type="text" name="name" id="editSubjectName" class="form-control form-control-sm" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold">Carrera Vinculada</label>
|
||||
<select name="career_id" id="editSubjectCareer" class="form-select form-select-sm">
|
||||
<option value="">Sin carrera específica (General)</option>
|
||||
<div class="d-flex justify-content-between align-items-center mb-1">
|
||||
<label class="form-label small fw-semibold mb-0">
|
||||
<i class="bi bi-mortarboard text-primary me-1"></i>Carreras Vinculadas
|
||||
</label>
|
||||
<span class="badge bg-secondary-subtle text-secondary border rounded-pill" id="editSubjectCareerCount">0 seleccionadas</span>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center mb-2 gap-2">
|
||||
<input type="text" class="form-control form-control-sm career-filter-input" placeholder="Filtrar carreras..." data-target="editSubjectCareerList">
|
||||
<div class="btn-group btn-group-sm flex-shrink-0">
|
||||
<button type="button" class="btn btn-outline-secondary select-all-careers" data-target="editSubjectCareerList" title="Seleccionar todas las visibles">Todas</button>
|
||||
<button type="button" class="btn btn-outline-secondary deselect-all-careers" data-target="editSubjectCareerList" title="Deseleccionar todas">Ninguna</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="border rounded p-2 bg-body-tertiary" style="max-height: 170px; overflow-y: auto;" id="editSubjectCareerList">
|
||||
{% for c in careers %}
|
||||
<option value="{{ c.id }}">{{ c.name }}</option>
|
||||
<div class="form-check career-item py-1 px-2 mb-1 rounded">
|
||||
<input class="form-check-input career-checkbox" type="checkbox" name="career_ids" value="{{ c.id }}" id="edit_career_{{ c.id }}">
|
||||
<label class="form-check-label small d-flex justify-content-between align-items-center w-100 cursor-pointer" for="edit_career_{{ c.id }}">
|
||||
<span class="career-label-text fw-medium">{{ c.name }}</span>
|
||||
<span class="badge bg-secondary-subtle text-secondary font-monospace ms-2">{{ c.code or ('ID ' + c.id) }}</span>
|
||||
</label>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted small mb-0 p-2 text-center">No hay carreras registradas.</p>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<small class="text-muted d-block mt-1">Podés seleccionar una o más carreras para asociar esta asignatura a múltiples planes de estudio.</small>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold">Departamento / Área</label>
|
||||
@@ -405,6 +446,93 @@
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
function updateCareerCount(containerId, countBadgeId) {
|
||||
var container = document.getElementById(containerId);
|
||||
var badge = document.getElementById(countBadgeId);
|
||||
if (!container || !badge) return;
|
||||
var checked = container.querySelectorAll('.career-checkbox:checked').length;
|
||||
badge.textContent = checked + (checked === 1 ? ' seleccionada' : ' seleccionadas');
|
||||
if (checked > 0) {
|
||||
badge.className = 'badge bg-primary text-white rounded-pill';
|
||||
} else {
|
||||
badge.className = 'badge bg-secondary-subtle text-secondary border rounded-pill';
|
||||
}
|
||||
}
|
||||
|
||||
// Dynamic career filter within modals
|
||||
document.querySelectorAll('.career-filter-input').forEach(function(input) {
|
||||
input.addEventListener('input', function() {
|
||||
var term = this.value.toLowerCase().trim();
|
||||
var targetId = this.getAttribute('data-target');
|
||||
var container = document.getElementById(targetId);
|
||||
if (container) {
|
||||
container.querySelectorAll('.career-item').forEach(function(item) {
|
||||
var text = item.textContent.toLowerCase();
|
||||
item.style.display = text.includes(term) ? '' : 'none';
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Select all / Deselect all
|
||||
document.querySelectorAll('.select-all-careers').forEach(function(btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
var targetId = this.getAttribute('data-target');
|
||||
var container = document.getElementById(targetId);
|
||||
if (container) {
|
||||
container.querySelectorAll('.career-checkbox').forEach(function(cb) {
|
||||
var item = cb.closest('.career-item');
|
||||
if (!item || item.style.display !== 'none') {
|
||||
cb.checked = true;
|
||||
}
|
||||
});
|
||||
var countId = targetId === 'addSubjectCareerList' ? 'addSubjectCareerCount' : 'editSubjectCareerCount';
|
||||
updateCareerCount(targetId, countId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.deselect-all-careers').forEach(function(btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
var targetId = this.getAttribute('data-target');
|
||||
var container = document.getElementById(targetId);
|
||||
if (container) {
|
||||
container.querySelectorAll('.career-checkbox').forEach(function(cb) {
|
||||
cb.checked = false;
|
||||
});
|
||||
var countId = targetId === 'addSubjectCareerList' ? 'addSubjectCareerCount' : 'editSubjectCareerCount';
|
||||
updateCareerCount(targetId, countId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Individual checkbox changes
|
||||
document.querySelectorAll('.career-checkbox').forEach(function(cb) {
|
||||
cb.addEventListener('change', function() {
|
||||
var container = this.closest('[id$="CareerList"]');
|
||||
if (container) {
|
||||
var countId = container.id === 'addSubjectCareerList' ? 'addSubjectCareerCount' : 'editSubjectCareerCount';
|
||||
updateCareerCount(container.id, countId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Reset Add Modal on open
|
||||
var modalAdd = document.getElementById('modalAddSubject');
|
||||
if (modalAdd) {
|
||||
modalAdd.addEventListener('show.bs.modal', function() {
|
||||
var filterInput = modalAdd.querySelector('.career-filter-input');
|
||||
if (filterInput) filterInput.value = '';
|
||||
modalAdd.querySelectorAll('.career-item').forEach(function(item) {
|
||||
item.style.display = '';
|
||||
});
|
||||
modalAdd.querySelectorAll('.career-checkbox').forEach(function(cb) {
|
||||
cb.checked = false;
|
||||
});
|
||||
updateCareerCount('addSubjectCareerList', 'addSubjectCareerCount');
|
||||
});
|
||||
}
|
||||
|
||||
// Populate Edit Subject Modal
|
||||
var modalEdit = document.getElementById('modalEditSubject');
|
||||
if (modalEdit) {
|
||||
@@ -415,10 +543,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('editSubjectCode').value = btn.getAttribute('data-code') || '';
|
||||
document.getElementById('editSubjectName').value = btn.getAttribute('data-name') || '';
|
||||
document.getElementById('editSubjectCredits').value = btn.getAttribute('data-credits') || '4';
|
||||
document.getElementById('editSubjectCareer').value = btn.getAttribute('data-career-id') || '';
|
||||
document.getElementById('editSubjectDept').value = btn.getAttribute('data-department') || '';
|
||||
document.getElementById('editSubjectDesc').value = btn.getAttribute('data-description') || '';
|
||||
document.getElementById('editSubjectActive').checked = (btn.getAttribute('data-active') === 'true');
|
||||
|
||||
// Reset search filter
|
||||
var filterInput = modalEdit.querySelector('.career-filter-input');
|
||||
if (filterInput) filterInput.value = '';
|
||||
modalEdit.querySelectorAll('.career-item').forEach(function(item) {
|
||||
item.style.display = '';
|
||||
});
|
||||
|
||||
// Populate careers checkboxes
|
||||
var careerIdsStr = btn.getAttribute('data-career-ids') || btn.getAttribute('data-career-id') || '';
|
||||
var selectedIds = careerIdsStr ? careerIdsStr.split(',').map(function(s) { return s.trim(); }).filter(Boolean) : [];
|
||||
|
||||
modalEdit.querySelectorAll('#editSubjectCareerList .career-checkbox').forEach(function(cb) {
|
||||
cb.checked = selectedIds.includes(cb.value);
|
||||
});
|
||||
updateCareerCount('editSubjectCareerList', 'editSubjectCareerCount');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user