Refactor package.manifest dashboards JSON structure

This commit is contained in:
Warren Buckley
2018-12-03 14:26:16 +00:00
parent 8b5eb1f0a4
commit b361d1c950
8 changed files with 47 additions and 99 deletions

View File

@@ -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; }
}
}

View File

@@ -3,18 +3,31 @@ using Newtonsoft.Json;
namespace Umbraco.Core.Manifest
{
public class ManifestDashboardSection
public class ManifestDashboard
{
public ManifestDashboardSection()
public ManifestDashboard()
{
Areas = new List<string>();
Tabs = new Dictionary<string, ManifestDashboardTab>();
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<string>();
}
[JsonProperty("areas")]
public List<string> Areas { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("tabs")]
public IDictionary<string, ManifestDashboardTab> 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<string> Sections { get; set; }
}
}
}

View File

@@ -1,20 +0,0 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Umbraco.Core.Manifest
{
public class ManifestDashboardTab
{
public ManifestDashboardTab()
{
Controls = new List<ManifestDashboardControl>();
Index = int.MaxValue; //default so we can check if this value has been explicitly set
}
[JsonProperty("controls")]
public List<ManifestDashboardControl> Controls { get; set; }
[JsonProperty("index")]
public int Index { get; set; }
}
}

View File

@@ -100,7 +100,7 @@ namespace Umbraco.Core.Manifest
var parameterEditors = new List<IDataEditor>();
var gridEditors = new List<GridEditor>();
var contentApps = new List<IContentAppDefinition>();
var dashboards = new Dictionary<string, ManifestDashboardSection>();
var dashboards = new List<ManifestDashboard>();
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()
};
}

View File

@@ -34,7 +34,7 @@ namespace Umbraco.Core.Manifest
/// The dictionary of dashboards
/// </summary>
[JsonProperty("dashboards")]
public IReadOnlyDictionary<string, ManifestDashboardSection> Dashboards { get; set; } = new Dictionary<string, ManifestDashboardSection>();
public ManifestDashboard[] Dashboards { get; set; } = Array.Empty<ManifestDashboard>();
}

View File

@@ -335,9 +335,7 @@
<Compile Include="Logging\Serilog\Enrichers\Log4NetLevelMapperEnricher.cs" />
<Compile Include="Manifest\ContentAppDefinitionConverter.cs" />
<Compile Include="Manifest\ManifestContentAppDefinition.cs" />
<Compile Include="Manifest\ManifestDashboardControl.cs" />
<Compile Include="Manifest\ManifestDashboardSection.cs" />
<Compile Include="Manifest\ManifestDashboardTab.cs" />
<Compile Include="Migrations\IncompleteMigrationExpressionException.cs" />
<Compile Include="Migrations\MigrationBase_Extra.cs" />
<Compile Include="Migrations\Upgrade\V_7_10_0\RenamePreviewFolder.cs" />

View File

@@ -194,6 +194,8 @@
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.controller.js" />
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.htm" />
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.resource.js" />
<Content Include="App_Plugins\Test\two.html" />
<Content Include="App_Plugins\Test\one.html" />
<Content Include="Config\grid.editors.config.js" />
<Content Include="Config\Lang\cs-CZ.user.xml" />
<Content Include="Config\Lang\da-DK.user.xml" />
@@ -231,6 +233,7 @@
<Content Include="Config\Splashes\noNodes.aspx" />
<Content Include="Umbraco\Install\Views\Web.config" />
<Content Include="App_Plugins\ModelsBuilder\package.manifest" />
<Content Include="App_Plugins\Test\package.manifest" />
<None Include="Config\404handlers.Release.config">
<DependentUpon>404handlers.config</DependentUpon>
</None>

View File

@@ -145,35 +145,30 @@ namespace Umbraco.Web.Editors
var tabs = new List<Tab<DashboardControl>>();
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<DashboardControl>();
var view = dashboard.View.Trim();
var dashboardControl = new DashboardControl
{
var dashboardControls = new List<DashboardControl>();
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<DashboardControl>
{
//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<DashboardControl>
{
//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;
}