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,6 +29,8 @@ getAdminCrontabR = do
|
||||
|
||||
let mCrontab = mCrontab' <&> _2 %~ filter (hasn't $ _3 . _MatchNone)
|
||||
|
||||
selectRep $ do
|
||||
provideRep $
|
||||
siteLayoutMsg MsgMenuAdminCrontab $ do
|
||||
setTitleI MsgMenuAdminCrontab
|
||||
[whamlet|
|
||||
@ -48,7 +58,11 @@ getAdminCrontabR = do
|
||||
$nothing
|
||||
_{MsgAdminCrontabNotGenerated}
|
||||
|]
|
||||
where doEnc = encodePrettyToTextBuilder' Pretty.defConfig
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user