Fix: corsi con più aule, prof dei corsi, patch speciale per il lab di primo anno

main
Antonio De Lucreziis 2 years ago
parent 96ca0fef8f
commit 7d20ccab10

@ -2,7 +2,7 @@ import { format } from 'date-fns'
import _ from 'lodash' import _ from 'lodash'
import { useEffect, useRef, useState } from 'preact/hooks' import { useEffect, useRef, useState } from 'preact/hooks'
import { normalizeCourseName, WEEK_DAYS } from '../../utils.jsx' import { prettyCourseName, WEEK_DAYS } from '../../utils.jsx'
export const Course = ({ events, selection, setSelection, hideOtherCourses }) => { export const Course = ({ events, selection, setSelection, hideOtherCourses }) => {
const selectionSet = new Set(selection) const selectionSet = new Set(selection)
@ -11,6 +11,12 @@ export const Course = ({ events, selection, setSelection, hideOtherCourses }) =>
const eventsByCourse = _.groupBy(_.sortBy(visibleEvents, 'id'), 'id') const eventsByCourse = _.groupBy(_.sortBy(visibleEvents, 'id'), 'id')
const profsPerCourse = _.mapValues(eventsByCourse, events =>
_.uniq(events.flatMap(event => event.docenti))
)
console.log(profsPerCourse)
const [currentlyHovered, setCurrentlyHovered] = useState(null) const [currentlyHovered, setCurrentlyHovered] = useState(null)
const element = useRef() const element = useRef()
@ -51,14 +57,14 @@ export const Course = ({ events, selection, setSelection, hideOtherCourses }) =>
else setSelection(selection.filter(selId => selId !== id)) else setSelection(selection.filter(selId => selId !== id))
}} }}
> >
<div class="title">{normalizeCourseName(courseEvents[0].name)}</div> <div class="title">{prettyCourseName(courseEvents[0].name)}</div>
<div class="docenti">{courseEvents[0].docenti.join(', ')}</div> <div class="docenti">{profsPerCourse[id].join(', ')}</div>
<div class="events"> <div class="events">
{courseEvents.map(course => ( {courseEvents.map(course => (
<div> <div>
{WEEK_DAYS[course.start.getDay()]}{' '} {WEEK_DAYS[course.start.getDay()]}{' '}
{format(course.start, 'H:mm')} &ndash;{' '} {format(course.start, 'H:mm')}&ndash;
{format(course.end, 'H:mm')} {course.aula} {format(course.end, 'H:mm')} {course.aule.join(', ')}
</div> </div>
))} ))}
</div> </div>

@ -1,6 +1,6 @@
import { format } from 'date-fns' import { format } from 'date-fns'
import _ from 'lodash' import _ from 'lodash'
import { normalizeCourseName, WEEK_DAYS, withClasses } from '../../utils.jsx' import { prettyCourseName, WEEK_DAYS, withClasses } from '../../utils.jsx'
export const Schedule = ({ events, selection, setSelection, hideOtherCourses }) => { export const Schedule = ({ events, selection, setSelection, hideOtherCourses }) => {
const selectionSet = new Set(selection) const selectionSet = new Set(selection)
@ -37,12 +37,12 @@ export const Schedule = ({ events, selection, setSelection, hideOtherCourses })
) )
}} }}
> >
<div class="title">{normalizeCourseName(event.name)}</div> <div class="title">{prettyCourseName(event.name)}</div>
<div class="orario"> <div class="orario">
{format(event.start, 'H:mm')} &ndash;{' '} {format(event.start, 'H:mm')} &ndash;{' '}
{format(event.end, 'H:mm')} {format(event.end, 'H:mm')}
</div> </div>
<div class="aula">{event.aula}</div> <div class="aula">{event.aule.join(', ')}</div>
</div> </div>
))} ))}
</> </>

@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'preact/hooks'
import _ from 'lodash' import _ from 'lodash'
import { differenceInMinutes, startOfDay } from 'date-fns' import { differenceInMinutes, startOfDay } from 'date-fns'
import { hashString, normalizeCourseName, WEEK_DAYS } from '../../utils.jsx' import { hashString, prettyCourseName, WEEK_DAYS } from '../../utils.jsx'
import { layoutIntervals } from '../../interval-layout.js' import { layoutIntervals } from '../../interval-layout.js'
export const WorkWeek = ({ events, selection, setSelection, hideOtherCourses }) => { export const WorkWeek = ({ events, selection, setSelection, hideOtherCourses }) => {
@ -126,10 +126,8 @@ export const WorkWeek = ({ events, selection, setSelection, hideOtherCourses })
) )
}} }}
> >
<div class="title"> <div class="title">{prettyCourseName(event.data.name)}</div>
{normalizeCourseName(event.data.name)} <div class="aula">{event.data.aule.join(', ')}</div>
</div>
<div class="aula">{event.data.aula}</div>
</div> </div>
))} ))}
</> </>

@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'preact/hooks'
import _ from 'lodash' import _ from 'lodash'
import { differenceInMinutes, startOfDay } from 'date-fns' import { differenceInMinutes, startOfDay } from 'date-fns'
import { normalizeCourseName } from '../../utils.jsx' import { prettyCourseName } from '../../utils.jsx'
import { layoutIntervals } from '../../interval-layout.js' import { layoutIntervals } from '../../interval-layout.js'
export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses }) => { export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses }) => {
@ -197,7 +197,7 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
colors[event.data.id][1] colors[event.data.id][1]
})`}</div> })`}</div>
)} )}
{event.data.aula} {event.data.aule.join(', ')}
</div> </div>
))} ))}
</> </>
@ -217,7 +217,7 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
> >
{colors[course.id][1]} {colors[course.id][1]}
</div> </div>
<div class="name">{normalizeCourseName(course.name)}</div> <div class="name">{prettyCourseName(course.name)}</div>
</> </>
))} ))}
</div> </div>

@ -3,7 +3,7 @@ import { useEffect, useRef } from 'preact/hooks'
import _ from 'lodash' import _ from 'lodash'
import { differenceInMinutes, startOfDay } from 'date-fns' import { differenceInMinutes, startOfDay } from 'date-fns'
import { hashString, normalizeCourseName, WEEK_DAYS } from '../../utils.jsx' import { hashString, prettyCourseName, WEEK_DAYS } from '../../utils.jsx'
import { layoutIntervals } from '../../interval-layout.js' import { layoutIntervals } from '../../interval-layout.js'
export const WorkWeekTranspose = ({ events }) => { export const WorkWeekTranspose = ({ events }) => {
@ -87,7 +87,7 @@ export const WorkWeekTranspose = ({ events }) => {
}} }}
ref={eventRef} ref={eventRef}
> >
{normalizeCourseName(event.data.name)} {prettyCourseName(event.data.name)}
</div> </div>
) )
} }

@ -10,7 +10,7 @@ import { Icon } from './components/Icon.jsx'
import { Popup } from './components/Popup.jsx' import { Popup } from './components/Popup.jsx'
import { Toolbar } from './components/Toolbar.jsx' import { Toolbar } from './components/Toolbar.jsx'
import { OptionBar } from './components/OptionBar.jsx' import { OptionBar } from './components/OptionBar.jsx'
import { usePersistentState } from './utils.jsx' import { prettyAulaName, prettyProfName, usePersistentState } from './utils.jsx'
window._ = _ window._ = _
window.dataBuffer = {} window.dataBuffer = {}
@ -28,6 +28,19 @@ const CALENDAR_IDS = {
], ],
} }
function specialEventPatches(eventi) {
// Il laboratorio del primo anno in realtà è in due canali separati
let i = 1
eventi.forEach(evento => {
if (evento.nome === 'LABORATORIO DI INTRODUZIONE ALLA MATEMATICA COMPUTAZIONALE') {
evento.nome += ` (${i})`
i++
}
})
return eventi
}
async function loadEventi(ids) { async function loadEventi(ids) {
const calendari = await Promise.all( const calendari = await Promise.all(
ids.map(async id => { ids.map(async id => {
@ -61,10 +74,10 @@ async function loadEventi(ids) {
) )
if (ids.length === 1) { if (ids.length === 1) {
return calendari[0] return specialEventPatches(calendari[0])
} }
return _.uniqBy(_.concat(...calendari), 'id') return specialEventPatches(_.uniqBy(_.concat(...calendari), 'id'))
} }
const App = ({}) => { const App = ({}) => {
@ -147,13 +160,8 @@ const App = ({}) => {
name: _.split(nome, '-', 1)[0].trim(), name: _.split(nome, '-', 1)[0].trim(),
start: new Date(dataInizio), start: new Date(dataInizio),
end: new Date(dataFine), end: new Date(dataFine),
docenti: docenti.map(({ nome, cognome }) => docenti: docenti.map(({ nome, cognome }) => prettyProfName(nome, cognome)),
_.startCase(_.lowerCase(nome) + ' ' + _.lowerCase(cognome)) aule: aule.map(aula => prettyAulaName(aula.codice)),
),
aula: _.startCase(aule[0].codice.toLowerCase()).replace(
/([A-Z]) ([1-9])/,
'$1$2'
),
}))} }))}
/> />
{toolOverlayVisible && ( {toolOverlayVisible && (

@ -29,7 +29,7 @@ export function hashString(str, seed = 0) {
// Courses // Courses
export function normalizeCourseName(name) { export function prettyCourseName(name) {
return name return name
.split(' ') .split(' ')
.map(word => word.toLowerCase()) .map(word => word.toLowerCase())
@ -46,6 +46,17 @@ export function normalizeCourseName(name) {
.replaceAll(/'(.)/g, ({}, letter) => "'" + letter.toUpperCase()) .replaceAll(/'(.)/g, ({}, letter) => "'" + letter.toUpperCase())
} }
export function prettyAulaName(name) {
return name.replace('FIB', 'Fib').replace(/([A-Z0-9])\-LAB/, 'Lab $1')
}
export function prettyProfName(nome, cognome) {
return (nome + ' ' + cognome)
.split(/\b/)
.map(word => _.capitalize(word))
.join('')
}
// JSX // JSX
export const withClasses = classes => export const withClasses = classes =>

Loading…
Cancel
Save