Skip to content

Commit 72aaee1

Browse files
committed
feat(dashboard): show scenario configuration in config-btn
1 parent e3ca9d3 commit 72aaee1

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

nebula/frontend/app.py

+20
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,26 @@ async def get_notes_for_scenario(scenario_name: str):
284284
return JSONResponse({"status": "error", "message": "Notes not found for the specified scenario"})
285285

286286

287+
@app.get("/nebula/dashboard/{scenario_name}/config")
288+
async def get_config_for_scenario(scenario_name: str):
289+
json_path = os.path.join(os.environ.get("NEBULA_CONFIG_DIR"), scenario_name, "scenario.json")
290+
logging.info(f"[FER] json_path: {json_path}")
291+
292+
try:
293+
with open(json_path) as file:
294+
scenarios_data = json.load(file)
295+
296+
if scenarios_data:
297+
return JSONResponse({"status": "success", "config": scenarios_data})
298+
else:
299+
return JSONResponse({"status": "error", "message": "Configuration not found for the specified scenario"})
300+
301+
except FileNotFoundError:
302+
return JSONResponse({"status": "error", "message": "scenario.json file not found"})
303+
except json.JSONDecodeError:
304+
return JSONResponse({"status": "error", "message": "Error decoding JSON file"})
305+
306+
287307
@app.post("/nebula/login")
288308
async def nebula_login(
289309
request: Request,

nebula/frontend/templates/dashboard.html

+39
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ <h3>Scenarios in the database</h3>
147147
class="label btn btn-dark">Real-time metrics</a>
148148
<a id="note-btn-{{ name }}" data-scenario-name="{{ name }}" class="label btn btn-dark"><i
149149
class="fa fa-sticky-note" style="color: white;"></i></a>
150+
<a id="config-btn-{{ name }}" data-scenario-name="{{ name }}" class="label btn btn-dark"><i
151+
class="fa fa-sliders" style="color: white;"></i></a>
150152
{% if status == "running" %}
151153
<a href="{{ url_for('nebula_stop_scenario', scenario_name=name, stop_all=False) }}"
152154
class="label btn btn-danger">Stop scenario</a>
@@ -169,6 +171,12 @@ <h3>Scenarios in the database</h3>
169171
class="btn btn-dark mt-2 save-note-btn" style="float: right;">Save</button>
170172
</td>
171173
</tr>
174+
<tr id="config-row-{{ name }}" class="config-row" style="display: none;">
175+
<td colspan="4">
176+
<textarea id="config-text-{{ name }}" class="form-control" rows="20"
177+
style="font-size: small; width: 100%;"></textarea>
178+
</td>
179+
</tr>
172180
{% endfor %}
173181
</table>
174182
</div>
@@ -238,6 +246,12 @@ <h3>Scenarios in the database</h3>
238246
saveNotes(this.dataset.scenarioName);
239247
});
240248
});
249+
250+
document.querySelectorAll('[id^=config-btn]').forEach(button => {
251+
button.addEventListener('click', function () {
252+
toggleConfigRow(this.dataset.scenarioName);
253+
});
254+
});
241255
});
242256

243257
async function toggleNotesRow(scenarioName) {
@@ -265,6 +279,31 @@ <h3>Scenarios in the database</h3>
265279
notesRow.style.display = notesRow.style.display === 'none' ? '' : 'none';
266280
}
267281

282+
async function toggleConfigRow(scenarioName) {
283+
const configRow = document.getElementById('config-row-' + scenarioName);
284+
const configTextElement = document.getElementById('config-text-' + scenarioName);
285+
286+
if (configRow.style.display === 'none') {
287+
try {
288+
const response = await fetch(`/nebula/dashboard/${scenarioName}/config`);
289+
const data = await response.json();
290+
291+
console.log("[FER] ", data.config)
292+
293+
if (data.status === 'success') {
294+
configTextElement.value = JSON.stringify(data.config, null, 2);
295+
} else {
296+
configTextElement.value = 'No configuration available.';
297+
}
298+
} catch (error) {
299+
console.error('Error:', error);
300+
alert('An error occurred while retrieving the configuration.');
301+
return;
302+
}
303+
}
304+
configRow.style.display = configRow.style.display === 'none' ? '' : 'none';
305+
}
306+
268307
async function saveNotes(scenarioName) {
269308
const notesText = document.getElementById('notes-text-' + scenarioName).value;
270309

0 commit comments

Comments
 (0)