diff --git a/messages/uniworx/utils/table_column/de-de-formal.msg b/messages/uniworx/utils/table_column/de-de-formal.msg index 18757a352..e95b4757e 100644 --- a/messages/uniworx/utils/table_column/de-de-formal.msg +++ b/messages/uniworx/utils/table_column/de-de-formal.msg @@ -79,4 +79,5 @@ TableCompanies: Firmen TableCompanyNos: Firmennummern TableSupervisor: Ansprechpartner TableCreationTime: Erstellungszeit -TableJobContent !ident-ok: Job +TableJob !ident-ok: Job +TableJobContent !ident-ok: Parameter diff --git a/messages/uniworx/utils/table_column/en-eu.msg b/messages/uniworx/utils/table_column/en-eu.msg index 1bfa7cdb7..682c66966 100644 --- a/messages/uniworx/utils/table_column/en-eu.msg +++ b/messages/uniworx/utils/table_column/en-eu.msg @@ -79,4 +79,5 @@ TableCompanies: Companies TableCompanyNos: Company numbers TableSupervisor: Supervisor TableCreationTime: Creation -TableJobContent: Job \ No newline at end of file +TableJob !ident-ok: Job +TableJobContent !ident-ok: Parameters \ No newline at end of file diff --git a/src/Handler/Admin/Crontab.hs b/src/Handler/Admin/Crontab.hs index e0232c3fe..18b14fbe6 100644 --- a/src/Handler/Admin/Crontab.hs +++ b/src/Handler/Admin/Crontab.hs @@ -14,8 +14,10 @@ import Import import Jobs import Handler.Utils -import qualified Data.Aeson.Encode.Pretty as Pretty -import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder') +-- import Data.Aeson (fromJSON) +-- import qualified Data.Aeson as Aeson +-- import qualified Data.Aeson.Types as Aeson +import qualified Data.Aeson.Encode.Pretty as Pretty -- import qualified Data.CaseInsensitive as CI import qualified Data.Text as Text @@ -28,7 +30,7 @@ import qualified Data.HashMap.Strict as HashMap import qualified Data.UUID as UUID import qualified Database.Esqueleto.Legacy as E --- import qualified Database.Esqueleto.Utils as E +import qualified Database.Esqueleto.Utils as E -- import Database.Esqueleto.Utils.TH @@ -97,8 +99,8 @@ getAdminCrontabR = do provideJson mCrontab' provideRep . return . Text.Builder.toLazyText $ doEnc mCrontab' where - doEnc :: _ => a -> _ - doEnc = encodePrettyToTextBuilder' Pretty.defConfig + doEnc :: ToJSON a => a -> _ + doEnc = Pretty.encodePrettyToTextBuilder' Pretty.defConfig { Pretty.confIndent = Pretty.Spaces 2 , Pretty.confCompare = comparing $ \t -> ( t `elem` ["instruction", "job", "notification"] , Text.splitOn "-" t @@ -119,16 +121,24 @@ postAdminJobsR = do dbtRowKey = (E.^. QueuedJobId) dbtProj = dbtProjId dbtColonnade = dbColonnade $ mconcat -- remove call to dbColonnade if table actions are added - [ sortable (Just "creation-time") (i18nCell MsgTableCreationTime) $ \(view $ resultJob . _entityVal -> QueuedJob{..}) -> dateTimeCell queuedJobCreationTime - , sortable (Just "content") (i18nCell MsgTableCreationTime) $ \(view $ resultJob . _entityVal -> QueuedJob{..}) -> stringCell $ show queuedJobContent + [ sortable (Just "job") (i18nCell MsgTableJob) $ \(view $ resultJob . _entityVal -> QueuedJob{..}) -> cellMaybe textCell $ getJobName queuedJobContent + , sortable (Just "creation-time") (i18nCell MsgTableCreationTime) $ \(view $ resultJob . _entityVal -> QueuedJob{..}) -> dateTimeCell queuedJobCreationTime + , sortable (Just "content") (i18nCell MsgTableJobContent) $ \(view $ resultJob . _entityVal -> QueuedJob{..}) -> cell [whamlet|#{doEnc queuedJobContent}|] & addCellClass ("json"::Text) ] dbtSorting = Map.fromList [ ("creation-time", SortColumnNullsInv (E.^. QueuedJobCreationTime)) + , ("job" , SortColumn (\v -> v E.^. QueuedJobContent E.->>. "job")) , ("content" , SortColumn (E.^. QueuedJobContent)) ] - dbtFilter = Map.empty - dbtFilterUI = const mempty - dbtStyle = def + dbtFilter = Map.fromList + [ + ("job", FilterColumn $ E.mkContainsFilter (\v -> v E.^. QueuedJobContent E.->>. "job")) + ] + dbtFilterUI = \mPrev -> mconcat + [ + prismAForm (singletonFilter "job" . maybePrism _PathPiece) mPrev $ aopt (hoistField lift textField) (fslI MsgTableJob) + ] + dbtStyle = def { dbsFilterLayout = defaultDBSFilterLayout } dbtParams = def dbtIdent :: Text dbtIdent = "queued-jobs" @@ -143,4 +153,17 @@ postAdminJobsR = do setTitleI MsgMenuAdminJobs [whamlet| ^{jobsTable} - |] \ No newline at end of file + |] + where + doEnc :: ToJSON a => a -> _ + doEnc = Pretty.encodePrettyToTextBuilder' Pretty.defConfig + { Pretty.confIndent = Pretty.Spaces 2 + , Pretty.confCompare = comparing $ \t -> ( t `elem` ["job", "notification"] + , Text.splitOn "-" t + ) + } + + getJobName :: Value -> Maybe Text + getJobName (Object o) + | Just (String s) <- HashMap.lookup "job" o = Just s -- $ kebabToCamel s + getJobName _ = Nothing \ No newline at end of file diff --git a/src/Utils/PathPiece.hs b/src/Utils/PathPiece.hs index 05f7f558a..45b5643e5 100644 --- a/src/Utils/PathPiece.hs +++ b/src/Utils/PathPiece.hs @@ -9,6 +9,7 @@ module Utils.PathPiece , splitCamel, dropCamel , camelToPathPiece, camelToPathPiece', camelToPathPiece'' , nameToPathPiece, nameToPathPiece' + , kebabToCamel , tuplePathPiece , pathPieceJSON, pathPieceJSONKey , pathPieceBinary @@ -237,6 +238,11 @@ nameToPathPiece' dropN = camelToPathPiece' dropN . repack . nameBase nameToPathPiece :: Textual t => Name -> t nameToPathPiece = nameToPathPiece' 0 +-- | convert kebab-case to CamelCase +kebabToCamel :: Text -> Text +-- kebabToCamel = Text.filter (not . Char.isSpace) . Text.toTitle . Text.replace "-" " " -- eliminates all space +kebabToCamel = mconcat . fmap Text.toTitle . Text.split ('-'==) -- preserves existing spaces + tuplePathPiece :: Int -> DecQ tuplePathPiece tupleDim = do