Skip to content

Commit

Permalink
Merge pull request #125 from Lombiq/issue/OSOE-818
Browse files Browse the repository at this point in the history
OSOE-818: Upgrade to Orchard Core 2.0
  • Loading branch information
sarahelsaig authored Sep 25, 2024
2 parents f4805f0 + 11c3157 commit 4ed2b1b
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 102 deletions.
4 changes: 2 additions & 2 deletions Lombiq.BaseTheme.Samples/Lombiq.BaseTheme.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Admin" Version="1.8.0" />
<PackageReference Include="OrchardCore.Theme.Targets" Version="1.8.0" />
<PackageReference Include="OrchardCore.Admin" Version="2.0.0" />
<PackageReference Include="OrchardCore.Theme.Targets" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.BaseTheme.Samples/Migrations/RecipeMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Lombiq.BaseTheme.Samples.Migrations;
// invoke the corresponding "{module-or-theme-id}.UpdateFromN.recipe.json" recipe and return the incremented version
// number.
// If you just want a static default icon, check out the DerivedTheme.Favicon in Manifest.cs!
public class RecipeMigrations : RecipeMigrationsBase
public sealed class RecipeMigrations : RecipeMigrationsBase
{
public RecipeMigrations(IRecipeMigrator recipeMigrator)
: base(recipeMigrator)
Expand Down
4 changes: 2 additions & 2 deletions Lombiq.BaseTheme.Samples/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

namespace Lombiq.BaseTheme.Samples;

public class Startup : StartupBase
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IConfigureOptions<ResourceManagementOptions>, ResourceManagementOptionsConfiguration>();

// This is a sample main menu item. See the "Front-end navigation via the "main" menu" section.
services.AddScoped<INavigationProvider, AccountNavigationProvider>();
services.AddNavigationProvider<AccountNavigationProvider>();

// This service provides configuration to the ResourceFilterMiddleware.
services.AddScoped<IResourceFilterProvider, ResourceFilters>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

@* You can even include shapes conditionally. In this case we want a link to the admin dashboard but only for users who
are able to access it. Using this approach can be much easier than implementing a custom layer condition. *@
@if (await AuthorizationService.AuthorizeAsync(User, Permissions.AccessAdminPanel))
@if (await AuthorizationService.AuthorizeAsync(User, AdminPermissions.AccessAdminPanel))
{
<zone name="@ZoneNames.Footer" position="1">
<div class="zoneInsertionExample_footer">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using Newtonsoft.Json;
using OpenQA.Selenium;
using System.Text.Json;
using System.Threading.Tasks;

namespace Lombiq.BaseTheme.Tests.UI.Extensions;
Expand All @@ -12,7 +12,7 @@ public static async Task ClickMainMenuPathAsync(this UITestContext context, stri
{
var byFirst = By.XPath(
$"//div[contains(@class, \"menuWidget__content\")]/ul/li/a" +
$"[contains(@class, \"nav-link\") and contains(., {JsonConvert.SerializeObject(topMenuLabel)})]");
$"[contains(@class, \"nav-link\") and contains(., {JsonSerializer.Serialize(topMenuLabel)})]");

if (string.IsNullOrWhiteSpace(subMenuLabel))
{
Expand All @@ -22,7 +22,7 @@ public static async Task ClickMainMenuPathAsync(this UITestContext context, stri
{
await context.SelectFromBootstrapDropdownReliablyAsync(
context.Get(byFirst),
By.XPath($".//*[contains(@class, 'dropdown-item') and contains(., {JsonConvert.SerializeObject(subMenuLabel)})]"));
By.XPath($".//*[contains(@class, 'dropdown-item') and contains(., {JsonSerializer.Serialize(subMenuLabel)})]"));
}
}
}
2 changes: 1 addition & 1 deletion Lombiq.BaseTheme.Tests.UI/Lombiq.BaseTheme.Tests.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="10.0.1" />
<PackageReference Include="Lombiq.Tests.UI" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Lombiq.BaseTheme/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using Lombiq.HelpfulExtensions.Extensions.ContentTypes;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.DisplayManagement;
Expand All @@ -16,13 +14,15 @@
using OrchardCore.Modules;
using OrchardCore.Settings;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace Lombiq.BaseTheme.Controllers;

// This controller is there for editing the BaseThemeSettings. We can't use a site settings driver for this, because you
// can't declare admin-accessible shapes in a site theme.
public class AdminController : Controller
public sealed class AdminController : Controller
{
private readonly IClock _clock;
private readonly INotifier _notifier;
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task<IActionResult> Index()

editor.Paths = string.IsNullOrWhiteSpace(section.Icon)
? "[]"
: JsonConvert.SerializeObject(new[] { new { path = section.Icon } });
: JsonSerializer.Serialize(new[] { new { path = section.Icon } });
editor.Field = part.Icon;
editor.Part = part;
editor.PartFieldDefinition = new ContentPartFieldDefinition(
Expand Down
20 changes: 10 additions & 10 deletions Lombiq.BaseTheme/Lombiq.BaseTheme.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Theme.Targets" Version="1.8.0" />
<PackageReference Include="OrchardCore.Menu" Version="1.8.0" />
<PackageReference Include="OrchardCore.Media" Version="1.8.0" />
<PackageReference Include="OrchardCore.ContentManagement" Version="1.8.0" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.0" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.0" />
<PackageReference Include="OrchardCore.Theme.Targets" Version="2.0.0" />
<PackageReference Include="OrchardCore.Menu" Version="2.0.0" />
<PackageReference Include="OrchardCore.Media" Version="2.0.0" />
<PackageReference Include="OrchardCore.ContentManagement" Version="2.0.0" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand All @@ -59,11 +59,11 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.HelpfulLibraries" Version="10.0.0" />
<PackageReference Include="Lombiq.HelpfulExtensions" Version="8.0.1" />
<PackageReference Include="Lombiq.HelpfulLibraries" Version="11.0.0" />
<PackageReference Include="Lombiq.HelpfulExtensions" Version="9.0.0" />
<PackageReference Include="Lombiq.NodeJs.Extensions" Version="2.1.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.SourceGenerators" Version="10.0.0" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="Lombiq.HelpfulLibraries.Attributes" Version="10.0.0" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
<PackageReference Include="Lombiq.HelpfulLibraries.SourceGenerators" Version="11.0.0" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="Lombiq.HelpfulLibraries.Attributes" Version="11.0.0" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />

<Content Include="Assets/Styles/**/*.*">
<IncludeInPackage>true</IncludeInPackage>
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.BaseTheme/Migrations/LayoutInjectionMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Lombiq.BaseTheme.Migrations;

public class LayoutInjectionMigrations : DataMigration
public sealed class LayoutInjectionMigrations : DataMigration
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
2 changes: 1 addition & 1 deletion Lombiq.BaseTheme/Migrations/RecipeMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Lombiq.BaseTheme.Migrations;

public class RecipeMigrations : DataMigration
public sealed class RecipeMigrations : DataMigration
{
private readonly IRecipeMigrator _recipeMigrator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Lombiq.BaseTheme.Permissions;

public class BaseThemeSettingsPermissions : AdminPermissionBase
public sealed class BaseThemeSettingsPermissions : AdminPermissionBase
{
public static readonly Permission ManageBaseThemeSettings =
new(nameof(ManageBaseThemeSettings), "Manage Lombiq.BaseTheme Settings.");
Expand Down
3 changes: 1 addition & 2 deletions Lombiq.BaseTheme/Services/IconResourceFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public void AddResourceFilter(ResourceFilterBuilder builder) =>
}

// If the site setting icon is set, that should take priority.
if ((await _siteService.GetSiteSettingsAsync()).As<BaseThemeSettings>() is { } settings &&
!string.IsNullOrEmpty(settings.Icon))
if (await _siteService.GetSettingsAsync<BaseThemeSettings>() is { Icon.Length: > 0 } settings)
{
var path = _mediaFileStore.MapPathToPublicUrl(settings.Icon);
AddIcon(resourceManager, $"{path}?at={settings.TimeStamp.ToTechnicalString()}");
Expand Down
7 changes: 2 additions & 5 deletions Lombiq.BaseTheme/Services/MainMenuNavigationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.Menu.Models;
using OrchardCore.Navigation;
Expand Down Expand Up @@ -58,14 +57,12 @@ private async Task AddAsync(NavigationBuilder builder, ContentItem menuItem)

if (menuItem.As<LinkMenuItemPart>() is { } linkMenuItemPart)
{
builder.Add(text, menu => menu.Url(linkMenuItemPart.Url).LocalNav());
builder.Add(text, menu => menu.Url(linkMenuItemPart.Url).Local(linkMenuItemPart.Target != "_blank"));
}
else if (menuItem.As<ContentMenuItemPart>() is { } contentMenuItemPart)
{
if (contentMenuItemPart.Content.SelectedContentItem is JObject &&
contentMenuItemPart.Content.SelectedContentItem.ContentItemIds is JArray contentItemIds)
if (contentMenuItemPart.GetProperty<IEnumerable<string>>("SelectedContentItem.ContentItemIds") is { } ids)
{
var ids = contentItemIds.ToObject<IEnumerable<string>>();
await AddContentMenuItemPartAsync(builder, text, ids);
}
}
Expand Down
15 changes: 6 additions & 9 deletions Lombiq.BaseTheme/Services/MainMenuWidgetFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Lombiq.BaseTheme.Services;

public class MainMenuWidgetFilter : WidgetFilterBase<MenuWidgetViewModel>
public sealed class MainMenuWidgetFilter : WidgetFilterBase<MenuWidgetViewModel>
{
private readonly INavigationManager _navigationManager;
private readonly IActionContextAccessor _actionContextAccessor;
Expand Down Expand Up @@ -43,19 +43,16 @@ public MainMenuWidgetFilter(

protected override async Task<MenuWidgetViewModel> GetViewModelAsync()
{
var siteSettings = await _siteService.GetSiteSettingsAsync();
if (siteSettings.As<BaseThemeSettings>()?.HideMenu == true) return null;
if (await _siteService.GetSettingsAsync<BaseThemeSettings>() is { HideMenu: true }) return null;

// Add the <nav> classes to the zone holder <nav>.
_cssClassHolder.AddClassToZone(ZoneNames.Navigation, "navbar-expand-md");
_cssClassHolder.AddClassToZone(ZoneNames.Navigation, "navbar");

return new()
{
MenuItems = await _navigationManager.BuildMenuAsync(
return new(
noWrapper: true, // The navigation zone is already the wrapper.
menuItems: await _navigationManager.BuildMenuAsync(
MainMenuNavigationProviderBase.MainNavigationName,
_actionContextAccessor.ActionContext),
NoWrapper = true, // The navigation zone is already the wrapper.
};
_actionContextAccessor.ActionContext));
}
}
9 changes: 2 additions & 7 deletions Lombiq.BaseTheme/Services/ResourceManagerDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;

namespace Lombiq.BaseTheme.Services;

Expand Down Expand Up @@ -93,9 +92,7 @@ public void RenderStylesheet(TextWriter writer)

var first = true;

var styleSheets = GetRequiredResources("stylesheet").ToList();

foreach (var context in styleSheets)
foreach (var context in GetRequiredResources("stylesheet"))
{
if (context.Settings.Location == ResourceLocation.Inline)
{
Expand All @@ -119,10 +116,8 @@ public void RenderStylesheet(TextWriter writer)
context.WriteTo(writer, _options.ContentBasePath);
}

var registeredStyles = GetRegisteredStyles().ToArray();
for (var i = 0; i < registeredStyles.Length; i++)
foreach (var context in GetRegisteredStyles())
{
var context = registeredStyles[i];
if (!first)
{
writer.Write(Environment.NewLine);
Expand Down
8 changes: 4 additions & 4 deletions Lombiq.BaseTheme/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Lombiq.BaseTheme;

public class Startup : StartupBase
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
Expand All @@ -31,10 +31,10 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IResourceFilterProvider, IconResourceFilter>();

PerTenantShapeTableManager.ReplaceDefaultShapeTableManager(services);
services.AddScoped<INavigationProvider, MainMenuNavigationProvider>();
services.AddNavigationProvider<MainMenuNavigationProvider>();

services.AddScoped<IPermissionProvider, BaseThemeSettingsPermissions>();
services.AddScoped<INavigationProvider, BaseThemeSettingsAdminMenu>();
services.AddPermissionProvider<BaseThemeSettingsPermissions>();
services.AddNavigationProvider<BaseThemeSettingsAdminMenu>();

services.Decorate<IResourceManager, ResourceManagerDecorator>();
}
Expand Down
10 changes: 0 additions & 10 deletions Lombiq.BaseTheme/ViewModels/GoogleTagViewModel.cs

This file was deleted.

38 changes: 0 additions & 38 deletions Lombiq.BaseTheme/Views/GoogleTag.cshtml

This file was deleted.

10 changes: 10 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- Ignore global configuration -->
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="OrchardCorePreview" value="https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json" />
<add key="Lombiq" value="https://nuget.cloudsmith.io/lombiq/open-source-orchard-core-extensions/v3/index.json" />
</packageSources>
</configuration>

0 comments on commit 4ed2b1b

Please sign in to comment.