diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..728bf55 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Created by .ignore support plugin (hsz.mobi) + +.idea + +target \ No newline at end of file diff --git a/project.clj b/project.clj index d02d409..cfe7cf9 100644 --- a/project.clj +++ b/project.clj @@ -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"] diff --git a/src/cse_client/controller.cljs b/src/cse_client/controller.cljs index 7754b70..d196d88 100644 --- a/src/cse_client/controller.cljs +++ b/src/cse_client/controller.cljs @@ -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]})]})) diff --git a/src/cse_client/core.cljs b/src/cse_client/core.cljs index 485ad24..d9f5723 100644 --- a/src/cse_client/core.cljs +++ b/src/cse_client/core.cljs @@ -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 diff --git a/src/cse_client/view.cljs b/src/cse_client/view.cljs index 1f090be..816e6cd 100644 --- a/src/cse_client/view.cljs +++ b/src/cse_client/view.cljs @@ -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 @@ -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])