diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 508560ddb..d1d47e48e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,7 +34,7 @@ npm install: - install -v -T -m 0644 ${APT_SOURCES_LIST} /etc/apt/sources.list - apt-get update -y - npm install -g n - - n 13.5.0 + - n 14.8.0 - export PATH="${N_PREFIX}/bin:$PATH" - npm install -g npm - hash -r @@ -149,7 +149,7 @@ frontend:test: - install -v -T -m 0644 ${APT_SOURCES_LIST} /etc/apt/sources.list - apt-get update -y - npm install -g n - - n 13.5.0 + - n 14.8.0 - export PATH="${N_PREFIX}/bin:$PATH" - npm install -g npm - hash -r diff --git a/CHANGELOG.md b/CHANGELOG.md index 452d377d4..595777f14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [19.2.1](https://gitlab2.rz.ifi.lmu.de/uni2work/uni2work/compare/v19.2.0...v19.2.1) (2020-08-26) + + +### Bug Fixes + +* improve hidecolumns behaviour ([9a4f30b](https://gitlab2.rz.ifi.lmu.de/uni2work/uni2work/commit/9a4f30b811fdf8c58ec5c50c185628eb3158931a)) + ## [19.2.0](https://gitlab2.rz.ifi.lmu.de/uni2work/uni2work/compare/v19.1.5...v19.2.0) (2020-08-24) diff --git a/frontend/src/lib/table/table.js b/frontend/src/lib/table/table.js index a87ef02c8..33c03cc80 100644 --- a/frontend/src/lib/table/table.js +++ b/frontend/src/lib/table/table.js @@ -5,17 +5,26 @@ import * as defer from 'lodash.defer'; class Overhang { colSpan; rowSpan; + cell; - constructor(colSpan, rowSpan) { + constructor(colSpan, rowSpan, cell) { this.colSpan = colSpan; this.rowSpan = rowSpan; + this.cell = cell; if (new.target === Overhang) Object.freeze(this); } nextLine() { - return new Overhang(this.colSpan, Math.max(0, this.rowSpan - 1)); + return new Overhang(this.colSpan, Math.max(0, this.rowSpan - 1), this.cell); + } + + reduceCol(n) { + if (this.colSpan > n) + return new Overhang(this.colSpan - n, this.rowSpan, this.cell); + else + return null; } isHole() { @@ -57,11 +66,10 @@ export class TableIndices { this._table = table; - let overhangs = new Array(); + let currentOverhangs = new Array(); let currentRow = 0; for (const rowParent of this._table.rows) { - let currentOverhangs = Array.from(overhangs); let newOverhangs = new Array(); let cellBefore = 0; @@ -76,18 +84,38 @@ export class TableIndices { break; else newOverhangs.push(overhang.nextLine()); + + if (DEBUG_MODE > 1) + console.log('From overhang', overhang); cellBefore += overhang.colSpan; } currentOverhangs = currentOverhangs.slice(i); + let remCols = this.colSpan(cell); + while (remCols > 0 && currentOverhangs[0]) { + let firstOverhang = currentOverhangs[0].reduceCol(this.colSpan(cell)); + if (firstOverhang) { + if (DEBUG_MODE > 1) + console.log('Replace first overhang', remCols, currentOverhangs[0], firstOverhang); + currentOverhangs[0] = firstOverhang; + break; + } else { + if (DEBUG_MODE > 1) + console.log('Drop first overhang', remCols, currentOverhangs[0], firstOverhang); + remCols -= currentOverhangs[0].colSpan; + currentOverhangs.shift(); + } + } this._cellToIndices.set(cell, { row: currentRow, col: cellBefore }); let rows = range(currentRow, currentRow + this.rowSpan(cell)); let columns = range(cellBefore, cellBefore + this.colSpan(cell)); - if (DEBUG_MODE > 0) { + if (DEBUG_MODE > 1) { + console.log('Result', rows, columns); + cell.dataset.rows = JSON.stringify(rows); cell.dataset.columns = JSON.stringify(columns); } @@ -104,11 +132,14 @@ export class TableIndices { } } - newOverhangs.push(new Overhang(this.colSpan(cell), this.rowSpan(cell) - 1)); + newOverhangs.push(new Overhang(this.colSpan(cell), this.rowSpan(cell) - 1, cell)); + + if (DEBUG_MODE > 1) + console.log('From current cell', this.colSpan(cell)); cellBefore += this.colSpan(cell); } - overhangs = newOverhangs; + currentOverhangs = Array.from(newOverhangs); currentRow++; } diff --git a/package-lock.json b/package-lock.json index 756462fda..cc7596947 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "uni2work", - "version": "19.2.0", + "version": "19.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2b75424df..6567585ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uni2work", - "version": "19.2.0", + "version": "19.2.1", "description": "", "keywords": [], "author": "", diff --git a/package.yaml b/package.yaml index 513b569a9..f7811ab83 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: uniworx -version: 19.2.0 +version: 19.2.1 dependencies: - base diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs index ce1767303..c0ad787ca 100644 --- a/src/Handler/Utils/Table/Pagination.hs +++ b/src/Handler/Utils/Table/Pagination.hs @@ -74,7 +74,6 @@ import Control.Monad.State (evalStateT, execStateT) import Control.Monad.Trans.Maybe import Control.Monad.State.Class (modify) import qualified Control.Monad.State.Class as State -import Control.Monad.Trans.Writer.Lazy (censor) import Data.Map ((!)) import qualified Data.Map as Map @@ -1277,22 +1276,22 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db _other -> False genHeaders :: forall h. Cornice h _ _ (DBCell m x) -> SortableP h -> WriterT x m Widget - genHeaders cornice SortableP{..} = execWriterT . go mempty $ annotate cornice + genHeaders cornice SortableP{..} = fmap wrap' . execWriterT . go mempty $ annotate cornice where go :: forall (p' :: Pillar) r'. [(Int, Int, Int)] -> AnnotatedCornice (Maybe Int) h p' r' (DBCell m x) - -> WriterT Widget (WriterT x m) () - go rowspanAcc (AnnotatedCorniceBase _ (Colonnade (toList -> v))) = censor wrap . forM_ (zip (inits v) v) $ \(before, OneColonnade Sized{..} _) -> do + -> WriterT (Seq (Seq (Widget, Int))) (WriterT x m) () + go rowspanAcc (AnnotatedCorniceBase _ (Colonnade (toList -> v))) = mapWriterT (over (mapped . _2) pure) . forM_ (zip (inits v) v) $ \(before, OneColonnade Sized{..} _) -> do let (_, cellSize') = compCellSize rowspanAcc (map oneColonnadeHead before) Sized{..} - whenIsJust cellSize' $ \cellSize -> tellM $ fromContent Sized { sizedSize = cellSize, sizedContent } + whenIsJust cellSize' $ \cellSize -> tellM . fmap pure $ fromContent Sized { sizedSize = cellSize, sizedContent } go rowspanAcc (AnnotatedCorniceCap _ v@(toList -> oneCornices)) = do - rowspanAcc' <- (execStateT ?? rowspanAcc) . hoist (censor wrap) . forM_ (zip (inits oneCornices) oneCornices) $ \(before, OneCornice h (size -> sz')) -> do + rowspanAcc' <- (execStateT ?? rowspanAcc) . hoist (mapWriterT $ over (mapped . _2) pure) . forM_ (zip (inits oneCornices) oneCornices) $ \(before, OneCornice h (size -> sz')) -> do let sz = Sized sz' h let (beforeSize, cellSize') = compCellSize rowspanAcc (concatMap (map oneColonnadeHead . toList . getColonnade . uncapAnnotated . oneCorniceBody) before) sz whenIsJust cellSize' $ \cellSize -> do let Sized{..} = sz - lift . tellM $ fromContent Sized { sizedSize = cellSize, sizedContent } + lift . tellM . fmap pure $ fromContent Sized { sizedSize = cellSize, sizedContent } if | [n] <- mapMaybe (\(key, val) -> guardOnM (is _Rowspan key) $ readMay val) (toSortable sizedContent ^. _sortableContent . cellAttrs) -> State.modify $ (:) (n, beforeSize, cellSize) | otherwise -> return () @@ -1309,11 +1308,14 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db guard $ beforeSize < firstCol + sz return . Sum $ sz - (beforeSize - firstCol) - wrap :: Widget -> Widget - wrap row = case dbsTemplate of + wrap' :: Seq (Seq (Widget, Int)) -> Widget + wrap' wRows = view _2 $ Foldable.foldl (\(stackHeight', acc) row -> (Nothing, (acc <>) . wrap stackHeight' $ foldOf (folded . _1) row)) (stackHeight, mempty) wRows + where stackHeight = maximumOf (folded . to (ala Sum foldMap . fmap (view _2))) wRows + wrap :: Maybe Int -> Widget -> Widget + wrap stackHeight row = case dbsTemplate of DBSTCourse{} -> row DBSTDefault{} -> $(widgetFile "table/header") - fromContent :: Sized Int h (DBCell m x) -> WriterT x m Widget + fromContent :: Sized Int h (DBCell m x) -> WriterT x m (Widget, Int) fromContent Sized{ sizedSize = cellSize, sizedContent = toSortable -> Sortable{..} } = do widget <- sortableContent ^. cellContents let @@ -1322,9 +1324,13 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db isSorted dir = fromMaybe False $ (==) <$> (SortingSetting <$> sortableKey <*> pure dir) <*> listToMaybe psSorting attrs = sortableContent ^. cellAttrs piSorting' = [ sSet | sSet <- fromMaybe [] piSorting, Just (sortKey sSet) /= sortableKey ] - case dbsTemplate of - DBSTCourse{} -> return $(widgetFile "table/course/header") - DBSTDefault{} -> return $(widgetFile "table/cell/header") + rowspan = preview _head $ do + (key, val) <- attrs + guard $ is _Rowspan key + hoistMaybe $ readMay val + return . (, fromMaybe 1 rowspan) $ case dbsTemplate of + DBSTCourse{} -> $(widgetFile "table/course/header") + DBSTDefault{} -> $(widgetFile "table/cell/header") in do wHeaders <- maybe (return Nothing) (fmap Just . genHeaders (dbtColonnade ^. _Cornice)) pSortable now <- liftIO getCurrentTime diff --git a/templates/table/header.hamlet b/templates/table/header.hamlet index 200126344..c2882f1b3 100644 --- a/templates/table/header.hamlet +++ b/templates/table/header.hamlet @@ -1,6 +1,7 @@ $newline never - $if numberColumn - + $maybe rowspan <- stackHeight + $if numberColumn + $# cell/header.hamlet ^{row}