diff --git a/libcosim/libcosim.go b/libcosim/libcosim.go index c1765c1..14f5a35 100644 --- a/libcosim/libcosim.go +++ b/libcosim/libcosim.go @@ -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" @@ -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" diff --git a/src/client/controller.cljs b/src/client/controller.cljs index 8dc7ee6..da1bfcb 100644 --- a/src/client/controller.cljs +++ b/src/client/controller.cljs @@ -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))] diff --git a/src/client/view.cljs b/src/client/view.cljs index 70a6f8b..ba453b2 100644 --- a/src/client/view.cljs +++ b/src/client/view.cljs @@ -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