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
|
module Handler.Admin.Crontab
|
||||||
( getAdminCrontabR
|
( getAdminCrontabR
|
||||||
) where
|
) where
|
||||||
@ -10,9 +12,15 @@ import qualified Data.Aeson.Encode.Pretty as Pretty
|
|||||||
import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder')
|
import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder')
|
||||||
|
|
||||||
import qualified Data.Text as Text
|
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
|
getAdminCrontabR = do
|
||||||
jState <- getsYesod appJobState
|
jState <- getsYesod appJobState
|
||||||
mCrontab' <- atomically . runMaybeT $ do
|
mCrontab' <- atomically . runMaybeT $ do
|
||||||
@ -21,36 +29,42 @@ getAdminCrontabR = do
|
|||||||
|
|
||||||
let mCrontab = mCrontab' <&> _2 %~ filter (hasn't $ _3 . _MatchNone)
|
let mCrontab = mCrontab' <&> _2 %~ filter (hasn't $ _3 . _MatchNone)
|
||||||
|
|
||||||
siteLayoutMsg MsgMenuAdminCrontab $ do
|
selectRep $ do
|
||||||
setTitleI MsgMenuAdminCrontab
|
provideRep $
|
||||||
[whamlet|
|
siteLayoutMsg MsgMenuAdminCrontab $ do
|
||||||
$newline never
|
setTitleI MsgMenuAdminCrontab
|
||||||
$maybe (genTime, crontab) <- mCrontab
|
[whamlet|
|
||||||
<p>
|
$newline never
|
||||||
^{formatTimeW SelFormatDateTime genTime}
|
$maybe (genTime, crontab) <- mCrontab
|
||||||
<table .table .table--striped .table--hover>
|
<p>
|
||||||
$forall (job, lExec, match) <- crontab
|
^{formatTimeW SelFormatDateTime genTime}
|
||||||
<tr .table__row>
|
<table .table .table--striped .table--hover>
|
||||||
<td .table__td>
|
$forall (job, lExec, match) <- crontab
|
||||||
$case match
|
<tr .table__row>
|
||||||
$of MatchAsap
|
<td .table__td>
|
||||||
_{MsgCronMatchAsap}
|
$case match
|
||||||
$of MatchNone
|
$of MatchAsap
|
||||||
_{MsgCronMatchNone}
|
_{MsgCronMatchAsap}
|
||||||
$of MatchAt t
|
$of MatchNone
|
||||||
^{formatTimeW SelFormatDateTime t}
|
_{MsgCronMatchNone}
|
||||||
<td .table__td>
|
$of MatchAt t
|
||||||
$maybe lT <- lExec
|
^{formatTimeW SelFormatDateTime t}
|
||||||
^{formatTimeW SelFormatDateTime lT}
|
<td .table__td>
|
||||||
<td .table__td>
|
$maybe lT <- lExec
|
||||||
<pre>
|
^{formatTimeW SelFormatDateTime lT}
|
||||||
#{doEnc job}
|
<td .table__td>
|
||||||
$nothing
|
<pre>
|
||||||
_{MsgAdminCrontabNotGenerated}
|
#{doEnc job}
|
||||||
|]
|
$nothing
|
||||||
where doEnc = encodePrettyToTextBuilder' Pretty.defConfig
|
_{MsgAdminCrontabNotGenerated}
|
||||||
{ Pretty.confIndent = Pretty.Spaces 2
|
|]
|
||||||
, Pretty.confCompare = comparing $ \t -> ( t `elem` ["instruction", "job", "notification"]
|
provideJson mCrontab'
|
||||||
, Text.splitOn "-" t
|
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