chore(job): add filtering to job queue view

This commit is contained in:
Steffen Jost 2023-07-13 16:09:12 +00:00
parent 240c6f81f8
commit a407094253
4 changed files with 44 additions and 13 deletions

View File

@ -79,4 +79,5 @@ TableCompanies: Firmen
TableCompanyNos: Firmennummern
TableSupervisor: Ansprechpartner
TableCreationTime: Erstellungszeit
TableJobContent !ident-ok: Job
TableJob !ident-ok: Job
TableJobContent !ident-ok: Parameter

View File

@ -79,4 +79,5 @@ TableCompanies: Companies
TableCompanyNos: Company numbers
TableSupervisor: Supervisor
TableCreationTime: Creation
TableJobContent: Job
TableJob !ident-ok: Job
TableJobContent !ident-ok: Parameters

View File

@ -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}
|]
|]
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

View File

@ -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