implemented the simplest web user interface possible

This commit is contained in:
didier amyot committed 2018-07-21 09:41:31 -04:00
1 parent d50d404099
commit 530bdfd0c6
126 files changed
+32392 -53

No files matched your search

+3 -2
View File
@@ -3,6 +3,7 @@
[skirmish.rest.core]
[skirmish.cli.benchmark]
[skirmish.exchange.core]
[skirmish.wui.server]
[skirmish.middleware.core :refer [create-exchange-apis-for]]
[aero.core :refer (read-config)]
[orchestra.spec.test :as st]
@@ -13,8 +14,8 @@
;; arguments: the config map and the "exchange-api"
{:api-server skirmish.rest.core/api-main
:exchange-core skirmish.exchange.core/-main ;; should be skirmish.exchange.core/api-main
:api-bookkeeper skirmish.rest.core/bookkeeper-main})
;:benchmark skirmish.cli.benchmark/-main})
:api-bookkeeper skirmish.rest.core/bookkeeper-main
:wui skirmish.wui.server/-main})
(defn run-all-targets-in-separate-threads [target-fns config exchange-apis]
(println "running multiple targets. This is okay in dev but horrible in production")
+54
View File
@@ -0,0 +1,54 @@
(ns skirmish.wui.handler
(:require [compojure.core :refer [GET defroutes]]
[compojure.route :refer [not-found resources]]
[hiccup.page :refer [include-js include-css html5]]
[skirmish.wui.middleware :refer [wrap-middleware]]))
(def mount-target
[:div#app
[:h3 "ClojureScript has not been compiled!"]
[:p "please run "
[:b "lein figwheel"]
" in order to start the compiler"]])
(defn head []
[:head
[:meta {:charset "utf-8"}]
[:meta {:name "viewport"
:content "width=device-width, initial-scale=1"}]
(include-css "/css/site.css"); use "/css/site.min.css" in production
(include-css "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css")
(include-css "https://fonts.googleapis.com/css?family=Frijole%7CKarma")])
(defn homepage []
(html5 {:class "has-background-black"}
(head)
[:body.body-container
mount-target
(include-js "/js/app.js")]))
(defn loading-page []
(html5
(head)
[:body {:class "body-container"}
mount-target
(include-js "/js/app.js")]))
(defn cards-page []
(html5
(head)
[:body
mount-target
(include-js "/js/app_devcards.js")]))
(defroutes routes
(GET "/" [] (homepage))
(GET "/:client-path" [] (homepage))
(GET "/:client-path-1/:client-path-2" [] (homepage))
(GET "/:client-path-1/:client-path-2/:client-path-3" [] (homepage))
(GET "/about" [] (loading-page))
(GET "/cards" [] (cards-page))
(resources "/")
(not-found "Not Found"))
(def app (wrap-middleware #'routes))
+8
View File
@@ -0,0 +1,8 @@
(ns skirmish.wui.server
(:require [skirmish.wui.handler :refer [app]]
[ring.adapter.jetty :refer [run-jetty]])
(:gen-class))
(defn -main [config exchange-apis]
(let [port 3000]
(run-jetty app {:port port :join? false})))
File renamed without changes.
@@ -0,0 +1,4 @@
(ns skirmish.wui.components.home-page)
(defn page [state]
[:h1 "Hello world sdjjksd dsklsd"])
@@ -0,0 +1,22 @@
(ns skirmish.wui.components.securities-page)
(def table-head
[:thead.has-background-grey-dark
[:tr
[:th.has-text-white-bis "sec-id"]
[:th.has-text-white-bis "name"]
[:th.has-text-white-bis "description"]]])
(defn create-row [sec]
(let [link [:a {:href (str "/securities/" (-> sec :sec-id name))} (-> sec :sec-id name)]]
[:tr.has-text-white-bis {:key (:sec-id sec)}
[:td link]
[:td (:name sec)]
[:td (:description sec)]]))
(defn page [state]
(let [securities [{:sec-id :foo} {:sec-id :bar} {:sec-id :toto}]]
[:table.table.is-hoverable.is-fullwidth
table-head
[:tbody
(for [sec securities] (create-row sec))]]))
@@ -0,0 +1,4 @@
(ns skirmish.wui.components.security-page)
(defn page [state]
[:h1 (str "this is a security page for " (:sec-id state))])
@@ -0,0 +1,32 @@
(ns skirmish.wui.components.todo-page)
(def on-it {:style {:font-weight "bold"}})
(def done {:style {:text-decoration "line-through"}})
(defn page []
[:div.content
[:ul
[:li "shits"
[:ul
[:li "add a list of bogus securities"]]]
[:li "kafka"
[:ul
[:li done "setup kafka"]
[:li "try kafka streams"]
[:li done "pass every order in kafka"]]]
[:li "Logic"
[:ul
[:li done "les orders doivent inclurent les bornes"]
[:li done "simplifier le spec des ordres en enlevant " [:code ":order/"]]
[:li "finish insertion logic and test with spec"]
[:li "link insertion logic to application"]]]
[:li "User interface"
[:ul
[:li "Add logo"]
[:li "Faire un ui pour sell limit order"]
[:li "Faire un ui pour buy limit order"]
[:li "Faire un ui pour sell market order"]
[:li "Faire un ui pour buy market order"]]]]])
@@ -0,0 +1,23 @@
(ns skirmish.wui.components.topbar)
(defn font-awesome [class]
[:i {:class (str "fa fa-" class) :aria-hidden true}])
(defn- top-bar-class [state page]
(when (= (:page @state) page)
"is-active"))
(defn top-bar [state]
[:nav.navbar.is-dark.is-boxed {:style {:margin-bottom "1em"}}
[:div.container
[:div.navbar-start
[:a.navbar-item.is-tab {:href "/" :class (top-bar-class state :home)} "Home"]
[:a.navbar-item.is-tab {:href "/securities" :class (top-bar-class state :securities)} "Securities"]
[:a.navbar-item.is-tab {:href "/create-order" :class (top-bar-class state :create-order)} "Create order"]
[:a.navbar-item.is-tab {:href "/portfolio" :class (top-bar-class state :view-portfolio)} "View Portfolio"]
[:a.navbar-item.is-tab {:href "/todo" :class (top-bar-class state :todo)} "Todo"]]
[:div.navbar-end
[:a.navbar-item.is-tab {} "Skirmish Shitty Exchange"]]]])
+63
View File
@@ -0,0 +1,63 @@
(ns skirmish.wui.core
(:require [reagent.core :as reagent :refer [atom]]
[skirmish.wui.pages :as pages]
[skirmish.wui.components.topbar :refer [top-bar]]
[reagent.session :as session]
[secretary.core :as secretary :include-macros true]
[accountant.core :as accountant]))
;; -------------------------
;; Views
(enable-console-print!)
(defonce state (atom {}))
;; -------------------------
;; Routes
(secretary/defroute "/todo" []
(session/put! :current-page #'pages/todo-page)
(swap! state #(into % {:page :todo})))
(secretary/defroute "/" []
(session/put! :current-page #'pages/home-page)
(swap! state #(into % {:page :home})))
(secretary/defroute "/securities" []
(session/put! :current-page #'pages/securities-page)
(swap! state #(into % {:page :securities})))
(secretary/defroute "/securities/:sec-id" [sec-id]
(session/put! :current-page #'pages/security-page)
(swap! state #(into % {:page :securities :sec-id (keyword sec-id)})))
;; -------------------------
;; Initialize app
(defn current-page []
"This is the basic page setup."
[:div
(top-bar state)
[:div
[:div.columns
[:div.column.is-8.is-offset-2
[(session/get :current-page) @state]]]]])
(defn mount-root []
(reagent/render [current-page] (.getElementById js/document "app")))
(defn init! []
(accountant/configure-navigation!
{:nav-handler
(fn [path]
(secretary/dispatch! path))
:path-exists?
(fn [path]
(secretary/locate-route path))})
(accountant/dispatch-current!)
(mount-root))
+13
View File
@@ -0,0 +1,13 @@
(ns skirmish.wui.pages
(:require [skirmish.wui.components.todo-page]
[skirmish.wui.components.home-page]
[skirmish.wui.components.securities-page]
[skirmish.wui.components.security-page]))
(def home-page skirmish.wui.components.home-page/page)
(def todo-page skirmish.wui.components.todo-page/page)
(def securities-page skirmish.wui.components.securities-page/page)
(def security-page skirmish.wui.components.security-page/page)
+4
View File
@@ -0,0 +1,4 @@
body {
background: tomato;
color: pink;
}
+37
View File
@@ -0,0 +1,37 @@
@charset "utf-8";
// Files not starting with _ are consided entrypoints, i.e. they are compiled to .css files
// Partials (files starting with _) can be inclued using @import:
// (import path can include _ but it is not needed)`
@import "../../node_modules/bulma/sass/utilities/_all";
$background: $black;
$body-background-color: $black;
$text: $white-ter;
$link: $turquoise;
$table-background-color: $grey-dark;
$table-cell-heading-color: $grey-darker;
$border: $yellow;
@import "../../node_modules/bulma/sass/base/_all";
@import "../../node_modules/bulma/sass/elements/_all";
@import "../../node_modules/bulma/sass/components/_all";
@import "../../node_modules/bulma/sass/grid/_all";
@import "../../node_modules/bulma/sass/layout/_all";
//@import "../../node_modules/bulma/sass/bulma.sass";
//@import "../../node_modules/bulma/sass/base/_all";
//@import "../../node_modules/bulma/sass/elements/_all";
//@import "../../node_modules/bulma/sass/components/_all";
//@import "../../node_modules/bulma/sass/grid/_all";
//@import "../../node_modules/bulma/sass/layout/_all";
//@import "../../node_modules/metrics-graphics/dist/metricsgraphics";