Merge pull request #2612 from umbraco/temp8-U4-11284

Fixes - U4-11284 When you don't have any doc types that are variant, the tree language drop downs should not be there
This commit is contained in:
Warren Buckley
2018-05-08 10:28:54 +01:00
committed by GitHub
5 changed files with 60 additions and 23 deletions

View File

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

View File

@@ -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(

View File

@@ -7,6 +7,10 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje
var contentTypeHelperService = {
allowsVariation: function() {
return contentTypeResource.allowsVariation();
},
createIdArray: function(array) {
var newArray = [];

View File

@@ -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,25 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
if (args.key === "showSearchResults") {
$scope.showSearchResults = args.value;
}
//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();
} else {
$scope.languages = [];
init();
}
});
}
}));
// 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 +245,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) {
evts.push(eventsService.on("app.ready", function (evt, data) {
$scope.authenticated = true;
// load languages
languageResource.getAll().then(function(languages) {
}));
function loadLanguages() {
languageResource.getAll().then(function (languages) {
$scope.languages = languages;
if ($scope.languages.length > 1) {
@@ -250,7 +265,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
init();
});
}));
}
function init() {
//select the current language if set in the query string
@@ -281,7 +296,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 +303,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
}
}
$scope.selectLanguage = function(language) {
$scope.selectLanguage = function (language) {
$location.search("mculture", language.culture);
@@ -322,7 +336,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
angularHelper.executeSequentialPromises(promises);
});
});
};
//this reacts to the options item in the tree

View File

@@ -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<DocumentTypeDisplay, DocumentTypeSave, PropertyTypeBasic>(
contentTypeSave: contentTypeSave,