From f447294c0ba3d0c424b4cb0cf8a1db1925654785 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 3 May 2018 10:18:08 +0200 Subject: [PATCH 1/4] Adds new end point that returns true/false if current document types allows variations, display language dropdown if current content types allow variations. --- .../common/resources/contenttype.resource.js | 9 +++++ .../services/contenttypehelper.service.js | 4 +++ .../src/controllers/navigation.controller.js | 36 ++++++++++++------- .../Editors/ContentTypeController.cs | 29 +++++++++------ 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js index 8bfcdfcc5a..2b0fd341d3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js @@ -166,6 +166,15 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { 'Failed to retrieve all content types'); }, + allowsVariation: function() { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "AllowsVariation")), + 'Failed to retrieve variant content types'); + }, + getScaffold: function (parentId) { return umbRequestHelper.resourcePromise( 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 5c3e6eb4c8..034f2c5a3a 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 @@ -7,6 +7,10 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje var contentTypeHelperService = { + allowsVariation: function() { + return contentTypeResource.allowsVariation(); + }, + createIdArray: function(array) { var newArray = []; diff --git a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js index 00458aa6b4..07fd546a25 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js @@ -9,7 +9,7 @@ * * @param {navigationService} navigationService A reference to the navigationService */ -function NavigationController($scope, $rootScope, $location, $log, $q, $routeParams, $timeout, treeService, appState, navigationService, keyboardService, dialogService, historyService, eventsService, sectionResource, angularHelper, languageResource) { +function NavigationController($scope, $rootScope, $location, $log, $q, $routeParams, $timeout, treeService, appState, navigationService, keyboardService, dialogService, historyService, eventsService, sectionResource, angularHelper, languageResource, contentTypeHelper) { $scope.treeApi = {}; @@ -201,11 +201,23 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar if (args.key === "showSearchResults") { $scope.showSearchResults = args.value; } + + $scope.authenticated = true; + + //load languages if doc types allow variations + if ($scope.currentSection === "content") { + contentTypeHelper.allowsVariation().then(function (b) { + if (b === "true") { + //load languages if there are more than 1 + loadLanguages(); + } + }); + } })); // Listen for language updates - evts.push(eventsService.on("editors.languages.languageDeleted", function(e, args) { - languageResource.getAll().then(function(languages) { + evts.push(eventsService.on("editors.languages.languageDeleted", function (e, args) { + languageResource.getAll().then(function (languages) { $scope.languages = languages; }); })); @@ -231,11 +243,12 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar })); //when the application is ready and the user is authorized setup the data - evts.push(eventsService.on("app.ready", function(evt, data) { - $scope.authenticated = true; - - // load languages - languageResource.getAll().then(function(languages) { + evts.push(eventsService.on("app.ready", function (evt, data) { + })); + + function loadLanguages() { + languageResource.getAll().then(function (languages) { + $scope.languages = languages; $scope.languages = languages; if ($scope.languages.length > 1) { @@ -250,7 +263,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar init(); }); - })); + } function init() { //select the current language if set in the query string @@ -281,7 +294,6 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar } } - function nodeExpandedHandler(args) { //store the reference to the expanded node path if (args.node) { @@ -289,7 +301,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar } } - $scope.selectLanguage = function(language) { + $scope.selectLanguage = function (language) { $location.search("mculture", language.culture); @@ -322,7 +334,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar angularHelper.executeSequentialPromises(promises); }); }); - + }; //this reacts to the options item in the tree diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 5ffe68afaa..04065e82ce 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -14,6 +14,7 @@ using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Filters; using Umbraco.Core.Logging; using Umbraco.Web.Composing; +using ContentVariation = Umbraco.Core.Models.ContentVariation; namespace Umbraco.Web.Editors { @@ -34,6 +35,12 @@ namespace Umbraco.Web.Editors { return Services.ContentTypeService.Count(); } + [HttpGet] + public bool AllowsVariation() + { + var contentTypes = Services.ContentTypeService.GetAll(); + return contentTypes.Any(contentType => contentType.Variations.HasFlag(ContentVariation.CultureNeutral)); + } public DocumentTypeDisplay GetById(int id) { @@ -169,17 +176,17 @@ namespace Umbraco.Web.Editors } public DocumentTypeDisplay PostSave(DocumentTypeSave contentTypeSave) - { - //Before we send this model into this saving/mapping pipeline, we need to do some cleanup on variations. - //If the doc type does not allow content variations, we need to update all of it's property types to not allow this either - //else we may end up with ysods. I'm unsure if the service level handles this but we'll make sure it is updated here - if (!contentTypeSave.AllowCultureVariant) - { - foreach(var prop in contentTypeSave.Groups.SelectMany(x => x.Properties)) - { - prop.AllowCultureVariant = false; - } - } + { + //Before we send this model into this saving/mapping pipeline, we need to do some cleanup on variations. + //If the doc type does not allow content variations, we need to update all of it's property types to not allow this either + //else we may end up with ysods. I'm unsure if the service level handles this but we'll make sure it is updated here + if (!contentTypeSave.AllowCultureVariant) + { + foreach(var prop in contentTypeSave.Groups.SelectMany(x => x.Properties)) + { + prop.AllowCultureVariant = false; + } + } var savedCt = PerformPostSave( contentTypeSave: contentTypeSave, From b5ec7758338a29f1a4f92a91cd92bd0df6dc5b55 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 3 May 2018 10:35:23 +0200 Subject: [PATCH 2/4] Removed duplicate code and fixed bug where dropdown would not go away when there were no document types that allowed variations --- .../src/controllers/navigation.controller.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js index 07fd546a25..926489ac2a 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js @@ -210,7 +210,11 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar if (b === "true") { //load languages if there are more than 1 loadLanguages(); + } else { + $scope.languages = []; + init(); } + }); } })); @@ -249,7 +253,6 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar function loadLanguages() { languageResource.getAll().then(function (languages) { $scope.languages = languages; - $scope.languages = languages; if ($scope.languages.length > 1) { var defaultLang = _.find($scope.languages, function (l) { From 8a9caad23d8a55eddb1d54a33359933b41203c20 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 3 May 2018 13:14:19 +0200 Subject: [PATCH 3/4] Small fix to editors that had no config values defined. --- src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs index 58fde70467..e13419f0d6 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs @@ -73,7 +73,10 @@ namespace Umbraco.Core.PropertyEditors // but only keep entries that have a non-null/empty value // rest will fall back to default during ToConfigurationEditor() - var keys = editorValues.Where(x => x.Value == null || x.Value is string stringValue && string.IsNullOrWhiteSpace(stringValue)).Select(x => x.Key); + var keys = editorValues.Where(x => + x.Value == null || x.Value is string stringValue && string.IsNullOrWhiteSpace(stringValue)) + .Select(x => x.Key).ToList(); + foreach (var key in keys) editorValues.Remove(key); return editorValues; From 70e4ea55023488553055d1f5e18ddfa1a18707c1 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 8 May 2018 10:46:09 +0200 Subject: [PATCH 4/4] Moved authenticated flag back to "app.ready" listener --- .../src/controllers/navigation.controller.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js index 926489ac2a..da0d26cd33 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js @@ -202,8 +202,6 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar $scope.showSearchResults = args.value; } - $scope.authenticated = true; - //load languages if doc types allow variations if ($scope.currentSection === "content") { contentTypeHelper.allowsVariation().then(function (b) { @@ -248,6 +246,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar //when the application is ready and the user is authorized setup the data evts.push(eventsService.on("app.ready", function (evt, data) { + $scope.authenticated = true; })); function loadLanguages() {