diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Index.hs | 25 | ||||
| -rw-r--r-- | src/Main.hs | 10 | ||||
| -rw-r--r-- | src/Pages.hs | 5 |
3 files changed, 27 insertions, 13 deletions
diff --git a/src/Index.hs b/src/Index.hs index 4b852bf..eedd1cd 100644 --- a/src/Index.hs +++ b/src/Index.hs @@ -466,24 +466,27 @@ indexCalendar (Index _ mp _) chan = do else coAll (scan IGV.! i) - coAll (scan IGV.! (i - 1)) | i <- [0 .. IGV.length scan - 1]]) -indexGetEventsDay :: Index -> Channel -> CountKind -> Day -> IO [(HMS, EventID, Event)] +-- | Returns the first and last day of this channel's logs, as well as the actual events on the requested day +indexGetEventsDay :: Index -> Channel -> CountKind -> Day -> IO ((Day, Day), [(HMS, EventID, Event)]) indexGetEventsDay index@(Index _ mp _) chan kind day = do ci <- readIORef (mp Map.! chan) + let firstlast = (ciStartDay ci, ciEndDay ci) let ymd = dayToYMD day if day < ciStartDay ci || day > ciEndDay ci - then return [] + then return (firstlast, []) else loadDay index chan ymd <&> \case Just (bs, _lineStarts) -> let events = parseLog bs - in case kind of - CKAll -> - [(hms, genEventID (YMDHMS ymd hms) off, ev) - | ((hms, ev), off) <- zip events [0..]] - CKCompressed -> - [(hms, genEventID (YMDHMS ymd hms) off, ev) - | ((hms, off), ev) <- compressEvents [((hms, off), ev) - | ((hms, ev), off) <- zip events [0..]]] - Nothing -> [] -- if the file doesn't exist, there ain't no events + events' = case kind of + CKAll -> + [(hms, genEventID (YMDHMS ymd hms) off, ev) + | ((hms, ev), off) <- zip events [0..]] + CKCompressed -> + [(hms, genEventID (YMDHMS ymd hms) off, ev) + | ((hms, off), ev) <- compressEvents [((hms, off), ev) + | ((hms, ev), off) <- zip events [0..]]] + in (firstlast, events') + Nothing -> (firstlast, []) -- if the file doesn't exist, there ain't no events -- utilities diff --git a/src/Main.hs b/src/Main.hs index 78098af..a06aef8 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -16,7 +16,7 @@ import Data.Map.Strict qualified as Map import Data.Text (Text) import Data.Text qualified as T import Data.Text.Encoding qualified as TE -import Data.Time (Day, toGregorian, fromGregorianValid) +import Data.Time (Day, toGregorian, fromGregorianValid, addDays) import System.Directory (listDirectory) import System.Environment import System.Exit (die) @@ -145,7 +145,7 @@ pageCalendarDay conf index req alias datestr = Just "all" -> (CKAll, Just "ef=all; Path=/") Just "compr" -> (CKCompressed, Just "ef=compr; Path=/") _ -> (CKAll, Nothing) - events <- indexGetEventsDay index chan kind day + ((firstday, lastday), events) <- indexGetEventsDay index chan kind day mpagehighlight <- if | Just (TE.decodeASCII' -> Just eventID) <- query req "eid" -> do mevidx <- findEventIDLinear index chan kind eventID @@ -166,6 +166,12 @@ pageCalendarDay conf index req alias datestr = , efAll = kind == CKAll , efCompr = kind == CKCompressed , date = T.pack (ymdToString (dayToYMD day)) + , picker = CalendarPickerData + { prevpage = if firstday < day then Just (T.pack (ymdToString (dayToYMD (addDays (-1) day)))) + else Nothing + , nextpage = if day < lastday then Just (T.pack (ymdToString (dayToYMD (addDays 1 day)))) + else Nothing + } , events = [EventData { classlist = if mpagehighlight == Just dayidx diff --git a/src/Pages.hs b/src/Pages.hs index 1a076ec..8bd7514 100644 --- a/src/Pages.hs +++ b/src/Pages.hs @@ -72,6 +72,7 @@ data CalendarDayData = CalendarDayData , efAll :: Bool , efCompr :: Bool , date :: Text + , picker :: CalendarPickerData , events :: [EventData Text ()] } @@ -88,6 +89,10 @@ data PickerData = PickerData , npages :: Int } +data CalendarPickerData = CalendarPickerData + { prevpage :: Maybe Text + , nextpage :: Maybe Text } + data EventData tm dttm = EventData { classlist :: Maybe Text , time :: tm |
