|
|
|
@ -24,43 +24,40 @@ import {
|
|
|
|
|
clearOldPersistentStates,
|
|
|
|
|
usePersistentState,
|
|
|
|
|
} from './utils.jsx'
|
|
|
|
|
import { SettingsBar } from './components/SettingsBar.jsx'
|
|
|
|
|
|
|
|
|
|
// Che fanno queste due righe?
|
|
|
|
|
window._ = _
|
|
|
|
|
window.dataBuffer = {}
|
|
|
|
|
|
|
|
|
|
const TIMETABLE_IDS = {
|
|
|
|
|
'anno-1': '667e88275e9623041f0e43d4',
|
|
|
|
|
'anno-2': '667e89055e9623041f0e43d6',
|
|
|
|
|
'anno-3': '667e89fcf748ed0415a11dcc',
|
|
|
|
|
'magistrale': '667ebae63379a3046517ffd4',
|
|
|
|
|
'anno-1': '64a7c1c651f079001d52e9c8',
|
|
|
|
|
'anno-2': '6308e2dc09352a0208fefdd9',
|
|
|
|
|
'anno-3': '6308e42a1df5cb026699ced4',
|
|
|
|
|
'magistrale': '64a7c7091ab813002c5d9ede',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// const DEFAULT_DATE_RANGE = {
|
|
|
|
|
// from: '2023-10-09T00:00:00.000Z',
|
|
|
|
|
// to: '2023-10-14T00:00:00.000Z',
|
|
|
|
|
// }
|
|
|
|
|
const DEFAULT_DATE_RANGE = {
|
|
|
|
|
from: '2023-10-09T00:00:00.000Z',
|
|
|
|
|
to: '2023-10-14T00:00:00.000Z',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// const DATE_RANGES = {
|
|
|
|
|
// '64a7c1c651f079001d52e9c8': DEFAULT_DATE_RANGE,
|
|
|
|
|
// '6308e2dc09352a0208fefdd9': DEFAULT_DATE_RANGE,
|
|
|
|
|
// '6308e42a1df5cb026699ced4': DEFAULT_DATE_RANGE,
|
|
|
|
|
// '64a7c7091ab813002c5d9ede': DEFAULT_DATE_RANGE,
|
|
|
|
|
// }
|
|
|
|
|
const DATE_RANGES = {
|
|
|
|
|
'64a7c1c651f079001d52e9c8': DEFAULT_DATE_RANGE,
|
|
|
|
|
'6308e2dc09352a0208fefdd9': DEFAULT_DATE_RANGE,
|
|
|
|
|
'6308e42a1df5cb026699ced4': DEFAULT_DATE_RANGE,
|
|
|
|
|
'64a7c7091ab813002c5d9ede': DEFAULT_DATE_RANGE,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function specialEventPatches(eventi) {
|
|
|
|
|
// Il laboratorio del primo anno in realtà è in due gruppi separati
|
|
|
|
|
// 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 ===
|
|
|
|
|
'LABORATORIO DI INTRODUZIONE ALLA MATEMATICA COMPUTAZIONALE'
|
|
|
|
|
) {
|
|
|
|
|
if (evento.docenti[0].nome === 'GIOVANNI') {
|
|
|
|
|
evento.nome += ' (A)'
|
|
|
|
|
}
|
|
|
|
|
if (evento.docenti[0].nome === 'PAOLO') {
|
|
|
|
|
evento.nome += ' (B)'
|
|
|
|
|
}
|
|
|
|
|
evento.nome += ` (${i})`
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
@ -74,24 +71,15 @@ function formatEvents(timetable) {
|
|
|
|
|
name: _.split(nome, '-', 1)[0].trim(),
|
|
|
|
|
start: new Date(dataInizio),
|
|
|
|
|
end: new Date(dataFine),
|
|
|
|
|
docenti: docenti.map(({ nome, cognome }) => prettyProfName(nome, cognome)),
|
|
|
|
|
docenti: docenti.map(({ nome, cognome }) =>
|
|
|
|
|
prettyProfName(nome, cognome)
|
|
|
|
|
),
|
|
|
|
|
aule: aule.map(aula => prettyAulaName(aula.codice)),
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadCalendari(date) {
|
|
|
|
|
function getMonday(d) {
|
|
|
|
|
const day = d.getDay()
|
|
|
|
|
const diff = d.getDate() - day + (day === 0 ? -6 : 1)
|
|
|
|
|
const monday = new Date(d.setDate(diff))
|
|
|
|
|
monday.setUTCHours(0, 0, 0, 0)
|
|
|
|
|
return monday
|
|
|
|
|
}
|
|
|
|
|
const monday = getMonday(date)
|
|
|
|
|
const saturday = new Date(monday)
|
|
|
|
|
saturday.setDate(monday.getDate() + 5)
|
|
|
|
|
|
|
|
|
|
async function loadCalendari() {
|
|
|
|
|
async function req(id) {
|
|
|
|
|
// Almost directly copy-pasted from Chrome Dev Tools
|
|
|
|
|
const req = await fetch(
|
|
|
|
@ -109,8 +97,8 @@ async function loadCalendari(date) {
|
|
|
|
|
linkCalendarioId: id,
|
|
|
|
|
clienteId: '628de8b9b63679f193b87046',
|
|
|
|
|
pianificazioneTemplate: false,
|
|
|
|
|
dataInizio: monday.toISOString(),
|
|
|
|
|
dataFine: saturday.toISOString(),
|
|
|
|
|
dataInizio: DATE_RANGES[id].from,
|
|
|
|
|
dataFine: DATE_RANGES[id].to,
|
|
|
|
|
}),
|
|
|
|
|
method: 'POST',
|
|
|
|
|
mode: 'cors',
|
|
|
|
@ -131,7 +119,7 @@ async function loadCalendari(date) {
|
|
|
|
|
const timetablesRaw = results.map(timetable =>
|
|
|
|
|
specialEventPatches(_.uniqBy(timetable, 'id'))
|
|
|
|
|
)
|
|
|
|
|
const allRaw = specialEventPatches(_.concat(...results), 'id')
|
|
|
|
|
const allRaw = specialEventPatches(_.uniqBy(_.concat(...results), 'id'))
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'anno-1': formatEvents(timetablesRaw[0]),
|
|
|
|
@ -142,53 +130,29 @@ async function loadCalendari(date) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const View = ({ view, selection, setSelection, timetables }) => {
|
|
|
|
|
if (view === 'orario') {
|
|
|
|
|
return <Schedule selection={selection} timetables={timetables} />
|
|
|
|
|
} else if (view === 'lista') {
|
|
|
|
|
return (
|
|
|
|
|
<Courses
|
|
|
|
|
selection={selection}
|
|
|
|
|
setSelection={setSelection}
|
|
|
|
|
source={'tutti'}
|
|
|
|
|
timetables={timetables}
|
|
|
|
|
hideOtherCourses={true}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<Courses
|
|
|
|
|
selection={selection}
|
|
|
|
|
setSelection={setSelection}
|
|
|
|
|
source={view}
|
|
|
|
|
timetables={timetables}
|
|
|
|
|
hideOtherCourses={false}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const App = ({}) => {
|
|
|
|
|
// Clear persistent states unless state_token corresponds to the one passed
|
|
|
|
|
// as the argument. Useful with breaking updates. Change this token if your
|
|
|
|
|
// (breaking) update needs a reset of persistent states to avoid crashes.
|
|
|
|
|
//
|
|
|
|
|
// Use any random string of your choice
|
|
|
|
|
// clearOldPersistentStates('e73cba02')
|
|
|
|
|
|
|
|
|
|
const [date, setDate] = useState(new Date().toISOString())
|
|
|
|
|
clearOldPersistentStates('e73cba02')
|
|
|
|
|
|
|
|
|
|
// Data Sources
|
|
|
|
|
const [view, setView] = usePersistentState('view', 'magistrale')
|
|
|
|
|
const [source, setSource] = usePersistentState('source', 'magistrale')
|
|
|
|
|
const [timetables, setTimetables] = useState(null)
|
|
|
|
|
useEffect(async () => {
|
|
|
|
|
setTimetables(await loadCalendari(new Date(date)))
|
|
|
|
|
}, [date])
|
|
|
|
|
setTimetables(await loadCalendari())
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
// View Modes
|
|
|
|
|
// const [mode, setMode] = usePersistentState('orario.mode', MODE_COURSES)
|
|
|
|
|
|
|
|
|
|
// Selection
|
|
|
|
|
const [selectedCourses, setSelectedCourses] = usePersistentState('selection', [])
|
|
|
|
|
const [selectedCourses, setSelectedCourses] = usePersistentState(
|
|
|
|
|
'selection',
|
|
|
|
|
[]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Menus
|
|
|
|
|
const [helpVisible, setHelpVisible] = useState(false)
|
|
|
|
@ -211,78 +175,69 @@ const App = ({}) => {
|
|
|
|
|
<>
|
|
|
|
|
<Toolbar
|
|
|
|
|
{...{
|
|
|
|
|
source: view,
|
|
|
|
|
setSource: setView,
|
|
|
|
|
date: date,
|
|
|
|
|
setDate: setDate,
|
|
|
|
|
showMobileMenu: showMobileMenu,
|
|
|
|
|
setShowMobileMenu: setShowMobileMenu,
|
|
|
|
|
source,
|
|
|
|
|
setSource,
|
|
|
|
|
onShowMenu: () => setShowMobileMenu(true),
|
|
|
|
|
onHelp: () => setHelpVisible(true),
|
|
|
|
|
theme,
|
|
|
|
|
setTheme,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{showMobileMenu ? (
|
|
|
|
|
<SettingsBar
|
|
|
|
|
{...{
|
|
|
|
|
theme,
|
|
|
|
|
setTheme,
|
|
|
|
|
date,
|
|
|
|
|
setDate,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<OptionBar
|
|
|
|
|
{...{
|
|
|
|
|
view: view,
|
|
|
|
|
setView: setView,
|
|
|
|
|
onHelp: () => setHelpVisible(true),
|
|
|
|
|
}}
|
|
|
|
|
orizzontale
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<OptionBar
|
|
|
|
|
{...{
|
|
|
|
|
source,
|
|
|
|
|
setSource,
|
|
|
|
|
onHelp: () => setHelpVisible(true),
|
|
|
|
|
}}
|
|
|
|
|
orizzontale
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div class="content">
|
|
|
|
|
{timetables &&
|
|
|
|
|
(showMobileMenu ? (
|
|
|
|
|
<HamburgerMenu
|
|
|
|
|
{...{
|
|
|
|
|
date,
|
|
|
|
|
setDate,
|
|
|
|
|
theme,
|
|
|
|
|
setTheme,
|
|
|
|
|
onClose: () => {
|
|
|
|
|
setShowMobileMenu(false)
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
{timetables && (
|
|
|
|
|
<div class="content">
|
|
|
|
|
{source === 'orario' ? (
|
|
|
|
|
<Schedule
|
|
|
|
|
selection={selectedCourses}
|
|
|
|
|
setSelection={setSelectedCourses}
|
|
|
|
|
start={new Date(2022, 10, 3)}
|
|
|
|
|
source={source}
|
|
|
|
|
timetables={timetables}
|
|
|
|
|
/>
|
|
|
|
|
) : timetables['tutti'].length === 0 ? (
|
|
|
|
|
<div class="warning">
|
|
|
|
|
<p>
|
|
|
|
|
Non esistono corsi per la settimana selezionata: buone
|
|
|
|
|
vacanze! 🎉
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
Per cambiare settimana puoi usare il widget Calendario (
|
|
|
|
|
<Icon name="calendar_month" />) in alto a destra
|
|
|
|
|
<br />
|
|
|
|
|
In versione mobile, il widget Calendario è situato dentro
|
|
|
|
|
il Menu (
|
|
|
|
|
<Icon name="menu" />)
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<View
|
|
|
|
|
<Courses
|
|
|
|
|
selection={selectedCourses}
|
|
|
|
|
setSelection={setSelectedCourses}
|
|
|
|
|
view={view}
|
|
|
|
|
start={new Date(2022, 10, 3)}
|
|
|
|
|
source={source}
|
|
|
|
|
timetables={timetables}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* showMobileMenu && (
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{/* toolOverlayVisible && (
|
|
|
|
|
<ToolOverlay
|
|
|
|
|
mode={mode}
|
|
|
|
|
toggleMode={() =>
|
|
|
|
|
setMode(
|
|
|
|
|
mode === MODE_COURSES ? MODE_SCHEDULE : MODE_COURSES
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onClose={() => {
|
|
|
|
|
setSelectedCourses([])
|
|
|
|
|
setMode(MODE_COURSES)
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) */}
|
|
|
|
|
{showMobileMenu && (
|
|
|
|
|
<HamburgerMenu
|
|
|
|
|
{...{
|
|
|
|
|
theme,
|
|
|
|
|
setTheme,
|
|
|
|
|
onClose: () => {
|
|
|
|
|
setShowMobileMenu(false)
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{helpVisible && (
|
|
|
|
|
<Popup
|
|
|
|
|
title={
|
|
|
|
|