Allow for changing the weight of built-in and 3rd party dashboards (#8628)

This commit is contained in:
Kenn Jacobsen
2020-08-19 15:41:48 +02:00
committed by GitHub
parent 0140d906a5
commit f9c41f99e3

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
@@ -9,8 +10,22 @@ namespace Umbraco.Web.Dashboards
{
public class DashboardCollectionBuilder : WeightedCollectionBuilderBase<DashboardCollectionBuilder, DashboardCollection, IDashboard>
{
private Dictionary<Type, int> _customWeights = new Dictionary<Type, int>();
protected override DashboardCollectionBuilder This => this;
/// <summary>
/// Changes the default weight of a dashboard
/// </summary>
/// <typeparam name="T">The type of dashboard</typeparam>
/// <param name="weight">The new dashboard weight</param>
/// <returns></returns>
public DashboardCollectionBuilder SetWeight<T>(int weight) where T : IDashboard
{
_customWeights[typeof(T)] = weight;
return this;
}
protected override IEnumerable<IDashboard> CreateItems(IFactory factory)
{
// get the manifest parser just-in-time - injecting it in the ctor would mean that
@@ -32,6 +47,12 @@ namespace Umbraco.Web.Dashboards
private int GetWeight(IDashboard dashboard)
{
var typeOfDashboard = dashboard.GetType();
if(_customWeights.ContainsKey(typeOfDashboard))
{
return _customWeights[typeOfDashboard];
}
switch (dashboard)
{
case ManifestDashboard manifestDashboardDefinition: