Implemented the text element filter
This commit is contained in:
parent
e08c94177a
commit
e762cfe21e
@ -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:
|
||||
|
@ -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
|
||||
//
|
||||
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user