Skip to content

Commit 16e2f31

Browse files
authored
Committed the example project.
1 parent 0648a52 commit 16e2f31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1764
-0
lines changed

Client/App.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>

Client/MyBlazorApp.Client.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview3.20168.3" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0" PrivateAssets="all" />
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0" PrivateAssets="all" />
13+
<PackageReference Include="Syncfusion.Blazor" Version="18.2.0.54" />
14+
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\Shared\MyBlazorApp.Shared.csproj" />
19+
</ItemGroup>
20+
21+
</Project>

Client/Pages/Counter.razor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/counter"
2+
3+
<h1>Counter</h1>
4+
5+
<p>Current count: @currentCount</p>
6+
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
9+
@code {
10+
private int currentCount = 0;
11+
12+
private void IncrementCount()
13+
{
14+
currentCount++;
15+
}
16+
}

Client/Pages/Index.razor

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
@page "/"
2+
@using Syncfusion.Blazor
3+
@using Syncfusion.Blazor.Navigations
4+
@using Syncfusion.Blazor.Data
5+
@using MyBlazorApp.Data;
6+
@using Newtonsoft.Json;
7+
@inject HttpClient Http
8+
9+
10+
@*<SfTreeView TValue="OrganizationDetails">
11+
<TreeViewFieldsSettings TValue="OrganizationDetails"
12+
Id="Id" Text="Name" ParentID="ParentId" HasChildren="HasTeam" Expanded="IsExpanded">
13+
<SfDataManager Url="api/Organization" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true"></SfDataManager>
14+
</TreeViewFieldsSettings>
15+
</SfTreeView>*@
16+
17+
<div id="treeview">
18+
<SfTreeView @ref="tree" TValue="OrganizationDetails">
19+
<TreeViewFieldsSettings TValue="OrganizationDetails"
20+
Id="Id" Text="Name" ParentID="ParentId" HasChildren="HasTeam" Expanded="IsExpanded">
21+
<SfDataManager Url="api/Organization" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true"></SfDataManager>
22+
</TreeViewFieldsSettings>
23+
<TreeViewEvents TValue="OrganizationDetails" NodeClicked="TreeViewNodeClicked"></TreeViewEvents>
24+
</SfTreeView>
25+
</div>
26+
<SfContextMenu TValue="ContextMenuItem" Target="#treeview">
27+
<ContextMenuItems>
28+
<ContextMenuItem Text="Edit"></ContextMenuItem>
29+
<ContextMenuItem Text="Add"></ContextMenuItem>
30+
<ContextMenuItem Text="Remove"></ContextMenuItem>
31+
</ContextMenuItems>
32+
<ContextMenuEvents TValue="ContextMenuItem" ItemSelected="ContextMenuItemSelected"></ContextMenuEvents>
33+
</SfContextMenu>
34+
35+
@code{
36+
37+
SfTreeView<OrganizationDetails> tree;
38+
string selectedId;
39+
int index;
40+
41+
public void ContextMenuItemSelected(MenuEventArgs<ContextMenuItem> args)
42+
{
43+
switch (args.Item.Text)
44+
{
45+
case "Edit":
46+
RenameNode();
47+
break;
48+
case "Add":
49+
AddNode();
50+
break;
51+
case "Remove":
52+
RemoveNode();
53+
break;
54+
}
55+
}
56+
57+
void RemoveNode()
58+
{
59+
string[] removeNode = new string[] { this.selectedId };
60+
this.tree.RemoveNodes(removeNode);
61+
}
62+
63+
protected override async Task OnInitializedAsync()
64+
{
65+
// To get the last item index from the db
66+
int count = await Http.GetJsonAsync<int>("api/Organization/Index");
67+
this.index = count +1;
68+
}
69+
70+
void AddNode()
71+
{
72+
List<object> treeData = new List<object>();
73+
treeData.Add(new
74+
{
75+
Id = this.index,
76+
Name = "New Entry",
77+
ParentId = this.selectedId
78+
});
79+
this.tree.AddNodes(treeData, this.selectedId, null, false);
80+
this.index += 1;
81+
}
82+
83+
async void RenameNode()
84+
{
85+
await tree.BeginEdit(this.selectedId);
86+
}
87+
88+
public async void TreeViewNodeClicked(NodeClickEventArgs args)
89+
{
90+
this.selectedId = null;
91+
string eventString = JsonConvert.SerializeObject(args.Event);
92+
Dictionary<string, dynamic> eventParameters = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(eventString);
93+
if ((eventParameters["which"]).ToString() == "3")
94+
{
95+
// To get the selected node id upon context menu click
96+
this.selectedId = await args.Node.GetAttribute<string>("data-uid");
97+
}
98+
}
99+
}

Client/Program.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
using System.Text;
6+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Logging;
10+
using Syncfusion.Blazor;
11+
12+
namespace MyBlazorApp.Client
13+
{
14+
public class Program
15+
{
16+
public static async Task Main(string[] args)
17+
{
18+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
19+
builder.RootComponents.Add<App>("app");
20+
21+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
22+
builder.Services.AddSyncfusionBlazor();
23+
await builder.Build().RunAsync();
24+
}
25+
}
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:57452",
7+
"sslPort": 44302
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"MyBlazorApp": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
23+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
}
27+
}
28+
}
29+
}

Client/Shared/MainLayout.razor

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>

Client/Shared/NavMenu.razor

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">MyBlazorApp</a>
3+
<button class="navbar-toggler" @onclick="ToggleNavMenu">
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
12+
<span class="oi oi-home" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="counter">
17+
<span class="oi oi-plus" aria-hidden="true"></span> Counter
18+
</NavLink>
19+
</li>
20+
</ul>
21+
</div>
22+
23+
@code {
24+
private bool collapseNavMenu = true;
25+
26+
private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
27+
28+
private void ToggleNavMenu()
29+
{
30+
collapseNavMenu = !collapseNavMenu;
31+
}
32+
}

Client/Shared/SurveyPrompt.razor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="alert alert-secondary mt-4" role="alert">
2+
<span class="oi oi-pencil mr-2" aria-hidden="true"></span>
3+
<strong>@Title</strong>
4+
5+
<span class="text-nowrap">
6+
Please take our
7+
<a target="_blank" class="font-weight-bold" href="https://go.microsoft.com/fwlink/?linkid=2127996">brief survey</a>
8+
</span>
9+
and tell us what you think.
10+
</div>
11+
12+
@code {
13+
// Demonstrates how a parent component can supply parameters
14+
[Parameter]
15+
public string Title { get; set; }
16+
}

Client/_Imports.razor

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using Microsoft.AspNetCore.Components.WebAssembly.Http
7+
@using Microsoft.JSInterop
8+
@using MyBlazorApp.Client
9+
@using MyBlazorApp.Client.Shared

0 commit comments

Comments
 (0)