From 26f8f392a96893bc3c97f1c2212a9c71f0a610f7 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 12 Mar 2020 11:56:26 +0100 Subject: [PATCH] feat(allocations): improve display --- .gitignore | 1 + frontend/src/app.sass | 2 +- src/Handler/Allocation/Users.hs | 6 +- src/Handler/Utils/Table/Pagination.hs | 5 +- src/Model/Types/Allocation.hs | 29 +++- .../de-de-formal.hamlet | 13 +- test/Database/Fill.hs | 141 ++++++++++++++++-- 7 files changed, 175 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index f90d75d56..e0ed9bbe2 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ tunnel.log /well-known /.well-known-cache /**/tmp-* +/testdata/bigAlloc_*.csv diff --git a/frontend/src/app.sass b/frontend/src/app.sass index 3222acdcc..ab75944e7 100644 --- a/frontend/src/app.sass +++ b/frontend/src/app.sass @@ -1176,7 +1176,7 @@ a.breadcrumbs__home font-size: 14px font-family: monospace -.func-field__wrapper +.func-field__wrapper, .allocation-missing-prios max-height: 75vh overflow: auto diff --git a/src/Handler/Allocation/Users.hs b/src/Handler/Allocation/Users.hs index 914bd3f59..564e35d5a 100644 --- a/src/Handler/Allocation/Users.hs +++ b/src/Handler/Allocation/Users.hs @@ -156,7 +156,7 @@ postAUsersR tid ssh ash = do , guardOn resultsDone . coursesModalAssigned . bool id assignedHeated resultsDone $ colAllocationAssigned resultAssignedCourses , coursesModalNewAssigned . assignedHeated <$> do allocMatching' <- allocMatching - pure . sortable Nothing (i18nCell MsgAllocationUserNewMatches) . + pure . sortable (Just "new-assigned") (i18nCell MsgAllocationUserNewMatches) . views (resultUser . _entityKey) $ \uid -> cell . toWidget . toMarkup . maybe 0 olength $ allocMatching' !? uid , pure $ emptyOpticColonnade' emptyPriorityCell (resultAllocationUser . _entityVal . _allocationUserPriority . _Just) colAllocationPriority ] @@ -211,6 +211,8 @@ postAUsersR tid ssh ash = do , sortAllocationRequested $ queryAllocationUser . to (E.^. AllocationUserTotalCourses) , sortAllocationVetoed queryVetoedCourses , sortAllocationPriority $ queryAllocationUser . to (E.^. AllocationUserPriority) + , singletonMap "new-assigned" $ + SortProjected . comparing $ (\uid -> maybe 0 olength $ Map.lookup uid =<< allocMatching) . view (resultUser . _entityKey) ] dbtFilter = mconcat [ fltrUserName' $ queryUser . to (E.^. UserDisplayName) @@ -237,7 +239,7 @@ postAUsersR tid ssh ash = do dbtCsvDecode = Nothing allocationUsersDBTableValidator = def & defaultSorting [SortAscBy "priority", SortAscBy "user-matriculation"] - & defaultPagesize PagesizeAll + & defaultPagesize (PagesizeLimit 500) usersTable <- dbTableDB' allocationUsersDBTableValidator allocationUsersDBTable diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs index 816521ec0..f9fe0b669 100644 --- a/src/Handler/Utils/Table/Pagination.hs +++ b/src/Handler/Utils/Table/Pagination.hs @@ -1021,6 +1021,7 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db case previousKeys of Nothing | PagesizeLimit l <- psLimit' + , selectPagesize -> do E.limit l E.offset (psPage * l) @@ -1236,7 +1237,9 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db _other -> return () let - rowCount = olength64 rows + rowCount + | selectPagesize = fromMaybe 0 $ rows' ^? _head . _1 . _Value + | otherwise = olength64 rows rawAction = tblLink $ setParam (wIdent "sorting") Nothing diff --git a/src/Model/Types/Allocation.hs b/src/Model/Types/Allocation.hs index b918deab0..f03b5ce69 100644 --- a/src/Model/Types/Allocation.hs +++ b/src/Model/Types/Allocation.hs @@ -4,6 +4,8 @@ module Model.Types.Allocation , AllocationPriorityComparison(..) , AllocationFingerprint , module Utils.Allocation + , AllocationPriorityNumericRecord(..) + , allocationPriorityNumericMap ) where import Import.NoModel @@ -44,13 +46,36 @@ deriving via E.JSONB AllocationPriority instance E.PersistFieldSql AllocationPri instance Binary AllocationPriority -instance Csv.FromRecord (Map UserMatriculation AllocationPriority) where +data AllocationPriorityNumericRecord = AllocationPriorityNumericRecord + { apmrMatrikelnummer :: UserMatriculation + , apmrPriority :: Vector Integer + } deriving (Eq, Ord, Read, Show, Generic, Typeable) + +allocationPriorityNumericMap :: Prism' (Map UserMatriculation AllocationPriority) AllocationPriorityNumericRecord +allocationPriorityNumericMap = prism' fromPrioRecord toPrioRecord + where + fromPrioRecord AllocationPriorityNumericRecord{..} + = Map.singleton apmrMatrikelnummer $ AllocationPriorityNumeric apmrPriority + + toPrioRecord recordMap = do + [(matr, AllocationPriorityNumeric{..})] <- pure $ Map.toList recordMap + return $ AllocationPriorityNumericRecord matr allocationPriorities + +instance Csv.FromRecord AllocationPriorityNumericRecord where parseRecord v = parseNumeric where parseNumeric - | Vector.length v >= 1 = Map.singleton <$> v Csv..! 0 <*> (AllocationPriorityNumeric <$> mapM Csv.parseField (Vector.tail v)) + | Vector.length v >= 1 = AllocationPriorityNumericRecord <$> v Csv..! 0 <*> mapM Csv.parseField (Vector.tail v) | otherwise = mzero +instance Csv.ToRecord AllocationPriorityNumericRecord where + toRecord AllocationPriorityNumericRecord{..} = Csv.record $ + Csv.toField apmrMatrikelnummer + : map Csv.toField (otoList apmrPriority) + +instance Csv.FromRecord (Map UserMatriculation AllocationPriority) where + parseRecord = fmap (review allocationPriorityNumericMap) . Csv.parseRecord + instance Csv.ToField AllocationPriority where toField (AllocationPriorityOrdinal n ) = Csv.toField n diff --git a/templates/i18n/allocation-confirm-missing-prios/de-de-formal.hamlet b/templates/i18n/allocation-confirm-missing-prios/de-de-formal.hamlet index 16ed09324..467be35e7 100644 --- a/templates/i18n/allocation-confirm-missing-prios/de-de-formal.hamlet +++ b/templates/i18n/allocation-confirm-missing-prios/de-de-formal.hamlet @@ -2,12 +2,13 @@ $newline never

Die folgenden Benutzer nehmen nicht an der Zentralvergabe teil, da # ihnen keine zentrale Dringlichkeit zugeordnet wurde: -