feat(admin-crontab): export as json
This commit is contained in:
parent
a27a553e0a
commit
bbd4916f3a
@ -1,3 +1,5 @@
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
|
||||
module Handler.Admin.Crontab
|
||||
( getAdminCrontabR
|
||||
) where
|
||||
@ -10,9 +12,15 @@ import qualified Data.Aeson.Encode.Pretty as Pretty
|
||||
import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder')
|
||||
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.Lazy.Builder as Text.Builder
|
||||
|
||||
|
||||
getAdminCrontabR :: Handler Html
|
||||
deriveJSON defaultOptions
|
||||
{ constructorTagModifier = camelToPathPiece' 1
|
||||
} ''CronNextMatch
|
||||
|
||||
|
||||
getAdminCrontabR :: Handler TypedContent
|
||||
getAdminCrontabR = do
|
||||
jState <- getsYesod appJobState
|
||||
mCrontab' <- atomically . runMaybeT $ do
|
||||
@ -21,36 +29,42 @@ getAdminCrontabR = do
|
||||
|
||||
let mCrontab = mCrontab' <&> _2 %~ filter (hasn't $ _3 . _MatchNone)
|
||||
|
||||
siteLayoutMsg MsgMenuAdminCrontab $ do
|
||||
setTitleI MsgMenuAdminCrontab
|
||||
[whamlet|
|
||||
$newline never
|
||||
$maybe (genTime, crontab) <- mCrontab
|
||||
<p>
|
||||
^{formatTimeW SelFormatDateTime genTime}
|
||||
<table .table .table--striped .table--hover>
|
||||
$forall (job, lExec, match) <- crontab
|
||||
<tr .table__row>
|
||||
<td .table__td>
|
||||
$case match
|
||||
$of MatchAsap
|
||||
_{MsgCronMatchAsap}
|
||||
$of MatchNone
|
||||
_{MsgCronMatchNone}
|
||||
$of MatchAt t
|
||||
^{formatTimeW SelFormatDateTime t}
|
||||
<td .table__td>
|
||||
$maybe lT <- lExec
|
||||
^{formatTimeW SelFormatDateTime lT}
|
||||
<td .table__td>
|
||||
<pre>
|
||||
#{doEnc job}
|
||||
$nothing
|
||||
_{MsgAdminCrontabNotGenerated}
|
||||
|]
|
||||
where doEnc = encodePrettyToTextBuilder' Pretty.defConfig
|
||||
{ Pretty.confIndent = Pretty.Spaces 2
|
||||
, Pretty.confCompare = comparing $ \t -> ( t `elem` ["instruction", "job", "notification"]
|
||||
, Text.splitOn "-" t
|
||||
)
|
||||
}
|
||||
selectRep $ do
|
||||
provideRep $
|
||||
siteLayoutMsg MsgMenuAdminCrontab $ do
|
||||
setTitleI MsgMenuAdminCrontab
|
||||
[whamlet|
|
||||
$newline never
|
||||
$maybe (genTime, crontab) <- mCrontab
|
||||
<p>
|
||||
^{formatTimeW SelFormatDateTime genTime}
|
||||
<table .table .table--striped .table--hover>
|
||||
$forall (job, lExec, match) <- crontab
|
||||
<tr .table__row>
|
||||
<td .table__td>
|
||||
$case match
|
||||
$of MatchAsap
|
||||
_{MsgCronMatchAsap}
|
||||
$of MatchNone
|
||||
_{MsgCronMatchNone}
|
||||
$of MatchAt t
|
||||
^{formatTimeW SelFormatDateTime t}
|
||||
<td .table__td>
|
||||
$maybe lT <- lExec
|
||||
^{formatTimeW SelFormatDateTime lT}
|
||||
<td .table__td>
|
||||
<pre>
|
||||
#{doEnc job}
|
||||
$nothing
|
||||
_{MsgAdminCrontabNotGenerated}
|
||||
|]
|
||||
provideJson mCrontab'
|
||||
provideRep . return . Text.Builder.toLazyText $ doEnc mCrontab'
|
||||
where
|
||||
doEnc :: _ => a -> _
|
||||
doEnc = encodePrettyToTextBuilder' Pretty.defConfig
|
||||
{ Pretty.confIndent = Pretty.Spaces 2
|
||||
, Pretty.confCompare = comparing $ \t -> ( t `elem` ["instruction", "job", "notification"]
|
||||
, Text.splitOn "-" t
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user