From 0a75805e1a25aba12fc5e43d69a076bc22d95541 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Tue, 6 Jul 2021 17:15:25 +0200 Subject: [PATCH] stuff --- .gitignore | 3 ++ .idea/open-retro.iml | 4 +- backend/resources/public/index.html | 6 ++- backend/src/openretro/main.clj | 37 +++++++++-------- frontend/assets/sass/style.scss | 4 +- frontend/frontend.iml | 4 +- frontend/src/Main.elm | 27 +++++++++---- frontend/src/Model.elm | 3 ++ frontend/src/Navigation.elm | 4 +- frontend/src/WsMessage.elm | 63 +++++++++++++++++++++++++++++ 10 files changed, 125 insertions(+), 30 deletions(-) create mode 100644 frontend/src/WsMessage.elm diff --git a/.gitignore b/.gitignore index de6c4c0..dc5260d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ /frontend/compiled/ backend/.nrepl-port .idea/sonarlint +/frontend/frontend.iml +/backend/backend.iml +.idea \ No newline at end of file diff --git a/.idea/open-retro.iml b/.idea/open-retro.iml index d6ebd48..a86534e 100644 --- a/.idea/open-retro.iml +++ b/.idea/open-retro.iml @@ -2,7 +2,9 @@ - + + + diff --git a/backend/resources/public/index.html b/backend/resources/public/index.html index 121ea5a..b2df007 100644 --- a/backend/resources/public/index.html +++ b/backend/resources/public/index.html @@ -33,8 +33,12 @@ } }) + let port = window.location.port + if(port === "8000") { + port = "8080" + } const ws = new WebSocket( - "ws://" + window.location.hostname + ":" + window.location.port + "/ws") + "ws://" + window.location.hostname + ":" + port + "/ws") ws.onmessage = function(event) { console.debug(event) app.ports.wsin.send(JSON.stringify(event.data)) diff --git a/backend/src/openretro/main.clj b/backend/src/openretro/main.clj index dae8b46..7c5942f 100644 --- a/backend/src/openretro/main.clj +++ b/backend/src/openretro/main.clj @@ -5,22 +5,25 @@ [hiccup.page :as h])) (defn ws-endpoint [req] - (http-server/with-channel req channel + (println "ws incoming") + (http-server/with-channel + req channel (http-server/on-close - channel - (fn [status] (println "closed" status))) + channel + (fn [status] (println "closed" status))) (http-server/on-receive - channel - (fn [data] - (http-server/send! channel data))))) + channel + (fn [data] + (println "received" data) + (http-server/send! channel data))))) (def router (ring/ring-handler - (ring/router - [["/ws" {:get {:handler ws-endpoint}}]]) - (ring/routes - (ring/create-resource-handler - {:path "/"})))) + (ring/router + [["/ws" {:get {:handler ws-endpoint}}]]) + (ring/routes + (ring/create-resource-handler + {:path "/"})))) (defonce server (atom nil)) @@ -31,12 +34,12 @@ (defn start-server [] (reset! - server - (http-server/run-server - (fn [req] - (clojure.pprint/pprint req) - (router req)) - {:port 8080}))) + server + (http-server/run-server + (fn [req] + ;(clojure.pprint/pprint req) + (router req)) + {:port 8080}))) (defn restart-server [] (stop-server) diff --git a/frontend/assets/sass/style.scss b/frontend/assets/sass/style.scss index 07fd22c..470a4a4 100644 --- a/frontend/assets/sass/style.scss +++ b/frontend/assets/sass/style.scss @@ -1,4 +1,6 @@ +// trio colour $ciColor: #691487; +$ciColor: InfoBackground; html { font-family: sans-serif; @@ -29,7 +31,7 @@ nav { margin: 0; padding-left: .5em; grid-area: title; - background-image: url("../img/klammer.svg"); + //background-image: url("../img/klammer.svg"); background-repeat: no-repeat; background-size: contain; } diff --git a/frontend/frontend.iml b/frontend/frontend.iml index 8021953..482bdba 100644 --- a/frontend/frontend.iml +++ b/frontend/frontend.iml @@ -2,7 +2,9 @@ - + + + diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index 15a0db1..6d0bd81 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -80,8 +80,8 @@ update msg model = WsOut wsmsg -> ( model, wsout wsmsg ) - WsIn wsmsg -> - Debug.log wsmsg ( model, Cmd.none ) + WsIn strmsg -> + ( model, Cmd.none ) routeChanged : Navigation.Route -> Model -> ( Model, Cmd Msg ) @@ -92,6 +92,11 @@ routeChanged route model = , Cmd.none ) + Navigation.Poker session -> + ( { model | route = route, session = Just session } + , Cmd.none + ) + view : Model -> Browser.Document Msg view model = @@ -101,11 +106,11 @@ view model = [ h1 [ class "app-title" ] [ text "Open-Retro" ] , ul [] [ li [] - [ input [ class "board-search-input", placeholder "Board ID..." ] [] - ] + [ input [ class "board-search-input", placeholder "Session ID..." ] [] ] + , li [] + [ text "🂿 New retro" ] , li [] - [ text "⊕ New board" - ] + [ text "🃠 New poker" ] ] ] , main_ [] (appContent model) @@ -120,7 +125,15 @@ appContent model = Navigation.Home -> homePage model + Navigation.Poker _ -> + pokerPage model + homePage : Model -> List (Html Msg) -homePage model = +homePage _ = + [] + + +pokerPage : Model -> List (Html Msg) +pokerPage _ = [] diff --git a/frontend/src/Model.elm b/frontend/src/Model.elm index 37639aa..0a42d20 100644 --- a/frontend/src/Model.elm +++ b/frontend/src/Model.elm @@ -16,6 +16,7 @@ type alias Model = , route : Navigation.Route , httpError : Maybe Http.Error , userUuid : Uuid + , session : Maybe String } @@ -37,6 +38,8 @@ initialModel init = Maybe.Nothing -- userUuid init.userUuid + -- session + Maybe.Nothing urlToPort : Url -> String diff --git a/frontend/src/Navigation.elm b/frontend/src/Navigation.elm index c7fb0f6..30892f9 100644 --- a/frontend/src/Navigation.elm +++ b/frontend/src/Navigation.elm @@ -2,8 +2,6 @@ module Navigation exposing (Route(..), linkClicked, routeParser) import Browser 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.Parser exposing ((), Parser, map, oneOf, s, top) @@ -20,12 +18,14 @@ linkClicked urlRequest key model = type Route = Home + | Poker String routeParser : Parser (Route -> Route) Route routeParser = oneOf [ map Home top + , map Poker (s "poker" Url.Parser.string) --, map ShowTicket (s "tickets" Url.Parser.int) ] diff --git a/frontend/src/WsMessage.elm b/frontend/src/WsMessage.elm new file mode 100644 index 0000000..a1a1c11 --- /dev/null +++ b/frontend/src/WsMessage.elm @@ -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