Use dbTable in /users
This commit is contained in:
parent
96eea52344
commit
ed4df0ef4d
@ -190,4 +190,8 @@ CourseMembersCount num@Int64: #{display num}
|
|||||||
CourseMembersCountLimited num@Int64 max@Int64: #{display num}/#{display max}
|
CourseMembersCountLimited num@Int64 max@Int64: #{display num}/#{display max}
|
||||||
|
|
||||||
NoTableContent: Kein Tabelleninhalt
|
NoTableContent: Kein Tabelleninhalt
|
||||||
NoUpcomingSheetDeadlines: Keine anstehenden Übungsblätter
|
NoUpcomingSheetDeadlines: Keine anstehenden Übungsblätter
|
||||||
|
|
||||||
|
AdminFor: Administrator
|
||||||
|
LecturerFor: Dozent
|
||||||
|
UserListTitle: Komprehensive Benutzerliste
|
||||||
@ -4,6 +4,7 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
|
||||||
module Handler.Users where
|
module Handler.Users where
|
||||||
|
|
||||||
@ -11,39 +12,64 @@ import Import
|
|||||||
-- import Data.Text
|
-- import Data.Text
|
||||||
import Handler.Utils
|
import Handler.Utils
|
||||||
|
|
||||||
import Colonnade hiding (fromMaybe)
|
import qualified Data.Map as Map
|
||||||
import Yesod.Colonnade
|
|
||||||
|
|
||||||
-- import qualified Database.Esqueleto as E
|
import Colonnade hiding (fromMaybe)
|
||||||
-- import Database.Esqueleto ((^.))
|
|
||||||
|
import qualified Database.Esqueleto as E
|
||||||
|
|
||||||
|
|
||||||
getUsersR :: Handler Html
|
getUsersR :: Handler Html
|
||||||
getUsersR = do
|
getUsersR = do
|
||||||
-- TODO: Esqueleto, combine the two queries into one
|
let
|
||||||
(users,schools) <- runDB $ (,)
|
colonnadeUsers = dbColonnade . mconcat $
|
||||||
<$> (selectList [] [Asc UserDisplayName]
|
[ dbRow
|
||||||
>>= mapM (\usr -> (,,)
|
, sortable (Just "display-name") (i18nCell MsgName) $ \DBRow{ dbrOutput = Entity uid User{..} } -> anchorCellM
|
||||||
<$> pure usr
|
(AdminUserR <$> encrypt uid)
|
||||||
<*> selectList [UserAdminUser ==. entityKey usr] [Asc UserAdminSchool]
|
(toWidget . display $ userDisplayName)
|
||||||
<*> selectList [UserLecturerUser ==. entityKey usr] [Asc UserLecturerSchool]
|
, sortable Nothing (i18nCell MsgAdminFor) $ \DBRow{ dbrOutput = Entity uid _ } -> mempty
|
||||||
))
|
{ dbCellContents = do
|
||||||
<*> selectList [] [Asc SchoolShorthand]
|
schools <- E.select . E.from $ \(school `E.InnerJoin` userAdmin) -> do
|
||||||
let schoolnames = entities2map schools
|
E.on $ school E.^. SchoolId E.==. userAdmin E.^. UserAdminSchool
|
||||||
let getSchoolname = \sid ->
|
E.where_ $ userAdmin E.^. UserAdminUser E.==. E.val uid
|
||||||
case lookup sid schoolnames of
|
E.orderBy [E.asc $ school E.^. SchoolShorthand]
|
||||||
Nothing -> "???"
|
return $ school E.^. SchoolShorthand
|
||||||
(Just school) -> schoolShorthand school
|
return [whamlet|
|
||||||
let colonnadeUsers = mconcat $
|
<ul>
|
||||||
[ headed "User" $ \u -> do
|
$forall (E.Value sh) <- schools
|
||||||
cID <- encrypt $ entityKey $ fst3 u
|
<li>#{sh}
|
||||||
let name = display $ userDisplayName $ entityVal $ fst3 u
|
|]
|
||||||
[whamlet|<a href=@{AdminUserR cID}>#{name}|]
|
}
|
||||||
, headed "Admin" $ (\u -> text2widget $ intercalate ", " $ map (getSchoolname.userAdminSchool .entityVal) $ snd3 u)
|
, sortable Nothing (i18nCell MsgLecturerFor) $ \DBRow{ dbrOutput = Entity uid _ } -> mempty
|
||||||
, headed "Lecturer" $ (\u -> text2widget $ intercalate ", " $ map (getSchoolname.userLecturerSchool.entityVal) $ trd3 u)
|
{ dbCellContents = do
|
||||||
|
schools <- E.select . E.from $ \(school `E.InnerJoin` userLecturer) -> do
|
||||||
|
E.on $ school E.^. SchoolId E.==. userLecturer E.^. UserLecturerSchool
|
||||||
|
E.where_ $ userLecturer E.^. UserLecturerUser E.==. E.val uid
|
||||||
|
E.orderBy [E.asc $ school E.^. SchoolShorthand]
|
||||||
|
return $ school E.^. SchoolShorthand
|
||||||
|
return [whamlet|
|
||||||
|
<ul>
|
||||||
|
$forall (E.Value sh) <- schools
|
||||||
|
<li>#{sh}
|
||||||
|
|]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
psValidator = def
|
||||||
|
& defaultSorting [("display-name", SortAsc)]
|
||||||
|
|
||||||
|
userList <- dbTable psValidator $ DBTable
|
||||||
|
{ dbtSQLQuery = return :: E.SqlExpr (Entity User) -> E.SqlQuery (E.SqlExpr (Entity User))
|
||||||
|
, dbtColonnade = colonnadeUsers
|
||||||
|
, dbtSorting = Map.fromList
|
||||||
|
[ ( "display-name"
|
||||||
|
, SortColumn $ \user -> user E.^. UserDisplayName
|
||||||
|
)
|
||||||
]
|
]
|
||||||
-- ++ map (\school -> headed (text2widget $ schoolName $ entityVal school) (\u -> "xx")) schools
|
, dbtFilter = mempty
|
||||||
|
, dbtStyle = def
|
||||||
|
, dbtIdent = "users" :: Text
|
||||||
|
}
|
||||||
|
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitle "Comprehensive User List"
|
setTitleI MsgUserListTitle
|
||||||
let userList = encodeWidgetTable tableSortable colonnadeUsers users
|
|
||||||
$(widgetFile "users")
|
$(widgetFile "users")
|
||||||
|
|||||||
@ -22,7 +22,7 @@ module Handler.Utils.Table.Pagination
|
|||||||
, FilterColumn(..), IsFilterColumn
|
, FilterColumn(..), IsFilterColumn
|
||||||
, DBRow(..), DBOutput
|
, DBRow(..), DBOutput
|
||||||
, DBStyle(..), DBEmptyStyle(..)
|
, DBStyle(..), DBEmptyStyle(..)
|
||||||
, DBTable(..), IsDBTable(..)
|
, DBTable(..), IsDBTable(..), DBCell(..)
|
||||||
, PaginationSettings(..), PaginationInput(..), piIsUnset
|
, PaginationSettings(..), PaginationInput(..), piIsUnset
|
||||||
, PSValidator(..)
|
, PSValidator(..)
|
||||||
, defaultFilter, defaultSorting
|
, defaultFilter, defaultSorting
|
||||||
@ -33,6 +33,7 @@ module Handler.Utils.Table.Pagination
|
|||||||
, textCell, stringCell, i18nCell, anchorCell, anchorCell', anchorCellM
|
, textCell, stringCell, i18nCell, anchorCell, anchorCell', anchorCellM
|
||||||
, formCell, DBFormResult, getDBFormResult
|
, formCell, DBFormResult, getDBFormResult
|
||||||
, dbRow, dbSelect
|
, dbRow, dbSelect
|
||||||
|
, (&)
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Handler.Utils.Table.Pagination.Types
|
import Handler.Utils.Table.Pagination.Types
|
||||||
@ -146,7 +147,7 @@ instance Default DBStyle where
|
|||||||
def = DBStyle
|
def = DBStyle
|
||||||
{ dbsEmptyStyle = def
|
{ dbsEmptyStyle = def
|
||||||
, dbsEmptyMessage = MsgNoTableContent
|
, dbsEmptyMessage = MsgNoTableContent
|
||||||
, dbsAttrs = [ ("class", "table table-striped table-hover table-sortable") ]
|
, dbsAttrs = [ ("class", "table table--striped table--hover table--sortable") ]
|
||||||
}
|
}
|
||||||
|
|
||||||
data DBTable m x = forall a r r' h i t.
|
data DBTable m x = forall a r r' h i t.
|
||||||
|
|||||||
@ -1,8 +1,2 @@
|
|||||||
<div .ui.container>
|
<div .ui.container>
|
||||||
|
^{userList}
|
||||||
<p .bg-danger>
|
|
||||||
This page is only for development purposes.
|
|
||||||
|
|
||||||
<h1>
|
|
||||||
User list
|
|
||||||
^{userList}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user