Ensures validation works for settings data, now to test other scenarios.

This commit is contained in:
Shannon
2020-07-24 00:42:37 +10:00
parent cb9ae7335e
commit 9e9f8863c2
6 changed files with 108 additions and 95 deletions

View File

@@ -57,15 +57,22 @@ function valServerMatch(serverValidationManager) {
throw "valServerMatch dictionary keys must be one of " + allowedKeys.join();
}
unsubscribe.push(serverValidationManager.subscribe(
scope.valServerMatch[k],
currentCulture,
"",
serverValidationManagerCallback,
currentSegment,
{ matchType: k } // specify the match type
));
var matchVal = scope.valServerMatch[k];
if (Utilities.isString(matchVal)) {
matchVal = [matchVal]; // change to an array since the value can also natively be an array
}
// match for each string in the array
matchVal.forEach(m => {
unsubscribe.push(serverValidationManager.subscribe(
m,
currentCulture,
"",
serverValidationManagerCallback,
currentSegment,
{ matchType: k } // specify the match type
));
})
});
}
else if (Utilities.isString(scope.valServerMatch)) {

View File

@@ -428,12 +428,12 @@
*/
getBlockObject: function (layoutEntry) {
var udi = layoutEntry.contentUdi;
var contentUdi = layoutEntry.contentUdi;
var dataModel = getDataByUdi(udi, this.value.contentData);
var dataModel = getDataByUdi(contentUdi, this.value.contentData);
if (dataModel === null) {
console.error("Couldn't find content model of " + udi)
console.error("Couldn't find content model of " + contentUdi)
return null;
}
@@ -441,12 +441,12 @@
var contentScaffold;
if (blockConfiguration === null) {
console.error("The block entry of " + udi + " is not being initialized because its contentTypeKey is not allowed for this PropertyEditor");
console.error("The block entry of " + contentUdi + " is not being initialized because its contentTypeKey is not allowed for this PropertyEditor");
}
else {
contentScaffold = this.getScaffoldFromKey(blockConfiguration.contentTypeKey);
if (contentScaffold === null) {
console.error("The block entry of " + udi + " is not begin initialized cause its Element Type was not loaded.");
console.error("The block entry of " + contentUdi + " is not begin initialized cause its Element Type was not loaded.");
}
}
@@ -483,9 +483,9 @@
// make basics from scaffold
blockObject.content = Utilities.copy(contentScaffold);
blockObject.content.udi = udi;
// Change the content.key to the GUID part of the udi, else it's just random which we don't want, it should be consistent
blockObject.content.key = udiService.getKey(udi);
blockObject.content.udi = contentUdi;
// Change the content.key to the GUID part of the udi, else it's just random which we don't want, it must be consistent
blockObject.content.key = udiService.getKey(contentUdi);
mapToElementModel(blockObject.content, dataModel);
@@ -515,6 +515,9 @@
// make basics from scaffold
blockObject.settings = Utilities.copy(settingsScaffold);
blockObject.settings.udi = settingsUdi;
// Change the settings.key to the GUID part of the udi, else it's just random which we don't want, it must be consistent
blockObject.settings.key = udiService.getKey(settingsUdi);
mapToElementModel(blockObject.settings, settingsData);
}
}

View File

@@ -1,86 +1,90 @@
angular.module("umbraco")
.controller("Umbraco.Editors.BlockEditorController",
function ($scope, localizationService, formHelper) {
var vm = this;
.controller("Umbraco.Editors.BlockEditorController",
function ($scope, localizationService, formHelper) {
var vm = this;
vm.model = $scope.model;
vm.model = $scope.model;
vm.tabs = [];
localizationService.localizeMany([
vm.model.liveEditing ? "prompt_discardChanges" : "general_close",
vm.model.liveEditing ? "buttons_confirmActionConfirm" : "buttons_submitChanges"
]).then(function (data) {
vm.closeLabel = data[0];
vm.submitLabel = data[1];
});
vm.model = $scope.model;
vm.model = $scope.model;
vm.tabs = [];
localizationService.localizeMany([
vm.model.liveEditing ? "prompt_discardChanges" : "general_close",
vm.model.liveEditing ? "buttons_confirmActionConfirm" : "buttons_submitChanges"
]).then(function (data) {
vm.closeLabel = data[0];
vm.submitLabel = data[1];
});
if ($scope.model.content && $scope.model.content.variants) {
if ($scope.model.content && $scope.model.content.variants) {
var apps = $scope.model.content.apps;
var apps = $scope.model.content.apps;
vm.tabs = apps;
vm.tabs = apps;
// replace view of content app.
var contentApp = apps.find(entry => entry.alias === "umbContent");
if (contentApp) {
contentApp.view = "views/common/infiniteeditors/blockeditor/blockeditor.content.html";
if(vm.model.hideContent) {
apps.splice(apps.indexOf(contentApp), 1);
} else if (vm.model.openSettings !== true) {
contentApp.active = true;
}
}
// remove info app:
var infoAppIndex = apps.findIndex(entry => entry.alias === "umbInfo");
apps.splice(infoAppIndex, 1);
}
if (vm.model.settings && vm.model.settings.variants) {
localizationService.localize("blockEditor_tabBlockSettings").then(
function (settingsName) {
var settingsTab = {
"name": settingsName,
"alias": "settings",
"icon": "icon-settings",
"view": "views/common/infiniteeditors/blockeditor/blockeditor.settings.html"
};
vm.tabs.push(settingsTab);
if (vm.model.openSettings) {
settingsTab.active = true;
// replace view of content app.
var contentApp = apps.find(entry => entry.alias === "umbContent");
if (contentApp) {
contentApp.view = "views/common/infiniteeditors/blockeditor/blockeditor.content.html";
if (vm.model.hideContent) {
apps.splice(apps.indexOf(contentApp), 1);
} else if (vm.model.openSettings !== true) {
contentApp.active = true;
}
}
);
}
vm.submitAndClose = function () {
if (vm.model && vm.model.submit) {
// always keep server validations since this will be a nested editor and server validations are global
if (formHelper.submitForm({ scope: $scope, formCtrl: vm.blockForm, keepServerValidation: true })) {
vm.model.submit(vm.model);
// remove info app:
var infoAppIndex = apps.findIndex(entry => entry.alias === "umbInfo");
apps.splice(infoAppIndex, 1);
}
if (vm.model.settings && vm.model.settings.variants) {
localizationService.localize("blockEditor_tabBlockSettings").then(
function (settingsName) {
var settingsTab = {
"name": settingsName,
"alias": "settings",
"icon": "icon-settings",
"view": "views/common/infiniteeditors/blockeditor/blockeditor.settings.html"
};
vm.tabs.push(settingsTab);
if (vm.model.openSettings) {
settingsTab.active = true;
}
}
);
}
vm.submitAndClose = function () {
if (vm.model && vm.model.submit) {
// always keep server validations since this will be a nested editor and server validations are global
if (formHelper.submitForm({
scope: $scope,
formCtrl: vm.blockForm,
keepServerValidation: true
})) {
vm.model.submit(vm.model);
}
}
}
}
vm.close = function () {
if (vm.model && vm.model.close) {
// TODO: At this stage there could very well have been server errors that have been cleared
// but if we 'close' we are basically cancelling the value changes which means we'd want to cancel
// all of the server errors just cleared. It would be possible to do that but also quite annoying.
// The rudimentary way would be to:
// * Track all cleared server errors here by subscribing to the prefix validation of controls contained here
// * If this is closed, re-add all of those server validation errors
// A more robust way to do this would be to:
// * Add functionality to the serverValidationManager whereby we can remove validation errors and it will
// maintain a copy of the original errors
// * It would have a 'commit' method to commit the removed errors - which we would call in the formHelper.submitForm when it's successful
// * It would have a 'rollback' method to reset the removed errors - which we would call here
vm.close = function () {
if (vm.model && vm.model.close) {
// TODO: At this stage there could very well have been server errors that have been cleared
// but if we 'close' we are basically cancelling the value changes which means we'd want to cancel
// all of the server errors just cleared. It would be possible to do that but also quite annoying.
// The rudimentary way would be to:
// * Track all cleared server errors here by subscribing to the prefix validation of controls contained here
// * If this is closed, re-add all of those server validation errors
// A more robust way to do this would be to:
// * Add functionality to the serverValidationManager whereby we can remove validation errors and it will
// maintain a copy of the original errors
// * It would have a 'commit' method to commit the removed errors - which we would call in the formHelper.submitForm when it's successful
// * It would have a 'rollback' method to reset the removed errors - which we would call here
// TODO: check if content/settings has changed and ask user if they are sure.
vm.model.close(vm.model);
// TODO: check if content/settings has changed and ask user if they are sure.
vm.model.close(vm.model);
}
}
}
}
);
}
);

View File

@@ -1,4 +1,4 @@
<ng-form name="vm.blockRowForm" val-server-match="{ 'contains' : vm.layout.$block.content.key }">
<ng-form name="vm.blockRowForm" val-server-match="{ 'contains' : [ vm.layout.$block.content.key, vm.layout.$block.settings.key] }">
<div class="umb-block-list__block" ng-class="{'--active':vm.layout.$block.active}">
<umb-block-list-block stylesheet="{{::vm.layout.$block.config.stylesheet}}"
@@ -12,7 +12,7 @@
<div class="umb-block-list__block--actions">
<button type="button" class="btn-reset umb-outline action --settings" localize="title" title="actions_editSettings"
ng-click="vm.blockEditorApi.openSettingsForBlock(vm.layout.$block, vm.index);"
ng-click="vm.blockEditorApi.openSettingsForBlock(vm.layout.$block, vm.index, vm.blockRowForm);"
ng-if="vm.layout.$block.showSettings === true">
<i class="icon icon-settings" aria-hidden="true"></i>
<span class="sr-only">

View File

@@ -555,9 +555,8 @@
});
}
// TODO: We'll need to pass in a parentForm here too
function openSettingsForBlock(block, blockIndex) {
editBlock(block, true, blockIndex);
function openSettingsForBlock(block, blockIndex, parentForm) {
editBlock(block, true, blockIndex, parentForm);
}
vm.blockEditorApi = {