Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

halogen-tx-explorer: create package #344 (WIP) #346

Merged
merged 7 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let additions =
, stbx-lang = ./stbx-lang/spago.dhall as Location
, stbx-service-rest = ./stbx-service-rest/spago.dhall as Location
, stbx-tx-store = ./stbx-tx-store/spago.dhall as Location
, studio = ./studio/spago.dhall as Location
, studio-common = ./studio-common/spago.dhall as Location
, vec = ./vec/spago.dhall as Location
, halogen-diagram-editor = ./halogen-diagram-editor/spago.dhall as Location
Expand Down
13 changes: 12 additions & 1 deletion studio/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Routing.Hash as Routing

import View.Studio as Studio
import View.Studio (Query(LoadTransactionsThenView))
import View.Studio.Model.Route (RouteF(Home))

import ExampleData as Ex

Expand All @@ -19,6 +20,16 @@ main = runHalogenAff do
urlHash <- liftEffect Routing.getHash
liftEffect $ log $ "studio: transaction hash to be visited: " <> urlHash
body <- awaitBody
io <- runUI Studio.ui unit body
io <- runUI Studio.ui initialState body
_ <- io.query $ H.tell (LoadTransactionsThenView Ex.endpointUrl urlHash)
pure io
where
initialState :: Studio.Input
initialState =
{ title: "Statebox Studio"
, msg: "Welcome to Statebox Studio!"
, projects: Ex.projects
, hashSpace: mempty
, apiUrl: Ex.endpointUrl
, route: Home
}
16 changes: 4 additions & 12 deletions studio/src/View/Studio.purs
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,20 @@ import View.Studio.Model.Route as Route
import View.Studio.Model.Route (Route, RouteF(..), NodeIdent(..))
import View.Studio.View (render, ChildSlots)

import ExampleData as Ex

type Input = Unit
type Input = State

data Query a = LoadTransactionsThenView URL TxId a

ui :: ∀ m. MonadAff m => H.Component HTML Query Input Void m
ui =
H.mkComponent
{ initialState: const initialState
{ initialState: mkInitialState
, eval: mkEval $ defaultEval { handleAction = handleAction, handleQuery = handleQuery }
, render: render
}
where
initialState :: State
initialState =
{ msg: "Welcome to Statebox Studio!"
, projects: Ex.projects
, hashSpace: AdjacencySpace.empty
, apiUrl: Ex.endpointUrl
, route: Home
}
mkInitialState :: Input -> State
mkInitialState input = input

handleQuery :: ∀ a. Query a -> H.HalogenM State Action ChildSlots Void m (Maybe a)
handleQuery = case _ of
Expand Down
1 change: 1 addition & 0 deletions studio/src/View/Studio/Model.purs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type State =
{ route :: Route
, projects :: Array Project
, hashSpace :: AdjacencySpace HashStr TxSum -- ^ Hashes and their (tree of) links.
, title :: String
, msg :: String
, apiUrl :: URL
}
Expand Down
13 changes: 7 additions & 6 deletions studio/src/View/Studio/View.purs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data VoidF a
render :: ∀ m. MonadAff m => State -> ComponentHTML Action ChildSlots m
render state =
div []
[ navBar
[ navBar state.title
, div [ classes [ ClassName "flex" ] ]
[ div [ classes [ ClassName "w-1/6", ClassName "h-12" ] ]
[ slot _objectTree unit (TreeMenu.menuComponent (_ == state.route)) (stateMenu state) ((\(TreeMenu.Clicked menuNodeId route) -> ShowDiagramNodeContent route) >>> Just) ]
Expand Down Expand Up @@ -141,13 +141,14 @@ routeBreadcrumbs route =
where
crumb str = li [] [ a [ href "#" ] [ text str ] ]

navBar :: ∀ m. ComponentHTML Action ChildSlots m
navBar =
navBar :: ∀ m. String -> ComponentHTML Action ChildSlots m
navBar title =
nav [ classes $ ClassName <$> [ "css-navbar", "flex", "items-center", "justify-between", "flex-wrap", "bg-purple-darker", "p-6" ] ]
[ div [ classes $ ClassName <$> [ "flex", "items-center", "flex-no-shrink", "text-white", "mr-6" ] ]
[ span [ classes [ ClassName "css-logo-statebox" ] ] []
[ div [ classes $ ClassName <$> [ "flex", "items-center", "flex-no-shrink", "text-white", "mr-6" ] ]
[ span [ classes [ ClassName "css-logo-statebox" ] ]
[]
, span [ classes $ ClassName <$> [ "navbar-item", "ml-4", "font-semibold", "text-xl" ] ]
[ text "Statebox Studio" ]
[ text title ]
]
, menu [ "Home" /\ Just Home
, "Project" /\ Nothing
Expand Down
36 changes: 36 additions & 0 deletions tx-browser/html/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@import "tailwindcss/dist/utilities.min.css";
@import "tailwindcss/dist/preflight.min.css";
@import "@fortawesome/fontawesome-free/css/all.min.css";

@import "../../studio/html/petrinet.css";
@import "../../studio/html/diagram.css";
@import "../../studio/html/typedefs.css";
@import "../../studio/html/auths.css";
@import "../../studio/html/kdmoncat-bricks.css";
@import "../../halogen-grid-kit/src/GridKit/KeyHandler.css";
@import "./tx-browser.css";

svg {
display: block;
height: 100%;
width: 100%;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
}
a {
text-decoration: none;
}
.css-navbar .css-logo-statebox {
display: inline-block;
width: 32px;
height: 37px;
background-image: url(../../studio/html/logo-statebox-white.svg);
}
.css-route-breadcrumbs li+li::before {
margin-left: 0.5em;
margin-right: 0.5em;
color: #b5b5b5;
content: "\02192";
}
13 changes: 13 additions & 0 deletions tx-browser/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>Statebox Transaction Browser</title>

<link rel="stylesheet" href="index.css">
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fast-xml-parser/3.10.0/parser.js"></script>
<script src="index.js"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions tx-browser/html/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
window.Stbx = require('@statebox/stbx-js')
window.dagre = require("dagre")
var Main = require("../output/index.js")
Main.main()
6 changes: 6 additions & 0 deletions tx-browser/html/tx-browser.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tr.css-tx-execution {
background: orange;
}
tr.css-tx-current {
background: pink;
}
39 changes: 39 additions & 0 deletions tx-browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "stbx-tx-browser",
"version": "1.0.0",
"description": "Statebox Transaction Browser",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"postinstall": "spago install",
"start": "npm run build && concurrently --kill-others --handle-input npm:watch npm:serve",
"build": "spago bundle-module --main Statebox.Browser.Main --to output/index.js --purs-args --censor-codes=ImplicitImport,ImplicitQualifiedImport,HidingImport",
"watch": "spago bundle-module --main Statebox.Browser.Main --to output/index.js --watch --purs-args --censor-codes=ImplicitImport,ImplicitQualifiedImport,HidingImport",
"test": "spago test",
"docs": "spago docs",
"repl": "spago repl",
"serve": "parcel html/index.html",
"bundle": "npm run build && rm -rf dist && parcel build html/index.html --public-url . --no-source-maps"
},
"keywords": [
"statebox",
"petrinet"
],
"author": "Erik Post <erik@shinsetsu.nl>",
"license": "Commercial",
"devDependencies": {
"concurrently": "^5.0.2",
"parcel-bundler": "^1.12.4",
"purescript": "^0.13.5",
"purescript-psa": "^0.7.3",
"spago": "^0.13"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.6.3",
"@statebox/stbx-js": "0.0.31",
"dagre": "^0.8.4",
"tailwindcss": "^0.7.3"
}
}
9 changes: 9 additions & 0 deletions tx-browser/spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ name =
"stbx-tx-browser"
, sources =
[ "src/**/*.purs" ]
, dependencies =
[ "studio" ]
, packages =
../packages.dhall
}
35 changes: 35 additions & 0 deletions tx-browser/src/Statebox/Browser/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Statebox.Browser.Main where

import Prelude
import Effect (Effect)
import Effect.Class (liftEffect)
import Effect.Console (log)
import Halogen as H
import Halogen.Aff (awaitBody, runHalogenAff)
import Halogen.VDom.Driver (runUI)
import Routing.Hash as Routing

import View.Studio as Studio
import View.Studio (Query(LoadTransactionsThenView))
import View.Studio.Model.Route (RouteF(Home))

import ExampleData as Ex

main :: Effect Unit
main = runHalogenAff do
urlHash <- liftEffect Routing.getHash
liftEffect $ log $ "tx browser: transaction hash to be visited: " <> urlHash
body <- awaitBody
io <- runUI Studio.ui initialState body
_ <- io.query $ H.tell (LoadTransactionsThenView Ex.endpointUrl urlHash)
pure io
where
initialState :: Studio.Input
initialState =
{ title: "Statebox Transaction Browser"
, msg: "Welcome to the Statebox Transaction Browser!"
, projects: mempty
, hashSpace: mempty
, apiUrl: Ex.endpointUrl
, route: Home
}