master
Josha von Gizycki 3 years ago
parent a036372335
commit 0a75805e1a

3
.gitignore vendored

@ -7,3 +7,6 @@
/frontend/compiled/ /frontend/compiled/
backend/.nrepl-port backend/.nrepl-port
.idea/sonarlint .idea/sonarlint
/frontend/frontend.iml
/backend/backend.iml
.idea

@ -2,7 +2,9 @@
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<excludePattern pattern="elm-stuff" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>

@ -33,8 +33,12 @@
} }
}) })
let port = window.location.port
if(port === "8000") {
port = "8080"
}
const ws = new WebSocket( const ws = new WebSocket(
"ws://" + window.location.hostname + ":" + window.location.port + "/ws") "ws://" + window.location.hostname + ":" + port + "/ws")
ws.onmessage = function(event) { ws.onmessage = function(event) {
console.debug(event) console.debug(event)
app.ports.wsin.send(JSON.stringify(event.data)) app.ports.wsin.send(JSON.stringify(event.data))

@ -5,22 +5,25 @@
[hiccup.page :as h])) [hiccup.page :as h]))
(defn ws-endpoint [req] (defn ws-endpoint [req]
(http-server/with-channel req channel (println "ws incoming")
(http-server/with-channel
req channel
(http-server/on-close (http-server/on-close
channel channel
(fn [status] (println "closed" status))) (fn [status] (println "closed" status)))
(http-server/on-receive (http-server/on-receive
channel channel
(fn [data] (fn [data]
(http-server/send! channel data))))) (println "received" data)
(http-server/send! channel data)))))
(def router (def router
(ring/ring-handler (ring/ring-handler
(ring/router (ring/router
[["/ws" {:get {:handler ws-endpoint}}]]) [["/ws" {:get {:handler ws-endpoint}}]])
(ring/routes (ring/routes
(ring/create-resource-handler (ring/create-resource-handler
{:path "/"})))) {:path "/"}))))
(defonce server (atom nil)) (defonce server (atom nil))
@ -31,12 +34,12 @@
(defn start-server [] (defn start-server []
(reset! (reset!
server server
(http-server/run-server (http-server/run-server
(fn [req] (fn [req]
(clojure.pprint/pprint req) ;(clojure.pprint/pprint req)
(router req)) (router req))
{:port 8080}))) {:port 8080})))
(defn restart-server [] (defn restart-server []
(stop-server) (stop-server)

@ -1,4 +1,6 @@
// trio colour
$ciColor: #691487; $ciColor: #691487;
$ciColor: InfoBackground;
html { html {
font-family: sans-serif; font-family: sans-serif;
@ -29,7 +31,7 @@ nav {
margin: 0; margin: 0;
padding-left: .5em; padding-left: .5em;
grid-area: title; grid-area: title;
background-image: url("../img/klammer.svg"); //background-image: url("../img/klammer.svg");
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: contain; background-size: contain;
} }

@ -2,7 +2,9 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<excludePattern pattern="elm-stuff" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>

@ -80,8 +80,8 @@ update msg model =
WsOut wsmsg -> WsOut wsmsg ->
( model, wsout wsmsg ) ( model, wsout wsmsg )
WsIn wsmsg -> WsIn strmsg ->
Debug.log wsmsg ( model, Cmd.none ) ( model, Cmd.none )
routeChanged : Navigation.Route -> Model -> ( Model, Cmd Msg ) routeChanged : Navigation.Route -> Model -> ( Model, Cmd Msg )
@ -92,6 +92,11 @@ routeChanged route model =
, Cmd.none , Cmd.none
) )
Navigation.Poker session ->
( { model | route = route, session = Just session }
, Cmd.none
)
view : Model -> Browser.Document Msg view : Model -> Browser.Document Msg
view model = view model =
@ -101,11 +106,11 @@ view model =
[ h1 [ class "app-title" ] [ text "Open-Retro" ] [ h1 [ class "app-title" ] [ text "Open-Retro" ]
, ul [] , ul []
[ li [] [ li []
[ input [ class "board-search-input", placeholder "Board ID..." ] [] [ input [ class "board-search-input", placeholder "Session ID..." ] [] ]
] , li []
[ text "🂿 New retro" ]
, li [] , li []
[ text " New board" [ text "🃠 New poker" ]
]
] ]
] ]
, main_ [] (appContent model) , main_ [] (appContent model)
@ -120,7 +125,15 @@ appContent model =
Navigation.Home -> Navigation.Home ->
homePage model homePage model
Navigation.Poker _ ->
pokerPage model
homePage : Model -> List (Html Msg) homePage : Model -> List (Html Msg)
homePage model = homePage _ =
[]
pokerPage : Model -> List (Html Msg)
pokerPage _ =
[] []

@ -16,6 +16,7 @@ type alias Model =
, route : Navigation.Route , route : Navigation.Route
, httpError : Maybe Http.Error , httpError : Maybe Http.Error
, userUuid : Uuid , userUuid : Uuid
, session : Maybe String
} }
@ -37,6 +38,8 @@ initialModel init =
Maybe.Nothing Maybe.Nothing
-- userUuid -- userUuid
init.userUuid init.userUuid
-- session
Maybe.Nothing
urlToPort : Url -> String urlToPort : Url -> String

@ -2,8 +2,6 @@ module Navigation exposing (Route(..), linkClicked, routeParser)
import Browser import Browser
import Browser.Navigation as Nav import Browser.Navigation as Nav
import Html exposing (Html, a, details, li, summary, text, ul)
import Html.Attributes as Attr exposing (href)
import Url import Url
import Url.Parser exposing ((</>), Parser, map, oneOf, s, top) import Url.Parser exposing ((</>), Parser, map, oneOf, s, top)
@ -20,12 +18,14 @@ linkClicked urlRequest key model =
type Route type Route
= Home = Home
| Poker String
routeParser : Parser (Route -> Route) Route routeParser : Parser (Route -> Route) Route
routeParser = routeParser =
oneOf oneOf
[ map Home top [ map Home top
, map Poker (s "poker" </> Url.Parser.string)
--, map ShowTicket (s "tickets" </> Url.Parser.int) --, map ShowTicket (s "tickets" </> Url.Parser.int)
] ]

@ -0,0 +1,63 @@
module WsMessage exposing (..)
import Json.Decode exposing (Decoder, andThen, decodeString, fail, field, map2, map3, string, succeed)
type Action
= Publish
strToAction : String -> Decoder Action
strToAction str =
if str == "Publish" then
succeed Publish
else
fail ("invalid action '" ++ str ++ "'")
type alias Publisher =
{ uuid : String
, name : String
}
type alias WsMessage =
{ action : Action
, publisher : Publisher
, payload : String
}
-- DECODERS
publisherDecoder : Decoder Publisher
publisherDecoder =
map2 Publisher
(field "uuid" string)
(field "name" string)
msgDecoder : Decoder WsMessage
msgDecoder =
map3 WsMessage
actionDecoder
(field "publisher" publisherDecoder)
(field "payload" string)
actionDecoder : Decoder Action
actionDecoder =
field "action" string |> andThen strToAction
decode : String -> Maybe WsMessage
decode str =
case decodeString msgDecoder str of
Ok msg ->
Just msg
Err _ ->
Nothing
Loading…
Cancel
Save