Skip to content

Commit

Permalink
Feature/8 variable metadata (#9)
Browse files Browse the repository at this point in the history
* #8 Group variables by causality

* #8 Display variable type
  • Loading branch information
eidekrist authored Oct 9, 2018
1 parent 97b175a commit c90fbed
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Created by .ignore support plugin (hsz.mobi)

.idea

target
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(defproject cse-client "1.0-SNAPSHOT"
:min-lein-version "2.0.0"
:dependencies [[kee-frame "0.2.8-SNAPSHOT"]
:dependencies [[kee-frame "0.3.0-SNAPSHOT"]
[reagent "0.8.1"]
[re-frame "0.10.6" :exclusions [reagent]]
[cljsjs/highstock "6.0.7-0"]
Expand Down
4 changes: 4 additions & 0 deletions src/cse_client/controller.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
:connections-loaded? (boolean (:connections db))}
config))

(k/reg-event-db ::causality-enter
(fn [db [causality]]
(assoc db :active-causality causality)))

(k/reg-event-fx ::module-enter
(fn [{:keys [db]} [module]]
{:dispatch [::websocket/send socket-url (ws-request db {:command ["module" module]})]}))
Expand Down
26 changes: 25 additions & 1 deletion src/cse_client/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,33 @@
["/modules/:module" :module]
["/trend/:module/:signal" :trend]])

(defn causalities [db]
(some->> db
:state
:module
:signals
(map :causality)
distinct))

(defn active-causality [db]
(or ((set (causalities db)) (:active-causality db))
(-> db
causalities
first)))

(rf/reg-sub :module (comp :module :state))
(rf/reg-sub :modules (comp :modules :state))

(rf/reg-sub :causalities causalities)
(rf/reg-sub :active-causality active-causality)
(rf/reg-sub :signals (fn [db]
(some->> db
:state
:module
:signals
(filter (fn [signal]
(= (active-causality db)
(:causality signal))))
(sort-by :name))))

(k/start! {:routes routes
:hash-routing? true
Expand Down
30 changes: 24 additions & 6 deletions src/cse_client/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
[cse-client.dp :as dp]
[cse-client.config :refer [socket-url]]))

(defn module-listing []
(let [{:keys [signals] :as module} @(rf/subscribe [:module])]
[:div
(defn tab-content [tabby]
(let [module @(rf/subscribe [:module])
signals @(rf/subscribe [:signals])
active @(rf/subscribe [:active-causality])]
[:div.ui.bottom.attached.tab.segment {:data-tab tabby
:class (when (= tabby active) "active")}
[:table.ui.single.line.striped.selectable.table
[:thead
[:tr
Expand All @@ -17,14 +20,29 @@
[:th "Value"]
[:th "..."]]]
[:tbody
(map (fn [{:keys [name value]}]
[:tr {:key (str "signal-" name)}
(map (fn [{:keys [name value causality type]}]
[:tr {:key (str causality "-" name)}
[:td name]
[:td "scalar"]
[:td type]
[:td value]
[:td [:a {:href (k/path-for [:trend {:module (:name module) :signal name}])} "Trend"]]])
signals)]]]))

(defn module-listing []
(let [causalities @(rf/subscribe [:causalities])
active @(rf/subscribe [:active-causality])]
[:div
[:div.ui.top.attached.tabular.menu
(for [causality causalities]
^{:key (str "tab-" causality)}
[:a.item {:data-tab causality
:class (when (= causality active) "active")
:on-click #(rf/dispatch [::controller/causality-enter causality])}
causality])]
(for [causality causalities]
^{:key (str "tab-content-" causality)}
[tab-content causality])]))

(defn sidebar []
(let [modules @(rf/subscribe [:modules])
route @(rf/subscribe [:kee-frame/route])
Expand Down

0 comments on commit c90fbed

Please sign in to comment.