diff --git a/Wonky.Client/Components/CompanySearchPhraseComponent.razor b/Wonky.Client/Components/CompanySearchPhraseComponent.razor new file mode 100644 index 00000000..e2d5c978 --- /dev/null +++ b/Wonky.Client/Components/CompanySearchPhraseComponent.razor @@ -0,0 +1,23 @@ +@* +// Copyright (C) 2022 FCS Frede's Computer Services. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] +// +*@ + +
+ + +
+ diff --git a/Wonky.Client/Components/CompanySearchPhraseComponent.razor.cs b/Wonky.Client/Components/CompanySearchPhraseComponent.razor.cs new file mode 100644 index 00000000..8cd0a344 --- /dev/null +++ b/Wonky.Client/Components/CompanySearchPhraseComponent.razor.cs @@ -0,0 +1,63 @@ +// Copyright (C) 2022 FCS Frede's Computer Services. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] +// + +using System.Timers; +using Microsoft.AspNetCore.Components; +using Wonky.Client.Services; +using Timer = System.Timers.Timer; + +namespace Wonky.Client.Components +{ + public partial class CompanySearchPhraseComponent + { + private Timer InputTimer { get; set; } = new(); + private string SearchTerm { get; set; } = ""; + private Preferences Preferences { get; set; } = new (); + [Inject] private UserPreferenceService PreferenceService { get; set; } + [Parameter] public EventCallback OnChanged { get; set; } + + protected override async Task OnInitializedAsync() + { + Preferences = await PreferenceService.GetPreferences(); + SearchTerm = string.IsNullOrWhiteSpace(Preferences.CompanyFilterPhrase) ? "" : Preferences.CompanyFilterPhrase; + + if(!string.IsNullOrWhiteSpace(SearchTerm)) + await OnChanged.InvokeAsync(SearchTerm); + } + + private async Task ClearSearch() + { + InputTimer.Dispose(); + SearchTerm = ""; + await OnChanged.InvokeAsync(SearchTerm); + } + + private async Task OnSearchChanged() + { + InputTimer.Dispose(); + InputTimer = new Timer(500); + InputTimer.AutoReset = false; + InputTimer.Elapsed += OnTimerElapsed; + InputTimer.Enabled = true; + await PreferenceService.SetCompanyFilterPhrase(SearchTerm.Trim()); + } + + private void OnTimerElapsed(object? sender, ElapsedEventArgs e) + { + InputTimer.Dispose(); + OnChanged.InvokeAsync(SearchTerm); + } + } +} diff --git a/Wonky.Client/Components/SearchPhraseComponent.razor b/Wonky.Client/Components/ItemSearchPhraseComponent.razor similarity index 100% rename from Wonky.Client/Components/SearchPhraseComponent.razor rename to Wonky.Client/Components/ItemSearchPhraseComponent.razor diff --git a/Wonky.Client/Components/SearchPhraseComponent.razor.cs b/Wonky.Client/Components/ItemSearchPhraseComponent.razor.cs similarity index 74% rename from Wonky.Client/Components/SearchPhraseComponent.razor.cs rename to Wonky.Client/Components/ItemSearchPhraseComponent.razor.cs index 86b56fea..c4a3f319 100644 --- a/Wonky.Client/Components/SearchPhraseComponent.razor.cs +++ b/Wonky.Client/Components/ItemSearchPhraseComponent.razor.cs @@ -19,28 +19,14 @@ using Timer = System.Timers.Timer; namespace Wonky.Client.Components { - public partial class SearchPhraseComponent + public partial class ItemSearchPhraseComponent { private Timer _timer { get; set; } = new(); private string _searchTerm { get; set; } = ""; [Parameter] public EventCallback OnChanged { get; set; } - [Parameter] public string SavedSearch { get; set; } = ""; - - protected override void OnParametersSet() - { - _searchTerm = SavedSearch; - } - - protected override void OnInitialized() - { - if (string.IsNullOrWhiteSpace(SavedSearch)) return; - _searchTerm = SavedSearch; - OnChanged.InvokeAsync(_searchTerm); - } private void ClearSearch() { - SavedSearch = ""; _searchTerm = ""; OnChanged.InvokeAsync(""); } @@ -48,7 +34,6 @@ namespace Wonky.Client.Components private void OnSearchChanged() { _timer.Dispose(); - // create new timer _timer = new Timer(500); _timer.AutoReset = false; _timer.Elapsed += OnTimerElapsed; @@ -57,7 +42,6 @@ namespace Wonky.Client.Components private void OnTimerElapsed(object? sender, ElapsedEventArgs e) { - // if (!string.IsNullOrWhiteSpace(_searchTerm) && _searchTerm.Length < 3) return; OnChanged.InvokeAsync(_searchTerm); _timer.Elapsed -= OnTimerElapsed; _timer.Enabled = false; diff --git a/Wonky.Client/Pages/AllCustomersListPage.razor b/Wonky.Client/Pages/AllCustomersListPage.razor index cc0cb50a..bc3be123 100644 --- a/Wonky.Client/Pages/AllCustomersListPage.razor +++ b/Wonky.Client/Pages/AllCustomersListPage.razor @@ -32,7 +32,7 @@
- +
diff --git a/Wonky.Client/Pages/CustomerListPage.razor b/Wonky.Client/Pages/CustomerListPage.razor index 6440d14b..9d768f28 100644 --- a/Wonky.Client/Pages/CustomerListPage.razor +++ b/Wonky.Client/Pages/CustomerListPage.razor @@ -28,7 +28,7 @@
- +
diff --git a/Wonky.Client/Pages/CustomerListPage.razor.cs b/Wonky.Client/Pages/CustomerListPage.razor.cs index 70810c4d..cf18fd93 100644 --- a/Wonky.Client/Pages/CustomerListPage.razor.cs +++ b/Wonky.Client/Pages/CustomerListPage.razor.cs @@ -92,16 +92,17 @@ namespace Wonky.Client.Pages private async Task SetSearchPhrase(string searchTerm) { - _savedSearch = searchTerm; - await _preferenceService.SetCompanyFilterPhrase(searchTerm.Trim()); - - // do not trigger search unless minimum 4 chars - if (!string.IsNullOrWhiteSpace(searchTerm) && searchTerm.Length < 4) return; + // if (!string.IsNullOrWhiteSpace(searchTerm) && searchTerm.Length < 3) return; _companyList = new List(); _paging.PageNumber = 1; _paging.SearchTerm = searchTerm; await GetCompanies(); + if (!string.IsNullOrWhiteSpace(searchTerm) && searchTerm.TrimEnd().Length > 2) + { + _savedSearch = searchTerm; + await _preferenceService.SetCompanyFilterPhrase(searchTerm.Trim()); + } } private async Task SetSortCol(string orderBy) diff --git a/Wonky.Client/Pages/ItemCatalogPage.razor b/Wonky.Client/Pages/ItemCatalogPage.razor index c9c25fc4..1ed52282 100644 --- a/Wonky.Client/Pages/ItemCatalogPage.razor +++ b/Wonky.Client/Pages/ItemCatalogPage.razor @@ -31,7 +31,7 @@
- +
diff --git a/Wonky.Client/Pages/ItemCatalogPage.razor.cs b/Wonky.Client/Pages/ItemCatalogPage.razor.cs index 96d893d4..cab0de20 100644 --- a/Wonky.Client/Pages/ItemCatalogPage.razor.cs +++ b/Wonky.Client/Pages/ItemCatalogPage.razor.cs @@ -38,7 +38,6 @@ public partial class ItemCatalogPage : IDisposable private MetaData? _metaData { get; set; } = new(); private CatalogPagingParams _paging = new(); private Preferences _preferences = new(); - private string _searchTerm { get; set; } = ""; protected override async Task OnInitializedAsync() { @@ -61,12 +60,6 @@ public partial class ItemCatalogPage : IDisposable private async Task SetSearchPhrase(string searchTerm) { - _searchTerm = searchTerm; - - if (_paging.SearchColumn != "shortName" - && !string.IsNullOrWhiteSpace(_searchTerm) - && _searchTerm.Length < 4) return; - _items = new List(); _paging.PageNumber = 1; _paging.SearchTerm = searchTerm; diff --git a/Wonky.Client/Shared/PriceListModal.razor b/Wonky.Client/Shared/PriceListModal.razor index 28c7c044..818caae2 100644 --- a/Wonky.Client/Shared/PriceListModal.razor +++ b/Wonky.Client/Shared/PriceListModal.razor @@ -30,7 +30,7 @@
- +
@*
*@ @* *@ diff --git a/Wonky.Client/Shared/PriceListModal.razor.cs b/Wonky.Client/Shared/PriceListModal.razor.cs index b30b6d79..fa31134b 100644 --- a/Wonky.Client/Shared/PriceListModal.razor.cs +++ b/Wonky.Client/Shared/PriceListModal.razor.cs @@ -35,7 +35,6 @@ public partial class PriceListModal : IDisposable private MetaData? _metaData { get; set; } = new(); private CatalogPagingParams _paging = new(); private Preferences _preferences = new(); - private string _searchTerm { get; set; } = ""; protected override async Task OnInitializedAsync() { @@ -56,7 +55,6 @@ public partial class PriceListModal : IDisposable private async Task SetSearchPhrase(string searchTerm) { - _searchTerm = searchTerm; _items = new List(); _paging.PageNumber = 1; _paging.SearchTerm = searchTerm; diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index b90a9357..6b76ca6d 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -1,13 +1,13 @@ { "appInfo": { "name": "Wonky Client", - "version": "0.10.120", + "version": "0.10.125", "rc": true, "sandBox": false, "image": "grumpy-coder.png" }, "apiConfig": { - "innoBaseUrl": "https://app.innotec.dk", + "innoBaseUrl": "https://api.innotec.dk", "glsTrackUrl": "https://www.gls-group.eu/276-I-PORTAL-WEB/content/GLS/DK01/DA/5004.htm?txtAction=71000&txtRefNo=", "glsId": "", "serviceVirk": "api/v2/services/virk",