Skip to content

Commit 637ed56

Browse files
committed
first
1 parent a6511fd commit 637ed56

36 files changed

+12702
-0
lines changed

CS/TreeViewCustomFilter.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.32002.185
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TreeViewCustomFilter", "TreeViewCustomFilter\TreeViewCustomFilter.csproj", "{44E1B010-11E1-4537-BBA1-170CAE9F86B3}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{44E1B010-11E1-4537-BBA1-170CAE9F86B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{44E1B010-11E1-4537-BBA1-170CAE9F86B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{44E1B010-11E1-4537-BBA1-170CAE9F86B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{44E1B010-11E1-4537-BBA1-170CAE9F86B3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3ED7015D-5113-4AB2-B141-D496461D4B2E}
24+
EndGlobalSection
25+
EndGlobal

CS/TreeViewCustomFilter/App.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
<Router AppAssembly="@typeof(Program).Assembly">
3+
<Found Context="routeData">
4+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
5+
</Found>
6+
<NotFound>
7+
<LayoutView Layout="@typeof(MainLayout)">
8+
<p>Sorry, there's nothing at this address.</p>
9+
</LayoutView>
10+
</NotFound>
11+
</Router>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace TreeViewCustomFilter.Data {
2+
public class OfficeLocation {
3+
public static readonly OfficeLocation[] Offices = new[] {
4+
new OfficeLocation(){Name="Africa", Id = "1" },
5+
new OfficeLocation(){Name="Ethiopia", Id="2", ParentId="1" },
6+
new OfficeLocation(){Name="Dire Dawa", Id = "3", ParentId="2"},
7+
new OfficeLocation(){Name="Addis Ababa", Id="4", ParentId="2" },
8+
new OfficeLocation(){Name="Nigeria",Id = "5", ParentId="1"},
9+
new OfficeLocation(){Name="Lagos",Id = "6", ParentId="5"},
10+
new OfficeLocation(){Name="Kano",Id = "7", ParentId="5"},
11+
new OfficeLocation(){Name="Asia",Id = "8"},
12+
new OfficeLocation(){Name="China",Id = "9", ParentId="8"},
13+
new OfficeLocation(){Name="Beijing",Id = "10", ParentId="9"},
14+
new OfficeLocation(){Name="Shanghai",Id = "11", ParentId="9"},
15+
new OfficeLocation(){Name="India",Id = "12", ParentId="8"},
16+
new OfficeLocation(){Name="Indianapolis",Id = "13", ParentId="12"},
17+
new OfficeLocation(){Name="New Delhi",Id = "14", ParentId="12"},
18+
new OfficeLocation(){Name="Australia",Id = "15" },
19+
new OfficeLocation(){Name="Australia",Id = "16", ParentId="15"},
20+
new OfficeLocation(){Name="Canberra",Id = "17", ParentId="16"},
21+
new OfficeLocation(){Name="Melbourne",Id = "18", ParentId="16"},
22+
new OfficeLocation(){Name="Sydney",Id = "19", ParentId="16"},
23+
new OfficeLocation(){Name="Europe",Id = "20" },
24+
new OfficeLocation(){Name="Germany",Id = "21", ParentId="20"},
25+
new OfficeLocation(){Name="Berlin",Id = "22", ParentId="20"},
26+
new OfficeLocation(){Name="Hamburg",Id = "23", ParentId="20"},
27+
new OfficeLocation(){Name="France", Id="24", ParentId="20" },
28+
new OfficeLocation(){Name="Paris",Id = "25", ParentId="24"},
29+
new OfficeLocation(){Name="North America",Id = "26"},
30+
new OfficeLocation(){Name="Mexico",Id = "27", ParentId="26"},
31+
new OfficeLocation(){Name="Mexico City",Id = "28", ParentId="27"},
32+
new OfficeLocation(){Name="United States",Id = "29", ParentId="26"},
33+
new OfficeLocation(){Name="New York", Id="30", ParentId="29" },
34+
new OfficeLocation(){Name="Washington",Id = "31", ParentId="29"},
35+
new OfficeLocation(){Name="South America",Id = "32" },
36+
new OfficeLocation(){Name="Brazil",Id = "33", ParentId="32"},
37+
new OfficeLocation(){Name="Brasilia",Id = "34", ParentId="33"},
38+
new OfficeLocation(){Name="Colombia",Id = "35", ParentId="32"},
39+
new OfficeLocation(){Name="Bogota",Id = "36", ParentId="35"}
40+
};
41+
42+
public string Id { get; set; }
43+
public string CssClass => "itemclass";
44+
public string ParentId { get; set; }
45+
public string Name { get; set; }
46+
}
47+
}

CS/TreeViewCustomFilter/NOTICE.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
The following open source libraries are used and included within thеse sample/demonstration projects:
2+
3+
Bootstrap (Open Source – MIT License)
4+
Copyright (c) 2011-2021 Twitter, Inc. / Copyright (c) 2011-2021 The Bootstrap Authors
5+
https://github.com/twbs/bootstrap/blob/main/LICENSE
6+
7+
open-iconic (Open Source – MIT License and SIL Open Font License)
8+
Copyright (c) 2014 Waybury
9+
https://github.com/iconic/open-iconic/blob/master/ICON-LICENSE
10+
https://github.com/iconic/open-iconic/blob/master/FONT-LICENSE
11+
12+
The open source libraries included in these sample/demonstration projects are done so pursuant to each individual open source library license and subject to the disclaimers and limitations on liability set forth in each open source library license.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@page
2+
@model TreeViewCustomFilter.Pages.ErrorModel
3+
4+
<!DOCTYPE html>
5+
<html>
6+
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
10+
<title>Error</title>
11+
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.css" rel="stylesheet" />
12+
13+
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true"/>
14+
</head>
15+
16+
<body>
17+
<div class="px-4">
18+
<h1 class="text-danger">Error.</h1>
19+
<h2 class="text-danger">An error occurred while processing your request.</h2>
20+
21+
@if (Model.ShowRequestId)
22+
{
23+
<p>
24+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
25+
</p>
26+
}
27+
28+
<h3>Development Mode</h3>
29+
<p>
30+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
31+
</p>
32+
<p>
33+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
34+
It can result in displaying sensitive information from exceptions to end users.
35+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
36+
and restarting the app.
37+
</p>
38+
</div>
39+
</body>
40+
41+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.RazorPages;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace TreeViewCustomFilter.Pages {
11+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
12+
[IgnoreAntiforgeryToken]
13+
public class ErrorModel : PageModel {
14+
public string? RequestId { get; set; }
15+
16+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
17+
18+
private readonly ILogger<ErrorModel> _logger;
19+
20+
public ErrorModel(ILogger<ErrorModel> logger) {
21+
_logger = logger;
22+
}
23+
24+
public void OnGet() {
25+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
26+
}
27+
}
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@page "/"
2+
@using TreeViewCustomFilter.Data
3+
@using System.Text.RegularExpressions;
4+
5+
<DxTreeView Data="@OfficeLocation.Offices"
6+
@bind-FilterString=FilterString
7+
ShowFilterPanel="true"
8+
CustomFilter=@CustomFilter>
9+
<NodeTextTemplate>
10+
<span>
11+
@Template(context)
12+
</span>
13+
</NodeTextTemplate>
14+
<DataMappings>
15+
<DxTreeViewDataMapping Key="Id" ParentKey="ParentId" Text="Name" />
16+
</DataMappings>
17+
</DxTreeView>
18+
19+
@code {
20+
static IEnumerable<string> SplitByComma(string value) => value
21+
.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
22+
string? FilterString { get; set; }
23+
bool CustomFilter(ITreeViewNodeInfo info) {
24+
return SplitByComma(info.FilterInfo.Value)
25+
.Any(word => info.Text.Contains(word, StringComparison.InvariantCultureIgnoreCase));
26+
}
27+
RenderFragment Template(ITreeViewNodeInfo info) {
28+
if(!info.FilterInfo.IsApplied)
29+
return @<text>@info.Text</text>;
30+
var words = SplitByComma(info.FilterInfo.Value);
31+
var pattern = $"(" + string.Join(")|(", words) + ")";
32+
var matched = Regex.Split(info.Text, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
33+
return
34+
@<text>
35+
@foreach(var m in matched) {
36+
@if(Regex.IsMatch(m, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)) {
37+
<span class="dxbl-filter-content">@m</span>
38+
}
39+
else { @m }
40+
}
41+
</text>;
42+
}
43+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page "/"
2+
@namespace TreeViewCustomFilter.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@{
5+
Layout = "_Layout";
6+
}
7+
8+
<component type="typeof(App)" render-mode="ServerPrerendered" />
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@using Microsoft.AspNetCore.Components.Web
2+
@namespace TreeViewCustomFilter.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10+
<base href="~/" />
11+
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.css" rel="stylesheet" />
12+
13+
<link href="~/css/site.css" rel="stylesheet" />
14+
<link href="TreeViewCustomFilter.styles.css" rel="stylesheet" />
15+
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
16+
</head>
17+
<body>
18+
@{
19+
var isIEOrEdgeLegacy = Context.Request.Headers["User-Agent"]
20+
.Any(userAgent => userAgent.Contains("MSIE") || userAgent.Contains("Trident") || userAgent.Contains("Edge/"));
21+
}
22+
@if(isIEOrEdgeLegacy)
23+
{
24+
<component type="typeof(TreeViewCustomFilter.Shared.BrowserNotSupported)" render-mode="Static" />
25+
}
26+
else
27+
{
28+
@RenderBody()
29+
30+
<div id="blazor-error-ui">
31+
<environment include="Staging,Production">
32+
An error has occurred. This application may no longer respond until reloaded.
33+
</environment>
34+
<environment include="Development">
35+
An unhandled exception has occurred. See browser dev tools for details.
36+
</environment>
37+
<a href="" class="reload">Reload</a>
38+
<a class="dismiss">🗙</a>
39+
</div>
40+
41+
<script src="_framework/blazor.server.js"></script>
42+
}
43+
</body>
44+
</html>

CS/TreeViewCustomFilter/Program.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using TreeViewCustomFilter.Data;
2+
using Microsoft.AspNetCore.Components;
3+
using Microsoft.AspNetCore.Components.Web;
4+
5+
6+
var builder = WebApplication.CreateBuilder(args);
7+
8+
// Add services to the container.
9+
builder.Services.AddRazorPages();
10+
builder.Services.AddServerSideBlazor();
11+
builder.Services.AddDevExpressBlazor();
12+
13+
builder.Services.Configure<DevExpress.Blazor.Configuration.GlobalOptions>(options => {
14+
options.BootstrapVersion = DevExpress.Blazor.BootstrapVersion.v5;
15+
});
16+
17+
var app = builder.Build();
18+
19+
// Configure the HTTP request pipeline.
20+
if (!app.Environment.IsDevelopment())
21+
{
22+
app.UseExceptionHandler("/Error");
23+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
24+
app.UseHsts();
25+
}
26+
app.UseHttpsRedirection();
27+
28+
app.UseStaticFiles();
29+
30+
app.UseRouting();
31+
32+
33+
app.MapBlazorHub();
34+
app.MapFallbackToPage("/_Host");
35+
36+
app.Run();

0 commit comments

Comments
 (0)