Skip to content
Snippets Groups Projects
Commit cdb6329b authored by stuebinm's avatar stuebinm
Browse files

server: simple servant-lucid stuff

parent a55e0ce9
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
-- | Module that contains high-level checking for an entire directory -- | Module that contains high-level checking for an entire directory
module CheckDir (recursiveCheckDir, DirResult(..), resultIsFatal) where module CheckDir (maximumLintLevel, recursiveCheckDir, DirResult(..), MissingAsset(..), MissingDep(..), resultIsFatal) where
import CheckMap (MapResult (..), loadAndLintMap) import CheckMap (MapResult (..), loadAndLintMap)
import Control.Monad (void) import Control.Monad (void)
...@@ -38,7 +38,6 @@ import Types (Dep (Local, LocalMap), Hint (Hint), ...@@ -38,7 +38,6 @@ import Types (Dep (Local, LocalMap), Hint (Hint),
Level (..), hintLevel) Level (..), hintLevel)
import Util (PrettyPrint (prettyprint), ellipsis) import Util (PrettyPrint (prettyprint), ellipsis)
-- based on the startling observation that Data.Map has lower complexity -- based on the startling observation that Data.Map has lower complexity
-- for difference than Data.Set, but the same complexity for fromList -- for difference than Data.Set, but the same complexity for fromList
type Set a = Map a () type Set a = Map a ()
......
...@@ -34,6 +34,7 @@ library: ...@@ -34,6 +34,7 @@ library:
- HList - HList
exposed-modules: exposed-modules:
- CheckDir - CheckDir
- CheckMap
- WriteRepo - WriteRepo
- Util - Util
- Types - Types
...@@ -74,3 +75,5 @@ executables: ...@@ -74,3 +75,5 @@ executables:
- microlens - microlens
- microlens-th - microlens-th
- tomland - tomland
- lucid
- servant-lucid
...@@ -22,14 +22,15 @@ import Network.Wai.Handler.Warp (run) ...@@ -22,14 +22,15 @@ import Network.Wai.Handler.Warp (run)
import Servant (Application, Capture, Get, Handler, import Servant (Application, Capture, Get, Handler,
HasServer (ServerT), JSON, HasServer (ServerT), JSON,
NoContent, Post, Proxy (Proxy), NoContent, Post, Proxy (Proxy),
ReqBody, ServerError (errBody), Raw, ReqBody,
err500, hoistServer, serve, ServerError (errBody), err500,
throwError, type (:<|>) (..), hoistServer, serve, throwError,
type (:>)) type (:<|>) (..), type (:>))
import Servant.HTML.Lucid (HTML)
import Servant.Server.StaticFiles (serveDirectoryWebApp)
import Server (Config (..), JobStatus, import Server (Config (..), JobStatus,
RemoteRef (..), State, RemoteRef (..), State,
defaultState, loadConfig) defaultState, loadConfig)
{- {-
Needed: Needed:
- admin overview (perhaps on seperate port?) - admin overview (perhaps on seperate port?)
...@@ -48,6 +49,10 @@ type API format = ...@@ -48,6 +49,10 @@ type API format =
:<|> "status" :> Capture "jobid" UUID :> Get '[format] JobStatus :<|> "status" :> Capture "jobid" UUID :> Get '[format] JobStatus
:<|> "relint" :> Capture "jobid" UUID :> Get '[format] NoContent :<|> "relint" :> Capture "jobid" UUID :> Get '[format] NoContent
type Routes =
"api" :> API JSON
:<|> "status" :> Capture "jobid" UUID :> Get '[HTML] JobStatus
:<|> Raw
-- | API's implementation -- | API's implementation
jsonAPI :: Config True -> MVar State -> ServerT (API JSON) App jsonAPI :: Config True -> MVar State -> ServerT (API JSON) App
...@@ -56,11 +61,17 @@ jsonAPI config state = ...@@ -56,11 +61,17 @@ jsonAPI config state =
:<|> statusImpl state :<|> statusImpl state
:<|> relintImpl config state :<|> relintImpl config state
server :: Config True -> MVar State -> ServerT Routes App
server config state =
jsonAPI config state
:<|> statusImpl state
:<|> serveDirectoryWebApp "./static"
-- | make an application; convert any cli errors into a 500 -- | make an application; convert any cli errors into a 500
app :: Config True -> MVar State -> Application app :: Config True -> MVar State -> Application
app config = app config =
serve api . hoistServer api conv . jsonAPI config serve api . hoistServer api conv . server config
where api = Proxy @(API JSON) where api = Proxy @Routes
conv :: App a -> Handler a conv :: App a -> Handler a
conv m = do conv m = do
config <- liftIO $ mkDefaultCliConfig [] config <- liftIO $ mkDefaultCliConfig []
......
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Orphans where
import Control.Monad (forM_, unless)
import qualified Data.Map as M
import Data.Text (Text)
import Lucid (ToHtml)
import Lucid.Base (ToHtml (toHtml))
import Lucid.Html5
import CheckDir
import CheckMap
import Types
import Util (prettyprint)
instance ToHtml Hint where
toHtml (Hint l m) = do
span_ [class_ "level"] $ toHtml (show l)
toHtml m
instance ToHtml DirResult where
toHtml res@DirResult { .. } = do
h3_ $ toHtml (show $ maximumLintLevel res)
unless (null dirresultMissingAssets && null dirresultDeps) $ do
h2_ "Dependencies"
ul_ $ do
forM_ dirresultMissingAssets $ \(MissingAsset missing) -> do
li_ $ toHtml (prettyprint missing)
forM_ dirresultDeps $ \missing -> do
li_ $ toHtml (prettyprint missing)
unless (null dirresultMaps) $ do
h2_ "Maps"
flip M.foldMapWithKey dirresultMaps $ \name MapResult { .. } -> do
h3_ (toHtml name)
ul_ $ do
forM_ mapresultGeneral $ \lint ->
li_ (toHtml lint)
flip M.foldMapWithKey mapresultLayer $ \lint layers ->
li_ $ do
toHtml lint
toHtml ("(in layer" :: Text)
forM_ layers $ \layer ->
span_ [class_ "layer"] (toHtml layer)
toHtml (")" :: Text)
flip M.foldMapWithKey mapresultTileset $ \lint tilesets ->
li_ $ do
toHtml lint
toHtml ("( in layer" :: Text)
forM_ tilesets $ \tileset ->
span_ [class_ "tileset"] (toHtml tileset)
toHtml (")" :: Text)
...@@ -27,12 +27,14 @@ import GHC.Generics (Generic) ...@@ -27,12 +27,14 @@ import GHC.Generics (Generic)
import Lens.Micro (over) import Lens.Micro (over)
import Lens.Micro.TH import Lens.Micro.TH
import LintConfig (LintConfig') import LintConfig (LintConfig')
import Lucid (ToHtml (..))
import Lucid.Html5
import Orphans ()
import System.Exit.Compat (exitFailure) import System.Exit.Compat (exitFailure)
import Toml (TomlCodec) import Toml (TomlCodec)
import qualified Toml import qualified Toml
import Toml.Codec ((.=)) import Toml.Codec ((.=))
-- | a reference in a remote git repository -- | a reference in a remote git repository
data RemoteRef = RemoteRef data RemoteRef = RemoteRef
{ repourl :: Text { repourl :: Text
...@@ -69,6 +71,23 @@ data State = State ...@@ -69,6 +71,23 @@ data State = State
, _registry :: Map UUID RemoteRef , _registry :: Map UUID RemoteRef
} }
instance ToHtml JobStatus where
toHtml status = html_ $ do
head_ $ do
title_ "Job Status"
link_ [rel_ "stylesheet", type_ "text/css", href_ "/styles.css"]
body_ $ div_ [class_ "main-content"] $ case status of
Pending -> do
h2_ "Pending …"
p_ "(please note that this site won't auto-reload, you'll have to refresh it yourself)"
Linted res -> do
p_ "Linted"
toHtml res
Failed err -> do
h2_ "System Error"
p_ $ "error: " <> toHtml err
p_ "you should probably ping an admin about this or sth"
makeLenses ''State makeLenses ''State
defaultState :: State defaultState :: State
......
...@@ -27,7 +27,7 @@ extra-deps: ...@@ -27,7 +27,7 @@ extra-deps:
- logging-effect-1.3.12@sha256:72d168dd09887649ba9501627219b6027cbec2d5541931555b7885b133785ce3,1679 - logging-effect-1.3.12@sha256:72d168dd09887649ba9501627219b6027cbec2d5541931555b7885b133785ce3,1679
- which-0.2@sha256:db82ca7d83d64cce8ad579756f02d27c5bd289806ee02474726f7fafb87318e8,858 - which-0.2@sha256:db82ca7d83d64cce8ad579756f02d27c5bd289806ee02474726f7fafb87318e8,858
- cli-git-0.1.0.2@sha256:4e62e6b7357e4fe698df8b58ba53919f9d4a056e9617dbc00c869a365e316387,1122 - cli-git-0.1.0.2@sha256:4e62e6b7357e4fe698df8b58ba53919f9d4a056e9617dbc00c869a365e316387,1122
- servant-lucid-0.9.0.4@sha256:698db96903a145fdef40cc897f8790728642af917c37b941a98b2da872b65f08,1787
allow-newer: true allow-newer: true
# use aeson with a non-hash-floodable implementation # use aeson with a non-hash-floodable implementation
......
...@@ -74,6 +74,13 @@ packages: ...@@ -74,6 +74,13 @@ packages:
sha256: 1e81c51e2b60db2b1784901cf0af33c67384f5412ad8edaad8a7068135f5217f sha256: 1e81c51e2b60db2b1784901cf0af33c67384f5412ad8edaad8a7068135f5217f
original: original:
hackage: cli-git-0.1.0.2@sha256:4e62e6b7357e4fe698df8b58ba53919f9d4a056e9617dbc00c869a365e316387,1122 hackage: cli-git-0.1.0.2@sha256:4e62e6b7357e4fe698df8b58ba53919f9d4a056e9617dbc00c869a365e316387,1122
- completed:
hackage: servant-lucid-0.9.0.4@sha256:698db96903a145fdef40cc897f8790728642af917c37b941a98b2da872b65f08,1787
pantry-tree:
size: 392
sha256: 39e0e7b2b25980bfe4df036e89959188f9ef9e8c78c85e241fa9a682d1d78cf3
original:
hackage: servant-lucid-0.9.0.4@sha256:698db96903a145fdef40cc897f8790728642af917c37b941a98b2da872b65f08,1787
snapshots: snapshots:
- completed: - completed:
size: 586286 size: 586286
......
...@@ -15,13 +15,13 @@ build-type: Simple ...@@ -15,13 +15,13 @@ build-type: Simple
library library
exposed-modules: exposed-modules:
CheckDir CheckDir
CheckMap
WriteRepo WriteRepo
Util Util
Types Types
LintConfig LintConfig
other-modules: other-modules:
Badges Badges
CheckMap
Dirgraph Dirgraph
KindLinter KindLinter
LayerData LayerData
...@@ -61,6 +61,7 @@ executable server ...@@ -61,6 +61,7 @@ executable server
main-is: Main.hs main-is: Main.hs
other-modules: other-modules:
Handlers Handlers
Orphans
Server Server
Paths_walint Paths_walint
hs-source-dirs: hs-source-dirs:
...@@ -79,11 +80,13 @@ executable server ...@@ -79,11 +80,13 @@ executable server
, filepath , filepath
, http-media , http-media
, logging-effect , logging-effect
, lucid
, microlens , microlens
, microlens-th , microlens-th
, mtl , mtl
, process , process
, servant , servant
, servant-lucid
, servant-server , servant-server
, string-conversions , string-conversions
, text , text
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment