Skip to content

Commit

Permalink
Merge pull request #169 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 d7a2ef6 + 56266ce commit a390098
Show file tree
Hide file tree
Showing 41 changed files with 432 additions and 286 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ wwwroot/
node_modules/
*.user
.pnpm-debug.log
*.orig
2 changes: 1 addition & 1 deletion Lombiq.DataTables.Samples/Controllers/SampleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Lombiq.DataTables.Samples.Controllers;

public class SampleController : Controller
public sealed class SampleController : Controller
{
private readonly ISession _session;

Expand Down
4 changes: 2 additions & 2 deletions Lombiq.DataTables.Samples/Lombiq.DataTables.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.ContentFields" Version="1.8.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.0" />
<PackageReference Include="OrchardCore.ContentFields" Version="2.0.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Lombiq.DataTables.Samples.Migrations;

// The migration for the data table index must inherit from IndexDataMigration<TIndex> so they can all be registered
// together in Startup in a tightly coupled fashion that reduces the chance of mistakes.
public class EmployeeDataTableMigrations : IndexDataMigration<EmployeeDataTableIndex>
public sealed class EmployeeDataTableMigrations : IndexDataMigration<EmployeeDataTableIndex>
{
protected override void CreateIndex(ICreateTableCommand table) =>
table
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.DataTables.Samples/Migrations/EmployeeMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Lombiq.DataTables.Samples.Migrations;

// Just the bare minimum to set up the content type for storing the sample data.
public class EmployeeMigrations : DataMigration
public sealed class EmployeeMigrations : DataMigration
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
4 changes: 2 additions & 2 deletions Lombiq.DataTables.Samples/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Lombiq.DataTables.Samples;

public class Startup : StartupBase
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
Expand All @@ -28,7 +28,7 @@ public override void ConfigureServices(IServiceCollection services)
EmployeeDataTableMigrations,
SampleIndexBasedDataTableDataProvider>();

services.AddScoped<INavigationProvider, DataTablesNavigationProvider>();
services.AddNavigationProvider<DataTablesNavigationProvider>();
}
}

Expand Down
2 changes: 1 addition & 1 deletion Lombiq.DataTables/Controllers/Api/ChildRowsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Lombiq.DataTables.Controllers.Api;

public class ChildRowsController : Controller
public sealed class ChildRowsController : Controller
{
private readonly IEnumerable<IDataTableDataProvider> _dataTableDataProviderAccessor;
private readonly IAuthorizationService _authorizationService;
Expand Down
14 changes: 6 additions & 8 deletions Lombiq.DataTables/Controllers/Api/RowsController.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Lombiq.DataTables.Models;
using Lombiq.DataTables.Services;
using Lombiq.HelpfulLibraries.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Lombiq.DataTables.Controllers.Api;

public class RowsController : Controller
public sealed class RowsController : Controller
{
private readonly IEnumerable<IDataTableDataProvider> _dataTableDataProviderAccessor;
private readonly Dictionary<string, IDataTableExportService> _exportServices;
Expand All @@ -32,7 +32,7 @@ public RowsController(
/// <summary>
/// Gets the current table view's rows.
/// </summary>
/// <param name="requestJson">The request to fulfill serialized as JSON.</param>
/// <param name="request">The request to fulfill serialized as JSON.</param>
/// <returns>The response for this API call.</returns>
/// <remarks>
/// <list type="bullet">
Expand All @@ -53,12 +53,11 @@ public RowsController(
/// </remarks>
[IgnoreAntiforgeryToken]
[HttpGet]
public async Task<ActionResult<DataTableDataResponse>> Get(string requestJson)
public async Task<ActionResult<DataTableDataResponse>> Get([FromJsonQueryString(Name = "requestJson")] DataTableDataRequest request)
{
if (string.IsNullOrEmpty(requestJson)) ModelState.AddModelError(nameof(requestJson), "Controller parameter is missing.");
if (request == null) return BadRequest();
if (!ModelState.IsValid) return BadRequest(ModelState);

var request = JsonConvert.DeserializeObject<DataTableDataRequest>(requestJson);
var dataProvider = _dataTableDataProviderAccessor.GetDataProvider(request.DataProvider);
if (dataProvider == null)
{
Expand Down Expand Up @@ -87,13 +86,12 @@ public async Task<ActionResult<DataTableDataResponse>> Get(string requestJson)
}

public async Task<ActionResult<DataTableDataResponse>> Export(
string requestJson,
[FromJsonQueryString(Name = "requestJson")] DataTableDataRequest request,
string name = null,
bool exportAll = true)
{
if (!ModelState.IsValid) return BadRequest(ModelState);

var request = JsonConvert.DeserializeObject<DataTableDataRequest>(requestJson);
if (exportAll)
{
request.Start = 0;
Expand Down
12 changes: 6 additions & 6 deletions Lombiq.DataTables/Controllers/TableController.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
using Lombiq.DataTables.Services;
using Lombiq.DataTables.ViewModels;
using Lombiq.HelpfulLibraries.OrchardCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using OrchardCore.Admin;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace Lombiq.DataTables.Controllers;

[Admin]
public class TableController : Controller
public sealed class TableController : Controller
{
private readonly IEnumerable<IDataTableDataProvider> _dataTableDataProviders;

public TableController(IEnumerable<IDataTableDataProvider> dataTableDataProviders) =>
_dataTableDataProviders = dataTableDataProviders;

[AdminRoute("DataTable/{providerName}/{queryId?}")]
[Admin("DataTable/{providerName}/{queryId?}")]
public async Task<IActionResult> Get(string providerName, string queryId = null, bool paging = true, bool viewAction = false)
{
if (!ModelState.IsValid) return BadRequest(ModelState);

var provider = _dataTableDataProviders.Single(provider => provider.Name == providerName);
if (string.IsNullOrEmpty(queryId)) queryId = providerName;
var definition = new DataTableDefinitionViewModel(JObject.FromObject(new { paging, viewAction }))

var additionalDatatableOptions = JObject.FromObject(new { paging, viewAction })!.AsObject();
var definition = new DataTableDefinitionViewModel(additionalDatatableOptions)
{
DataProvider = providerName,
QueryId = queryId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json;
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Security.Permissions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text.Json;
using System.Threading.Tasks;
using static Lombiq.DataTables.Constants.SortingDirection;

Expand Down Expand Up @@ -167,7 +167,7 @@ public static string GetCustomActionsJson(
IHttpContextAccessor hca,
LinkGenerator linkGenerator,
IStringLocalizer<ActionsDescriptor> actionsStringLocalizer) =>
JsonConvert.SerializeObject(GetCustomActions(
JsonSerializer.Serialize(GetCustomActions(
dataProvider,
contentItemId,
canDelete,
Expand Down
11 changes: 11 additions & 0 deletions Lombiq.DataTables/Extensions/JsonNodeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace System.Text.Json.Nodes;

public static class JsonNodeExtensions
{
/// <summary>
/// Checks if the provided <paramref name="node"/> is object and has a <c>Type</c> property, and if its value
/// matches <typeparamref name="T"/>.
/// </summary>
public static bool HasMatchingTypeProperty<T>(this JsonNode node) =>
node is JsonObject jsonObject && jsonObject["Type"]?.ToString() == typeof(T).Name;
}
4 changes: 2 additions & 2 deletions Lombiq.DataTables/Liquid/ActionsLiquidFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.DisplayManagement;
using OrchardCore.Liquid;
using System;
using System.IO;
using System.Text.Encodings.Web;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace Lombiq.DataTables.Liquid;
Expand Down Expand Up @@ -71,7 +71,7 @@ public ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArguments argu
FluidValues.Object => input!.ToObjectValue() switch
{
ActionsDescriptor model => FromObjectAsync(model, title, returnUrl),
JToken jToken => FromObjectAsync(jToken.ToObject<ActionsDescriptor>(), title, returnUrl),
JsonNode jsonNode => FromObjectAsync(jsonNode.ToObject<ActionsDescriptor>(), title, returnUrl),
{ } unknown => throw GetException(unknown),
_ => throw new ArgumentNullException(nameof(input)),
},
Expand Down
11 changes: 5 additions & 6 deletions Lombiq.DataTables/Lombiq.DataTables.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.102.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Nito.AsyncEx.Tasks" Version="5.1.2" />
<PackageReference Include="OrchardCore.Contents" Version="1.8.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.0" />
<PackageReference Include="OrchardCore.Search.Lucene" Version="1.8.0" />
<PackageReference Include="OrchardCore.Contents" Version="2.0.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0" />
<PackageReference Include="OrchardCore.Search.Lucene" Version="2.0.0" />
</ItemGroup>

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

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="10.0.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.LinqToDb" Version="10.0.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="11.0.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.LinqToDb" Version="11.0.0" />
<PackageReference Include="Lombiq.NodeJs.Extensions" Version="2.1.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Lombiq.DataTables/LombiqTests/Services/TestingFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Lombiq.DataTables.LombiqTests.Services;

public class TestingFilter : IAsyncResultFilter
public sealed class TestingFilter : IAsyncResultFilter
{
private readonly ILayoutAccessor _layoutAccessor;
private readonly IShapeFactory _shapeFactory;
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.DataTables/LombiqTests/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Lombiq.DataTables.LombiqTests;

[RequireFeatures("Lombiq.Tests.UI.Shortcuts")]
public class Startup : StartupBase
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services) =>
services.Configure<MvcOptions>(options => options.Filters.Add(typeof(TestingFilter)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Lombiq.DataTables.Migrations;

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

Expand Down
7 changes: 4 additions & 3 deletions Lombiq.DataTables/Models/DataTableChildRowResponse.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Text.Json.Serialization;

namespace Lombiq.DataTables.Models;

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class DataTableChildRowResponse
{
[JsonPropertyName("error")]
public string Error { get; set; }

[JsonPropertyName("content")]
public string Content { get; set; }

public static DataTableChildRowResponse ErrorResult(string errorText) => new() { Error = errorText };
Expand Down
13 changes: 10 additions & 3 deletions Lombiq.DataTables/Models/DataTableColumn.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Text.Json.Serialization;

namespace Lombiq.DataTables.Models;

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class DataTableColumn
{
[JsonPropertyName("data")]
public string Data { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("searchable")]
public bool Searchable { get; set; }

[JsonPropertyName("orderable")]
public bool Orderable { get; set; }

[JsonPropertyName("search")]
public DataTableSearchParameters Search { get; set; }
}
14 changes: 11 additions & 3 deletions Lombiq.DataTables/Models/DataTableDataRequest.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

namespace Lombiq.DataTables.Models;

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class DataTableDataRequest
{
public string QueryId { get; set; }

public string DataProvider { get; set; }

[JsonRequired]
public int Draw { get; set; }

[JsonRequired]
public int Start { get; set; }

[JsonRequired]
public int Length { get; set; }

public IEnumerable<DataTableColumn> ColumnFilters { get; set; }

public DataTableSearchParameters Search { get; set; }

public IEnumerable<DataTableOrder> Order { get; set; }

public bool HasSearch => !string.IsNullOrWhiteSpace(Search?.Value);
Expand Down
11 changes: 7 additions & 4 deletions Lombiq.DataTables/Models/DataTableDataResponse.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Lombiq.DataTables.Models;

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class DataTableDataResponse
{
/// <summary>
Expand All @@ -14,28 +12,33 @@ public class DataTableDataResponse
/// <remarks>
/// <para>For internal use only. It's overwritten during normal use.</para>
/// </remarks>
[JsonProperty]
[JsonPropertyName("draw")]
[JsonInclude]
internal int Draw { get; set; }

/// <summary>
/// Gets or sets the extra informational field that shows the actual total if filtering (such as keyword
/// search) is used. When not filtering it must be the same as <see cref="RecordsFiltered"/>.
/// </summary>
[JsonPropertyName("recordsTotal")]
public int RecordsTotal { get; set; }

/// <summary>
/// Gets or sets the total number of results; used for paging.
/// </summary>
[JsonPropertyName("recordsFiltered")]
public int RecordsFiltered { get; set; }

/// <summary>
/// Gets or sets the table contents of the current page.
/// </summary>
[JsonPropertyName("data")]
public IEnumerable<DataTableRow> Data { get; set; }

/// <summary>
/// Gets or sets the user-facing error message in case something went wrong.
/// </summary>
[JsonPropertyName("error")]
public string Error { get; set; }

/// <summary>
Expand Down
Loading

0 comments on commit a390098

Please sign in to comment.