Implemented the text element filter

This commit is contained in:
Thorsten Sommer 2022-07-21 21:14:32 +02:00
parent e08c94177a
commit e762cfe21e
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
3 changed files with 15 additions and 8 deletions

View File

@ -8,10 +8,14 @@ namespace Processor;
public static class TextElementProcessor
{
// Load all text elements for one particular section:
public static async Task<List<TextElement>> GetTextElements(Section section)
public static async Task<List<TextElement>> GetTextElements(Section section, string filterTerm)
{
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
return await db.TextElements.Where(n => n.Section == section).OrderBy(n => n.Name).ThenBy(n => n.Id).ToListAsync();
if(string.IsNullOrWhiteSpace(filterTerm))
return await db.TextElements.Where(n => n.Section == section).OrderBy(n => n.Name).ThenBy(n => n.Id).ToListAsync();
else
return await db.TextElements.Where(n => n.Section == section && n.Name.Contains(filterTerm)).OrderBy(n => n.Name).ThenBy(n => n.Id).ToListAsync();
}
// Load one text element by id:

View File

@ -129,6 +129,7 @@
this.textBoxFilter.Size = new System.Drawing.Size(554, 34);
this.textBoxFilter.TabIndex = 2;
this.textBoxFilter.WordWrap = false;
this.textBoxFilter.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBoxFilter_KeyUp);
//
// labelFilter
//

View File

@ -40,7 +40,7 @@ public partial class TextElements : UserControl
// Update the path:
this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.currentSection.DataKey);
this.LoadTextElements();
await this.LoadTextElements();
};
// When the text element is changed, update the button states:
@ -52,13 +52,13 @@ public partial class TextElements : UserControl
}
// Loads all the text elements for the current section.
private async void LoadTextElements()
private async Task LoadTextElements()
{
if (this.currentSection is null)
return;
// Load the text elements:
var textElements = await TextElementProcessor.GetTextElements(this.currentSection);
var textElements = await TextElementProcessor.GetTextElements(this.currentSection, this.textBoxFilter.Text);
// Update the list:
this.listTextElements.Items.Clear();
@ -136,7 +136,7 @@ public partial class TextElements : UserControl
return;
// Reload the text elements:
this.LoadTextElements();
await this.LoadTextElements();
}
private async void listTextElements_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
@ -148,4 +148,6 @@ public partial class TextElements : UserControl
// Fire the event:
AppEvents.TextElementChanged(this.currentTextElement);
}
private async void textBoxFilter_KeyUp(object sender, KeyEventArgs e) => await this.LoadTextElements();
}