65 lines
1.8 KiB
Plaintext
65 lines
1.8 KiB
Plaintext
@page "/counter"
|
|
@using UserService.DatabaseLayer.DataModels
|
|
@using UserService.DatabaseLayer.Repository
|
|
@using System.Collections
|
|
@inject IOrganizationUnitsRepository OuRepository
|
|
|
|
<h1>Tree</h1>
|
|
|
|
@if (_organizationUnits == null)
|
|
{
|
|
<p>
|
|
<em>Loading...</em>
|
|
</p>
|
|
}
|
|
else
|
|
{
|
|
<DxFormLayout>
|
|
<DxFormLayoutItem Caption="Navigation" ColSpanMd="3">
|
|
<Template>
|
|
<DxTreeView Data="@_organizationUnits"
|
|
TextExpression="@(dataItem => ((Node)dataItem).CommonName)" AllowSelectNodes="true" SelectionChanged="@OnSelectionChanged"
|
|
ChildrenExpression="@(dataItem => GetNodeChildren(dataItem))" >
|
|
</DxTreeView>
|
|
|
|
</Template>
|
|
</DxFormLayoutItem>
|
|
|
|
<DxFormLayoutItem Caption="Selected:" ColSpanMd="9">
|
|
<Template>
|
|
@if (_selectedOu != null)
|
|
{
|
|
<h1>@_selectedOu.CommonName</h1>
|
|
}
|
|
</Template>
|
|
</DxFormLayoutItem>
|
|
|
|
</DxFormLayout>
|
|
|
|
}
|
|
@code {
|
|
private IReadOnlyList<OrganizationUnit> _organizationUnits;
|
|
private OrganizationUnit _selectedOu;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_organizationUnits = (await OuRepository.GetAllAsync().ConfigureAwait(false)).Where(x=> x.Parent is null).ToList();
|
|
}
|
|
|
|
private void OnSelectionChanged(TreeViewNodeEventArgs args)
|
|
{
|
|
_selectedOu = args.NodeInfo.DataItem as OrganizationUnit;
|
|
}
|
|
|
|
private IEnumerable GetNodeChildren(object dataItem)
|
|
{
|
|
if (dataItem is OrganizationUnit organizationUnit)
|
|
{
|
|
foreach (var organizationUnitChild in organizationUnit.Children)
|
|
{
|
|
yield return organizationUnitChild;
|
|
}
|
|
}
|
|
}
|
|
|
|
} |