Files
HC_APTBS/ViewModels/AuthGateViewModel.cs
LucianoDev 0280a2fad1 feat: page-based navigation shell + Tests page wizard
Replace the monolithic MainWindow with a SelectedPage-driven shell
(Dashboard / Pump / Bench / Tests / Results / Settings). The Tests
page gets the Plan -> Preconditions -> Running -> Done wizard from
ui-structure.md \u00a74, backed by a 7-item precondition gate and
shared sub-views (PhaseCardView / TestSectionView / GraphicIndicatorView)
extracted from the now-deleted monolithic TestPanelView.

New VMs / views:
- Tests wizard: TestPreconditions, PhaseCard, GraphicIndicator,
  TestSection, TestPlan, TestRunning, TestDone
- Dashboard panels: DashboardConnection, DashboardReadings,
  DashboardAlarms, InterlockBanner, ResultHistory
- Pump / bench panels: PumpIdentificationPanel, PumpLiveData,
  UnlockPanel, BenchDriveControl, BenchReadings, RelayBank,
  TemperatureControl, DtcList, AuthGate
- Dialogs: generic ConfirmDialog, UserManageDialog, UserPromptDialog

Supporting changes:
- IsOilPumpOn exposed on MainViewModel for precondition evaluation
- RequiresAuth added to TestDefinition (XML round-trip)
- BipStatusDefinition + CompletedTestRun models
- ~35 new Test.* localization keys (en + es)
- Settings moved from modal dialog to full page
- Pause / Retry / Skip stubs in TestRunningView; full spec in
  docs/gap-test-running-controls.md for follow-up implementation
- docs/ui-structure.md captures the wizard design

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-18 13:11:34 +02:00

69 lines
2.8 KiB
C#

using System;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using HC_APTBS.Services;
using HC_APTBS.ViewModels.Dialogs;
using HC_APTBS.Views.Dialogs;
namespace HC_APTBS.ViewModels
{
/// <summary>
/// ViewModel for the <c>AuthGateView</c> wrapper control that hides write-capable
/// content behind an operator authentication dialog.
///
/// <para>Used by the Pump page on the Adaptation and Unlock sub-sections per
/// <c>docs/ui-structure.md</c> §3.d/§3.e (write actions require authentication).</para>
/// </summary>
public sealed partial class AuthGateViewModel : ObservableObject
{
private readonly IConfigurationService _config;
private readonly ILocalizationService _loc;
/// <summary>Initialises the gate; starts in the locked state.</summary>
public AuthGateViewModel(IConfigurationService config, ILocalizationService loc)
{
_config = config;
_loc = loc;
}
// ── State ─────────────────────────────────────────────────────────────────
/// <summary>True once the operator has successfully authenticated.</summary>
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(AuthenticateCommand))]
[NotifyCanExecuteChangedFor(nameof(LockCommand))]
private bool _isAuthenticated;
/// <summary>The currently authenticated username (empty when locked).</summary>
[ObservableProperty] private string _authenticatedUser = string.Empty;
// ── Commands ──────────────────────────────────────────────────────────────
/// <summary>Opens the UserCheck dialog; flips to authenticated on success.</summary>
[RelayCommand(CanExecute = nameof(CanAuthenticate))]
private void Authenticate()
{
var vm = new UserCheckViewModel(_config, _loc, AuthenticatedUser);
var dlg = new UserCheckDialog(vm) { Owner = Application.Current.MainWindow };
dlg.ShowDialog();
if (!vm.Accepted) return;
AuthenticatedUser = vm.AuthenticatedUser;
IsAuthenticated = true;
}
private bool CanAuthenticate() => !IsAuthenticated;
/// <summary>Re-locks the gate (e.g. after finishing a sensitive operation).</summary>
[RelayCommand(CanExecute = nameof(CanLock))]
private void Lock()
{
IsAuthenticated = false;
AuthenticatedUser = string.Empty;
}
private bool CanLock() => IsAuthenticated;
}
}