Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-60: .NET 6 and Orchard Core 1.3 upgrade #90

Merged
merged 6 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Lombiq.DataTables.Samples/Constants/ContentTypes.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Lombiq.DataTables.Samples.Constants
namespace Lombiq.DataTables.Samples.Constants;

public static class ContentTypes
{
public static class ContentTypes
{
public const string Employee = nameof(Employee);
}
public const string Employee = nameof(Employee);
}
37 changes: 18 additions & 19 deletions Lombiq.DataTables.Samples/Controllers/SampleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@
using YesSql;
using static Lombiq.DataTables.Samples.Constants.ContentTypes;

namespace Lombiq.DataTables.Samples.Controllers
namespace Lombiq.DataTables.Samples.Controllers;

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

public SampleController(ISession session) => _session = session;
public SampleController(ISession session) => _session = session;

// The tag helper needs the data during page render, which can make the initial page load slower. This is okay
// for small tables. You'll see approaches better suited for large datasets later. See it under
// /Lombiq.DataTables.Samples/Sample/DataTableTagHelper
public async Task<IActionResult> DataTableTagHelper() =>
View(
(await _session
.QueryContentItem(PublicationStatus.Published)
.Where(index => index.ContentType == Employee)
.ListAsync())
.Select(contentItem => contentItem.As<EmployeePart>()));
// The tag helper needs the data during page render, which can make the initial page load slower. This is okay for
// small tables. You'll see approaches better suited for large datasets later. See it under
// /Lombiq.DataTables.Samples/Sample/DataTableTagHelper
public async Task<IActionResult> DataTableTagHelper() =>
View(
(await _session
.QueryContentItem(PublicationStatus.Published)
.Where(index => index.ContentType == Employee)
.ListAsync())
.Select(contentItem => contentItem.As<EmployeePart>()));

// Nothing interesting happens here, the shape sends out the asynchronous request on its own via JavaScript. See
// it under /Lombiq.DataTables.Samples/Sample/ProviderWithShape
public IActionResult ProviderWithShape() => View();
}
// Nothing interesting happens here, the shape sends out the asynchronous request on its own via JavaScript. See it
// under /Lombiq.DataTables.Samples/Sample/ProviderWithShape
public IActionResult ProviderWithShape() => View();
}
36 changes: 18 additions & 18 deletions Lombiq.DataTables.Samples/Indexes/EmployeeDataTableIndex.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
using System;
using YesSql.Indexes;

namespace Lombiq.DataTables.Samples.Indexes
namespace Lombiq.DataTables.Samples.Indexes;

// An index-based provider needs its own dedicated index which represents the final computed or joined data to be
// displayed in the table. During display you only need to query this index alone to get all table data. However, to
// make it happen you must update the index with an index generator.
public class EmployeeDataTableIndex : MapIndex
{
// An index-based provider needs its own dedicated index which represents the final computed or joined data to be
// displayed in the table. During display you only need to query this index alone to get all table data. However,
// to make it happen you must update the index with an index generator.
public class EmployeeDataTableIndex : MapIndex
{
// If you are coming from the SampleJsonResultDataTableDataProvider, you can see this is very similar to the
// EmployeeJsonResult there, because it serves the same purpose. This one doesn't have the Actions property
// which only contains additional data related to the user visiting the page. Also the numeric types are smaller
// to conserve space in the database. This can be very important on large sets.
public string ContentItemId { get; set; }
public string Name { get; set; }
public string Position { get; set; }
public string Office { get; set; }
public short? Age { get; set; }
public DateTime? StartDate { get; set; }
public int? Salary { get; set; }
}
// If you are coming from the SampleJsonResultDataTableDataProvider, you can see this is very similar to the
// EmployeeJsonResult there, because it serves the same purpose. This one doesn't have the Actions property which
// only contains additional data related to the user visiting the page. Also the numeric types are smaller to
// conserve space in the database. This can be very important on large sets.
public string ContentItemId { get; set; }

public string Name { get; set; }
public string Position { get; set; }
public string Office { get; set; }
public short? Age { get; set; }
public DateTime? StartDate { get; set; }
public int? Salary { get; set; }
}

// NEXT STATION: Services/EmployeeDataTableIndexGenerator.cs
6 changes: 3 additions & 3 deletions Lombiq.DataTables.Samples/Lombiq.DataTables.Samples.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**;Tests\**</DefaultItemExcludes>
</PropertyGroup>
Expand Down Expand Up @@ -34,8 +34,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.ContentFields" Version="1.2.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.2.2" />
<PackageReference Include="OrchardCore.ContentFields" Version="1.3.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 14 additions & 15 deletions Lombiq.DataTables.Samples/Migrations/EmployeeDataTableMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
using System;
using YesSql.Sql.Schema;

namespace Lombiq.DataTables.Samples.Migrations
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>
{
// 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>
{
protected override void CreateIndex(ICreateTableCommand table) =>
table
.Column<string>(nameof(EmployeeDataTableIndex.ContentItemId))
.Column<string>(nameof(EmployeeDataTableIndex.Name))
.Column<string>(nameof(EmployeeDataTableIndex.Position))
.Column<string>(nameof(EmployeeDataTableIndex.Office))
.Column<short?>(nameof(EmployeeDataTableIndex.Age))
.Column<DateTime?>(nameof(EmployeeDataTableIndex.StartDate))
.Column<int?>(nameof(EmployeeDataTableIndex.Salary));
}
protected override void CreateIndex(ICreateTableCommand table) =>
table
.Column<string>(nameof(EmployeeDataTableIndex.ContentItemId))
.Column<string>(nameof(EmployeeDataTableIndex.Name))
.Column<string>(nameof(EmployeeDataTableIndex.Position))
.Column<string>(nameof(EmployeeDataTableIndex.Office))
.Column<short?>(nameof(EmployeeDataTableIndex.Age))
.Column<DateTime?>(nameof(EmployeeDataTableIndex.StartDate))
.Column<int?>(nameof(EmployeeDataTableIndex.Salary));
}

// NEXT STATION: Services/SampleIndexBasedDataTableDataProvider.cs
45 changes: 22 additions & 23 deletions Lombiq.DataTables.Samples/Migrations/EmployeeMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,32 @@
using System;
using static Lombiq.DataTables.Samples.Constants.ContentTypes;

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

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

public int Create()
{
_contentDefinitionManager.AlterPartDefinition(nameof(EmployeePart), part => part
.WithField(nameof(EmployeePart.Name), ConfigureField<TextField>(name: "Name"))
.WithField(nameof(EmployeePart.Position), ConfigureField<TextField>(name: "Position"))
.WithField(nameof(EmployeePart.Office), ConfigureField<TextField>(name: "Office Location"))
.WithField(nameof(EmployeePart.Age), ConfigureField<NumericField>(name: "Age"))
.WithField(nameof(EmployeePart.StartDate), ConfigureField<DateField>(name: "Start Date"))
.WithField(nameof(EmployeePart.Salary), ConfigureField<NumericField>(name: "Salary")));
public EmployeeMigrations(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager;

_contentDefinitionManager.AlterTypeDefinition(Employee, type => type
.Listable()
.WithPart(nameof(EmployeePart)));
public int Create()
{
_contentDefinitionManager.AlterPartDefinition(nameof(EmployeePart), part => part
.WithField(nameof(EmployeePart.Name), ConfigureField<TextField>(name: "Name"))
.WithField(nameof(EmployeePart.Position), ConfigureField<TextField>(name: "Position"))
.WithField(nameof(EmployeePart.Office), ConfigureField<TextField>(name: "Office Location"))
.WithField(nameof(EmployeePart.Age), ConfigureField<NumericField>(name: "Age"))
.WithField(nameof(EmployeePart.StartDate), ConfigureField<DateField>(name: "Start Date"))
.WithField(nameof(EmployeePart.Salary), ConfigureField<NumericField>(name: "Salary")));

return 1;
}
_contentDefinitionManager.AlterTypeDefinition(Employee, type => type
.Listable()
.WithPart(nameof(EmployeePart)));

private static Action<ContentPartFieldDefinitionBuilder> ConfigureField<T>(string name) =>
field => field.OfType(typeof(T).Name).WithDisplayName(name);
return 1;
}

private static Action<ContentPartFieldDefinitionBuilder> ConfigureField<T>(string name) =>
field => field.OfType(typeof(T).Name).WithDisplayName(name);
}
19 changes: 9 additions & 10 deletions Lombiq.DataTables.Samples/Models/EmployeePart.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using OrchardCore.ContentFields.Fields;
using OrchardCore.ContentManagement;

namespace Lombiq.DataTables.Samples.Models
namespace Lombiq.DataTables.Samples.Models;

public class EmployeePart : ContentPart
{
public class EmployeePart : ContentPart
{
public TextField Name { get; set; } = new();
public TextField Position { get; set; } = new();
public TextField Office { get; set; } = new();
public NumericField Age { get; set; } = new();
public DateField StartDate { get; set; } = new();
public NumericField Salary { get; set; } = new();
}
public TextField Name { get; set; } = new();
public TextField Position { get; set; } = new();
public TextField Office { get; set; } = new();
public NumericField Age { get; set; } = new();
public DateField StartDate { get; set; } = new();
public NumericField Salary { get; set; } = new();
}
Loading