From b361d1c95028983d28539cf34df4b8ace18590d5 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 3 Dec 2018 14:26:16 +0000 Subject: [PATCH] Refactor package.manifest dashboards JSON structure --- .../Manifest/ManifestDashboardControl.cs | 13 ------ .../Manifest/ManifestDashboardSection.cs | 31 ++++++++++---- .../Manifest/ManifestDashboardTab.cs | 20 --------- src/Umbraco.Core/Manifest/ManifestParser.cs | 34 ++------------- src/Umbraco.Core/Manifest/PackageManifest.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 2 - src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 3 ++ src/Umbraco.Web/Editors/DashboardHelper.cs | 41 ++++++++----------- 8 files changed, 47 insertions(+), 99 deletions(-) delete mode 100644 src/Umbraco.Core/Manifest/ManifestDashboardControl.cs delete mode 100644 src/Umbraco.Core/Manifest/ManifestDashboardTab.cs diff --git a/src/Umbraco.Core/Manifest/ManifestDashboardControl.cs b/src/Umbraco.Core/Manifest/ManifestDashboardControl.cs deleted file mode 100644 index acac5e51fa..0000000000 --- a/src/Umbraco.Core/Manifest/ManifestDashboardControl.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Newtonsoft.Json; - -namespace Umbraco.Core.Manifest -{ - public class ManifestDashboardControl - { - [JsonProperty("path")] - public string Path { get; set; } - - [JsonProperty("caption")] - public string Caption { get; set; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Manifest/ManifestDashboardSection.cs b/src/Umbraco.Core/Manifest/ManifestDashboardSection.cs index e8586c366b..c09cd6bb45 100644 --- a/src/Umbraco.Core/Manifest/ManifestDashboardSection.cs +++ b/src/Umbraco.Core/Manifest/ManifestDashboardSection.cs @@ -3,18 +3,31 @@ using Newtonsoft.Json; namespace Umbraco.Core.Manifest { - public class ManifestDashboardSection + public class ManifestDashboard { - public ManifestDashboardSection() + public ManifestDashboard() { - Areas = new List(); - Tabs = new Dictionary(); + Name = string.Empty; + Alias = string.Empty; + Weight = int.MaxValue; //default so we can check if this value has been explicitly set + View = string.Empty; + Sections = new List(); } - [JsonProperty("areas")] - public List Areas { get; set; } + [JsonProperty("name")] + public string Name { get; set; } - [JsonProperty("tabs")] - public IDictionary Tabs { get; set; } + [JsonProperty("aias")] + public string Alias { get; set; } + + [JsonProperty("weight")] + public int Weight { get; set; } + + [JsonProperty("view")] + public string View { get; set; } + + [JsonProperty("sections")] + public List Sections { get; set; } + } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Manifest/ManifestDashboardTab.cs b/src/Umbraco.Core/Manifest/ManifestDashboardTab.cs deleted file mode 100644 index 970b1ead89..0000000000 --- a/src/Umbraco.Core/Manifest/ManifestDashboardTab.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Umbraco.Core.Manifest -{ - public class ManifestDashboardTab - { - public ManifestDashboardTab() - { - Controls = new List(); - Index = int.MaxValue; //default so we can check if this value has been explicitly set - } - - [JsonProperty("controls")] - public List Controls { get; set; } - - [JsonProperty("index")] - public int Index { get; set; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index 878ecc0b42..9a6b6ae343 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -100,7 +100,7 @@ namespace Umbraco.Core.Manifest var parameterEditors = new List(); var gridEditors = new List(); var contentApps = new List(); - var dashboards = new Dictionary(); + var dashboards = new List(); foreach (var manifest in manifests) { @@ -110,35 +110,7 @@ namespace Umbraco.Core.Manifest if (manifest.ParameterEditors != null) parameterEditors.AddRange(manifest.ParameterEditors); if (manifest.GridEditors != null) gridEditors.AddRange(manifest.GridEditors); if (manifest.ContentApps != null) contentApps.AddRange(manifest.ContentApps); - if (manifest.Dashboards != null) - { - foreach (var item in manifest.Dashboards) - { - if (dashboards.TryGetValue(item.Key, out var existing)) - { - foreach (var area in item.Value.Areas) - if (existing.Areas.Contains(area, StringComparer.InvariantCultureIgnoreCase) == false) - existing.Areas.Add(area); - - //merge - foreach (var tab in item.Value.Tabs) - { - if (existing.Tabs.TryGetValue(tab.Key, out var existingTab)) - { - //merge - foreach (var control in tab.Value.Controls) - { - existingTab.Controls.Add(control); - } - } - else - existing.Tabs[tab.Key] = tab.Value; - } - } - else - dashboards[item.Key] = item.Value; - } - } + if (manifest.Dashboards != null) dashboards.AddRange(manifest.Dashboards); } return new PackageManifest @@ -149,7 +121,7 @@ namespace Umbraco.Core.Manifest ParameterEditors = parameterEditors.ToArray(), GridEditors = gridEditors.ToArray(), ContentApps = contentApps.ToArray(), - Dashboards = dashboards + Dashboards = dashboards.ToArray() }; } diff --git a/src/Umbraco.Core/Manifest/PackageManifest.cs b/src/Umbraco.Core/Manifest/PackageManifest.cs index 92c5f89a9c..ac472e0eec 100644 --- a/src/Umbraco.Core/Manifest/PackageManifest.cs +++ b/src/Umbraco.Core/Manifest/PackageManifest.cs @@ -34,7 +34,7 @@ namespace Umbraco.Core.Manifest /// The dictionary of dashboards /// [JsonProperty("dashboards")] - public IReadOnlyDictionary Dashboards { get; set; } = new Dictionary(); + public ManifestDashboard[] Dashboards { get; set; } = Array.Empty(); } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 1f21de646d..d3a547f436 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -335,9 +335,7 @@ - - diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index b87bcb2b23..177033f88d 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -194,6 +194,8 @@ + + @@ -231,6 +233,7 @@ + 404handlers.config diff --git a/src/Umbraco.Web/Editors/DashboardHelper.cs b/src/Umbraco.Web/Editors/DashboardHelper.cs index f128c5b6a6..365e0c6f9a 100644 --- a/src/Umbraco.Web/Editors/DashboardHelper.cs +++ b/src/Umbraco.Web/Editors/DashboardHelper.cs @@ -145,35 +145,30 @@ namespace Umbraco.Web.Editors var tabs = new List>(); var i = startTabId; - foreach (var sectionDashboard in _manifestParser.Manifest.Dashboards.Where(x => x.Value.Areas.InvariantContains(section))) + foreach (var dashboard in _manifestParser.Manifest.Dashboards.Where(x => x.Sections.InvariantContains(section))) { - foreach (var tab in sectionDashboard.Value.Tabs) + var dashboardControls = new List(); + var view = dashboard.View.Trim(); + var dashboardControl = new DashboardControl { - var dashboardControls = new List(); + Path = IOHelper.FindFile(view) + }; - foreach (var control in tab.Value.Controls) - { - var dashboardControl = new DashboardControl(); - var controlPath = control.Path.Trim(); - dashboardControl.Caption = control.Caption; - dashboardControl.Path = IOHelper.FindFile(controlPath); - if (controlPath.ToLowerInvariant().EndsWith(".ascx".ToLowerInvariant())) - throw new NotSupportedException("Legacy UserControl (.ascx) dashboards are no longer supported"); + if (view.ToLowerInvariant().EndsWith(".ascx".ToLowerInvariant())) + throw new NotSupportedException("Legacy UserControl (.ascx) dashboards are no longer supported"); - dashboardControls.Add(dashboardControl); - } + dashboardControls.Add(dashboardControl); - tabs.Add(new Tab - { - //assign the Id to the value of the index if one was defined, then we'll use the Id to sort later - Id = tab.Value.Index == int.MaxValue ? i : tab.Value.Index, - Alias = tab.Key.ToSafeAlias(), - Label = tab.Key, - Properties = dashboardControls - }); + tabs.Add(new Tab + { + //assign the Id to the value of the index if one was defined, then we'll use the Id to sort later + Id = dashboard.Weight == int.MaxValue ? i : dashboard.Weight, + Alias = dashboard.Alias.ToSafeAlias(), + Label = dashboard.Name, + Properties = dashboardControls + }); - i++; - } + i++; } return tabs; }