Skip to content

Commit

Permalink
#103 Show the user that an erroneous state has been reached. (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
eidekrist authored Oct 21, 2019
1 parent 700372a commit 73603e5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 30 deletions.
4 changes: 4 additions & 0 deletions src/cse_client/controller.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,7 @@
(k/reg-event-fx ::abort-scenario
(fn [_ [file-name]]
(socket-command ["abort-scenario" file-name])))

(k/reg-event-db ::toggle-dismiss-error
(fn [db]
(update db :error-dismissed not)))
14 changes: 11 additions & 3 deletions src/cse_client/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
(rf/reg-sub :pages
(fn [db]
(let [page-count (:page-count db)
all-pages (range 1 (inc page-count))]
all-pages (range 1 (inc page-count))]
all-pages)))

(rf/reg-sub :module-signals (fn [db]
Expand Down Expand Up @@ -136,8 +136,8 @@
(rf/reg-sub :show-success-feedback-messages :show-success-feedback-messages)

(defn validate-event [db event]
(let [module-tree (-> db :state :module-data :fmus)
model-valid? (->> module-tree (map :name) (filter #(= (:model event) %)) seq boolean)
(let [module-tree (-> db :state :module-data :fmus)
model-valid? (->> module-tree (map :name) (filter #(= (:model event) %)) seq boolean)
variable-valid? (some->> module-tree
(filter #(= (:model event) (:name %)))
first
Expand Down Expand Up @@ -207,6 +207,13 @@
(= gui-type type)
(= value-reference valueReference))) manip-vars)))))

(rf/reg-sub :error (fn [db]
(when (-> db :state :executionState (= "CSE_EXECUTION_ERROR"))
{:last-error-code (-> db :state :lastErrorCode)
:last-error-message (-> db :state :lastErrorMessage)})))

(rf/reg-sub :error-dismissed #(:error-dismissed %))

(k/start! {:routes routes
:hash-routing? true
:debug? (if debug {:blacklist #{::controller/socket-message-received}} false)
Expand All @@ -216,3 +223,4 @@
:vars-per-page 20
:prev-paths (reader/read-string (storage/get-item "cse-paths"))
:show-success-feedback-messages (reader/read-string (storage/get-item "show-success-feedback-message"))}})

70 changes: 43 additions & 27 deletions src/cse_client/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

"scatter" (when (xy-plottable? type)
(let [label-text (trend/plot-type-from-label label)
axis (if (even? count) 'X 'Y)]
axis (if (even? count) 'X 'Y)]
(semantic/ui-dropdown-item
{:key (str "trend-item-" id)
:text label-text
Expand All @@ -54,8 +54,8 @@
(map (partial trend-item current-module name causality type value-reference) trend-info)))))

(defn pages-menu []
(let [current-page @(rf/subscribe [:current-page])
pages @(rf/subscribe [:pages])
(let [current-page @(rf/subscribe [:current-page])
pages @(rf/subscribe [:pages])
vars-per-page @(rf/subscribe [:vars-per-page])]
[:div.right.menu
[:div.item
Expand Down Expand Up @@ -85,11 +85,11 @@
[:button.ui.button {:on-click #(rf/dispatch [::controller/set-vars-per-page (+ vars-per-page 5)])} [:i.plus.icon] 5]]]]]]]))

(defn tab-content [tabby]
(let [current-module @(rf/subscribe [:current-module])
(let [current-module @(rf/subscribe [:current-module])
current-module-index @(rf/subscribe [:current-module-index])
module-signals @(rf/subscribe [:module-signals])
active @(rf/subscribe [:active-causality])
trend-info @(rf/subscribe [:trend-info])]
module-signals @(rf/subscribe [:module-signals])
active @(rf/subscribe [:active-causality])
trend-info @(rf/subscribe [:trend-info])]
[:div.ui.bottom.attached.tab.segment {:data-tab tabby
:class (when (= tabby active) "active")}
[:table.ui.compact.single.line.striped.selectable.table
Expand All @@ -109,8 +109,8 @@
module-signals)]]]))

(defn module-listing []
(let [causalities @(rf/subscribe [:causalities])
active @(rf/subscribe [:active-causality])
(let [causalities @(rf/subscribe [:causalities])
active @(rf/subscribe [:active-causality])
module-active? @(rf/subscribe [:module-active?])
current-module @(rf/subscribe [:current-module])]
(if module-active?
Expand All @@ -136,14 +136,14 @@
(if simulation-has-loaded? "Simulation status" "Simulation setup"))

(defn sidebar []
(let [module-routes @(rf/subscribe [:module-routes])
route @(rf/subscribe [:kee-frame/route])
route-name (-> route :data :name)
route-module (-> route :path-params :module)
loaded? @(rf/subscribe [:loaded?])
trend-info @(rf/subscribe [:trend-info])
(let [module-routes @(rf/subscribe [:module-routes])
route @(rf/subscribe [:kee-frame/route])
route-name (-> route :data :name)
route-module (-> route :path-params :module)
loaded? @(rf/subscribe [:loaded?])
trend-info @(rf/subscribe [:trend-info])
active-trend-index @(rf/subscribe [:active-trend-index])
scenarios @(rf/subscribe [:scenarios])]
scenarios @(rf/subscribe [:scenarios])]
[:div.ui.secondary.vertical.fluid.menu
[:div.item
[:a.header {:href (k/path-for [:index])
Expand Down Expand Up @@ -254,10 +254,10 @@
[:tr [:td "Simulation execution"] [:td [teardown-button]]]]]])

(defn index-page []
(let [loaded? (rf/subscribe [:loaded?])
(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)]
load-dir (r/atom default-load-dir)
log-dir (r/atom default-log-dir)]
(fn []
(if @loaded?
[dashboard]
Expand Down Expand Up @@ -306,20 +306,24 @@
[:span.additional (str "scenario data from ") file-name]]))

(defn root-comp []
(let [socket-state (rf/subscribe [:kee-frame.websocket/state socket-url])
loaded? (rf/subscribe [:loaded?])
status (rf/subscribe [:status])
module (rf/subscribe [:current-module])
trends @(rf/subscribe [:trend-info])
(let [socket-state (rf/subscribe [:kee-frame.websocket/state socket-url])
loaded? (rf/subscribe [:loaded?])
status (rf/subscribe [:status])
module (rf/subscribe [:current-module])
trends @(rf/subscribe [:trend-info])
active-trend-index @(rf/subscribe [:active-trend-index])
scenario-name @(rf/subscribe [:scenario-id])]
scenario-name @(rf/subscribe [:scenario-id])
error (rf/subscribe [:error])
error-dismissed (rf/subscribe [:error-dismissed])]
[:div
[:div.ui.inverted.huge.borderless.fixed.menu
[:a.header.item {:href "/"} "Core Simulation Environment - demo application"]
[:div.right.menu
(when (= :disconnected (:state @socket-state))
[:div.item
[:div "Lost server connection!"]])
(when @error
[:a.item {:on-click #(rf/dispatch [::controller/toggle-dismiss-error])} "Error!"])
(when @loaded?
[:div.item
[:div "RTF: " @(rf/subscribe [:real-time-factor])]])
Expand Down Expand Up @@ -366,13 +370,25 @@
:scenarios [scenario/overview]
:scenario [scenario/one]
nil [:div "Loading..."]]]]]]]
(when (not= :connected (:state @socket-state))
(if (not= :connected (:state @socket-state))
[:div.ui.page.dimmer.transition.active
{:style {:display :flex}}
[:div.content
[:div.center
[:h2.ui.inverted.icon.header
[:i.heartbeat.icon]
"Lost server connection!"]
[:div.sub.header "It looks like the server is down. Try restarting the server and hit F5"]]]])
[:div.sub.header "It looks like the server is down. Try restarting the server and hit F5"]]]]
(when (and @error (not @error-dismissed))
[:div.ui.page.dimmer.transition.active
{:style {:display :flex}}
[:div.content
[:div.center
[:h2.ui.inverted.icon.header
[:i.red.bug.icon]
"An error occured!"]
[:h3 (str "Last error code: " (:last-error-code @error))]
[:h3 (str "Last error message: " (:last-error-message @error))]
[:h4 "The simulation can no longer continue. Please restart the application."]
[:button.ui.button.inverted {:on-click #(rf/dispatch [::controller/toggle-dismiss-error])} "Dismiss"]]]]))
[command-feedback-message]]))

0 comments on commit 73603e5

Please sign in to comment.