Skip to content

Commit 7c29915

Browse files
author
Andika Demas Riyandi
committed
adding link to luite's hdiff and extract the dyn function out
1 parent 1b983a8 commit 7c29915

File tree

2 files changed

+63
-82
lines changed

2 files changed

+63
-82
lines changed

src-ui.v3/src/Main.hs

Lines changed: 57 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,14 @@ app dynFrag = do
421421

422422
el "hr" blank
423423

424-
(_, evCellClick) <- runEventWriterT $ reportTableWidget dynRepSum dynQRows dynWorkers dynHist dynInfo
425-
426-
dynCellClick <- holdDyn Nothing (Just . _unCellTable <$> evCellClick)
424+
evCC <- dyn $ reportTableWidget <$> dynRepSum
425+
<*> dynQRows
426+
<*> dynWorkers
427+
<*> dynHist
428+
<*> dynInfo
429+
evCellClick <- switchHold never evCC
430+
431+
dynCellClick <- holdDyn Nothing (Just . _unCellTable <$> evCellClick) -- . _unCellTable
427432

428433
let dynCell' = mergeCellId pn <$> dynCellClick <*> dynIdxSt
429434

@@ -531,101 +536,75 @@ packagesPageWidget dynPackages dynTags dynPkgTags = do
531536
V.filter (tagContained st dpt) pkg
532537

533538

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)
535-
=> Dynamic t PkgIdxTsReport
536-
-> Dynamic t (Vector QEntryRow)
537-
-> Dynamic t (Vector WorkerRow)
538-
-> Dynamic t (Vector PkgHistoryEntry)
539-
-> Dynamic t ControllerInfo
540-
-> m (Event t (Ver,CompilerID))
541-
reportTableWidget dynRepSum dynQRows dynWorkers dynHist dynInfo = joinE =<< go
542-
where
543-
go = dyn $ do
544-
PkgIdxTsReport{..} <- dynRepSum
545-
qrowsAll <- dynQRows
546-
wrowsAll <- dynWorkers
547-
hrowsAll <- dynHist
548-
ControllerInfo{..} <- dynInfo
549-
let activeHcs = [ k | (k,CompilerInfo { ciActive = True }) <- Map.toDescList ciCompilers ]
539+
reportTableWidget :: forall t m. ( SetRoute t FragRoute m, MonadHold t m, PostBuild t m, DomBuilder t m, Reflex t)
540+
=> PkgIdxTsReport
541+
-> (Vector QEntryRow)
542+
-> (Vector WorkerRow)
543+
-> (Vector PkgHistoryEntry)
544+
-> ControllerInfo
545+
-> m (Event t CellTable)
546+
reportTableWidget dynRepSum dynQRows dynWorkers dynHist dynInfo = do
547+
let PkgIdxTsReport{..} = dynRepSum
548+
qrowsAll = dynQRows
549+
wrowsAll = dynWorkers
550+
hrowsAll = dynHist
551+
ControllerInfo{..} = dynInfo
552+
553+
let activeHcs = [ k | (k,CompilerInfo { ciActive = True }) <- Map.toDescList ciCompilers ]
550554

551555

552-
let (Just defVer) = verFromText "0"
553-
hcvsLR = computeLR pitrHcversions activeHcs
554-
hcvs = applyLR hcvsLR pitrHcversions activeHcs
556+
let (Just defVer) = verFromText "0"
557+
hcvsLR = computeLR pitrHcversions activeHcs
558+
hcvs = applyLR hcvsLR pitrHcversions activeHcs
555559

556-
let vmap = Map.mergeWithKey (\_ (t,u) e -> Just (t,u,applyLR hcvsLR e emptyActive)) (fmap (\(t,u) -> (t,u,emptyHcvs))) (const mempty)
557-
vmap0 pitrPkgversions
560+
let emptyHcvs = hcvs $> emptyCellReportSummary
561+
emptyActive = activeHcs $> emptyCellReportSummary
558562

559-
emptyHcvs = hcvs $> emptyCellReportSummary
560-
emptyActive = activeHcs $> emptyCellReportSummary
563+
vmap = Map.mergeWithKey (\_ (t,u) e -> Just (t,u,applyLR hcvsLR e emptyActive)) (fmap (\(t,u) -> (t,u,emptyHcvs))) (const mempty)
564+
vmap0 pitrPkgversions
561565

562-
vmap0 = Map.fromList [ (v,(t,u)) | PkgHistoryEntry t v 0 u <- V.toList hrowsAll ]
566+
vmap0 = Map.fromList [ (v,(t,u)) | PkgHistoryEntry t v 0 u <- V.toList hrowsAll ]
563567

564-
let inQueue = not (null [ () | QEntryRow{..} <- V.toList qrowsAll, qrIdxstate == pitrIdxstate ])
568+
let inQueue = not (null [ () | QEntryRow{..} <- V.toList qrowsAll, qrIdxstate == pitrIdxstate ])
565569

566-
let wip = [ (pv,hcv) | WorkerRow{..} <- V.toList wrowsAll
570+
let wip = [ (pv,hcv) | WorkerRow{..} <- V.toList wrowsAll
567571
, wrIdxState == Just pitrIdxstate
568572
, Just pv <- [wrPkgversion]
569573
, Just hcv <- [wrHcversion]
570574
]
571575

572-
let pn' = pkgNToText pitrPkgname
576+
let pn' = pkgNToText pitrPkgname
573577

574578
-- TODO: push Dynamics into cells; the table dimensions are semi-static
575-
pure $ do
576-
el "table" $ do
577-
el "thead" $ do
578-
el "tr" $ do
579-
el "th" blank
580-
forM_ hcvs $ \cid -> el "th" (text (compilerIdToText cid))
581-
el "th" blank
582-
el "th" (text "released")
583-
el "th" (text "uploader")
584-
585-
el "tbody" $ do
586-
sequence_ . snd $ List.mapAccumL (accumTableRow pn' hcvs pitrIdxstate wip inQueue) (defVer, ((PkgIdxTs 0), "", [])) (Map.toAscList vmap)
587-
evsRows <- forM (Map.toDescList vmap) $ \(pv,(t,u,cs)) -> do
588-
let tooSoon = t > pitrIdxstate
589-
tooSoonAttr = if tooSoon then ("style" =: "opacity:0.5;") else mempty
590-
elAttr "tr" tooSoonAttr $ do
591-
elAttr "th" ("style" =: "text-align:left;") $
592-
elAttr "a" ("href" =: (mconcat [ "https://hackage.haskell.org/package/", pn',"-",verToText pv,"/",pn',".cabal/edit" ])) $
593-
text (verToText pv)
594-
evsRow1 <- forM (zip cs hcvs) $ \(x,hcv) -> do
595-
let (cellAttr,cellText) = case crsT x of
596-
Nothing
597-
| tooSoon -> ("class" =: "stat-unknown", el "b" (text ""))
598-
| (pv,hcv) `elem` wip -> ("class" =: "stat-wip", el "b" (text "WIP"))
599-
| inQueue -> ("class" =: "stat-queued", text "queued")
600-
_ -> ("class" =: (snd $ fmtCRS x), (text $ fst $ fmtCRS x))
601-
602-
(l,_) <- elAttr' "td" (("style" =: if tooSoon then "cursor: not-allowed;" else "cursor: cell;") <> cellAttr) cellText
603-
604-
pure $ ((pv,hcv) <$ (if tooSoon then never else domEvent Click l) :: Event t (Ver,CompilerID))
605-
606-
elAttr "th" ("style" =: "text-align:left;") (text (verToText pv))
607-
el "td" $ text (pkgIdxTsToText t)
608-
el "td" $ routeLink False ("#/user/" <> u) (text u)
609-
610-
pure (leftmost evsRow1)
611-
pure (leftmost evsRows) -- main "return" value
612-
613-
accumTableRow :: forall t w m. (SetRoute t FragRoute m, DomBuilder t m, Reflex t, EventWriter t CellTable m, HasCellTable CellTable)
579+
el "table" $ do
580+
el "thead" $ do
581+
el "tr" $ do
582+
el "th" blank
583+
forM_ hcvs $ \cid -> el "th" (text (compilerIdToText cid))
584+
el "th" blank
585+
el "th" (text "released")
586+
el "th" (text "uploader")
587+
588+
el "tbody" $ do
589+
evrows <- sequence . List.reverse . snd $ List.mapAccumL (accumTableRow pn' hcvs pitrIdxstate wip inQueue) (defVer, ((PkgIdxTs 0), "", [])) (Map.toAscList vmap)
590+
pure (leftmost evrows)
591+
592+
accumTableRow :: forall t m. (SetRoute t FragRoute m, DomBuilder t m, Reflex t)
614593
=> Text
615594
-> [CompilerID]
616595
-> PkgIdxTs
617596
-> [(Ver,CompilerID)]
618597
-> Bool
619598
-> (Ver, (PkgIdxTs, UserName, [CellReportSummary]))
620599
-> (Ver, (PkgIdxTs, UserName, [CellReportSummary]))
621-
-> ((Ver, (PkgIdxTs, UserName, [CellReportSummary])), m ())
600+
-> ((Ver, (PkgIdxTs, UserName, [CellReportSummary])), m (Event t CellTable))
622601
accumTableRow pn' hcvs pkgIdxTs wip inQ prevVer currVer =
623602
let pkgVer = const currVer prevVer
624-
(pcVer, (t, u, cs)) = currVer
603+
(pcVer, (t, u, cs)) = pkgVer
625604
(ppVer, _) = prevVer
626605
in (pkgVer, (renderRow pn' hcvs pkgIdxTs wip inQ ppVer pcVer t u cs))
627606

628-
renderRow :: forall t w m. (SetRoute t FragRoute m, DomBuilder t m, Reflex t, EventWriter t CellTable m, HasCellTable CellTable)
607+
renderRow :: forall t m. (SetRoute t FragRoute m, DomBuilder t m, Reflex t)
629608
=> Text
630609
-> [CompilerID]
631610
-> PkgIdxTs
@@ -636,12 +615,15 @@ renderRow :: forall t w m. (SetRoute t FragRoute m, DomBuilder t m, Reflex t, Ev
636615
-> PkgIdxTs
637616
-> UserName
638617
-> [CellReportSummary]
639-
-> m ()
618+
-> m (Event t CellTable)
640619
renderRow pn' hcvs pitrIdxstate wip inQueue ppV pcV t u cs = do
641620
let tooSoon = t > pitrIdxstate
642621
tooSoonAttr = if tooSoon then ("style" =: "opacity:0.5;") else mempty
643622
elAttr "tr" tooSoonAttr $ do
644-
elAttr "th" ("style" =: "text-align:left;") $
623+
elAttr "th" ("style" =: "text-align:left;") $ do
624+
let id2Ver = if verToText ppV == "0" then "" else "&id2=" <> verToText ppV
625+
elAttr "a" ("href" =: (mconcat [ "http://hdiff.luite.com/cgit/", pn', "/diff?id=",verToText pcV, id2Ver ])) $
626+
text "Δ"
645627
elAttr "a" ("href" =: (mconcat [ "https://hackage.haskell.org/package/", pn',"-",verToText pcV,"/",pn',".cabal/edit" ])) $
646628
text (verToText pcV)
647629
evsRow1 <- forM (zip cs hcvs) $ \(x,hcv) -> do
@@ -659,8 +641,7 @@ renderRow pn' hcvs pitrIdxstate wip inQueue ppV pcV t u cs = do
659641
elAttr "th" ("style" =: "text-align:left;") (text (verToText pcV))
660642
el "td" $ text (pkgIdxTsToText t)
661643
el "td" $ routeLink False ("#/user/" <> u) (text u)
662-
tellEvent (leftmost evsRow1)
663-
pure () -- (leftmost evsRow1)
644+
pure (leftmost evsRow1)
664645

665646
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 ()
666647
reportDetailWidget dynCellId = do
@@ -785,9 +766,6 @@ pkgTagList m = Map.fromListWith (List.++) $ do
785766
v <- (V.toList vs)
786767
pure $ (v, [k])
787768

788-
joinE :: forall t m a. (Reflex t, MonadHold t m) => Event t (Event t a) -> m (Event t a)
789-
joinE = fmap switch . hold never
790-
791769
clickElement_ :: forall t m. (DomBuilder t m, PostBuild t m) => Text -> Text -> m (Event t ())
792770
clickElement_ elm t = do
793771
let cfg = (def :: ElementConfig EventResult t (DomBuilderSpace m))

src-ui.v3/src/PkgId.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module PkgId
2525

2626
-- , UnitID(..), unUnitID
2727
-- , unitIDFromUnitId
28-
, CellTable(..), HasCellTable
28+
, CellTable(..) --, HasCellTable
2929
, CompilerID, compilerVer
3030
, compilerIdFromText
3131
, compilerIdToText
@@ -37,7 +37,6 @@ module PkgId
3737
) where
3838

3939
import Control.Monad (fail)
40-
import Control.Lens
4140
import Data.Aeson (FromJSON (..), FromJSONKey (..),
4241
ToJSON (..), ToJSONKey (..))
4342
import qualified Data.Aeson as J
@@ -177,7 +176,11 @@ matchesEmpty = Matches { matchesInput = T.empty, matchesExact = Map.empty, match
177176
data CellTable = CellTable { _unCellTable :: (Ver, CompilerID) }
178177
deriving (Eq, Ord)
179178

180-
makeClassy ''CellTable
179+
instance Semigroup CellTable where
180+
_ <> (CellTable a2) = CellTable a2
181+
182+
183+
--makeClassy ''CellTable
181184

182185

183186

0 commit comments

Comments
 (0)