| <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-12-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-12-desktop"> | ||||
| <MatTextField Class="w-100 form-check-label" Label="@i18n["Price"]" Format="0.00" Outlined="true" @bind-Value="@price"></MatTextField> | <MatTextField Class="w-100 form-check-label" Label="@i18n["Price"]" Format="0.00" Outlined="true" @bind-Value="@price"></MatTextField> | ||||
| </div> | </div> | ||||
| <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"> | |||||
| <MatSelectValue FullWidth="true" Outlined="true" Label="@i18n["SearchService"]" @bind-Value="selectedSearchService" Items="@SearchServices" ValueSelector="@(i=>i)"> | |||||
| <ItemTemplate> | |||||
| <div> | |||||
| <span>@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-12-desktop"> | |||||
| <MatStringField Class="w-100 form-check-label" Label="@i18n["SearchServiceNbr"]" Outlined="true" type="text" @bind-Value="searchServiceNbr"></MatStringField> | |||||
| </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-12-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-12-desktop"> | ||||
| <MatStringField Class="w-100 form-check-label" Label="@i18n["Remark"]" Outlined="true" type="text" @bind-Value="remark"></MatStringField> | <MatStringField Class="w-100 form-check-label" Label="@i18n["Remark"]" Outlined="true" type="text" @bind-Value="remark"></MatStringField> | ||||
| </div> | </div> | ||||
| private Boolean loading = false; | private Boolean loading = false; | ||||
| private ColorItem selectedColor; | private ColorItem selectedColor; | ||||
| private BicycleType selectedBcType; | private BicycleType selectedBcType; | ||||
| private SearchService selectedSearchService; | |||||
| private string brandStringValue; | private string brandStringValue; | ||||
| private Brand selectedBrand; | private Brand selectedBrand; | ||||
| private Brand SelectedBrand { | private Brand SelectedBrand { | ||||
| } | } | ||||
| private string frameNumber; | private string frameNumber; | ||||
| private string remark; | private string remark; | ||||
| private string searchServiceNbr; | |||||
| private uint age; | private uint age; | ||||
| private float price; | private float price; | ||||
| await GetColors(); | await GetColors(); | ||||
| await GetBicycleTypes(); | await GetBicycleTypes(); | ||||
| await GetBrands(); | await GetBrands(); | ||||
| await GetSearchServices(); | |||||
| refreshGUIFromDto(); | refreshGUIFromDto(); | ||||
| PageHistoryManager.AddPageToHistory(NavigationManager.Uri); | PageHistoryManager.AddPageToHistory(NavigationManager.Uri); | ||||
| StateHasChanged(); | StateHasChanged(); | ||||
| await MasterDataService.GetBrands(); | await MasterDataService.GetBrands(); | ||||
| } | } | ||||
| private async Task GetSearchServices() { | |||||
| await MasterDataService.GetSearchServices(); | |||||
| } | |||||
| private ColorItem[] Colors { | private ColorItem[] Colors { | ||||
| get => MasterDataService.Colors; | get => MasterDataService.Colors; | ||||
| } | } | ||||
| get => MasterDataService.Brands; | get => MasterDataService.Brands; | ||||
| } | } | ||||
| private SearchService[] SearchServices { | |||||
| get => MasterDataService.SearchServices; | |||||
| } | |||||
| private void Next() { | private void Next() { | ||||
| updateDtoFromGUI(); | updateDtoFromGUI(); | ||||
| NavigationManager.NavigateTo("fundvelo/account/Missing"); | NavigationManager.NavigateTo("fundvelo/account/Missing"); | ||||
| selectedBrand = String.IsNullOrEmpty(report.NeueMarke) ? Array.Find(Brands, brand => brand.Id == report.MarkeId) : new Brand(-999, report.NeueMarke); | selectedBrand = String.IsNullOrEmpty(report.NeueMarke) ? Array.Find(Brands, brand => brand.Id == report.MarkeId) : new Brand(-999, report.NeueMarke); | ||||
| selectedBcType = Array.Find(BicycleTypes, bcType => bcType.Id == report.TypId); | selectedBcType = Array.Find(BicycleTypes, bcType => bcType.Id == report.TypId); | ||||
| frameNumber = report.RahmenNummer; | frameNumber = report.RahmenNummer; | ||||
| remark = report.Bemerkung; | |||||
| age = report.Alter; | age = report.Alter; | ||||
| price = report.Preis; | price = report.Preis; | ||||
| selectedSearchService = Array.Find(SearchServices, searchService => searchService.Id == report.SuchDienstId); | |||||
| searchServiceNbr = report.SuchDienstNr; | |||||
| remark = report.Bemerkung; | |||||
| } | } | ||||
| private void updateDtoFromGUI() { | private void updateDtoFromGUI() { | ||||
| report.Bemerkung = remark; | report.Bemerkung = remark; | ||||
| report.Alter = age; | report.Alter = age; | ||||
| report.Preis = price; | report.Preis = price; | ||||
| report.SuchDienstId = selectedSearchService.Id; | |||||
| report.SuchDienstNr = searchServiceNbr; | |||||
| } | } | ||||
| } | } |
| new Brand(35, "GT") | new Brand(35, "GT") | ||||
| }; | }; | ||||
| private static readonly SearchService[] SearchServices = { | |||||
| new SearchService(0, "n_d"), | |||||
| new SearchService(1, "Suchdienst 1"), | |||||
| new SearchService(2, "Suchdienst 2") | |||||
| }; | |||||
| public static List<ColorItem> GetColorDefaults(IStringLocalizer<Resources> _i18n) { | public static List<ColorItem> GetColorDefaults(IStringLocalizer<Resources> _i18n) { | ||||
| List<ColorItem> colors = new(); | List<ColorItem> colors = new(); | ||||
| foreach (ColorItem color in ColorItems) { | foreach (ColorItem color in ColorItems) { | ||||
| return brands; | return brands; | ||||
| } | } | ||||
| public static List<SearchService> GetSearchServiceDefaults(IStringLocalizer<Resources> _i18n) { | |||||
| List<SearchService> searchServices = new(); | |||||
| foreach (SearchService searchService in SearchServices) { | |||||
| searchServices.Add(new SearchService(searchService.Id, searchService.Id == 0 ? _i18n.GetString("SearchService." + searchService.Id) : searchService.Bezeichnung)); | |||||
| } | |||||
| return searchServices; | |||||
| } | |||||
| } | } | ||||
| } | } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| namespace cwebplusApp.Shared.Models { | |||||
| public class SearchService { | |||||
| public int Id { get; set; } | |||||
| public string Bezeichnung { get; set; } | |||||
| public SearchService() { } | |||||
| public SearchService(int id, string type) { | |||||
| Id = id; | |||||
| Bezeichnung = type; | |||||
| } | |||||
| } | |||||
| } |
| <data name="Save" xml:space="preserve"> | <data name="Save" xml:space="preserve"> | ||||
| <value>Speichern</value> | <value>Speichern</value> | ||||
| </data> | </data> | ||||
| <data name="SearchService" xml:space="preserve"> | |||||
| <value>Suchdienst</value> | |||||
| </data> | |||||
| <data name="SearchService.0" xml:space="preserve"> | |||||
| <value>Nicht definiert</value> | |||||
| </data> | |||||
| <data name="SearchService.1" xml:space="preserve"> | |||||
| <value>Suchdienst 1</value> | |||||
| </data> | |||||
| <data name="SearchService.2" xml:space="preserve"> | |||||
| <value>Suchdienst 2</value> | |||||
| </data> | |||||
| <data name="SearchServiceNbr" xml:space="preserve"> | |||||
| <value>Suchdienst-Nr.</value> | |||||
| </data> | |||||
| <data name="Send" xml:space="preserve"> | <data name="Send" xml:space="preserve"> | ||||
| <value>Absenden</value> | <value>Absenden</value> | ||||
| </data> | </data> |
| <data name="Save" xml:space="preserve"> | <data name="Save" xml:space="preserve"> | ||||
| <value>Sauver</value> | <value>Sauver</value> | ||||
| </data> | </data> | ||||
| <data name="SearchService" xml:space="preserve"> | |||||
| <value>Service de recherche</value> | |||||
| </data> | |||||
| <data name="SearchService.0" xml:space="preserve"> | |||||
| <value>Ne pas definé</value> | |||||
| </data> | |||||
| <data name="SearchService.1" xml:space="preserve"> | |||||
| <value>Service de recherche 1</value> | |||||
| </data> | |||||
| <data name="SearchService.2" xml:space="preserve"> | |||||
| <value>Service de recherche 2</value> | |||||
| </data> | |||||
| <data name="SearchServiceNbr" xml:space="preserve"> | |||||
| <value>No. de Service de recherche</value> | |||||
| </data> | |||||
| <data name="Send" xml:space="preserve"> | <data name="Send" xml:space="preserve"> | ||||
| <value>Envoie</value> | <value>Envoie</value> | ||||
| </data> | </data> |
| <data name="Save" xml:space="preserve"> | <data name="Save" xml:space="preserve"> | ||||
| <value>Salva</value> | <value>Salva</value> | ||||
| </data> | </data> | ||||
| <data name="SearchService" xml:space="preserve"> | |||||
| <value>Servizio ritrovamento</value> | |||||
| </data> | |||||
| <data name="SearchService.0" xml:space="preserve"> | |||||
| <value>Non definito</value> | |||||
| </data> | |||||
| <data name="SearchService.1" xml:space="preserve"> | |||||
| <value>Servizio ritrovamento 1</value> | |||||
| </data> | |||||
| <data name="SearchService.2" xml:space="preserve"> | |||||
| <value>Servizio ritrovamento 2</value> | |||||
| </data> | |||||
| <data name="Send" xml:space="preserve"> | <data name="Send" xml:space="preserve"> | ||||
| <value>Invia</value> | <value>Invia</value> | ||||
| </data> | </data> | ||||
| <data name="Service de recherche" xml:space="preserve"> | |||||
| <value>N. del Servizio ritrovamento</value> | |||||
| </data> | |||||
| <data name="Specifications" xml:space="preserve"> | <data name="Specifications" xml:space="preserve"> | ||||
| <value>Descrizione dettagliata</value> | <value>Descrizione dettagliata</value> | ||||
| </data> | </data> |
| <data name="Save" xml:space="preserve"> | <data name="Save" xml:space="preserve"> | ||||
| <value>Save</value> | <value>Save</value> | ||||
| </data> | </data> | ||||
| <data name="SearchService" xml:space="preserve"> | |||||
| <value>Search Service</value> | |||||
| </data> | |||||
| <data name="SearchService.0" xml:space="preserve"> | |||||
| <value>Not defined</value> | |||||
| </data> | |||||
| <data name="SearchService.1" xml:space="preserve"> | |||||
| <value>Search Service 1</value> | |||||
| </data> | |||||
| <data name="SearchService.2" xml:space="preserve"> | |||||
| <value>Search Service 2</value> | |||||
| </data> | |||||
| <data name="SearchServiceNbr" xml:space="preserve"> | |||||
| <value>Search Service Nbr</value> | |||||
| </data> | |||||
| <data name="Send" xml:space="preserve"> | <data name="Send" xml:space="preserve"> | ||||
| <value>Send</value> | <value>Send</value> | ||||
| </data> | </data> |
| throw new HttpRequestException("HTTP client not initialized!"); | throw new HttpRequestException("HTTP client not initialized!"); | ||||
| } | } | ||||
| public async Task<List<SearchService>> GetSearchServices() { | |||||
| if (httpClient != null) { | |||||
| string subResourceUrl = configuration.GetValue<string>("subresource_url_searchservices"); | |||||
| if (!String.IsNullOrEmpty(subResourceUrl)) { | |||||
| HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName)); | |||||
| if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { | |||||
| SearchService[] searchServices = JsonConvert.DeserializeObject<SearchService[]>(await httpResult.Content.ReadAsStringAsync()); | |||||
| return new List<SearchService>(searchServices); | |||||
| } | |||||
| throw new HttpRequestException("HTTP error " + httpResult.StatusCode); | |||||
| } | |||||
| } | |||||
| throw new HttpRequestException("HTTP client not initialized!"); | |||||
| } | |||||
| public async Task<ReportResponse> SendFoundReport(Report report) { | public async Task<ReportResponse> SendFoundReport(Report report) { | ||||
| string subResourceUrl = configuration.GetValue<string>("subresource_url_foundreport"); | string subResourceUrl = configuration.GetValue<string>("subresource_url_foundreport"); | ||||
| return await SendReport(report, subResourceUrl, new FoundReportRepositoryItem((FoundReport)report, 0)); | return await SendReport(report, subResourceUrl, new FoundReportRepositoryItem((FoundReport)report, 0)); |
| Task<List<Brand>> GetBrands(); | Task<List<Brand>> GetBrands(); | ||||
| Task<List<SearchService>> GetSearchServices(); | |||||
| Task<ReportResponse> SendFoundReport(Report report); | Task<ReportResponse> SendFoundReport(Report report); | ||||
| Task<ReportResponse> SendFoundReport(FoundReportRepositoryItem reportRepositoryItem); | Task<ReportResponse> SendFoundReport(FoundReportRepositoryItem reportRepositoryItem); |
| private const string KeyNameColors = "colors"; | private const string KeyNameColors = "colors"; | ||||
| private const string KeyNameBcTypes = "bicycleTypes"; | private const string KeyNameBcTypes = "bicycleTypes"; | ||||
| private const string KeyNameBrands = "brands"; | private const string KeyNameBrands = "brands"; | ||||
| private const string KeyNameSearchservices = "searchServices"; | |||||
| private bool _initializedColors; | private bool _initializedColors; | ||||
| private bool _initializedBcTypes; | private bool _initializedBcTypes; | ||||
| private bool _initializedBrands; | private bool _initializedBrands; | ||||
| private bool _initializedSearchServices; | |||||
| private bool _firstActivation; | private bool _firstActivation; | ||||
| public bool FirstActivation { get => _firstActivation; } | public bool FirstActivation { get => _firstActivation; } | ||||
| private ColorItem[] _colors; | private ColorItem[] _colors; | ||||
| private BicycleType[] _bicycleTypes; | private BicycleType[] _bicycleTypes; | ||||
| private Brand[] _brands; | private Brand[] _brands; | ||||
| private SearchService[] _searchServices; | |||||
| public ColorItem[] Colors { | public ColorItem[] Colors { | ||||
| get => _colors; | get => _colors; | ||||
| get => _brands; | get => _brands; | ||||
| } | } | ||||
| public SearchService[] SearchServices { | |||||
| get => _searchServices; | |||||
| } | |||||
| public event EventHandler Changed; | public event EventHandler Changed; | ||||
| public MasterDataService(IJSRuntime jsRuntime, IBicycleRestService bicycleRestService, IStringLocalizer<Resources> i18n, OnlineStatusProvider onlineStatusProvider) { | public MasterDataService(IJSRuntime jsRuntime, IBicycleRestService bicycleRestService, IStringLocalizer<Resources> i18n, OnlineStatusProvider onlineStatusProvider) { | ||||
| _brands = Defaults.GetBrandDefaults(_i18n).ToArray(); | _brands = Defaults.GetBrandDefaults(_i18n).ToArray(); | ||||
| _colors = Defaults.GetColorDefaults(_i18n).ToArray(); | _colors = Defaults.GetColorDefaults(_i18n).ToArray(); | ||||
| _bicycleTypes = Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | _bicycleTypes = Defaults.GetBicycleTypeDefaults(_i18n).ToArray(); | ||||
| _searchServices= Defaults.GetSearchServiceDefaults(_i18n).ToArray(); | |||||
| } | } | ||||
| public async Task SynchronizeMasterdata() { | public async Task SynchronizeMasterdata() { | ||||
| await SynchronizeColors(); | await SynchronizeColors(); | ||||
| await SynchronizeBcTypes(); | await SynchronizeBcTypes(); | ||||
| await SynchronizeBrands(); | await SynchronizeBrands(); | ||||
| await SynchronizeSearchServices(); | |||||
| } finally { | } finally { | ||||
| _firstActivation = false; | _firstActivation = false; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| public async Task SynchronizeSearchServices() { | |||||
| SearchService[] searchServices = (await _bicycleRestService.GetSearchServices()).ToArray(); | |||||
| if (searchServices != null && searchServices.Length > 0) { | |||||
| _searchServices = searchServices; | |||||
| await SaveSearchServicesToStorage(searchServices); | |||||
| } | |||||
| } | |||||
| public async Task<ColorItem[]> GetColors() { | public async Task<ColorItem[]> GetColors() { | ||||
| ColorItem[] colors = await GetColorsFromStorage(); | ColorItem[] colors = await GetColorsFromStorage(); | ||||
| if (colors != null && colors.Length > 0) { | if (colors != null && colors.Length > 0) { | ||||
| return Brands; | return Brands; | ||||
| } | } | ||||
| public async Task<SearchService[]> GetSearchServices() { | |||||
| SearchService[] searchServices = await GetSearchServicesFromStorage(); | |||||
| if (searchServices != null && searchServices.Length > 0) { | |||||
| _searchServices = searchServices; | |||||
| } | |||||
| _searchServices = SortSearchServices(new List<SearchService>(_searchServices)).ToArray(); | |||||
| return SearchServices; | |||||
| } | |||||
| // This method is called from BlazorRegisterStorageEvent when the storage changed | // This method is called from BlazorRegisterStorageEvent when the storage changed | ||||
| [JSInvokable] | [JSInvokable] | ||||
| public void OnStorageUpdated(string key) { | public void OnStorageUpdated(string key) { | ||||
| return result; | return result; | ||||
| } | } | ||||
| private async ValueTask<SearchService[]> GetSearchServicesFromStorage() { | |||||
| // 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 (!_initializedSearchServices) { | |||||
| // 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); | |||||
| _initializedSearchServices = true; | |||||
| } | |||||
| // Read the JSON string that contains the data from the local storage | |||||
| SearchService[] result; | |||||
| var str = await _jsRuntime.InvokeAsync<string>("BlazorGetLocalStorage", KeyNameSearchservices); | |||||
| if (String.IsNullOrEmpty(str)) { | |||||
| result = Array.Empty<SearchService>(); | |||||
| } else { | |||||
| result = JsonConvert.DeserializeObject<SearchService[]>(str) ?? Array.Empty<SearchService>(); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| private async Task SaveColorsToStorage(ColorItem[] colors) { | private async Task SaveColorsToStorage(ColorItem[] colors) { | ||||
| var json = JsonConvert.SerializeObject(colors); | var json = JsonConvert.SerializeObject(colors); | ||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json); | await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameBrands, json); | ||||
| } | } | ||||
| private async Task SaveSearchServicesToStorage(SearchService[] searchServices) { | |||||
| var json = JsonConvert.SerializeObject(searchServices); | |||||
| await _jsRuntime.InvokeVoidAsync("BlazorSetLocalStorage", KeyNameSearchservices, json); | |||||
| } | |||||
| private static List<ColorItem> SortColors(List<ColorItem> cols) { | 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); }); | cols.Sort(delegate (ColorItem c1, ColorItem c2) { return c1.Id == 0 ? -1 : c2.Id == 0 ? 1 : c1.Bezeichnung.CompareTo(c2.Bezeichnung); }); | ||||
| return cols; | return cols; | ||||
| brands.Sort(delegate (Brand b1, Brand b2) { return b1.Id == 0 ? -1 : b2.Id == 0 ? 1 : b1.Bezeichnung.CompareTo(b2.Bezeichnung); }); | brands.Sort(delegate (Brand b1, Brand b2) { return b1.Id == 0 ? -1 : b2.Id == 0 ? 1 : b1.Bezeichnung.CompareTo(b2.Bezeichnung); }); | ||||
| return brands; | return brands; | ||||
| } | } | ||||
| private static List<SearchService> SortSearchServices(List<SearchService> searchServices) { | |||||
| searchServices.Sort(delegate (SearchService ss1, SearchService ss2) { return ss1.Id == 0 ? -1 : ss2.Id == 0 ? 1 : ss1.Bezeichnung.CompareTo(ss2.Bezeichnung); }); | |||||
| return searchServices; | |||||
| } | |||||
| } | } | ||||
| } | } |
| "subresource_url_colors": "api/{0}/{1}/fundvelo/colors", | "subresource_url_colors": "api/{0}/{1}/fundvelo/colors", | ||||
| "subresource_url_brands": "api/{0}/{1}/fundvelo/brands", | "subresource_url_brands": "api/{0}/{1}/fundvelo/brands", | ||||
| "subresource_url_types": "api/{0}/{1}/fundvelo/types", | "subresource_url_types": "api/{0}/{1}/fundvelo/types", | ||||
| "subresource_url_searchservices": "api/{0}/{1}/fundvelo/searchservices", | |||||
| "subresource_url_foundreport": "api/{0}/{1}/fundvelo/fundmeldung", | "subresource_url_foundreport": "api/{0}/{1}/fundvelo/fundmeldung", | ||||
| "subresource_url_missingreport": "api/{0}/{1}/fundvelo/suchauftrag" | "subresource_url_missingreport": "api/{0}/{1}/fundvelo/suchauftrag" | ||||
| } | } |