From d47fa717a32bcfbc62ba647e36a2b5f06aa01de7 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 16 Mar 2018 12:58:49 +0100 Subject: [PATCH] Identify tables --- src/Handler/Term.hs | 1 + src/Handler/Utils/Table/Pagination.hs | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Handler/Term.hs b/src/Handler/Term.hs index f33fde929..60776bbef 100644 --- a/src/Handler/Term.hs +++ b/src/Handler/Term.hs @@ -73,6 +73,7 @@ getTermShowR = do , dbtColonnade = colonnadeTerms , dbtSorting = mempty , dbtAttrs = tableDefault + , dbtIdent = "terms" :: Text } defaultLayout $ do setTitle "Freigeschaltete Semester" diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs index c564111d3..cbe39921b 100644 --- a/src/Handler/Utils/Table/Pagination.hs +++ b/src/Handler/Utils/Table/Pagination.hs @@ -31,14 +31,16 @@ sqlSortDirection :: (SortColumn, SortDirection) -> E.SqlExpr E.OrderBy sqlSortDirection (SortColumn e, SortAsc ) = E.asc e sqlSortDirection (SortColumn e, SortDesc) = E.desc e -data DBTable = forall a r h. +data DBTable = forall a r h i. ( Headedness h , E.SqlSelect a r + , PathPiece i ) => DBTable { dbtSQLQuery :: E.SqlQuery a , dbtColonnade :: Colonnade h r (Cell UniWorX) , dbtSorting :: Map Text SortColumn , dbtAttrs :: Attribute + , dbtIdent :: i } data PaginationSettings = PaginationSettings @@ -82,12 +84,13 @@ dbTable PSValidator{..} DBTable{..} = do Nothing -> return $ Left "Error parsing values" Just res -> return $ Right $ Just res (_, defPS) = runPSValidator Nothing + wIdent n = toPathPiece dbtIdent <> "-" <> n psResult <- runInputGetResult $ PaginationSettings - <$> ireq sortingField "sorting" - <*> (fromMaybe (psLimit defPS) <$> iopt intField "pagesize") - <*> (fromMaybe (psPage defPS) <$> iopt intField "page") - <*> ireq checkBoxField "table-only" + <$> ireq sortingField (wIdent "sorting") + <*> (fromMaybe (psLimit defPS) <$> iopt intField (wIdent "pagesize")) + <*> (fromMaybe (psPage defPS) <$> iopt intField (wIdent "page")) + <*> ireq checkBoxField (wIdent "table-only") $(logDebug) . tshow $ (,,,) <$> (length . psSorting <$> psResult) <*> (psLimit <$> psResult)