Skip to content

Commit 1b983a8

Browse files
author
Andika Demas Riyandi
committed
initial work on matrix table
1 parent 5b30ff8 commit 1b983a8

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

src-ui.v3/src/Main.hs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--
2020
module Main (main) where
2121

22+
import Control.Monad (sequence_)
2223
import Data.Aeson (FromJSON)
2324
import qualified Data.Aeson as J
2425
import qualified Data.Aeson.Types as J
@@ -420,9 +421,9 @@ app dynFrag = do
420421

421422
el "hr" blank
422423

423-
evCellClick <- reportTableWidget dynRepSum dynQRows dynWorkers dynHist dynInfo
424+
(_, evCellClick) <- runEventWriterT $ reportTableWidget dynRepSum dynQRows dynWorkers dynHist dynInfo
424425

425-
dynCellClick <- holdDyn Nothing (Just <$> evCellClick)
426+
dynCellClick <- holdDyn Nothing (Just . _unCellTable <$> evCellClick)
426427

427428
let dynCell' = mergeCellId pn <$> dynCellClick <*> dynIdxSt
428429

@@ -530,7 +531,7 @@ packagesPageWidget dynPackages dynTags dynPkgTags = do
530531
V.filter (tagContained st dpt) pkg
531532

532533

533-
reportTableWidget :: forall t m . (SetRoute t FragRoute m, MonadHold t m, PostBuild t m, DomBuilder t m, Reflex t)
534+
reportTableWidget :: forall t w m . (EventWriter t CellTable m, HasCellTable CellTable, SetRoute t FragRoute m, MonadHold t m, PostBuild t m, DomBuilder t m, Reflex t)
534535
=> Dynamic t PkgIdxTsReport
535536
-> Dynamic t (Vector QEntryRow)
536537
-> Dynamic t (Vector WorkerRow)
@@ -548,7 +549,8 @@ reportTableWidget dynRepSum dynQRows dynWorkers dynHist dynInfo = joinE =<< go
548549
let activeHcs = [ k | (k,CompilerInfo { ciActive = True }) <- Map.toDescList ciCompilers ]
549550

550551

551-
let hcvsLR = computeLR pitrHcversions activeHcs
552+
let (Just defVer) = verFromText "0"
553+
hcvsLR = computeLR pitrHcversions activeHcs
552554
hcvs = applyLR hcvsLR pitrHcversions activeHcs
553555

554556
let vmap = Map.mergeWithKey (\_ (t,u) e -> Just (t,u,applyLR hcvsLR e emptyActive)) (fmap (\(t,u) -> (t,u,emptyHcvs))) (const mempty)
@@ -580,7 +582,8 @@ reportTableWidget dynRepSum dynQRows dynWorkers dynHist dynInfo = joinE =<< go
580582
el "th" (text "released")
581583
el "th" (text "uploader")
582584

583-
el "tbody" $ do
585+
el "tbody" $ do
586+
sequence_ . snd $ List.mapAccumL (accumTableRow pn' hcvs pitrIdxstate wip inQueue) (defVer, ((PkgIdxTs 0), "", [])) (Map.toAscList vmap)
584587
evsRows <- forM (Map.toDescList vmap) $ \(pv,(t,u,cs)) -> do
585588
let tooSoon = t > pitrIdxstate
586589
tooSoonAttr = if tooSoon then ("style" =: "opacity:0.5;") else mempty
@@ -607,6 +610,58 @@ reportTableWidget dynRepSum dynQRows dynWorkers dynHist dynInfo = joinE =<< go
607610
pure (leftmost evsRow1)
608611
pure (leftmost evsRows) -- main "return" value
609612

613+
accumTableRow :: forall t w m. (SetRoute t FragRoute m, DomBuilder t m, Reflex t, EventWriter t CellTable m, HasCellTable CellTable)
614+
=> Text
615+
-> [CompilerID]
616+
-> PkgIdxTs
617+
-> [(Ver,CompilerID)]
618+
-> Bool
619+
-> (Ver, (PkgIdxTs, UserName, [CellReportSummary]))
620+
-> (Ver, (PkgIdxTs, UserName, [CellReportSummary]))
621+
-> ((Ver, (PkgIdxTs, UserName, [CellReportSummary])), m ())
622+
accumTableRow pn' hcvs pkgIdxTs wip inQ prevVer currVer =
623+
let pkgVer = const currVer prevVer
624+
(pcVer, (t, u, cs)) = currVer
625+
(ppVer, _) = prevVer
626+
in (pkgVer, (renderRow pn' hcvs pkgIdxTs wip inQ ppVer pcVer t u cs))
627+
628+
renderRow :: forall t w m. (SetRoute t FragRoute m, DomBuilder t m, Reflex t, EventWriter t CellTable m, HasCellTable CellTable)
629+
=> Text
630+
-> [CompilerID]
631+
-> PkgIdxTs
632+
-> [(Ver,CompilerID)]
633+
-> Bool
634+
-> (Ver)
635+
-> (Ver)
636+
-> PkgIdxTs
637+
-> UserName
638+
-> [CellReportSummary]
639+
-> m ()
640+
renderRow pn' hcvs pitrIdxstate wip inQueue ppV pcV t u cs = do
641+
let tooSoon = t > pitrIdxstate
642+
tooSoonAttr = if tooSoon then ("style" =: "opacity:0.5;") else mempty
643+
elAttr "tr" tooSoonAttr $ do
644+
elAttr "th" ("style" =: "text-align:left;") $
645+
elAttr "a" ("href" =: (mconcat [ "https://hackage.haskell.org/package/", pn',"-",verToText pcV,"/",pn',".cabal/edit" ])) $
646+
text (verToText pcV)
647+
evsRow1 <- forM (zip cs hcvs) $ \(x,hcv) -> do
648+
let (cellAttr,cellText) = case crsT x of
649+
Nothing
650+
| tooSoon -> ("class" =: "stat-unknown", el "b" (text ""))
651+
| (pcV,hcv) `elem` wip -> ("class" =: "stat-wip", el "b" (text "WIP"))
652+
| inQueue -> ("class" =: "stat-queued", text "queued")
653+
_ -> ("class" =: (snd $ fmtCRS x), (text $ fst $ fmtCRS x))
654+
655+
(l,_) <- elAttr' "td" (("style" =: if tooSoon then "cursor: not-allowed;" else "cursor: cell;") <> cellAttr) cellText
656+
657+
pure $ ((CellTable (pcV,hcv)) <$ (if tooSoon then never else domEvent Click l) :: Event t CellTable)
658+
659+
elAttr "th" ("style" =: "text-align:left;") (text (verToText pcV))
660+
el "td" $ text (pkgIdxTsToText t)
661+
el "td" $ routeLink False ("#/user/" <> u) (text u)
662+
tellEvent (leftmost evsRow1)
663+
pure () -- (leftmost evsRow1)
664+
610665
reportDetailWidget :: (SupportsServantReflex t m, MonadFix m, PostBuild t m, DomBuilder t m, Reflex t, MonadHold t m, Adjustable t m) => Dynamic t (Maybe (PkgN,Ver,CompilerID,PkgIdxTs)) -> m ()
611666
reportDetailWidget dynCellId = do
612667

src-ui.v3/src/PkgId.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
22
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE TemplateHaskell #-}
34

45
-- |
56
-- Copyright: © 2018 Herbert Valerio Riedel
@@ -24,7 +25,7 @@ module PkgId
2425

2526
-- , UnitID(..), unUnitID
2627
-- , unitIDFromUnitId
27-
28+
, CellTable(..), HasCellTable
2829
, CompilerID, compilerVer
2930
, compilerIdFromText
3031
, compilerIdToText
@@ -36,6 +37,7 @@ module PkgId
3637
) where
3738

3839
import Control.Monad (fail)
40+
import Control.Lens
3941
import Data.Aeson (FromJSON (..), FromJSONKey (..),
4042
ToJSON (..), ToJSONKey (..))
4143
import qualified Data.Aeson as J
@@ -172,7 +174,10 @@ matchesEmpty :: Matches
172174
matchesEmpty = Matches { matchesInput = T.empty, matchesExact = Map.empty, matchesInfix = Map.empty}
173175

174176
---------------------------------
177+
data CellTable = CellTable { _unCellTable :: (Ver, CompilerID) }
178+
deriving (Eq, Ord)
175179

180+
makeClassy ''CellTable
176181

177182

178183

0 commit comments

Comments
 (0)