Browse Source

Recalculate bycicle postion on focus lost of address fields

master
Flo Smilari 4 years ago
parent
commit
f16ef7464c

+ 15
- 6
Pages/Fundvelo/CaritasServiceFundVeloFoundKeyDataPage.razor View File

<div class="mat-layout-grid-inner"> <div class="mat-layout-grid-inner">
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-12-desktop"> <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-12-desktop">
<MatStringField Class="w-100 form-check-label" Label="@getAddressLbl()" Outlined="true" Required="true" Type="text" @bind-Value="@bicycleGeoPosition.Address" <MatStringField Class="w-100 form-check-label" Label="@getAddressLbl()" Outlined="true" Required="true" Type="text" @bind-Value="@bicycleGeoPosition.Address"
OnKeyDown="@InputCursorHandler.OnKeyDownHandlerAsync" maxlength="50"></MatStringField>
OnKeyDown="@InputCursorHandler.OnKeyDownHandlerAsync" maxlength="50"
OnFocusOut="@TransformAdressToDeviceMapLocation"></MatStringField>
</div> </div>
@if (OnlineStatusProvider.Online) { @if (OnlineStatusProvider.Online) {
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-12-desktop"> <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-12-desktop">
<MatStringField Class="w-100 form-check-label" Label="@getZipCityLbl()" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.DisplayCity" <MatStringField Class="w-100 form-check-label" Label="@getZipCityLbl()" Outlined="true" Required="true" type="text" @bind-Value="@bicycleGeoPosition.DisplayCity"
OnKeyDown="@InputCursorHandler.OnKeyDownHandlerAsync"></MatStringField>
OnKeyDown="@InputCursorHandler.OnKeyDownHandlerAsync"
OnFocusOut="@TransformAdressToDeviceMapLocation"></MatStringField>
</div> </div>
} else { } else {
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-4-desktop"> <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-4-desktop">
await GetBicycleTypes(); await GetBicycleTypes();
await GetBrands(); await GetBrands();
await GetZipCities(); await GetZipCities();
refreshGUIFromDto();
RefreshGUIFromDto();
OnlineStatusProvider.AddOnlineStatusChangeCallBack(OnOnlineStatusChanged); OnlineStatusProvider.AddOnlineStatusChangeCallBack(OnOnlineStatusChanged);
StateHasChanged(); StateHasChanged();
} }
private void Next() { private void Next() {
updateDtoFromGUI();
UpdateDtoFromGUI();
PageHistoryManager.AddPageToHistory(NavigationManager.Uri); PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
try { try {
Validator.ValidateFoundReportKeyData(ReportDataProvider.GetFoundReport()); Validator.ValidateFoundReportKeyData(ReportDataProvider.GetFoundReport());
} }
} }
private async void refreshGUIFromDto() {
private async void RefreshGUIFromDto() {
FoundReport report = ReportDataProvider.GetFoundReport(); FoundReport report = ReportDataProvider.GetFoundReport();
bicycleGeoPosition.Address = report.GeographicInfo.Address; bicycleGeoPosition.Address = report.GeographicInfo.Address;
bicycleGeoPosition.Zip = report.GeographicInfo.Postcode; bicycleGeoPosition.Zip = report.GeographicInfo.Postcode;
StateHasChanged(); StateHasChanged();
} }
private void updateDtoFromGUI() {
private void UpdateDtoFromGUI() {
FoundReport report = ReportDataProvider.GetFoundReport(); FoundReport report = ReportDataProvider.GetFoundReport();
report.GeographicInfo.Address = bicycleGeoPosition.Address; report.GeographicInfo.Address = bicycleGeoPosition.Address;
if (OnlineStatusProvider.Online) { if (OnlineStatusProvider.Online) {
report.Bemerkung = remark; report.Bemerkung = remark;
report.AbholadresseIstKontakt = !abholadresseIsNotContact; report.AbholadresseIstKontakt = !abholadresseIsNotContact;
} }
private async void TransformAdressToDeviceMapLocation() {
bicycleGeoPosition.DisplayCity = bicycleGeoPosition.DisplayCity; // Hack, force a decode of zip and city
await ShowBicycleGeoLocation(true);
StateHasChanged();
}
} }

+ 3
- 3
Pages/Fundvelo/CaritasServiceFundVeloFoundKeyDataPage.razor.cs View File

protected async Task InitializeBicycleMapPosition() { protected async Task InitializeBicycleMapPosition() {
CreateBicycleMarkerOptions(); CreateBicycleMarkerOptions();
await AddEventsToMap(); await AddEventsToMap();
await ShowBicycleGeoLocation();
await ShowBicycleGeoLocation(false);
} }
protected async Task<string> GetFormattedAddressZipAndTown(ReportDataProvider ReportDataProvider) { protected async Task<string> GetFormattedAddressZipAndTown(ReportDataProvider ReportDataProvider) {
return geoPosition; return geoPosition;
} }
private async Task ShowBicycleGeoLocation() {
if (this.bicycleGeoPosition.Latitude != 0 && this.bicycleGeoPosition.Longitude != 0) {
protected async Task ShowBicycleGeoLocation(bool forceRecalc) {
if (this.bicycleGeoPosition.Latitude != 0 && this.bicycleGeoPosition.Longitude != 0 && !forceRecalc) {
LatLng geoPosition = new(this.bicycleGeoPosition.Latitude, this.bicycleGeoPosition.Longitude); LatLng geoPosition = new(this.bicycleGeoPosition.Latitude, this.bicycleGeoPosition.Longitude);
await this.mapRef.SetZoom(16); await this.mapRef.SetZoom(16);
await this.mapRef.SetView(geoPosition); await this.mapRef.SetView(geoPosition);

+ 3
- 0
Shared/Models/Fundvelo/OSM/BicycleGeoPosition.cs View File

} else if (tokens.Length == 2) { } else if (tokens.Length == 2) {
Zip = tokens[0]; Zip = tokens[0];
City = tokens[1]; City = tokens[1];
} else {
Zip = null;
City = null;
} }
} }
} }

Loading…
Cancel
Save