fixes sort of variants problem

This commit is contained in:
Niels Lyngsø
2020-04-29 14:21:44 +02:00
parent 7f42974bc2
commit ea2f8fe71f
15 changed files with 56 additions and 64 deletions

View File

@@ -143,8 +143,8 @@
}
/** Returns true if the content item varies by culture */
function isContentCultureVariant() {
return $scope.content.variants.length > 1;
function hasVariants(content) {
return content.variants.length > 1;
}
function reload() {
@@ -216,6 +216,11 @@
return $scope.getMethod()($scope.contentId)
.then(function (data) {
data.variants.forEach((variant) => {
variant.compositeId = contentEditingHelper.buildCompositeVariantId(variant);
variant.htmlId = "_content_variant_" + variant.compositeId;
});
$scope.content = data;
init();
@@ -581,7 +586,7 @@
$scope.sendToPublish = function () {
clearNotifications($scope.content);
if (isContentCultureVariant()) {
if (hasVariants($scope.content)) {
//before we launch the dialog we want to execute all client side validations first
if (formHelper.submitForm({ scope: $scope, action: "publish" })) {
@@ -641,7 +646,7 @@
$scope.saveAndPublish = function () {
clearNotifications($scope.content);
if (isContentCultureVariant()) {
if (hasVariants($scope.content)) {
//before we launch the dialog we want to execute all client side validations first
if (formHelper.submitForm({ scope: $scope, action: "publish" })) {
var dialog = {
@@ -703,7 +708,7 @@
$scope.save = function () {
clearNotifications($scope.content);
// TODO: Add "..." to save button label if there are more than one variant to publish - currently it just adds the elipses if there's more than 1 variant
if (isContentCultureVariant()) {
if (hasVariants($scope.content)) {
//before we launch the dialog we want to execute all client side validations first
if (formHelper.submitForm({ scope: $scope, action: "openSaveDialog" })) {
@@ -768,7 +773,7 @@
clearNotifications($scope.content);
//before we launch the dialog we want to execute all client side validations first
if (formHelper.submitForm({ scope: $scope, action: "schedule" })) {
if (!isContentCultureVariant()) {
if (!hasVariants($scope.content)) {
//ensure the flags are set
$scope.content.variants[0].save = true;
}
@@ -805,7 +810,7 @@
}, function (err) {
clearDirtyState($scope.content.variants);
//if this is invariant, show the notification errors, else they'll be shown inline with the variant
if (!isContentCultureVariant()) {
if (!hasVariants($scope.content)) {
formHelper.showNotifications(err.data);
}
model.submitButtonState = "error";
@@ -832,7 +837,7 @@
//before we launch the dialog we want to execute all client side validations first
if (formHelper.submitForm({ scope: $scope, action: "publishDescendants" })) {
if (!isContentCultureVariant()) {
if (!hasVariants($scope.content)) {
//ensure the flags are set
$scope.content.variants[0].save = true;
$scope.content.variants[0].publish = true;
@@ -865,7 +870,7 @@
}, function (err) {
clearDirtyState($scope.content.variants);
//if this is invariant, show the notification errors, else they'll be shown inline with the variant
if (!isContentCultureVariant()) {
if (!hasVariants($scope.content)) {
formHelper.showNotifications(err.data);
}
model.submitButtonState = "error";

View File

@@ -20,7 +20,7 @@
controller: umbVariantContentEditorsController
};
function umbVariantContentEditorsController($scope, $location) {
function umbVariantContentEditorsController($scope, $location, contentEditingHelper) {
var prevContentDateUpdated = null;
@@ -59,8 +59,7 @@
if (changes.culture && !changes.culture.isFirstChange() && changes.culture.currentValue !== changes.culture.previousValue) {
setActiveVariant();
}
if (changes.segment && !changes.segment.isFirstChange() && changes.segment.currentValue !== changes.segment.previousValue) {
} else if (changes.segment && !changes.segment.isFirstChange() && changes.segment.currentValue !== changes.segment.previousValue) {
setActiveVariant();
}
}
@@ -86,7 +85,7 @@
// set the active variant
var activeVariant = null;
_.each(vm.content.variants, function (v) {
if ((!v.language || v.language.culture === vm.culture) && v.segment === vm.segment) {
if ((vm.culture === "invariant" || v.language && v.language.culture === vm.culture) && v.segment === vm.segment) {
activeVariant = v;
}
});
@@ -119,6 +118,10 @@
function insertVariantEditor(index, variant) {
if (vm.editors[index]) {
if (vm.editors[index].content === variant) {
console.error("This editor is already in this place.");
return;
}
vm.editors[index].content.active = false;
}
variant.active = true;
@@ -126,28 +129,27 @@
var variantCulture = variant.language ? variant.language.culture : "invariant";
var variantSegment = variant.segment;
//check if the culture at the index is the same, if it's null an editor will be added
var currentCulture = vm.editors.length === 0 || vm.editors.length <= index ? null : vm.editors[index].culture;
//check if the segment at the index is the same, if it's null an editor will be added
var currentSegment = vm.editors.length === 0 || vm.editors.length <= index ? null : vm.editors[index].segment;
var currentCulture = index < vm.editors.length ? vm.editors[index].culture : null;
var currentSegment = index < vm.editors.length ? vm.editors[index].segment : null;
if (currentCulture !== variantCulture || currentSegment !== variantSegment) {
// if index not already exists or if the culture or segment isnt identical then we do a replacement.
if (index >= vm.editors.length || currentCulture !== variantCulture || currentSegment !== variantSegment) {
//Not the current culture which means we need to modify the array.
//Not the current culture or segment which means we need to modify the array.
//NOTE: It is not good enough to just replace the `content` object at a given index in the array
// since that would mean that directives are not re-initialized.
vm.editors.splice(index, 1, {
compositeId: variant.compositeId,
content: variant,
//used for "track-by" ng-repeat
culture: variantCulture,
segment: variantSegment
});
}
else {
//replace the editor for the same culture
//replace the content of the editor, since the cultura and segment is the same.
vm.editors[index].content = variant;
}
}
/**

View File

@@ -330,7 +330,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt
* Returns a id for the variant that is unique between all variants on the content
*/
buildCompositeVariantId: function (variant) {
return (variant.language ? variant.language.culture : "invariant") + "_" + (variant.segment ? variant.segment : "");
return (variant.language ? variant.language.culture : "invariant") + "." + (variant.segment ? variant.segment : "");
},

View File

@@ -1,6 +1,6 @@
<div class="umb-split-views">
<div class="umb-split-view"
ng-repeat="editor in vm.editors track by editor.culture+'.'+editor.segment">
ng-repeat="editor in vm.editors track by editor.compositeId">
<umb-variant-content
page="vm.page"

View File

@@ -112,8 +112,6 @@
});
_.each(vm.variants, (variant) => {
variant.compositeId = contentEditingHelper.buildCompositeVariantId(variant);
variant.htmlId = "_content_variant_" + variant.compositeId;
// if this is a new node and we have data on this variant.
if(vm.isNew === true && hasAnyDataFilter(variant)) {
@@ -133,7 +131,7 @@
});
if (vm.availableVariants.length !== 0) {
vm.availableVariants = vm.availableVariants.sort(function (a, b) {
vm.availableVariants.sort(function (a, b) {
if (a.language && b.language) {
if (a.language.name > b.language.name) {
return -1;

View File

@@ -14,6 +14,7 @@
function onInit() {
vm.variants = $scope.model.variants;
vm.displayVariants = vm.variants.slice(0);// shallow copy, we dont want to share the array-object(because we will be performing a sort method) but each entry should be shared (because we need validation and notifications).
vm.labels = {};
if (!$scope.model.title) {
@@ -23,15 +24,12 @@
}
_.each(vm.variants, function (variant) {
variant.compositeId = (variant.language ? variant.language.culture : "inv") + "_" + (variant.segment ? variant.segment : "");
variant.htmlId = "_content_variant_" + variant.compositeId;
variant.isMandatory = isMandatoryFilter(variant);
});
if (vm.variants.length > 1) {
vm.variants = vm.variants.sort(function (a, b) {
vm.displayVariants.sort(function (a, b) {
if (a.language && b.language) {
if (a.language.name > b.language.name) {
return -1;

View File

@@ -1,6 +1,6 @@
<div ng-controller="Umbraco.Overlays.PublishDescendantsController as vm" class="umb-variant-selector-overlay">
<div ng-if="vm.variants.length === 1">
<div ng-if="vm.displayVariants.length === 1">
<div class="mb3">
<p><localize key="{{vm.labels.help.key}}" tokens="vm.labels.help.tokens"></localize></p>
</div>
@@ -16,7 +16,7 @@
</div>
<div ng-if="vm.variants.length > 1">
<div ng-if="vm.displayVariants.length > 1">
<div class="mb3">
<p><localize key="content_publishDescendantsWithVariantsHelp"></localize></p>
@@ -33,7 +33,7 @@
<div class="umb-list umb-list--condensed">
<div class="umb-list-item umb-list--condensed" ng-repeat="variant in vm.variants">
<div class="umb-list-item umb-list--condensed" ng-repeat="variant in vm.displayVariants track by variant.compositeId">
<ng-form name="publishVariantSelectorForm">
<div class="umb-variant-selector-entry" ng-class="{'umb-list-item--error': publishVariantSelectorForm.publishVariantSelector.$invalid}">

View File

@@ -9,7 +9,6 @@
vm.isNew = true;
vm.changeSelection = changeSelection;
vm.dirtyVariantFilter = dirtyVariantFilter;
function changeSelection(variant) {
var firstSelected = _.find(vm.variants, function (v) {
@@ -18,7 +17,7 @@
$scope.model.disableSubmitButton = !firstSelected; //disable submit button if there is none selected
}
function dirtyVariantFilter(variant) {
function saveableVariantFilter(variant) {
//determine a variant is 'dirty' (meaning it will show up as save-able) if it's
// * the active one
// * it's editor is in a $dirty state
@@ -58,6 +57,7 @@
function onInit() {
vm.variants = $scope.model.variants;
vm.availableVariants = vm.variants.filter(saveableVariantFilter);
if(!$scope.model.title) {
localizationService.localize("content_readyToSave").then(function(value){
@@ -81,17 +81,21 @@
_.each(vm.variants,
function (variant) {
variant.compositeId = contentEditingHelper.buildCompositeVariantId(variant);
variant.htmlId = "_content_variant_" + variant.compositeId;
if(vm.isNew && hasAnyData(variant)){
variant.save = true;
}
});
if (vm.variants.length !== 0) {
vm.variants = vm.variants.sort(function (a, b) {
_.find(vm.variants, function (v) {
if(v.active) {
//ensure that the current one is selected
v.save = true;
}
});
vm.availableVariants.sort(function (a, b) {
if (a.language && b.language) {
if (a.language.name > b.language.name) {
return -1;
@@ -111,13 +115,6 @@
return 0;
});
_.find(vm.variants, function (v) {
if(v.active) {
//ensure that the current one is selected
v.save = true;
}
});
} else {
//disable save button if we have nothing to save
$scope.model.disableSubmitButton = true;

View File

@@ -14,7 +14,7 @@
<div class="umb-list umb-list--condensed">
<div class="umb-list-item"
ng-repeat="variant in vm.variants | filter:vm.dirtyVariantFilter track by variant.compositeId">
ng-repeat="variant in vm.availableVariants track by variant.compositeId">
<ng-form name="saveVariantSelectorForm">
<div class="umb-variant-selector-entry" ng-class="{'umb-list-item--error': saveVariantSelectorForm.saveVariantSelector.$invalid}">

View File

@@ -23,6 +23,7 @@
function onInit() {
vm.variants = $scope.model.variants;
vm.displayVariants = vm.variants.slice(0);// shallow copy, we dont want to share the array-object(because we will be performing a sort method) but each entry should be shared (because we need validation and notifications).
for (let i = 0; i < vm.variants.length; i++) {
origDates.push({
@@ -38,9 +39,6 @@
}
_.each(vm.variants, function (variant) {
variant.compositeId = contentEditingHelper.buildCompositeVariantId(variant);
variant.htmlId = "_content_variant_" + variant.compositeId;
variant.isMandatory = isMandatoryFilter(variant);
});
@@ -49,7 +47,7 @@
// so we have to check for length > 1
if (vm.variants.length > 1) {
vm.variants = vm.variants.sort(function (a, b) {
vm.displayVariants.sort(function (a, b) {
if (a.language && b.language) {
if (a.language.name > b.language.name) {
return -1;

View File

@@ -84,7 +84,7 @@
<div class="umb-list umb-list--condensed">
<div class="umb-list-item" ng-repeat="variant in vm.variants">
<div class="umb-list-item" ng-repeat="variant in vm.displayVariants track by variant.compositeId">
<ng-form name="scheduleSelectorForm" style="width:100%;">
<div class="umb-variant-selector-entry" ng-class="{'umb-list-item--error': scheduleSelectorForm.saveVariantReleaseDate.$invalid}">

View File

@@ -20,9 +20,6 @@
}
_.each(vm.variants, function (variant) {
variant.compositeId = contentEditingHelper.buildCompositeVariantId(variant);
variant.htmlId = "_content_variant_" + variant.compositeId;
variant.isMandatory = isMandatoryFilter(variant);
});

View File

@@ -10,7 +10,7 @@
<div class="umb-list umb-list--condensed" ng-if="!vm.loading">
<div class="umb-list-item" ng-repeat="variant in vm.availableVariants">
<div class="umb-list-item" ng-repeat="variant in vm.availableVariants track by variant.compositeId">
<ng-form name="publishVariantSelectorForm">
<div class="umb-variant-selector-entry" ng-class="{'umb-list-item--error': publishVariantSelectorForm.publishVariantSelector.$invalid}">

View File

@@ -7,11 +7,11 @@
var autoSelectedVariants = [];
vm.changeSelection = changeSelection;
vm.publishedVariantFilter = publishedVariantFilter;
function onInit() {
vm.variants = $scope.model.variants;
vm.unpublishableVariants = vm.variants.filter(publishedVariantFilter)
// set dialog title
if (!$scope.model.title) {
@@ -21,16 +21,13 @@
}
_.each(vm.variants, function (variant) {
variant.compositeId = contentEditingHelper.buildCompositeVariantId(variant);
variant.htmlId = "_content_variant_" + variant.compositeId;
variant.isMandatory = isMandatoryFilter(variant);
});
// node has variants
if (vm.variants.length !== 1) {
vm.variants = vm.variants.sort(function (a, b) {
vm.unpublishableVariants.sort(function (a, b) {
if (a.language && b.language) {
if (a.language.name > b.language.name) {
return -1;

View File

@@ -13,7 +13,7 @@
<div class="umb-list umb-list--condensed">
<div class="umb-list-item" ng-repeat="variant in vm.variants | filter:vm.publishedVariantFilter">
<div class="umb-list-item" ng-repeat="variant in vm.unpublishableVariants track by variant.compositeId">
<ng-form name="unpublishVariantSelectorForm">
<div class="umb-variant-selector-entry" ng-class="{'umb-list-item--error': unpublishVariantSelectorForm.unpublishVariantSelector.$invalid}">