optimizing search facility
This commit is contained in:
parent
74e41b09bf
commit
e4947a9b62
12 changed files with 99 additions and 37 deletions
23
Wonky.Client/Components/CompanySearchPhraseComponent.razor
Normal file
23
Wonky.Client/Components/CompanySearchPhraseComponent.razor
Normal file
|
@ -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]
|
||||
//
|
||||
*@
|
||||
|
||||
<div class="input-group">
|
||||
<input id="search-input" type="text" class="form-control" placeholder="Søg ..." aria-described-by="search-addon"
|
||||
@bind-value="@SearchTerm" @bind-value:event="oninput" @onkeyup="OnSearchChanged" />
|
||||
<span class="input-group-text" id="search-addon"><i class="oi oi-delete" @onclick="ClearSearch"></i></span>
|
||||
</div>
|
||||
|
|
@ -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<string> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<string> 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;
|
|
@ -32,7 +32,7 @@
|
|||
<CompanySearchColumnComponent OnChanged="SetSearchCol" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<SearchPhraseComponent SavedSearch="@_savedSearch" OnChanged="SetSearchPhrase" />
|
||||
<CompanySearchPhraseComponent SavedSearch="@_savedSearch" OnChanged="SetSearchPhrase" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<CompanySortComponent OnChanged="SetSortCol" />
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<CompanySearchColumnComponent OnChanged="SetSearchCol" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<SearchPhraseComponent SavedSearch="@_savedSearch" OnChanged="SetSearchPhrase" />
|
||||
<CompanySearchPhraseComponent OnChanged="SetSearchPhrase" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<CompanySortComponent OnChanged="SetSortCol" />
|
||||
|
|
|
@ -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<CompanyDto>();
|
||||
_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)
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<ItemSearchComponent OnChanged="SetSearchCol"/>
|
||||
</div>
|
||||
<div class="col">
|
||||
<SearchPhraseComponent SavedSearch="@_searchTerm" OnChanged="SetSearchPhrase"/>
|
||||
<ItemSearchPhraseComponent OnChanged="SetSearchPhrase"/>
|
||||
</div>
|
||||
<div class="col">
|
||||
<ItemSortComponent OnChanged="SetSortCol"/>
|
||||
|
|
|
@ -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<SalesItemView>();
|
||||
_paging.PageNumber = 1;
|
||||
_paging.SearchTerm = searchTerm;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<ItemSearchComponent OnChanged="SetSearchCol"/>
|
||||
</div>
|
||||
<div class="col">
|
||||
<SearchPhraseComponent SavedSearch="@_searchTerm" OnChanged="SetSearchPhrase"/>
|
||||
<ItemSearchPhraseComponent OnChanged="SetSearchPhrase"/>
|
||||
</div>
|
||||
@* <div class="col"> *@
|
||||
@* <ItemSortComponent OnChanged="SetSortCol"/> *@
|
||||
|
|
|
@ -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<SalesItemView>();
|
||||
_paging.PageNumber = 1;
|
||||
_paging.SearchTerm = searchTerm;
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue