Skip to content

Commit

Permalink
Change the handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PetJer committed Nov 19, 2024
1 parent 95fd5a7 commit b59794a
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions website/src/components/TimetableDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,46 @@ function filterForTargetDay(lessonsTime: MergedLesson[][]) {
}
function handleSubstitutionsSpacialCase(lessonsTimeDay: MergedLesson[]) {
if (lessonsTimeDay.length > 1) {
for (const lesson of lessonsTimeDay) {
if (lesson.isSubstitution && lesson.substitutionSubject !== lesson.subject) {
const sharedSubstitutionLesson = lesson
sharedSubstitutionLesson.subject = ''
sharedSubstitutionLesson.teacher = ''
sharedSubstitutionLesson.classroom = ''
sharedSubstitutionLesson.notes ??= 'ves razred'
// Important: this can cause breaking changes when multiple entities have overlapping times
// Special cases occur only when multiple lessons happen at the same time (only in class view).
// This counts for ŠVM/ŠVŽ, INFV/INF and language lessons happening at the same time (FRA/ITA/NEM/ŠPA)
if (currentEntityType.value === EntityType.Class && lessonsTimeDay.length > 1) {
// If subjects that are not in the timetable originally appear,
// we replace the original subjects with them
if (lessonsTimeDay.find(l => l.subject === null)) {
return lessonsTimeDay.filter(l => l.subject === null)
}
lessonsTimeDay = [sharedSubstitutionLesson]
// A subject change needs to be present as this is the breaking point
const lesson: MergedLesson | undefined = lessonsTimeDay.find(
l => l.isSubstitution && l.substitutionSubject !== l.subject,
)
if (!lesson) return lessonsTimeDay
// We need to treat ŠVM/ŠVŽ and INFV/INF as the same subject,
// so what happens to one happens to another
if (['ŠVM', 'ŠVŽ', 'INFV', 'INF'].includes(lesson.subject!)) {
if (lessonsTimeDay.length > 2) {
// When there are more than 2 subject it means a new subject has appeared.
// We need to delete the original subjects then
return lessonsTimeDay.filter(l => !['ŠVM', 'ŠVŽ', 'INFV', 'INF'].includes(l.subject || ''))
} else {
// We keep only the element of the subject pair that changed
return lessonsTimeDay.filter(l => l === lesson)
}
}
// At this point we are left only with languages
const LanguageLesson: MergedLesson | undefined = lessonsTimeDay.find(
l => l.isSubstitution && !['FRA', 'ITA', 'NEM', 'ŠPA', null].includes(l.substitutionSubject),
)
if (!LanguageLesson) return lessonsTimeDay
// If a subject was changed for another then all the languages are substituted with the new subject
return [LanguageLesson!]
}
return lessonsTimeDay
Expand Down

0 comments on commit b59794a

Please sign in to comment.