| @inject IStringLocalizer<Resources> i18n | @inject IStringLocalizer<Resources> i18n | ||||
| @inject PageHistoryManager PageHistoryManager | @inject PageHistoryManager PageHistoryManager | ||||
| @inject MasterDataService MasterDataService | @inject MasterDataService MasterDataService | ||||
| @inject IMatToaster Toaster | |||||
| @inject Toaster Toaster | |||||
| @inject IJSRuntime JS | @inject IJSRuntime JS | ||||
| } | } | ||||
| private async Task GetColors() { | private async Task GetColors() { | ||||
| //await InvokeAsync(async () => { | |||||
| // await MasterDataService.GetColors(); | |||||
| // StateHasChanged(); | |||||
| //}); | |||||
| await MasterDataService.GetColors(); | await MasterDataService.GetColors(); | ||||
| StateHasChanged(); | StateHasChanged(); | ||||
| } | } | ||||
| private async Task GetBicycleTypes() { | private async Task GetBicycleTypes() { | ||||
| await InvokeAsync(async () => { | |||||
| await MasterDataService.GetBicycleTypes(); | |||||
| StateHasChanged(); | |||||
| }); | |||||
| await MasterDataService.GetBicycleTypes(); | |||||
| StateHasChanged(); | |||||
| } | } | ||||
| private async Task GetBrands() { | private async Task GetBrands() { | ||||
| await InvokeAsync(async () => { | |||||
| await MasterDataService.GetBrands(); | |||||
| StateHasChanged(); | |||||
| }); | |||||
| await MasterDataService.GetBrands(); | |||||
| StateHasChanged(); | |||||
| } | } | ||||
| private ColorItem[] Colors { | private ColorItem[] Colors { | ||||
| } catch (IOException ex) { | } catch (IOException ex) { | ||||
| Console.WriteLine("Ex.Message is: {0}.", ex.Message); | Console.WriteLine("Ex.Message is: {0}.", ex.Message); | ||||
| if (ex.Message.Contains("exceeds the maximum of")) { | if (ex.Message.Contains("exceeds the maximum of")) { | ||||
| Show(MatToastType.Danger, i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024))); | |||||
| Toaster.ShowError(i18n.GetString("Error.PhotoOrPictureToBig.Title"), i18n.GetString("Error.PhotoOrPictureToBig.Msg", MAX_FILE_SIZE / (1024 * 1024))); | |||||
| } else { | } else { | ||||
| Show(MatToastType.Danger, i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg")); | |||||
| Toaster.ShowError(i18n.GetString("Error.IOException.Title"), i18n.GetString("Error.IOException.Msg")); | |||||
| } | } | ||||
| } catch (JSException ex) { | } catch (JSException ex) { | ||||
| Console.WriteLine("Ex.Message is: {0}.", ex.Message); | Console.WriteLine("Ex.Message is: {0}.", ex.Message); |
| private BlazorGeolocationService BlazorGeolocationService { get; init; } | private BlazorGeolocationService BlazorGeolocationService { get; init; } | ||||
| [Inject] | [Inject] | ||||
| private MatBlazor.IMatToaster Toaster { get; init; } | |||||
| private Toaster Toaster { get; init; } | |||||
| [Inject] | [Inject] | ||||
| private IStringLocalizer<Resources> I18n { get; init; } | private IStringLocalizer<Resources> I18n { get; init; } | ||||
| this.NominatimService = new NominatimService(); | this.NominatimService = new NominatimService(); | ||||
| } | } | ||||
| protected void Show(MatBlazor.MatToastType type, string title, string message, string icon = "") { | |||||
| Toaster.Add(message, type, title, icon); | |||||
| } | |||||
| protected async Task AddEventsToMap() { | protected async Task AddEventsToMap() { | ||||
| await this.mapRef.OnClick(async (MouseEvent mouseEvent) => await OnMouseMapClicked(mouseEvent)); | await this.mapRef.OnClick(async (MouseEvent mouseEvent) => await OnMouseMapClicked(mouseEvent)); | ||||
| } | } | ||||
| private async Task ShowDeviceGeoLocation() { | private async Task ShowDeviceGeoLocation() { | ||||
| BlazorGeolocationPosition position = await this.BlazorGeolocationService.GetPositionAsync(); | BlazorGeolocationPosition position = await this.BlazorGeolocationService.GetPositionAsync(); | ||||
| if (position.ErrorCode != null) { | if (position.ErrorCode != null) { | ||||
| Show(MatBlazor.MatToastType.Danger, I18n.GetString("Error.GeoLocation.Title", position.ErrorCode), I18n.GetString("Error.GeoLocation.Msg", position.ErrorMessage)); | |||||
| Toaster.ShowError(I18n.GetString("Error.GeoLocation.Title", position.ErrorCode), I18n.GetString("Error.GeoLocation.Msg", position.ErrorMessage)); | |||||
| } else { | } else { | ||||
| LatLng geoPosition = new((double)position.Latitude, (double)position.Longitude); | LatLng geoPosition = new((double)position.Latitude, (double)position.Longitude); | ||||
| this.bicycleGeoPosition.Address = GetFormattedAddressStreet(addressDto); | this.bicycleGeoPosition.Address = GetFormattedAddressStreet(addressDto); | ||||
| this.bicycleGeoPosition.City = GetFormattedAddressZipAndTown(addressDto); | this.bicycleGeoPosition.City = GetFormattedAddressZipAndTown(addressDto); | ||||
| } else { | } else { | ||||
| Show(MatBlazor.MatToastType.Warning, I18n.GetString("Warning.Nominatim.Title"), I18n.GetString("Warning.Nominatim.Msg")); | |||||
| Toaster.ShowWarning(I18n.GetString("Warning.Nominatim.Title"), I18n.GetString("Warning.Nominatim.Msg")); | |||||
| } | } | ||||
| StateHasChanged(); | StateHasChanged(); |
| @inject IStringLocalizer<Resources> i18n | @inject IStringLocalizer<Resources> i18n | ||||
| @inject PageHistoryManager PageHistoryManager | @inject PageHistoryManager PageHistoryManager | ||||
| @inject MasterDataService MasterDataService; | @inject MasterDataService MasterDataService; | ||||
| @inject Toaster Toaster; | |||||
| <div class="row h-100 justify-content-center"> | <div class="row h-100 justify-content-center"> | ||||
| </div> | </div> | ||||
| <div class="row align-items-center justify-content-center vw-100 h-25"> | <div class="row align-items-center justify-content-center vw-100 h-25"> | ||||
| <div> | <div> | ||||
| @if(showProgressCircle) { | |||||
| @if (showProgressCircle) { | |||||
| <MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Large" Style="padding-left:1.2rem" /> | <MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Large" Style="padding-left:1.2rem" /> | ||||
| <h6 style="font-style:italic;padding-bottom:1em">@i18n["Initializing..."]</h6> | |||||
| } | |||||
| <h6 style="font-style:italic;padding-bottom:1em">@i18n["Info.Masterdata.Initializing"]</h6> | |||||
| } | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| Console.WriteLine("First activation"); | Console.WriteLine("First activation"); | ||||
| showProgressCircle = true; | showProgressCircle = true; | ||||
| StateHasChanged(); | StateHasChanged(); | ||||
| await MasterDataService.SynchronizeMasterdata(); | |||||
| showProgressCircle = false; | |||||
| //await MasterDataService.SynchronizeMasterdata(); | |||||
| //showProgressCircle = false; | |||||
| try { | |||||
| await MasterDataService.SynchronizeMasterdata(); | |||||
| } catch (Exception ex) { | |||||
| Toaster.ShowWarning(i18n.GetString("Warning.Masterdata.Title"), i18n.GetString("Warning.Masterdata.Msg")); | |||||
| } finally { | |||||
| showProgressCircle = false; | |||||
| } | |||||
| } | } | ||||
| btnDisabled = false; | btnDisabled = false; | ||||
| PageHistoryManager.Reset(); | PageHistoryManager.Reset(); | ||||
| StateHasChanged(); | StateHasChanged(); | ||||
| } | } | ||||
| private void ButtonClicked() { | private void ButtonClicked() { | ||||
| NavigationManager.NavigateTo("./caritas_services"); | NavigationManager.NavigateTo("./caritas_services"); | ||||
| AppState.LoggedIn = true; | AppState.LoggedIn = true; |
| builder.Services.AddSingleton<ILFBicycleRest, LFBicycleRest>(); | builder.Services.AddSingleton<ILFBicycleRest, LFBicycleRest>(); | ||||
| builder.Services.AddSingleton<AppState>(); | builder.Services.AddSingleton<AppState>(); | ||||
| builder.Services.AddSingleton<PageHistoryManager>(); | builder.Services.AddSingleton<PageHistoryManager>(); | ||||
| builder.Services.AddScoped<Toaster>(); | |||||
| builder.Services.AddScoped<UserDataProvider>(); | builder.Services.AddScoped<UserDataProvider>(); | ||||
| builder.Services.AddScoped<MasterDataService>(); | builder.Services.AddScoped<MasterDataService>(); | ||||
| builder.Services.AddScoped<BlazorGeolocationService>(); | |||||
| builder.Services.AddLocalization(); | builder.Services.AddLocalization(); | ||||
| builder.Services.AddBlazorLeafletMaps(); | builder.Services.AddBlazorLeafletMaps(); | ||||
| builder.Services.AddScoped<BlazorGeolocationService>(); | |||||
| builder.Services.AddMatToaster(config => { | builder.Services.AddMatToaster(config => { | ||||
| config.Position = MatToastPosition.BottomCenter; | config.Position = MatToastPosition.BottomCenter; |
| <data name="info" xml:space="preserve"> | <data name="info" xml:space="preserve"> | ||||
| <value>Info</value> | <value>Info</value> | ||||
| </data> | </data> | ||||
| <data name="Info.Masterdata.Initializing" xml:space="preserve"> | |||||
| <value>Am Initialisieren...</value> | |||||
| </data> | |||||
| <data name="Lastname" xml:space="preserve"> | <data name="Lastname" xml:space="preserve"> | ||||
| <value>Nachname</value> | <value>Nachname</value> | ||||
| </data> | </data> | ||||
| <data name="Username" xml:space="preserve"> | <data name="Username" xml:space="preserve"> | ||||
| <value>Benutzername oder E-Mail</value> | <value>Benutzername oder E-Mail</value> | ||||
| </data> | </data> | ||||
| <data name="Warning.Masterdata.Msg" xml:space="preserve"> | |||||
| <value>Die Stammdaten konnten nicht abgerufen werden. Es werden stattdessen die Standardwerte verwendet!</value> | |||||
| </data> | |||||
| <data name="Warning.Masterdata.Title" xml:space="preserve"> | |||||
| <value>Die Stammdaten konnten nicht abgerufen werden!</value> | |||||
| </data> | |||||
| <data name="Warning.Nominatim.Msg" xml:space="preserve"> | <data name="Warning.Nominatim.Msg" xml:space="preserve"> | ||||
| <value>Die Adresse konnte beim Aufrufen des Nominatim-Dienstes nicht aufgelöst werden. Bitte geben Sie die Straße und Postleitzahl/Ort manuell ein.</value> | <value>Die Adresse konnte beim Aufrufen des Nominatim-Dienstes nicht aufgelöst werden. Bitte geben Sie die Straße und Postleitzahl/Ort manuell ein.</value> | ||||
| </data> | </data> |
| <data name="info" xml:space="preserve"> | <data name="info" xml:space="preserve"> | ||||
| <value>Information</value> | <value>Information</value> | ||||
| </data> | </data> | ||||
| <data name="Info.Masterdata.Initializing" xml:space="preserve"> | |||||
| <value>Initialisation...</value> | |||||
| </data> | |||||
| <data name="Lastname" xml:space="preserve"> | <data name="Lastname" xml:space="preserve"> | ||||
| <value>Nom de famille</value> | <value>Nom de famille</value> | ||||
| </data> | </data> | ||||
| <data name="Username" xml:space="preserve"> | <data name="Username" xml:space="preserve"> | ||||
| <value>Nom d'utilisateur ou courriel</value> | <value>Nom d'utilisateur ou courriel</value> | ||||
| </data> | </data> | ||||
| <data name="Warning.Masterdata.Msg" xml:space="preserve"> | |||||
| <value>Les données de base n'ont pas pu être récupérées. Les valeurs par défaut sont utilisées à la place !</value> | |||||
| </data> | |||||
| <data name="Warning.Masterdata.Title" xml:space="preserve"> | |||||
| <value>Impossible de récupérer les données de base !</value> | |||||
| </data> | |||||
| <data name="Warning.Nominatim.Msg" xml:space="preserve"> | <data name="Warning.Nominatim.Msg" xml:space="preserve"> | ||||
| <value>L'adresse n'a pas pu être résolue en invoquant le service Nominatim. Veuillez saisir l'adresse en indiquant la rue et le code postal/ville.</value> | <value>L'adresse n'a pas pu être résolue en invoquant le service Nominatim. Veuillez saisir l'adresse en indiquant la rue et le code postal/ville.</value> | ||||
| </data> | </data> |
| <data name="info" xml:space="preserve"> | <data name="info" xml:space="preserve"> | ||||
| <value>Informazione</value> | <value>Informazione</value> | ||||
| </data> | </data> | ||||
| <data name="Info.Masterdata.Initializing" xml:space="preserve"> | |||||
| <value>Inizializzazione...</value> | |||||
| </data> | |||||
| <data name="Lastname" xml:space="preserve"> | <data name="Lastname" xml:space="preserve"> | ||||
| <value>Cognome</value> | <value>Cognome</value> | ||||
| </data> | </data> | ||||
| <data name="Username" xml:space="preserve"> | <data name="Username" xml:space="preserve"> | ||||
| <value>Nome d'utente o e-mail</value> | <value>Nome d'utente o e-mail</value> | ||||
| </data> | </data> | ||||
| <data name="Warning.Masterdata.Msg" xml:space="preserve"> | |||||
| <value>Non è stato possibile recuperare i dati anagrafici. Vengono invece utilizzati i valori di default!</value> | |||||
| </data> | |||||
| <data name="Warning.Masterdata.Title" xml:space="preserve"> | |||||
| <value>Impossibile recuperare i dati anagrafici!</value> | |||||
| </data> | |||||
| <data name="Warning.Nominatim.Msg" xml:space="preserve"> | <data name="Warning.Nominatim.Msg" xml:space="preserve"> | ||||
| <value>L'indirizzo non può essere risolto invocando il servizio Nominatim. Si prega di digitare la via e CAP/città.</value> | <value>L'indirizzo non può essere risolto invocando il servizio Nominatim. Si prega di digitare la via e CAP/città.</value> | ||||
| </data> | </data> |
| <data name="info" xml:space="preserve"> | <data name="info" xml:space="preserve"> | ||||
| <value>Info</value> | <value>Info</value> | ||||
| </data> | </data> | ||||
| <data name="Info.Masterdata.Initializing" xml:space="preserve"> | |||||
| <value>Initializing...</value> | |||||
| </data> | |||||
| <data name="Lastname" xml:space="preserve"> | <data name="Lastname" xml:space="preserve"> | ||||
| <value>Last name</value> | <value>Last name</value> | ||||
| </data> | </data> | ||||
| <data name="Username" xml:space="preserve"> | <data name="Username" xml:space="preserve"> | ||||
| <value>Username or E-Mail</value> | <value>Username or E-Mail</value> | ||||
| </data> | </data> | ||||
| <data name="Warning.Masterdata.Msg" xml:space="preserve"> | |||||
| <value>The master data could not be retrieved. The default values are used instead!</value> | |||||
| </data> | |||||
| <data name="Warning.Masterdata.Title" xml:space="preserve"> | |||||
| <value>Could not retreive master data!</value> | |||||
| </data> | |||||
| <data name="Warning.Nominatim.Msg" xml:space="preserve"> | <data name="Warning.Nominatim.Msg" xml:space="preserve"> | ||||
| <value>The address could not be resolved invoking Nominatim service. Please type in the address street and zip/town.</value> | <value>The address could not be resolved invoking Nominatim service. Please type in the address street and zip/town.</value> | ||||
| </data> | </data> |
| Task<List<ColorItem>> GetColors(); | Task<List<ColorItem>> GetColors(); | ||||
| List<BicycleType> GetBicycleTypes(); | |||||
| Task<List<BicycleType>> GetBicycleTypes(); | |||||
| List<Brand> GetBrands(); | |||||
| Task<List<Brand>> GetBrands(); | |||||
| } | } | ||||
| } | } |
| using CaritasPWA.Shared.Models; | using CaritasPWA.Shared.Models; | ||||
| using CaritasPWA.Shared.ResourceFiles; | |||||
| using Json.Net; | using Json.Net; | ||||
| using Microsoft.Extensions.Localization; | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Globalization; | using System.Globalization; | ||||
| namespace CaritasPWA.Shared.Services { | namespace CaritasPWA.Shared.Services { | ||||
| // REST interface responsible to submit lost or found reports and get the available masterdata. | |||||
| // REST interface responsible to submit lost or found reports and get the available master data. | |||||
| public class LFBicycleRest : ILFBicycleRest { | public class LFBicycleRest : ILFBicycleRest { | ||||
| private static readonly string VERSION = "v1"; | private static readonly string VERSION = "v1"; | ||||
| private readonly IStringLocalizer<Resources> _i18n; | |||||
| private readonly HttpClient httpClient; | private readonly HttpClient httpClient; | ||||
| public LFBicycleRest(IStringLocalizer<Resources> i18n) { | |||||
| _i18n = i18n; | |||||
| public LFBicycleRest() { | |||||
| this.httpClient = new HttpClient { BaseAddress = new Uri("https://integrate.dynalias.net:9443/Fundvelo/") }; | this.httpClient = new HttpClient { BaseAddress = new Uri("https://integrate.dynalias.net:9443/Fundvelo/") }; | ||||
| } | } | ||||
| public async Task<List<ColorItem>> GetColors() { | public async Task<List<ColorItem>> GetColors() { | ||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/colors", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| try { | |||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/colors", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<ColorItem>(colors); | |||||
| } | |||||
| // TODO: show a warning message here | |||||
| } catch (Exception ex) { | |||||
| // TODO: show a warning message here | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<ColorItem>(colors); | |||||
| } | } | ||||
| return new List<ColorItem>(); | |||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| } | } | ||||
| public List<BicycleType> GetBicycleTypes() { | |||||
| //return Defaults.GetBicycleTypeDefaults(_i18n); | |||||
| return new List<BicycleType>(); | |||||
| public async Task<List<BicycleType>> GetBicycleTypes() { | |||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/types", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| BicycleType[] bicycleTypes = JsonNet.Deserialize<BicycleType[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<BicycleType>(bicycleTypes); | |||||
| } | |||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| } | } | ||||
| public async Task<List<Brand>> GetBrands() { | |||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/brands", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| public List<Brand> GetBrands() { | |||||
| //return Defaults.Brands.ToList(); | |||||
| return new List<Brand>(); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| Brand[] brands = JsonNet.Deserialize<Brand[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<Brand>(brands); | |||||
| } | |||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| } | } | ||||
| } | } |
| public ColorItem[] Colors { | public ColorItem[] Colors { | ||||
| get => _colors; | get => _colors; | ||||
| set => _colors = value; | |||||
| } | } | ||||
| public BicycleType[] BicycleTypes { | public BicycleType[] BicycleTypes { | ||||
| get => _bicycleTypes; | get => _bicycleTypes; | ||||
| set => _bicycleTypes = value; | |||||
| } | } | ||||
| public Brand[] Brands { | public Brand[] Brands { | ||||
| get => _brands; | get => _brands; | ||||
| set => _brands = value; | |||||
| } | } | ||||
| public event EventHandler Changed; | public event EventHandler Changed; | ||||
| _lFBicycleRest = lFBicycleRest; | _lFBicycleRest = lFBicycleRest; | ||||
| _i18n = i18n; | _i18n = i18n; | ||||
| _firstActivation = true; | _firstActivation = true; | ||||
| _brands = Defaults.GetBrandDefaults(_i18n).ToArray(); | |||||
| _colors = Defaults.GetColorDefaults(_i18n).ToArray(); | |||||
| _bicycleTypes = Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | |||||
| Console.WriteLine("MasterDataService constructor / colors: " + _colors.Length); | |||||
| } | } | ||||
| public async Task SynchronizeMasterdata() { | public async Task SynchronizeMasterdata() { | ||||
| await SynchronizeColors(); | |||||
| await SynchronizeBcTypes(); | |||||
| await SynchronizeBrands(); | |||||
| _firstActivation = false; | |||||
| try { | |||||
| await SynchronizeColors(); | |||||
| await SynchronizeBcTypes(); | |||||
| await SynchronizeBrands(); | |||||
| } finally { | |||||
| _firstActivation = false; | |||||
| } | |||||
| } | } | ||||
| public async Task SynchronizeColors() { | public async Task SynchronizeColors() { | ||||
| Colors = (await _lFBicycleRest.GetColors()).ToArray(); | |||||
| if (Colors != null && Colors.Length > 0) { | |||||
| await SaveColorsToStorage(); | |||||
| ColorItem[] colors = (await _lFBicycleRest.GetColors()).ToArray(); | |||||
| if (colors != null && colors.Length > 0) { | |||||
| _colors = colors; | |||||
| await SaveColorsToStorage(colors); | |||||
| }; | }; | ||||
| } | } | ||||
| public async Task SynchronizeBcTypes() { | public async Task SynchronizeBcTypes() { | ||||
| BicycleTypes = _lFBicycleRest.GetBicycleTypes().ToArray(); | |||||
| if (BicycleTypes != null && BicycleTypes.Length > 0) { | |||||
| await SaveBcTypesToStorage(); | |||||
| BicycleType[] bicycleTypes = (await _lFBicycleRest.GetBicycleTypes()).ToArray(); | |||||
| if (bicycleTypes != null && bicycleTypes.Length > 0) { | |||||
| _bicycleTypes = bicycleTypes; | |||||
| await SaveBcTypesToStorage(bicycleTypes); | |||||
| } | } | ||||
| } | } | ||||
| public async Task SynchronizeBrands() { | public async Task SynchronizeBrands() { | ||||
| Brands = _lFBicycleRest.GetBrands().ToArray(); | |||||
| if (Brands != null && Brands.Length > 0) { | |||||
| await SaveBrandsToStorage(); | |||||
| Brand[] brands = (await _lFBicycleRest.GetBrands()).ToArray(); | |||||
| if (brands != null && brands.Length > 0) { | |||||
| _brands = brands; | |||||
| await SaveBrandsToStorage(brands); | |||||
| } | } | ||||
| } | } | ||||
| public async Task<ColorItem[]> GetColors() { | public async Task<ColorItem[]> GetColors() { | ||||
| ColorItem[] colors = await GetColorsFromStorage(); | ColorItem[] colors = await GetColorsFromStorage(); | ||||
| Colors = (colors != null && colors.Length > 0) ? colors: Defaults.GetColorDefaults(_i18n).ToArray(); | |||||
| Colors = SortColors(new List<ColorItem>(Colors)).ToArray(); | |||||
| if (colors != null && colors.Length > 0) { | |||||
| _colors = colors; | |||||
| } | |||||
| _colors = SortColors(new List<ColorItem>(_colors)).ToArray(); | |||||
| return Colors; | return Colors; | ||||
| } | } | ||||
| public async Task<BicycleType[]> GetBicycleTypes() { | public async Task<BicycleType[]> GetBicycleTypes() { | ||||
| BicycleType[] bicycleTypes = await GetBicycleTypesFromStorage(); | BicycleType[] bicycleTypes = await GetBicycleTypesFromStorage(); | ||||
| BicycleTypes = (bicycleTypes != null && bicycleTypes.Length > 0) ? bicycleTypes : Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | |||||
| BicycleTypes = SortBicycleTypes(new List<BicycleType>(BicycleTypes)).ToArray(); | |||||
| if (bicycleTypes != null && bicycleTypes.Length > 0) { | |||||
| _bicycleTypes = bicycleTypes; | |||||
| } | |||||
| _bicycleTypes = SortBicycleTypes(new List<BicycleType>(_bicycleTypes)).ToArray(); | |||||
| return BicycleTypes; | return BicycleTypes; | ||||
| } | } | ||||
| public async Task<Brand[]> GetBrands() { | public async Task<Brand[]> GetBrands() { | ||||
| Brand[] brands = await GetBrandsFromStorage(); | Brand[] brands = await GetBrandsFromStorage(); | ||||
| Brands = (brands != null && brands.Length > 0) ? brands : Defaults.GetBrandDefaults(_i18n).ToArray(); | |||||
| Brands = SortBrands(new List<Brand>(Brands)).ToArray(); | |||||
| if (brands != null && brands.Length > 0) { | |||||
| _brands = brands; | |||||
| } | |||||
| _brands = SortBrands(new List<Brand>(_brands)).ToArray(); | |||||
| return Brands; | return Brands; | ||||
| } | } | ||||
| } else { | } else { | ||||
| result = JsonNet.Deserialize<ColorItem[]>(str) ?? Array.Empty<ColorItem>(); | result = JsonNet.Deserialize<ColorItem[]>(str) ?? Array.Empty<ColorItem>(); | ||||
| } | } | ||||
| _colors = result; | |||||
| return result; | return result; | ||||
| } | } | ||||
| // Read the JSON string that contains the data from the local storage | // Read the JSON string that contains the data from the local storage | ||||
| BicycleType[] result; | BicycleType[] result; | ||||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBcTypes); | var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBcTypes); | ||||
| if (str != null) { | |||||
| result = JsonNet.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>(); | |||||
| } else { | |||||
| if (String.IsNullOrEmpty(str)) { | |||||
| result = Array.Empty<BicycleType>(); | result = Array.Empty<BicycleType>(); | ||||
| } else { | |||||
| result = JsonNet.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>(); | |||||
| } | } | ||||
| _bicycleTypes = result; | |||||
| return result; | return result; | ||||
| } | } | ||||
| // Read the JSON string that contains the data from the local storage | // Read the JSON string that contains the data from the local storage | ||||
| Brand[] result; | Brand[] result; | ||||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBrands); | var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBrands); | ||||
| if (str != null) { | |||||
| result = JsonNet.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>(); | |||||
| } else { | |||||
| if (String.IsNullOrEmpty(str)) { | |||||
| result = Array.Empty<Brand>(); | result = Array.Empty<Brand>(); | ||||
| } else { | |||||
| result = JsonNet.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>(); | |||||
| } | } | ||||
| _brands = result; | |||||
| return result; | return result; | ||||
| } | } | ||||
| private async Task SaveColorsToStorage() { | |||||
| var json = JsonNet.Serialize(_colors); | |||||
| private async Task SaveColorsToStorage(ColorItem[] colors) { | |||||
| var json = JsonNet.Serialize(colors); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json); | await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json); | ||||
| } | } | ||||
| private async Task SaveBcTypesToStorage() { | |||||
| var json = JsonNet.Serialize(_bicycleTypes); | |||||
| private async Task SaveBcTypesToStorage(BicycleType[] bicycleTypes) { | |||||
| var json = JsonNet.Serialize(bicycleTypes); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, json); | await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, json); | ||||
| } | } | ||||
| private async Task SaveBrandsToStorage() { | |||||
| var json = JsonNet.Serialize(_brands); | |||||
| private async Task SaveBrandsToStorage(Brand[] brands) { | |||||
| var json = JsonNet.Serialize(brands); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json); | await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json); | ||||
| } | } | ||||
| using MatBlazor; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| namespace CaritasPWA.Shared.Services { | |||||
| public class Toaster { | |||||
| private readonly IMatToaster matToaster; | |||||
| public Toaster(IMatToaster toaster) { | |||||
| this.matToaster = toaster; | |||||
| } | |||||
| public void ShowInfo(string title, string message, string icon = "") { | |||||
| matToaster.Add(message, MatBlazor.MatToastType.Info, title, icon); | |||||
| } | |||||
| public void ShowWarning(string title, string message, string icon = "") { | |||||
| matToaster.Add(message, MatBlazor.MatToastType.Warning, title, icon); | |||||
| } | |||||
| public void ShowError(string title, string message, string icon = "") { | |||||
| matToaster.Add(message, MatBlazor.MatToastType.Danger, title, icon); | |||||
| } | |||||
| } | |||||
| } |