mirror of https://github.com/voidlizard/hbs2
back button for commits, ugly
This commit is contained in:
parent
86764baf6c
commit
f8249b4000
|
@ -30,12 +30,13 @@ import HBS2.Peer.CLI.Detect
|
||||||
import Lucid (renderTextT)
|
import Lucid (renderTextT)
|
||||||
import Options.Applicative as O
|
import Options.Applicative as O
|
||||||
import Data.Either
|
import Data.Either
|
||||||
|
import Data.Text qualified as Text
|
||||||
import Data.ByteString.Lazy qualified as LBS
|
import Data.ByteString.Lazy qualified as LBS
|
||||||
import Network.HTTP.Types.Status
|
import Network.HTTP.Types.Status
|
||||||
import Network.Wai.Middleware.Static hiding ((<|>))
|
import Network.Wai.Middleware.Static hiding ((<|>))
|
||||||
import Network.Wai.Middleware.StaticEmbedded as E
|
import Network.Wai.Middleware.StaticEmbedded as E
|
||||||
import Network.Wai.Middleware.RequestLogger
|
import Network.Wai.Middleware.RequestLogger
|
||||||
import Web.Scotty.Trans
|
import Web.Scotty.Trans as Scotty
|
||||||
import Control.Monad.Except
|
import Control.Monad.Except
|
||||||
import System.Random
|
import System.Random
|
||||||
import Data.HashMap.Strict (HashMap)
|
import Data.HashMap.Strict (HashMap)
|
||||||
|
@ -230,14 +231,18 @@ runDashboardWeb wo = do
|
||||||
hash' <- captureParam @String "hash" <&> fromStringMay @GitHash
|
hash' <- captureParam @String "hash" <&> fromStringMay @GitHash
|
||||||
co' <- captureParam @String "co" <&> fromStringMay @GitHash
|
co' <- captureParam @String "co" <&> fromStringMay @GitHash
|
||||||
|
|
||||||
|
|
||||||
flip runContT pure do
|
flip runContT pure do
|
||||||
lww <- lwws' & orFall (status status404)
|
lww <- lwws' & orFall (status status404)
|
||||||
hash <- hash' & orFall (status status404)
|
hash <- hash' & orFall (status status404)
|
||||||
co <- co' & orFall (status status404)
|
co <- co' & orFall (status status404)
|
||||||
tree <- lift $ gitShowTree lww hash
|
tree <- lift $ gitShowTree lww hash
|
||||||
back <- lift $ selectParentTree (TreeCommit co) (TreeTree hash)
|
back <- lift $ selectParentTree (TreeCommit co) (TreeTree hash)
|
||||||
|
|
||||||
|
let ctx = ViewContext [qc|/repo/{show $ pretty $ lww}/tree/{show $ pretty co}/{show $ pretty hash}|] mempty
|
||||||
|
|
||||||
debug $ "selectParentTree" <+> pretty co <+> pretty hash <+> pretty back
|
debug $ "selectParentTree" <+> pretty co <+> pretty hash <+> pretty back
|
||||||
lift $ html =<< renderTextT (repoTree lww co hash tree (coerce <$> back))
|
lift $ html =<< renderTextT (repoTree ctx lww co hash tree (coerce <$> back))
|
||||||
|
|
||||||
get "/repo/:lww/blob/:co/:hash/:blob" do
|
get "/repo/:lww/blob/:co/:hash/:blob" do
|
||||||
lwws' <- captureParam @String "lww" <&> fromStringMay @(LWWRefKey HBS2Basic)
|
lwws' <- captureParam @String "lww" <&> fromStringMay @(LWWRefKey HBS2Basic)
|
||||||
|
@ -279,7 +284,12 @@ runDashboardWeb wo = do
|
||||||
& set commitPredLimit lim
|
& set commitPredLimit lim
|
||||||
|
|
||||||
flip runContT pure do
|
flip runContT pure do
|
||||||
|
|
||||||
lww <- lwws' & orFall (status status404)
|
lww <- lwws' & orFall (status status404)
|
||||||
|
|
||||||
|
referrer <- lift (Scotty.header "Referer")
|
||||||
|
>>= orFall (redirect $ fromString $ Text.unpack $ path ["repo", show $ pretty lww])
|
||||||
|
|
||||||
lift $ html =<< renderTextT (repoCommits lww (Left pred))
|
lift $ html =<< renderTextT (repoCommits lww (Left pred))
|
||||||
|
|
||||||
where
|
where
|
||||||
|
@ -287,6 +297,9 @@ runDashboardWeb wo = do
|
||||||
lwws' <- captureParam @String "lww" <&> fromStringMay @(LWWRefKey HBS2Basic)
|
lwws' <- captureParam @String "lww" <&> fromStringMay @(LWWRefKey HBS2Basic)
|
||||||
co <- captureParam @String "hash" <&> fromStringMay @GitHash
|
co <- captureParam @String "hash" <&> fromStringMay @GitHash
|
||||||
|
|
||||||
|
referrer <- Scotty.header "Referer"
|
||||||
|
debug $ yellow "COMMIT-REFERRER" <+> pretty referrer
|
||||||
|
|
||||||
flip runContT pure do
|
flip runContT pure do
|
||||||
lww <- lwws' & orFall (status status404)
|
lww <- lwws' & orFall (status status404)
|
||||||
hash <- co & orFall (status status404)
|
hash <- co & orFall (status status404)
|
||||||
|
|
|
@ -34,6 +34,15 @@ import Data.List (sortOn)
|
||||||
|
|
||||||
import Streaming.Prelude qualified as S
|
import Streaming.Prelude qualified as S
|
||||||
|
|
||||||
|
data ViewContext =
|
||||||
|
ViewContext
|
||||||
|
{ _baseUri :: String
|
||||||
|
, _tab :: Text
|
||||||
|
}
|
||||||
|
deriving stock Generic
|
||||||
|
|
||||||
|
instance Serialise ViewContext
|
||||||
|
|
||||||
rootPath :: [String] -> [String]
|
rootPath :: [String] -> [String]
|
||||||
rootPath = ("/":)
|
rootPath = ("/":)
|
||||||
|
|
||||||
|
@ -284,14 +293,15 @@ treeLocator lww co locator next = do
|
||||||
next
|
next
|
||||||
|
|
||||||
repoTree :: (DashBoardPerks m, MonadReader DashBoardEnv m)
|
repoTree :: (DashBoardPerks m, MonadReader DashBoardEnv m)
|
||||||
=> LWWRefKey 'HBS2Basic
|
=> ViewContext
|
||||||
|
-> LWWRefKey 'HBS2Basic
|
||||||
-> GitHash -- ^ this
|
-> GitHash -- ^ this
|
||||||
-> GitHash -- ^ this
|
-> GitHash -- ^ this
|
||||||
-> [(GitObjectType, GitHash, Text)]
|
-> [(GitObjectType, GitHash, Text)]
|
||||||
-> Maybe GitHash -- ^ back
|
-> Maybe GitHash -- ^ back
|
||||||
-> HtmlT m ()
|
-> HtmlT m ()
|
||||||
|
|
||||||
repoTree lww co root tree back' = do
|
repoTree ctx lww co root tree back' = do
|
||||||
|
|
||||||
let repo = show $ pretty $ lww
|
let repo = show $ pretty $ lww
|
||||||
|
|
||||||
|
@ -306,8 +316,9 @@ repoTree lww co root tree back' = do
|
||||||
tpOrder Blob = 1
|
tpOrder Blob = 1
|
||||||
tpOrder _ = 2
|
tpOrder _ = 2
|
||||||
|
|
||||||
locator <- lift $ selectTreeLocator (TreeCommit co) (TreeTree root)
|
let wtf = show $ pretty $ AsBase58 (serialise ctx)
|
||||||
|
|
||||||
|
locator <- lift $ selectTreeLocator (TreeCommit co) (TreeTree root)
|
||||||
|
|
||||||
table_ [] do
|
table_ [] do
|
||||||
|
|
||||||
|
@ -353,6 +364,8 @@ repoTree lww co root tree back' = do
|
||||||
|
|
||||||
img_ ([alt_ (fromMaybe "blob" syn)] <> icon)
|
img_ ([alt_ (fromMaybe "blob" syn)] <> icon)
|
||||||
|
|
||||||
|
-- debug $ red "PUSH URL" <+> pretty (path ["back", wtf])
|
||||||
|
|
||||||
td_ [class_ itemClass] (toHtml $ show $ pretty name)
|
td_ [class_ itemClass] (toHtml $ show $ pretty name)
|
||||||
td_ [class_ "mono"] do
|
td_ [class_ "mono"] do
|
||||||
case tp of
|
case tp of
|
||||||
|
@ -361,14 +374,12 @@ repoTree lww co root tree back' = do
|
||||||
a_ [ href_ "#"
|
a_ [ href_ "#"
|
||||||
, hxGet_ blobUri
|
, hxGet_ blobUri
|
||||||
, hxTarget_ "#repo-tab-data"
|
, hxTarget_ "#repo-tab-data"
|
||||||
, hxPushUrl_ (path ["repo", repo, "refs" ])
|
|
||||||
] (toHtml hash_)
|
] (toHtml hash_)
|
||||||
|
|
||||||
Tree -> do
|
Tree -> do
|
||||||
a_ [ href_ "#"
|
a_ [ href_ "#"
|
||||||
, hxGet_ uri
|
, hxGet_ uri
|
||||||
, hxTarget_ "#repo-tab-data"
|
, hxTarget_ "#repo-tab-data"
|
||||||
, hxPushUrl_ (path ["repo", repo, "refs" ])
|
|
||||||
] (toHtml hash_)
|
] (toHtml hash_)
|
||||||
|
|
||||||
_ -> mempty
|
_ -> mempty
|
||||||
|
@ -525,8 +536,11 @@ repoBlob :: (DashBoardPerks m, MonadReader DashBoardEnv m)
|
||||||
|
|
||||||
repoBlob lww co tree BlobInfo{..} = do
|
repoBlob lww co tree BlobInfo{..} = do
|
||||||
locator <- lift $ selectTreeLocator co tree
|
locator <- lift $ selectTreeLocator co tree
|
||||||
|
|
||||||
|
let repo = show $ pretty lww
|
||||||
let co_ = show $ pretty co
|
let co_ = show $ pretty co
|
||||||
let tree_ = show $ pretty tree
|
let tree_ = show $ pretty tree
|
||||||
|
|
||||||
table_ [] do
|
table_ [] do
|
||||||
tr_ do
|
tr_ do
|
||||||
td_ [class_ "tree-locator", colspan_ "3"] do
|
td_ [class_ "tree-locator", colspan_ "3"] do
|
||||||
|
|
Loading…
Reference in New Issue