fix(tutorial): template moving works now
This commit is contained in:
parent
79b45be5b6
commit
b982e59b63
@ -32,6 +32,7 @@ import Generics.Deriving.Monoid (memptydefault, mappenddefault)
|
|||||||
import qualified Database.Esqueleto.Experimental as E -- needs TypeApplications Lang-Pragma
|
import qualified Database.Esqueleto.Experimental as E -- needs TypeApplications Lang-Pragma
|
||||||
import qualified Database.Esqueleto.Utils as E
|
import qualified Database.Esqueleto.Utils as E
|
||||||
|
|
||||||
|
import Utils.Occurrences
|
||||||
|
|
||||||
|
|
||||||
type UserSearchKey = Text
|
type UserSearchKey = Text
|
||||||
@ -316,7 +317,7 @@ upsertNewTutorial cid newTutorialName newTutorialType newFirstDay = runDB $ do
|
|||||||
Course{..} <- get404 cid
|
Course{..} <- get404 cid
|
||||||
term <- get404 courseTerm
|
term <- get404 courseTerm
|
||||||
let oldFirstDay = fromMaybe moveDay $ tutorialFirstDay <|> fst (occurrencesBounds term tutorialTime)
|
let oldFirstDay = fromMaybe moveDay $ tutorialFirstDay <|> fst (occurrencesBounds term tutorialTime)
|
||||||
newTime = occurrencesAddBusinessDays term (oldFirstDay, moveDay) tutorialTime
|
newTime = normalizeOccurrences $ occurrencesAddBusinessDays term (oldFirstDay, moveDay) tutorialTime
|
||||||
dayDiff = maybe 0 (diffDays moveDay) tutorialFirstDay
|
dayDiff = maybe 0 (diffDays moveDay) tutorialFirstDay
|
||||||
mvTime = fmap $ addLocalDays dayDiff
|
mvTime = fmap $ addLocalDays dayDiff
|
||||||
newType0 = CI.mk . snd . Text.breakOnEnd tutorialTypeSeparator $ CI.original tutorialType
|
newType0 = CI.mk . snd . Text.breakOnEnd tutorialTypeSeparator $ CI.original tutorialType
|
||||||
|
|||||||
@ -51,8 +51,8 @@ occurrencesBounds Term{..} Occurrences{..} = (Set.lookupMin occDays, Set.lookupM
|
|||||||
getOccDays :: OccurrenceSchedule -> Set Day -> Set Day
|
getOccDays :: OccurrenceSchedule -> Set Day -> Set Day
|
||||||
getOccDays ScheduleWeekly{scheduleDayOfWeek=wday} = Set.union $ daysOfWeekBetween (termLectureStart,termLectureEnd) wday
|
getOccDays ScheduleWeekly{scheduleDayOfWeek=wday} = Set.union $ daysOfWeekBetween (termLectureStart,termLectureEnd) wday
|
||||||
|
|
||||||
occurrencesAddBusinessDays :: Term -> (Day,Day) -> Occurrences -> (Occurrences,_)
|
occurrencesAddBusinessDays :: Term -> (Day,Day) -> Occurrences -> Occurrences
|
||||||
occurrencesAddBusinessDays Term{..} (dayOld, dayNew) Occurrences{..} = (Occurrences newSchedule newExceptions,(dayDiff, offDays,loff,dgb))
|
occurrencesAddBusinessDays Term{..} (dayOld, dayNew) Occurrences{..} = Occurrences newSchedule newExceptions
|
||||||
where
|
where
|
||||||
newSchedule = Set.map switchDayOfWeek occurrencesScheduled
|
newSchedule = Set.map switchDayOfWeek occurrencesScheduled
|
||||||
dayDiff = diffDays dayNew dayOld
|
dayDiff = diffDays dayNew dayOld
|
||||||
@ -64,16 +64,16 @@ occurrencesAddBusinessDays Term{..} (dayOld, dayNew) Occurrences{..} = (Occurren
|
|||||||
switchDayOfWeek os | 0 == dayDiff `mod` 7 = os
|
switchDayOfWeek os | 0 == dayDiff `mod` 7 = os
|
||||||
switchDayOfWeek os@ScheduleWeekly{scheduleDayOfWeek=wday} = os{scheduleDayOfWeek= toEnum (fromIntegral dayDiff + fromEnum wday)}
|
switchDayOfWeek os@ScheduleWeekly{scheduleDayOfWeek=wday} = os{scheduleDayOfWeek= toEnum (fromIntegral dayDiff + fromEnum wday)}
|
||||||
|
|
||||||
(loff,newExceptions,dgb) = Set.foldl (flip advanceExceptions) (dayDiff,mempty,mempty) occurrencesExceptions
|
newExceptions = snd $ Set.foldl' advanceExceptions (dayDiff,mempty) occurrencesExceptions
|
||||||
|
|
||||||
-- we assume that instance Ord OccurrenceException is ordered chronologically
|
-- we assume that instance Ord OccurrenceException is ordered chronologically
|
||||||
advanceExceptions :: OccurrenceException -> (Integer, Set OccurrenceException,_) -> (Integer, Set OccurrenceException,_)
|
advanceExceptions :: (Integer, Set OccurrenceException) -> OccurrenceException -> (Integer, Set OccurrenceException)
|
||||||
advanceExceptions ex (offset, acc, dbg)
|
advanceExceptions (offset, acc) ex
|
||||||
| ed `Set.notMember` offDays -- skip term-holidays and weekends, unless the original day was a holiday or weekend
|
| ed `Set.notMember` offDays -- skip term-holidays and weekends, unless the original day was a holiday or weekend
|
||||||
, nd `Set.member` offDays
|
, nd `Set.member` offDays
|
||||||
= advanceExceptions ex (succ offset, acc, ("skip"<>show offset) :dbg)
|
= advanceExceptions (succ offset, acc) ex
|
||||||
| otherwise
|
| otherwise
|
||||||
= (offset, Set.insert (setDayOfOccurrenceException nd ex) acc, show ex : dbg)
|
= (offset, Set.insert (setDayOfOccurrenceException nd ex) acc)
|
||||||
where
|
where
|
||||||
ed = dayOfOccurrenceException ex
|
ed = dayOfOccurrenceException ex
|
||||||
nd = addDays offset ed
|
nd = addDays offset ed
|
||||||
|
|||||||
@ -1027,7 +1027,7 @@ fillDb = do
|
|||||||
insert_ Tutorial
|
insert_ Tutorial
|
||||||
{ tutorialName = mkName "Vorlage"
|
{ tutorialName = mkName "Vorlage"
|
||||||
, tutorialCourse = c
|
, tutorialCourse = c
|
||||||
, tutorialType = "Vorlage___Schulung"
|
, tutorialType = "Vorlage"
|
||||||
, tutorialCapacity = capacity
|
, tutorialCapacity = capacity
|
||||||
, tutorialRoom = Just $ case weekDay of
|
, tutorialRoom = Just $ case weekDay of
|
||||||
Monday -> "A380"
|
Monday -> "A380"
|
||||||
@ -1045,10 +1045,15 @@ fillDb = do
|
|||||||
, exceptEnd = TimeOfDay 16 0 0
|
, exceptEnd = TimeOfDay 16 0 0
|
||||||
}
|
}
|
||||||
, ExceptOccur
|
, ExceptOccur
|
||||||
{ exceptDay = secondDay
|
{ exceptDay = succ firstDay
|
||||||
, exceptStart = TimeOfDay 9 0 0
|
, exceptStart = TimeOfDay 9 0 0
|
||||||
, exceptEnd = TimeOfDay 16 0 0
|
, exceptEnd = TimeOfDay 16 0 0
|
||||||
}
|
}
|
||||||
|
, ExceptOccur
|
||||||
|
{ exceptDay = secondDay
|
||||||
|
, exceptStart = TimeOfDay 10 12 0
|
||||||
|
, exceptEnd = TimeOfDay 12 13 0
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
, tutorialRegGroup = Just "schulung"
|
, tutorialRegGroup = Just "schulung"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user