Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added reset button (that navigates to index and sends a command to reset the simulation)
added "reset" command on server-go (command will stop, terminate and initialize a simulation)
  • Loading branch information
Ćésar Carvalho committed May 26, 2020
1 parent d4ea766 commit acabd2a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
37 changes: 37 additions & 0 deletions libcosim/libcosim.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,30 @@ func initializeSimulation(sim *Simulation, status *structs.SimulationStatus, con
return true, "Simulation loaded successfully", config.configDir
}

func resetSimulation(sim *Simulation, status *structs.SimulationStatus, configPath string, logDir string) (bool, string, string) {
var success = false
var message = ""
var configDir = ""

success, message = executionStop(sim.Execution)
log.Println(message)

if success{
status.Loaded = false
status.Status = "stopped"
status.ConfigDir = ""
status.Trends = []structs.Trend{}
status.Module = ""
success, message = simulationTeardown(sim)
log.Println(message)
}

success, message, configDir = initializeSimulation(sim, status, configPath, logDir)
log.Println(message)

return success, message, configDir
}

func executeCommand(cmd []string, sim *Simulation, status *structs.SimulationStatus) (shorty structs.ShortLivedData, feedback structs.CommandFeedback) {
var success = false
var message = "No feedback implemented for this command"
Expand All @@ -670,6 +694,19 @@ func executeCommand(cmd []string, sim *Simulation, status *structs.SimulationSta
status.Module = ""
success, message = simulationTeardown(sim)
shorty.ModuleData = sim.MetaData
case "reset":
status.Loading = true
var configDir string
success, message, configDir = resetSimulation(sim, status, cmd[1], cmd[2])
if success {
status.Loaded = true
status.ConfigDir = configDir
status.Status = "pause"
shorty.ModuleData = sim.MetaData
scenarios := findScenarios(status)
shorty.Scenarios = &scenarios
}
status.Loading = false
case "pause":
success, message = executionStop(sim.Execution)
status.Status = "pause"
Expand Down
5 changes: 5 additions & 0 deletions src/client/controller.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@
(merge {:db (assoc db :prev-paths paths :plot-config-changed? false :log-dir (or log-folder ""))}
(socket-command ["load" folder (or log-folder "")])))))

(k/reg-event-fx ::reset
(fn [{:keys [db]} [folder log-folder]]
(merge {:navigate-to [:index]}
(socket-command ["reset" folder (or log-folder "")]))))

(k/reg-event-fx ::delete-prev
(fn [{:keys [db]} [path]]
(let [paths (remove #(= path %) (:prev-paths db))]
Expand Down
2 changes: 1 addition & 1 deletion src/client/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
(when (and @loaded? (= @status "play"))
[:a.item {:on-click #(rf/dispatch [::controller/pause])} "Pause"])
(when @loaded?
[:a.item {:on-click #(rf/dispatch [::controller/load @load-dir @log-dir])} "Reset"])
[:a.item {:on-click #(rf/dispatch [::controller/reset @load-dir @log-dir])} "Reset"])
[:div.ui.simple.dropdown.item
[:i.question.circle.icon]
[:div.menu
Expand Down

0 comments on commit acabd2a

Please sign in to comment.