Skip to content

Commit

Permalink
Previously used config folders (#41)
Browse files Browse the repository at this point in the history
* #34 first attempt using localStorage

* #34 can load config from previously-used-list

* #34 updating semantic to 2.4.0

* #34 can remove paths from previously used list

* #34 robustifying js interop

* #34 Not loading directly from prev configs, but setting input field
  • Loading branch information
ljamt authored Feb 28, 2019
1 parent ec7de15 commit 54aab1e
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 73 deletions.
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[org.clojure/clojure "1.9.0"]
[fulcrologic/fulcro "2.8.0"]
[fulcrologic/semantic-ui-react-wrappers "2.0.4"]
[cljsjs/semantic-ui-react "0.84.0-0"]]
[cljsjs/semantic-ui-react "0.84.0-0"]
[binaryage/oops "0.7.0"]]
:plugins [[lein-figwheel "0.5.16"]
[figwheel-sidecar "0.5.17"]
[lein-cljsbuild "1.1.7"]
Expand Down
140 changes: 74 additions & 66 deletions resources/public/static/css/semantic.css

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions src/cse_client/controller.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[cljs.spec.alpha :as s]
[cljs.core.async :refer [<! timeout]]
[clojure.string :as str]
[re-frame.core :as rf]))
[re-frame.core :as rf]
[cse-client.localstorage :as storage]))

;; Prevent handler overwriting warnings during cljs reload.
(re-frame-log/set-loggers!
Expand Down Expand Up @@ -142,8 +143,18 @@
(socket-command ["signals"]))))

(k/reg-event-fx ::load
(fn [_ [folder log-folder]]
(socket-command ["load" folder (or log-folder "")])))
(fn [{:keys [db]} [folder log-folder]]
(let [paths (distinct (conj (:prev-paths db) folder))]
(storage/set-item! "cse-paths" (pr-str paths))
(merge
{:db (assoc db :prev-paths paths)}
(socket-command ["load" folder (or log-folder "")])))))

(k/reg-event-fx ::delete-prev
(fn [{:keys [db]} [path]]
(let [paths (remove #(= path %) (:prev-paths db))]
(storage/set-item! "cse-paths" (pr-str paths))
{:db (assoc db :prev-paths paths)})))

(k/reg-event-fx ::teardown
(fn [_ _]
Expand Down
9 changes: 7 additions & 2 deletions src/cse_client/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
[re-frame.core :as rf]
[cse-client.view :as view]
[cse-client.controller :as controller]
[cse-client.config :refer [socket-url]]))
[cse-client.config :refer [socket-url]]
[cljs.reader :as reader]
[cse-client.localstorage :as storage]))

(enable-console-print!)

Expand Down Expand Up @@ -63,6 +65,8 @@
(rf/reg-sub :overview status-data)
(rf/reg-sub :time simulation-time)
(rf/reg-sub :loaded? (comp :loaded :state))
(rf/reg-sub :prev-paths (fn [db]
(:prev-paths db)))
(rf/reg-sub :status (comp :status :state))
(rf/reg-sub :realtime? (comp :isRealTime :state))

Expand Down Expand Up @@ -124,4 +128,5 @@
:initial-db {:trend-range 10
:active-guide-tab "About"
:page 1
:vars-per-page 20}})
:vars-per-page 20
:prev-paths (reader/read-string (storage/get-item "cse-paths"))}})
17 changes: 17 additions & 0 deletions src/cse_client/localstorage.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns cse-client.localstorage
(:require [oops.core :refer [ocall oget]]))

(def local-storage
(oget js/window "localStorage"))

(defn set-item!
[key val]
(ocall local-storage "setItem" key val))

(defn get-item
[key]
(ocall local-storage "getItem" key))

(defn remove-item!
[key]
(ocall local-storage "removeItem" key))
17 changes: 16 additions & 1 deletion src/cse_client/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@

(defn index-page []
(let [loaded? (rf/subscribe [:loaded?])
prev-paths (rf/subscribe [:prev-paths])
load-dir (r/atom default-load-dir)
log-dir (r/atom default-log-dir)]
(fn []
Expand Down Expand Up @@ -250,7 +251,21 @@
[:div.two.column.row
[:div.column
[:button.ui.button.right.floated {:disabled (empty? @load-dir)
:on-click #(rf/dispatch [::controller/load @load-dir @log-dir])} "Load simulation"]]]]))))
:on-click #(rf/dispatch [::controller/load @load-dir @log-dir])} "Load simulation"]]]
[:div.two.column.row
[:div.column
[:h3 "Previously used configurations"]
[:div.ui.relaxed.divided.list
(map (fn [path]
[:div.item {:key path}
[:i.large.folder.open.middle.aligned.icon]
[:div.content
[:a.header {:on-click #(reset! load-dir path)}
path]
[:div.description
[:a.right.floated {:on-click #(rf/dispatch [::controller/delete-prev path])}
[:i.delete.icon]]]]])
@prev-paths)]]]]))))

(defn root-comp []
(let [socket-state (rf/subscribe [:kee-frame.websocket/state socket-url])
Expand Down

0 comments on commit 54aab1e

Please sign in to comment.