Skip to content

Commit

Permalink
- Add Blazor to orchard core
Browse files Browse the repository at this point in the history
- Options Editor  and ModalDialog in Blazor
- Using blazor in PredefinedList
  • Loading branch information
ns8482e committed Feb 15, 2024
1 parent bfa7487 commit c2bb83c
Show file tree
Hide file tree
Showing 26 changed files with 669 additions and 30 deletions.
28 changes: 26 additions & 2 deletions OrchardCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Search.AzureAI"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Search.AzureAI.Core", "src\OrchardCore\OrchardCore.Search.AzureAI.Core\OrchardCore.Search.AzureAI.Core.csproj", "{E9428DE8-5D81-4359-BF84-31435041FF1A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.Media.Indexing.Pdf", "src\OrchardCore.Modules\OrchardCore.Media.Indexing.Pdf\OrchardCore.Media.Indexing.Pdf.csproj", "{95187E6A-5B74-4475-8FEB-758ACD012DCC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Media.Indexing.Pdf", "src\OrchardCore.Modules\OrchardCore.Media.Indexing.Pdf\OrchardCore.Media.Indexing.Pdf.csproj", "{95187E6A-5B74-4475-8FEB-758ACD012DCC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.Media.Indexing.OpenXML", "src\OrchardCore.Modules\OrchardCore.Media.Indexing.OpenXML\OrchardCore.Media.Indexing.OpenXML.csproj", "{47777735-7432-4CCA-A8C5-672E9EE65121}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Media.Indexing.OpenXML", "src\OrchardCore.Modules\OrchardCore.Media.Indexing.OpenXML\OrchardCore.Media.Indexing.OpenXML.csproj", "{47777735-7432-4CCA-A8C5-672E9EE65121}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OrchardCore.Components", "OrchardCore.Components", "{7525406F-AEA0-4397-8E6B-3837ABEC2A36}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Admin.Components", "src\OrchardCore.Components\OrchardCore.Admin.Components\OrchardCore.Admin.Components.csproj", "{0734E6A3-5D42-4698-91F1-4068364E8FCC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Admin.WebAssembly.App", "src\OrchardCore.Components\OrchardCore.Admin.WebAssembly.App\OrchardCore.Admin.WebAssembly.App.csproj", "{361B5892-DE24-4249-827E-3D144CC68643}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Common.Components", "src\OrchardCore.Components\OrchardCore.Common.Components\OrchardCore.Common.Components.csproj", "{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -1359,6 +1367,18 @@ Global
{47777735-7432-4CCA-A8C5-672E9EE65121}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47777735-7432-4CCA-A8C5-672E9EE65121}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47777735-7432-4CCA-A8C5-672E9EE65121}.Release|Any CPU.Build.0 = Release|Any CPU
{0734E6A3-5D42-4698-91F1-4068364E8FCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0734E6A3-5D42-4698-91F1-4068364E8FCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0734E6A3-5D42-4698-91F1-4068364E8FCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0734E6A3-5D42-4698-91F1-4068364E8FCC}.Release|Any CPU.Build.0 = Release|Any CPU
{361B5892-DE24-4249-827E-3D144CC68643}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{361B5892-DE24-4249-827E-3D144CC68643}.Debug|Any CPU.Build.0 = Debug|Any CPU
{361B5892-DE24-4249-827E-3D144CC68643}.Release|Any CPU.ActiveCfg = Release|Any CPU
{361B5892-DE24-4249-827E-3D144CC68643}.Release|Any CPU.Build.0 = Release|Any CPU
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1594,6 +1614,10 @@ Global
{E9428DE8-5D81-4359-BF84-31435041FF1A} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{95187E6A-5B74-4475-8FEB-758ACD012DCC} = {90030E85-0C4F-456F-B879-443E8A3F220D}
{47777735-7432-4CCA-A8C5-672E9EE65121} = {90030E85-0C4F-456F-B879-443E8A3F220D}
{7525406F-AEA0-4397-8E6B-3837ABEC2A36} = {275E087F-A4E2-4A7B-A924-ED68E3A52086}
{0734E6A3-5D42-4698-91F1-4068364E8FCC} = {7525406F-AEA0-4397-8E6B-3837ABEC2A36}
{361B5892-DE24-4249-827E-3D144CC68643} = {7525406F-AEA0-4397-8E6B-3837ABEC2A36}
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7} = {7525406F-AEA0-4397-8E6B-3837ABEC2A36}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46A1D25A-78D1-4476-9CBF-25B75E296341}
Expand Down
5 changes: 5 additions & 0 deletions src/OrchardCore.Build/Dependencies.AspNetCore.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<PackageManagement Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Owin" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="$(AspNetCorePackagesVersion)"/>
<PackageManagement Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCorePackagesVersion)"/>
<PackageManagement Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(AspNetCorePackagesVersion)"/>
<PackageManagement Include="Microsoft.AspNetCore.Components.CustomElements" Version="$(AspNetCorePackagesVersion)"/>

</ItemGroup>

<!-- 'Microsoft.Extensions' packages that are not included in the ASP.NET Core shared framework -->
Expand Down
5 changes: 4 additions & 1 deletion src/OrchardCore.Cms.Web/OrchardCore.Cms.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<Import Project="..\OrchardCore.Build\Dependencies.props" />

Expand Down Expand Up @@ -30,10 +30,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Condition="'$(RazorRuntimeCompilation)' == 'true'" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Components\OrchardCore.Admin.WebAssembly.App\OrchardCore.Admin.WebAssembly.App.csproj" />
<ProjectReference Include="..\OrchardCore\OrchardCore.Application.Cms.Targets\OrchardCore.Application.Cms.Targets.csproj" />
<ProjectReference Include="..\OrchardCore\OrchardCore.Logging.NLog\OrchardCore.Logging.NLog.csproj" />
</ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/OrchardCore.Cms.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

var app = builder.Build();

if (!app.Environment.IsDevelopment())
if (app.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
}
else
{
app.UseExceptionHandler("/Error");
}
Expand Down
1 change: 1 addition & 0 deletions src/OrchardCore.Cms.Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Kestrel": {
"commandName": "Project",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"launchUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
10 changes: 10 additions & 0 deletions src/OrchardCore.Components/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="..\..\Directory.Build.props" />
<Import Project="..\OrchardCore.Build\OrchardCore.Commons.props" />

<PropertyGroup>
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions src/OrchardCore.Components/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="..\OrchardCore.Build\OrchardCore.Commons.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h3>Future Admin App in Blazor</h3>

@code {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>


<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Common.Components\OrchardCore.Common.Components.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@using Microsoft.AspNetCore.Components.Web
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h3>Initializer</h3>

@code {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Admin.Components\OrchardCore.Admin.Components.csproj" />
<ProjectReference Include="..\OrchardCore.Common.Components\OrchardCore.Common.Components.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using OrchardCore.Admin.WebAssembly.App;
using OrchardCore.Common.Components;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.RegisterCustomElement<OptionEditor>("option-editor");
builder.RootComponents.RegisterCustomElement<Initializer>("init");
builder.Services.AddScoped<ExampleJsInterop>();


await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using OrchardCore.Admin.WebAssembly.App
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;

namespace OrchardCore.Common.Components;

public class ColloctedJSComponent : ComponentBase, IAsyncDisposable

This comment has been minimized.

Copy link
@soma-kurisu

soma-kurisu Feb 17, 2024

Hey @ns8482e; Seems like a typo to me. May be you intended to convey either "collocated", "collected" or "connected" for "CollocatedJSComponent", CollectedJSComponent" or "ConnectedJSComponent" although I don't think they match either: it's an option-editor and neither of above generic terms seems to fit.

This comment has been minimized.

Copy link
@ns8482e

ns8482e Feb 17, 2024

Author Contributor

Thanks - Its CollocatedJSComponent - Updated.
It's base component for any component that wants to use collocated js for js interop. This allows a component to define *.razor.js

{
[Inject]
private IJSRuntime? JS { get; set; }

[Parameter]
public bool RaiseDomEvents { get; set; }

protected IJSObjectReference? JSModule { get; private set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var ns = GetType().Namespace;
var cmp = GetType().Name;
if (JS is not null)
{
JSModule = await JS.InvokeAsync<IJSObjectReference>("import",
$"./_content/{ns}/{cmp}.razor.js");
}
}
}

async ValueTask IAsyncDisposable.DisposeAsync()
{
if (JSModule is not null)
{
await JSModule.DisposeAsync();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<div class="modal fade @IsOpenClass text-start" role="dialog" style="display:@IsOpenDisplayStyle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@Title</h5>
<button type="button" class="btn-close" aria-label="Close" @onclick="Close"></button>
</div>
<div class="modal-body">
@Body
</div>
<div class="modal-footer">
@Actions
</div>
</div>
</div>
</div>

@if (ShowBackdrop && IsOpen)
{
<div class="modal-backdrop fade show"></div>
}

@code {

[Parameter]
public string? Title { get; set; }
[Parameter]
public bool ShowBackdrop { get; set; }
[Parameter]
public RenderFragment? Body { get; set; }
[Parameter]
public RenderFragment? Actions { get; set; }


public bool IsOpen { get; set; }

string IsOpenClass { get; set; } = string.Empty;

string IsOpenDisplayStyle { get; set; } = "none";

public async Task Open()
{
IsOpenDisplayStyle = "block";
IsOpen = true;
await Task.Delay(100);//Delay allows bootstrap to perform nice fade animation
IsOpenClass = "show";
StateHasChanged();

}

public async Task Close()
{
IsOpenClass = "";
IsOpen = false;
await Task.Delay(250);//Delay allows bootstrap to perform nice fade animation
IsOpenDisplayStyle = "none";
StateHasChanged();
}
}
Loading

0 comments on commit c2bb83c

Please sign in to comment.