From 9f52bec00561d7d481b79a38fa02586626b4b5cd Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 20 Jul 2026 10:10:21 +0100 Subject: Prev/next buttons on calendar-day Thanks jreicher for suggesting! --- pages/calendar-day.mustache | 8 +++++++- src/Index.hs | 25 ++++++++++++++----------- src/Main.hs | 10 ++++++++-- src/Pages.hs | 5 +++++ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/pages/calendar-day.mustache b/pages/calendar-day.mustache index a40f072..f47a41b 100644 --- a/pages/calendar-day.mustache +++ b/pages/calendar-day.mustache @@ -18,7 +18,13 @@

Logs on {{date}} ({{network}}/{{channel}})

-
+
+ {{#picker}} + {{#prevpage}}{{/prevpage}}←Prev{{#prevpage}}{{/prevpage}}  + {{#nextpage}}{{/nextpage}}Next→{{#nextpage}}{{/nextpage}} + {{/picker}} +
+
View: {{^efAll}}{{/efAll}}All{{^efAll}}{{/efAll}}  {{^efCompr}}{{/efCompr}}Compressed{{^efCompr}}{{/efCompr}} 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 -- cgit v1.3.1