Implemented the text element filter
This commit is contained in:
parent
e08c94177a
commit
e762cfe21e
@ -8,10 +8,14 @@ namespace Processor;
|
|||||||
public static class TextElementProcessor
|
public static class TextElementProcessor
|
||||||
{
|
{
|
||||||
// Load all text elements for one particular section:
|
// 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>();
|
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:
|
// Load one text element by id:
|
||||||
|
@ -129,6 +129,7 @@
|
|||||||
this.textBoxFilter.Size = new System.Drawing.Size(554, 34);
|
this.textBoxFilter.Size = new System.Drawing.Size(554, 34);
|
||||||
this.textBoxFilter.TabIndex = 2;
|
this.textBoxFilter.TabIndex = 2;
|
||||||
this.textBoxFilter.WordWrap = false;
|
this.textBoxFilter.WordWrap = false;
|
||||||
|
this.textBoxFilter.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBoxFilter_KeyUp);
|
||||||
//
|
//
|
||||||
// labelFilter
|
// labelFilter
|
||||||
//
|
//
|
||||||
|
@ -9,7 +9,7 @@ public partial class TextElements : UserControl
|
|||||||
{
|
{
|
||||||
private Section? currentSection;
|
private Section? currentSection;
|
||||||
private TextElement? currentTextElement;
|
private TextElement? currentTextElement;
|
||||||
|
|
||||||
public TextElements()
|
public TextElements()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
@ -17,7 +17,7 @@ public partial class TextElements : UserControl
|
|||||||
// Check if we are in the designer:
|
// Check if we are in the designer:
|
||||||
if(Program.SERVICE_PROVIDER is null)
|
if(Program.SERVICE_PROVIDER is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Create an image list from a resource:
|
// Create an image list from a resource:
|
||||||
var imgList = new ImageList();
|
var imgList = new ImageList();
|
||||||
imgList.ImageSize = new Size(45, 45);
|
imgList.ImageSize = new Size(45, 45);
|
||||||
@ -40,7 +40,7 @@ public partial class TextElements : UserControl
|
|||||||
|
|
||||||
// Update the path:
|
// Update the path:
|
||||||
this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.currentSection.DataKey);
|
this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.currentSection.DataKey);
|
||||||
this.LoadTextElements();
|
await this.LoadTextElements();
|
||||||
};
|
};
|
||||||
|
|
||||||
// When the text element is changed, update the button states:
|
// 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.
|
// Loads all the text elements for the current section.
|
||||||
private async void LoadTextElements()
|
private async Task LoadTextElements()
|
||||||
{
|
{
|
||||||
if (this.currentSection is null)
|
if (this.currentSection is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Load the text elements:
|
// Load the text elements:
|
||||||
var textElements = await TextElementProcessor.GetTextElements(this.currentSection);
|
var textElements = await TextElementProcessor.GetTextElements(this.currentSection, this.textBoxFilter.Text);
|
||||||
|
|
||||||
// Update the list:
|
// Update the list:
|
||||||
this.listTextElements.Items.Clear();
|
this.listTextElements.Items.Clear();
|
||||||
@ -136,7 +136,7 @@ public partial class TextElements : UserControl
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Reload the text elements:
|
// Reload the text elements:
|
||||||
this.LoadTextElements();
|
await this.LoadTextElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void listTextElements_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
private async void listTextElements_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
||||||
@ -148,4 +148,6 @@ public partial class TextElements : UserControl
|
|||||||
// Fire the event:
|
// Fire the event:
|
||||||
AppEvents.TextElementChanged(this.currentTextElement);
|
AppEvents.TextElementChanged(this.currentTextElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void textBoxFilter_KeyUp(object sender, KeyEventArgs e) => await this.LoadTextElements();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user