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

pull/4/head
Antonio De Lucreziis 2 years ago
parent 96ca0fef8f
commit 7d20ccab10

@ -2,7 +2,7 @@ import { format } from 'date-fns'
import _ from 'lodash'
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 }) => {
const selectionSet = new Set(selection)
@ -11,6 +11,12 @@ export const Course = ({ events, selection, setSelection, hideOtherCourses }) =>
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 element = useRef()
@ -51,14 +57,14 @@ export const Course = ({ events, selection, setSelection, hideOtherCourses }) =>
else setSelection(selection.filter(selId => selId !== id))
}}
>
<div class="title">{normalizeCourseName(courseEvents[0].name)}</div>
<div class="docenti">{courseEvents[0].docenti.join(', ')}</div>
<div class="title">{prettyCourseName(courseEvents[0].name)}</div>
<div class="docenti">{profsPerCourse[id].join(', ')}</div>
<div class="events">
{courseEvents.map(course => (
<div>
{WEEK_DAYS[course.start.getDay()]}{' '}
{format(course.start, 'H:mm')} &ndash;{' '}
{format(course.end, 'H:mm')} {course.aula}
{format(course.start, 'H:mm')}&ndash;
{format(course.end, 'H:mm')} {course.aule.join(', ')}
</div>
))}
</div>

@ -1,6 +1,6 @@
import { format } from 'date-fns'
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 }) => {
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">
{format(event.start, 'H:mm')} &ndash;{' '}
{format(event.end, 'H:mm')}
</div>
<div class="aula">{event.aula}</div>
<div class="aula">{event.aule.join(', ')}</div>
</div>
))}
</>

@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'preact/hooks'
import _ from 'lodash'
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'
export const WorkWeek = ({ events, selection, setSelection, hideOtherCourses }) => {
@ -126,10 +126,8 @@ export const WorkWeek = ({ events, selection, setSelection, hideOtherCourses })
)
}}
>
<div class="title">
{normalizeCourseName(event.data.name)}
</div>
<div class="aula">{event.data.aula}</div>
<div class="title">{prettyCourseName(event.data.name)}</div>
<div class="aula">{event.data.aule.join(', ')}</div>
</div>
))}
</>

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

@ -3,7 +3,7 @@ import { useEffect, useRef } from 'preact/hooks'
import _ from 'lodash'
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'
export const WorkWeekTranspose = ({ events }) => {
@ -87,7 +87,7 @@ export const WorkWeekTranspose = ({ events }) => {
}}
ref={eventRef}
>
{normalizeCourseName(event.data.name)}
{prettyCourseName(event.data.name)}
</div>
)
}

@ -10,7 +10,7 @@ import { Icon } from './components/Icon.jsx'
import { Popup } from './components/Popup.jsx'
import { Toolbar } from './components/Toolbar.jsx'
import { OptionBar } from './components/OptionBar.jsx'
import { usePersistentState } from './utils.jsx'
import { prettyAulaName, prettyProfName, usePersistentState } from './utils.jsx'
window._ = _
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) {
const calendari = await Promise.all(
ids.map(async id => {
@ -61,10 +74,10 @@ async function loadEventi(ids) {
)
if (ids.length === 1) {
return calendari[0]
return specialEventPatches(calendari[0])
}
return _.uniqBy(_.concat(...calendari), 'id')
return specialEventPatches(_.uniqBy(_.concat(...calendari), 'id'))
}
const App = ({}) => {
@ -147,13 +160,8 @@ const App = ({}) => {
name: _.split(nome, '-', 1)[0].trim(),
start: new Date(dataInizio),
end: new Date(dataFine),
docenti: docenti.map(({ nome, cognome }) =>
_.startCase(_.lowerCase(nome) + ' ' + _.lowerCase(cognome))
),
aula: _.startCase(aule[0].codice.toLowerCase()).replace(
/([A-Z]) ([1-9])/,
'$1$2'
),
docenti: docenti.map(({ nome, cognome }) => prettyProfName(nome, cognome)),
aule: aule.map(aula => prettyAulaName(aula.codice)),
}))}
/>
{toolOverlayVisible && (

@ -29,7 +29,7 @@ export function hashString(str, seed = 0) {
// Courses
export function normalizeCourseName(name) {
export function prettyCourseName(name) {
return name
.split(' ')
.map(word => word.toLowerCase())
@ -46,6 +46,17 @@ export function normalizeCourseName(name) {
.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
export const withClasses = classes =>

Loading…
Cancel
Save