postit: persist settings save and apply ApiUrl changes without restart #51

Merged
notazof merged 25 commits from feat/estimate into main 2026-09-06 21:05:58 +01:00
14 changed files with 165 additions and 198 deletions
Showing only changes of commit e881de05aa - Show all commits

postit: replace inferred status severity with explicit setters

Paul Schneider 2026-09-06 15:45:24 +01:00
Signed by: notazof
GPG key ID: 1DD5D838E5343B06

View file

@ -0,0 +1,32 @@
namespace PostIt.ViewModels;
public interface IActionStatusViewModel
{
string StatusMessage { get; set; }
StatusNotice ActionStatus { get; set; }
}
public static class ActionStatusViewModelExtensions
{
public static void SetInfoStatus(this IActionStatusViewModel viewModel, string message)
=> viewModel.SetStatus(message, StatusSeverity.Info);
public static void SetWarningStatus(this IActionStatusViewModel viewModel, string message)
=> viewModel.SetStatus(message, StatusSeverity.Warning);
public static void SetErrorStatus(this IActionStatusViewModel viewModel, string message)
=> viewModel.SetStatus(message, StatusSeverity.Error);
public static void SetStatus(this IActionStatusViewModel viewModel, string message, StatusSeverity severity)
{
var normalizedMessage = string.IsNullOrWhiteSpace(message) ? "Pret." : message.Trim();
viewModel.StatusMessage = normalizedMessage;
viewModel.ActionStatus = severity switch
{
StatusSeverity.Error => StatusNotice.Error(normalizedMessage),
StatusSeverity.Warning => StatusNotice.Warning(normalizedMessage),
_ => StatusNotice.Info(normalizedMessage),
};
}
}

View file

@ -13,7 +13,7 @@ using Yavsc.Api.Client;
namespace PostIt.ViewModels; namespace PostIt.ViewModels;
public partial class ActivitiesPageViewModel : ViewModelBase public partial class ActivitiesPageViewModel : ViewModelBase, IActionStatusViewModel
{ {
private readonly ActivityApiClient _client; private readonly ActivityApiClient _client;
private readonly BillingApiClient _billingClient; private readonly BillingApiClient _billingClient;
@ -46,11 +46,6 @@ public partial class ActivitiesPageViewModel : ViewModelBase
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Choisissez une activité."); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Choisissez une activité.");
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
public ActivityInfo? CurrentActivity => SelectedSpecialization ?? SelectedActivity; public ActivityInfo? CurrentActivity => SelectedSpecialization ?? SelectedActivity;
public string SelectedActivityLabel => SelectedActivity?.Name ?? "(aucune activité)"; public string SelectedActivityLabel => SelectedActivity?.Name ?? "(aucune activité)";
public string CurrentActivityLabel => CurrentActivity?.Name ?? "(aucune)"; public string CurrentActivityLabel => CurrentActivity?.Name ?? "(aucune)";
@ -94,11 +89,11 @@ public partial class ActivitiesPageViewModel : ViewModelBase
} }
catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
StatusMessage = "Accès refusé pour les activités (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé pour les activités (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
} }
@ -110,11 +105,11 @@ public partial class ActivitiesPageViewModel : ViewModelBase
} }
catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
StatusMessage = "Accès refusé pour les activités (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé pour les activités (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
} }
@ -131,7 +126,7 @@ public partial class ActivitiesPageViewModel : ViewModelBase
await ShowActivityAsync(first); await ShowActivityAsync(first);
if (first is null) if (first is null)
{ {
StatusMessage = "Aucune activité disponible."; this.SetInfoStatus("Aucune activité disponible.");
} }
} }
catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
@ -139,14 +134,14 @@ public partial class ActivitiesPageViewModel : ViewModelBase
Activities = new ObservableCollection<ActivityInfo>(); Activities = new ObservableCollection<ActivityInfo>();
Specializations = new ObservableCollection<ActivityInfo>(); Specializations = new ObservableCollection<ActivityInfo>();
Performers = new ObservableCollection<ActivityUserDisplayItem>(); Performers = new ObservableCollection<ActivityUserDisplayItem>();
StatusMessage = "Accès refusé pour les activités (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé pour les activités (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
Activities = new ObservableCollection<ActivityInfo>(); Activities = new ObservableCollection<ActivityInfo>();
Specializations = new ObservableCollection<ActivityInfo>(); Specializations = new ObservableCollection<ActivityInfo>();
Performers = new ObservableCollection<ActivityUserDisplayItem>(); Performers = new ObservableCollection<ActivityUserDisplayItem>();
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -238,19 +233,19 @@ public partial class ActivitiesPageViewModel : ViewModelBase
Performers = new ObservableCollection<ActivityUserDisplayItem>(items); Performers = new ObservableCollection<ActivityUserDisplayItem>(items);
SelectedPerformer = null; SelectedPerformer = null;
StatusMessage = $"{activity.Name} · {Performers.Count} utilisateur(s)"; this.SetInfoStatus($"{activity.Name} · {Performers.Count} utilisateur(s)");
} }
catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
Performers = new ObservableCollection<ActivityUserDisplayItem>(); Performers = new ObservableCollection<ActivityUserDisplayItem>();
SelectedPerformer = null; SelectedPerformer = null;
StatusMessage = "Accès refusé pour les activités (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé pour les activités (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
Performers = new ObservableCollection<ActivityUserDisplayItem>(); Performers = new ObservableCollection<ActivityUserDisplayItem>();
SelectedPerformer = null; SelectedPerformer = null;
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -267,7 +262,7 @@ public partial class ActivitiesPageViewModel : ViewModelBase
{ {
if (SelectedPerformer is null || CurrentActivity is null) if (SelectedPerformer is null || CurrentActivity is null)
{ {
StatusMessage = "Sélectionnez un utilisateur et une activité avec formulaire."; this.SetWarningStatus("Sélectionnez un utilisateur et une activité avec formulaire.");
return; return;
} }

View file

@ -29,7 +29,7 @@ namespace PostIt.ViewModels;
/// <c>CirclesPage</c> then calls /// <c>CirclesPage</c> then calls
/// <see cref="CircleApiClient.AddMemberAsync"/>.</para> /// <see cref="CircleApiClient.AddMemberAsync"/>.</para>
/// </summary> /// </summary>
public partial class AddCircleMemberDialogViewModel : ViewModelBase public partial class AddCircleMemberDialogViewModel : ViewModelBase, IActionStatusViewModel
{ {
private readonly IUserDirectory _directory; private readonly IUserDirectory _directory;
@ -46,15 +46,10 @@ public partial class AddCircleMemberDialogViewModel : ViewModelBase
public partial bool IsBusy { get; set; } public partial bool IsBusy { get; set; }
[ObservableProperty] [ObservableProperty]
public partial string StatusMessage { get; set; } = string.Empty; public partial string StatusMessage { get; set; } = "Pret.";
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.FromMessage(string.Empty); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Pret.");
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
/// <summary> /// <summary>
/// Raised when the user confirms a selection. The hosting /// Raised when the user confirms a selection. The hosting
@ -87,7 +82,7 @@ public partial class AddCircleMemberDialogViewModel : ViewModelBase
if (string.IsNullOrWhiteSpace(SearchQuery)) if (string.IsNullOrWhiteSpace(SearchQuery))
{ {
Results.Clear(); Results.Clear();
StatusMessage = "Tapez un nom ou un email"; this.SetWarningStatus("Tapez un nom ou un email");
return; return;
} }
@ -96,11 +91,11 @@ public partial class AddCircleMemberDialogViewModel : ViewModelBase
{ {
var hits = await _directory.SearchAsync(SearchQuery, CancellationToken.None).ConfigureAwait(true); var hits = await _directory.SearchAsync(SearchQuery, CancellationToken.None).ConfigureAwait(true);
Results = new ObservableCollection<UserSummary>(hits ?? Array.Empty<UserSummary>()); Results = new ObservableCollection<UserSummary>(hits ?? Array.Empty<UserSummary>());
StatusMessage = $"{Results.Count} résultat(s)"; this.SetInfoStatus($"{Results.Count} résultat(s)");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -118,7 +113,7 @@ public partial class AddCircleMemberDialogViewModel : ViewModelBase
{ {
if (Selected is null) if (Selected is null)
{ {
StatusMessage = "Sélectionnez un utilisateur"; this.SetWarningStatus("Sélectionnez un utilisateur");
return; return;
} }
Confirmed?.Invoke(this, Selected); Confirmed?.Invoke(this, Selected);

View file

@ -14,7 +14,7 @@ using Yavsc.Abstract.Workflow;
namespace PostIt.ViewModels; namespace PostIt.ViewModels;
public partial class BillingQueriesPageViewModel : ViewModelBase public partial class BillingQueriesPageViewModel : ViewModelBase, IActionStatusViewModel
{ {
private readonly BillingApiClient _billingClient; private readonly BillingApiClient _billingClient;
@ -37,12 +37,7 @@ public partial class BillingQueriesPageViewModel : ViewModelBase
public partial string StatusMessage { get; set; } = "Chargement des commandes..."; public partial string StatusMessage { get; set; } = "Chargement des commandes...";
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.FromMessage("Chargement des commandes..."); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Chargement des commandes...");
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
public string Title => IsReadOnly public string Title => IsReadOnly
? $"Demandes en cours ({Form.Title})" ? $"Demandes en cours ({Form.Title})"
@ -98,17 +93,17 @@ public partial class BillingQueriesPageViewModel : ViewModelBase
.ToList(); .ToList();
Queries = new ObservableCollection<BillingQueryDisplayItem>(filtered); Queries = new ObservableCollection<BillingQueryDisplayItem>(filtered);
StatusMessage = BuildLoadedStatusMessage(filtered.Count); this.SetInfoStatus(BuildLoadedStatusMessage(filtered.Count));
} }
catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
Queries = new ObservableCollection<BillingQueryDisplayItem>(); Queries = new ObservableCollection<BillingQueryDisplayItem>();
StatusMessage = "Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
Queries = new ObservableCollection<BillingQueryDisplayItem>(); Queries = new ObservableCollection<BillingQueryDisplayItem>();
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -121,13 +116,13 @@ public partial class BillingQueriesPageViewModel : ViewModelBase
{ {
if (IsReadOnly) if (IsReadOnly)
{ {
StatusMessage = "Mode lecture seule: l'ouverture en modification est désactivée."; this.SetWarningStatus("Mode lecture seule: l'ouverture en modification est désactivée.");
return; return;
} }
if (SelectedQuery is null) if (SelectedQuery is null)
{ {
StatusMessage = "Sélectionnez une commande."; this.SetWarningStatus("Sélectionnez une commande.");
return; return;
} }
@ -147,11 +142,11 @@ public partial class BillingQueriesPageViewModel : ViewModelBase
} }
catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
StatusMessage = "Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur lors de l'ouverture: {ex.Message}"; this.SetErrorStatus($"Erreur lors de l'ouverture: {ex.Message}");
} }
finally finally
{ {

View file

@ -34,7 +34,7 @@ namespace PostIt.ViewModels;
/// <see cref="OnAddMemberConfirmedAsync"/>. The "remove" /// <see cref="OnAddMemberConfirmedAsync"/>. The "remove"
/// command is per-row and runs inline.</para> /// command is per-row and runs inline.</para>
/// </summary> /// </summary>
public partial class CirclesPageViewModel : ViewModelBase public partial class CirclesPageViewModel : ViewModelBase, IActionStatusViewModel
{ {
private readonly CircleApiClient _client; private readonly CircleApiClient _client;
@ -63,17 +63,11 @@ public partial class CirclesPageViewModel : ViewModelBase
public partial bool IsBusy { get; set; } public partial bool IsBusy { get; set; }
[ObservableProperty] [ObservableProperty]
public partial string StatusMessage { get; set; } = string.Empty; public partial string StatusMessage { get; set; } = "Pret.";
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Pret."); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Pret.");
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
public CirclesPageViewModel(CircleApiClient client) public CirclesPageViewModel(CircleApiClient client)
{ {
_client = client ?? throw new ArgumentNullException(nameof(client)); _client = client ?? throw new ArgumentNullException(nameof(client));
@ -108,11 +102,11 @@ public partial class CirclesPageViewModel : ViewModelBase
{ {
var list = await _client.GetMyCirclesAsync(); var list = await _client.GetMyCirclesAsync();
Circles = new ObservableCollection<CircleDto>(list ?? new()); Circles = new ObservableCollection<CircleDto>(list ?? new());
StatusMessage = $"{Circles.Count} cercle(s)"; this.SetInfoStatus($"{Circles.Count} cercle(s)");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -157,11 +151,11 @@ public partial class CirclesPageViewModel : ViewModelBase
{ {
var list = await _client.GetMembersAsync(circleId); var list = await _client.GetMembersAsync(circleId);
Members = new ObservableCollection<CircleMemberDto>(list ?? new()); Members = new ObservableCollection<CircleMemberDto>(list ?? new());
StatusMessage = $"{Members.Count} membre(s)"; this.SetInfoStatus($"{Members.Count} membre(s)");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
Members = new ObservableCollection<CircleMemberDto>(); Members = new ObservableCollection<CircleMemberDto>();
} }
finally finally
@ -176,7 +170,7 @@ public partial class CirclesPageViewModel : ViewModelBase
SelectedCircle = null; SelectedCircle = null;
DraftName = string.Empty; DraftName = string.Empty;
DraftPublic = false; DraftPublic = false;
StatusMessage = "Nouveau cercle"; this.SetInfoStatus("Nouveau cercle");
} }
[RelayCommand] [RelayCommand]
@ -186,7 +180,7 @@ public partial class CirclesPageViewModel : ViewModelBase
SelectedCircle = circle; SelectedCircle = circle;
DraftName = circle.Name; DraftName = circle.Name;
DraftPublic = circle.Public; DraftPublic = circle.Public;
StatusMessage = $"Édition de « {circle.Name} »"; this.SetInfoStatus($"Édition de « {circle.Name} »");
} }
[RelayCommand] [RelayCommand]
@ -194,7 +188,7 @@ public partial class CirclesPageViewModel : ViewModelBase
{ {
if (string.IsNullOrWhiteSpace(DraftName)) if (string.IsNullOrWhiteSpace(DraftName))
{ {
StatusMessage = "Le nom est obligatoire"; this.SetWarningStatus("Le nom est obligatoire");
return; return;
} }
@ -208,22 +202,22 @@ public partial class CirclesPageViewModel : ViewModelBase
Name = DraftName.Trim(), Name = DraftName.Trim(),
Public = DraftPublic, Public = DraftPublic,
}); });
StatusMessage = created is null this.SetStatus(
? "Création échouée" created is null ? "Création échouée" : $"Cercle « {created.Name} » créé",
: $"Cercle « {created.Name} » créé"; created is null ? StatusSeverity.Warning : StatusSeverity.Info);
} }
else else
{ {
SelectedCircle.Name = DraftName.Trim(); SelectedCircle.Name = DraftName.Trim();
SelectedCircle.Public = DraftPublic; SelectedCircle.Public = DraftPublic;
await _client.UpdateCircleAsync(SelectedCircle.Id, SelectedCircle); await _client.UpdateCircleAsync(SelectedCircle.Id, SelectedCircle);
StatusMessage = $"Cercle « {SelectedCircle.Name} » mis à jour"; this.SetInfoStatus($"Cercle « {SelectedCircle.Name} » mis à jour");
} }
await RefreshAsync(); await RefreshAsync();
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -239,7 +233,7 @@ public partial class CirclesPageViewModel : ViewModelBase
try try
{ {
await _client.DeleteCircleAsync(circle.Id); await _client.DeleteCircleAsync(circle.Id);
StatusMessage = $"Cercle « {circle.Name} » supprimé"; this.SetInfoStatus($"Cercle « {circle.Name} » supprimé");
// If the deleted circle was the selected one, // If the deleted circle was the selected one,
// clear the selection so the Members view goes // clear the selection so the Members view goes
// empty too (the partial setter on // empty too (the partial setter on
@ -250,7 +244,7 @@ public partial class CirclesPageViewModel : ViewModelBase
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -271,7 +265,7 @@ public partial class CirclesPageViewModel : ViewModelBase
try try
{ {
await _client.AddMemberAsync(SelectedCircle.Id, picked.Id); await _client.AddMemberAsync(SelectedCircle.Id, picked.Id);
StatusMessage = $"« {picked.DisplayName} » ajouté au cercle"; this.SetInfoStatus($"« {picked.DisplayName} » ajouté au cercle");
await LoadMembersAsync(SelectedCircle.Id); await LoadMembersAsync(SelectedCircle.Id);
} }
catch (Exception ex) catch (Exception ex)
@ -286,7 +280,7 @@ public partial class CirclesPageViewModel : ViewModelBase
var msg = ex.Message.Contains("409") || ex.Message.Contains("Conflict") var msg = ex.Message.Contains("409") || ex.Message.Contains("Conflict")
? "Déjà membre du cercle" ? "Déjà membre du cercle"
: $"Erreur: {ex.Message}"; : $"Erreur: {ex.Message}";
StatusMessage = msg; this.SetStatus(msg, msg == "Déjà membre du cercle" ? StatusSeverity.Warning : StatusSeverity.Error);
} }
finally finally
{ {
@ -307,11 +301,11 @@ public partial class CirclesPageViewModel : ViewModelBase
{ {
await _client.RemoveMemberAsync(SelectedCircle.Id, member.Id); await _client.RemoveMemberAsync(SelectedCircle.Id, member.Id);
Members.Remove(member); Members.Remove(member);
StatusMessage = $"« {member.UserName} » retiré du cercle"; this.SetInfoStatus($"« {member.UserName} » retiré du cercle");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {

View file

@ -11,7 +11,7 @@ using Yavsc.Api.Client;
namespace PostIt.ViewModels; namespace PostIt.ViewModels;
public partial class CommandFormsPageViewModel : ViewModelBase public partial class CommandFormsPageViewModel : ViewModelBase, IActionStatusViewModel
{ {
private readonly BillingApiClient _billingClient; private readonly BillingApiClient _billingClient;
@ -25,15 +25,10 @@ public partial class CommandFormsPageViewModel : ViewModelBase
public partial CommandFormSummary? SelectedForm { get; set; } public partial CommandFormSummary? SelectedForm { get; set; }
[ObservableProperty] [ObservableProperty]
public partial string StatusMessage { get; set; } public partial string StatusMessage { get; set; } = "Pret.";
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.FromMessage(string.Empty); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Pret.");
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
public string Title => $"Formulaires pour {Performer.UserName}"; public string Title => $"Formulaires pour {Performer.UserName}";
public string ContextLabel => $"{Activity.Name} · {Forms.Count} formulaire(s)"; public string ContextLabel => $"{Activity.Name} · {Forms.Count} formulaire(s)";
@ -63,9 +58,11 @@ public partial class CommandFormsPageViewModel : ViewModelBase
.OrderBy(f => f.Title) .OrderBy(f => f.Title)
.ThenBy(f => f.ActionName)); .ThenBy(f => f.ActionName));
SelectedForm = Forms.FirstOrDefault(); SelectedForm = Forms.FirstOrDefault();
StatusMessage = Forms.Count == 0 this.SetStatus(
? "Aucun formulaire n'est disponible pour cette activité." Forms.Count == 0
: "Choisissez le formulaire à utiliser."; ? "Aucun formulaire n'est disponible pour cette activité."
: "Choisissez le formulaire à utiliser.",
Forms.Count == 0 ? StatusSeverity.Warning : StatusSeverity.Info);
} }
private bool CanOpenSelectedForm() => SelectedForm is not null; private bool CanOpenSelectedForm() => SelectedForm is not null;
@ -79,7 +76,7 @@ public partial class CommandFormsPageViewModel : ViewModelBase
{ {
if (SelectedForm is null) if (SelectedForm is null)
{ {
StatusMessage = "Sélectionnez un formulaire."; this.SetWarningStatus("Sélectionnez un formulaire.");
return; return;
} }
@ -100,7 +97,7 @@ public partial class CommandFormsPageViewModel : ViewModelBase
{ {
if (SelectedForm is null) if (SelectedForm is null)
{ {
StatusMessage = "Sélectionnez un formulaire."; this.SetWarningStatus("Sélectionnez un formulaire.");
return; return;
} }
@ -120,7 +117,7 @@ public partial class CommandFormsPageViewModel : ViewModelBase
{ {
if (SelectedForm is null) if (SelectedForm is null)
{ {
StatusMessage = "Sélectionnez un formulaire."; this.SetWarningStatus("Sélectionnez un formulaire.");
return; return;
} }

View file

@ -9,7 +9,7 @@ using Yavsc.Models.Billing;
namespace PostIt.ViewModels; namespace PostIt.ViewModels;
public abstract partial class BillingCommandPageViewModel : RemoteViewModelBase public abstract partial class BillingCommandPageViewModel : RemoteViewModelBase, IActionStatusViewModel
{ {
protected readonly BillingApiClient _billingClient; protected readonly BillingApiClient _billingClient;
@ -21,7 +21,7 @@ public abstract partial class BillingCommandPageViewModel : RemoteViewModelBase
public partial bool IsBusy { get; set; } public partial bool IsBusy { get; set; }
[ObservableProperty] [ObservableProperty]
public partial string StatusMessage { get; set; } public partial string StatusMessage { get; set; } = "Pret.";
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Pret."); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Pret.");
@ -78,7 +78,7 @@ public abstract partial class BillingCommandPageViewModel : RemoteViewModelBase
Form = form ?? throw new ArgumentNullException(nameof(form)); Form = form ?? throw new ArgumentNullException(nameof(form));
_billingClient = billingClient ?? throw new ArgumentNullException(nameof(billingClient)); _billingClient = billingClient ?? throw new ArgumentNullException(nameof(billingClient));
StatusMessage = SupportMessage; this.SetInfoStatus(SupportMessage);
} }
partial void OnExistingQueryIdChanged(long? value) partial void OnExistingQueryIdChanged(long? value)
@ -92,11 +92,6 @@ public abstract partial class BillingCommandPageViewModel : RemoteViewModelBase
OnPropertyChanged(nameof(CanUseCurrentLocation)); OnPropertyChanged(nameof(CanUseCurrentLocation));
} }
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
public async Task InitializeAsync(BillingQueryDetailsDto? existingQuery = null) public async Task InitializeAsync(BillingQueryDetailsDto? existingQuery = null)
{ {
await LoadAsync(); await LoadAsync();

View file

@ -58,18 +58,20 @@ public partial class BrushViewModel : RdvViewModel
SelectedPrestation = AvailablePrestations.FirstOrDefault(); SelectedPrestation = AvailablePrestations.FirstOrDefault();
} }
StatusMessage = AvailablePrestations.Count == 0 this.SetStatus(
? "Aucune prestation coiffure disponible." AvailablePrestations.Count == 0
: SupportMessage; ? "Aucune prestation coiffure disponible."
: SupportMessage,
AvailablePrestations.Count == 0 ? StatusSeverity.Warning : StatusSeverity.Info);
} }
catch (HttpRequestException ex) catch (HttpRequestException ex)
when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
StatusMessage = "Accès refusé au catalogue de prestations (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé au catalogue de prestations (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur lors du chargement des prestations: {ex.Message}"; this.SetErrorStatus($"Erreur lors du chargement des prestations: {ex.Message}");
} }
finally finally
{ {
@ -81,19 +83,19 @@ public partial class BrushViewModel : RdvViewModel
{ {
if (!Consent) if (!Consent)
{ {
StatusMessage = "Le consentement est requis pour poster la commande."; this.SetWarningStatus("Le consentement est requis pour poster la commande.");
return; return;
} }
if (string.IsNullOrWhiteSpace(Address)) if (string.IsNullOrWhiteSpace(Address))
{ {
StatusMessage = "L'adresse du rendez-vous est requise."; this.SetWarningStatus("L'adresse du rendez-vous est requise.");
return; return;
} }
if (SelectedPrestation is null) if (SelectedPrestation is null)
{ {
StatusMessage = "Sélectionnez une prestation coiffure."; this.SetWarningStatus("Sélectionnez une prestation coiffure.");
return; return;
} }
@ -143,18 +145,18 @@ public partial class BrushViewModel : RdvViewModel
}).ConfigureAwait(true); }).ConfigureAwait(true);
} }
StatusMessage = IsEditingExisting this.SetInfoStatus(IsEditingExisting
? $"Commande #{ExistingQueryId} mise à jour sur {BillingRoute} pour {Performer.UserName}." ? $"Commande #{ExistingQueryId} mise à jour sur {BillingRoute} pour {Performer.UserName}."
: $"Commande transmise sur {BillingRoute} pour {Performer.UserName}."; : $"Commande transmise sur {BillingRoute} pour {Performer.UserName}.");
} }
catch (HttpRequestException ex) catch (HttpRequestException ex)
when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
StatusMessage = "Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur lors de l'envoi de la commande: {ex.Message}"; this.SetErrorStatus($"Erreur lors de l'envoi de la commande: {ex.Message}");
} }
finally finally
{ {

View file

@ -49,20 +49,20 @@ public partial class MBrushViewModel : BrushViewModel
{ {
if (!Consent) if (!Consent)
{ {
StatusMessage = "Le consentement est requis pour poster la commande."; this.SetWarningStatus("Le consentement est requis pour poster la commande.");
return; return;
} }
if (string.IsNullOrWhiteSpace(Address)) if (string.IsNullOrWhiteSpace(Address))
{ {
StatusMessage = "L'adresse du rendez-vous est requise."; this.SetWarningStatus("L'adresse du rendez-vous est requise.");
return; return;
} }
var selectedPrestations = MultiPrestations.Where(x => x.IsSelected).ToList(); var selectedPrestations = MultiPrestations.Where(x => x.IsSelected).ToList();
if (selectedPrestations.Count == 0) if (selectedPrestations.Count == 0)
{ {
StatusMessage = "Sélectionnez au moins une prestation coiffure."; this.SetWarningStatus("Sélectionnez au moins une prestation coiffure.");
return; return;
} }
@ -109,18 +109,18 @@ public partial class MBrushViewModel : BrushViewModel
}).ConfigureAwait(true); }).ConfigureAwait(true);
} }
StatusMessage = IsEditingExisting this.SetInfoStatus(IsEditingExisting
? $"Commande #{ExistingQueryId} mise à jour sur {BillingRoute} pour {Performer.UserName}." ? $"Commande #{ExistingQueryId} mise à jour sur {BillingRoute} pour {Performer.UserName}."
: $"Commande transmise sur {BillingRoute} pour {Performer.UserName}."; : $"Commande transmise sur {BillingRoute} pour {Performer.UserName}.");
} }
catch (HttpRequestException ex) catch (HttpRequestException ex)
when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
StatusMessage = "Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur lors de l'envoi de la commande: {ex.Message}"; this.SetErrorStatus($"Erreur lors de l'envoi de la commande: {ex.Message}");
} }
finally finally
{ {

View file

@ -54,7 +54,7 @@ public partial class RdvViewModel : BillingCommandPageViewModel
Longitude = existingQuery.Location.Longitude; Longitude = existingQuery.Location.Longitude;
} }
StatusMessage = $"Commande #{existingQuery.Id} chargée."; this.SetInfoStatus($"Commande #{existingQuery.Id} chargée.");
} }
[RelayCommand(CanExecute = nameof(CanUseCurrentLocation))] [RelayCommand(CanExecute = nameof(CanUseCurrentLocation))]
@ -71,23 +71,23 @@ public partial class RdvViewModel : BillingCommandPageViewModel
var result = await Platform.TryGetCurrentLocationAsync(default).ConfigureAwait(true); var result = await Platform.TryGetCurrentLocationAsync(default).ConfigureAwait(true);
if (!result.IsSuccess || !result.Latitude.HasValue || !result.Longitude.HasValue) if (!result.IsSuccess || !result.Latitude.HasValue || !result.Longitude.HasValue)
{ {
StatusMessage = result.Message; this.SetWarningStatus(result.Message);
return; return;
} }
Latitude = result.Latitude.Value; Latitude = result.Latitude.Value;
Longitude = result.Longitude.Value; Longitude = result.Longitude.Value;
StatusMessage = string.IsNullOrWhiteSpace(Address) this.SetInfoStatus(string.IsNullOrWhiteSpace(Address)
? "Position récupérée. Complétez l'adresse puis envoyez la commande." ? "Position récupérée. Complétez l'adresse puis envoyez la commande."
: result.Message; : result.Message);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
StatusMessage = "La récupération de la position a été annulée."; this.SetWarningStatus("La récupération de la position a été annulée.");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Impossible de récupérer la position: {ex.Message}"; this.SetErrorStatus($"Impossible de récupérer la position: {ex.Message}");
} }
finally finally
{ {
@ -118,26 +118,26 @@ public partial class RdvViewModel : BillingCommandPageViewModel
{ {
if (!IsSupported) if (!IsSupported)
{ {
StatusMessage = SupportMessage; this.SetWarningStatus(SupportMessage);
return; return;
} }
if (!Consent) if (!Consent)
{ {
StatusMessage = "Le consentement est requis pour poster la commande."; this.SetWarningStatus("Le consentement est requis pour poster la commande.");
return; return;
} }
if (string.IsNullOrWhiteSpace(Address)) if (string.IsNullOrWhiteSpace(Address))
{ {
StatusMessage = "L'adresse du rendez-vous est requise."; this.SetWarningStatus("L'adresse du rendez-vous est requise.");
return; return;
} }
if (string.IsNullOrWhiteSpace(Reason)) if (string.IsNullOrWhiteSpace(Reason))
{ {
StatusMessage = "Le motif du rendez-vous est requis."; this.SetWarningStatus("Le motif du rendez-vous est requis.");
return; return;
} }
@ -186,17 +186,17 @@ public partial class RdvViewModel : BillingCommandPageViewModel
}).ConfigureAwait(true); }).ConfigureAwait(true);
} }
StatusMessage = IsEditingExisting this.SetInfoStatus(IsEditingExisting
? $"Commande #{ExistingQueryId} mise à jour sur {BillingRoute} pour {Performer.UserName}." ? $"Commande #{ExistingQueryId} mise à jour sur {BillingRoute} pour {Performer.UserName}."
: $"Commande transmise sur {BillingRoute} pour {Performer.UserName}."; : $"Commande transmise sur {BillingRoute} pour {Performer.UserName}.");
} }
catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)
{ {
StatusMessage = "Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous."; this.SetWarningStatus("Accès refusé au billing (scope 'api'). Déconnectez puis reconnectez-vous.");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur lors de l'envoi: {ex.Message}"; this.SetErrorStatus($"Erreur lors de l'envoi: {ex.Message}");
} }
finally finally
{ {

View file

@ -12,7 +12,7 @@ using PostIt.Helpers;
namespace PostIt.ViewModels; namespace PostIt.ViewModels;
public partial class MainViewModel : ViewModelBase public partial class MainViewModel : ViewModelBase, IActionStatusViewModel
{ {
/// <summary>Window/tab title. Cosmetic — bound by /// <summary>Window/tab title. Cosmetic — bound by
/// <c>MainPage.axaml</c> if at all. Not the post title.</summary> /// <c>MainPage.axaml</c> if at all. Not the post title.</summary>
@ -55,16 +55,11 @@ public partial class MainViewModel : ViewModelBase
public partial string StatusMessage { get; set; } public partial string StatusMessage { get; set; }
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.FromMessage(string.Empty); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Pret.");
[ObservableProperty] [ObservableProperty]
public partial string SearchText { get; set; } public partial string SearchText { get; set; }
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
[ObservableProperty] [ObservableProperty]
public partial ObservableCollection<BlogPostDto> Posts { get; set; } public partial ObservableCollection<BlogPostDto> Posts { get; set; }
@ -92,7 +87,7 @@ public partial class MainViewModel : ViewModelBase
Posts.Add(post); Posts.Add(post);
} }
ApplyFilter(); ApplyFilter();
StatusMessage = $"Loaded {Posts.Count} posts."; this.SetInfoStatus($"Loaded {Posts.Count} posts.");
}); });
} }
@ -112,7 +107,7 @@ public partial class MainViewModel : ViewModelBase
// than to send a request the server will reject. // than to send a request the server will reject.
if (string.IsNullOrWhiteSpace(DraftTitle)) if (string.IsNullOrWhiteSpace(DraftTitle))
{ {
StatusMessage = "Title is required."; this.SetWarningStatus("Title is required.");
return; return;
} }
@ -142,7 +137,7 @@ public partial class MainViewModel : ViewModelBase
if (created is not null) if (created is not null)
{ {
SelectedPost = created; SelectedPost = created;
StatusMessage = $"Created post {created.Id}."; this.SetInfoStatus($"Created post {created.Id}.");
} }
} }
else else
@ -158,7 +153,7 @@ public partial class MainViewModel : ViewModelBase
DateModified = DateTime.UtcNow, DateModified = DateTime.UtcNow,
}; };
await BlogClient!.UpdatePostAsync(SelectedPost.Id, update); await BlogClient!.UpdatePostAsync(SelectedPost.Id, update);
StatusMessage = $"Saved post {SelectedPost.Id}."; this.SetInfoStatus($"Saved post {SelectedPost.Id}.");
} }
await RefreshPostsAsync(); await RefreshPostsAsync();
@ -170,14 +165,14 @@ public partial class MainViewModel : ViewModelBase
{ {
if (SelectedPost is null || SelectedPost.Id == 0) if (SelectedPost is null || SelectedPost.Id == 0)
{ {
StatusMessage = "Select an existing post before deleting."; this.SetWarningStatus("Select an existing post before deleting.");
return; return;
} }
await ExecuteAsync(async () => await ExecuteAsync(async () =>
{ {
await BlogClient!.DeletePostAsync(SelectedPost.Id); await BlogClient!.DeletePostAsync(SelectedPost.Id);
StatusMessage = $"Deleted post {SelectedPost.Id}."; this.SetInfoStatus($"Deleted post {SelectedPost.Id}.");
SelectedPost = null; SelectedPost = null;
await RefreshPostsAsync(); await RefreshPostsAsync();
}); });
@ -202,7 +197,7 @@ public partial class MainViewModel : ViewModelBase
{ {
if (SelectedPost is null || SelectedPost.Id == 0) if (SelectedPost is null || SelectedPost.Id == 0)
{ {
StatusMessage = "Sélectionnez un billet existant pour changer sa publication."; this.SetWarningStatus("Sélectionnez un billet existant pour changer sa publication.");
return; return;
} }
@ -219,9 +214,9 @@ public partial class MainViewModel : ViewModelBase
// locally flipped state until the round-trip // locally flipped state until the round-trip
// re-hydrates it. // re-hydrates it.
SelectedPost.IsPublished = publish; SelectedPost.IsPublished = publish;
StatusMessage = publish this.SetInfoStatus(publish
? $"Billet {SelectedPost.Id} publié." ? $"Billet {SelectedPost.Id} publié."
: $"Billet {SelectedPost.Id} remis en brouillon."; : $"Billet {SelectedPost.Id} remis en brouillon.");
}); });
} }
@ -255,7 +250,7 @@ public partial class MainViewModel : ViewModelBase
{ {
if (SelectedPost is null) if (SelectedPost is null)
{ {
StatusMessage = "Select an existing post before managing ACL."; this.SetWarningStatus("Select an existing post before managing ACL.");
return; return;
} }
@ -354,7 +349,7 @@ public partial class MainViewModel : ViewModelBase
FilteredPosts = new ObservableCollection<BlogPostDto>(); FilteredPosts = new ObservableCollection<BlogPostDto>();
SelectedPost = null; SelectedPost = null;
IsBusy = false; IsBusy = false;
StatusMessage = "Ready"; this.SetInfoStatus("Ready");
Settings = settings ?? new Settings(); Settings = settings ?? new Settings();
SearchText = Settings.SearchText; SearchText = Settings.SearchText;
WindowTitle = "PostIt"; WindowTitle = "PostIt";
@ -484,12 +479,12 @@ public partial class MainViewModel : ViewModelBase
try try
{ {
IsBusy = true; IsBusy = true;
StatusMessage = "Working..."; this.SetInfoStatus("Working...");
await action(); await action();
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Error: {ex.Message}"; this.SetErrorStatus($"Error: {ex.Message}");
} }
finally finally
{ {

View file

@ -37,7 +37,7 @@ public sealed class PostAclEntry
/// any 403 / 404 will surface as an exception caught by the /// any 403 / 404 will surface as an exception caught by the
/// command and routed to <see cref="StatusMessage"/>.</para> /// command and routed to <see cref="StatusMessage"/>.</para>
/// </summary> /// </summary>
public partial class PostAclDialogViewModel : ViewModelBase public partial class PostAclDialogViewModel : ViewModelBase, IActionStatusViewModel
{ {
private readonly BlogAclApiClient _aclClient; private readonly BlogAclApiClient _aclClient;
private readonly CircleApiClient _circleClient; private readonly CircleApiClient _circleClient;
@ -61,15 +61,10 @@ public partial class PostAclDialogViewModel : ViewModelBase
public partial bool IsBusy { get; set; } public partial bool IsBusy { get; set; }
[ObservableProperty] [ObservableProperty]
public partial string StatusMessage { get; set; } = string.Empty; public partial string StatusMessage { get; set; } = "Pret.";
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.FromMessage(string.Empty); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Pret.");
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
/// <summary> /// <summary>
/// Idempotency gate for <see cref="LoadAsync"/>: the dialog /// Idempotency gate for <see cref="LoadAsync"/>: the dialog
@ -123,12 +118,12 @@ public partial class PostAclDialogViewModel : ViewModelBase
AclEntries = new ObservableCollection<PostAclEntry>(AclEntries.Select(a => ToAclEntry(a.CircleId))); AclEntries = new ObservableCollection<PostAclEntry>(AclEntries.Select(a => ToAclEntry(a.CircleId)));
StatusMessage = $"{AclEntries.Count} autorisation(s)"; this.SetInfoStatus($"{AclEntries.Count} autorisation(s)");
_loaded = true; _loaded = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -141,7 +136,7 @@ public partial class PostAclDialogViewModel : ViewModelBase
{ {
if (SelectedCircleToAdd is null) if (SelectedCircleToAdd is null)
{ {
StatusMessage = "Sélectionnez un cercle à ajouter"; this.SetWarningStatus("Sélectionnez un cercle à ajouter");
return; return;
} }
@ -150,7 +145,7 @@ public partial class PostAclDialogViewModel : ViewModelBase
{ {
if (AclEntries.Any(a => a.CircleId == SelectedCircleToAdd.Id)) if (AclEntries.Any(a => a.CircleId == SelectedCircleToAdd.Id))
{ {
StatusMessage = $"Cercle « {SelectedCircleToAdd.Name} » déjà autorisé"; this.SetWarningStatus($"Cercle « {SelectedCircleToAdd.Name} » déjà autorisé");
return; return;
} }
@ -162,11 +157,11 @@ public partial class PostAclDialogViewModel : ViewModelBase
if (created is not null) if (created is not null)
{ {
AclEntries.Add(ToAclEntry(created.CircleId)); AclEntries.Add(ToAclEntry(created.CircleId));
StatusMessage = $"Cercle « {SelectedCircleToAdd.Name} » autorisé"; this.SetInfoStatus($"Cercle « {SelectedCircleToAdd.Name} » autorisé");
} }
else else
{ {
StatusMessage = "Autorisation refusée par le serveur"; this.SetWarningStatus("Autorisation refusée par le serveur");
} }
} }
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.Conflict) catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.Conflict)
@ -174,11 +169,11 @@ public partial class PostAclDialogViewModel : ViewModelBase
// Conflict means the link already exists in backend. Resync // Conflict means the link already exists in backend. Resync
// from the dedicated ACL API so the UI reflects server truth. // from the dedicated ACL API so the UI reflects server truth.
await ReloadAclEntriesFromServerAsync(); await ReloadAclEntriesFromServerAsync();
StatusMessage = $"Cercle « {SelectedCircleToAdd.Name} » déjà autorisé"; this.SetWarningStatus($"Cercle « {SelectedCircleToAdd.Name} » déjà autorisé");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {
@ -197,11 +192,11 @@ public partial class PostAclDialogViewModel : ViewModelBase
var existing = AclEntries.FirstOrDefault(e => e.CircleId == acl.CircleId); var existing = AclEntries.FirstOrDefault(e => e.CircleId == acl.CircleId);
if (existing is not null) if (existing is not null)
AclEntries.Remove(existing); AclEntries.Remove(existing);
StatusMessage = "Autorisation révoquée"; this.SetInfoStatus("Autorisation révoquée");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
finally finally
{ {

View file

@ -30,7 +30,7 @@ namespace PostIt.ViewModels;
/// until the Yavsc.Org endpoint exists; the contract there will /// until the Yavsc.Org endpoint exists; the contract there will
/// be <c>POST /api/signature/{devisId}</c> with this same payload. /// be <c>POST /api/signature/{devisId}</c> with this same payload.
/// </summary> /// </summary>
public partial class SignaturePageViewModel : ViewModelBase public partial class SignaturePageViewModel : ViewModelBase, IActionStatusViewModel
{ {
/// <summary> /// <summary>
/// Default capture surface, in DIPs. 3:1 ratio matches a /// Default capture surface, in DIPs. 3:1 ratio matches a
@ -43,12 +43,7 @@ public partial class SignaturePageViewModel : ViewModelBase
public partial string StatusMessage { get; set; } = "Prêt."; public partial string StatusMessage { get; set; } = "Prêt.";
[ObservableProperty] [ObservableProperty]
public partial StatusNotice ActionStatus { get; set; } = StatusNotice.FromMessage("Prêt."); public partial StatusNotice ActionStatus { get; set; } = StatusNotice.Info("Prêt.");
partial void OnStatusMessageChanged(string value)
{
ActionStatus = StatusNotice.FromMessage(value);
}
[ObservableProperty] [ObservableProperty]
public partial int StrokeCount { get; set; } public partial int StrokeCount { get; set; }
@ -115,7 +110,7 @@ public partial class SignaturePageViewModel : ViewModelBase
private void OnStrokeCompleted(object? sender, SignaturePadData data) private void OnStrokeCompleted(object? sender, SignaturePadData data)
{ {
StatusMessage = $"Trait terminé. {data.StrokeCount} trait(s)."; this.SetInfoStatus($"Trait terminé. {data.StrokeCount} trait(s).");
RefreshCounts(); RefreshCounts();
} }
@ -133,7 +128,7 @@ public partial class SignaturePageViewModel : ViewModelBase
public void Clear() public void Clear()
{ {
_control?.Clear(); _control?.Clear();
StatusMessage = "Effacé."; this.SetInfoStatus("Effacé.");
RefreshCounts(); RefreshCounts();
} }
@ -142,14 +137,14 @@ public partial class SignaturePageViewModel : ViewModelBase
{ {
if (_control is null) if (_control is null)
{ {
StatusMessage = "Contrôle non attaché."; this.SetWarningStatus("Contrôle non attaché.");
return; return;
} }
var data = _control.Snapshot(); var data = _control.Snapshot();
if (data.IsEmpty) if (data.IsEmpty)
{ {
StatusMessage = "Rien à capturer."; this.SetWarningStatus("Rien à capturer.");
return; return;
} }
@ -157,11 +152,11 @@ public partial class SignaturePageViewModel : ViewModelBase
{ {
var path = WriteCapture(data); var path = WriteCapture(data);
LastCapturedPath = path; LastCapturedPath = path;
StatusMessage = $"Capture enregistrée: {path}"; this.SetInfoStatus($"Capture enregistrée: {path}");
} }
catch (Exception ex) catch (Exception ex)
{ {
StatusMessage = $"Erreur: {ex.Message}"; this.SetErrorStatus($"Erreur: {ex.Message}");
} }
await Task.CompletedTask; await Task.CompletedTask;
} }

View file

@ -32,27 +32,4 @@ public sealed class StatusNotice
public static StatusNotice Info(string message) => new(message, StatusSeverity.Info); public static StatusNotice Info(string message) => new(message, StatusSeverity.Info);
public static StatusNotice Warning(string message) => new(message, StatusSeverity.Warning); public static StatusNotice Warning(string message) => new(message, StatusSeverity.Warning);
public static StatusNotice Error(string message) => new(message, StatusSeverity.Error); public static StatusNotice Error(string message) => new(message, StatusSeverity.Error);
public static StatusNotice FromMessage(string? message)
{
if (string.IsNullOrWhiteSpace(message))
{
return Info("Pret.");
}
var text = message.Trim();
var lower = text.ToLowerInvariant();
if (lower.StartsWith("erreur") || lower.StartsWith("echec") || lower.StartsWith("impossible"))
{
return Error(text);
}
if (lower.Contains("refuse") || lower.Contains("annule") || lower.Contains("obligatoire") || lower.Contains("deja"))
{
return Warning(text);
}
return Info(text);
}
} }