| <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-8-tablet mat-layout-grid-cell-span-12-desktop"> | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-8-tablet mat-layout-grid-cell-span-12-desktop"> | ||||
| <div class="mat-layout-grid-inner"> | <div class="mat-layout-grid-inner"> | ||||
| <div class="mat-layout-grid-cell mat-layout-grid-cell-span-4-phone mat-layout-grid-cell-span-4-tablet mat-layout-grid-cell-span-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"> | ||||
| <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> | ||||
| <MatStringField Class="w-100 form-check-label" Label="@i18n["Brand"]" Outlined="true" type="text"></MatStringField> | <MatStringField Class="w-100 form-check-label" Label="@i18n["Brand"]" Outlined="true" type="text"></MatStringField> | ||||
| </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"> | ||||
| <MatSelect Class="w-100" Outlined="true" Label="@i18n["Type"]" @bind-Value="value"> | |||||
| <MatOptionString></MatOptionString> | |||||
| <MatOptionString Value="Mountain-Bike">Mountain-Bike</MatOptionString> | |||||
| <MatOptionString Value="City-Bike">City-Bike</MatOptionString> | |||||
| <MatOptionString Value="Child-Bike">Child-Bike</MatOptionString> | |||||
| </MatSelect> | |||||
| <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["Type"]" @bind-Value="selectedBcType" Items="@BicycleTypes" ValueSelector="@(i=>i)"> | |||||
| <ItemTemplate> | |||||
| <div> | |||||
| <span>@i18n["Bike." + @context?.Type]</span> | |||||
| </div> | |||||
| </ItemTemplate> | |||||
| </MatSelectValue> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| [Parameter] | [Parameter] | ||||
| public string FromRoute { get; set; } | public string FromRoute { get; set; } | ||||
| string value; | |||||
| private ColorItem selectedColor; | private ColorItem selectedColor; | ||||
| private BicycleType selectedBcType; | |||||
| protected async override void OnInitialized() { | protected async override void OnInitialized() { | ||||
| await GetColors(); | await GetColors(); | ||||
| await GetBicycleTypes(); | |||||
| PageHistoryManager.AddPageToHistory(NavigationManager.Uri); | PageHistoryManager.AddPageToHistory(NavigationManager.Uri); | ||||
| base.OnInitialized(); | base.OnInitialized(); | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| private async Task GetBicycleTypes() { | |||||
| await InvokeAsync(async () => { | |||||
| await MasterDataService.GetBicycleTypes(); | |||||
| StateHasChanged(); | |||||
| }); | |||||
| } | |||||
| private ColorItem[] Colors { | private ColorItem[] Colors { | ||||
| get => MasterDataService.Colors; | get => MasterDataService.Colors; | ||||
| } | } | ||||
| private BicycleType[] BicycleTypes { | |||||
| get => MasterDataService.BicycleTypes; | |||||
| } | |||||
| private void Next() { | private void Next() { | ||||
| NavigationManager.NavigateTo("fundvelo/account/" + @FromRoute); | NavigationManager.NavigateTo("fundvelo/account/" + @FromRoute); | ||||
| } | } |
| @code { | @code { | ||||
| protected async override void OnInitialized() { | protected async override void OnInitialized() { | ||||
| await MasterDataService.SynchronizeColors(); | |||||
| await MasterDataService.SynchronizeMasterdata(); | |||||
| PageHistoryManager.Reset(); | PageHistoryManager.Reset(); | ||||
| base.OnInitialized(); | base.OnInitialized(); | ||||
| } | } |
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using MatBlazor; | using MatBlazor; | ||||
| using CaritasPWA.Shared; | using CaritasPWA.Shared; | ||||
| using CaritasPWA.Shared.ResourceFiles; | |||||
| using Microsoft.Extensions.Localization; | |||||
| namespace CaritasPWA { | namespace CaritasPWA { | ||||
| public class Program { | public class Program { | ||||
| builder.Services.AddMatBlazor(); | builder.Services.AddMatBlazor(); | ||||
| builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); | builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); | ||||
| builder.Services.AddScoped<UserDataProvider>(); | |||||
| builder.Services.AddScoped<MasterDataService>(); | |||||
| builder.Services.AddSingleton<ILFBicycleRest, LFBicycleRest>(); | |||||
| builder.Services.AddSingleton<AppState>(); | builder.Services.AddSingleton<AppState>(); | ||||
| builder.Services.AddSingleton<PageHistoryManager>(); | builder.Services.AddSingleton<PageHistoryManager>(); | ||||
| builder.Services.AddScoped<UserDataProvider>(); | |||||
| builder.Services.AddScoped<MasterDataService>(); | |||||
| builder.Services.AddLocalization(); | builder.Services.AddLocalization(); | ||||
| await builder.Build().RunAsync(); | await builder.Build().RunAsync(); |
| "environmentVariables": { | "environmentVariables": { | ||||
| "ASPNETCORE_ENVIRONMENT": "Development" | "ASPNETCORE_ENVIRONMENT": "Development" | ||||
| }, | }, | ||||
| "nativeDebugging": true, | |||||
| "jsWebView2Debugging": false, | |||||
| "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}" | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}" | ||||
| }, | }, | ||||
| "CaritasPWA": { | "CaritasPWA": { |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| using CaritasPWA.Shared.Models; | |||||
| using Microsoft.JSInterop; | |||||
| namespace CaritasPWA.Shared { | |||||
| public class MasterDataService { | |||||
| private const string KeyNameColors = "colors"; | |||||
| private const string KeyNameBcTypes = "bicycleTypes"; | |||||
| private readonly IJSRuntime _jsRuntime; | |||||
| private bool _initializedColors; | |||||
| private ColorItem[] _colors = new ColorItem[] { }; | |||||
| public ColorItem[] Colors { | |||||
| get => _colors; | |||||
| set => _colors = value; | |||||
| } | |||||
| public event EventHandler Changed; | |||||
| public MasterDataService(IJSRuntime jsRuntime) { | |||||
| _jsRuntime = jsRuntime; | |||||
| } | |||||
| public async Task SynchronizeColors() { | |||||
| // TODO: Get the color from server via REST and save it when not empty | |||||
| _colors = Defaults.ColorItems; | |||||
| await SaveColorsToStorage(); | |||||
| } | |||||
| public async Task<ColorItem[]> GetColors() { | |||||
| // To search first in local storage, when nothing is found return the defaults. | |||||
| //return Defaults.ColorItems; | |||||
| return await GetColorsFromStorage(); | |||||
| } | |||||
| private async ValueTask<ColorItem[]> GetColorsFromStorage() { | |||||
| // Register the Storage event handler. This handler calls OnStorageUpdated when the storage changed. | |||||
| // This way, you can reload the settings when another instance of the application (tab / window) save the settings | |||||
| if (!_initializedColors) { | |||||
| // Create a reference to the current object, so the JS function can call the public method "OnStorageUpdated" | |||||
| var reference = DotNetObjectReference.Create(this); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorRegisterStorageEvent", reference); | |||||
| _initializedColors = true; | |||||
| } | |||||
| // 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) ?? new ColorItem[] { }; | |||||
| } else { | |||||
| result = new ColorItem[] { }; | |||||
| } | |||||
| _colors= result; | |||||
| return result; | |||||
| } | |||||
| private async Task SaveColorsToStorage() { | |||||
| var json = System.Text.Json.JsonSerializer.Serialize(_colors); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, 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) { | |||||
| //_bicycleType = null; | |||||
| Changed?.Invoke(this, EventArgs.Empty); | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| namespace CaritasPWA.Shared.Models { | |||||
| public class BicycleType { | |||||
| public int Index { get; set; } | |||||
| public string Type { get; set; } | |||||
| public BicycleType() { } | |||||
| public BicycleType(int index, string type) { | |||||
| Index = index; | |||||
| Type = type; | |||||
| } | |||||
| } | |||||
| } |
| new ColorItem(7, "White", "255, 255, 255"), | new ColorItem(7, "White", "255, 255, 255"), | ||||
| }; | }; | ||||
| public enum BycicleType { | |||||
| Men_Bycicle, | |||||
| Women_Bycicle, | |||||
| Child_Bycicle, | |||||
| E_Bike, | |||||
| Mountain_Bike, | |||||
| City_Bike, | |||||
| Tandem, | |||||
| Trailer | |||||
| } | |||||
| public static 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") | |||||
| }; | |||||
| } | } | ||||
| } | } | ||||
| Href="account" | Href="account" | ||||
| @onclick="@((e) => ButtonClicked(2))"> | @onclick="@((e) => ButtonClicked(2))"> | ||||
| <MatIcon Icon="@MatIconNames.Person_outline"></MatIcon> | <MatIcon Icon="@MatIconNames.Person_outline"></MatIcon> | ||||
| <MatListItemText Style="padding-left:0.5em">@i18n["Account"]</MatListItemText> | |||||
| <MatListItemText Style="padding-left:0.5em">@i18n["account"]</MatListItemText> | |||||
| </MatListItem> | </MatListItem> | ||||
| <MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")" | <MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")" | ||||
| Href="info" | Href="info" | ||||
| @onclick="@((e) => ButtonClicked(3))"> | @onclick="@((e) => ButtonClicked(3))"> | ||||
| <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon> | <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon> | ||||
| <MatListItemText Style="padding-left:0.5em">@i18n["Info"]</MatListItemText> | |||||
| <MatListItemText Style="padding-left:0.5em">@i18n["info"]</MatListItemText> | |||||
| </MatListItem> | </MatListItem> | ||||
| <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")" | <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")" | ||||
| href="" | href="" |
| /// <summary> | /// <summary> | ||||
| /// Sucht eine lokalisierte Zeichenfolge, die Account ähnelt. | /// Sucht eine lokalisierte Zeichenfolge, die Account ähnelt. | ||||
| /// </summary> | /// </summary> | ||||
| public static string Account { | |||||
| public static string account { | |||||
| get { | get { | ||||
| return ResourceManager.GetString("Account", resourceCulture); | |||||
| return ResourceManager.GetString("account", resourceCulture); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /// <summary> | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die Children Bycicle ähnelt. | |||||
| /// </summary> | |||||
| public static string Bike_Child_Bycicle { | |||||
| get { | |||||
| return ResourceManager.GetString("Bike.Child_Bycicle", resourceCulture); | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die City-Bike ähnelt. | |||||
| /// </summary> | |||||
| public static string Bike_City_Bike { | |||||
| get { | |||||
| return ResourceManager.GetString("Bike.City_Bike", resourceCulture); | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die E-Bike ähnelt. | |||||
| /// </summary> | |||||
| public static string Bike_E_Bike { | |||||
| get { | |||||
| return ResourceManager.GetString("Bike.E_Bike", resourceCulture); | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die Men's Bycicle ähnelt. | |||||
| /// </summary> | |||||
| public static string Bike_Men_Bycicle { | |||||
| get { | |||||
| return ResourceManager.GetString("Bike.Men_Bycicle", resourceCulture); | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die Mountain-Bike ähnelt. | |||||
| /// </summary> | |||||
| public static string Bike_Mountain_Bike { | |||||
| get { | |||||
| return ResourceManager.GetString("Bike.Mountain_Bike", resourceCulture); | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die Tandem ähnelt. | |||||
| /// </summary> | |||||
| public static string Bike_Tandem { | |||||
| get { | |||||
| return ResourceManager.GetString("Bike.Tandem", resourceCulture); | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die Trailer ähnelt. | |||||
| /// </summary> | |||||
| public static string Bike_Trailer { | |||||
| get { | |||||
| return ResourceManager.GetString("Bike.Trailer", resourceCulture); | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// Sucht eine lokalisierte Zeichenfolge, die Women's Bycicle ähnelt. | |||||
| /// </summary> | |||||
| public static string Bike_Women_Bycicle { | |||||
| get { | |||||
| return ResourceManager.GetString("Bike.Women_Bycicle", resourceCulture); | |||||
| } | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// Sucht eine lokalisierte Zeichenfolge, die Brand ähnelt. | /// Sucht eine lokalisierte Zeichenfolge, die Brand ähnelt. | ||||
| /// </summary> | /// </summary> | ||||
| /// <summary> | /// <summary> | ||||
| /// Sucht eine lokalisierte Zeichenfolge, die Info ähnelt. | /// Sucht eine lokalisierte Zeichenfolge, die Info ähnelt. | ||||
| /// </summary> | /// </summary> | ||||
| public static string Info { | |||||
| public static string info { | |||||
| get { | get { | ||||
| return ResourceManager.GetString("Info", resourceCulture); | |||||
| return ResourceManager.GetString("info", resourceCulture); | |||||
| } | } | ||||
| } | } | ||||
| <data name="Abouttext" xml:space="preserve"> | <data name="Abouttext" xml:space="preserve"> | ||||
| <value>Hier komt ein Informationstext über die App.</value> | <value>Hier komt ein Informationstext über die App.</value> | ||||
| </data> | </data> | ||||
| <data name="Account" xml:space="preserve"> | |||||
| <data name="account" xml:space="preserve"> | |||||
| <value>Konto</value> | <value>Konto</value> | ||||
| </data> | </data> | ||||
| <data name="Address" xml:space="preserve"> | <data name="Address" xml:space="preserve"> | ||||
| <value>Adresse</value> | <value>Adresse</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Child_Bycicle" xml:space="preserve"> | |||||
| <value>Kindervelo</value> | |||||
| </data> | |||||
| <data name="Bike.City_Bike" xml:space="preserve"> | |||||
| <value>City-Bike</value> | |||||
| </data> | |||||
| <data name="Bike.E_Bike" xml:space="preserve"> | |||||
| <value>E-Bike</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.Tandem" xml:space="preserve"> | |||||
| <value>Tandem</value> | |||||
| </data> | |||||
| <data name="Bike.Trailer" xml:space="preserve"> | |||||
| <value>Anhänger</value> | |||||
| </data> | |||||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | |||||
| <value>Damenvelo</value> | |||||
| </data> | |||||
| <data name="Brand" xml:space="preserve"> | <data name="Brand" xml:space="preserve"> | ||||
| <value>Marke</value> | <value>Marke</value> | ||||
| </data> | </data> | ||||
| <data name="fundvelo/lost_found" xml:space="preserve"> | <data name="fundvelo/lost_found" xml:space="preserve"> | ||||
| <value>Fundvelo</value> | <value>Fundvelo</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="Lastname" xml:space="preserve"> | <data name="Lastname" xml:space="preserve"> |
| <data name="Abouttext" xml:space="preserve"> | <data name="Abouttext" xml:space="preserve"> | ||||
| <value>Ici on va voir une text informatif sur l'app.</value> | <value>Ici on va voir une text informatif sur l'app.</value> | ||||
| </data> | </data> | ||||
| <data name="Account" xml:space="preserve"> | |||||
| <data name="account" xml:space="preserve"> | |||||
| <value>Compte</value> | <value>Compte</value> | ||||
| </data> | </data> | ||||
| <data name="Address" xml:space="preserve"> | <data name="Address" xml:space="preserve"> | ||||
| <value>Adresse</value> | <value>Adresse</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Child_Bycicle" xml:space="preserve"> | |||||
| <value>Vélo pour enfants</value> | |||||
| </data> | |||||
| <data name="Bike.City_Bike" xml:space="preserve"> | |||||
| <value>City-Bike</value> | |||||
| </data> | |||||
| <data name="Bike.E_Bike" xml:space="preserve"> | |||||
| <value>E-Bike</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.Tandem" xml:space="preserve"> | |||||
| <value>Tandem</value> | |||||
| </data> | |||||
| <data name="Bike.Trailer" xml:space="preserve"> | |||||
| <value>Remorque</value> | |||||
| </data> | |||||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | |||||
| <value>Vélo pour dames</value> | |||||
| </data> | |||||
| <data name="Brand" xml:space="preserve"> | <data name="Brand" xml:space="preserve"> | ||||
| <value>Marque</value> | <value>Marque</value> | ||||
| </data> | </data> | ||||
| <data name="fundvelo/lost_found" xml:space="preserve"> | <data name="fundvelo/lost_found" xml:space="preserve"> | ||||
| <value>Velo</value> | <value>Velo</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="Lastname" xml:space="preserve"> | <data name="Lastname" xml:space="preserve"> |
| <data name="Abouttext" xml:space="preserve"> | <data name="Abouttext" xml:space="preserve"> | ||||
| <value>Qui appare un testo informativo sull'app.</value> | <value>Qui appare un testo informativo sull'app.</value> | ||||
| </data> | </data> | ||||
| <data name="Account" xml:space="preserve"> | |||||
| <data name="account" xml:space="preserve"> | |||||
| <value>Profilo</value> | <value>Profilo</value> | ||||
| </data> | </data> | ||||
| <data name="Address" xml:space="preserve"> | <data name="Address" xml:space="preserve"> | ||||
| <value>Indirizzo</value> | <value>Indirizzo</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Child_Bycicle" xml:space="preserve"> | |||||
| <value>Bicicletta per bambino</value> | |||||
| </data> | |||||
| <data name="Bike.City_Bike" xml:space="preserve"> | |||||
| <value>City-Bike</value> | |||||
| </data> | |||||
| <data name="Bike.E_Bike" xml:space="preserve"> | |||||
| <value>E-Bike</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.Tandem" xml:space="preserve"> | |||||
| <value>Tandem</value> | |||||
| </data> | |||||
| <data name="Bike.Trailer" xml:space="preserve"> | |||||
| <value>Rimorchio</value> | |||||
| </data> | |||||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | |||||
| <value>Bicicletta per donna</value> | |||||
| </data> | |||||
| <data name="Brand" xml:space="preserve"> | <data name="Brand" xml:space="preserve"> | ||||
| <value>Marca</value> | <value>Marca</value> | ||||
| </data> | </data> | ||||
| <data name="fundvelo/lost_found" xml:space="preserve"> | <data name="fundvelo/lost_found" xml:space="preserve"> | ||||
| <value>Bicicletta</value> | <value>Bicicletta</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="Lastname" xml:space="preserve"> | <data name="Lastname" xml:space="preserve"> |
| <data name="Abouttext" xml:space="preserve"> | <data name="Abouttext" xml:space="preserve"> | ||||
| <value>Here you will read some information about the app.</value> | <value>Here you will read some information about the app.</value> | ||||
| </data> | </data> | ||||
| <data name="Account" xml:space="preserve"> | |||||
| <data name="account" xml:space="preserve"> | |||||
| <value>Account</value> | <value>Account</value> | ||||
| </data> | </data> | ||||
| <data name="Address" xml:space="preserve"> | <data name="Address" xml:space="preserve"> | ||||
| <value>Address</value> | <value>Address</value> | ||||
| </data> | </data> | ||||
| <data name="Bike.Child_Bycicle" xml:space="preserve"> | |||||
| <value>Children Bycicle</value> | |||||
| </data> | |||||
| <data name="Bike.City_Bike" xml:space="preserve"> | |||||
| <value>City-Bike</value> | |||||
| </data> | |||||
| <data name="Bike.E_Bike" xml:space="preserve"> | |||||
| <value>E-Bike</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.Tandem" xml:space="preserve"> | |||||
| <value>Tandem</value> | |||||
| </data> | |||||
| <data name="Bike.Trailer" xml:space="preserve"> | |||||
| <value>Trailer</value> | |||||
| </data> | |||||
| <data name="Bike.Women_Bycicle" xml:space="preserve"> | |||||
| <value>Women's Bycicle</value> | |||||
| </data> | |||||
| <data name="Brand" xml:space="preserve"> | <data name="Brand" xml:space="preserve"> | ||||
| <value>Brand</value> | <value>Brand</value> | ||||
| </data> | </data> | ||||
| <data name="fundvelo/lost_found" xml:space="preserve"> | <data name="fundvelo/lost_found" xml:space="preserve"> | ||||
| <value>Bicycle</value> | <value>Bicycle</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="Lastname" xml:space="preserve"> | <data name="Lastname" xml:space="preserve"> |
| using CaritasPWA.Shared.Models; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| namespace CaritasPWA.Shared { | |||||
| public interface ILFBicycleRest { | |||||
| List<ColorItem> GetColors(); | |||||
| List<BicycleType> GetBicycleTypes(); | |||||
| } | |||||
| } |
| using CaritasPWA.Shared.Models; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| namespace CaritasPWA.Shared { | |||||
| // REST interface responsible to submit lost or found reports and get the available masterdata. | |||||
| public class LFBicycleRest : ILFBicycleRest { | |||||
| public List<ColorItem> GetColors() { | |||||
| //return Defaults.ColorItems.ToList(); | |||||
| return new List<ColorItem>(); | |||||
| } | |||||
| public List<BicycleType> GetBicycleTypes() { | |||||
| return Defaults.BycicleTypes.ToList(); | |||||
| //return new List<BicycleType>(); | |||||
| } | |||||
| } | |||||
| } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| using CaritasPWA.Shared.Models; | |||||
| using Microsoft.AspNetCore.Components; | |||||
| using Microsoft.JSInterop; | |||||
| namespace CaritasPWA.Shared { | |||||
| public class MasterDataService { | |||||
| private ILFBicycleRest _lFBicycleRest; | |||||
| private const string KeyNameColors = "colors"; | |||||
| private const string KeyNameBcTypes = "bicycleTypes"; | |||||
| private readonly IJSRuntime _jsRuntime; | |||||
| private bool _initializedColors; | |||||
| private bool _initializedBcTypes; | |||||
| private ColorItem[] _colors = new ColorItem[] { }; | |||||
| private BicycleType[] _bicycleTypes = new BicycleType[] { }; | |||||
| public ColorItem[] Colors { | |||||
| get => _colors; | |||||
| set => _colors = value; | |||||
| } | |||||
| public BicycleType[] BicycleTypes { | |||||
| get => _bicycleTypes; | |||||
| set => _bicycleTypes = value; | |||||
| } | |||||
| public event EventHandler Changed; | |||||
| public MasterDataService(IJSRuntime jsRuntime, ILFBicycleRest lFBicycleRest) { | |||||
| _jsRuntime = jsRuntime; | |||||
| _lFBicycleRest = lFBicycleRest; | |||||
| } | |||||
| public async Task SynchronizeMasterdata() { | |||||
| await SynchronizeColors(); | |||||
| await SynchronizeBcTypes(); | |||||
| } | |||||
| public async Task SynchronizeColors() { | |||||
| Colors = _lFBicycleRest.GetColors().ToArray(); | |||||
| if (Colors != null && Colors.Length > 0) { | |||||
| await SaveColorsToStorage(); | |||||
| }; | |||||
| } | |||||
| public async Task SynchronizeBcTypes() { | |||||
| BicycleTypes = _lFBicycleRest.GetBicycleTypes().ToArray(); | |||||
| if (BicycleTypes != null && BicycleTypes.Length > 0) { | |||||
| await SaveBcTypesToStorage(); | |||||
| } | |||||
| } | |||||
| public async Task<ColorItem[]> GetColors() { | |||||
| ColorItem[] colors = await GetColorsFromStorage(); | |||||
| Colors = (colors != null && colors.Length > 0) ? colors : Defaults.ColorItems; | |||||
| return Colors; | |||||
| } | |||||
| public async Task<BicycleType[]> GetBicycleTypes() { | |||||
| BicycleType[] bicycleTypes = await GetBicycleTypesFromStorage(); | |||||
| BicycleTypes = (bicycleTypes != null && bicycleTypes.Length > 0) ? bicycleTypes : Defaults.BycicleTypes; | |||||
| return BicycleTypes; | |||||
| } | |||||
| private async ValueTask<ColorItem[]> GetColorsFromStorage() { | |||||
| // Register the Storage event handler. This handler calls OnStorageUpdated when the storage changed. | |||||
| // This way, you can reload the settings when another instance of the application (tab / window) save the settings | |||||
| if (!_initializedColors) { | |||||
| // Create a reference to the current object, so the JS function can call the public method "OnStorageUpdated" | |||||
| var reference = DotNetObjectReference.Create(this); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorRegisterStorageEvent", reference); | |||||
| _initializedColors = true; | |||||
| } | |||||
| // 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) ?? new ColorItem[] { }; | |||||
| } else { | |||||
| result = new ColorItem[] { }; | |||||
| } | |||||
| _colors= result; | |||||
| return result; | |||||
| } | |||||
| private async ValueTask<BicycleType[]> GetBicycleTypesFromStorage() { | |||||
| // Register the Storage event handler. This handler calls OnStorageUpdated when the storage changed. | |||||
| // This way, you can reload the settings when another instance of the application (tab / window) save the settings | |||||
| if (!_initializedBcTypes) { | |||||
| // Create a reference to the current object, so the JS function can call the public method "OnStorageUpdated" | |||||
| var reference = DotNetObjectReference.Create(this); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorRegisterStorageEvent", reference); | |||||
| _initializedBcTypes = true; | |||||
| } | |||||
| // Read the JSON string that contains the data from the local storage | |||||
| BicycleType[] result; | |||||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameBcTypes); | |||||
| if (str != null) { | |||||
| result = System.Text.Json.JsonSerializer.Deserialize<BicycleType[]>(str) ?? new BicycleType[] { }; | |||||
| } else { | |||||
| result = new BicycleType[] { }; | |||||
| } | |||||
| _bicycleTypes = result; | |||||
| return result; | |||||
| } | |||||
| private async Task SaveColorsToStorage() { | |||||
| var json = System.Text.Json.JsonSerializer.Serialize(_colors); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameColors, json); | |||||
| } | |||||
| private async Task SaveBcTypesToStorage() { | |||||
| var json = System.Text.Json.JsonSerializer.Serialize(_bicycleTypes); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBcTypes, 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); | |||||
| } | |||||
| } | |||||
| } | |||||
| } |