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

6
.gitignore vendored

@ -1,3 +1,7 @@
*~
.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"?>
<project version="4">
<component name="ProjectTasksOptions" suppressed-tasks="Sass" />
<component name="ProjectTasksOptions" suppressed-tasks="Sass;SCSS" />
</project>

@ -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

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

@ -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"]}

@ -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
(: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,8 +30,12 @@
(reset! server nil)))
(defn start-server []
(reset! server
(http-server/run-server #'router
(reset!
server
(http-server/run-server
(fn [req]
(clojure.pprint/pprint req)
(router req))
{:port 8080})))
(defn restart-server []
@ -45,6 +45,5 @@
(comment
(restart-server))
(defn -main [& args]
(defn -main [& _]
(start-server))

@ -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 ]
[ h1 [] [ text "Open-Retro" ]
, nav [] [ Navigation.navTree ]
, main_ [] (appContent model)
]
, node "link" [ rel "stylesheet", href "/assets/style.css" ] []
, node "link" [ rel "stylesheet", href "/compiled/css/style.css" ] []
]
}
@ -100,4 +102,3 @@ homePage : Model -> List (Html Msg)
homePage model =
[ h2 [] [ text "Home" ]
]

@ -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

Loading…
Cancel
Save