diff --git a/src/Handler/Admin/Crontab.hs b/src/Handler/Admin/Crontab.hs index e1e5313f8..09035b3ca 100644 --- a/src/Handler/Admin/Crontab.hs +++ b/src/Handler/Admin/Crontab.hs @@ -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 -

- ^{formatTimeW SelFormatDateTime genTime} - - $forall (job, lExec, match) <- crontab - -
- $case match - $of MatchAsap - _{MsgCronMatchAsap} - $of MatchNone - _{MsgCronMatchNone} - $of MatchAt t - ^{formatTimeW SelFormatDateTime t} - - $maybe lT <- lExec - ^{formatTimeW SelFormatDateTime lT} - -
-                  #{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
+            

+ ^{formatTimeW SelFormatDateTime genTime} + + $forall (job, lExec, match) <- crontab + +
+ $case match + $of MatchAsap + _{MsgCronMatchAsap} + $of MatchNone + _{MsgCronMatchNone} + $of MatchAt t + ^{formatTimeW SelFormatDateTime t} + + $maybe lT <- lExec + ^{formatTimeW SelFormatDateTime lT} + +
+                      #{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
+                                               )
+      }