postit: preserve manual rdv address with map suggestion

This commit is contained in:
Paul Schneider 2026-09-06 17:16:14 +01:00
commit 5d502fd6a7
Signed by: notazof
GPG key ID: 1DD5D838E5343B06
3 changed files with 111 additions and 14 deletions

View file

@ -135,6 +135,50 @@ public class BillingCommandPageViewModelTests
Assert.Contains("Position sélectionnée", vm.StatusMessage, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void ApplyResolvedAddress_populates_empty_address_directly()
{
var api = new RecordingApi();
var client = new BillingApiClient(api, "https://business.example/api/v1/");
var vm =
new CommandFormSummary { Id = 12, ActionName = "Rdv", Title = "Rendez-vous" }
.CreateCommandPageViewModel(
new ActivityInfo { Code = "dev", Name = "Développement" },
new ActivityUserDisplayItem { PerformerId = "perf-1", UserName = "Alice" },
client) as RdvViewModel;
vm!.Address = string.Empty;
vm.ApplyResolvedAddress("10 rue de Rivoli, 75001 Paris");
Assert.Equal("10 rue de Rivoli, 75001 Paris", vm.Address);
Assert.False(vm.HasSuggestedAddress);
}
[Fact]
public void ApplyResolvedAddress_preserves_manual_address_and_exposes_suggestion()
{
var api = new RecordingApi();
var client = new BillingApiClient(api, "https://business.example/api/v1/");
var vm =
new CommandFormSummary { Id = 12, ActionName = "Rdv", Title = "Rendez-vous" }
.CreateCommandPageViewModel(
new ActivityInfo { Code = "dev", Name = "Développement" },
new ActivityUserDisplayItem { PerformerId = "perf-1", UserName = "Alice" },
client) as RdvViewModel;
vm!.Address = "Saisie manuelle";
vm.ApplyResolvedAddress("10 rue de Rivoli, 75001 Paris");
Assert.Equal("Saisie manuelle", vm.Address);
Assert.True(vm.HasSuggestedAddress);
Assert.Equal("10 rue de Rivoli, 75001 Paris", vm.SuggestedAddress);
vm.ApplySuggestedAddressCommand.Execute(null);
Assert.Equal("10 rue de Rivoli, 75001 Paris", vm.Address);
Assert.False(vm.HasSuggestedAddress);
}
[Fact]
public async Task InitializeAsync_loads_prestations_for_brush_and_submit_posts_selected_prestation()
{

View file

@ -17,6 +17,9 @@ public partial class RdvViewModel : BillingCommandPageViewModel
[ObservableProperty]
public partial string Address { get; set; } = string.Empty;
[ObservableProperty]
public partial string SuggestedAddress { get; set; } = string.Empty;
[ObservableProperty]
public partial double? Latitude { get; set; }
@ -33,6 +36,8 @@ public partial class RdvViewModel : BillingCommandPageViewModel
EventDate = DateTime.Now.AddDays(1);
}
public bool HasSuggestedAddress => !string.IsNullOrWhiteSpace(SuggestedAddress);
protected override void ApplyExistingQuery(BillingQueryDetailsDto existingQuery)
{
ExistingQueryId = existingQuery.Id;
@ -50,6 +55,7 @@ public partial class RdvViewModel : BillingCommandPageViewModel
if (existingQuery.Location is not null)
{
Address = existingQuery.Location.Address ?? string.Empty;
SuggestedAddress = string.Empty;
Latitude = existingQuery.Location.Latitude;
Longitude = existingQuery.Location.Longitude;
}
@ -132,8 +138,40 @@ public partial class RdvViewModel : BillingCommandPageViewModel
if (string.IsNullOrWhiteSpace(address))
return;
Address = address.Trim();
var trimmedAddress = address.Trim();
if (string.IsNullOrWhiteSpace(Address))
{
Address = trimmedAddress;
SuggestedAddress = string.Empty;
this.SetInfoStatus("Adresse mise à jour depuis la carte.");
return;
}
if (string.Equals(Address.Trim(), trimmedAddress, StringComparison.Ordinal))
{
SuggestedAddress = string.Empty;
return;
}
SuggestedAddress = trimmedAddress;
this.SetInfoStatus("Adresse suggérée depuis la carte. Appliquez-la si besoin.");
}
[RelayCommand(CanExecute = nameof(HasSuggestedAddress))]
private void ApplySuggestedAddress()
{
if (string.IsNullOrWhiteSpace(SuggestedAddress))
return;
Address = SuggestedAddress.Trim();
SuggestedAddress = string.Empty;
this.SetInfoStatus("Adresse suggérée appliquée.");
}
partial void OnSuggestedAddressChanged(string value)
{
OnPropertyChanged(nameof(HasSuggestedAddress));
ApplySuggestedAddressCommand.NotifyCanExecuteChanged();
}

View file

@ -7,7 +7,7 @@
x:DataType="cvm:RdvViewModel"
Header="Commande billing">
<ScrollViewer>
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,*" Margin="12">
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,*" Margin="12">
<TextBlock Grid.Row="0" Grid.ColumnSpan="2"
Text="{Binding Title}"
FontSize="18"
@ -41,6 +41,21 @@
<TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Address, Mode=TwoWay}" Margin="0,0,0,8" />
<Grid Grid.Row="7"
Grid.ColumnSpan="2"
ColumnDefinitions="*,12,Auto"
Margin="0,0,0,8"
IsVisible="{Binding HasSuggestedAddress}">
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{Binding SuggestedAddress, StringFormat='Adresse suggérée: {0}'}"
TextWrapping="Wrap"
Opacity="0.8" />
<Button Grid.Column="2"
Content="Utiliser"
Command="{Binding ApplySuggestedAddressCommand}" />
</Grid>
<Grid Grid.Row="8"
Grid.ColumnSpan="2"
ColumnDefinitions="Auto,12,Auto"
Margin="0,0,0,8">
@ -55,37 +70,37 @@
IsEnabled="{Binding CanUseCurrentLocation}" />
</Grid>
<TextBlock Grid.Row="8" Text="Latitude" VerticalAlignment="Center" Margin="0,0,12,8" />
<TextBox Grid.Row="8" Grid.Column="1" Text="{Binding Latitude, Mode=TwoWay}" PlaceholderText="Optionnel" Margin="0,0,0,8" />
<TextBlock Grid.Row="9" Text="Latitude" VerticalAlignment="Center" Margin="0,0,12,8" />
<TextBox Grid.Row="9" Grid.Column="1" Text="{Binding Latitude, Mode=TwoWay}" PlaceholderText="Optionnel" Margin="0,0,0,8" />
<TextBlock Grid.Row="9" Text="Longitude" VerticalAlignment="Center" Margin="0,0,12,8" />
<TextBox Grid.Row="9" Grid.Column="1" Text="{Binding Longitude, Mode=TwoWay}" PlaceholderText="Optionnel" Margin="0,0,0,8" />
<TextBlock Grid.Row="10" Text="Longitude" VerticalAlignment="Center" Margin="0,0,12,8" />
<TextBox Grid.Row="10" Grid.Column="1" Text="{Binding Longitude, Mode=TwoWay}" PlaceholderText="Optionnel" Margin="0,0,0,8" />
<TextBlock Grid.Row="10" Grid.ColumnSpan="2"
<TextBlock Grid.Row="11" Grid.ColumnSpan="2"
Text="Carte: cliquez pour positionner le rendez-vous"
Margin="0,0,0,8"
Opacity="0.85" />
<mapsui:MapControl Grid.Row="11"
<mapsui:MapControl Grid.Row="12"
Grid.ColumnSpan="2"
x:Name="LocationMap"
Height="260"
Margin="0,0,0,8" />
<TextBlock Grid.Row="12"
<TextBlock Grid.Row="13"
Text="Informations"
VerticalAlignment="Center"
Margin="0,0,12,8" />
<TextBox Grid.Row="12"
<TextBox Grid.Row="13"
Grid.Column="1"
Text="{Binding AdditionalInfo, Mode=TwoWay}"
Margin="0,0,0,8" />
<CheckBox Grid.Row="13" Grid.ColumnSpan="2"
<CheckBox Grid.Row="14" Grid.ColumnSpan="2"
Content="Je consens à la création de cette commande"
IsChecked="{Binding Consent, Mode=TwoWay}"
Margin="0,4,0,12" />
<Grid Grid.Row="14" Grid.ColumnSpan="2" ColumnDefinitions="Auto,12,*,Auto">
<Grid Grid.Row="15" Grid.ColumnSpan="2" ColumnDefinitions="Auto,12,*,Auto">
<Button Grid.Column="0"
Content="{Binding SubmitLabel}"
Command="{Binding SubmitCommand}"