forked from dtekcth/DtekPortalen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StandardLayout.hs
53 lines (50 loc) · 1.98 KB
/
StandardLayout.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
module StandardLayout (standardLayout)
where
import Prelude
import Foundation
import Data.Time
import Data.Time.Calendar.OrdinalDate (mondayStartWeek)
import Scrapers.CalendarFeed (EventInfo(..))
import Data.IORef
import Text.Markdown (Markdown(..))
import Text.Blaze (ToMarkup (toMarkup))
import Yesod
import Data.Shorten (shorten)
import Settings
standardLayout :: Widget -> Handler RepHtml
standardLayout contentWidget = do
mu <- maybeAuth
(rmenu :: Widget) <- mkrmenu
(lmenu :: Widget) <- mklmenu
(header :: Widget) <- mkHeader mu
defaultLayout $(widgetFile "standard")
where
(footer :: Widget) = $(widgetFile "footer")
mkHeader mu = return $(widgetFile "header")
mklmenu = do
sndmd <- documentFromDB "stat_sndfrontpage"
dagmd@(Markdown dagtext) <- documentFromDB "stat_dagads"
let dagmdEmtpy = dagtext == ""
return $(widgetFile "lmenu" )
mkrmenu = do
(cache -> (CachedValues einsteinRef calendarRef)) <- getYesod
einsteinScrapResult <- liftIO $ readIORef einsteinRef
eventInfos <- liftIO $ readIORef calendarRef
esMenu <- case einsteinScrapResult of
Nothing -> return ["Ingen meny tillgänglig"]
Just (esWeek, sss) -> do
day <- liftIO $ fmap utctDay getCurrentTime
let (week, weekday) = mondayStartWeek day
return $ head $
[["Stängt under helgdag"] | weekday `notElem` [1..5]]
++ [["Einstein har ej uppdaterat veckan"] | esWeek /= week]
++ [sss !! (weekday - 1)]
return $(widgetFile "rmenu" )
niceShowEvent :: EventInfo -> String
niceShowEvent event =
let format = formatTime swedishTimeLocale
in (title event) ++ ": " ++ format "%A %R" (startTime event) ++ "-"
++ format "%R" (endTime event)