From 27100c7d656ab6922fa3c5793b0ff808e14509bc Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 16 Sep 2021 10:55:09 +0200 Subject: [PATCH] Completata search libera (senza debounce da sistemare) --- MP.FileData/Controllers/FileController.cs | 24 +++++-- MP.Prog/Components/SearchMod.razor | 16 +---- MP.Prog/Data/FileArchDataService.cs | 4 +- MP.Prog/Data/MessageService.cs | 80 +++++++++++++++++------ MP.Prog/Data/SelectData.cs | 3 +- MP.Prog/MP.Prog.csproj | 2 +- MP.Prog/Pages/Archive.razor.cs | 46 ++++++++++--- MP.Prog/Resources/ChangeLog.html | 2 +- MP.Prog/Resources/VersNum.txt | 2 +- MP.Prog/Resources/manifest.xml | 2 +- 10 files changed, 128 insertions(+), 53 deletions(-) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 3a929a28..a519a78d 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -162,15 +162,21 @@ namespace MP.FileData.Controllers dbCtx.Dispose(); } - public int FileCountFilt(string IdxMacchina, bool OnlyActive, bool OnlyMod, bool OnlyNoTag, string FileName, string Tag) + public int FileCountFilt(string IdxMacchina, bool OnlyActive, bool OnlyMod, bool OnlyNoTag, string FileName, string Tag, string SearchVal) { int answ = 0; using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) { answ = localDbCtx .DbSetProgFile - .Where(x => (x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.Active == OnlyActive || !OnlyActive) && (x.Tags.Count() == 0 || !OnlyNoTag) && (!OnlyMod || x.DiskStatus != FileState.Ok) && (x.Path.Equals(FileName) || string.IsNullOrEmpty(FileName)) && (x.Tags.Where(t => t.TagId == Tag).Count() > 0 || string.IsNullOrEmpty(Tag))) - .Count(); + .Where(x => + (x.IdxMacchina == IdxMacchina || IdxMacchina == "0") + && (x.Active == OnlyActive || !OnlyActive) && (x.Tags.Count() == 0 || !OnlyNoTag) + && (!OnlyMod || x.DiskStatus != FileState.Ok) + && (x.Path.Equals(FileName) || string.IsNullOrEmpty(FileName)) + && (x.Tags.Where(t => t.TagId == Tag).Count() > 0 || string.IsNullOrEmpty(Tag)) + && ((!string.IsNullOrEmpty(SearchVal) && (x.Path.Contains(SearchVal) || x.Tags.Where(t => t.TagId.Contains(SearchVal)).Count() > 0)) || string.IsNullOrEmpty(SearchVal)) + ).Count(); } return answ; } @@ -255,7 +261,7 @@ namespace MP.FileData.Controllers return dbResult; } - public List FileGetFilt(string IdxMacchina, bool OnlyActive, bool OnlyMod, bool OnlyNoTag, string FileName, string Tag, int NumStart, int NumRecords) + public List FileGetFilt(string IdxMacchina, bool OnlyActive, bool OnlyMod, bool OnlyNoTag, string FileName, string Tag, string SearchVal, int NumStart, int NumRecords) { List dbResult = new List(); using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) @@ -264,8 +270,14 @@ namespace MP.FileData.Controllers .DbSetProgFile .Include(m => m.Macchina) .Include(t => t.Tags) - .Where(x => (x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.Active == OnlyActive || !OnlyActive) && (x.Tags.Count() == 0 || !OnlyNoTag) && (!OnlyMod || x.DiskStatus != FileState.Ok) && (x.Path.Equals(FileName) || string.IsNullOrEmpty(FileName)) && (x.Tags.Where(t => t.TagId == Tag).Count() > 0 || string.IsNullOrEmpty(Tag))) - .OrderByDescending(x => x.LastMod) + .Where(x => + (x.IdxMacchina == IdxMacchina || IdxMacchina == "0") + && (x.Active == OnlyActive || !OnlyActive) && (x.Tags.Count() == 0 || !OnlyNoTag) + && (!OnlyMod || x.DiskStatus != FileState.Ok) + && (x.Path.Equals(FileName) || string.IsNullOrEmpty(FileName)) + && (x.Tags.Where(t => t.TagId == Tag).Count() > 0 || string.IsNullOrEmpty(Tag)) + && ((!string.IsNullOrEmpty(SearchVal) && (x.Path.Contains(SearchVal) || x.Tags.Where(t => t.TagId.Contains(SearchVal)).Count() > 0)) || string.IsNullOrEmpty(SearchVal)) + ).OrderByDescending(x => x.LastMod) .Skip(NumStart) .Take(NumRecords) .ToList(); diff --git a/MP.Prog/Components/SearchMod.razor b/MP.Prog/Components/SearchMod.razor index fde33991..cc5329e9 100644 --- a/MP.Prog/Components/SearchMod.razor +++ b/MP.Prog/Components/SearchMod.razor @@ -11,9 +11,6 @@ @code { - [Parameter] - public EventCallback searchUpdated { get; set; } - [Parameter] public string searchVal { @@ -23,20 +20,13 @@ } set { - MessageService.SearchVal = value; - var pUpd = Task.Run(async () => + if (!MessageService.SearchVal.Equals(value)) { - await reportChange(); - }); - pUpd.Wait(); + MessageService.SearchVal = value; + } } } - private async Task reportChange() - { - await searchUpdated.InvokeAsync(searchVal); - } - private void reset() { searchVal = ""; diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index 21f558e2..18858c25 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -146,7 +146,7 @@ namespace MP.Prog.Data int numCount = 0; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - numCount = dbController.FileCountFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.OnlyNoTag, CurrFilter.FileName, CurrFilter.Tag); + numCount = dbController.FileCountFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.OnlyNoTag, CurrFilter.FileName, CurrFilter.Tag, CurrFilter.SearchVal); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per FileCountFilt: {ts.TotalMilliseconds} ms"); @@ -163,7 +163,7 @@ namespace MP.Prog.Data List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.FileGetFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.OnlyNoTag, CurrFilter.FileName, CurrFilter.Tag, CurrFilter.NumSkip, CurrFilter.PageSize).ToList(); + dbResult = dbController.FileGetFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.OnlyNoTag, CurrFilter.FileName, CurrFilter.Tag, CurrFilter.SearchVal, CurrFilter.NumSkip, CurrFilter.PageSize).ToList(); //dbResult = dbController.FileGetFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.FirstRecord, CurrFilter.PageSize * 10, CurrFilter.SearchVal).ToList(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; diff --git a/MP.Prog/Data/MessageService.cs b/MP.Prog/Data/MessageService.cs index 00556f11..bed71adb 100644 --- a/MP.Prog/Data/MessageService.cs +++ b/MP.Prog/Data/MessageService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using System.Timers; namespace MP.Prog.Data { @@ -12,11 +13,17 @@ namespace MP.Prog.Data private SelectData _fileFilter = SelectData.Init(5, 15); private string _pageIcon; private string _pageName; - private string _searchVal; + private string _searchVal = ""; private bool showSearch; #endregion Private Fields + #region Protected Fields + + protected Timer SearchTimer; + + #endregion Protected Fields + #region Public Events public event Action EA_FilterUpdated; @@ -41,11 +48,7 @@ namespace MP.Prog.Data if (_fileFilter != value) { _fileFilter = value; - - if (EA_FilterUpdated != null) - { - EA_FilterUpdated?.Invoke(); - } + ReportFilter(); } } } @@ -84,11 +87,8 @@ namespace MP.Prog.Data if (_searchVal != value) { _searchVal = value; - - if (EA_SearchUpdated != null) - { - EA_SearchUpdated?.Invoke(); - } + //TriggerSearch(); + ReportSearch(); } } } @@ -103,17 +103,11 @@ namespace MP.Prog.Data showSearch = value; if (showSearch) { - if (EA_ShowSearch != null) - { - EA_ShowSearch?.Invoke(); - } + ReportShowSearch(); } else { - if (EA_HideSearch != null) - { - EA_HideSearch?.Invoke(); - } + ReportHideSearch(); } } } @@ -123,6 +117,22 @@ namespace MP.Prog.Data #region Private Methods + private void ReportFilter() + { + if (EA_FilterUpdated != null) + { + EA_FilterUpdated?.Invoke(); + } + } + + private void ReportHideSearch() + { + if (EA_HideSearch != null) + { + EA_HideSearch?.Invoke(); + } + } + private void ReportPageUpd() { if (EA_PageUpdated != null) @@ -139,6 +149,38 @@ namespace MP.Prog.Data } } + private void ReportShowSearch() + { + if (EA_ShowSearch != null) + { + EA_ShowSearch?.Invoke(); + } + } + + private void SearchTimerElapsed_TickAsync(object sender, EventArgs e) + { + DisposeSearchTimer(); + ReportSearch(); + } + + private void TriggerSearch() + { + DisposeSearchTimer(); + SearchTimer = new Timer(150); + SearchTimer.Elapsed += SearchTimerElapsed_TickAsync; + SearchTimer.Enabled = true; + SearchTimer.Start(); + } + #endregion Private Methods + + #region Protected Methods + + protected void DisposeSearchTimer() + { + SearchTimer.Dispose(); + } + + #endregion Protected Methods } } \ No newline at end of file diff --git a/MP.Prog/Data/SelectData.cs b/MP.Prog/Data/SelectData.cs index 08f7b5c6..577fdcdf 100644 --- a/MP.Prog/Data/SelectData.cs +++ b/MP.Prog/Data/SelectData.cs @@ -66,7 +66,8 @@ namespace MP.Prog.Data SelectData answ = new SelectData() { DateEnd = endRounded, - DateStart = endRounded.AddDays(-numDayPrev) + DateStart = endRounded.AddDays(-numDayPrev), + SearchVal = "" }; return answ; } diff --git a/MP.Prog/MP.Prog.csproj b/MP.Prog/MP.Prog.csproj index 925e64c0..e509580b 100644 --- a/MP.Prog/MP.Prog.csproj +++ b/MP.Prog/MP.Prog.csproj @@ -3,7 +3,7 @@ net5.0 MP.Prog - 1.1.2109.1609 + 1.1.2109.1610 diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index 82e190ee..e823eb27 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -136,6 +136,31 @@ namespace MP.Prog.Pages } } + private string SearchVal + { + get + { + string answ = ""; + if (AppMService.File_Filter != null) + { + answ = AppMService.File_Filter.SearchVal; + } + return answ; + } + set + { + if (!AppMService.File_Filter.SearchVal.Equals(value)) + { + AppMService.File_Filter.SearchVal = value; + var pUpd = Task.Run(async () => + { + await AsyncReload(); + }); + pUpd.Wait(); + } + } + } + private string SelFileName { get @@ -359,11 +384,11 @@ namespace MP.Prog.Pages protected override async Task OnInitializedAsync() { SearchTag = defTag; - AppMService.ShowSearch = false; + AppMService.ShowSearch = true; AppMService.PageName = "Archivio File Programmi"; AppMService.PageIcon = "fas fa-folder pr-2"; AppMService.EA_SearchUpdated += OnSeachUpdated; - AppMService.EA_FilterUpdated += OnSeachUpdated; + AppMService.EA_FilterUpdated += OnFilterUpdated; await ReloadAllData(); isLoading = false; } @@ -423,6 +448,7 @@ namespace MP.Prog.Pages currRecord = null; ListRecords = null; AppMService.File_Filter = SelectData.Init(5, 10); + AppMService.SearchVal = ""; SearchTag = defTag; await ReloadAllData(); isLoading = false; @@ -471,16 +497,20 @@ namespace MP.Prog.Pages public void Dispose() { AppMService.EA_SearchUpdated -= OnSeachUpdated; - AppMService.EA_FilterUpdated -= OnSeachUpdated; + AppMService.EA_FilterUpdated -= OnFilterUpdated; + } + + public async void OnFilterUpdated() + { + await ReloadData(); + //StateHasChanged(); } public async void OnSeachUpdated() { - await InvokeAsync(() => - { - Task task = UpdateData(); - StateHasChanged(); - }); + SearchVal = AppMService.SearchVal; + //await ReloadData(); + StateHasChanged(); } public void ResetTag() diff --git a/MP.Prog/Resources/ChangeLog.html b/MP.Prog/Resources/ChangeLog.html index cd52035c..a31cefd7 100644 --- a/MP.Prog/Resources/ChangeLog.html +++ b/MP.Prog/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo gestione Programmi MAPO -

Versione: 1.1.2109.1609

+

Versione: 1.1.2109.1610


Note di rilascio:
    diff --git a/MP.Prog/Resources/VersNum.txt b/MP.Prog/Resources/VersNum.txt index 91d87534..d8b00005 100644 --- a/MP.Prog/Resources/VersNum.txt +++ b/MP.Prog/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2109.1609 +1.1.2109.1610 diff --git a/MP.Prog/Resources/manifest.xml b/MP.Prog/Resources/manifest.xml index b3cf81b3..54f12db7 100644 --- a/MP.Prog/Resources/manifest.xml +++ b/MP.Prog/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.1.2109.1609 + 1.1.2109.1610 http://nexus.steamware.net/repository/SWS/MP-PROG/stable/0/MP.Prog.zip http://nexus.steamware.net/repository/SWS/MP-PROG/stable/0/ChangeLog.html false