From f51e59492975ba2194bbfb6303ebaf55ffe442f7 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 7 Sep 2021 14:45:44 +0200 Subject: [PATCH 1/4] sets sortOrder on the converted tab based on the exiting tabs --- .../services/contenttypehelper.service.js | 5 ++- .../services/content-type-helper.spec.js | 35 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js index e8c67e0f6e..d9157093a7 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js @@ -90,6 +90,9 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje }, convertGroupToTab: function (groups, group) { + const tabs = groups.filter(group => group.type === this.TYPE_TAB).sort((a, b) => a.sortOrder - b.sortOrder); + const nextSortOrder = tabs && tabs.length > 0 ? tabs[tabs.length - 1].sortOrder + 1 : 0; + group.convertingToTab = true; group.type = this.TYPE_TAB; @@ -100,7 +103,7 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje group.alias = this.isAliasUnique(otherGroups, newAlias) ? newAlias : this.createUniqueAlias(otherGroups, newAlias); group.parentAlias = null; - + group.sortOrder = nextSortOrder; group.convertingToTab = false; }, diff --git a/src/Umbraco.Web.UI.Client/test/unit/common/services/content-type-helper.spec.js b/src/Umbraco.Web.UI.Client/test/unit/common/services/content-type-helper.spec.js index 5add5a4129..88b6d828af 100644 --- a/src/Umbraco.Web.UI.Client/test/unit/common/services/content-type-helper.spec.js +++ b/src/Umbraco.Web.UI.Client/test/unit/common/services/content-type-helper.spec.js @@ -173,13 +173,13 @@ describe('contentTypeHelper tests', function () { describe('convertGroupToTab', function () { - const groups = [ - { type: 0, alias: 'hero', name: 'Hero' }, - { type: 0, alias: 'content' }, - { type: 0, alias: 'footer' } - ]; - it('should convert group to tab', function () { + const groups = [ + { type: 0, alias: 'hero', name: 'Hero' }, + { type: 0, alias: 'content' }, + { type: 0, alias: 'footer' } + ]; + const newTab = groups[0]; contentTypeHelper.convertGroupToTab(groups, newTab); @@ -189,6 +189,29 @@ describe('contentTypeHelper tests', function () { expect(newTab.parentAlias).toBeNull(); }); + it('should set sort order to 0 if it is the first tab', function () { + const groups = [ + { type: 0, alias: 'hero', name: 'Hero' } + ]; + + const newTab = groups[0]; + contentTypeHelper.convertGroupToTab(groups, newTab); + + expect(newTab.sortOrder).toBe(0); + }); + + it('should set sort order to 1 higher than the last tab', function () { + const groups = [ + { type: 0, alias: 'settings', name: 'Settings', sortOrder: 100 }, + { type: 1, alias: 'content', name: 'Content', sortOrder: 5 } + ]; + + const newTab = groups[0]; + contentTypeHelper.convertGroupToTab(groups, newTab); + + expect(newTab.sortOrder).toBe(6); + }); + }); }); From 1fa816bd32a9d77d2d607b16151054b468ed3e48 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 8 Sep 2021 15:14:12 +0200 Subject: [PATCH 2/4] Show notification when a group can't be moved + reset requested tab --- .../directives/components/umbgroupsbuilder.directive.js | 7 ++++++- src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbgroupsbuilder.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbgroupsbuilder.directive.js index d4c8b3d300..68460f4982 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbgroupsbuilder.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbgroupsbuilder.directive.js @@ -143,6 +143,9 @@ const dropIndex = groupsInTab.findIndex(group => group.key === groupKey); updateSortOrder(groupsInTab, dropIndex); + + // when a group is dropped we need to reset the requested tab hover alias + scope.sortableRequestedTabAlias = undefined; } } }; @@ -192,7 +195,9 @@ const newAlias = contentTypeHelper.updateParentAlias(group.alias || null, hoveredTabAlias); // Check alias is unique if (group.alias !== newAlias && contentTypeHelper.isAliasUnique(scope.model.groups, newAlias) === false) { - // TODO: Missing UI indication of why you cant move here. + localizationService.localize("contentTypeEditor_groupReorderSameAliasError", [group.name, newAlias]).then((value) => { + notificationsService.error(value); + }); return; } } diff --git a/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml b/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml index ec2fd1245c..67982b0e94 100644 --- a/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml +++ b/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml @@ -1670,6 +1670,7 @@ To manage your website, simply open the Umbraco backoffice and start adding cont Compositions Group + You can't move the group %0% to this tab because the group will get the same alias as a tab: "%1%". Rename the group to continue. You have not added any groups Add group Inherited from From 05dc65ecf08fac420d707a3df07a08f7e402e764 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 8 Sep 2021 15:58:54 +0200 Subject: [PATCH 3/4] Fixes folder creation for doc, data, and media types (#11040) * fixes folder creation for doctype and datatype * add fix for media types * remove umb-auto-focus we use focus-when instead --- .../src/views/datatypes/create.html | 10 ++++++++-- .../src/views/documenttypes/create.html | 11 +++++++++-- .../src/views/mediatypes/create.html | 10 ++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/datatypes/create.html b/src/Umbraco.Web.UI.Client/src/views/datatypes/create.html index 3cfc6e0cc4..5a7859add9 100644 --- a/src/Umbraco.Web.UI.Client/src/views/datatypes/create.html +++ b/src/Umbraco.Web.UI.Client/src/views/datatypes/create.html @@ -24,13 +24,19 @@ -
+
- + diff --git a/src/Umbraco.Web.UI.Client/src/views/documenttypes/create.html b/src/Umbraco.Web.UI.Client/src/views/documenttypes/create.html index 02db433b1c..8992c73525 100644 --- a/src/Umbraco.Web.UI.Client/src/views/documenttypes/create.html +++ b/src/Umbraco.Web.UI.Client/src/views/documenttypes/create.html @@ -54,7 +54,7 @@
-
+
@@ -67,7 +67,14 @@
- + diff --git a/src/Umbraco.Web.UI.Client/src/views/mediatypes/create.html b/src/Umbraco.Web.UI.Client/src/views/mediatypes/create.html index 6f74174776..cb7bd74424 100644 --- a/src/Umbraco.Web.UI.Client/src/views/mediatypes/create.html +++ b/src/Umbraco.Web.UI.Client/src/views/mediatypes/create.html @@ -24,7 +24,7 @@
-
+
@@ -37,7 +37,13 @@
- + From 0aa545df75af6ce01775238ab8a4a05edb9790d1 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Wed, 8 Sep 2021 16:24:10 +0200 Subject: [PATCH 4/4] Update parameter order of new AddPropertyGroup overload --- src/Umbraco.Core/Models/ContentTypeBase.cs | 2 +- .../Models/ContentTypeCompositionBase.cs | 16 ++++++++-------- src/Umbraco.Core/Models/IContentTypeBase.cs | 6 +++--- .../Packaging/PackageDataInstallation.cs | 2 +- .../Services/ContentTypeServiceTests.cs | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index ea18923e68..447b3d3f33 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -302,7 +302,7 @@ namespace Umbraco.Core.Models public abstract bool AddPropertyGroup(string groupName); /// - public abstract bool AddPropertyGroup(string name, string alias); + public abstract bool AddPropertyGroup(string alias, string name); /// [Obsolete("Use AddPropertyType(propertyType, groupAlias, groupName) instead to explicitly set the alias of the group (note the slighty different parameter order).")] diff --git a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index e1c098f033..eef61abaeb 100644 --- a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -205,19 +205,19 @@ namespace Umbraco.Core.Models } /// - [Obsolete("Use AddPropertyGroup(name, alias) instead to explicitly set the alias.")] + [Obsolete("Use AddPropertyGroup(alias, name) instead to explicitly set the alias (note the slighty different parameter order).")] public override bool AddPropertyGroup(string groupName) { - return AddAndReturnPropertyGroup(groupName, groupName.ToSafeAlias(true)) != null; + return AddAndReturnPropertyGroup(groupName.ToSafeAlias(true), groupName) != null; } /// - public override bool AddPropertyGroup(string name, string alias) + public override bool AddPropertyGroup(string alias, string name) { - return AddAndReturnPropertyGroup(name, alias) != null; + return AddAndReturnPropertyGroup(alias, name) != null; } - private PropertyGroup AddAndReturnPropertyGroup(string name, string alias) + private PropertyGroup AddAndReturnPropertyGroup(string alias, string name) { // Ensure we don't have it already if (PropertyGroups.Contains(alias)) @@ -226,8 +226,8 @@ namespace Umbraco.Core.Models // Add new group var group = new PropertyGroup(SupportsPublishing) { - Name = name, - Alias = alias + Alias = alias, + Name = name }; // check if it is inherited - there might be more than 1 but we want the 1st, to @@ -273,7 +273,7 @@ namespace Umbraco.Core.Models } else if (!string.IsNullOrEmpty(groupName)) { - group = AddAndReturnPropertyGroup(groupName, groupAlias); + group = AddAndReturnPropertyGroup(groupAlias, groupName); if (group == null) return false; } else diff --git a/src/Umbraco.Core/Models/IContentTypeBase.cs b/src/Umbraco.Core/Models/IContentTypeBase.cs index 7152ccb0f9..9ba5b737dc 100644 --- a/src/Umbraco.Core/Models/IContentTypeBase.cs +++ b/src/Umbraco.Core/Models/IContentTypeBase.cs @@ -168,21 +168,21 @@ namespace Umbraco.Core.Models /// /// This method will also check if a group already exists with the same alias. /// - [Obsolete("Use AddPropertyGroup(name, alias) instead to explicitly set the alias.")] + [Obsolete("Use AddPropertyGroup(alias, name) instead to explicitly set the alias (note the slighty different parameter order).")] bool AddPropertyGroup(string groupName); /// /// Adds a property group with the specified and . /// - /// Name of the group. /// The alias. + /// Name of the group. /// /// Returns true if a property group with specified was added; otherwise, false. /// /// /// This method will also check if a group already exists with the same alias. /// - bool AddPropertyGroup(string name, string alias); + bool AddPropertyGroup(string alias, string name); /// /// Moves a PropertyType to a specified PropertyGroup diff --git a/src/Umbraco.Core/Packaging/PackageDataInstallation.cs b/src/Umbraco.Core/Packaging/PackageDataInstallation.cs index f3c1a80278..42eed2b29c 100644 --- a/src/Umbraco.Core/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Core/Packaging/PackageDataInstallation.cs @@ -750,7 +750,7 @@ namespace Umbraco.Core.Packaging alias = name.ToSafeAlias(true); } - contentType.AddPropertyGroup(name, alias); + contentType.AddPropertyGroup(alias, name); var propertyGroup = contentType.PropertyGroups[alias]; if (Guid.TryParse(propertyGroupElement.Element("Key")?.Value, out var key)) diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceTests.cs index 6d82c0db03..fb6d469fd6 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceTests.cs @@ -1325,7 +1325,7 @@ namespace Umbraco.Tests.Services Assert.AreEqual(2, meta.PropertyTypes.Count()); Assert.AreEqual("Meta Keywords", meta.PropertyTypes.First().Name); Assert.AreEqual("Meta Description", meta.PropertyTypes.Skip(1).First().Name); - meta.AddPropertyGroup("Content", "content"); + meta.AddPropertyGroup("content", "Content"); Assert.AreEqual(2, meta.PropertyTypes.Count()); service.Save(meta);