Skip to content

Commit

Permalink
Merge pull request #102 from saritasa-nest/feature/SN-774-custom-header
Browse files Browse the repository at this point in the history
Add extra header content SN-774
  • Loading branch information
tanhieu-nguyen authored Nov 22, 2024
2 parents 25125ee + f7f7353 commit 55a9acf
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 7 deletions.
64 changes: 61 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ The **NetForge** is a library that provides a user-friendly and intuitive user i
- [Search](#search)
- [View Site URL](#view-site-url)
- [Grouping](#grouping)
- [Customizing the UI](#customizing-the-ui)
- [Main Layout Overriding](#main-layout-overriding)
- [Head Tag Overriding](#head-tag-overriding)
- [Create Groups for Entities](#create-groups-for-entities)
- [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 All @@ -39,12 +40,14 @@ The **NetForge** is a library that provides a user-friendly and intuitive user i
- [Rich Text Field](#rich-text-field)
- [Image Properties](#image-properties)
- [Configuration](#configuration-1)
- [Max image size](#max-image-size)
- [Read-only Properties](#read-only-properties)
- [Configuration](#configuration-2)
- [String Truncate](#string-truncate)
- [Configuration](#configuration-3)
- [Multiline Text Field Property](#multiline-text-field-property)
- [Configuration](#configuration-4)
- [License](#license)

# How to Use

Expand Down Expand Up @@ -197,6 +200,61 @@ The example of the custom component with navigation bar and footer:
</footer>
```

### Head Tag Overriding

You can inject custom meta tags or page title into the head tag of the admin panel.

```csharp
services.AddNetForge(optionsBuilder =>
{
optionsBuilder.SetCustomHeadType(typeof(CustomHead));
});
```

Example of injecting custom meta tags or a page title into the head tag of the admin panel.
```csharp
@using Microsoft.AspNetCore.Components.Web

<PageTitle>This is the custom page title.</PageTitle>
<meta name="custom-meta" content="content-meta">
```

**Note:** If you are using a `Custom Layout`, you must add the dynamic component into the custom layout:

```csharp
@using Saritasa.NetForge.Domain.Entities.Options
@inject AdminOptions AdminOptions;

<HeadContent>
@if (AdminOptions.CustomHeadType is not null)
{
<DynamicComponent Type="AdminOptions.CustomHeadType" />
}
</HeadContent>
```

Example:

```csharp
@using MudBlazor
@using Saritasa.NetForge.Domain.Entities.Options
@using Microsoft.AspNetCore.Components.Web
@inherits Saritasa.NetForge.Blazor.Shared.AdminBaseLayout
@inject AdminOptions AdminOptions;

<HeadContent>
@if (AdminOptions.CustomHeadType is not null)
{
<DynamicComponent Type="AdminOptions.CustomHeadType" />
}
</HeadContent>

<MudThemeProvider />
<MudDialogProvider />
...
...
```

### Create Groups for Entities

Before assigning entities to specific groups, users need to define the groups to which the entities will belong.
Expand Down Expand Up @@ -822,7 +880,7 @@ public required string Street { get; set; }
```csharp
entityOptionsBuilder.ConfigureProperty(address => address.Street, builder =>
{
builder.SetIsMultiline(maxLines: 15); // sets the max lines value as 15
builder.SetIsMultiline(maxLines: 15); // sets the max lines value as 15
});
```

Expand Down
4 changes: 2 additions & 2 deletions demo/Saritasa.NetForge.Demo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public void ConfigureServices(IServiceCollection services, IWebHostEnvironment e
var connectionString = configuration.GetConnectionString("AppDatabase")
?? throw new ArgumentNullException("ConnectionStrings:AppDatabase",
"Database connection string is not initialized");

services.AddDbContext<ShopDbContext>(options =>
{
options.UseNpgsql(connectionString).UseSnakeCaseNamingConvention();
});
services.AddAsyncInitializer<DatabaseInitializer>();
services.AddHealthChecks().AddNpgSql(connectionString);

// Identity.
services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<ShopDbContext>()
Expand Down
2 changes: 1 addition & 1 deletion src/Saritasa.NetForge.Blazor/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@(AdminOptions?.CustomLayoutType ?? typeof(MainLayout))">
<NotFound/>
<NotFound />
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
Expand Down
11 changes: 11 additions & 0 deletions src/Saritasa.NetForge.Blazor/Domain/AdminOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,15 @@ public AdminOptionsBuilder SetCustomLayout(Type layoutType)
options.CustomLayoutType = layoutType;
return this;
}

/// <summary>
/// Sets the custom head type for the admin panel.
/// </summary>
/// <param name="headType">The type of the custom head.</param>
/// <returns>The current instance of <see cref="AdminOptionsBuilder"/>.</returns>
public AdminOptionsBuilder SetCustomHeadType(Type headType)
{
options.CustomHeadType = headType;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ public class AdminOptions
/// The optional type of custom layout for the admin panel.
/// </summary>
public Type? CustomLayoutType { get; set; }

/// <summary>
/// The optional type of custom head for the admin panel.
/// </summary>
public Type? CustomHeadType { get; set; }
}
2 changes: 1 addition & 1 deletion src/Saritasa.NetForge.Blazor/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
@inject AdminOptions AdminOptions;

<PageTitle>@AdminOptions.AdminPanelHtmlTitle</PageTitle>
<Entities/>
<Entities />
7 changes: 7 additions & 0 deletions src/Saritasa.NetForge.Blazor/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
@inherits MainLayoutComponent
@inject AdminOptions AdminOptions;

<HeadContent>
@if (AdminOptions.CustomHeadType is not null)
{
<DynamicComponent Type="AdminOptions.CustomHeadType" />
}
</HeadContent>

<MudThemeProvider />
<MudDialogProvider />
<MudSnackbarProvider />
Expand Down

0 comments on commit 55a9acf

Please sign in to comment.