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-795: Upgrade to latest OC preview to test System.Text.Json #70

Merged
merged 16 commits into from
May 15, 2024
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
20 changes: 13 additions & 7 deletions Lombiq.ChartJs.Samples/Helpers/TransactionMigrationHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using Lombiq.ChartJs.Samples.Constants;
using Lombiq.ChartJs.Samples.Models;
using OrchardCore.Alias.Models;
using OrchardCore.Autoroute.Models;
using OrchardCore.ContentFields.Settings;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Taxonomies.Models;
using OrchardCore.Taxonomies.Settings;
using OrchardCore.Title.Models;
using System.Threading.Tasks;
using YesSql.Sql;

Expand All @@ -19,17 +23,19 @@ public static async Task<int> CreateTransactionAsync<TPart>(
string typeItemTaxonomyId)
where TPart : TransactionPart
{
// We need lower case version of content type name here
#pragma warning disable CA1308 // Normalize strings to uppercase
var aliasName = contentTypeName.ToLowerInvariant() + "-tags";
#pragma warning restore CA1308 // Normalize strings to uppercase

var taxonomyTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(ContentTypes.Taxonomy);
var taxonomyItem = await contentManager.NewAsync(taxonomyTypeDefinition.Name);
taxonomyItem.DisplayText = contentTypeName + " tags";
taxonomyItem.ContentItemId = typeItemTaxonomyId;
taxonomyItem.Content.TitlePart.Title = contentTypeName + " tags";
// We need lower case version of content type name here
#pragma warning disable CA1308 // Normalize strings to uppercase
taxonomyItem.Content.AliasPart.Alias = contentTypeName.ToLowerInvariant() + "-tags";
taxonomyItem.Content.AutoroutePart.Path = contentTypeName.ToLowerInvariant() + "-tags";
#pragma warning restore CA1308 // Normalize strings to uppercase
taxonomyItem.Content.TaxonomyPart.TermContentType = ContentTypes.Tag;
taxonomyItem.Alter<TitlePart>(part => part.Title = contentTypeName + " tags");
taxonomyItem.Alter<AliasPart>(part => part.Alias = aliasName);
taxonomyItem.Alter<AutoroutePart>(part => part.Path = aliasName);
taxonomyItem.Alter<TaxonomyPart>(part => part.TermContentType = ContentTypes.Tag);
await contentManager.CreateAsync(taxonomyItem, VersionOptions.Published);

await contentDefinitionManager.AlterPartDefinitionAsync<TPart>(part => part
Expand Down
4 changes: 2 additions & 2 deletions Lombiq.ChartJs.Samples/Lombiq.ChartJs.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.ContentFields" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.ContentFields" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.ChartJs/Lombiq.ChartJs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand Down
6 changes: 3 additions & 3 deletions Lombiq.ChartJs/Models/ChartJsDataSet.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Lombiq.ChartJs.Models;

Expand All @@ -9,10 +9,10 @@ public class ChartJsDataSet

public IEnumerable<double?> Data { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IEnumerable<string> BackgroundColor { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IEnumerable<string> BorderColor { get; set; }

public double BorderWidth { get; set; } = 1;
Expand Down
16 changes: 11 additions & 5 deletions Lombiq.ChartJs/Models/DataLabelAlignmentConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System;
using System.Text.Json.Serialization;

namespace Lombiq.ChartJs.Models;

Expand All @@ -8,7 +8,8 @@ public class DataLabelAlignmentConfiguration
[JsonIgnore]
public DataLabelAlignment Align { get; set; }

[JsonProperty("align")]
[JsonInclude]
sarahelsaig marked this conversation as resolved.
Show resolved Hide resolved
[JsonPropertyName("align")]
internal string AlignText
{
get => GetAlignment(Align);
Expand All @@ -18,15 +19,18 @@ internal string AlignText
[JsonIgnore]
public DataLabelAlignment Anchor { get; set; }

[JsonProperty("anchor")]
[JsonInclude]
sarahelsaig marked this conversation as resolved.
Show resolved Hide resolved
[JsonPropertyName("anchor")]
internal string AnchorText
{
get => GetAlignment(Anchor);
set => Anchor = SetAlignment(value);
}

[JsonPropertyName("offset")]
public double Offset { get; set; }

[JsonPropertyName("font")]
public FontStyle Font { get; set; }

private static string GetAlignment(DataLabelAlignment value) =>
Expand All @@ -49,13 +53,15 @@ private static DataLabelAlignment SetAlignment(string value) =>

public class FontStyle
{
[JsonPropertyName("size")]
public double Size { get; set; }

[JsonIgnore]
public bool IsBold { get; set; }

[JsonProperty("weight")]
public string Weight
[JsonInclude]
[JsonPropertyName("weight")]
internal string Weight
{
get => IsBold ? "bold" : "normal";
dministro marked this conversation as resolved.
Show resolved Hide resolved
set => IsBold = value.EqualsOrdinalIgnoreCase("bold");
Expand Down
4 changes: 2 additions & 2 deletions Lombiq.ChartJs/Models/LineAnnotation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using OrchardCore.Modules;
using System.Text.Json.Serialization;

namespace Lombiq.ChartJs.Models;

Expand All @@ -16,7 +16,7 @@ public string Mode
set => IsVertical = value.EqualsOrdinalIgnoreCase("vertical");
}

[JsonProperty("scaleID")]
[JsonPropertyName("scaleID")]
public string ScaleId => IsVertical ? "x-axis-0" : "y-axis-0";

public double Value { get; set; }
Expand Down
10 changes: 2 additions & 8 deletions Lombiq.ChartJs/Views/Chart.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
const string canvasName = blockName + "__canvas";

var canvasId = $"{canvasName}_{Guid.NewGuid():N}";

var camelCase = new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() },
Formatting = Formatting.Indented,
};
}
<div class="@containerName">
<canvas id="@canvasId" class="@canvasName"></canvas>
Expand Down Expand Up @@ -48,9 +42,9 @@
type: @Json.Serialize(type),
data: {
labels: @Json.Serialize(labels),
datasets: @Json.Serialize(datasets, camelCase),
datasets: @Json.Serialize(datasets),
},
options: @Json.Serialize(options, camelCase),
options: @Json.Serialize(options),
plugins: [{
beforeDraw: function(chartInstance) {
var canvasContext = chartInstance.chart.ctx;
Expand Down
4 changes: 2 additions & 2 deletions Lombiq.ChartJs/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
@using Lombiq.ChartJs.Constants
@using Lombiq.ChartJs.Models
@using Microsoft.AspNetCore.Mvc.Localization
@using Newtonsoft.Json
@using Newtonsoft.Json.Serialization
@using System.Text.Json
@using System.Text.Json.Serialization
@using OrchardCore.Mvc.Core.Utilities