Skip to content

Commit

Permalink
Merge pull request #10606 from umbraco/v8/feature/reintroduce-tabs
Browse files Browse the repository at this point in the history
Reintroduce tabs
  • Loading branch information
Warren Buckley authored Aug 31, 2021
2 parents b9ca313 + c29383d commit 4c9d773
Show file tree
Hide file tree
Showing 93 changed files with 3,541 additions and 1,099 deletions.
40 changes: 34 additions & 6 deletions src/Umbraco.Core/Exceptions/InvalidCompositionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public class InvalidCompositionException : Exception
/// </value>
public string[] PropertyTypeAliases { get; }

/// <summary>
/// Gets the property group aliases.
/// </summary>
/// <value>
/// The property group aliases.
/// </value>
public string[] PropertyGroupAliases { get; }

/// <summary>
/// Initializes a new instance of the <see cref="InvalidCompositionException" /> class.
/// </summary>
Expand All @@ -56,7 +64,29 @@ public InvalidCompositionException(string contentTypeAlias, string[] propertyTyp
/// <param name="addedCompositionAlias">The added composition alias.</param>
/// <param name="propertyTypeAliases">The property type aliases.</param>
public InvalidCompositionException(string contentTypeAlias, string addedCompositionAlias, string[] propertyTypeAliases)
: this(addedCompositionAlias.IsNullOrWhiteSpace()
: this(contentTypeAlias, addedCompositionAlias, propertyTypeAliases, new string[0])
{ }

/// <summary>
/// Initializes a new instance of the <see cref="InvalidCompositionException" /> class.
/// </summary>
/// <param name="contentTypeAlias">The content type alias.</param>
/// <param name="addedCompositionAlias">The added composition alias.</param>
/// <param name="propertyTypeAliases">The property type aliases.</param>
/// <param name="propertyGroupAliases">The property group aliases.</param>
public InvalidCompositionException(string contentTypeAlias, string addedCompositionAlias, string[] propertyTypeAliases, string[] propertyGroupAliases)
: this(FormatMessage(contentTypeAlias, addedCompositionAlias, propertyTypeAliases, propertyGroupAliases))
{
ContentTypeAlias = contentTypeAlias;
AddedCompositionAlias = addedCompositionAlias;
PropertyTypeAliases = propertyTypeAliases;
PropertyGroupAliases = propertyGroupAliases;
}

private static string FormatMessage(string contentTypeAlias, string addedCompositionAlias, string[] propertyTypeAliases, string[] propertyGroupAliases)
{
// TODO Add property group aliases to message
return addedCompositionAlias.IsNullOrWhiteSpace()
? string.Format(
"ContentType with alias '{0}' has an invalid composition " +
"and there was a conflict on the following PropertyTypes: '{1}'. " +
Expand All @@ -66,11 +96,7 @@ public InvalidCompositionException(string contentTypeAlias, string addedComposit
"ContentType with alias '{0}' was added as a Composition to ContentType with alias '{1}', " +
"but there was a conflict on the following PropertyTypes: '{2}'. " +
"PropertyTypes must have a unique alias across all Compositions in order to compose a valid ContentType Composition.",
addedCompositionAlias, contentTypeAlias, string.Join(", ", propertyTypeAliases)))
{
ContentTypeAlias = contentTypeAlias;
AddedCompositionAlias = addedCompositionAlias;
PropertyTypeAliases = propertyTypeAliases;
addedCompositionAlias, contentTypeAlias, string.Join(", ", propertyTypeAliases));
}

/// <summary>
Expand Down Expand Up @@ -101,6 +127,7 @@ protected InvalidCompositionException(SerializationInfo info, StreamingContext c
ContentTypeAlias = info.GetString(nameof(ContentTypeAlias));
AddedCompositionAlias = info.GetString(nameof(AddedCompositionAlias));
PropertyTypeAliases = (string[])info.GetValue(nameof(PropertyTypeAliases), typeof(string[]));
PropertyGroupAliases = (string[])info.GetValue(nameof(PropertyGroupAliases), typeof(string[]));
}

/// <summary>
Expand All @@ -119,6 +146,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
info.AddValue(nameof(ContentTypeAlias), ContentTypeAlias);
info.AddValue(nameof(AddedCompositionAlias), AddedCompositionAlias);
info.AddValue(nameof(PropertyTypeAliases), PropertyTypeAliases);
info.AddValue(nameof(PropertyGroupAliases), PropertyGroupAliases);

base.GetObjectData(info, context);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Umbraco.Core/Migrations/Install/DatabaseDataCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ private void CreateUserGroup2AppData()

private void CreatePropertyTypeGroupData()
{
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 3, ContentTypeNodeId = 1032, Text = "Image", SortOrder = 1, UniqueId = new Guid(Constants.PropertyTypeGroups.Image) });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 4, ContentTypeNodeId = 1033, Text = "File", SortOrder = 1, UniqueId = new Guid(Constants.PropertyTypeGroups.File) });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 52, ContentTypeNodeId = 1034, Text = "Video", SortOrder = 1, UniqueId = new Guid(Constants.PropertyTypeGroups.Video) });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 53, ContentTypeNodeId = 1035, Text = "Audio", SortOrder = 1, UniqueId = new Guid(Constants.PropertyTypeGroups.Audio) });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 54, ContentTypeNodeId = 1036, Text = "Article", SortOrder = 1, UniqueId = new Guid(Constants.PropertyTypeGroups.Article) });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 55, ContentTypeNodeId = 1037, Text = "Vector Graphics", SortOrder = 1, UniqueId = new Guid(Constants.PropertyTypeGroups.VectorGraphics) });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 3, UniqueId = new Guid(Constants.PropertyTypeGroups.Image), ContentTypeNodeId = 1032, Text = "Image", Alias = "image", SortOrder = 1 });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 4, UniqueId = new Guid(Constants.PropertyTypeGroups.File), ContentTypeNodeId = 1033, Text = "File", Alias = "file", SortOrder = 1, });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 52, UniqueId = new Guid(Constants.PropertyTypeGroups.Video), ContentTypeNodeId = 1034, Text = "Video", Alias = "video", SortOrder = 1 });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 53, UniqueId = new Guid(Constants.PropertyTypeGroups.Audio), ContentTypeNodeId = 1035, Text = "Audio", Alias = "audio", SortOrder = 1 });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 54, UniqueId = new Guid(Constants.PropertyTypeGroups.Article), ContentTypeNodeId = 1036, Text = "Article", Alias = "article", SortOrder = 1 });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 55, UniqueId = new Guid(Constants.PropertyTypeGroups.VectorGraphics), ContentTypeNodeId = 1037, Text = "Vector Graphics", Alias = "vectorGraphics", SortOrder = 1 });
//membership property group
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 11, ContentTypeNodeId = 1044, Text = "Membership", SortOrder = 1, UniqueId = new Guid(Constants.PropertyTypeGroups.Membership) });
_database.Insert(Constants.DatabaseSchema.Tables.PropertyTypeGroup, "id", false, new PropertyTypeGroupDto { Id = 11, UniqueId = new Guid(Constants.PropertyTypeGroups.Membership), ContentTypeNodeId = 1044, Text = "Membership", Alias = "membership", SortOrder = 1 });
}

private void CreatePropertyTypeData()
Expand Down
10 changes: 6 additions & 4 deletions src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Umbraco.Core.Migrations.Upgrade.V_8_9_0;
using Umbraco.Core.Migrations.Upgrade.V_8_10_0;
using Umbraco.Core.Migrations.Upgrade.V_8_15_0;
using Umbraco.Core.Migrations.Upgrade.V_8_17_0;

namespace Umbraco.Core.Migrations.Upgrade
{
Expand Down Expand Up @@ -119,7 +120,6 @@ protected void DefinePlan()


// plan starts at 7.14.0 (anything before 7.14.0 is not supported)
//
From(GetInitState(new SemVersion(7, 14, 0)));

// begin migrating from v7 - remove all keys and indexes
Expand Down Expand Up @@ -174,13 +174,12 @@ protected void DefinePlan()
// finish migrating from v7 - recreate all keys and indexes
To<CreateKeysAndIndexes>("{3F9764F5-73D0-4D45-8804-1240A66E43A2}");

// to 8.0.0
To<RenameLabelAndRichTextPropertyEditorAliases>("{E0CBE54D-A84F-4A8F-9B13-900945FD7ED9}");
To<MergeDateAndDateTimePropertyEditor>("{78BAF571-90D0-4D28-8175-EF96316DA789}");
// release-8.0.0

// to 8.0.1
To<ChangeNuCacheJsonFormat>("{80C0A0CB-0DD5-4573-B000-C4B7C313C70D}");
// release-8.0.1

// to 8.1.0
To<ConvertTinyMceAndGridMediaUrlsToLocalLink>("{B69B6E8C-A769-4044-A27E-4A4E18D1645A}");
Expand All @@ -203,11 +202,14 @@ protected void DefinePlan()
// to 8.10.0
To<AddPropertyTypeLabelOnTopColumn>("{D6A8D863-38EC-44FB-91EC-ACD6A668BD18}");

// to 8.15.0...
// to 8.15.0
To<AddCmsContentNuByteColumn>("{8DDDCD0B-D7D5-4C97-BD6A-6B38CA65752F}");
To<UpgradedIncludeIndexes>("{4695D0C9-0729-4976-985B-048D503665D8}");
To<UpdateCmsPropertyGroupIdSeed>("{5C424554-A32D-4852-8ED1-A13508187901}");

// to 8.17.0
To<AddPropertyTypeGroupColumns>("{153865E9-7332-4C2A-9F9D-F20AEE078EC7}");

//FINAL
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.Dtos;

namespace Umbraco.Core.Migrations.Upgrade.V_8_17_0
{
public class AddPropertyTypeGroupColumns : MigrationBase
{
public AddPropertyTypeGroupColumns(IMigrationContext context)
: base(context)
{ }

public override void Migrate()
{
AddColumn<PropertyTypeGroupDto>("type");

// Add column without constraints
AddColumn<PropertyTypeGroupDto>("alias", out var sqls);

// Populate non-null alias column
var dtos = Database.Fetch<PropertyTypeGroupDto>();
foreach (var dto in PopulateAliases(dtos))
Database.Update(dto, x => new { x.Alias });

// Finally add the constraints
foreach (var sql in sqls)
Database.Execute(sql);
}

internal IEnumerable<PropertyTypeGroupDto> PopulateAliases(IEnumerable<PropertyTypeGroupDto> dtos)
{
foreach (var dtosPerAlias in dtos.GroupBy(x => x.Text.ToSafeAlias(true)))
{
var dtosPerAliasAndText = dtosPerAlias.GroupBy(x => x.Text);
var numberSuffix = 1;
foreach (var dtosPerText in dtosPerAliasAndText)
{
foreach (var dto in dtosPerText)
{
dto.Alias = dtosPerAlias.Key;

if (numberSuffix > 1)
{
// More than 1 name found for the alias, so add a suffix
dto.Alias += numberSuffix;
}

yield return dto;
}

numberSuffix++;
}

if (numberSuffix > 2)
{
Logger.Error<AddPropertyTypeGroupColumns>("Detected the same alias {Alias} for different property group names {Names}, the migration added suffixes, but this might break backwards compatibility.", dtosPerAlias.Key, dtosPerAliasAndText.Select(x => x.Key));
}
}
}
}
}
44 changes: 23 additions & 21 deletions src/Umbraco.Core/Models/ContentTypeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,20 @@ private set
/// <returns>Returns <c>True</c> if a PropertyType with the passed in alias exists, otherwise <c>False</c></returns>
public abstract bool PropertyTypeExists(string propertyTypeAlias);

/// <summary>
/// Adds a PropertyGroup.
/// This method will also check if a group already exists with the same name and link it to the parent.
/// </summary>
/// <param name="groupName">Name of the PropertyGroup to add</param>
/// <returns>Returns <c>True</c> if a PropertyGroup with the passed in name was added, otherwise <c>False</c></returns>
/// <inheritdoc />
[Obsolete("Use AddPropertyGroup(name, alias) instead to explicitly set the alias.")]
public abstract bool AddPropertyGroup(string groupName);

/// <summary>
/// Adds a PropertyType to a specific PropertyGroup
/// </summary>
/// <param name="propertyType"><see cref="PropertyType"/> to add</param>
/// <param name="propertyGroupName">Name of the PropertyGroup to add the PropertyType to</param>
/// <returns>Returns <c>True</c> if PropertyType was added, otherwise <c>False</c></returns>
/// <inheritdoc />
public abstract bool AddPropertyGroup(string name, string alias);

/// <inheritdoc />
[Obsolete("Use AddPropertyType(propertyType, groupAlias, groupName) instead to explicitly set the alias of the group (note the slighty different parameter order).")]
public abstract bool AddPropertyType(PropertyType propertyType, string propertyGroupName);

/// <inheritdoc />
public abstract bool AddPropertyType(PropertyType propertyType, string groupAlias, string groupName);

/// <summary>
/// Adds a PropertyType, which does not belong to a PropertyGroup.
/// </summary>
Expand All @@ -339,18 +337,20 @@ public bool AddPropertyType(PropertyType propertyType)
/// "generic properties" ie does not have a tab anymore.</remarks>
public bool MovePropertyType(string propertyTypeAlias, string propertyGroupName)
{
// note: not dealing with alias casing at all here?

// get property, ensure it exists
var propertyType = PropertyTypes.FirstOrDefault(x => x.Alias == propertyTypeAlias);
if (propertyType == null) return false;

// get new group, if required, and ensure it exists
var newPropertyGroup = propertyGroupName == null
? null
: PropertyGroups.FirstOrDefault(x => x.Name == propertyGroupName);
if (propertyGroupName != null && newPropertyGroup == null) return false;
PropertyGroup newPropertyGroup = null;
if (propertyGroupName != null)
{
var index = PropertyGroups.IndexOfKey(propertyGroupName);
if (index == -1) return false;

newPropertyGroup = PropertyGroups[index];
}

// get old group
var oldPropertyGroup = PropertyGroups.FirstOrDefault(x =>
x.PropertyTypes.Any(y => y.Alias == propertyTypeAlias));
Expand Down Expand Up @@ -403,11 +403,13 @@ public void RemovePropertyType(string propertyTypeAlias)
public void RemovePropertyGroup(string propertyGroupName)
{
// if no group exists with that name, do nothing
var group = PropertyGroups[propertyGroupName];
if (group == null) return;
var index = PropertyGroups.IndexOfKey(propertyGroupName);
if (index == -1) return;

var group = PropertyGroups[index];

// first remove the group
PropertyGroups.RemoveItem(propertyGroupName);
PropertyGroups.Remove(group);

// Then re-assign the group's properties to no group
foreach (var property in group.PropertyTypes)
Expand Down
Loading

0 comments on commit 4c9d773

Please sign in to comment.