Skip to content

Commit

Permalink
Merge pull request #95 from saritasa-nest/feature/SN-755-customize-ma…
Browse files Browse the repository at this point in the history
…in-layout

Override layout component SN-755
  • Loading branch information
vasiliy-chefonov authored Oct 14, 2024
2 parents 3efe86d + 50e935a commit d275f95
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 6 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

0.3.0-alpha [2024-10-07]
[+] Exclude all entities from admin panel.
[+} Include entity properties if NetForgeProperty attribute is set.
[+] Include entity properties if NetForgeProperty attribute is set.

0.3.1-alpha [2024-10-08]
[*] Replaced MudAlert with Snackbar control on edit entity page
[*] Replaced MudAlert with Snackbar control on edit entity page.

0.4.0-alpha [2024-10-10]
[+] Added support for the admin panel layout overriding.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The **NetForge** is a library that provides a user-friendly and intuitive user i
- [Configuration](#configuration)
- [Headers Expansion](#headers-expansion)
- [Exclude All Entities and Include Specific Only](#exclude-all-entities-and-include-specific-only)
- [Customizing the UI](#customizing-the-ui)
- [Main Layout Overriding](#main-layout-overriding)
- [Customizing Entities](#customizing-entities)
- [Fluent API](#fluent-api)
- [Creating an Entity Configuration Class](#creating-an-entity-configuration-class)
Expand Down Expand Up @@ -147,6 +149,54 @@ services.AddNetForge(optionsBuilder =>

Group rows of entities into categories and make it easier for users to navigate and understand the data presented.

## Customizing the UI

### Main Layout Overriding

You can override the default layout of the admin panel.
To do this, create a new layout in your host project and specify its type in the configuration.

```csharp
services.AddNetForge(optionsBuilder =>
{
optionsBuilder.SetCustomLayout(typeof(CustomLayout));
});
```

Your custom layout should inherit from the `AdminBaseLayout` class.

The example of the custom component with navigation bar and footer:
```csharp
@using MudBlazor
@inherits Saritasa.NetForge.Blazor.Shared.AdminBaseLayout

<MudThemeProvider />
<MudDialogProvider />
<MudSnackbarProvider />

<MudAppBar Color="Color.Primary" Elevation="4">
<MudText Typo="Typo.h6">My Application</MudText>
<MudSpacer />
<MudNavMenu>
<MudNavLink Href="/about">About</MudNavLink>
<MudNavLink Href="/contact">Contact</MudNavLink>
</MudNavMenu>
</MudAppBar>

@Body

<footer>
<MudPaper Class="pa-4" Elevation="4">
<MudText Typo="Typo.body2">My Application</MudText>
<MudSpacer />
<MudNavMenu>
<MudNavLink Href="/privacy">Privacy Policy</MudNavLink>
<MudNavLink Href="/terms">Terms of Service</MudNavLink>
</MudNavMenu>
</MudPaper>
</footer>
```

### Create Groups for Entities

Before assigning entities to specific groups, users need to define the groups to which the entities will belong.
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1-alpha
0.4.0-alpha
11 changes: 9 additions & 2 deletions src/Saritasa.NetForge.Blazor/App.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@using Saritasa.NetForge.Blazor.Controls
@using Saritasa.NetForge.Domain.Entities.Options

<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@(AdminOptions?.CustomLayoutType ?? typeof(MainLayout))">
<NotAuthorized>
<h1>Sorry</h1>
<p>You're not authorized to reach this page.</p>
Expand All @@ -14,9 +15,15 @@
</Found>
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@typeof(MainLayout)">
<LayoutView Layout="@(AdminOptions?.CustomLayoutType ?? typeof(MainLayout))">
<NotFound/>
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
</Router>

@code
{
[Inject]
AdminOptions? AdminOptions { get; set; }
}
1 change: 1 addition & 0 deletions src/Saritasa.NetForge.Blazor/Shared/AdminBaseLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@inherits Microsoft.AspNetCore.Components.LayoutComponentBase
8 changes: 8 additions & 0 deletions src/Saritasa.NetForge.Blazor/Shared/AdminBaseLayout.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.AspNetCore.Components;

namespace Saritasa.NetForge.Blazor.Shared;

/// <summary>
/// Base layout for admin pages.
/// </summary>
public partial class AdminBaseLayout : LayoutComponentBase;
2 changes: 1 addition & 1 deletion src/Saritasa.NetForge.Blazor/Shared/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Saritasa.NetForge.Blazor.Shared;
/// <summary>
/// Main layout page.
/// </summary>
public class MainLayoutComponent : Microsoft.AspNetCore.Components.LayoutComponentBase
public class MainLayoutComponent : AdminBaseLayout
{
/// <summary>
/// Get home page route.
Expand Down
5 changes: 5 additions & 0 deletions src/Saritasa.NetForge.Domain/Entities/Options/AdminOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public class AdminOptions
/// Entities to include in the admin panel.
/// </summary>
public List<Type> IncludedEntities { get; set; } = [];

/// <summary>
/// The optional type of custom layout for the admin panel.
/// </summary>
public Type? CustomLayoutType { get; set; }
}
10 changes: 10 additions & 0 deletions src/Saritasa.NetForge.DomainServices/AdminOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,14 @@ public AdminOptionsBuilder IncludeEntities(params Type[] tableTypes)
options.IncludedEntities.AddRange(tableTypes);
return this;
}

/// <summary>
/// Sets the custom layout for the admin panel.
/// </summary>
/// <param name="layoutType">Type of the custom layout.</param>
public AdminOptionsBuilder SetCustomLayout(Type layoutType)
{
options.CustomLayoutType = layoutType;
return this;
}
}

0 comments on commit d275f95

Please sign in to comment.