Testing devexpress

This commit is contained in:
Holger Börchers 2020-07-26 22:05:32 +02:00
parent 110663456d
commit 7a8cd13c2d
9 changed files with 126 additions and 48 deletions

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
@ -33,15 +32,8 @@ namespace UserService.DatabaseLayer.Repository
public class NodesRepository : INodesRepository public class NodesRepository : INodesRepository
{ {
private readonly IUsersRepository _users; public NodesRepository()
private readonly ISecurityGroupsRepository _securityGroups;
private readonly IOrganizationUnitsRepository _organizationUnits;
public NodesRepository(IUsersRepository users, ISecurityGroupsRepository securityGroups, IOrganizationUnitsRepository organizationUnits)
{ {
_users = users;
_securityGroups = securityGroups;
_organizationUnits = organizationUnits;
} }
public static async IAsyncEnumerable<Node> GetNodesAsync([EnumeratorCancellation] CancellationToken token = default) public static async IAsyncEnumerable<Node> GetNodesAsync([EnumeratorCancellation] CancellationToken token = default)

View File

@ -0,0 +1,27 @@
//------------------------------------------------------------------------------
// Generated by the DevExpress.Blazor package.
// To prevent this operation, add the DxExtendStartupHost property to the project and set this property to False.
//
// UserService.Test.csproj:
//
// <Project Sdk="Microsoft.NET.Sdk.Web">
// <PropertyGroup>
// <TargetFramework>netcoreapp3.1</TargetFramework>
// <DxExtendStartupHost>False</DxExtendStartupHost>
// </PropertyGroup>
//------------------------------------------------------------------------------
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
[assembly: HostingStartup(typeof(UserService.Test.DevExpressHostingStartup))]
namespace UserService.Test {
public partial class DevExpressHostingStartup : IHostingStartup {
void IHostingStartup.Configure(IWebHostBuilder builder) {
builder.ConfigureServices((serviceCollection) => {
serviceCollection.AddDevExpressBlazor();
});
}
}
}

Binary file not shown.

View File

@ -1,6 +1,7 @@
@page "/counter" @page "/counter"
@using UserService.DatabaseLayer.DataModels @using UserService.DatabaseLayer.DataModels
@using UserService.DatabaseLayer.Repository @using UserService.DatabaseLayer.Repository
@using System.Collections
@inject IOrganizationUnitsRepository OuRepository @inject IOrganizationUnitsRepository OuRepository
<h1>Tree</h1> <h1>Tree</h1>
@ -13,18 +14,52 @@
} }
else else
{ {
<MatNavMenu> <DxFormLayout>
@foreach (var unit in _organizationUnits) <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)
{ {
<OrgUnitItem OrganizationUnit="@unit"/> <h1>@_selectedOu.CommonName</h1>
} }
</MatNavMenu> </Template>
</DxFormLayoutItem>
</DxFormLayout>
} }
@code { @code {
private IReadOnlyList<OrganizationUnit> _organizationUnits; private IReadOnlyList<OrganizationUnit> _organizationUnits;
private OrganizationUnit _selectedOu;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
_organizationUnits = await OuRepository.GetAllAsync().ConfigureAwait(false); _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;
}
}
}
} }

View File

@ -8,21 +8,22 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>UserService</title> <title>UserService</title>
<base href="~/" /> <base href="~/"/>
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" /> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link href="css/site.css" rel="stylesheet" /> <link href="css/site.css" rel="stylesheet"/>
<script src="_content/MatBlazor/dist/matBlazor.js"></script> <script src="_content/MatBlazor/dist/matBlazor.js"></script>
<link href="_content/MatBlazor/dist/matBlazor.css" rel="stylesheet" /> <link href="_content/MatBlazor/dist/matBlazor.css" rel="stylesheet"/>
<link href="_content/DevExpress.Blazor/dx-blazor.css" rel="stylesheet"/>
</head> </head>
<body> <body>
<app> <app>
<component type="typeof(App)" render-mode="ServerPrerendered" /> <component type="typeof(App)" render-mode="ServerPrerendered"/>
</app> </app>
<div id="blazor-error-ui"> <div id="blazor-error-ui">
<environment include="Staging,Production"> <environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded. An error has occurred. This application may no longer respond until reloaded.
</environment> </environment>
@ -31,8 +32,10 @@
</environment> </environment>
<a href="" class="reload">Reload</a> <a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a> <a class="dismiss">🗙</a>
</div> </div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="_framework/blazor.server.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<script src="_framework/blazor.server.js"></script>
</body> </body>
</html> </html>

View File

@ -1,13 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace UserService namespace UserService
{ {

View File

@ -0,0 +1,27 @@
//------------------------------------------------------------------------------
// Generated by the DevExpress.Blazor package.
// To prevent this operation, add the DxExtendStartupHost property to the project and set this property to False.
//
// UserService.csproj:
//
// <Project Sdk="Microsoft.NET.Sdk.Web">
// <PropertyGroup>
// <TargetFramework>netcoreapp3.1</TargetFramework>
// <DxExtendStartupHost>False</DxExtendStartupHost>
// </PropertyGroup>
//------------------------------------------------------------------------------
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
[assembly: HostingStartup(typeof(UserService.DevExpressHostingStartup))]
namespace UserService {
public partial class DevExpressHostingStartup : IHostingStartup {
void IHostingStartup.Configure(IWebHostBuilder builder) {
builder.ConfigureServices((serviceCollection) => {
serviceCollection.AddDevExpressBlazor();
});
}
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
@ -6,6 +6,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DevExpress.Blazor" Version="20.1.5" />
<PackageReference Include="MatBlazor" Version="2.6.2" /> <PackageReference Include="MatBlazor" Version="2.6.2" />
</ItemGroup> </ItemGroup>

View File

@ -8,3 +8,4 @@
@using UserService @using UserService
@using UserService.Shared @using UserService.Shared
@using MatBlazor @using MatBlazor
@using DevExpress.Blazor