From 10879914b5d3a962e2c42fa3bf7b68e60bb40609 Mon Sep 17 00:00:00 2001 From: Francesco Baldino Date: Sun, 8 Oct 2023 19:09:53 +0200 Subject: [PATCH] Aggiornata ProposalPage e rimosso default limit --- api/controllers/ModelController.js | 2 +- frontend/src/components/NavBar.tsx | 2 +- frontend/src/pages/ProposalPage.js | 139 +++++++++++++++-------------- 3 files changed, 75 insertions(+), 68 deletions(-) diff --git a/api/controllers/ModelController.js b/api/controllers/ModelController.js index c8a5dce3..54871796 100644 --- a/api/controllers/ModelController.js +++ b/api/controllers/ModelController.js @@ -14,7 +14,7 @@ function queryFieldsToPipeline(query={}, fields={}) { let filter = {}; let sort = "_id"; let direction = 1; - let limit = 100; + let limit = Number.MAX_SAFE_INTEGER; for (key in query) { const value = query[key]; diff --git a/frontend/src/components/NavBar.tsx b/frontend/src/components/NavBar.tsx index c512883e..41987f85 100644 --- a/frontend/src/components/NavBar.tsx +++ b/frontend/src/components/NavBar.tsx @@ -35,7 +35,7 @@ export default function NavBar() {
  • - + Nuovo piano di studio diff --git a/frontend/src/pages/ProposalPage.js b/frontend/src/pages/ProposalPage.js index da492b3d..94451e0d 100644 --- a/frontend/src/pages/ProposalPage.js +++ b/frontend/src/pages/ProposalPage.js @@ -39,31 +39,56 @@ function ExamRow({ exam }) { } function ExamSelect({ exam, exams, groups }) { - let options = [] - let optionsPlaceholder = null if (exam.__t === "CompulsoryExam") { - const compulsoryExam = exams.find(e => e._id === exam.exam_id) - if (compulsoryExam) { - options = [ compulsoryExam.name ] - } + const compulsoryExam = exams[exam.exam_id] + return
  • +
    +
    + +
    +
    + +
    +
    +
  • } else if (exam.__t === "CompulsoryGroup") { - optionsPlaceholder = `Un esame a scelta nel gruppo ${exam.group}` - options = groups[exam.group].map(e => e.name) - } - return
  • -
    -
    - + const options = groups[exam.group] + return
  • +
    +
    + +
    +
    + +
    -
    - +
  • + } else if (exam.__t === "FreeChoiceExam") { + const options = Object.values(exams).sort((a, b) => a.name > b.name) + return
  • +
    +
    + +
    +
    + +
    +
    + +
    - -
  • + + } } + function YearCard({ year, number, exams, groups }) { const yearName = ["Primo", "Secondo", "Terzo"][number] || `#${number}` @@ -75,8 +100,13 @@ function YearCard({ year, number, exams, groups }) { return - {year.exams.map(exam => )} - + {year.exams.map(exam => )} +
    + + + +
    + } export function NewProposalPage() { @@ -104,52 +134,34 @@ export function NewProposalPage() { const degreesQuery = useIndex(Degree, null) const curriculaQuery = useIndex(Curriculum, proposal.degree_id ? { degree_id: proposal.degree_id } : null ) - const examsQuery = useIndex(Exam, { _limit: 99999 }) // Soluzione temporanea, capire se si possono ottenere tutti - // Anzi meglio sarebbe ottenere i degree con i groups giĆ  popolati + const examsQuery = useIndex(Exam, null) if (degreesQuery.isLoading) return caricamento corsi di laurea... if (degreesQuery.isError) return errore corsi di laurea... - const degrees = degreesQuery.data.items.map(d => new Degree(d)) + const degrees = Object.fromEntries(degreesQuery.data.items.map(d => [d._id, new Degree(d)])) if (curriculaQuery.isLoading) return caricamento curricula... if (curriculaQuery.isError) return errore curricula... - const curricula = curriculaQuery.data.items + const curricula = Object.fromEntries(curriculaQuery.data.items.map(c => [c._id, c])) if (examsQuery.isLoading) return caricamento esami... if (examsQuery.isError) return errore esami... - const exams = examsQuery.data.items - - const degree = proposal.degree_id ? degrees.find(d => d._id === proposal.degree_id) : null - const curriculum = proposal.curriculum_id ? curricula.find(c => c._id === proposal.curriculum_id) : null - - // Solo soluzione temporanea, potrebbe esser necessario cambiare l'API per - // poter popolare direttamente "groups" dei degrees - let groups = {} - if (degree) { - for (const key in degree.groups) { - groups[key] = [] - degree.groups[key].forEach(id => { - const exam = exams.find(e => e._id === id) - if (exam) { - groups[key].push(exam) - } - }) - } - } + const exams = Object.fromEntries(examsQuery.data.items.map(e => [e._id, e])) - if (degree) { - console.log('degree', degree) - console.log('groups', groups) - } - if (curriculum) { - console.log('curriculum', curriculum) - } - if (exams) { - console.log('exams', exams) - } + const degree = proposal.degree_id ? degrees[proposal.degree_id] : null + const curriculum = proposal.curriculum_id ? curricula[proposal.curriculum_id] : null + + const groups = degree ? + Object.fromEntries( + Object.entries(degree.groups).map(([group_id, group_exams]) => { + const populated_exams = group_exams.flatMap(id => exams[id] ? [ exams[id] ] : [] ).sort((a, b) => a.name > b.name ) + return [group_id, populated_exams] + }) + ) : + {} return <> @@ -162,15 +174,13 @@ export function NewProposalPage() { Selezionare il corso di Laurea { - degrees.map(degree => - [ - degree.academic_year, - degree.name, + Object.values(degrees).sort( + (a,b) => a.academic_year < b.academic_year || (a.academic_year === b.academic_year && a.name > b.name) + ).map((degree) => - ] - ).sort().reverse().map(([a,b,rendering]) => rendering) + ) } @@ -184,14 +194,11 @@ export function NewProposalPage() { Selezionare il Curriculum { - curricula.map(curriculum => - [ - curriculum.name, + Object.values(curricula).sort((a, b) => a.name > b.name).map(curriculum => - ] - ).sort().map(([a,rendering]) => rendering) + ) }