Added variantHelper for methods used in various places
(cherry picked from commit a97f8254f550b453ebd1cab91837da4f60f9aff6)
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
controller: umbVariantContentEditorsController
|
||||
};
|
||||
|
||||
function umbVariantContentEditorsController($scope, $location, $timeout) {
|
||||
function umbVariantContentEditorsController($scope, $location, $timeout, variantHelper) {
|
||||
|
||||
var prevContentDateUpdated = null;
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
vm.editors = [];
|
||||
//Used to track the open variants across the split views
|
||||
// The values are the variant ids of the currently open variants.
|
||||
// See getVariantId() for the current format.
|
||||
// See variantHelper.getId() for the current format.
|
||||
vm.openVariants = [];
|
||||
|
||||
/** Called when the component initializes */
|
||||
@@ -87,7 +87,7 @@
|
||||
// set the active variant
|
||||
var activeVariant = null;
|
||||
_.each(vm.content.variants, function (v) {
|
||||
if (getVariantId(v) === vm.variantId) {
|
||||
if (variantHelper.getId(v) === vm.variantId) {
|
||||
v.active = true;
|
||||
activeVariant = v;
|
||||
}
|
||||
@@ -107,10 +107,10 @@
|
||||
if (vm.editors.length > 1) {
|
||||
//now re-sync any other editor content (i.e. if split view is open)
|
||||
for (var s = 1; s < vm.editors.length; s++) {
|
||||
var editorVariantId = getVariantId(vm.editors[s].content);
|
||||
var editorVariantId = variantHelper.getId(vm.editors[s].content);
|
||||
//get the variant from the scope model
|
||||
var variant = _.find(vm.content.variants, function (v) {
|
||||
return getVariantId(v) === editorVariantId;
|
||||
return variantHelper.getId(v) === editorVariantId;
|
||||
});
|
||||
vm.editors[s].content = initVariant(variant, s);
|
||||
}
|
||||
@@ -125,7 +125,7 @@
|
||||
*/
|
||||
function insertVariantEditor(index, variant) {
|
||||
|
||||
var variantId = getVariantId(variant);
|
||||
var variantId = variantHelper.getId(variant);
|
||||
|
||||
//check if the variant at the index is the same, if it's null an editor will be added
|
||||
var currentVariantId = vm.editors.length === 0 || vm.editors.length <= index ? null : vm.editors[index].variantId;
|
||||
@@ -146,27 +146,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function getVariantId(variant) {
|
||||
var hasLanguage = variant.language && !!variant.language.culture;
|
||||
var hasSegment = !!variant.segment;
|
||||
|
||||
var sep = ";";
|
||||
|
||||
if (!hasLanguage && !hasSegment) {
|
||||
// Invariant
|
||||
return "";
|
||||
} else if (hasLanguage && !hasSegment) {
|
||||
// Culture only
|
||||
return variant.language.culture;
|
||||
} else if (!hasLanguage && hasSegment) {
|
||||
// Segment only
|
||||
return sep + variant.segment;
|
||||
} else {
|
||||
// Culture and Segment
|
||||
return variant.language.culture + sep + variant.segment;
|
||||
}
|
||||
}
|
||||
|
||||
function initVariant(variant, editorIndex) {
|
||||
//The model that is assigned to the editor contains the current content variant along
|
||||
//with a copy of the contentApps. This is required because each editor renders it's own
|
||||
@@ -208,7 +187,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
var variantId = getVariantId(variant);
|
||||
var variantId = variantHelper.getId(variant);
|
||||
// keep track of the open variants across the different split views
|
||||
// push the first variant then update the variant index based on the editor index
|
||||
if (vm.openVariants && vm.openVariants.length === 0) {
|
||||
@@ -247,11 +226,11 @@
|
||||
* @param {any} selectedVariant
|
||||
*/
|
||||
function openSplitView(selectedVariant) {
|
||||
var variant = getVariantId(selectedVariant);
|
||||
var variant = variantHelper.getId(selectedVariant);
|
||||
|
||||
//Find the whole variant model based on the culture that was chosen
|
||||
var variant = _.find(vm.content.variants, function (v) {
|
||||
return getVariantId(v) === variant;
|
||||
return variantHelper.getId(v) === variant;
|
||||
});
|
||||
|
||||
insertVariantEditor(vm.editors.length, initVariant(variant, vm.editors.length));
|
||||
@@ -308,7 +287,7 @@
|
||||
*/
|
||||
function selectVariant(variant, editorIndex) {
|
||||
|
||||
var variantId = getVariantId(variant);
|
||||
var variantId = variantHelper.getId(variant);
|
||||
|
||||
// prevent variants already open in a split view to be opened
|
||||
if (vm.openVariants.indexOf(variantId) !== -1) {
|
||||
@@ -335,7 +314,7 @@
|
||||
//get the variant content model and initialize the editor with that
|
||||
var contentVariant = _.find(vm.content.variants,
|
||||
function (v) {
|
||||
return getVariantId(v) === variantId;
|
||||
return variantHelper.getId(v) === variantId;
|
||||
});
|
||||
editor.content = initVariant(contentVariant, editorIndex);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function EditorContentHeader(serverValidationManager, localizationService, editorState) {
|
||||
function EditorContentHeader(serverValidationManager, localizationService, editorState, variantHelper) {
|
||||
|
||||
function link(scope, el, attr, ctrl) {
|
||||
|
||||
@@ -91,29 +91,6 @@
|
||||
|
||||
}
|
||||
|
||||
function getVariantDisplayName(variant) {
|
||||
if (variant == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var parts = [];
|
||||
|
||||
if (variant.language && variant.language.name) {
|
||||
parts.push(variant.language.name);
|
||||
}
|
||||
|
||||
if (variant.segment) {
|
||||
parts.push(variant.segment);
|
||||
}
|
||||
|
||||
if (parts.length === 0) {
|
||||
// Invariant
|
||||
parts.push("Default");
|
||||
}
|
||||
|
||||
return parts.join(" - ");
|
||||
}
|
||||
|
||||
function setCurrentVariant() {
|
||||
angular.forEach(scope.content.variants, function (variant) {
|
||||
if (variant.active) {
|
||||
@@ -123,7 +100,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
scope.getVariantDisplayName = getVariantDisplayName;
|
||||
scope.getVariantDisplayName = variantHelper.getDisplayName;
|
||||
|
||||
scope.goBack = function () {
|
||||
if (scope.onBack) {
|
||||
@@ -164,33 +141,12 @@
|
||||
}
|
||||
};
|
||||
|
||||
function getVariantId(variant) {
|
||||
var hasLanguage = variant.language && !!variant.language.culture;
|
||||
var hasSegment = !!variant.segment;
|
||||
|
||||
var sep = ";";
|
||||
|
||||
if (!hasLanguage && !hasSegment) {
|
||||
// Invariant
|
||||
return "";
|
||||
} else if (hasLanguage && !hasSegment) {
|
||||
// Culture only
|
||||
return variant.language.culture;
|
||||
} else if (!hasLanguage && hasSegment) {
|
||||
// Segment only
|
||||
return sep + variant.segment;
|
||||
} else {
|
||||
// Culture and Segment
|
||||
return variant.language.culture + sep + variant.segment;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* keep track of open variants - this is used to prevent the same variant to be open in more than one split view
|
||||
* @param {any} culture
|
||||
*/
|
||||
scope.variantIsOpen = function (variant) {
|
||||
var variantId = getVariantId(variant);
|
||||
var variantId = variantHelper.getId(variant);
|
||||
return (scope.openVariants.indexOf(variantId) !== -1);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @ngdoc service
|
||||
* @name umbraco.services.variantHelper
|
||||
* @description A helper service for dealing with variants
|
||||
**/
|
||||
function variantHelper() {
|
||||
/**
|
||||
* Returns the id for this variant
|
||||
* @param {any} variant
|
||||
*/
|
||||
function getId(variant) {
|
||||
var hasLanguage = variant.language && !!variant.language.culture;
|
||||
var hasSegment = !!variant.segment;
|
||||
|
||||
var sep = ";";
|
||||
|
||||
if (!hasLanguage && !hasSegment) {
|
||||
// Invariant
|
||||
return "";
|
||||
} else if (hasLanguage && !hasSegment) {
|
||||
// Culture only
|
||||
return variant.language.culture;
|
||||
} else if (!hasLanguage && hasSegment) {
|
||||
// Segment only
|
||||
return sep + variant.segment;
|
||||
} else {
|
||||
// Culture and Segment
|
||||
return variant.language.culture + sep + variant.segment;
|
||||
}
|
||||
}
|
||||
|
||||
function getDisplayName(variant) {
|
||||
if (variant == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var parts = [];
|
||||
|
||||
if (variant.language && variant.language.name) {
|
||||
parts.push(variant.language.name);
|
||||
}
|
||||
|
||||
if (variant.segment) {
|
||||
parts.push(variant.segment);
|
||||
}
|
||||
|
||||
if (parts.length === 0) {
|
||||
// Invariant
|
||||
parts.push("Default");
|
||||
}
|
||||
|
||||
return parts.join(" - ");
|
||||
}
|
||||
|
||||
return {
|
||||
getId,
|
||||
getDisplayName
|
||||
}
|
||||
}
|
||||
angular.module('umbraco.services').factory('variantHelper', variantHelper);
|
||||
@@ -1,7 +1,7 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function PublishController($scope, localizationService, contentEditingHelper) {
|
||||
function PublishController($scope, localizationService, contentEditingHelper, variantHelper) {
|
||||
|
||||
var vm = this;
|
||||
vm.loading = true;
|
||||
@@ -12,31 +12,7 @@
|
||||
vm.dirtyVariantFilter = dirtyVariantFilter;
|
||||
vm.pristineVariantFilter = pristineVariantFilter;
|
||||
|
||||
$scope.getVariantDisplayName = getVariantDisplayName;
|
||||
|
||||
// TODO: Move to some variantService / helper
|
||||
function getVariantDisplayName(variant) {
|
||||
if (variant == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var parts = [];
|
||||
|
||||
if (variant.language && variant.language.name) {
|
||||
parts.push(variant.language.name);
|
||||
}
|
||||
|
||||
if (variant.segment) {
|
||||
parts.push(variant.segment);
|
||||
}
|
||||
|
||||
if (parts.length === 0) {
|
||||
// Invariant
|
||||
parts.push("Default");
|
||||
}
|
||||
|
||||
return parts.join(" - ");
|
||||
}
|
||||
$scope.getVariantDisplayName = variantHelper.getDisplayName;
|
||||
|
||||
/** Returns true if publishing is possible based on if there are un-published mandatory languages */
|
||||
function canPublish() {
|
||||
|
||||
Reference in New Issue
Block a user