Skip to content

Commit 21a2d51

Browse files
committed
feat(dashboard) relaunch button added
1 parent bf2796c commit 21a2d51

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

nebula/frontend/app.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ async def startup_event():
190190

191191
nodes_registration = {}
192192

193+
scenarios_list = []
194+
193195
scenarios_list_length = 0
194196

195197
scenarios_finished = 0
@@ -807,6 +809,28 @@ def remove_scenario(scenario_name=None):
807809
ScenarioManagement.remove_files_by_scenario(scenario_name)
808810

809811

812+
@app.get("/nebula/dashboard/{scenario_name}/relaunch")
813+
async def nebula_relaunch_scenario(scenario_name: str, request: Request, session: dict = Depends(get_session)):
814+
global scenarios_list, scenarios_list_length
815+
816+
if "user" in session:
817+
if session["role"] == "demo":
818+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
819+
elif session["role"] == "user":
820+
if not check_scenario_with_role(session["role"], scenario_name):
821+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
822+
823+
scenario_path = Utils.check_path(settings.config_dir, os.path.join(scenario_name, "scenario.json"))
824+
with open(scenario_path) as scenario_file:
825+
scenario = json.load(scenario_file)
826+
827+
scenarios_list.append(scenario)
828+
scenarios_list_length = scenarios_list_length + 1
829+
return RedirectResponse(url="/nebula/dashboard")
830+
else:
831+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
832+
833+
810834
@app.get("/nebula/dashboard/{scenario_name}/remove")
811835
async def nebula_remove_scenario(scenario_name: str, request: Request, session: dict = Depends(get_session)):
812836
if "user" in session:
@@ -1238,8 +1262,9 @@ async def run_scenario(scenario_data, role):
12381262

12391263
# Deploy the list of scenarios
12401264
async def run_scenarios(data, role):
1241-
global scenarios_finished
1242-
for scenario_data in data:
1265+
global scenarios_finished, scenarios_list
1266+
scenarios_list = data
1267+
for scenario_data in scenarios_list:
12431268
finish_scenario_event.clear()
12441269
logging.info(f"Running scenario {scenario_data['scenario_title']}")
12451270
scenario_name = await run_scenario(scenario_data, role)

nebula/frontend/templates/dashboard.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ <h3>Scenarios in the database</h3>
158158
<a href="{{ url_for('nebula_stop_scenario', scenario_name='all', stop_all=True) }}"
159159
class="label btn btn-danger">Stop scenario queue</a>
160160
{% else %}
161+
<a id="relaunch-btn" data-scenario-name="{{ name }}" data-scenario-title="{{ title }}" class="label btn btn-dark"><i
162+
class="fa fa-rotate-right" style="color: white;"></i></a>
161163
<a id="remove-btn" data-scenario-name="{{ name }}" class="label btn btn-danger"><i
162164
class="fa fa-trash"></i></a>
163165
{% endif %}
@@ -205,6 +207,35 @@ <h3>Scenarios in the database</h3>
205207
}, 10000);
206208
</script>
207209

210+
<script>
211+
$(document).on('click', '#relaunch-btn', function () {
212+
var scenario_name = $(this).data('scenario-name');
213+
var scenario_title = $(this).data('scenario-title');
214+
$('#confirm-modal').modal('show');
215+
$('#confirm-modal .modal-title').text('Relaunch scenario');
216+
$('#confirm-modal #confirm-modal-body').html('Are you sure you want to relaunch the scenario ' + scenario_title + '?');
217+
218+
$('#confirm-modal #yes-button').off('click').on('click', function () {
219+
const response = fetch('/nebula/dashboard/' + scenario_name + '/relaunch', {
220+
method: 'GET'
221+
})
222+
.then(response => {
223+
console.log(response)
224+
if (response.redirected) {
225+
window.location.href = response.url; // Manually redirect to the URL provided by the server
226+
} else {
227+
$('#confirm-modal').modal('hide');
228+
$('#confirm-modal').on('hidden.bs.modal', function () {
229+
$('#info-modal-body').html('You are not allowed to relaunch a scenario with demo role.');
230+
$('#info-modal').modal('show');
231+
});
232+
}
233+
})
234+
.catch(error => console.error('Error:', error));
235+
});
236+
});
237+
</script>
238+
208239
<script>
209240
$(document).on('click', '#remove-btn', function () {
210241
var scenario_name = $(this).data('scenario-name');

0 commit comments

Comments
 (0)