-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a new Narbar shape (#14488)
- Loading branch information
1 parent
f377a07
commit 878b693
Showing
37 changed files
with
519 additions
and
375 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/OrchardCore.Modules/OrchardCore.Admin/Drivers/VisitSiteNavbarDisplayDriver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using OrchardCore.Admin.Models; | ||
using OrchardCore.DisplayManagement.Handlers; | ||
using OrchardCore.DisplayManagement.Views; | ||
|
||
namespace OrchardCore.Admin.Drivers; | ||
|
||
public class VisitSiteNavbarDisplayDriver : DisplayDriver<Navbar> | ||
{ | ||
public override IDisplayResult Display(Navbar model) | ||
{ | ||
return View("VisitSiteNavbarItem", model) | ||
.Location("DetailAdmin", "Content:20"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/OrchardCore.Modules/OrchardCore.Admin/Views/Navbar.DetailAdmin.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@if (Model.Content == null) | ||
{ | ||
return; | ||
} | ||
|
||
<ul class="navbar-nav user-top-navbar ms-auto d-flex flex-row"> | ||
@await DisplayAsync(Model.Content) | ||
</ul> |
8 changes: 8 additions & 0 deletions
8
src/OrchardCore.Modules/OrchardCore.Admin/Views/Navbar.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@if (Model.Content == null) | ||
{ | ||
return; | ||
} | ||
|
||
<ul class="navbar-nav user-top-navbar"> | ||
@await DisplayAsync(Model.Content) | ||
</ul> |
File renamed without changes.
42 changes: 42 additions & 0 deletions
42
...odules/OrchardCore.ContentLocalization/Drivers/ContentCulturePickerNavbarDisplayDriver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Localization; | ||
using OrchardCore.Admin.Models; | ||
using OrchardCore.ContentLocalization.ViewModels; | ||
using OrchardCore.DisplayManagement.Handlers; | ||
using OrchardCore.DisplayManagement.Views; | ||
using OrchardCore.Localization; | ||
|
||
namespace OrchardCore.ContentLocalization.Drivers; | ||
|
||
public class ContentCulturePickerNavbarDisplayDriver : DisplayDriver<Navbar> | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly ILocalizationService _localizationService; | ||
|
||
public ContentCulturePickerNavbarDisplayDriver( | ||
IHttpContextAccessor httpContextAccessor, | ||
ILocalizationService localizationService) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
_localizationService = localizationService; | ||
} | ||
|
||
public override async Task<IDisplayResult> DisplayAsync(Navbar model, BuildDisplayContext context) | ||
{ | ||
var supportedCultures = (await _localizationService.GetSupportedCulturesAsync()).Select(c => CultureInfo.GetCultureInfo(c)); | ||
|
||
return Initialize<CulturePickerViewModel>("ContentCulturePicker", model => | ||
{ | ||
model.SupportedCultures = supportedCultures; | ||
model.CurrentCulture = _httpContextAccessor | ||
.HttpContext | ||
.Features | ||
.Get<IRequestCultureFeature>()?.RequestCulture?.Culture ?? CultureInfo.CurrentUICulture; | ||
}).RenderWhen(() => Task.FromResult(supportedCultures.Count() > 1)) | ||
.Location("Detail", "Content:5"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/OrchardCore.Modules/OrchardCore.ContentLocalization/ViewModels/CulturePickerViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using Microsoft.AspNetCore.Mvc.ModelBinding; | ||
|
||
namespace OrchardCore.ContentLocalization.ViewModels; | ||
|
||
public class CulturePickerViewModel | ||
{ | ||
[BindNever] | ||
public CultureInfo CurrentCulture { get; set; } | ||
|
||
[BindNever] | ||
public IEnumerable<CultureInfo> SupportedCultures { get; set; } | ||
} |
29 changes: 17 additions & 12 deletions
29
src/OrchardCore.Modules/OrchardCore.ContentLocalization/Views/ContentCulturePicker.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
@using System.Globalization | ||
@using Microsoft.AspNetCore.Localization | ||
@inject OrchardCore.Localization.ILocalizationService localizationService | ||
|
||
@{ | ||
var currentCulture = Context.Features.Get<IRequestCultureFeature>()?.RequestCulture?.Culture ?? CultureInfo.CurrentUICulture; | ||
var supportedCultures = (await localizationService.GetSupportedCulturesAsync()).Select(c => CultureInfo.GetCultureInfo(c)); | ||
} | ||
@await DisplayAsync(await New.ContentCulturePickerContainer( | ||
CurrentCulture: currentCulture, | ||
SupportedCultures: supportedCultures | ||
)) | ||
<li class="nav-item dropdown"> | ||
<a class="nav-link dropdown-toggle" href="#" id="oc-culture-picker" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">@Model.CurrentCulture.NativeName</a> | ||
<div class="dropdown-menu" aria-labelledby="oc-culture-picker"> | ||
@foreach (var culture in Model.SupportedCultures) | ||
{ | ||
if (culture.Name != Model.CurrentCulture.Name) | ||
{ | ||
<a asp-route="RedirectToLocalizedContent" | ||
asp-route-area="OrchardCore.ContentLocalization" | ||
asp-route-targetCulture="@culture.Name" | ||
asp-route-contentItemUrl="@Context.Request.Path.Value" | ||
asp-route-queryStringValue="@Context.Request.QueryString.Value" | ||
class="dropdown-item">@culture.NativeName</a> | ||
} | ||
} | ||
</div> | ||
</li> |
19 changes: 0 additions & 19 deletions
19
...rdCore.Modules/OrchardCore.ContentLocalization/Views/ContentCulturePickerContainer.cshtml
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
src/OrchardCore.Modules/OrchardCore.Localization/AdminCulturePickerShapes.cs
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
...ardCore.Modules/OrchardCore.Localization/Drivers/AdminCulturePickerNavbarDisplayDriver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Localization; | ||
using OrchardCore.Admin.Models; | ||
using OrchardCore.DisplayManagement.Handlers; | ||
using OrchardCore.DisplayManagement.Views; | ||
using OrchardCore.Localization.ViewModels; | ||
|
||
namespace OrchardCore.Localization.Drivers; | ||
|
||
public class AdminCulturePickerNavbarDisplayDriver : DisplayDriver<Navbar> | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly ILocalizationService _localizationService; | ||
|
||
public AdminCulturePickerNavbarDisplayDriver( | ||
IHttpContextAccessor httpContextAccessor, | ||
ILocalizationService localizationService) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
_localizationService = localizationService; | ||
} | ||
|
||
public override async Task<IDisplayResult> DisplayAsync(Navbar model, BuildDisplayContext context) | ||
{ | ||
var supportedCultures = (await _localizationService.GetSupportedCulturesAsync()).Select(c => CultureInfo.GetCultureInfo(c)); | ||
|
||
return Initialize<AdminCulturePickerViewModel>("AdminCulturePicker", model => | ||
{ | ||
model.SupportedCultures = supportedCultures; | ||
model.CurrentCulture = _httpContextAccessor | ||
.HttpContext | ||
.Features | ||
.Get<IRequestCultureFeature>()?.RequestCulture?.Culture ?? CultureInfo.CurrentUICulture; | ||
}).RenderWhen(() => Task.FromResult(supportedCultures.Count() > 1)) | ||
.Location("DetailAdmin", "Content:5"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/OrchardCore.Modules/OrchardCore.Localization/ViewModels/AdminCulturePickerViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using Microsoft.AspNetCore.Mvc.ModelBinding; | ||
|
||
namespace OrchardCore.Localization.ViewModels; | ||
|
||
public class AdminCulturePickerViewModel | ||
{ | ||
[BindNever] | ||
public CultureInfo CurrentCulture { get; set; } | ||
|
||
[BindNever] | ||
public IEnumerable<CultureInfo> SupportedCultures { get; set; } | ||
} |
50 changes: 38 additions & 12 deletions
50
src/OrchardCore.Modules/OrchardCore.Localization/Views/AdminCulturePicker.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,42 @@ | ||
@using System.Globalization | ||
@using Microsoft.AspNetCore.Localization | ||
@inject OrchardCore.Localization.ILocalizationService localizationService | ||
@using OrchardCore.Localization | ||
@using OrchardCore.Environment.Shell | ||
|
||
@model AdminCulturePickerViewModel | ||
|
||
@inject ShellSettings ShellSettings | ||
|
||
@{ | ||
var currentCulture = Context.Features.Get<IRequestCultureFeature>()?.RequestCulture?.Culture ?? CultureInfo.CurrentUICulture; | ||
var supportedCultures = (await localizationService.GetSupportedCulturesAsync()).Select(c => CultureInfo.GetCultureInfo(c)); | ||
var cookieName = AdminCookieCultureProvider.MakeCookieName(ShellSettings); | ||
var cookiePath = AdminCookieCultureProvider.MakeCookiePath(Context); | ||
var selectedCultureName = Model.CurrentCulture.Name; | ||
} | ||
|
||
@if (supportedCultures.Count() > 1) | ||
{ | ||
@await DisplayAsync(await New.AdminCulturePickerContainer( | ||
CurrentCulture: currentCulture, | ||
SupportedCultures: supportedCultures | ||
)); | ||
} | ||
<li class="nav-item"> | ||
<select id="oc-admin-culture-picker" class="form-select me-3" | ||
data-cookie-name="@cookieName" | ||
data-cookie-path="@cookiePath" | ||
data-selected-culture="@selectedCultureName"> | ||
|
||
@foreach (var culture in Model.SupportedCultures) | ||
{ | ||
<option selected="@(culture.Name == selectedCultureName ? "selected" : null)" value="@culture.Name">@culture.NativeName</option> | ||
} | ||
</select> | ||
</li> | ||
|
||
<script at="Foot" depends-on="jquery"> | ||
$(function () { | ||
$('#oc-admin-culture-picker').change(function () { | ||
var $this = $(this); | ||
var culture = $this.val(); | ||
var selectedCulture = $this.data('selected-culture'); | ||
if (culture != selectedCulture) { | ||
var cookieName = $this.data('cookie-name'); | ||
var cookiePath = $this.data('cookie-path'); | ||
var cookieValue = `${cookieName}=c=${culture}|uic=${culture};path=${cookiePath}`; | ||
document.cookie = cookieValue; | ||
window.location = window.location.href; | ||
} | ||
}); | ||
}); | ||
</script> |
40 changes: 0 additions & 40 deletions
40
src/OrchardCore.Modules/OrchardCore.Localization/Views/AdminCulturePickerContainer.cshtml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.