Josha von Gizycki 4 years ago
parent 59a8d396aa
commit 0ac0d71141

6
.gitignore vendored

@ -1,3 +1,7 @@
*~ *~
.cpcache .cpcache
/backend/resources/public/compiled/ /backend/resources/public/compiled/*
/frontend/assets/css/
/frontend/elm-stuff/
/frontend/index.html
/frontend/compiled/

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectTasksOptions" suppressed-tasks="Sass" /> <component name="ProjectTasksOptions" suppressed-tasks="Sass;SCSS" />
</project> </project>

@ -1,26 +1,34 @@
ROOT=$(shell pwd) 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 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 TARGET_JS_FILE=$(TARGET_JS_DIR)/app.js
SOURCE_ELM_FILES=$(wildcard frontend/src/*.elm) SOURCE_ELM_FILES=$(wildcard frontend/src/*.elm)
SOURCE_SASS_FILE=frontend/assets/sass/style.scss SOURCE_SASS_FILE=frontend/assets/sass/style.scss
INDEX_FILE=backend/resources/public/index.html
.PHONY: compile .PHONY: compile
compile: $(TARGET_JS_FILE) $(TARGET_CSS_FILE) compile: $(TARGET_JS_FILE) $(TARGET_CSS_FILE)
$(TARGET_JS_FILE): $(SOURCE_ELM_FILES) $(TARGET_JS_FILE): $(SOURCE_ELM_FILES)
mkdir -p $(TARGET_JS_DIR) 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) $(TARGET_CSS_FILE): $(SOURCE_SASS_FILE)
mkdir -p $(TARGET_CSS_DIR) mkdir -p $(TARGET_CSS_DIR)
sassc --style compressed $(SOURCE_SASS_FILE) > $(TARGET_CSS_FILE) 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 .PHONY: compile-debug
compile-debug: compile-debug:
cd frontend && elm make src/Main.elm --output $(ROOT)/$(APP_JS) --debug cd frontend && elm make src/Main.elm --output $(ROOT)/$(APP_JS) --debug
@ -28,8 +36,14 @@ compile-debug:
.PHONY: elm-live .PHONY: elm-live
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 .PHONE: sass-live
sass-live: sass-live:
while sleep 1; do make -s $(TARGET_CSS_FILE); done while sleep 1; do make -s $(LIVE_CSS_FILE); done

@ -5,6 +5,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/resources/public/compiled" type="java-resource" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

@ -1,4 +1,6 @@
{:deps {:deps
{http-kit/http-kit {:mvn/version "2.3.0"} {http-kit/http-kit {:mvn/version "2.3.0"}
metosin/reitit {:mvn/version "0.5.6"} 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"]}

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<title>Open-Retro</title>
<script src="/compiled/js/app.js"></script>
</head>
<body>
<script>
function createUUID() {
// http://www.ietf.org/rfc/rfc4122.txt
const s = [];
const hexDigits = "0123456789abcdef";
for (let i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
return s.join("");
}
let uuid = localStorage.getItem("uuid") || createUUID();
localStorage.setItem("uuid", uuid)
Elm.Main.init({
flags: {
userUuid: uuid
}
})
</script>
</body>
</html>

@ -1,12 +1,8 @@
(ns openretro.main (ns openretro.main
(:require [org.httpkit.server :as http-server] (:require [org.httpkit.server :as http-server]
[reitit.ring :as reitit-ring] [reitit.ring :as ring]
[ring.middleware.defaults :refer [wrap-defaults]])) [ring.middleware.defaults :refer [wrap-defaults api-defaults]]
[hiccup.page :as h]))
(defn hello [req]
{:status 200
:headers {"Content-Type" "text/html"}
:body "http-kit"})
(defn ws-endpoint [req] (defn ws-endpoint [req]
(http-server/with-channel req channel (http-server/with-channel req channel
@ -19,12 +15,12 @@
(http-server/send! channel data))))) (http-server/send! channel data)))))
(def router (def router
(wrap-defaults (ring/ring-handler
(reitit-ring/ring-handler (ring/router
(reitit-ring/router [["/ws" {:get {:handler ws-endpoint}}]])
[["/hello" {:get {:handler hello}}] (ring/routes
["/ws" {:get {:handler ws-endpoint}}]])) (ring/create-resource-handler
ring.middleware.defaults/api-defaults)) {:path "/"}))))
(defonce server (atom nil)) (defonce server (atom nil))
@ -34,8 +30,12 @@
(reset! server nil))) (reset! server nil)))
(defn start-server [] (defn start-server []
(reset! server (reset!
(http-server/run-server #'router server
(http-server/run-server
(fn [req]
(clojure.pprint/pprint req)
(router req))
{:port 8080}))) {:port 8080})))
(defn restart-server [] (defn restart-server []
@ -45,6 +45,5 @@
(comment (comment
(restart-server)) (restart-server))
(defn -main [& _]
(defn -main [& args]
(start-server)) (start-server))

@ -24,17 +24,21 @@ main =
{-| currently no flags are needed {-| currently no flags are needed
that's the reason for the generic type and \_ as param name that's the reason for the generic type and \_ as param name
-} -}
init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg ) init : { userUuid : String } -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
init _ url key = init flags url key =
let let
route : Navigation.Route route : Navigation.Route
route = route =
Url.Parser.parse Navigation.routeParser url Url.Parser.parse Navigation.routeParser url
|> Maybe.withDefault Navigation.Home |> Maybe.withDefault Navigation.Home
initInfo : Model.InitInfo
initInfo =
Model.InitInfo key route url flags.userUuid
model : Model model : Model
model = model =
Model.initialModel key route url Model.initialModel initInfo
in in
routeChanged route model routeChanged route model
@ -77,14 +81,12 @@ routeChanged route model =
view : Model -> Browser.Document Msg view : Model -> Browser.Document Msg
view model = view model =
{ title = "OpenAgile" { title = "Open-Retro"
, body = , body =
[ h1 [] [ text "OpenAgile" ] [ h1 [] [ text "Open-Retro" ]
, div [ class "content" ] , nav [] [ Navigation.navTree ]
[ nav [] [ Navigation.navTree ]
, main_ [] (appContent model) , main_ [] (appContent model)
] , node "link" [ rel "stylesheet", href "/compiled/css/style.css" ] []
, node "link" [ rel "stylesheet", href "/assets/style.css" ] []
] ]
} }
@ -100,4 +102,3 @@ homePage : Model -> List (Html Msg)
homePage model = homePage model =
[ h2 [] [ text "Home" ] [ h2 [] [ text "Home" ]
] ]

@ -1,4 +1,4 @@
module Model exposing (Model, initialModel) module Model exposing (InitInfo, Model, initialModel)
import Browser.Navigation as Nav import Browser.Navigation as Nav
import Http import Http
@ -11,17 +11,28 @@ type alias Model =
, apiHost : String , apiHost : String
, route : Navigation.Route , route : Navigation.Route
, httpError : Maybe Http.Error , httpError : Maybe Http.Error
, userUuid : String
} }
initialModel : Nav.Key -> Navigation.Route -> Url -> Model type alias InitInfo =
initialModel key route url = { navkey : Nav.Key
, route : Navigation.Route
, url : Url
, userUuid : String
}
initialModel : InitInfo -> Model
initialModel init =
Model Model
key init.navkey
("//" ++ url.host ++ urlToPort url) ("//" ++ init.url.host ++ urlToPort init.url)
route init.route
-- httpError -- httpError
Maybe.Nothing Maybe.Nothing
-- userUuid
init.userUuid
urlToPort : Url -> String urlToPort : Url -> String

Loading…
Cancel
Save