From c8512fb3309961a88cf9cc88386fb23df9489869 Mon Sep 17 00:00:00 2001 From: Rick Butterfield Date: Wed, 13 Nov 2024 09:56:49 +0000 Subject: [PATCH 1/2] Fixes #35 --- .../appsettings-schema.Umbraco.Cms.json | 7 ++ .../Models/ExternalResource.cs | 4 +- .../Models/SustainabilityData.cs | 86 +++++++++---------- .../Models/SustainabilityResponse.cs | 2 +- .../Services/SustainabilityService.cs | 10 +-- .../views/sustainability-content-app.html | 12 +-- 6 files changed, 64 insertions(+), 57 deletions(-) diff --git a/src/Umbraco.Community.Sustainability.TestSite.13.x/appsettings-schema.Umbraco.Cms.json b/src/Umbraco.Community.Sustainability.TestSite.13.x/appsettings-schema.Umbraco.Cms.json index 4a3bd2a..2d3d4d8 100644 --- a/src/Umbraco.Community.Sustainability.TestSite.13.x/appsettings-schema.Umbraco.Cms.json +++ b/src/Umbraco.Community.Sustainability.TestSite.13.x/appsettings-schema.Umbraco.Cms.json @@ -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 " } } }, diff --git a/src/Umbraco.Community.Sustainability/Models/ExternalResource.cs b/src/Umbraco.Community.Sustainability/Models/ExternalResource.cs index bd85c9c..3f25679 100644 --- a/src/Umbraco.Community.Sustainability/Models/ExternalResource.cs +++ b/src/Umbraco.Community.Sustainability/Models/ExternalResource.cs @@ -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; diff --git a/src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs b/src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs index 056212e..5bf95d1 100644 --- a/src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs +++ b/src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs @@ -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; } + 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; } } } diff --git a/src/Umbraco.Community.Sustainability/Models/SustainabilityResponse.cs b/src/Umbraco.Community.Sustainability/Models/SustainabilityResponse.cs index 1b1af76..553defa 100644 --- a/src/Umbraco.Community.Sustainability/Models/SustainabilityResponse.cs +++ b/src/Umbraco.Community.Sustainability/Models/SustainabilityResponse.cs @@ -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; } diff --git a/src/Umbraco.Community.Sustainability/Services/SustainabilityService.cs b/src/Umbraco.Community.Sustainability/Services/SustainabilityService.cs index fb93c59..e43c4d1 100644 --- a/src/Umbraco.Community.Sustainability/Services/SustainabilityService.cs +++ b/src/Umbraco.Community.Sustainability/Services/SustainabilityService.cs @@ -46,9 +46,9 @@ 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 }; } @@ -56,13 +56,13 @@ await page.AddScriptTagAsync(new PageAddScriptTagOptions() private ExternalResourceGroup GetExternalResourceGroup(ResourceGroupType groupType, IList 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(); foreach (var resource in resourcesByType.OrderByDescending(x => x.transferSize)) { - transferSize += resource.transferSize; + transferSize += resource.transferSize.GetValueOrDefault(); resourceList.Add(new ExternalResource(resource.name, resource.transferSize)); } diff --git a/src/Umbraco.Community.Sustainability/wwwroot/UmbracoCommunitySustainability/views/sustainability-content-app.html b/src/Umbraco.Community.Sustainability/wwwroot/UmbracoCommunitySustainability/views/sustainability-content-app.html index 4785e01..b9767fa 100644 --- a/src/Umbraco.Community.Sustainability/wwwroot/UmbracoCommunitySustainability/views/sustainability-content-app.html +++ b/src/Umbraco.Community.Sustainability/wwwroot/UmbracoCommunitySustainability/views/sustainability-content-app.html @@ -1,6 +1,6 @@
-
+

It looks like you haven't run a report on this page yet. Click the button below to get started.

-

Total size: {{(group.totalSize / 1024).toFixed(2)}}KB

+

Total size: {{(group.totalSize / 1024).toFixed(2)}}KB

  • {{resource.url}} ({{(resource.size / 1024).toFixed(2)}}KB) @@ -21,9 +21,9 @@
-
+
-

Last tested: {{lastTested}}

+

Last tested: {{lastTested}}

- + {{(sustainabilityData.totalSize / 1024).toFixed(2)}}KB - + {{sustainabilityData.totalEmissions.toFixed(4)}}g From 2d222d39dfed3ff41b040f82866cea73dfbb19c2 Mon Sep 17 00:00:00 2001 From: Rick Butterfield Date: Wed, 13 Nov 2024 13:39:36 +0000 Subject: [PATCH 2/2] Remove unused properties --- .../Models/SustainabilityData.cs | 43 ------------------- 1 file changed, 43 deletions(-) diff --git a/src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs b/src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs index 5bf95d1..41dcdc8 100644 --- a/src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs +++ b/src/Umbraco.Community.Sustainability/Models/SustainabilityData.cs @@ -12,55 +12,12 @@ public record Emissions { public double? co2 { get; set; } public bool green { 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 double? dataReloadRatio { get; set; } - public double? firstVisitPercentage { get; set; } - public double? returnVisitPercentage { get; set; } - } - - public record GridIntensity - { - 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 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; } } }