Adds new end point that returns true/false if current document types allows variations, display language dropdown if current content types allow variations.

This commit is contained in:
Robert
2018-05-03 10:18:08 +02:00
parent 64d467e071
commit f447294c0b
4 changed files with 55 additions and 23 deletions
@@ -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(
@@ -7,6 +7,10 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje
var contentTypeHelperService = {
allowsVariation: function() {
return contentTypeResource.allowsVariation();
},
createIdArray: function(array) {
var newArray = [];
@@ -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
@@ -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,