Skip to content

Commit

Permalink
WIP Implement components for dashboard
Browse files Browse the repository at this point in the history
Add subscription for stats.uptime

Complete functional implementation for the dashboard UI
  • Loading branch information
kaffein committed Jun 10, 2020
1 parent 1aea3fc commit 91da706
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
53 changes: 41 additions & 12 deletions src/dashboard/components/dashboard.cljs
Original file line number Diff line number Diff line change
@@ -1,24 +1,53 @@
(ns dashboard.components.dashboard
(:require [reagent.core :as r]
[re-frame.core :as rf]
[reagent.dom :as rdom]
[taoensso.timbre :as log
:refer-macros [log trace debug info warn error fatal report
logf tracef debugf infof warnf errorf fatalf reportf
spy get-env]]
["bloomer" :refer (Tile Hero HeroBody Title Subtitle Notification)]
["react-router-dom" :refer (NavLink)]
[dashboard.components.search :refer [search]]))
[dashboard.components.search :refer [search]]
[dashboard.subs.dashboard]))

(defn stat-display
[label value]
[:> Tile {:is-child "true" :class "box"}
[:> Title @value]
[:> Subtitle label]])

(defn expandable-stat-display
[label value path]
[:> NavLink {:class "tile is-parent is-4" :to path}
[stat-display label value]])

(defn dashboard
[]
[:div
[:> Hero {:isbold "true" :iscolor "true" :issize "small"}
[:> HeroBody
[:> Title "Dashboard"]
[:> Subtitle "Uptime"]]]
[:div.tiles
[:> Tile {:isancestor "true" :hastextalign "centered"}
[:> NavLink {:class "tile is-parent is-4" :to "/adapters"}
[:> Tile {:ischild "true" :class "box"}
[:> Title "stats.adapter_count"]
[:> Subtitle "Adapters"]]]]]])
(let [_ (rf/dispatch [:dashboard.stats/fetch 120])
adapter-count (rf/subscribe [:dashboard.stats/adapter-count])
command-count (rf/subscribe [:dashboard.stats/command-count])
command-count-today (rf/subscribe [:dashboard.stats/command-count-today])
user-count (rf/subscribe [:dashboard.stats/user-count])
history-count (rf/subscribe [:dashboard.stats/history-count])
history-count-today (rf/subscribe [:dashboard.stats/history-count-today])
alias-count (rf/subscribe [:dashboard.stats/alias-count])
observer-count (rf/subscribe [:dashboard.stats/observer-count])
cront-count (rf/subscribe [:dashboard.stats/cron-count])
uptime (rf/subscribe [:dashboard.stats/uptime])]
[:div
[:> Hero {:is-bold "true" :is-color "info" :is-size "small"}
[:> HeroBody
[:> Title "Dashboard"]
[:> Subtitle (str "Uptime " @uptime)]]]
[:div.tiles
[:> Tile {:is-ancestor "true" :has-text-align "centered"}
[expandable-stat-display "Adapters" adapter-count "/adapters"]
[expandable-stat-display "Commands" command-count "/history?co=1"]
[stat-display "Commands today" command-count-today]
[expandable-stat-display "User" user-count "/users"]
[expandable-stat-display "History items" history-count "/history"]
[stat-display "History items today" history-count-today]
[expandable-stat-display "Aliases" alias-count "/aliases"]
[expandable-stat-display "Observers" observer-count "/observers"]
[expandable-stat-display "Cron tasks" cront-count "/cron"]]]]))
5 changes: 5 additions & 0 deletions src/dashboard/subs/dashboard.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
(ns dashboard.subs.dashboard
(:require [re-frame.core :as rf]))

(rf/reg-sub
:dashboard.stats/uptime
(fn [db _]
(get-in db [:dashboard/stats :uptime])))

(rf/reg-sub
:dashboard.stats/adapter-count
(fn [db _]
Expand Down

0 comments on commit 91da706

Please sign in to comment.