Resolve "Component: Text Element Navigator" #67

Merged
thorsten merged 43 commits from 11-component-text-element-navigator into main 2022-07-23 19:29:16 +00:00
2 changed files with 13 additions and 5 deletions
Showing only changes of commit 0adc95b016 - Show all commits

No files matched your search

+11 -3
View File
@@ -138,13 +138,21 @@ public static class SectionProcessor
public static Section GetSection(DataContext db, string sectionKey) => db.Sections.First(n => n.DataKey == sectionKey); public static Section GetSection(DataContext db, string sectionKey) => db.Sections.First(n => n.DataKey == sectionKey);
public static string GetSectionPath(DataContext db, string sectionKey) public static async Task<string> GetSectionPath(DataContext db, string sectionKey)
{ {
var section = db.Sections.First(n => n.DataKey == sectionKey); var section = await db.Sections.FirstAsync(n => n.DataKey == sectionKey);
// Ensure, that the database loaded the section's parent:
await db.Entry(section).Reference(n => n.Parent).LoadAsync();
var path = section.Name; var path = section.Name;
while (section.Parent != null) while (section.Parent != null)
{ {
section = section.Parent; section = await db.Sections.FirstAsync(n => n.DataKey == section.Parent.DataKey);
// Ensure, that the database loaded the section's parent:
await db.Entry(section).Reference(n => n.Parent).LoadAsync();
path = $"{section.Name}/{path}"; path = $"{section.Name}/{path}";
} }
@@ -26,14 +26,14 @@ public partial class TextElements : UserControl
this.Disposed += (_, _) => this.db.Dispose(); this.Disposed += (_, _) => this.db.Dispose();
// When the section is changed, update this component: // When the section is changed, update this component:
AppEvents.WhenSectionChanged += (sender, section) => AppEvents.WhenSectionChanged += async (sender, section) =>
{ {
this.currentSection = section; this.currentSection = section;
this.buttonAdd.Enabled = this.currentSection is not null; this.buttonAdd.Enabled = this.currentSection is not null;
// Update the path: // Update the path:
if (this.currentSection is not null) if (this.currentSection is not null)
this.labelSectionPath.Text = SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey); this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey);
}; };
} }
} }