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

V1/bugfix/json deserialization #49

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,13 @@
"type": "string",
"description": "Invalid HTML elements for RichText Editor.\n ",
"default": "font"
},
"CloudApiKey": {
"type": [
"null",
"string"
],
"description": "Cloud API Key for TinyMCE. This is required to use TinyMCE premium plugins.\n "
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public class ExternalResource
public string? Url { get; set; }

[JsonProperty("size")]
public decimal Size { get; set; } = 0;
public int? Size { get; set; } = 0;

public ExternalResource() { }

public ExternalResource(string url, decimal size)
public ExternalResource(string url, int? size)
{
Url = url;
Size = size;
Expand Down
86 changes: 43 additions & 43 deletions src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,65 @@ namespace Umbraco.Community.Sustainability.Models
{
public record SustainabilityData
{
public int pageWeight { get; set; }
public string carbonRating { get; set; }
public Emissions emissions { get; set; }
public Resource[] resources { get; set; }
public int? pageWeight { get; set; }
public string? carbonRating { get; set; }
public Emissions? emissions { get; set; }
public Resource[]? resources { get; set; }
}

public record Emissions
{
public float co2 { get; set; }
public double? co2 { get; set; }
public bool green { get; set; }
public Variables variables { get; set; }
public Variables? variables { get; set; }
}

public record Variables
{
public string description { get; set; }
public int bytes { get; set; }
public Gridintensity gridIntensity { get; set; }
public float dataReloadRatio { get; set; }
public float firstVisitPercentage { get; set; }
public float returnVisitPercentage { get; set; }
public string? description { get; set; }
public int? bytes { get; set; }
public GridIntensity? gridIntensity { get; set; }
public double? dataReloadRatio { get; set; }
public double? firstVisitPercentage { get; set; }
public double? returnVisitPercentage { get; set; }
}

public record Gridintensity
public record GridIntensity
{
public string description { get; set; }
public float network { get; set; }
public float dataCenter { get; set; }
public float production { get; set; }
public float device { get; set; }
public string? description { get; set; }
public double? network { get; set; }
public double? dataCenter { get; set; }
public double? production { get; set; }
public double? device { get; set; }
}

public record Resource
{
public string name { get; set; }
public string entryType { get; set; }
public float startTime { get; set; }
public float duration { get; set; }
public string initiatorType { get; set; }
public string deliveryType { get; set; }
public string nextHopProtocol { get; set; }
public string renderBlockingStatus { get; set; }
public int workerStart { get; set; }
public int redirectStart { get; set; }
public int redirectEnd { get; set; }
public float fetchStart { get; set; }
public float domainLookupStart { get; set; }
public float domainLookupEnd { get; set; }
public float connectStart { get; set; }
public float secureConnectionStart { get; set; }
public float connectEnd { get; set; }
public float requestStart { get; set; }
public float responseStart { get; set; }
public int firstInterimResponseStart { get; set; }
public float responseEnd { get; set; }
public int transferSize { get; set; }
public int encodedBodySize { get; set; }
public int decodedBodySize { get; set; }
public int responseStatus { get; set; }
public string? name { get; set; }
rickbutterfield marked this conversation as resolved.
Show resolved Hide resolved
public string? entryType { get; set; }
public double? startTime { get; set; }
public double? duration { get; set; }
public string? initiatorType { get; set; }
public string? deliveryType { get; set; }
public string? nextHopProtocol { get; set; }
public string? renderBlockingStatus { get; set; }
public double? workerStart { get; set; }
public double? redirectStart { get; set; }
public double? redirectEnd { get; set; }
public double? fetchStart { get; set; }
public double? domainLookupStart { get; set; }
public double? domainLookupEnd { get; set; }
public double? connectStart { get; set; }
public double? secureConnectionStart { get; set; }
public double? connectEnd { get; set; }
public double? requestStart { get; set; }
public double? responseStart { get; set; }
public double? firstInterimResponseStart { get; set; }
public double? responseEnd { get; set; }
public int? transferSize { get; set; }
public int? encodedBodySize { get; set; }
public int? decodedBodySize { get; set; }
public int? responseStatus { get; set; }
public object[] serverTiming { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SustainabilityResponse
public decimal TotalSize { get; set; } = 0;

[JsonProperty("totalEmissions")]
public float TotalEmissions { get; set; } = 0;
public double TotalEmissions { get; set; } = 0;

[JsonProperty("carbonRating")]
public string? CarbonRating { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ await page.AddScriptTagAsync(new PageAddScriptTagOptions()

return new SustainabilityResponse()
{
TotalSize = sustainabilityData.pageWeight,
TotalEmissions = sustainabilityData.emissions.co2,
CarbonRating = sustainabilityData.carbonRating,
TotalSize = sustainabilityData?.pageWeight.GetValueOrDefault() ?? 0,
TotalEmissions = sustainabilityData?.emissions?.co2.GetValueOrDefault() ?? 0,
CarbonRating = sustainabilityData?.carbonRating,
ResourceGroups = resourceGroups
};
}

private ExternalResourceGroup GetExternalResourceGroup(ResourceGroupType groupType, IList<Resource> resources)
{
var initiator = ExternalResourceGroup.GetInitiatorType(groupType);
var resourcesByType = resources.Where(x => x.initiatorType.Equals(initiator) && x.transferSize > 0);
var resourcesByType = resources.Where(x => !string.IsNullOrEmpty(x.initiatorType) && x.initiatorType.Equals(initiator) && x.transferSize > 0);

var transferSize = 0;
var resourceList = new List<ExternalResource>();
foreach (var resource in resourcesByType.OrderByDescending(x => x.transferSize))
{
transferSize += resource.transferSize;
transferSize += resource.transferSize.GetValueOrDefault();
resourceList.Add(new ExternalResource(resource.name, resource.transferSize));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div ng-controller="Umbraco.Sustainability.ContentApp.Controller as vm">
<div class="umb-logviewer">
<div class="umb-logviewer__main-content">
<div class="umb-logviewer__main-content" style="width: calc(100% - 420px)">
<uui-box headline="Loading sustainability report" ng-if="loading">
<p>It looks like you haven't run a report on this page yet. Click the button below to get started.</p>
<uui-button look="primary"
Expand All @@ -12,7 +12,7 @@
</uui-box>

<uui-box style="margin-bottom: 16px;" headline="{{group.name}}" ng-repeat="group in sustainabilityData.resourceGroups" ng-if="!loading">
<p style="margin-bottom: 0;" slot="header">Total size: {{(group.totalSize / 1024).toFixed(2)}}KB</p>
<p style="margin-bottom: 0;" slot="header-actions">Total size: {{(group.totalSize / 1024).toFixed(2)}}KB</p>
<ul>
<li ng-repeat="resource in group.resources">
{{resource.url}} ({{(resource.size / 1024).toFixed(2)}}KB)
Expand All @@ -21,9 +21,9 @@
</uui-box>
</div>

<div class="umb-logviewer__sidebar" ng-if="!loading">
<div class="umb-logviewer__sidebar" style="flex: 0 0 400px;" ng-if="!loading">
<uui-box headline="Sustainability report" style="margin-bottom: 16px;">
<p slot="header" style="margin-bottom: 0;">Last tested: {{lastTested}}</p>
<p slot="headline" style="margin-bottom: 0; font-weight: 400;">Last tested: {{lastTested}}</p>

<uui-button look="primary"
ng-click="vm.clickButton()"
Expand All @@ -34,11 +34,11 @@
</uui-box>

<div class="umb-box-row" style="margin-bottom: 16px;">
<uui-box headline="Page size" style="margin-left: 10px; margin-right: 10px; flex: 1;">
<uui-box headline="Page size" style="margin-left: 8px; margin-right: 8px; flex: 1;">
{{(sustainabilityData.totalSize / 1024).toFixed(2)}}KB
</uui-box>

<uui-box headline="CO₂ per page view" style="margin-left: 10px; margin-right: 10px; flex: 1;">
<uui-box headline="CO₂ per page view" style="margin-left: 8px; margin-right: 8px; flex: 1;">
{{sustainabilityData.totalEmissions.toFixed(4)}}g
</uui-box>

Expand Down