| @@ -111,21 +111,21 @@ | |||
| <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Color"]" @bind-Value="selectedColor" Items="@Colors" ValueSelector="@(i=>i)"> | |||
| <ItemTemplate> | |||
| <div> | |||
| <span class="btn-sm" style="background-color:rgb(@context.RGB); | |||
| <span class="btn-sm" style="background-color:@context.Code; | |||
| display:initial; | |||
| border:1px solid black; | |||
| 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> | |||
| </ItemTemplate> | |||
| </MatSelectValue> | |||
| </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="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> | |||
| <div> | |||
| <span>@context?.Name</span> | |||
| <span>@context?.Bezeichnung</span> | |||
| </div> | |||
| </ItemTemplate> | |||
| </MatAutocompleteList> | |||
| @@ -135,7 +135,7 @@ | |||
| <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Type"]" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)"> | |||
| <ItemTemplate> | |||
| <div> | |||
| <span>@context?.Type</span> | |||
| <span>@context?.Bezeichnung</span> | |||
| </div> | |||
| </ItemTemplate> | |||
| </MatSelectValue> | |||
| @@ -180,14 +180,11 @@ | |||
| } | |||
| 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 GetBicycleTypes(); | |||
| await GetBrands(); | |||
| PageHistoryManager.AddPageToHistory(NavigationManager.Uri); | |||
| base.OnInitialized(); | |||
| } | |||
| private Brand getBrand(Brand brand) { | |||
| @@ -195,10 +192,12 @@ | |||
| } | |||
| 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() { | |||
| @@ -28,7 +28,7 @@ namespace CaritasPWA.Pages { | |||
| private IIconFactory IconFactory { get; init; } | |||
| [Inject] | |||
| private BlazorGeolocationService blazorGeolocationService { get; init; } | |||
| private BlazorGeolocationService BlazorGeolocationService { get; init; } | |||
| [Inject] | |||
| private MatBlazor.IMatToaster Toaster { get; init; } | |||
| @@ -36,7 +36,7 @@ namespace CaritasPWA.Pages { | |||
| [Inject] | |||
| private IStringLocalizer<Resources> I18n { get; init; } | |||
| private NominatimService nominatimService { get; set; } | |||
| private NominatimService NominatimService { get; set; } | |||
| public CaritasServiceFundVeloKeyDataPageBase() : base() { | |||
| @@ -56,7 +56,7 @@ namespace CaritasPWA.Pages { | |||
| }; | |||
| this.bicycleGeoPosition = new(); | |||
| this.nominatimService = new NominatimService(); | |||
| this.NominatimService = new NominatimService(); | |||
| } | |||
| protected void Show(MatBlazor.MatToastType type, string title, string message, string icon = "") { | |||
| @@ -68,12 +68,12 @@ namespace CaritasPWA.Pages { | |||
| } | |||
| protected async Task InitializeMapPosition() { | |||
| createBicycleMarkerOptions(); | |||
| CreateBicycleMarkerOptions(); | |||
| await AddEventsToMap(); | |||
| await ShowDeviceGeoLocation(); | |||
| } | |||
| private async void createBicycleMarkerOptions() { | |||
| private async void CreateBicycleMarkerOptions() { | |||
| this.bicycleMarkerOptions = new MarkerOptions() { | |||
| IconRef = await this.IconFactory.Create(new IconOptions() { | |||
| IconUrl = "./icons/bicycle_location.png", | |||
| @@ -87,7 +87,7 @@ namespace CaritasPWA.Pages { | |||
| } | |||
| private async Task ShowDeviceGeoLocation() { | |||
| BlazorGeolocationPosition position = await this.blazorGeolocationService.GetPositionAsync(); | |||
| BlazorGeolocationPosition position = await this.BlazorGeolocationService.GetPositionAsync(); | |||
| if (position.ErrorCode != null) { | |||
| Show(MatBlazor.MatToastType.Danger, I18n.GetString("Error.GeoLocation.Title", position.ErrorCode), I18n.GetString("Error.GeoLocation.Msg", position.ErrorMessage)); | |||
| } else { | |||
| @@ -109,10 +109,10 @@ namespace CaritasPWA.Pages { | |||
| this.bicycleGeoPosition.Latitude = mouseEvent.LatLng.Lat; | |||
| 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) { | |||
| this.bicycleGeoPosition.Address = getFormattedAddressStreet(addressDto); | |||
| this.bicycleGeoPosition.City = getFormattedAddressZipAndTown(addressDto); | |||
| this.bicycleGeoPosition.Address = GetFormattedAddressStreet(addressDto); | |||
| this.bicycleGeoPosition.City = GetFormattedAddressZipAndTown(addressDto); | |||
| } else { | |||
| Show(MatBlazor.MatToastType.Warning, I18n.GetString("Warning.Nominatim.Title"), I18n.GetString("Warning.Nominatim.Msg")); | |||
| } | |||
| @@ -127,17 +127,17 @@ namespace CaritasPWA.Pages { | |||
| 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 : ""); | |||
| } | |||
| 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; | |||
| } | |||
| @@ -12,23 +12,42 @@ | |||
| <img src="./images/caritas_logo.png" style="padding:1em;max-width:320px" class="w-100" alt=""> | |||
| </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"> | |||
| <h3 style="font-style:italic;padding-bottom:1em">@i18n["Welcome"]</h3> | |||
| <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 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> | |||
| @code { | |||
| private bool btnDisabled = true; | |||
| private bool showProgressCircle = true; | |||
| protected async override void OnInitialized() { | |||
| await MasterDataService.SynchronizeMasterdata(); | |||
| PageHistoryManager.Reset(); | |||
| base.OnInitialized(); | |||
| if (MasterDataService.FirstActivation) { | |||
| Console.WriteLine("First activation"); | |||
| showProgressCircle = true; | |||
| StateHasChanged(); | |||
| await MasterDataService.SynchronizeMasterdata(); | |||
| showProgressCircle = false; | |||
| } | |||
| btnDisabled = false; | |||
| PageHistoryManager.Reset(); | |||
| StateHasChanged(); | |||
| } | |||
| @@ -2,13 +2,13 @@ | |||
| public class BicycleType { | |||
| public int Id { get; set; } | |||
| public string Type { get; set; } | |||
| public string Bezeichnung { get; set; } | |||
| public BicycleType() { } | |||
| public BicycleType(int id, string type) { | |||
| Id = id; | |||
| Type = type; | |||
| Bezeichnung = type; | |||
| } | |||
| } | |||
| } | |||
| @@ -2,13 +2,13 @@ | |||
| public class Brand { | |||
| public int Id { get; set; } | |||
| public string Name { get; set; } | |||
| public string Bezeichnung { get; set; } | |||
| public Brand() { } | |||
| public Brand(int id, string name) { | |||
| Id = id; | |||
| Name = name; | |||
| Bezeichnung = name; | |||
| } | |||
| } | |||
| } | |||
| @@ -2,16 +2,16 @@ | |||
| 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(int index, string name, string rgb) { | |||
| Index = index; | |||
| Name = name; | |||
| RGB = rgb; | |||
| Id = index; | |||
| Bezeichnung = name; | |||
| Code = rgb; | |||
| } | |||
| } | |||
| @@ -1,42 +1,114 @@ | |||
| namespace CaritasPWA.Shared.Models { | |||
| using CaritasPWA.Shared.ResourceFiles; | |||
| using Microsoft.Extensions.Localization; | |||
| using System.Collections.Generic; | |||
| namespace CaritasPWA.Shared.Models { | |||
| 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(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; | |||
| } | |||
| } | |||
| } | |||
| @@ -673,7 +673,7 @@ namespace CaritasPWA.Shared.ResourceFiles { | |||
| } | |||
| /// <summary> | |||
| /// Sucht eine lokalisierte Zeichenfolge, die Type ähnelt. | |||
| /// Sucht eine lokalisierte Zeichenfolge, die Bezeichnung ähnelt. | |||
| /// </summary> | |||
| public static string Type { | |||
| get { | |||
| @@ -135,24 +135,39 @@ | |||
| <data name="Bike.E_Bike" xml:space="preserve"> | |||
| <value>E-Bike</value> | |||
| </data> | |||
| <data name="Bike.Kickboard" xml:space="preserve"> | |||
| <value>Kickboard</value> | |||
| </data> | |||
| <data name="Bike.Men_Bycicle" xml:space="preserve"> | |||
| <value>Herrenvelo</value> | |||
| </data> | |||
| <data name="Bike.Mountain_Bike" xml:space="preserve"> | |||
| <value>Mountain-Bike</value> | |||
| </data> | |||
| <data name="Bike.n_d" xml:space="preserve"> | |||
| <value>Nicht definiert</value> | |||
| </data> | |||
| <data name="Bike.Tandem" xml:space="preserve"> | |||
| <value>Tandem</value> | |||
| </data> | |||
| <data name="Bike.Touring_Bike" xml:space="preserve"> | |||
| <value>Touring-Bike</value> | |||
| </data> | |||
| <data name="Bike.Trailer" xml:space="preserve"> | |||
| <value>Anhänger</value> | |||
| </data> | |||
| <data name="Bike.Tricycle" xml:space="preserve"> | |||
| <value>Dreirad</value> | |||
| </data> | |||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | |||
| <value>Damenvelo</value> | |||
| </data> | |||
| <data name="Brand" xml:space="preserve"> | |||
| <value>Marke</value> | |||
| </data> | |||
| <data name="Brand.n_d" xml:space="preserve"> | |||
| <value>Nicht definiert</value> | |||
| </data> | |||
| <data name="Cancel" xml:space="preserve"> | |||
| <value>Abbrechen</value> | |||
| </data> | |||
| @@ -168,6 +183,12 @@ | |||
| <data name="Color" xml:space="preserve"> | |||
| <value>Farbe</value> | |||
| </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"> | |||
| <value>Schwarz</value> | |||
| </data> | |||
| @@ -177,6 +198,9 @@ | |||
| <data name="Color.Brown" xml:space="preserve"> | |||
| <value>Braun</value> | |||
| </data> | |||
| <data name="Color.Gold" xml:space="preserve"> | |||
| <value>Gold</value> | |||
| </data> | |||
| <data name="Color.Green" xml:space="preserve"> | |||
| <value>Grün</value> | |||
| </data> | |||
| @@ -186,11 +210,14 @@ | |||
| <data name="Color.Indigo" xml:space="preserve"> | |||
| <value>Indigo</value> | |||
| </data> | |||
| <data name="Color.n_d" xml:space="preserve"> | |||
| <value>Nicht definiert</value> | |||
| </data> | |||
| <data name="Color.Orange" xml:space="preserve"> | |||
| <value>Orange</value> | |||
| </data> | |||
| <data name="Color.Pink" xml:space="preserve"> | |||
| <value>Rosa</value> | |||
| <value>Pink</value> | |||
| </data> | |||
| <data name="Color.Purple" xml:space="preserve"> | |||
| <value>Purpur</value> | |||
| @@ -198,6 +225,12 @@ | |||
| <data name="Color.Red" xml:space="preserve"> | |||
| <value>Rot</value> | |||
| </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"> | |||
| <value>Türkis</value> | |||
| </data> | |||
| @@ -135,24 +135,39 @@ | |||
| <data name="Bike.E_Bike" xml:space="preserve"> | |||
| <value>E-Bike</value> | |||
| </data> | |||
| <data name="Bike.Kickboard" xml:space="preserve"> | |||
| <value>Kickboard</value> | |||
| </data> | |||
| <data name="Bike.Men_Bycicle" xml:space="preserve"> | |||
| <value>Vélo pour hommes</value> | |||
| </data> | |||
| <data name="Bike.Mountain_Bike" xml:space="preserve"> | |||
| <value>Mountain-Bike</value> | |||
| </data> | |||
| <data name="Bike.n_d" xml:space="preserve"> | |||
| <value>Ne pas definé</value> | |||
| </data> | |||
| <data name="Bike.Tandem" xml:space="preserve"> | |||
| <value>Tandem</value> | |||
| </data> | |||
| <data name="Bike.Touring_Bike" xml:space="preserve"> | |||
| <value>Touring_Bike</value> | |||
| </data> | |||
| <data name="Bike.Trailer" xml:space="preserve"> | |||
| <value>Remorque</value> | |||
| </data> | |||
| <data name="Bike.Tricycle" xml:space="preserve"> | |||
| <value>Tricycle</value> | |||
| </data> | |||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | |||
| <value>Vélo pour dames</value> | |||
| </data> | |||
| <data name="Brand" xml:space="preserve"> | |||
| <value>Marque</value> | |||
| </data> | |||
| <data name="Brand.n_d" xml:space="preserve"> | |||
| <value>Ne pas definé</value> | |||
| </data> | |||
| <data name="Cancel" xml:space="preserve"> | |||
| <value>Annuler</value> | |||
| </data> | |||
| @@ -168,6 +183,12 @@ | |||
| <data name="Color" xml:space="preserve"> | |||
| <value>Couleur</value> | |||
| </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"> | |||
| <value>Noir</value> | |||
| </data> | |||
| @@ -177,6 +198,9 @@ | |||
| <data name="Color.Brown" xml:space="preserve"> | |||
| <value>Marron</value> | |||
| </data> | |||
| <data name="Color.Gold" xml:space="preserve"> | |||
| <value>Or</value> | |||
| </data> | |||
| <data name="Color.Green" xml:space="preserve"> | |||
| <value>Verde</value> | |||
| </data> | |||
| @@ -186,6 +210,9 @@ | |||
| <data name="Color.Indigo" xml:space="preserve"> | |||
| <value>Indigo</value> | |||
| </data> | |||
| <data name="Color.n_d" xml:space="preserve"> | |||
| <value>Ne pas definé</value> | |||
| </data> | |||
| <data name="Color.Orange" xml:space="preserve"> | |||
| <value>Orange</value> | |||
| </data> | |||
| @@ -198,6 +225,12 @@ | |||
| <data name="Color.Red" xml:space="preserve"> | |||
| <value>Rouge</value> | |||
| </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"> | |||
| <value>Turquoise</value> | |||
| </data> | |||
| @@ -135,24 +135,39 @@ | |||
| <data name="Bike.E_Bike" xml:space="preserve"> | |||
| <value>E-Bike</value> | |||
| </data> | |||
| <data name="Bike.Kickboard" xml:space="preserve"> | |||
| <value>Kickboard</value> | |||
| </data> | |||
| <data name="Bike.Men_Bycicle" xml:space="preserve"> | |||
| <value>Bicicletta per uomo</value> | |||
| </data> | |||
| <data name="Bike.Mountain_Bike" xml:space="preserve"> | |||
| <value>Mountain-Bike</value> | |||
| </data> | |||
| <data name="Bike.n_d" xml:space="preserve"> | |||
| <value>Non definito</value> | |||
| </data> | |||
| <data name="Bike.Tandem" xml:space="preserve"> | |||
| <value>Tandem</value> | |||
| </data> | |||
| <data name="Bike.Touring_Bike" xml:space="preserve"> | |||
| <value>Bicicletta da Touring</value> | |||
| </data> | |||
| <data name="Bike.Trailer" xml:space="preserve"> | |||
| <value>Rimorchio</value> | |||
| </data> | |||
| <data name="Bike.Tricycle" xml:space="preserve"> | |||
| <value>Triciclo</value> | |||
| </data> | |||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | |||
| <value>Bicicletta per donna</value> | |||
| </data> | |||
| <data name="Brand" xml:space="preserve"> | |||
| <value>Marca</value> | |||
| </data> | |||
| <data name="Brand.n_d" xml:space="preserve"> | |||
| <value>Non definito</value> | |||
| </data> | |||
| <data name="Cancel" xml:space="preserve"> | |||
| <value>Annulla</value> | |||
| </data> | |||
| @@ -168,6 +183,12 @@ | |||
| <data name="Color" xml:space="preserve"> | |||
| <value>Colore</value> | |||
| </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"> | |||
| <value>Nero</value> | |||
| </data> | |||
| @@ -177,6 +198,9 @@ | |||
| <data name="Color.Brown" xml:space="preserve"> | |||
| <value>Marrone</value> | |||
| </data> | |||
| <data name="Color.Gold" xml:space="preserve"> | |||
| <value>Oro</value> | |||
| </data> | |||
| <data name="Color.Green" xml:space="preserve"> | |||
| <value>Verde</value> | |||
| </data> | |||
| @@ -186,6 +210,9 @@ | |||
| <data name="Color.Indigo" xml:space="preserve"> | |||
| <value>Indigo</value> | |||
| </data> | |||
| <data name="Color.n_d" xml:space="preserve"> | |||
| <value>Non definito</value> | |||
| </data> | |||
| <data name="Color.Orange" xml:space="preserve"> | |||
| <value>Arancione</value> | |||
| </data> | |||
| @@ -198,6 +225,12 @@ | |||
| <data name="Color.Red" xml:space="preserve"> | |||
| <value>Rosso</value> | |||
| </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"> | |||
| <value>Turchese</value> | |||
| </data> | |||
| @@ -135,24 +135,39 @@ | |||
| <data name="Bike.E_Bike" xml:space="preserve"> | |||
| <value>E-Bike</value> | |||
| </data> | |||
| <data name="Bike.Kickboard" xml:space="preserve"> | |||
| <value>Kickboard</value> | |||
| </data> | |||
| <data name="Bike.Men_Bycicle" xml:space="preserve"> | |||
| <value>Men's Bycicle</value> | |||
| </data> | |||
| <data name="Bike.Mountain_Bike" xml:space="preserve"> | |||
| <value>Mountain-Bike</value> | |||
| </data> | |||
| <data name="Bike.n_d" xml:space="preserve"> | |||
| <value>Not defined</value> | |||
| </data> | |||
| <data name="Bike.Tandem" xml:space="preserve"> | |||
| <value>Tandem</value> | |||
| </data> | |||
| <data name="Bike.Touring_Bike" xml:space="preserve"> | |||
| <value>Touring_Bike</value> | |||
| </data> | |||
| <data name="Bike.Trailer" xml:space="preserve"> | |||
| <value>Trailer</value> | |||
| </data> | |||
| <data name="Bike.Tricycle" xml:space="preserve"> | |||
| <value>Tricycle</value> | |||
| </data> | |||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | |||
| <value>Women's Bycicle</value> | |||
| </data> | |||
| <data name="Brand" xml:space="preserve"> | |||
| <value>Brand</value> | |||
| </data> | |||
| <data name="Brand.n_d" xml:space="preserve"> | |||
| <value>Not defined</value> | |||
| </data> | |||
| <data name="Cancel" xml:space="preserve"> | |||
| <value>Cancel</value> | |||
| </data> | |||
| @@ -168,6 +183,12 @@ | |||
| <data name="Color" xml:space="preserve"> | |||
| <value>Color</value> | |||
| </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"> | |||
| <value>Black</value> | |||
| </data> | |||
| @@ -177,6 +198,9 @@ | |||
| <data name="Color.Brown" xml:space="preserve"> | |||
| <value>Brown</value> | |||
| </data> | |||
| <data name="Color.Gold" xml:space="preserve"> | |||
| <value>Gold</value> | |||
| </data> | |||
| <data name="Color.Green" xml:space="preserve"> | |||
| <value>Green</value> | |||
| </data> | |||
| @@ -186,6 +210,9 @@ | |||
| <data name="Color.Indigo" xml:space="preserve"> | |||
| <value>Indigo</value> | |||
| </data> | |||
| <data name="Color.n_d" xml:space="preserve"> | |||
| <value>Not defined</value> | |||
| </data> | |||
| <data name="Color.Orange" xml:space="preserve"> | |||
| <value>Orange</value> | |||
| </data> | |||
| @@ -198,6 +225,12 @@ | |||
| <data name="Color.Red" xml:space="preserve"> | |||
| <value>Red</value> | |||
| </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"> | |||
| <value>Turquoise</value> | |||
| </data> | |||
| @@ -1,10 +1,11 @@ | |||
| using CaritasPWA.Shared.Models; | |||
| using System.Collections.Generic; | |||
| using System.Threading.Tasks; | |||
| namespace CaritasPWA.Shared.Services { | |||
| public interface ILFBicycleRest { | |||
| List<ColorItem> GetColors(); | |||
| Task<List<ColorItem>> GetColors(); | |||
| List<BicycleType> GetBicycleTypes(); | |||
| @@ -1,38 +1,53 @@ | |||
| using CaritasPWA.Shared.Models; | |||
| using CaritasPWA.Shared.ResourceFiles; | |||
| using Json.Net; | |||
| using Microsoft.Extensions.Localization; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Globalization; | |||
| using System.Net.Http; | |||
| using System.Threading.Tasks; | |||
| namespace CaritasPWA.Shared.Services { | |||
| // REST interface responsible to submit lost or found reports and get the available masterdata. | |||
| public class LFBicycleRest : ILFBicycleRest { | |||
| private static readonly string VERSION = "v1"; | |||
| private readonly IStringLocalizer<Resources> _i18n; | |||
| private readonly HttpClient httpClient; | |||
| public LFBicycleRest(IStringLocalizer<Resources> 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>(); | |||
| } | |||
| 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() { | |||
| return Defaults.Brands.ToList(); | |||
| //return new List<BicycleType>(); | |||
| //return Defaults.Brands.ToList(); | |||
| return new List<Brand>(); | |||
| } | |||
| } | |||
| @@ -1,6 +1,11 @@ | |||
| using CaritasPWA.Shared.Models; | |||
| using CaritasPWA.Shared.ResourceFiles; | |||
| using Json.Net; | |||
| using Microsoft.Extensions.Localization; | |||
| using Microsoft.JSInterop; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Runtime.CompilerServices; | |||
| using System.Threading.Tasks; | |||
| namespace CaritasPWA.Shared.Services { | |||
| @@ -12,9 +17,12 @@ namespace CaritasPWA.Shared.Services { | |||
| private const string KeyNameBrands = "brands"; | |||
| private readonly IJSRuntime _jsRuntime; | |||
| private readonly IStringLocalizer<Resources> _i18n; | |||
| private bool _initializedColors; | |||
| private bool _initializedBcTypes; | |||
| private bool _initializedBrands; | |||
| private bool _firstActivation; | |||
| public bool FirstActivation { get => _firstActivation; } | |||
| private ColorItem[] _colors; | |||
| private BicycleType[] _bicycleTypes; | |||
| private Brand[] _brands; | |||
| @@ -36,19 +44,22 @@ namespace CaritasPWA.Shared.Services { | |||
| public event EventHandler Changed; | |||
| public MasterDataService(IJSRuntime jsRuntime, ILFBicycleRest lFBicycleRest) { | |||
| public MasterDataService(IJSRuntime jsRuntime, ILFBicycleRest lFBicycleRest, IStringLocalizer<Resources> i18n) { | |||
| _jsRuntime = jsRuntime; | |||
| _lFBicycleRest = lFBicycleRest; | |||
| _i18n = i18n; | |||
| _firstActivation = true; | |||
| } | |||
| public async Task SynchronizeMasterdata() { | |||
| await SynchronizeColors(); | |||
| await SynchronizeBcTypes(); | |||
| await SynchronizeBrands(); | |||
| _firstActivation = false; | |||
| } | |||
| public async Task SynchronizeColors() { | |||
| Colors = _lFBicycleRest.GetColors().ToArray(); | |||
| Colors = (await _lFBicycleRest.GetColors()).ToArray(); | |||
| if (Colors != null && Colors.Length > 0) { | |||
| await SaveColorsToStorage(); | |||
| }; | |||
| @@ -70,20 +81,36 @@ namespace CaritasPWA.Shared.Services { | |||
| public async Task<ColorItem[]> GetColors() { | |||
| 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; | |||
| } | |||
| public async Task<BicycleType[]> GetBicycleTypes() { | |||
| 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; | |||
| } | |||
| public async Task<BicycleType[]> GetBrands() { | |||
| public async Task<Brand[]> GetBrands() { | |||
| 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() { | |||
| @@ -100,10 +127,10 @@ namespace CaritasPWA.Shared.Services { | |||
| // Read the JSON string that contains the data from the local storage | |||
| ColorItem[] result; | |||
| 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>(); | |||
| } else { | |||
| result = JsonNet.Deserialize<ColorItem[]>(str) ?? Array.Empty<ColorItem>(); | |||
| } | |||
| _colors = result; | |||
| return result; | |||
| @@ -124,7 +151,7 @@ namespace CaritasPWA.Shared.Services { | |||
| BicycleType[] result; | |||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBcTypes); | |||
| if (str != null) { | |||
| result = System.Text.Json.JsonSerializer.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>(); | |||
| result = JsonNet.Deserialize<BicycleType[]>(str) ?? Array.Empty<BicycleType>(); | |||
| } else { | |||
| result = Array.Empty<BicycleType>(); | |||
| } | |||
| @@ -147,7 +174,7 @@ namespace CaritasPWA.Shared.Services { | |||
| Brand[] result; | |||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBrands); | |||
| if (str != null) { | |||
| result = System.Text.Json.JsonSerializer.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>(); | |||
| result = JsonNet.Deserialize<Brand[]>(str) ?? Array.Empty<Brand>(); | |||
| } else { | |||
| result = Array.Empty<Brand>(); | |||
| } | |||
| @@ -157,31 +184,33 @@ namespace CaritasPWA.Shared.Services { | |||
| private async Task SaveColorsToStorage() { | |||
| var json = System.Text.Json.JsonSerializer.Serialize(_colors); | |||
| var json = JsonNet.Serialize(_colors); | |||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json); | |||
| } | |||
| private async Task SaveBcTypesToStorage() { | |||
| var json = System.Text.Json.JsonSerializer.Serialize(_bicycleTypes); | |||
| var json = JsonNet.Serialize(_bicycleTypes); | |||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, json); | |||
| } | |||
| private async Task SaveBrandsToStorage() { | |||
| var json = System.Text.Json.JsonSerializer.Serialize(_brands); | |||
| var json = JsonNet.Serialize(_brands); | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -8,13 +8,11 @@ using System.Threading.Tasks; | |||
| namespace CaritasPWA.Shared.Services { | |||
| 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 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 { | |||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("reverse?format=json&lat={0}&lon={1}", lat, lng)); | |||