summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2026-07-20 11:10:21 +0200
committerTom Smeding <tom@tomsmeding.com>2026-07-20 11:10:21 +0200
commit9f52bec00561d7d481b79a38fa02586626b4b5cd (patch)
tree405566b391ce43743aa997a213d06371658fdcb7
parent72379334b9efa362e7083963b75bb6e69530298d (diff)
Prev/next buttons on calendar-day
Thanks jreicher for suggesting!
-rw-r--r--pages/calendar-day.mustache8
-rw-r--r--src/Index.hs25
-rw-r--r--src/Main.hs10
-rw-r--r--src/Pages.hs5
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 @@
</header>
<main>
<h1>Logs on {{date}} ({{network}}/{{channel}})</h1>
- <div class="viewopts">
+ <div class="pagepicker">
+ {{#picker}}
+ {{#prevpage}}<a href="/cal/{{&alias}}/{{.}}">{{/prevpage}}&larr;Prev{{#prevpage}}</a>{{/prevpage}}&nbsp;
+ {{#nextpage}}<a href="/cal/{{&alias}}/{{.}}">{{/nextpage}}Next&rarr;{{#nextpage}}</a>{{/nextpage}}
+ {{/picker}}
+ </div>
+ <div class="viewopts" style="margin-left: 15px">
View:
{{^efAll}}<a href="?ef=all">{{/efAll}}All{{^efAll}}</a>{{/efAll}}&nbsp;
{{^efCompr}}<a href="?ef=compr">{{/efCompr}}Compressed{{^efCompr}}</a>{{/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