From 0ac0d71141fb106dace8c9a55f8dd24a883b3db4 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sat, 10 Oct 2020 01:44:36 +0200 Subject: [PATCH] bla --- .gitignore | 6 ++++- .idea/watcherTasks.xml | 2 +- Makefile | 26 ++++++++++++++++----- backend/.nrepl-port | 1 - backend/backend.iml | 1 + backend/deps.edn | 4 +++- backend/resources/public/index.html | 34 ++++++++++++++++++++++++++++ backend/src/openretro/main.clj | 35 ++++++++++++++--------------- frontend/src/Main.elm | 23 ++++++++++--------- frontend/src/Model.elm | 23 ++++++++++++++----- 10 files changed, 110 insertions(+), 45 deletions(-) delete mode 100644 backend/.nrepl-port create mode 100644 backend/resources/public/index.html diff --git a/.gitignore b/.gitignore index b94e5b4..d3977dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *~ .cpcache -/backend/resources/public/compiled/ +/backend/resources/public/compiled/* +/frontend/assets/css/ +/frontend/elm-stuff/ +/frontend/index.html +/frontend/compiled/ diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml index 9d98b43..f957e1e 100644 --- a/.idea/watcherTasks.xml +++ b/.idea/watcherTasks.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Makefile b/Makefile index 497481f..29b7456 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,34 @@ ROOT=$(shell pwd) -ASSETS_DIR=backend/resources/public/compiled +BACKEND_ASSETS_DIR=backend/resources/public/compiled -TARGET_CSS_DIR=$(ASSETS_DIR)/css +TARGET_CSS_DIR=$(BACKEND_ASSETS_DIR)/css TARGET_CSS_FILE=$(TARGET_CSS_DIR)/style.css +LIVE_CSS_DIR=frontend/compiled/css +LIVE_CSS_FILE=$(LIVE_CSS_DIR)/style.css -TARGET_JS_DIR=$(ASSETS_DIR)/js +TARGET_JS_DIR=$(BACKEND_ASSETS_DIR)/js TARGET_JS_FILE=$(TARGET_JS_DIR)/app.js SOURCE_ELM_FILES=$(wildcard frontend/src/*.elm) SOURCE_SASS_FILE=frontend/assets/sass/style.scss +INDEX_FILE=backend/resources/public/index.html + .PHONY: compile compile: $(TARGET_JS_FILE) $(TARGET_CSS_FILE) $(TARGET_JS_FILE): $(SOURCE_ELM_FILES) mkdir -p $(TARGET_JS_DIR) - cd frontend && elm make src/Main.elm --output $(ROOT)/$(APP_JS) --optimize + cd frontend && elm make src/Main.elm --output $(ROOT)/$(TARGET_JS_FILE) --optimize $(TARGET_CSS_FILE): $(SOURCE_SASS_FILE) mkdir -p $(TARGET_CSS_DIR) sassc --style compressed $(SOURCE_SASS_FILE) > $(TARGET_CSS_FILE) +$(LIVE_CSS_FILE): $(SOURCE_SASS_FILE) + mkdir -p $(LIVE_CSS_DIR) + sassc $(SOURCE_SASS_FILE) > $(LIVE_CSS_FILE) + .PHONY: compile-debug compile-debug: cd frontend && elm make src/Main.elm --output $(ROOT)/$(APP_JS) --debug @@ -28,8 +36,14 @@ compile-debug: .PHONY: elm-live elm-live: - cd frontend && elm-live src/Main.elm --pushstate -- --debug + cd frontend && \ + elm-live src/Main.elm \ + --pushstate \ + --start-page=../$(INDEX_FILE) \ + -- \ + --debug \ + --output=compiled/js/app.js .PHONE: sass-live sass-live: - while sleep 1; do make -s $(TARGET_CSS_FILE); done + while sleep 1; do make -s $(LIVE_CSS_FILE); done diff --git a/backend/.nrepl-port b/backend/.nrepl-port deleted file mode 100644 index 980bda8..0000000 --- a/backend/.nrepl-port +++ /dev/null @@ -1 +0,0 @@ -38495 \ No newline at end of file diff --git a/backend/backend.iml b/backend/backend.iml index 4291198..9051e46 100644 --- a/backend/backend.iml +++ b/backend/backend.iml @@ -5,6 +5,7 @@ + diff --git a/backend/deps.edn b/backend/deps.edn index e6d9f47..67a5648 100644 --- a/backend/deps.edn +++ b/backend/deps.edn @@ -1,4 +1,6 @@ {:deps {http-kit/http-kit {:mvn/version "2.3.0"} metosin/reitit {:mvn/version "0.5.6"} - ring/ring-defaults {:mvn/version "0.3.2"}}} + ring/ring-defaults {:mvn/version "0.3.2"} + hiccup/hiccup {:mvn/version "1.0.5"}} + :paths ["src" "resources"]} diff --git a/backend/resources/public/index.html b/backend/resources/public/index.html new file mode 100644 index 0000000..783b8e7 --- /dev/null +++ b/backend/resources/public/index.html @@ -0,0 +1,34 @@ + + + + + Open-Retro + + + + + + diff --git a/backend/src/openretro/main.clj b/backend/src/openretro/main.clj index 276a075..dae8b46 100644 --- a/backend/src/openretro/main.clj +++ b/backend/src/openretro/main.clj @@ -1,12 +1,8 @@ (ns openretro.main (:require [org.httpkit.server :as http-server] - [reitit.ring :as reitit-ring] - [ring.middleware.defaults :refer [wrap-defaults]])) - -(defn hello [req] - {:status 200 - :headers {"Content-Type" "text/html"} - :body "http-kit"}) + [reitit.ring :as ring] + [ring.middleware.defaults :refer [wrap-defaults api-defaults]] + [hiccup.page :as h])) (defn ws-endpoint [req] (http-server/with-channel req channel @@ -19,12 +15,12 @@ (http-server/send! channel data))))) (def router - (wrap-defaults - (reitit-ring/ring-handler - (reitit-ring/router - [["/hello" {:get {:handler hello}}] - ["/ws" {:get {:handler ws-endpoint}}]])) - ring.middleware.defaults/api-defaults)) + (ring/ring-handler + (ring/router + [["/ws" {:get {:handler ws-endpoint}}]]) + (ring/routes + (ring/create-resource-handler + {:path "/"})))) (defonce server (atom nil)) @@ -34,9 +30,13 @@ (reset! server nil))) (defn start-server [] - (reset! server - (http-server/run-server #'router - {:port 8080}))) + (reset! + server + (http-server/run-server + (fn [req] + (clojure.pprint/pprint req) + (router req)) + {:port 8080}))) (defn restart-server [] (stop-server) @@ -45,6 +45,5 @@ (comment (restart-server)) - -(defn -main [& args] +(defn -main [& _] (start-server)) diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index dd8aa45..6c6a16f 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -24,17 +24,21 @@ main = {-| currently no flags are needed that's the reason for the generic type and \_ as param name -} -init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg ) -init _ url key = +init : { userUuid : String } -> Url.Url -> Nav.Key -> ( Model, Cmd Msg ) +init flags url key = let route : Navigation.Route route = Url.Parser.parse Navigation.routeParser url |> Maybe.withDefault Navigation.Home + initInfo : Model.InitInfo + initInfo = + Model.InitInfo key route url flags.userUuid + model : Model model = - Model.initialModel key route url + Model.initialModel initInfo in routeChanged route model @@ -77,14 +81,12 @@ routeChanged route model = view : Model -> Browser.Document Msg view model = - { title = "OpenAgile" + { title = "Open-Retro" , body = - [ h1 [] [ text "OpenAgile" ] - , div [ class "content" ] - [ nav [] [ Navigation.navTree ] - , main_ [] (appContent model) - ] - , node "link" [ rel "stylesheet", href "/assets/style.css" ] [] + [ h1 [] [ text "Open-Retro" ] + , nav [] [ Navigation.navTree ] + , main_ [] (appContent model) + , node "link" [ rel "stylesheet", href "/compiled/css/style.css" ] [] ] } @@ -100,4 +102,3 @@ homePage : Model -> List (Html Msg) homePage model = [ h2 [] [ text "Home" ] ] - diff --git a/frontend/src/Model.elm b/frontend/src/Model.elm index cdb4f2a..8e1c4d2 100644 --- a/frontend/src/Model.elm +++ b/frontend/src/Model.elm @@ -1,4 +1,4 @@ -module Model exposing (Model, initialModel) +module Model exposing (InitInfo, Model, initialModel) import Browser.Navigation as Nav import Http @@ -11,17 +11,28 @@ type alias Model = , apiHost : String , route : Navigation.Route , httpError : Maybe Http.Error + , userUuid : String } -initialModel : Nav.Key -> Navigation.Route -> Url -> Model -initialModel key route url = +type alias InitInfo = + { navkey : Nav.Key + , route : Navigation.Route + , url : Url + , userUuid : String + } + + +initialModel : InitInfo -> Model +initialModel init = Model - key - ("//" ++ url.host ++ urlToPort url) - route + init.navkey + ("//" ++ init.url.host ++ urlToPort init.url) + init.route -- httpError Maybe.Nothing + -- userUuid + init.userUuid urlToPort : Url -> String