feat: move test buttons to right panel, add user auth dialog for reports
Move Start/Stop/Report buttons from the middle panel to the top of TestPanelView (automated tests section), matching the old application layout. Remove inline Operator/Client text fields — operator identity now comes from a UserCheckDialog (username/password) shown before the existing ReportDialog. Add credential storage to ConfigurationService. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
81
ViewModels/Dialogs/UserCheckViewModel.cs
Normal file
81
ViewModels/Dialogs/UserCheckViewModel.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using HC_APTBS.Services;
|
||||
|
||||
namespace HC_APTBS.ViewModels.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// ViewModel for the user authentication dialog shown before report generation.
|
||||
/// Validates operator credentials against the stored user list.
|
||||
/// </summary>
|
||||
public sealed partial class UserCheckViewModel : ObservableObject
|
||||
{
|
||||
private readonly IConfigurationService _config;
|
||||
|
||||
/// <summary>Initialises the dialog, optionally pre-filling the last used username.</summary>
|
||||
public UserCheckViewModel(IConfigurationService config, string lastUsername = "")
|
||||
{
|
||||
_config = config;
|
||||
_username = lastUsername;
|
||||
}
|
||||
|
||||
// ── Bindable properties ───────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Username entered by the operator.</summary>
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
|
||||
private string _username = string.Empty;
|
||||
|
||||
/// <summary>Password entered by the operator (set from code-behind PasswordChanged handler).</summary>
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
|
||||
private string _password = string.Empty;
|
||||
|
||||
// ── Dialog result ─────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>True if the user authenticated successfully.</summary>
|
||||
public bool Accepted { get; private set; }
|
||||
|
||||
/// <summary>The validated username, available after <see cref="Accepted"/> is true.</summary>
|
||||
public string AuthenticatedUser { get; private set; } = string.Empty;
|
||||
|
||||
// ── Commands ──────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Validates credentials and closes the dialog on success.</summary>
|
||||
[RelayCommand(CanExecute = nameof(CanAccept))]
|
||||
private void Accept()
|
||||
{
|
||||
if (_config.ValidateUser(Username, Password))
|
||||
{
|
||||
AuthenticatedUser = Username;
|
||||
Accepted = true;
|
||||
RequestClose?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Invalid username or password.\n(Both are case-sensitive.)",
|
||||
"Authentication Error",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Stop);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanAccept() => !string.IsNullOrWhiteSpace(Username)
|
||||
&& !string.IsNullOrEmpty(Password);
|
||||
|
||||
/// <summary>Cancels authentication and closes the dialog.</summary>
|
||||
[RelayCommand]
|
||||
private void Cancel()
|
||||
{
|
||||
Accepted = false;
|
||||
RequestClose?.Invoke();
|
||||
}
|
||||
|
||||
// ── Events ────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Raised when the dialog should close itself.</summary>
|
||||
public event System.Action? RequestClose;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user