From 9f8c53ac165f134d0c2c8600b8d0a239337bad93 Mon Sep 17 00:00:00 2001 From: Francesco Baldino Date: Tue, 3 Oct 2023 19:37:19 +0200 Subject: [PATCH] Strutturato form di ProposalPage Non definitivo, prevede notevoli modifiche e aggiunte, possibilmente anche all'API per le index query --- frontend/src/pages/ProposalPage.js | 72 ++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/ProposalPage.js b/frontend/src/pages/ProposalPage.js index 335b4ec2..da492b3d 100644 --- a/frontend/src/pages/ProposalPage.js +++ b/frontend/src/pages/ProposalPage.js @@ -38,7 +38,33 @@ function ExamRow({ exam }) { } -function YearCard({ year, number }) { +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 ] + } + } else if (exam.__t === "CompulsoryGroup") { + optionsPlaceholder = `Un esame a scelta nel gruppo ${exam.group}` + options = groups[exam.group].map(e => e.name) + } + return
  • +
    +
    + +
    +
    + +
    +
    +
  • +} +function YearCard({ year, number, exams, groups }) { const yearName = ["Primo", "Secondo", "Terzo"][number] || `#${number}` const customHeader =
    @@ -49,7 +75,7 @@ function YearCard({ year, number }) {
    return - + {year.exams.map(exam => )} } @@ -78,12 +104,12 @@ 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 if (degreesQuery.isLoading) return caricamento corsi di laurea... if (degreesQuery.isError) return errore corsi di laurea... - // const degrees = degreesQuery.data.items - // console.log(degrees[0] instanceof Degree) // FALSE! const degrees = degreesQuery.data.items.map(d => new Degree(d)) if (curriculaQuery.isLoading) return caricamento curricula... @@ -91,10 +117,38 @@ export function NewProposalPage() { const curricula = curriculaQuery.data.items + 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) + } + }) + } + } + + if (degree) { + console.log('degree', degree) + console.log('groups', groups) + } if (curriculum) { - console.log(curriculum) + console.log('curriculum', curriculum) + } + if (exams) { + console.log('exams', exams) } return <> @@ -104,7 +158,7 @@ export function NewProposalPage() { onChange={e => setProposal({ ... proposal, degree_id: e.target.value })} value={proposal.degree_id || -1} > - { @@ -116,7 +170,7 @@ export function NewProposalPage() { {degree.name} — anno di immatricolazione {degree.academic_years()} ] - ).sort().map(([a,b,rendering]) => rendering) + ).sort().reverse().map(([a,b,rendering]) => rendering) } @@ -126,7 +180,7 @@ export function NewProposalPage() { onChange={e => setProposal({ ... proposal, curriculum_id: e.target.value })} value={proposal.curriculum_id || -1} > - { @@ -148,7 +202,7 @@ export function NewProposalPage() { { proposal.degree_id && proposal.curriculum_id && curriculum && <> { - curriculum.years.map((year, number) => ) + curriculum.years.map((year, number) => ) } }