@page "/fundvelo/keydata/Found" @inherits CaritasServiceFundVeloKeyDataPageBase @implements IDisposable; @using cwebplusApp.Shared.Models; @using cwebplusApp.Shared.Services; @using System.Globalization; @using Microsoft.AspNetCore.Components.Forms; @using System.IO; @inject NavigationManager NavigationManager @inject IStringLocalizer I18n @inject PageHistoryManager PageHistoryManager @inject MasterDataService MasterDataService @inject Toaster Toaster @inject IJSRuntime JS @inject ReportDataProvider ReportDataProvider @inject OnlineStatusProvider OnlineStatusProvider @inject InputCursorHandler InputCursorHandler @inject PermissionsProvider PermissionsProvider

@I18n["FoundBike"]

@if (loading) { }
@if (OnlineStatusProvider.Online) {
@if (IsGeoLocationAllowed) {
}
}
@if (OnlineStatusProvider.Online) {
} else {
@context?.Zip_City
}
@context?.Bezeichnung
@context?.Bezeichnung
@context?.Bezeichnung
@I18n["Cancel"]
@I18n["Continue"]
@code { private static long MAX_FILE_SIZE = 3145728; //3MB private string imgUrl = string.Empty; private Boolean loading = false; private ColorItem selectedColor; private bool IsGeoLocationAllowed = false; private string brandStringValue; private Brand selectedBrand; private Brand SelectedBrand { get { return selectedBrand; } set { selectedBrand = (value != null) ? value : new Brand(-999, brandStringValue); } } private void setBrandValue(string value) { brandStringValue = value; selectedBrand = null; } private string bcTypeStringValue; private BicycleType selectedBcType; private BicycleType SelectedBcType { get { return selectedBcType; } set { selectedBcType = (value != null) ? value : new BicycleType(-999, bcTypeStringValue); } } private void setBcTypeValue(string value) { bcTypeStringValue = value; } private string zipCityStringValue; private ZipCity selectedZipCity; private ZipCity SelectedZipCity { get { return selectedZipCity; } set { selectedZipCity = (value != null) ? value : new ZipCity(zipCityStringValue); } } private void setZipCityValue(string value) { zipCityStringValue = value; selectedZipCity = null; } private string frameNumber; private string remark; private bool abholadresseIsNotContact; public void Dispose() { OnlineStatusProvider.RemoveOnlineStatusChangeCallBack(OnOnlineStatusChanged); } protected async override void OnInitialized() { base.OnInitialized(); await GetColors(); await GetBicycleTypes(); await GetBrands(); await GetZipCities(); RefreshGUIFromDto(); OnlineStatusProvider.AddOnlineStatusChangeCallBack(OnOnlineStatusChanged); PermissionsProvider.SetGeoLocationPermissionChangeCallBack(OnGeoLocationPermissionChanged); StateHasChanged(); } private void OnOnlineStatusChanged(bool isOnline) { StateHasChanged(); } private async void OnGeoLocationPermissionChanged(bool allowed) { IsGeoLocationAllowed = allowed; MouseEvent mouseEvent = new MouseEvent(); mouseEvent.LatLng = await InitializeDeviceMapPosition(); await OnMouseMapClicked(mouseEvent); StateHasChanged(); } private async void AfterRenderMap() { FoundReport report = ReportDataProvider.GetFoundReport(); MouseEvent mouseEvent = new MouseEvent(); LatLng coordinates; LatLng devicePosition = await InitializeDeviceMapPosition(); if (report != null && ((report.GeographicInfo.Latitude != 0 && report.GeographicInfo.Longitude != 0) || (ReportDataProvider.ReportRepositoryItem != null && ReportDataProvider.ReportRepositoryItem.ID != 0))) { bicycleGeoPosition.DisplayCity = await GetFormattedAddressZipAndTown(ReportDataProvider); coordinates = new LatLng(report.GeographicInfo.Latitude, report.GeographicInfo.Longitude); mouseEvent.LatLng = coordinates; await InitializeBicycleMapPosition(); await AddBicycleMarkerOnClickPosition(mouseEvent); StateHasChanged(); } else { // Set bicycle postion equal to device position coordinates = new LatLng(devicePosition.Lat, devicePosition.Lng); mouseEvent.LatLng = coordinates; await OnMouseMapClicked(mouseEvent); } StateHasChanged(); } private Brand getBrand(Brand brand) { return brand != null ? brand : new Brand(-999, "Test"); } private async Task GetColors() { await MasterDataService.GetColors(); } private async Task GetBicycleTypes() { await MasterDataService.GetBicycleTypes(); } private async Task GetBrands() { await MasterDataService.GetBrands(); } private async Task GetZipCities() { await MasterDataService.GetZipCities(); } private ColorItem[] Colors { get => MasterDataService.Colors; } private BicycleType[] BicycleTypes { get => MasterDataService.BicycleTypes; } private Brand[] Brands { get => MasterDataService.Brands; } private ZipCity[] ZipCities { get => MasterDataService.ZipCities; } private void Next() { UpdateDtoFromGUI(); PageHistoryManager.AddPageToHistory(NavigationManager.Uri); try { Validator.ValidateFoundReportKeyData(ReportDataProvider.GetFoundReport()); if (abholadresseIsNotContact) { NavigationManager.NavigateTo("fundvelo/alternate_pickup"); } else { NavigationManager.NavigateTo("fundvelo/account/Found"); } } catch (ArgumentException) { Toaster.ShowWarning(I18n.GetString("Warning.MandatoryFields.Title"), I18n.GetString("Warning.MandatoryFields.Msg")); } } private void Cancel() { NavigationManager.NavigateTo("caritas_services"); } private string getAddressLbl() { return I18n.GetString("Street"); } private string getZipCityLbl() { return String.Format("{0} {1}", I18n.GetString("Zip"), I18n.GetString("City")); } private async Task OnGatheringPicture(InputFileChangeEventArgs e) { IBrowserFile imgFile = e.File; var buffer = new byte[imgFile.Size]; imgUrl = string.Empty; loading = true; StateHasChanged(); try { using (var stream = imgFile.OpenReadStream(MAX_FILE_SIZE)) { await stream.ReadAsync(buffer); imgUrl = $"data:{imgFile.ContentType};base64,{Convert.ToBase64String(buffer)}"; await stream.DisposeAsync(); } } catch (IOException ex) { Console.WriteLine("Ex.Message is: {0}.", ex.Message); if (ex.Message.Contains("exceeds the maximum of")) { Toaster.ShowError(I18n.GetString("Error.PhotoOrPictureToBig.Title"), I18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024))); } else { Toaster.ShowError(I18n.GetString("Error.IOException.Title"), I18n.GetString("Error.IOException.Msg")); } } catch (JSException ex) { Console.WriteLine("Ex.Message is: {0}.", ex.Message); } finally { Array.Clear(buffer, 0, buffer.Length); buffer = null; loading = false; StateHasChanged(); } } private async void RefreshGUIFromDto() { FoundReport report = ReportDataProvider.GetFoundReport(); bicycleGeoPosition.Address = report.GeographicInfo.Address; bicycleGeoPosition.Zip = report.GeographicInfo.Postcode; bicycleGeoPosition.City = report.GeographicInfo.Town; bicycleGeoPosition.Latitude = report.GeographicInfo.Latitude; bicycleGeoPosition.Longitude = report.GeographicInfo.Longitude; if (OnlineStatusProvider.Online) { bicycleGeoPosition.DisplayCity = await GetFormattedAddressZipAndTown(ReportDataProvider); } else { setZipCityValue(report.GeographicInfo.Postcode + " " + report.GeographicInfo.Town); SelectedZipCity = new ZipCity(zipCityStringValue); } imgUrl = report.FotoString; selectedColor = Array.Find(Colors, color => color.Id == report.FarbeId); selectedBrand = String.IsNullOrEmpty(report.NeueMarke) ? Array.Find(Brands, brand => brand.Id == report.MarkeId) : new Brand(-999, report.NeueMarke); selectedBcType = Array.Find(BicycleTypes, bcType => bcType.Id == report.TypId); frameNumber = report.RahmenNummer; remark = report.Bemerkung; abholadresseIsNotContact = !report.AbholadresseIstKontakt; StateHasChanged(); } private void UpdateDtoFromGUI() { FoundReport report = ReportDataProvider.GetFoundReport(); report.GeographicInfo.Address = bicycleGeoPosition.Address; if (OnlineStatusProvider.Online) { report.GeographicInfo.Postcode = bicycleGeoPosition.Zip; report.GeographicInfo.Town = bicycleGeoPosition.City; } else { report.GeographicInfo.Postcode = SelectedZipCity.Zip; report.GeographicInfo.Town = SelectedZipCity.City; } report.GeographicInfo.Latitude = bicycleGeoPosition.Latitude; report.GeographicInfo.Longitude = bicycleGeoPosition.Longitude; report.FotoString = imgUrl; report.FarbeId = selectedColor != null ? selectedColor.Id : null; report.TypId = selectedBcType != null ? selectedBcType.Id : null; if (SelectedBrand != null) { if (SelectedBrand.Id == -999) { report.NeueMarke = SelectedBrand.Bezeichnung; report.MarkeId = null; } else { report.MarkeId = SelectedBrand.Id; } } report.RahmenNummer = frameNumber; report.Bemerkung = remark; report.AbholadresseIstKontakt = !abholadresseIsNotContact; } private async void TransformAdressToDeviceMapLocation() { bicycleGeoPosition.DisplayCity = bicycleGeoPosition.DisplayCity; // Hack, force a decode of zip and city await ShowBicycleGeoLocation(true); StateHasChanged(); } }