| <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Color"]" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)"> | <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Color"]" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)"> | ||||
| <ItemTemplate> | <ItemTemplate> | ||||
| <div> | <div> | ||||
| <span class="btn-sm" style="background-color:rgb(@context.RGB); | |||||
| <span class="btn-sm" style="background-color:@context.Code; | |||||
| display:initial; | display:initial; | ||||
| border:1px solid black; | border:1px solid black; | ||||
| box-shadow:0.2em 0.2em 0.3em 0.025em #3f4244" /> | box-shadow:0.2em 0.2em 0.3em 0.025em #3f4244" /> | ||||
| <span class="btn">@i18n["Color." + @context?.Name]</span> | |||||
| <span class="btn">@context?.Bezeichnung</span> | |||||
| </div> | </div> | ||||
| </ItemTemplate> | </ItemTemplate> | ||||
| </MatSelectValue> | </MatSelectValue> | ||||
| </div> | </div> | ||||
| <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"> | ||||
| <div class="outlined"> | <div class="outlined"> | ||||
| <MatAutocompleteList TItem="Brand" FullWidth="true" Label="@i18n["Brand"]" Items="@Brands" OnTextChanged="setBrandValue" @bind-Value="SelectedBrand" CustomStringSelector="@(i => i?.Name)"> | |||||
| <MatAutocompleteList TItem="Brand" FullWidth="true" Label="@i18n["Brand"]" Items="@Brands" OnTextChanged="setBrandValue" @bind-Value="SelectedBrand" CustomStringSelector="@(i => i?.Bezeichnung)"> | |||||
| <ItemTemplate> | <ItemTemplate> | ||||
| <div> | <div> | ||||
| <span>@context?.Name</span> | |||||
| <span>@context?.Bezeichnung</span> | |||||
| </div> | </div> | ||||
| </ItemTemplate> | </ItemTemplate> | ||||
| </MatAutocompleteList> | </MatAutocompleteList> | ||||
| <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Type"]" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)"> | <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Type"]" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)"> | ||||
| <ItemTemplate> | <ItemTemplate> | ||||
| <div> | <div> | ||||
| <span>@context?.Type</span> | |||||
| <span>@context?.Bezeichnung</span> | |||||
| </div> | </div> | ||||
| </ItemTemplate> | </ItemTemplate> | ||||
| </MatSelectValue> | </MatSelectValue> | ||||
| } | } | ||||
| protected async override void OnInitialized() { | protected async override void OnInitialized() { | ||||
| base.OnInitialized(); | |||||
| Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name); | |||||
| Console.WriteLine("Current language is {0}.", CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToUpper()); | |||||
| await GetColors(); | await GetColors(); | ||||
| await GetBicycleTypes(); | await GetBicycleTypes(); | ||||
| await GetBrands(); | await GetBrands(); | ||||
| PageHistoryManager.AddPageToHistory(NavigationManager.Uri); | PageHistoryManager.AddPageToHistory(NavigationManager.Uri); | ||||
| base.OnInitialized(); | |||||
| } | } | ||||
| private Brand getBrand(Brand brand) { | private Brand getBrand(Brand brand) { | ||||
| } | } | ||||
| private async Task GetColors() { | private async Task GetColors() { | ||||
| await InvokeAsync(async () => { | |||||
| await MasterDataService.GetColors(); | |||||
| StateHasChanged(); | |||||
| }); | |||||
| //await InvokeAsync(async () => { | |||||
| // await MasterDataService.GetColors(); | |||||
| // StateHasChanged(); | |||||
| //}); | |||||
| await MasterDataService.GetColors(); | |||||
| StateHasChanged(); | |||||
| } | } | ||||
| private async Task GetBicycleTypes() { | private async Task GetBicycleTypes() { |
| private IIconFactory IconFactory { get; init; } | private IIconFactory IconFactory { get; init; } | ||||
| [Inject] | [Inject] | ||||
| private BlazorGeolocationService blazorGeolocationService { get; init; } | |||||
| private BlazorGeolocationService BlazorGeolocationService { get; init; } | |||||
| [Inject] | [Inject] | ||||
| private MatBlazor.IMatToaster Toaster { get; init; } | private MatBlazor.IMatToaster Toaster { get; init; } | ||||
| [Inject] | [Inject] | ||||
| private IStringLocalizer<Resources> I18n { get; init; } | private IStringLocalizer<Resources> I18n { get; init; } | ||||
| private NominatimService nominatimService { get; set; } | |||||
| private NominatimService NominatimService { get; set; } | |||||
| public CaritasServiceFundVeloKeyDataPageBase() : base() { | public CaritasServiceFundVeloKeyDataPageBase() : base() { | ||||
| }; | }; | ||||
| this.bicycleGeoPosition = new(); | this.bicycleGeoPosition = new(); | ||||
| this.nominatimService = new NominatimService(); | |||||
| this.NominatimService = new NominatimService(); | |||||
| } | } | ||||
| protected void Show(MatBlazor.MatToastType type, string title, string message, string icon = "") { | protected void Show(MatBlazor.MatToastType type, string title, string message, string icon = "") { | ||||
| } | } | ||||
| protected async Task InitializeMapPosition() { | protected async Task InitializeMapPosition() { | ||||
| createBicycleMarkerOptions(); | |||||
| CreateBicycleMarkerOptions(); | |||||
| await AddEventsToMap(); | await AddEventsToMap(); | ||||
| await ShowDeviceGeoLocation(); | await ShowDeviceGeoLocation(); | ||||
| } | } | ||||
| private async void createBicycleMarkerOptions() { | |||||
| private async void CreateBicycleMarkerOptions() { | |||||
| this.bicycleMarkerOptions = new MarkerOptions() { | this.bicycleMarkerOptions = new MarkerOptions() { | ||||
| IconRef = await this.IconFactory.Create(new IconOptions() { | IconRef = await this.IconFactory.Create(new IconOptions() { | ||||
| IconUrl = "./icons/bicycle_location.png", | IconUrl = "./icons/bicycle_location.png", | ||||
| } | } | ||||
| 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)); | Show(MatBlazor.MatToastType.Danger, I18n.GetString("Error.GeoLocation.Title", position.ErrorCode), I18n.GetString("Error.GeoLocation.Msg", position.ErrorMessage)); | ||||
| } else { | } else { | ||||
| this.bicycleGeoPosition.Latitude = mouseEvent.LatLng.Lat; | this.bicycleGeoPosition.Latitude = mouseEvent.LatLng.Lat; | ||||
| this.bicycleGeoPosition.Longitude = mouseEvent.LatLng.Lng; | this.bicycleGeoPosition.Longitude = mouseEvent.LatLng.Lng; | ||||
| NominatimReverseAddress addressDto = await nominatimService.GetAddressForCoordinates(mouseEvent.LatLng.Lat, mouseEvent.LatLng.Lng); | |||||
| NominatimReverseAddress addressDto = await NominatimService.GetAddressForCoordinates(mouseEvent.LatLng.Lat, mouseEvent.LatLng.Lng); | |||||
| if (addressDto != null) { | if (addressDto != null) { | ||||
| this.bicycleGeoPosition.Address = getFormattedAddressStreet(addressDto); | |||||
| this.bicycleGeoPosition.City = getFormattedAddressZipAndTown(addressDto); | |||||
| this.bicycleGeoPosition.Address = GetFormattedAddressStreet(addressDto); | |||||
| this.bicycleGeoPosition.City = GetFormattedAddressZipAndTown(addressDto); | |||||
| } else { | } else { | ||||
| Show(MatBlazor.MatToastType.Warning, I18n.GetString("Warning.Nominatim.Title"), I18n.GetString("Warning.Nominatim.Msg")); | Show(MatBlazor.MatToastType.Warning, I18n.GetString("Warning.Nominatim.Title"), I18n.GetString("Warning.Nominatim.Msg")); | ||||
| } | } | ||||
| this.bicyclePositionMarker = await this.MarkerFactory.CreateAndAddToMap(mouseEvent.LatLng, this.mapRef, this.bicycleMarkerOptions); | this.bicyclePositionMarker = await this.MarkerFactory.CreateAndAddToMap(mouseEvent.LatLng, this.mapRef, this.bicycleMarkerOptions); | ||||
| } | } | ||||
| private String getFormattedAddressStreet(NominatimReverseAddress addressDto) { | |||||
| String street = addressDto.address.road; | |||||
| String houseNr = addressDto.address.house_number != null ? addressDto.address.house_number : ""; | |||||
| private static string GetFormattedAddressStreet(NominatimReverseAddress addressDto) { | |||||
| string street = addressDto.address.road; | |||||
| string houseNr = addressDto.address.house_number ?? ""; | |||||
| return street + (!houseNr.Equals("") ? " " + houseNr : ""); | return street + (!houseNr.Equals("") ? " " + houseNr : ""); | ||||
| } | } | ||||
| private String getFormattedAddressZipAndTown(NominatimReverseAddress addressDto) { | |||||
| String country_code = addressDto.address.country_code; | |||||
| String zip = addressDto.address.postcode.Split("-", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)[0]; | |||||
| String town = addressDto.address.town; | |||||
| private static string GetFormattedAddressZipAndTown(NominatimReverseAddress addressDto) { | |||||
| string country_code = addressDto.address.country_code; | |||||
| string zip = addressDto.address.postcode.Split("-", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)[0]; | |||||
| string town = addressDto.address.town; | |||||
| return !String.IsNullOrEmpty(country_code) ? country_code.ToUpper() + "-" + zip + " " + town : zip + " " + town; | return !String.IsNullOrEmpty(country_code) ? country_code.ToUpper() + "-" + zip + " " + town : zip + " " + town; | ||||
| } | } |
| <img src="./images/caritas_logo.png" style="padding:1em;max-width:320px" class="w-100" alt=""> | <img src="./images/caritas_logo.png" style="padding:1em;max-width:320px" class="w-100" alt=""> | ||||
| </div> | </div> | ||||
| <div class="row align-items-center vw-100 h-75"> | |||||
| <div class="row align-items-end vw-100 h-50"> | |||||
| <div class="col text-center"> | <div class="col text-center"> | ||||
| <h3 style="font-style:italic;padding-bottom:1em">@i18n["Welcome"]</h3> | <h3 style="font-style:italic;padding-bottom:1em">@i18n["Welcome"]</h3> | ||||
| <div> | <div> | ||||
| <MatButton Raised="true" Style="width:50%" @onclick="@((e) => ButtonClicked())">@i18n["Login"]</MatButton> | |||||
| <MatButton Disabled="@btnDisabled" Raised="true" Style="width:50%" @onclick="@((e) => ButtonClicked())">@i18n["Login"]</MatButton> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div class="row align-items-center justify-content-center vw-100 h-25"> | |||||
| <div> | |||||
| @if(showProgressCircle) { | |||||
| <MatProgressCircle Indeterminate="true" Size="MatProgressCircleSize.Large" Style="padding-left:1.2rem" /> | |||||
| <h6 style="font-style:italic;padding-bottom:1em">@i18n["Initializing..."]</h6> | |||||
| } | |||||
| </div> | |||||
| </div> | |||||
| </div> | </div> | ||||
| @code { | @code { | ||||
| private bool btnDisabled = true; | |||||
| private bool showProgressCircle = true; | |||||
| protected async override void OnInitialized() { | protected async override void OnInitialized() { | ||||
| await MasterDataService.SynchronizeMasterdata(); | |||||
| PageHistoryManager.Reset(); | |||||
| base.OnInitialized(); | base.OnInitialized(); | ||||
| if (MasterDataService.FirstActivation) { | |||||
| Console.WriteLine("First activation"); | |||||
| showProgressCircle = true; | |||||
| StateHasChanged(); | |||||
| await MasterDataService.SynchronizeMasterdata(); | |||||
| showProgressCircle = false; | |||||
| } | |||||
| btnDisabled = false; | |||||
| PageHistoryManager.Reset(); | |||||
| StateHasChanged(); | |||||
| } | } | ||||
| public class BicycleType { | public class BicycleType { | ||||
| public int Id { get; set; } | public int Id { get; set; } | ||||
| public string Type { get; set; } | |||||
| public string Bezeichnung { get; set; } | |||||
| public BicycleType() { } | public BicycleType() { } | ||||
| public BicycleType(int id, string type) { | public BicycleType(int id, string type) { | ||||
| Id = id; | Id = id; | ||||
| Type = type; | |||||
| Bezeichnung = type; | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| public class Brand { | public class Brand { | ||||
| public int Id { get; set; } | public int Id { get; set; } | ||||
| public string Name { get; set; } | |||||
| public string Bezeichnung { get; set; } | |||||
| public Brand() { } | public Brand() { } | ||||
| public Brand(int id, string name) { | public Brand(int id, string name) { | ||||
| Id = id; | Id = id; | ||||
| Name = name; | |||||
| Bezeichnung = name; | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| public class ColorItem { | public class ColorItem { | ||||
| public int Index { get; set; } | |||||
| public string Name { get; set; } | |||||
| public string RGB { get; set; } | |||||
| public int Id { get; set; } | |||||
| public string Bezeichnung { get; set; } | |||||
| public string Code { get; set; } | |||||
| public ColorItem() { } | public ColorItem() { } | ||||
| public ColorItem(int index, string name, string rgb) { | public ColorItem(int index, string name, string rgb) { | ||||
| Index = index; | |||||
| Name = name; | |||||
| RGB = rgb; | |||||
| Id = index; | |||||
| Bezeichnung = name; | |||||
| Code = rgb; | |||||
| } | } | ||||
| } | } | ||||
| namespace CaritasPWA.Shared.Models { | |||||
| using CaritasPWA.Shared.ResourceFiles; | |||||
| using Microsoft.Extensions.Localization; | |||||
| using System.Collections.Generic; | |||||
| namespace CaritasPWA.Shared.Models { | |||||
| public class Defaults { | public class Defaults { | ||||
| public static readonly ColorItem[] ColorItems = { | |||||
| new ColorItem(3, "Blue","0,0,255"), | |||||
| new ColorItem(14, "Brown", "165,42,42"), | |||||
| new ColorItem(4, "Yellow", "255, 255, 0"), | |||||
| new ColorItem(8, "Grey", "128, 128, 128"), | |||||
| new ColorItem(2, "Green", "0, 128, 0"), | |||||
| new ColorItem(9, "Indigo", "75, 0, 130"), | |||||
| new ColorItem(11, "Purple", "128, 0, 128"), | |||||
| new ColorItem(6, "Orange", "255, 165, 0"), | |||||
| new ColorItem(13, "Pink", "255, 192, 203"), | |||||
| new ColorItem(1, "Red", "255, 0, 0"), | |||||
| new ColorItem(5, "Black", "0, 0, 0"), | |||||
| new ColorItem(12, "Turquoise", "64, 224, 208"), | |||||
| new ColorItem(10, "Violet", "238, 130, 238"), | |||||
| new ColorItem(7, "White", "255, 255, 255"), | |||||
| private static readonly ColorItem[] ColorItems = { | |||||
| new ColorItem(0, "n_d", "#FFFFFF"), | |||||
| new ColorItem(1, "Red", "#FF0000"), | |||||
| new ColorItem(2, "Green", "#008000"), | |||||
| new ColorItem(3, "Blue", "#0000FF"), | |||||
| new ColorItem(4, "Yellow", "#FFFF00"), | |||||
| new ColorItem(5, "Black", "#000000"), | |||||
| new ColorItem(6, "Orange", "#FFA500"), | |||||
| new ColorItem(7, "White", "#FFFFFF"), | |||||
| new ColorItem(8, "Grey", "#808080"), | |||||
| new ColorItem(9, "Indigo", "#4B0082"), | |||||
| new ColorItem(10, "Violet", "#EE82EE"), | |||||
| new ColorItem(11, "Purple", "#800080"), | |||||
| new ColorItem(12, "Turquoise", "#40E0D0"), | |||||
| new ColorItem(13, "Pink", "#FFC0CB"), | |||||
| new ColorItem(14, "Brown", "#A52A2A"), | |||||
| new ColorItem(15, "Beige", "#D1BC8A"), | |||||
| new ColorItem(16, "Anthracite", "#373F43"), | |||||
| new ColorItem(17, "Gold", "#E2B007"), | |||||
| new ColorItem(18, "Rose", "#FF69B4"), //??? | |||||
| new ColorItem(19, "Silver", "#C0C0C0") | |||||
| }; | }; | ||||
| public static readonly BicycleType[] BycicleTypes = { | |||||
| new BicycleType(1, "Men_Bycicle"), | |||||
| new BicycleType(2, "Women_Bycicle"), | |||||
| new BicycleType(3, "Child_Bycicle"), | |||||
| new BicycleType(4, "E_Bike"), | |||||
| new BicycleType(5, "Mountain_Bike"), | |||||
| new BicycleType(6,"City_Bike"), | |||||
| new BicycleType(7, "Tandem"), | |||||
| new BicycleType(8, "Trailer") | |||||
| private static readonly BicycleType[] BycicleTypes = { | |||||
| new BicycleType(0, "n_d"), | |||||
| new BicycleType(1, "City_Bike"), | |||||
| new BicycleType(2, "Mountain_Bike"), | |||||
| new BicycleType(3, "Touring_Bike"), | |||||
| new BicycleType(4, "Tricycle"), | |||||
| new BicycleType(5, "E_Bike"), | |||||
| new BicycleType(6, "Tandem"), | |||||
| new BicycleType(7, "Men_Bycicle"), | |||||
| new BicycleType(8, "Women_Bycicle"), | |||||
| new BicycleType(9, "Child_Bycicle"), | |||||
| new BicycleType(10, "Trailer"), | |||||
| new BicycleType(11, "Kickboard") | |||||
| }; | }; | ||||
| public static readonly Brand[] Brands = { | |||||
| private static readonly Brand[] Brands = { | |||||
| new Brand(0, "n_d"), | |||||
| new Brand(1, "Mondia"), | new Brand(1, "Mondia"), | ||||
| new Brand(2, "Leopard"), | |||||
| new Brand(3, "Cilo"), | |||||
| new Brand(4, "Kettler") | |||||
| new Brand(2, "Cilo"), | |||||
| new Brand(3, "Cresta"), | |||||
| new Brand(4, "Stromer"), | |||||
| new Brand(5, "Ibex"), | |||||
| new Brand(6, "Bikester"), | |||||
| new Brand(7, "Tour de Suisse"), | |||||
| new Brand(8, "Cube"), | |||||
| new Brand(9, "Specialized"), | |||||
| new Brand(10, "Totem"), | |||||
| new Brand(11, "Apollo"), | |||||
| new Brand(12, "Avanti"), | |||||
| new Brand(13, "Bianchi"), | |||||
| new Brand(14, "Cannondale"), | |||||
| new Brand(15, "Felt"), | |||||
| new Brand(16, "Yeti"), | |||||
| new Brand(17, "Titan"), | |||||
| new Brand(18, "Giant"), | |||||
| new Brand(19, "Fuji"), | |||||
| new Brand(20, "Klein"), | |||||
| new Brand(21, "Raleigh"), | |||||
| new Brand(22, "Merida"), | |||||
| new Brand(23, "Trek"), | |||||
| new Brand(24, "Huffy"), | |||||
| new Brand(25, "Magna"), | |||||
| new Brand(26, "Scott"), | |||||
| new Brand(27, "Mongoose"), | |||||
| new Brand(28, "BMC"), | |||||
| new Brand(29, "Kona"), | |||||
| new Brand(30, "Schwinn"), | |||||
| new Brand(31, "Silverback"), | |||||
| new Brand(32, "Diamondback"), | |||||
| new Brand(33, "Pinarello"), | |||||
| new Brand(34, "Fox"), | |||||
| new Brand(35, "GT") | |||||
| }; | }; | ||||
| public static List<ColorItem> GetColorDefaults(IStringLocalizer<Resources> _i18n) { | |||||
| List<ColorItem> colors = new(); | |||||
| foreach (ColorItem color in ColorItems) { | |||||
| colors.Add(new ColorItem(color.Id, _i18n.GetString("Color." + color.Bezeichnung), color.Code)); | |||||
| } | |||||
| return colors; | |||||
| } | |||||
| public static List<BicycleType> GetBicycleTypeDefaults(IStringLocalizer<Resources> _i18n) { | |||||
| List<BicycleType> bicycleTypes = new(); | |||||
| foreach (BicycleType bct in Defaults.BycicleTypes) { | |||||
| bicycleTypes.Add(new BicycleType(bct.Id, _i18n.GetString("Bike." + bct.Bezeichnung))); | |||||
| } | |||||
| return bicycleTypes; | |||||
| } | |||||
| public static List<Brand> GetBrandDefaults(IStringLocalizer<Resources> _i18n) { | |||||
| List<Brand> brands = new(); | |||||
| foreach (Brand brand in Brands) { | |||||
| brands.Add(new Brand(brand.Id, brand.Id == 0 ? _i18n.GetString("Brand." + brand.Bezeichnung): brand.Bezeichnung)); | |||||
| } | |||||
| return brands; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| /// Sucht eine lokalisierte Zeichenfolge, die Type ähnelt. | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die Bezeichnung ähnelt. | |||||
| /// </summary> | /// </summary> | ||||
| public static string Type { | public static string Type { | ||||
| get { | get { |
| <data name="Bike.E_Bike" xml:space="preserve"> | <data name="Bike.E_Bike" xml:space="preserve"> | ||||
| <value>E-Bike</value> | <value>E-Bike</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Kickboard" xml:space="preserve"> | |||||
| <value>Kickboard</value> | |||||
| </data> | |||||
| <data name="Bike.Men_Bycicle" xml:space="preserve"> | <data name="Bike.Men_Bycicle" xml:space="preserve"> | ||||
| <value>Herrenvelo</value> | <value>Herrenvelo</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Mountain_Bike" xml:space="preserve"> | <data name="Bike.Mountain_Bike" xml:space="preserve"> | ||||
| <value>Mountain-Bike</value> | <value>Mountain-Bike</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.n_d" xml:space="preserve"> | |||||
| <value>Nicht definiert</value> | |||||
| </data> | |||||
| <data name="Bike.Tandem" xml:space="preserve"> | <data name="Bike.Tandem" xml:space="preserve"> | ||||
| <value>Tandem</value> | <value>Tandem</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Touring_Bike" xml:space="preserve"> | |||||
| <value>Touring-Bike</value> | |||||
| </data> | |||||
| <data name="Bike.Trailer" xml:space="preserve"> | <data name="Bike.Trailer" xml:space="preserve"> | ||||
| <value>Anhänger</value> | <value>Anhänger</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Tricycle" xml:space="preserve"> | |||||
| <value>Dreirad</value> | |||||
| </data> | |||||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | <data name="Bike.Women_Bycicle" xml:space="preserve"> | ||||
| <value>Damenvelo</value> | <value>Damenvelo</value> | ||||
| </data> | </data> | ||||
| <data name="Brand" xml:space="preserve"> | <data name="Brand" xml:space="preserve"> | ||||
| <value>Marke</value> | <value>Marke</value> | ||||
| </data> | </data> | ||||
| <data name="Brand.n_d" xml:space="preserve"> | |||||
| <value>Nicht definiert</value> | |||||
| </data> | |||||
| <data name="Cancel" xml:space="preserve"> | <data name="Cancel" xml:space="preserve"> | ||||
| <value>Abbrechen</value> | <value>Abbrechen</value> | ||||
| </data> | </data> | ||||
| <data name="Color" xml:space="preserve"> | <data name="Color" xml:space="preserve"> | ||||
| <value>Farbe</value> | <value>Farbe</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Anthracite" xml:space="preserve"> | |||||
| <value>Anthrazit</value> | |||||
| </data> | |||||
| <data name="Color.Beige" xml:space="preserve"> | |||||
| <value>Beige</value> | |||||
| </data> | |||||
| <data name="Color.Black" xml:space="preserve"> | <data name="Color.Black" xml:space="preserve"> | ||||
| <value>Schwarz</value> | <value>Schwarz</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Brown" xml:space="preserve"> | <data name="Color.Brown" xml:space="preserve"> | ||||
| <value>Braun</value> | <value>Braun</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Gold" xml:space="preserve"> | |||||
| <value>Gold</value> | |||||
| </data> | |||||
| <data name="Color.Green" xml:space="preserve"> | <data name="Color.Green" xml:space="preserve"> | ||||
| <value>Grün</value> | <value>Grün</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Indigo" xml:space="preserve"> | <data name="Color.Indigo" xml:space="preserve"> | ||||
| <value>Indigo</value> | <value>Indigo</value> | ||||
| </data> | </data> | ||||
| <data name="Color.n_d" xml:space="preserve"> | |||||
| <value>Nicht definiert</value> | |||||
| </data> | |||||
| <data name="Color.Orange" xml:space="preserve"> | <data name="Color.Orange" xml:space="preserve"> | ||||
| <value>Orange</value> | <value>Orange</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Pink" xml:space="preserve"> | <data name="Color.Pink" xml:space="preserve"> | ||||
| <value>Rosa</value> | |||||
| <value>Pink</value> | |||||
| </data> | </data> | ||||
| <data name="Color.Purple" xml:space="preserve"> | <data name="Color.Purple" xml:space="preserve"> | ||||
| <value>Purpur</value> | <value>Purpur</value> | ||||
| <data name="Color.Red" xml:space="preserve"> | <data name="Color.Red" xml:space="preserve"> | ||||
| <value>Rot</value> | <value>Rot</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Rose" xml:space="preserve"> | |||||
| <value>Rosa</value> | |||||
| </data> | |||||
| <data name="Color.Silver" xml:space="preserve"> | |||||
| <value>Silber</value> | |||||
| </data> | |||||
| <data name="Color.Turquoise" xml:space="preserve"> | <data name="Color.Turquoise" xml:space="preserve"> | ||||
| <value>Türkis</value> | <value>Türkis</value> | ||||
| </data> | </data> |
| <data name="Bike.E_Bike" xml:space="preserve"> | <data name="Bike.E_Bike" xml:space="preserve"> | ||||
| <value>E-Bike</value> | <value>E-Bike</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Kickboard" xml:space="preserve"> | |||||
| <value>Kickboard</value> | |||||
| </data> | |||||
| <data name="Bike.Men_Bycicle" xml:space="preserve"> | <data name="Bike.Men_Bycicle" xml:space="preserve"> | ||||
| <value>Vélo pour hommes</value> | <value>Vélo pour hommes</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Mountain_Bike" xml:space="preserve"> | <data name="Bike.Mountain_Bike" xml:space="preserve"> | ||||
| <value>Mountain-Bike</value> | <value>Mountain-Bike</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.n_d" xml:space="preserve"> | |||||
| <value>Ne pas definé</value> | |||||
| </data> | |||||
| <data name="Bike.Tandem" xml:space="preserve"> | <data name="Bike.Tandem" xml:space="preserve"> | ||||
| <value>Tandem</value> | <value>Tandem</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Touring_Bike" xml:space="preserve"> | |||||
| <value>Touring_Bike</value> | |||||
| </data> | |||||
| <data name="Bike.Trailer" xml:space="preserve"> | <data name="Bike.Trailer" xml:space="preserve"> | ||||
| <value>Remorque</value> | <value>Remorque</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Tricycle" xml:space="preserve"> | |||||
| <value>Tricycle</value> | |||||
| </data> | |||||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | <data name="Bike.Women_Bycicle" xml:space="preserve"> | ||||
| <value>Vélo pour dames</value> | <value>Vélo pour dames</value> | ||||
| </data> | </data> | ||||
| <data name="Brand" xml:space="preserve"> | <data name="Brand" xml:space="preserve"> | ||||
| <value>Marque</value> | <value>Marque</value> | ||||
| </data> | </data> | ||||
| <data name="Brand.n_d" xml:space="preserve"> | |||||
| <value>Ne pas definé</value> | |||||
| </data> | |||||
| <data name="Cancel" xml:space="preserve"> | <data name="Cancel" xml:space="preserve"> | ||||
| <value>Annuler</value> | <value>Annuler</value> | ||||
| </data> | </data> | ||||
| <data name="Color" xml:space="preserve"> | <data name="Color" xml:space="preserve"> | ||||
| <value>Couleur</value> | <value>Couleur</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Anthracite" xml:space="preserve"> | |||||
| <value>Anthracite</value> | |||||
| </data> | |||||
| <data name="Color.Beige" xml:space="preserve"> | |||||
| <value>Beige</value> | |||||
| </data> | |||||
| <data name="Color.Black" xml:space="preserve"> | <data name="Color.Black" xml:space="preserve"> | ||||
| <value>Noir</value> | <value>Noir</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Brown" xml:space="preserve"> | <data name="Color.Brown" xml:space="preserve"> | ||||
| <value>Marron</value> | <value>Marron</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Gold" xml:space="preserve"> | |||||
| <value>Or</value> | |||||
| </data> | |||||
| <data name="Color.Green" xml:space="preserve"> | <data name="Color.Green" xml:space="preserve"> | ||||
| <value>Verde</value> | <value>Verde</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Indigo" xml:space="preserve"> | <data name="Color.Indigo" xml:space="preserve"> | ||||
| <value>Indigo</value> | <value>Indigo</value> | ||||
| </data> | </data> | ||||
| <data name="Color.n_d" xml:space="preserve"> | |||||
| <value>Ne pas definé</value> | |||||
| </data> | |||||
| <data name="Color.Orange" xml:space="preserve"> | <data name="Color.Orange" xml:space="preserve"> | ||||
| <value>Orange</value> | <value>Orange</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Red" xml:space="preserve"> | <data name="Color.Red" xml:space="preserve"> | ||||
| <value>Rouge</value> | <value>Rouge</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Rose" xml:space="preserve"> | |||||
| <value>Rose</value> | |||||
| </data> | |||||
| <data name="Color.Silver" xml:space="preserve"> | |||||
| <value>Argent</value> | |||||
| </data> | |||||
| <data name="Color.Turquoise" xml:space="preserve"> | <data name="Color.Turquoise" xml:space="preserve"> | ||||
| <value>Turquoise</value> | <value>Turquoise</value> | ||||
| </data> | </data> |
| <data name="Bike.E_Bike" xml:space="preserve"> | <data name="Bike.E_Bike" xml:space="preserve"> | ||||
| <value>E-Bike</value> | <value>E-Bike</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Kickboard" xml:space="preserve"> | |||||
| <value>Kickboard</value> | |||||
| </data> | |||||
| <data name="Bike.Men_Bycicle" xml:space="preserve"> | <data name="Bike.Men_Bycicle" xml:space="preserve"> | ||||
| <value>Bicicletta per uomo</value> | <value>Bicicletta per uomo</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Mountain_Bike" xml:space="preserve"> | <data name="Bike.Mountain_Bike" xml:space="preserve"> | ||||
| <value>Mountain-Bike</value> | <value>Mountain-Bike</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.n_d" xml:space="preserve"> | |||||
| <value>Non definito</value> | |||||
| </data> | |||||
| <data name="Bike.Tandem" xml:space="preserve"> | <data name="Bike.Tandem" xml:space="preserve"> | ||||
| <value>Tandem</value> | <value>Tandem</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Touring_Bike" xml:space="preserve"> | |||||
| <value>Bicicletta da Touring</value> | |||||
| </data> | |||||
| <data name="Bike.Trailer" xml:space="preserve"> | <data name="Bike.Trailer" xml:space="preserve"> | ||||
| <value>Rimorchio</value> | <value>Rimorchio</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Tricycle" xml:space="preserve"> | |||||
| <value>Triciclo</value> | |||||
| </data> | |||||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | <data name="Bike.Women_Bycicle" xml:space="preserve"> | ||||
| <value>Bicicletta per donna</value> | <value>Bicicletta per donna</value> | ||||
| </data> | </data> | ||||
| <data name="Brand" xml:space="preserve"> | <data name="Brand" xml:space="preserve"> | ||||
| <value>Marca</value> | <value>Marca</value> | ||||
| </data> | </data> | ||||
| <data name="Brand.n_d" xml:space="preserve"> | |||||
| <value>Non definito</value> | |||||
| </data> | |||||
| <data name="Cancel" xml:space="preserve"> | <data name="Cancel" xml:space="preserve"> | ||||
| <value>Annulla</value> | <value>Annulla</value> | ||||
| </data> | </data> | ||||
| <data name="Color" xml:space="preserve"> | <data name="Color" xml:space="preserve"> | ||||
| <value>Colore</value> | <value>Colore</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Anthracite" xml:space="preserve"> | |||||
| <value>Antracite</value> | |||||
| </data> | |||||
| <data name="Color.Beige" xml:space="preserve"> | |||||
| <value>Beige</value> | |||||
| </data> | |||||
| <data name="Color.Black" xml:space="preserve"> | <data name="Color.Black" xml:space="preserve"> | ||||
| <value>Nero</value> | <value>Nero</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Brown" xml:space="preserve"> | <data name="Color.Brown" xml:space="preserve"> | ||||
| <value>Marrone</value> | <value>Marrone</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Gold" xml:space="preserve"> | |||||
| <value>Oro</value> | |||||
| </data> | |||||
| <data name="Color.Green" xml:space="preserve"> | <data name="Color.Green" xml:space="preserve"> | ||||
| <value>Verde</value> | <value>Verde</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Indigo" xml:space="preserve"> | <data name="Color.Indigo" xml:space="preserve"> | ||||
| <value>Indigo</value> | <value>Indigo</value> | ||||
| </data> | </data> | ||||
| <data name="Color.n_d" xml:space="preserve"> | |||||
| <value>Non definito</value> | |||||
| </data> | |||||
| <data name="Color.Orange" xml:space="preserve"> | <data name="Color.Orange" xml:space="preserve"> | ||||
| <value>Arancione</value> | <value>Arancione</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Red" xml:space="preserve"> | <data name="Color.Red" xml:space="preserve"> | ||||
| <value>Rosso</value> | <value>Rosso</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Rose" xml:space="preserve"> | |||||
| <value>Rosa</value> | |||||
| </data> | |||||
| <data name="Color.Silver" xml:space="preserve"> | |||||
| <value>Argento</value> | |||||
| </data> | |||||
| <data name="Color.Turquoise" xml:space="preserve"> | <data name="Color.Turquoise" xml:space="preserve"> | ||||
| <value>Turchese</value> | <value>Turchese</value> | ||||
| </data> | </data> |
| <data name="Bike.E_Bike" xml:space="preserve"> | <data name="Bike.E_Bike" xml:space="preserve"> | ||||
| <value>E-Bike</value> | <value>E-Bike</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Kickboard" xml:space="preserve"> | |||||
| <value>Kickboard</value> | |||||
| </data> | |||||
| <data name="Bike.Men_Bycicle" xml:space="preserve"> | <data name="Bike.Men_Bycicle" xml:space="preserve"> | ||||
| <value>Men's Bycicle</value> | <value>Men's Bycicle</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Mountain_Bike" xml:space="preserve"> | <data name="Bike.Mountain_Bike" xml:space="preserve"> | ||||
| <value>Mountain-Bike</value> | <value>Mountain-Bike</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.n_d" xml:space="preserve"> | |||||
| <value>Not defined</value> | |||||
| </data> | |||||
| <data name="Bike.Tandem" xml:space="preserve"> | <data name="Bike.Tandem" xml:space="preserve"> | ||||
| <value>Tandem</value> | <value>Tandem</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Touring_Bike" xml:space="preserve"> | |||||
| <value>Touring_Bike</value> | |||||
| </data> | |||||
| <data name="Bike.Trailer" xml:space="preserve"> | <data name="Bike.Trailer" xml:space="preserve"> | ||||
| <value>Trailer</value> | <value>Trailer</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Tricycle" xml:space="preserve"> | |||||
| <value>Tricycle</value> | |||||
| </data> | |||||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | <data name="Bike.Women_Bycicle" xml:space="preserve"> | ||||
| <value>Women's Bycicle</value> | <value>Women's Bycicle</value> | ||||
| </data> | </data> | ||||
| <data name="Brand" xml:space="preserve"> | <data name="Brand" xml:space="preserve"> | ||||
| <value>Brand</value> | <value>Brand</value> | ||||
| </data> | </data> | ||||
| <data name="Brand.n_d" xml:space="preserve"> | |||||
| <value>Not defined</value> | |||||
| </data> | |||||
| <data name="Cancel" xml:space="preserve"> | <data name="Cancel" xml:space="preserve"> | ||||
| <value>Cancel</value> | <value>Cancel</value> | ||||
| </data> | </data> | ||||
| <data name="Color" xml:space="preserve"> | <data name="Color" xml:space="preserve"> | ||||
| <value>Color</value> | <value>Color</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Anthracite" xml:space="preserve"> | |||||
| <value>Anthracite</value> | |||||
| </data> | |||||
| <data name="Color.Beige" xml:space="preserve"> | |||||
| <value>Beige</value> | |||||
| </data> | |||||
| <data name="Color.Black" xml:space="preserve"> | <data name="Color.Black" xml:space="preserve"> | ||||
| <value>Black</value> | <value>Black</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Brown" xml:space="preserve"> | <data name="Color.Brown" xml:space="preserve"> | ||||
| <value>Brown</value> | <value>Brown</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Gold" xml:space="preserve"> | |||||
| <value>Gold</value> | |||||
| </data> | |||||
| <data name="Color.Green" xml:space="preserve"> | <data name="Color.Green" xml:space="preserve"> | ||||
| <value>Green</value> | <value>Green</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Indigo" xml:space="preserve"> | <data name="Color.Indigo" xml:space="preserve"> | ||||
| <value>Indigo</value> | <value>Indigo</value> | ||||
| </data> | </data> | ||||
| <data name="Color.n_d" xml:space="preserve"> | |||||
| <value>Not defined</value> | |||||
| </data> | |||||
| <data name="Color.Orange" xml:space="preserve"> | <data name="Color.Orange" xml:space="preserve"> | ||||
| <value>Orange</value> | <value>Orange</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Red" xml:space="preserve"> | <data name="Color.Red" xml:space="preserve"> | ||||
| <value>Red</value> | <value>Red</value> | ||||
| </data> | </data> | ||||
| <data name="Color.Rose" xml:space="preserve"> | |||||
| <value>Rose</value> | |||||
| </data> | |||||
| <data name="Color.Silver" xml:space="preserve"> | |||||
| <value>Silver</value> | |||||
| </data> | |||||
| <data name="Color.Turquoise" xml:space="preserve"> | <data name="Color.Turquoise" xml:space="preserve"> | ||||
| <value>Turquoise</value> | <value>Turquoise</value> | ||||
| </data> | </data> |
| using CaritasPWA.Shared.Models; | using CaritasPWA.Shared.Models; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Threading.Tasks; | |||||
| namespace CaritasPWA.Shared.Services { | namespace CaritasPWA.Shared.Services { | ||||
| public interface ILFBicycleRest { | public interface ILFBicycleRest { | ||||
| List<ColorItem> GetColors(); | |||||
| Task<List<ColorItem>> GetColors(); | |||||
| List<BicycleType> GetBicycleTypes(); | List<BicycleType> GetBicycleTypes(); | ||||
| using CaritasPWA.Shared.Models; | using CaritasPWA.Shared.Models; | ||||
| using CaritasPWA.Shared.ResourceFiles; | using CaritasPWA.Shared.ResourceFiles; | ||||
| using Json.Net; | |||||
| using Microsoft.Extensions.Localization; | using Microsoft.Extensions.Localization; | ||||
| using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Linq; | |||||
| using System.Globalization; | |||||
| using System.Net.Http; | |||||
| using System.Threading.Tasks; | |||||
| 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 masterdata. | ||||
| public class LFBicycleRest : ILFBicycleRest { | public class LFBicycleRest : ILFBicycleRest { | ||||
| private static readonly string VERSION = "v1"; | |||||
| private readonly IStringLocalizer<Resources> _i18n; | private readonly IStringLocalizer<Resources> _i18n; | ||||
| private readonly HttpClient httpClient; | |||||
| public LFBicycleRest(IStringLocalizer<Resources> i18n) { | public LFBicycleRest(IStringLocalizer<Resources> i18n) { | ||||
| _i18n = i18n; | _i18n = i18n; | ||||
| this.httpClient = new HttpClient { BaseAddress = new Uri("https://integrate.dynalias.net:9443/Fundvelo/") }; | |||||
| } | } | ||||
| public List<ColorItem> GetColors() { | |||||
| //return Defaults.ColorItems.ToList(); | |||||
| public async Task<List<ColorItem>> GetColors() { | |||||
| 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 | |||||
| } | |||||
| return new List<ColorItem>(); | return new List<ColorItem>(); | ||||
| } | } | ||||
| public List<BicycleType> GetBicycleTypes() { | public List<BicycleType> GetBicycleTypes() { | ||||
| List<BicycleType> bicycleTypes = new(); | |||||
| foreach (BicycleType bct in Defaults.BycicleTypes) { | |||||
| bicycleTypes.Add(new BicycleType(bct.Id, _i18n.GetString("Bike." + bct.Type))); | |||||
| } | |||||
| return bicycleTypes; | |||||
| //return new List<BicycleType>(); | |||||
| //return Defaults.GetBicycleTypeDefaults(_i18n); | |||||
| return new List<BicycleType>(); | |||||
| } | } | ||||
| public List<Brand> GetBrands() { | public List<Brand> GetBrands() { | ||||
| return Defaults.Brands.ToList(); | |||||
| //return new List<BicycleType>(); | |||||
| //return Defaults.Brands.ToList(); | |||||
| return new List<Brand>(); | |||||
| } | } | ||||
| } | } |
| using CaritasPWA.Shared.Models; | using CaritasPWA.Shared.Models; | ||||
| using CaritasPWA.Shared.ResourceFiles; | |||||
| using Json.Net; | |||||
| using Microsoft.Extensions.Localization; | |||||
| using Microsoft.JSInterop; | using Microsoft.JSInterop; | ||||
| using System; | using System; | ||||
| using System.Collections.Generic; | |||||
| using System.Runtime.CompilerServices; | |||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace CaritasPWA.Shared.Services { | namespace CaritasPWA.Shared.Services { | ||||
| private const string KeyNameBrands = "brands"; | private const string KeyNameBrands = "brands"; | ||||
| private readonly IJSRuntime _jsRuntime; | private readonly IJSRuntime _jsRuntime; | ||||
| private readonly IStringLocalizer<Resources> _i18n; | |||||
| private bool _initializedColors; | private bool _initializedColors; | ||||
| private bool _initializedBcTypes; | private bool _initializedBcTypes; | ||||
| private bool _initializedBrands; | private bool _initializedBrands; | ||||
| private bool _firstActivation; | |||||
| public bool FirstActivation { get => _firstActivation; } | |||||
| private ColorItem[] _colors; | private ColorItem[] _colors; | ||||
| private BicycleType[] _bicycleTypes; | private BicycleType[] _bicycleTypes; | ||||
| private Brand[] _brands; | private Brand[] _brands; | ||||
| public event EventHandler Changed; | public event EventHandler Changed; | ||||
| public MasterDataService(IJSRuntime jsRuntime, ILFBicycleRest lFBicycleRest) { | |||||
| public MasterDataService(IJSRuntime jsRuntime, ILFBicycleRest lFBicycleRest, IStringLocalizer<Resources> i18n) { | |||||
| _jsRuntime = jsRuntime; | _jsRuntime = jsRuntime; | ||||
| _lFBicycleRest = lFBicycleRest; | _lFBicycleRest = lFBicycleRest; | ||||
| _i18n = i18n; | |||||
| _firstActivation = true; | |||||
| } | } | ||||
| public async Task SynchronizeMasterdata() { | public async Task SynchronizeMasterdata() { | ||||
| await SynchronizeColors(); | await SynchronizeColors(); | ||||
| await SynchronizeBcTypes(); | await SynchronizeBcTypes(); | ||||
| await SynchronizeBrands(); | await SynchronizeBrands(); | ||||
| _firstActivation = false; | |||||
| } | } | ||||
| public async Task SynchronizeColors() { | public async Task SynchronizeColors() { | ||||
| Colors = _lFBicycleRest.GetColors().ToArray(); | |||||
| Colors = (await _lFBicycleRest.GetColors()).ToArray(); | |||||
| if (Colors != null && Colors.Length > 0) { | if (Colors != null && Colors.Length > 0) { | ||||
| await SaveColorsToStorage(); | await SaveColorsToStorage(); | ||||
| }; | }; | ||||
| 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.ColorItems; | |||||
| Colors = (colors != null && colors.Length > 0) ? colors: Defaults.GetColorDefaults(_i18n).ToArray(); | |||||
| 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.BycicleTypes; | |||||
| BicycleTypes = (bicycleTypes != null && bicycleTypes.Length > 0) ? bicycleTypes : Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | |||||
| BicycleTypes = SortBicycleTypes(new List<BicycleType>(BicycleTypes)).ToArray(); | |||||
| return BicycleTypes; | return BicycleTypes; | ||||
| } | } | ||||
| public async Task<BicycleType[]> GetBrands() { | |||||
| public async Task<Brand[]> GetBrands() { | |||||
| Brand[] brands = await GetBrandsFromStorage(); | Brand[] brands = await GetBrandsFromStorage(); | ||||
| Brands = (brands != null && brands.Length > 0) ? brands : Defaults.Brands; | |||||
| return BicycleTypes; | |||||
| Brands = (brands != null && brands.Length > 0) ? brands : Defaults.GetBrandDefaults(_i18n).ToArray(); | |||||
| Brands = SortBrands(new List<Brand>(Brands)).ToArray(); | |||||
| return Brands; | |||||
| } | |||||
| // This method is called from BlazorRegisterStorageEvent when the storage changed | |||||
| [JSInvokable] | |||||
| public void OnStorageUpdated(string key) { | |||||
| // Reset the settings. The next call to Get will reload the data | |||||
| if (key == KeyNameColors) { | |||||
| _colors = null; | |||||
| Changed?.Invoke(this, EventArgs.Empty); | |||||
| } else if (key == KeyNameBcTypes) { | |||||
| _bicycleTypes = null; | |||||
| Changed?.Invoke(this, EventArgs.Empty); | |||||
| } | |||||
| } | } | ||||
| private async ValueTask<ColorItem[]> GetColorsFromStorage() { | private async ValueTask<ColorItem[]> GetColorsFromStorage() { | ||||
| // Read the JSON string that contains the data from the local storage | // Read the JSON string that contains the data from the local storage | ||||
| ColorItem[] result; | ColorItem[] result; | ||||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameColors); | var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameColors); | ||||
| if (str != null) { | |||||
| result = System.Text.Json.JsonSerializer.Deserialize<ColorItem[]>(str) ?? Array.Empty<ColorItem>(); | |||||
| } else { | |||||
| if (String.IsNullOrEmpty(str)) { | |||||
| result = Array.Empty<ColorItem>(); | result = Array.Empty<ColorItem>(); | ||||
| } else { | |||||
| result = JsonNet.Deserialize<ColorItem[]>(str) ?? Array.Empty<ColorItem>(); | |||||
| } | } | ||||
| _colors = result; | _colors = result; | ||||
| return result; | return result; | ||||
| BicycleType[] result; | BicycleType[] result; | ||||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBcTypes); | var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBcTypes); | ||||
| if (str != null) { | if (str != null) { | ||||
| result = System.Text.Json.JsonSerializer.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>(); | |||||
| result = JsonNet.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>(); | |||||
| } else { | } else { | ||||
| result = Array.Empty<BicycleType>(); | result = Array.Empty<BicycleType>(); | ||||
| } | } | ||||
| Brand[] result; | Brand[] result; | ||||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBrands); | var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBrands); | ||||
| if (str != null) { | if (str != null) { | ||||
| result = System.Text.Json.JsonSerializer.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>(); | |||||
| result = JsonNet.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>(); | |||||
| } else { | } else { | ||||
| result = Array.Empty<Brand>(); | result = Array.Empty<Brand>(); | ||||
| } | } | ||||
| private async Task SaveColorsToStorage() { | private async Task SaveColorsToStorage() { | ||||
| var json = System.Text.Json.JsonSerializer.Serialize(_colors); | |||||
| var json = JsonNet.Serialize(_colors); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json); | await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json); | ||||
| } | } | ||||
| private async Task SaveBcTypesToStorage() { | private async Task SaveBcTypesToStorage() { | ||||
| var json = System.Text.Json.JsonSerializer.Serialize(_bicycleTypes); | |||||
| var json = JsonNet.Serialize(_bicycleTypes); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, json); | await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, json); | ||||
| } | } | ||||
| private async Task SaveBrandsToStorage() { | private async Task SaveBrandsToStorage() { | ||||
| var json = System.Text.Json.JsonSerializer.Serialize(_brands); | |||||
| var json = JsonNet.Serialize(_brands); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json); | await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json); | ||||
| } | } | ||||
| // This method is called from BlazorRegisterStorageEvent when the storage changed | |||||
| [JSInvokable] | |||||
| public void OnStorageUpdated(string key) { | |||||
| // Reset the settings. The next call to Get will reload the data | |||||
| if (key == KeyNameColors) { | |||||
| _colors = null; | |||||
| Changed?.Invoke(this, EventArgs.Empty); | |||||
| } else if (key == KeyNameBcTypes) { | |||||
| _bicycleTypes = null; | |||||
| Changed?.Invoke(this, EventArgs.Empty); | |||||
| } | |||||
| private static List<ColorItem> SortColors(List<ColorItem> cols) { | |||||
| cols.Sort(delegate (ColorItem c1, ColorItem c2) { return c1.Id == 0 ? -1 : c2.Id == 0 ? 1 : c1.Bezeichnung.CompareTo(c2.Bezeichnung); }); | |||||
| return cols; | |||||
| } | |||||
| private static List<BicycleType> SortBicycleTypes(List<BicycleType> bcTypes) { | |||||
| bcTypes.Sort(delegate (BicycleType bct1, BicycleType bct2) { return bct1.Id == 0 ? -1 : bct2.Id == 0 ? 1 : bct1.Bezeichnung.CompareTo(bct2.Bezeichnung); }); | |||||
| return bcTypes; | |||||
| } | |||||
| private static List<Brand> SortBrands(List<Brand> brands) { | |||||
| brands.Sort(delegate (Brand b1, Brand b2) { return b1.Id == 0 ? -1 : b2.Id == 0 ? 1 : b1.Bezeichnung.CompareTo(b2.Bezeichnung); }); | |||||
| return brands; | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| namespace CaritasPWA.Shared.Services { | namespace CaritasPWA.Shared.Services { | ||||
| public class NominatimService { | public class NominatimService { | ||||
| public async Task<NominatimReverseAddress> GetAddressForCoordinates(double latitude, double longitude) { | |||||
| public static async Task<NominatimReverseAddress> GetAddressForCoordinates(double latitude, double longitude) { | |||||
| string lat = latitude.ToString("0.0000000000", CultureInfo.InvariantCulture); | string lat = latitude.ToString("0.0000000000", CultureInfo.InvariantCulture); | ||||
| string lng = longitude.ToString("0.0000000000", CultureInfo.InvariantCulture); | string lng = longitude.ToString("0.0000000000", CultureInfo.InvariantCulture); | ||||
| HttpClient httpClient = new HttpClient { | |||||
| BaseAddress = new Uri("https://nominatim.openstreetmap.org/") | |||||
| }; | |||||
| HttpClient httpClient = new() { BaseAddress = new Uri("https://nominatim.openstreetmap.org/") }; | |||||
| try { | try { | ||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("reverse?format=json&lat={0}&lon={1}", lat, lng)); | HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("reverse?format=json&lat={0}&lon={1}", lat, lng)); | ||||