Add functional simulation question review

This commit is contained in:
hz
2026-07-14 17:49:23 -05:00
parent 3e39a4ffce
commit 705f079997
13 changed files with 551 additions and 32 deletions
+49
View File
@@ -14,6 +14,8 @@ var retry_button: Button
var simulation_button: Button
var simulation_status_label: Label
var simulation_preview_link: LinkButton
var completed_history_list: VBoxContainer
var completed_history_more: Button
var pending_simulation_launch := false
var current_stage := "exam"
var pending_question_bank_launch := false
@@ -35,6 +37,8 @@ func _ready() -> void:
ExamSimulationService.request_failed.connect(_on_simulation_failed)
if not AuthState.auth_changed.is_connected(_refresh_simulation_preview_visibility):
AuthState.auth_changed.connect(_refresh_simulation_preview_visibility)
if not ExamSimulationService.completed_history_changed.is_connected(_refresh_completed_history):
ExamSimulationService.completed_history_changed.connect(_refresh_completed_history)
_build_exam_view()
_build_mode_view()
@@ -49,6 +53,7 @@ func on_show(payload: Variant = null) -> void:
_refresh_bank_state()
_refresh_simulation_preview_visibility()
ExamSimulationService.load_readiness()
ExamSimulationService.load_completed_history()
func on_hide() -> void:
@@ -174,6 +179,26 @@ func _build_mode_view() -> void:
mode_view.add_child(simulation_preview_link)
_refresh_simulation_preview_visibility()
var history_heading := Label.new()
history_heading.text = "Completed simulations"
Style.set_label(history_heading, 20, Style.TEXT)
mode_view.add_child(history_heading)
completed_history_list = VBoxContainer.new()
completed_history_list.add_theme_constant_override("separation", 6)
completed_history_list.size_flags_horizontal = Control.SIZE_EXPAND_FILL
var history_scroll := ScrollContainer.new()
history_scroll.custom_minimum_size = Vector2(0, 150)
history_scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
history_scroll.add_child(completed_history_list)
mode_view.add_child(history_scroll)
completed_history_more = Button.new()
completed_history_more.text = "Load more"
completed_history_more.visible = false
completed_history_more.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
Style.style_chip(completed_history_more, Style.CYAN)
completed_history_more.pressed.connect(func(): ExamSimulationService.load_completed_history(ExamSimulationService.completed_history_next_before))
mode_view.add_child(completed_history_more)
bank_status_label = Label.new()
bank_status_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
Style.set_label(bank_status_label, 16, Style.CYAN)
@@ -269,6 +294,30 @@ func _refresh_simulation_preview_visibility() -> void:
simulation_preview_link.visible = AuthState.role.to_upper() == "SUPER"
func _refresh_completed_history() -> void:
if completed_history_list == null:
return
for child in completed_history_list.get_children():
child.queue_free()
for raw_summary in ExamSimulationService.completed_history:
var summary: Dictionary = raw_summary
var button := Button.new()
button.text = "%s | Predicted %d (%d-%d) | %d/%d correct" % [
str(summary.get("completedUtc", "")).left(10), int(summary.get("predictedScore", 0)),
int(summary.get("rangeLow", 0)), int(summary.get("rangeHigh", 0)),
int(summary.get("correct", 0)), int(summary.get("total", 0))]
button.alignment = HORIZONTAL_ALIGNMENT_LEFT
Style.style_chip(button, Style.CYAN)
button.pressed.connect(_open_completed_simulation.bind(str(summary.get("id", ""))))
completed_history_list.add_child(button)
completed_history_more.visible = not ExamSimulationService.completed_history_next_before.is_empty()
func _open_completed_simulation(simulation_id: String) -> void:
pending_simulation_launch = true
ExamSimulationService.load_simulation(simulation_id)
func _on_simulation_state_changed() -> void:
_refresh_simulation_state()
if not pending_simulation_launch or ExamSimulationService.simulation.is_empty():