diff --git a/src/components/view/Course.jsx b/src/components/view/Course.jsx index fe2a7bf..6a4d70f 100644 --- a/src/components/view/Course.jsx +++ b/src/components/view/Course.jsx @@ -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)) }} > -
{normalizeCourseName(courseEvents[0].name)}
-
{courseEvents[0].docenti.join(', ')}
+
{prettyCourseName(courseEvents[0].name)}
+
{profsPerCourse[id].join(', ')}
{courseEvents.map(course => (
{WEEK_DAYS[course.start.getDay()]}{' '} - {format(course.start, 'H:mm')} –{' '} - {format(course.end, 'H:mm')} {course.aula} + {format(course.start, 'H:mm')}– + {format(course.end, 'H:mm')} {course.aule.join(', ')}
))}
diff --git a/src/components/view/Schedule.jsx b/src/components/view/Schedule.jsx index eb05f18..c3a1a9d 100644 --- a/src/components/view/Schedule.jsx +++ b/src/components/view/Schedule.jsx @@ -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 }) ) }} > -
{normalizeCourseName(event.name)}
+
{prettyCourseName(event.name)}
{format(event.start, 'H:mm')} –{' '} {format(event.end, 'H:mm')}
-
{event.aula}
+
{event.aule.join(', ')}
))} diff --git a/src/components/view/WorkWeek.jsx b/src/components/view/WorkWeek.jsx index 07b8228..1ce41e1 100644 --- a/src/components/view/WorkWeek.jsx +++ b/src/components/view/WorkWeek.jsx @@ -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 }) ) }} > -
- {normalizeCourseName(event.data.name)} -
-
{event.data.aula}
+
{prettyCourseName(event.data.name)}
+
{event.data.aule.join(', ')}
))} diff --git a/src/components/view/WorkWeekGrid.jsx b/src/components/view/WorkWeekGrid.jsx index 7112403..75bd076 100644 --- a/src/components/view/WorkWeekGrid.jsx +++ b/src/components/view/WorkWeekGrid.jsx @@ -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] })`} )} - {event.data.aula} + {event.data.aule.join(', ')} ))} @@ -217,7 +217,7 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses > {colors[course.id][1]} -
{normalizeCourseName(course.name)}
+
{prettyCourseName(course.name)}
))} diff --git a/src/components/view/WorkWeekTranspose.jsx b/src/components/view/WorkWeekTranspose.jsx index 25f17f6..9d0a43b 100644 --- a/src/components/view/WorkWeekTranspose.jsx +++ b/src/components/view/WorkWeekTranspose.jsx @@ -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)} ) } diff --git a/src/main.jsx b/src/main.jsx index adb197c..0597af7 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -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 && ( diff --git a/src/utils.jsx b/src/utils.jsx index 48fcf14..9a05af2 100644 --- a/src/utils.jsx +++ b/src/utils.jsx @@ -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 =>