Sibucs commited on
Commit
67f0b4c
·
verified ·
1 Parent(s): 2a706e7

Pubblicato da GitHub: 6021e00

Browse files
Files changed (1) hide show
  1. app.py +112 -16
app.py CHANGED
@@ -2471,6 +2471,60 @@ def guided_intro_view(state: dict[str, Any]):
2471
  )
2472
 
2473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2474
  def questionnaire_panel_view(state: dict[str, Any]):
2475
  """Show the mandatory form only after the recommended route is complete."""
2476
  participant_id = str(state.get("participant_id", ""))
@@ -3158,14 +3212,17 @@ def pause_session_and_choose_scale(state: dict[str, Any]):
3158
  str(session.get("activity", "")),
3159
  str(session.get("scale", "")),
3160
  )
3161
- if path == GUIDED_STAGES[0].path:
3162
- # The introductory QCER scale deliberately has no free-exploration
3163
- # card. Return to the catalog, where its route can be resumed.
 
 
 
3164
  _, schema, modality, _, _ = _first_path_values()
3165
  navigation = _navigation_selection(schema, modality)
3166
  navigation = (
3167
  *navigation[:-1],
3168
- "Tappa introduttiva messa in pausa. I tentativi restano salvati: "
3169
  "usa «Percorso consigliato» per riprenderla.",
3170
  )
3171
  elif all(path):
@@ -3189,8 +3246,8 @@ def pause_session_and_choose_scale(state: dict[str, Any]):
3189
  navigation = _navigation_selection(*_first_path_values()[1:3])
3190
  return (
3191
  updated,
3192
- gr.update(visible=path == GUIDED_STAGES[0].path),
3193
- gr.update(visible=path != GUIDED_STAGES[0].path),
3194
  gr.update(visible=False),
3195
  gr.update(visible=False),
3196
  *navigation,
@@ -3629,8 +3686,9 @@ def build_demo() -> gr.Blocks:
3629
  variant="primary",
3630
  )
3631
  explore_other_scales_button = gr.Button(
3632
- "Esplora tutte le altre scale",
3633
  variant="secondary",
 
3634
  elem_classes="alternate-path-button",
3635
  )
3636
  with gr.Group(visible=False) as optional_catalog:
@@ -3664,13 +3722,14 @@ def build_demo() -> gr.Blocks:
3664
  "Continua con questo ambito", variant="primary"
3665
  )
3666
  close_other_scales_button = gr.Button("Chiudi le altre scale")
3667
- with gr.Accordion("Riprendi una sessione", open=False):
3668
- resume_choice = gr.Dropdown(
3669
- choices=[],
3670
- label="Sessione da riprendere",
3671
- interactive=False,
3672
- )
3673
- resume_button = gr.Button("Riprendi")
 
3674
  taxonomy_logout_button = gr.Button("Cambia nome")
3675
  gr.HTML(
3676
  '<nav class="page-links" aria-label="Altre pagine">'
@@ -4057,6 +4116,14 @@ def build_demo() -> gr.Blocks:
4057
  questionnaire_success_group,
4058
  questionnaire_message,
4059
  ],
 
 
 
 
 
 
 
 
4060
  )
4061
 
4062
  identify_button.click(
@@ -4090,6 +4157,14 @@ def build_demo() -> gr.Blocks:
4090
  questionnaire_success_group,
4091
  questionnaire_message,
4092
  ],
 
 
 
 
 
 
 
 
4093
  )
4094
  guided_intro_button.click(
4095
  guided_intro_view,
@@ -4269,6 +4344,10 @@ def build_demo() -> gr.Blocks:
4269
  summary_navigation_group,
4270
  questionnaire_message,
4271
  ],
 
 
 
 
4272
  )
4273
  leave_exercise_button.click(
4274
  open_exercise_exit_confirmation,
@@ -4349,8 +4428,13 @@ def build_demo() -> gr.Blocks:
4349
  user_message,
4350
  ],
4351
  ).then(
4352
- lambda: gr.update(visible=True),
4353
- outputs=optional_catalog,
 
 
 
 
 
4354
  )
4355
  next_block_button.click(
4356
  continue_with_next_block,
@@ -4384,6 +4468,10 @@ def build_demo() -> gr.Blocks:
4384
  questionnaire_message,
4385
  summary_navigation_group,
4386
  ],
 
 
 
 
4387
  )
4388
  questionnaire_finish_button.click(
4389
  finish_questionnaire,
@@ -4396,6 +4484,14 @@ def build_demo() -> gr.Blocks:
4396
  taxonomy_group,
4397
  user_message,
4398
  ],
 
 
 
 
 
 
 
 
4399
  )
4400
 
4401
  def bind_logout(button):
 
2471
  )
2472
 
2473
 
2474
+ def _optional_exploration_status(
2475
+ state: dict[str, Any],
2476
+ ) -> tuple[bool, str]:
2477
+ participant_id = str(state.get("participant_id", ""))
2478
+ if not participant_id:
2479
+ return False, "Disponibile dopo il percorso consigliato"
2480
+ try:
2481
+ events = STORE.list_events(participant_id)
2482
+ progress = guided_progress(events)
2483
+ except EventStoreError:
2484
+ return False, "Esplorazione temporaneamente non disponibile"
2485
+ if progress["next_index"] is not None:
2486
+ return False, "Disponibile dopo il percorso consigliato"
2487
+ if not questionnaire_is_submitted(events):
2488
+ return False, "Disponibile dopo il questionario finale"
2489
+ return True, "Esplora tutte le altre scale"
2490
+
2491
+
2492
+ def optional_exploration_access_view(state: dict[str, Any]):
2493
+ """Keep the alternative catalogue visible but locked until the pilot ends."""
2494
+ unlocked, label = _optional_exploration_status(state)
2495
+ return (
2496
+ gr.Button(
2497
+ label,
2498
+ visible=True,
2499
+ interactive=unlocked,
2500
+ variant="secondary",
2501
+ ),
2502
+ gr.update(visible=False),
2503
+ gr.update(visible=unlocked),
2504
+ )
2505
+
2506
+
2507
+ def summary_exploration_buttons_view(state: dict[str, Any]):
2508
+ unlocked, _ = _optional_exploration_status(state)
2509
+ return (
2510
+ gr.Button(
2511
+ "Scegli un’altra scala"
2512
+ if unlocked
2513
+ else "Altre scale disponibili dopo il percorso",
2514
+ visible=True,
2515
+ interactive=unlocked,
2516
+ variant="primary" if unlocked else "secondary",
2517
+ ),
2518
+ gr.Button(
2519
+ "Cambia ambito"
2520
+ if unlocked
2521
+ else "Torna al percorso consigliato",
2522
+ visible=True,
2523
+ interactive=True,
2524
+ ),
2525
+ )
2526
+
2527
+
2528
  def questionnaire_panel_view(state: dict[str, Any]):
2529
  """Show the mandatory form only after the recommended route is complete."""
2530
  participant_id = str(state.get("participant_id", ""))
 
3212
  str(session.get("activity", "")),
3213
  str(session.get("scale", "")),
3214
  )
3215
+ is_guided_session = session.get("progression_phase") in {
3216
+ stage.phase for stage in GUIDED_STAGES
3217
+ }
3218
+ if is_guided_session:
3219
+ # Every recommended stage resumes through its own route. Returning to
3220
+ # the free scale page here would bypass the pilot sequence.
3221
  _, schema, modality, _, _ = _first_path_values()
3222
  navigation = _navigation_selection(schema, modality)
3223
  navigation = (
3224
  *navigation[:-1],
3225
+ "Tappa consigliata messa in pausa. I tentativi restano salvati: "
3226
  "usa «Percorso consigliato» per riprenderla.",
3227
  )
3228
  elif all(path):
 
3246
  navigation = _navigation_selection(*_first_path_values()[1:3])
3247
  return (
3248
  updated,
3249
+ gr.update(visible=is_guided_session),
3250
+ gr.update(visible=not is_guided_session),
3251
  gr.update(visible=False),
3252
  gr.update(visible=False),
3253
  *navigation,
 
3686
  variant="primary",
3687
  )
3688
  explore_other_scales_button = gr.Button(
3689
+ "Disponibile dopo il percorso consigliato",
3690
  variant="secondary",
3691
+ interactive=False,
3692
  elem_classes="alternate-path-button",
3693
  )
3694
  with gr.Group(visible=False) as optional_catalog:
 
3722
  "Continua con questo ambito", variant="primary"
3723
  )
3724
  close_other_scales_button = gr.Button("Chiudi le altre scale")
3725
+ with gr.Group(visible=False) as resume_sessions_group:
3726
+ with gr.Accordion("Riprendi una sessione", open=False):
3727
+ resume_choice = gr.Dropdown(
3728
+ choices=[],
3729
+ label="Sessione da riprendere",
3730
+ interactive=False,
3731
+ )
3732
+ resume_button = gr.Button("Riprendi")
3733
  taxonomy_logout_button = gr.Button("Cambia nome")
3734
  gr.HTML(
3735
  '<nav class="page-links" aria-label="Altre pagine">'
 
4116
  questionnaire_success_group,
4117
  questionnaire_message,
4118
  ],
4119
+ ).then(
4120
+ optional_exploration_access_view,
4121
+ inputs=ui_state,
4122
+ outputs=[
4123
+ explore_other_scales_button,
4124
+ optional_catalog,
4125
+ resume_sessions_group,
4126
+ ],
4127
  )
4128
 
4129
  identify_button.click(
 
4157
  questionnaire_success_group,
4158
  questionnaire_message,
4159
  ],
4160
+ ).then(
4161
+ optional_exploration_access_view,
4162
+ inputs=ui_state,
4163
+ outputs=[
4164
+ explore_other_scales_button,
4165
+ optional_catalog,
4166
+ resume_sessions_group,
4167
+ ],
4168
  )
4169
  guided_intro_button.click(
4170
  guided_intro_view,
 
4344
  summary_navigation_group,
4345
  questionnaire_message,
4346
  ],
4347
+ ).then(
4348
+ summary_exploration_buttons_view,
4349
+ inputs=ui_state,
4350
+ outputs=[dashboard_button, summary_taxonomy_button],
4351
  )
4352
  leave_exercise_button.click(
4353
  open_exercise_exit_confirmation,
 
4428
  user_message,
4429
  ],
4430
  ).then(
4431
+ optional_exploration_access_view,
4432
+ inputs=ui_state,
4433
+ outputs=[
4434
+ explore_other_scales_button,
4435
+ optional_catalog,
4436
+ resume_sessions_group,
4437
+ ],
4438
  )
4439
  next_block_button.click(
4440
  continue_with_next_block,
 
4468
  questionnaire_message,
4469
  summary_navigation_group,
4470
  ],
4471
+ ).then(
4472
+ summary_exploration_buttons_view,
4473
+ inputs=ui_state,
4474
+ outputs=[dashboard_button, summary_taxonomy_button],
4475
  )
4476
  questionnaire_finish_button.click(
4477
  finish_questionnaire,
 
4484
  taxonomy_group,
4485
  user_message,
4486
  ],
4487
+ ).then(
4488
+ optional_exploration_access_view,
4489
+ inputs=ui_state,
4490
+ outputs=[
4491
+ explore_other_scales_button,
4492
+ optional_catalog,
4493
+ resume_sessions_group,
4494
+ ],
4495
  )
4496
 
4497
  def bind_logout(button):