{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} module Main where import Control.Monad.Logger (runStderrLoggingT) import Control.Monad.Trans.Resource (runResourceT) import Data.ByteString.Lazy as BS import Data.List as List import Data.Text as T import Data.Text.Lazy qualified as T (toStrict) import Data.Text.Lazy.Builder qualified as B import Data.Text.Lazy.Builder.Int qualified as B import Data.Time.Clock (nominalDiffTimeToSeconds) import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds) import Database.Persist.Postgresql (ConnectionPool, ConnectionString, SqlBackend, runMigration, runSqlPool, withPostgresqlPool) import Debug.Trace (traceShow) import Point qualified (fetch, migration, save) import Session qualified import Track (parseBS) import Yesod.Core import Yesod.Form.Fields import Yesod.Form.Functions import Yesod.Form.Input import Yesod.Form.Types import Yesod.Persist import Yesod.Static staticFiles "frontend" -- this param appears to be a pathname data Souplesse = Souplesse ConnectionPool Static -- ref https://www.yesodweb.com/book/routing-and-handlers -- for adding params (start/end) to the timeline route mkYesod "Souplesse" [parseRoutes| / CalendarR GET /timeline TimelineR GET /upload UploadR POST /static StaticR Static getStatic /points PointsR GET |] getStatic :: Souplesse -> Static getStatic y = let Souplesse _ s = y in s instance Yesod Souplesse instance YesodPersist Souplesse where type YesodPersistBackend Souplesse = SqlBackend runDB action = do Souplesse pool _ <- getYesod runSqlPool action pool intToText :: (Integral a) => a -> T.Text intToText = T.toStrict . B.toLazyText . B.decimal getCalendarR :: Handler Html getCalendarR = do let fTime = intToText . floor . utcTimeToPOSIXSeconds fDur = intToText . ceiling . nominalDiffTimeToSeconds (formWidget, _) <- generateFormPost uploadForm sessions' <- runDB Session.recents defaultLayout [whamlet|
A calendar view goes here