Quellcode durchsuchen

SearchServices and SearchServiceNbr

master
Flo Smilari vor 4 Jahren
Ursprung
Commit
1116dc4a87

+ 31
- 1
Pages/CaritasServiceFundVeloMissingKeyDataPage.razor Datei anzeigen

@@ -115,6 +115,21 @@
<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>
</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">
<MatStringField Class="w-100 form-check-label" Label="@i18n["Remark"]" Outlined="true" type="text" @bind-Value="remark"></MatStringField>
</div>
@@ -145,6 +160,7 @@
private Boolean loading = false;
private ColorItem selectedColor;
private BicycleType selectedBcType;
private SearchService selectedSearchService;
private string brandStringValue;
private Brand selectedBrand;
private Brand SelectedBrand {
@@ -153,6 +169,7 @@
}
private string frameNumber;
private string remark;
private string searchServiceNbr;
private uint age;
private float price;
@@ -167,6 +184,7 @@
await GetColors();
await GetBicycleTypes();
await GetBrands();
await GetSearchServices();
refreshGUIFromDto();
PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
StateHasChanged();
@@ -188,6 +206,10 @@
await MasterDataService.GetBrands();
}
private async Task GetSearchServices() {
await MasterDataService.GetSearchServices();
}
private ColorItem[] Colors {
get => MasterDataService.Colors;
}
@@ -200,6 +222,10 @@
get => MasterDataService.Brands;
}
private SearchService[] SearchServices {
get => MasterDataService.SearchServices;
}
private void Next() {
updateDtoFromGUI();
NavigationManager.NavigateTo("fundvelo/account/Missing");
@@ -245,9 +271,11 @@
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);
frameNumber = report.RahmenNummer;
remark = report.Bemerkung;
age = report.Alter;
price = report.Preis;
selectedSearchService = Array.Find(SearchServices, searchService => searchService.Id == report.SuchDienstId);
searchServiceNbr = report.SuchDienstNr;
remark = report.Bemerkung;
}
private void updateDtoFromGUI() {
@@ -266,6 +294,8 @@
report.Bemerkung = remark;
report.Alter = age;
report.Preis = price;
report.SuchDienstId = selectedSearchService.Id;
report.SuchDienstNr = searchServiceNbr;
}
}

+ 14
- 0
Shared/Models/Defaults.cs Datei anzeigen

@@ -83,6 +83,12 @@ namespace cwebplusApp.Shared.Models {
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) {
List<ColorItem> colors = new();
foreach (ColorItem color in ColorItems) {
@@ -107,6 +113,14 @@ namespace cwebplusApp.Shared.Models {
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;
}
}
}

+ 19
- 0
Shared/Models/SearchService.cs Datei anzeigen

@@ -0,0 +1,19 @@
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;
}
}
}

+ 15
- 0
Shared/ResourceFiles/Resources.de.resx Datei anzeigen

@@ -462,6 +462,21 @@
<data name="Save" xml:space="preserve">
<value>Speichern</value>
</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">
<value>Absenden</value>
</data>

+ 15
- 0
Shared/ResourceFiles/Resources.fr.resx Datei anzeigen

@@ -462,6 +462,21 @@
<data name="Save" xml:space="preserve">
<value>Sauver</value>
</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">
<value>Envoie</value>
</data>

+ 15
- 0
Shared/ResourceFiles/Resources.it.resx Datei anzeigen

@@ -462,9 +462,24 @@
<data name="Save" xml:space="preserve">
<value>Salva</value>
</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">
<value>Invia</value>
</data>
<data name="Service de recherche" xml:space="preserve">
<value>N. del Servizio ritrovamento</value>
</data>
<data name="Specifications" xml:space="preserve">
<value>Descrizione dettagliata</value>
</data>

+ 15
- 0
Shared/ResourceFiles/Resources.resx Datei anzeigen

@@ -462,6 +462,21 @@
<data name="Save" xml:space="preserve">
<value>Save</value>
</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">
<value>Send</value>
</data>

+ 16
- 0
Shared/Services/BicycleRestService.cs Datei anzeigen

@@ -86,6 +86,22 @@ namespace cwebplusApp.Shared.Services {
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) {
string subResourceUrl = configuration.GetValue<string>("subresource_url_foundreport");
return await SendReport(report, subResourceUrl, new FoundReportRepositoryItem((FoundReport)report, 0));

+ 2
- 0
Shared/Services/IBicycleRestService.cs Datei anzeigen

@@ -14,6 +14,8 @@ namespace cwebplusApp.Shared.Services {
Task<List<Brand>> GetBrands();
Task<List<SearchService>> GetSearchServices();
Task<ReportResponse> SendFoundReport(Report report);
Task<ReportResponse> SendFoundReport(FoundReportRepositoryItem reportRepositoryItem);

+ 58
- 0
Shared/Services/MasterDataService.cs Datei anzeigen

@@ -17,15 +17,18 @@ namespace cwebplusApp.Shared.Services {
private const string KeyNameColors = "colors";
private const string KeyNameBcTypes = "bicycleTypes";
private const string KeyNameBrands = "brands";
private const string KeyNameSearchservices = "searchServices";
private bool _initializedColors;
private bool _initializedBcTypes;
private bool _initializedBrands;
private bool _initializedSearchServices;
private bool _firstActivation;
public bool FirstActivation { get => _firstActivation; }
private ColorItem[] _colors;
private BicycleType[] _bicycleTypes;
private Brand[] _brands;
private SearchService[] _searchServices;
public ColorItem[] Colors {
get => _colors;
@@ -39,6 +42,10 @@ namespace cwebplusApp.Shared.Services {
get => _brands;
}
public SearchService[] SearchServices {
get => _searchServices;
}
public event EventHandler Changed;
public MasterDataService(IJSRuntime jsRuntime, IBicycleRestService bicycleRestService, IStringLocalizer<Resources> i18n, OnlineStatusProvider onlineStatusProvider) {
@@ -50,6 +57,7 @@ namespace cwebplusApp.Shared.Services {
_brands = Defaults.GetBrandDefaults(_i18n).ToArray();
_colors = Defaults.GetColorDefaults(_i18n).ToArray();
_bicycleTypes = Defaults.GetBicycleTypeDefaults(_i18n).ToArray();
_searchServices= Defaults.GetSearchServiceDefaults(_i18n).ToArray();
}
public async Task SynchronizeMasterdata() {
@@ -58,6 +66,7 @@ namespace cwebplusApp.Shared.Services {
await SynchronizeColors();
await SynchronizeBcTypes();
await SynchronizeBrands();
await SynchronizeSearchServices();
} finally {
_firstActivation = false;
}
@@ -90,6 +99,14 @@ namespace cwebplusApp.Shared.Services {
}
}
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() {
ColorItem[] colors = await GetColorsFromStorage();
if (colors != null && colors.Length > 0) {
@@ -117,6 +134,15 @@ namespace cwebplusApp.Shared.Services {
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
[JSInvokable]
public void OnStorageUpdated(string key) {
@@ -199,6 +225,28 @@ namespace cwebplusApp.Shared.Services {
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) {
var json = JsonConvert.SerializeObject(colors);
@@ -215,6 +263,11 @@ namespace cwebplusApp.Shared.Services {
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) {
cols.Sort(delegate (ColorItem c1, ColorItem c2) { return c1.Id == 0 ? -1 : c2.Id == 0 ? 1 : c1.Bezeichnung.CompareTo(c2.Bezeichnung); });
return cols;
@@ -229,5 +282,10 @@ namespace cwebplusApp.Shared.Services {
brands.Sort(delegate (Brand b1, Brand b2) { return b1.Id == 0 ? -1 : b2.Id == 0 ? 1 : b1.Bezeichnung.CompareTo(b2.Bezeichnung); });
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;
}
}
}

+ 1
- 0
wwwroot/appsettings.json Datei anzeigen

@@ -4,6 +4,7 @@
"subresource_url_colors": "api/{0}/{1}/fundvelo/colors",
"subresource_url_brands": "api/{0}/{1}/fundvelo/brands",
"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_missingreport": "api/{0}/{1}/fundvelo/suchauftrag"
}

Laden…
Abbrechen
Speichern