Commit 6a2eca9e authored by Cédric F.'s avatar Cédric F.

Allow navigation through both keyboard and mouse clicks

parent bd79196c
elm-stuff/ elm-stuff/
/public/elm.min.js /public/assets/js/elm.min.js
all: trappisto all: trappisto
trappisto: src/*.elm trappisto: src/*.elm
elm-make src/Trappisto.elm --warn --output public/elm.js elm-make src/Trappisto.elm --warn --output public/assets/js/elm.js
uglifyjs --mangle --screw-ie8 --output public/elm.min.js -- public/elm.js uglifyjs --mangle --screw-ie8 --output public/assets/js/elm.min.js -- public/assets/js/elm.js
rm public/elm.js rm public/assets/js/elm.js
test: src/*.elm tests/*.elm test: src/*.elm tests/*.elm
elm-test elm-test
...@@ -12,4 +12,4 @@ nginx: nginx/nginx.conf ...@@ -12,4 +12,4 @@ nginx: nginx/nginx.conf
nginx -c nginx/nginx.conf -p . -g 'daemon off;' nginx -c nginx/nginx.conf -p . -g 'daemon off;'
clean: clean:
$(RM) public/elm.js $(RM) public/assets/js/elm*.js
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"elm-lang/http": "1.0.0 <= v < 2.0.0", "elm-lang/http": "1.0.0 <= v < 2.0.0",
"elm-lang/keyboard": "1.0.1 <= v < 2.0.0", "elm-lang/keyboard": "1.0.1 <= v < 2.0.0",
"elm-lang/mouse": "1.0.1 <= v < 2.0.0", "elm-lang/mouse": "1.0.1 <= v < 2.0.0",
"elm-lang/navigation": "2.1.0 <= v < 3.0.0",
"elm-lang/virtual-dom": "2.0.4 <= v < 3.0.0", "elm-lang/virtual-dom": "2.0.4 <= v < 3.0.0",
"elm-lang/window": "1.0.1 <= v < 2.0.0" "elm-lang/window": "1.0.1 <= v < 2.0.0"
}, },
......
...@@ -66,12 +66,20 @@ http { ...@@ -66,12 +66,20 @@ http {
return 200; return 200;
} }
location /rpc { location /assets/ {
break;
}
location = /rpc {
limit_req zone=default burst=10; limit_req zone=default burst=10;
proxy_set_header Authorization "Basic SWp4enNybXNybHFoZGRna2ZqNTVmZ2tjZU1jc3Rzb2F6aWthc2VzdWM6c3RhMmJqYmZ5cWN0eXRxdWpvbGNhdGJ2dmtzanVsclVxcnpjNnd1TWM="; proxy_set_header Authorization "Basic SWp4enNybXNybHFoZGRna2ZqNTVmZ2tjZU1jc3Rzb2F6aWthc2VzdWM6c3RhMmJqYmZ5cWN0eXRxdWpvbGNhdGJ2dmtzanVsclVxcnpjNnd1TWM=";
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_pass https://localhost:9109; proxy_pass https://localhost:9109;
} }
location / {
try_files $uri /index.html;
}
} }
} }
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="elm.min.js" async defer></script> <script src="assets/js/elm.min.js" async defer></script>
<style> <style>
/* inconsolata-regular - latin */ /* inconsolata-regular - latin */
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
src: local('Inconsolata Regular'), local('Inconsolata-Regular'), src: local('Inconsolata Regular'), local('Inconsolata-Regular'),
url('../fonts/inconsolata-v15-latin-regular.woff2') format('woff2'); url('assets/fonts/inconsolata-v15-latin-regular.woff2') format('woff2');
} }
body { body {
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>
<script> <script>
particlesJS.load('particles-js', 'particles.json', function() { particlesJS.load('particles-js', 'assets/js/particles.json', function() {
console.log('callback - particles.js config loaded'); console.log('callback - particles.js config loaded');
}); });
......
...@@ -2,6 +2,7 @@ module Components.Block exposing (..) ...@@ -2,6 +2,7 @@ module Components.Block exposing (..)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Http exposing (Error) import Http exposing (Error)
import Json.Encode as Encode import Json.Encode as Encode
import Json.Decode as Decode import Json.Decode as Decode
...@@ -90,7 +91,9 @@ view model = ...@@ -90,7 +91,9 @@ view model =
List.map List.map
(\ticket -> (\ticket ->
li [ class "list-group-item bg-dark" ] li [ class "list-group-item bg-dark" ]
[ a [ href <| "#" ++ ticket ] [ text <| "Stake transaction " ++ ticket ] [ a
[ href ticket ]
[ text <| "Stake transaction " ++ ticket ]
] ]
) )
model.tickets model.tickets
......
module Trappisto exposing (main) module Trappisto exposing (main)
import Html exposing (program) import Navigation
import Trappisto.Model exposing (Model, Msg) import Trappisto.Model
import Trappisto.Update exposing (init, update, subscriptions) import Trappisto.Update exposing (init, update, subscriptions)
import Trappisto.View exposing (view) import Trappisto.View exposing (view)
main : Program Never Model Msg main : Program Never Trappisto.Model.Model Trappisto.Model.Msg
main = main =
program Navigation.program Trappisto.Model.NewUrl
{ init = init { init = init
, view = view , view = view
, update = update , update = update
......
module Trappisto.Model exposing (..) module Trappisto.Model exposing (..)
import Navigation
import Mouse import Mouse
import Window import Window
import Keyboard import Keyboard
...@@ -43,7 +44,8 @@ initialModel = ...@@ -43,7 +44,8 @@ initialModel =
type Msg type Msg
= StatusMsg StatusComponent.Msg = NewUrl Navigation.Location
| StatusMsg StatusComponent.Msg
| BlockMsg BlockComponent.Msg | BlockMsg BlockComponent.Msg
| JsMsg String | JsMsg String
| Query String | Query String
......
port module Trappisto.Update exposing (init, update, subscriptions) port module Trappisto.Update exposing (init, update, subscriptions)
import Navigation
import Keyboard import Keyboard
import Mouse import Mouse
import Task exposing (Task) import Task exposing (Task)
...@@ -16,13 +17,25 @@ port elmToJs : String -> Cmd msg ...@@ -16,13 +17,25 @@ port elmToJs : String -> Cmd msg
port jsToElm : (String -> msg) -> Sub msg port jsToElm : (String -> msg) -> Sub msg
init : ( Model, Cmd Msg ) init : Navigation.Location -> ( Model, Cmd Msg )
init = init location =
let let
query =
extractQuery location
( model, msg ) = ( model, msg ) =
update FetchStatus initialModel if String.isEmpty query then
update FetchStatus { initialModel | query = query }
else
update (Query query) { initialModel | query = query }
in in
( model, Cmd.batch [ elmToJs "focus", msg, Task.perform Resize Window.size ] ) ( model
, Cmd.batch
[ elmToJs "focus"
, msg
, Task.perform Resize Window.size
]
)
subscriptions : Model -> Sub Msg subscriptions : Model -> Sub Msg
...@@ -49,6 +62,9 @@ update action model = ...@@ -49,6 +62,9 @@ update action model =
in in
( { updatedModel | time = time }, cmd ) ( { updatedModel | time = time }, cmd )
NewUrl location ->
( { model | query = extractQuery location }, Cmd.none )
FetchStatus -> FetchStatus ->
let let
( updatedModel, cmd ) = ( updatedModel, cmd ) =
...@@ -68,16 +84,14 @@ update action model = ...@@ -68,16 +84,14 @@ update action model =
possibleBlockHash query = possibleBlockHash query =
(String.length query == 64 && String.left 8 query == "00000000") || query == genesis (String.length query == 64 && String.left 8 query == "00000000") || query == genesis
possibleBlockHeight query = parseBlockHeight string =
case String.toInt query of String.toInt string |> Result.toMaybe |> Maybe.withDefault -1
Ok int ->
True
Err _ -> possibleBlockHeight query =
False parseBlockHeight query /= -1
possibleTransaction query = possibleTransaction query =
False String.length query == 64 && String.left 8 query /= "00000000" && query /= genesis
statusModel = statusModel =
model.statusModel model.statusModel
...@@ -87,17 +101,22 @@ update action model = ...@@ -87,17 +101,22 @@ update action model =
updatedModel = updatedModel =
{ model | query = query, statusModel = updatedStatusModel } { model | query = query, statusModel = updatedStatusModel }
updateUrl ( model, cmd ) =
( model
, Cmd.batch [ newUrl model, cmd ]
)
in in
if query == "" then if query == "" then
( { updatedModel | template = Status }, Cmd.none ) ( { updatedModel | template = Status }, Cmd.none ) |> updateUrl
else if possibleTransaction query then else if possibleTransaction query then
fetchTransaction query updatedModel fetchTransaction query updatedModel |> updateUrl
else if possibleBlockHash query then else if possibleBlockHash query then
fetchBlockByHash query updatedModel fetchBlockByHash query updatedModel |> updateUrl
else if possibleBlockHeight query then else if possibleBlockHeight query then
fetchBlockByHeight (String.toInt query |> Result.toMaybe |> Maybe.withDefault -1) updatedModel fetchBlockByHeight (parseBlockHeight query) updatedModel |> updateUrl
else if possibleAddress query then else if possibleAddress query then
fetchAddress query updatedModel fetchAddress query updatedModel |> updateUrl
else else
let let
statusModel = statusModel =
...@@ -106,7 +125,7 @@ update action model = ...@@ -106,7 +125,7 @@ update action model =
updatedStatusModel = updatedStatusModel =
{ statusModel | error = Just "Not sure what you're looking for :|" } { statusModel | error = Just "Not sure what you're looking for :|" }
in in
( { updatedModel | statusModel = updatedStatusModel }, Cmd.none ) ( { updatedModel | statusModel = updatedStatusModel }, Cmd.none ) |> updateUrl
StatusMsg statusMsg -> StatusMsg statusMsg ->
let let
...@@ -178,7 +197,7 @@ fetchBlockByHeight height model = ...@@ -178,7 +197,7 @@ fetchBlockByHeight height model =
fetchTransaction : String -> Model -> ( Model, Cmd Msg ) fetchTransaction : String -> Model -> ( Model, Cmd Msg )
fetchTransaction transaction model = fetchTransaction transaction model =
( model, Cmd.none ) fetchBlockByHash transaction model
decodeKeys : Bool -> Keyboard.KeyCode -> Keys -> Keys decodeKeys : Bool -> Keyboard.KeyCode -> Keys -> Keys
...@@ -230,3 +249,23 @@ handleKeys { esc, i, j, k } model = ...@@ -230,3 +249,23 @@ handleKeys { esc, i, j, k } model =
model model
else else
model model
extractQuery : Navigation.Location -> String
extractQuery location =
let
pathname =
String.dropLeft 1 location.pathname
hash =
String.dropLeft 1 location.hash
in
if String.isEmpty pathname then
hash
else
pathname
newUrl : Model -> Cmd Msg
newUrl model =
Navigation.newUrl <| "/#" ++ model.query
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment