From 2df481332b0e4246545628c226bf1046f59ce2e2 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 29 Jun 2020 14:51:57 +1000 Subject: [PATCH] commits wip to resume later. --- .../services/servervalidationmgr.service.js | 73 ++++++++++++------- .../server-validation-manager.spec.js | 20 +++++ .../Validation/ValidationResultConverter.cs | 8 +- 3 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/servervalidationmgr.service.js b/src/Umbraco.Web.UI.Client/src/common/services/servervalidationmgr.service.js index 04b4d2ad9a..d3f798c35f 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/servervalidationmgr.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/servervalidationmgr.service.js @@ -106,9 +106,26 @@ function serverValidationManager($timeout) { throw "Invalid JSON structure for complex property, missing 'nestedValidation'"; } + nestedValidation.forEach((item, index) => { + + var elementType = Object.keys(item)[0]; + + + var key = "nestedValidation.[" + index + "]."; + + + + }); + + for (var i = 0; i < nestedValidation.length; i++) { + + } + // each key represents an element type, the key is it's alias var keys = Object.keys(nestedValidation); + var asdf = keys; + // TODO: Could we use an individual instance of serverValidationManager for each element type? It could/should work the way // it does today since it currently manages all callbacks for all simple properties on a content item based on a content type. // Hrmmm... only thing is then how to dispose/cleanup of these instances? @@ -418,37 +435,39 @@ function serverValidationManager($timeout) { // if the error message is json it's a complex editor validation response that we need to parse if (errorMsg.startsWith("{")) { - parseComplexEditorError(errorMsg); + + var parsed = parseComplexEditorError(errorMsg); + + // reset to nothing because we will not display the json message but we still want to inform the + // root properties of the error. + errorMsg = "Hello!"; } - else { - //only add the item if it doesn't exist - if (!this.hasPropertyError(propertyAlias, culture, fieldName, segment)) { - this.items.push({ - propertyAlias: propertyAlias, - culture: culture, - segment: segment, - fieldName: fieldName, - errorMsg: errorMsg - }); - } + //only add the item if it doesn't exist + if (!this.hasPropertyError(propertyAlias, culture, fieldName, segment)) { + this.items.push({ + propertyAlias: propertyAlias, + culture: culture, + segment: segment, + fieldName: fieldName, + errorMsg: errorMsg + }); + } - //find all errors for this item - var errorsForCallback = getPropertyErrors(this, propertyAlias, culture, segment, fieldName); - //we should now call all of the call backs registered for this error - var cbs = this.getPropertyCallbacks(propertyAlias, culture, fieldName, segment); - //call each callback for this error - for (var cb in cbs) { - executeCallback(this, errorsForCallback, cbs[cb].callback, culture, segment); - } - - //execute variant specific callbacks here too when a propery error is added - var variantCbs = this.getVariantCallbacks(culture, segment); - //call each callback for this error - for (var cb in variantCbs) { - executeCallback(this, errorsForCallback, variantCbs[cb].callback, culture, segment); - } + //find all errors for this item + var errorsForCallback = getPropertyErrors(this, propertyAlias, culture, segment, fieldName); + //we should now call all of the call backs registered for this error + var cbs = this.getPropertyCallbacks(propertyAlias, culture, fieldName, segment); + //call each callback for this error + for (var cb in cbs) { + executeCallback(this, errorsForCallback, cbs[cb].callback, culture, segment); + } + //execute variant specific callbacks here too when a propery error is added + var variantCbs = this.getVariantCallbacks(culture, segment); + //call each callback for this error + for (var cb in variantCbs) { + executeCallback(this, errorsForCallback, variantCbs[cb].callback, culture, segment); } }, diff --git a/src/Umbraco.Web.UI.Client/test/unit/common/services/server-validation-manager.spec.js b/src/Umbraco.Web.UI.Client/test/unit/common/services/server-validation-manager.spec.js index 5d2a618f46..dcc662ff22 100644 --- a/src/Umbraco.Web.UI.Client/test/unit/common/services/server-validation-manager.spec.js +++ b/src/Umbraco.Web.UI.Client/test/unit/common/services/server-validation-manager.spec.js @@ -314,6 +314,26 @@ }); + describe('managing complex editor validation errors', function () { + + it('can retrieve validation errors for the property', function () { + + //arrange + var complexValidationMsg = '{"nestedValidation":[{"textPage":{"title":[{"errorMessage":"WRONG!","memberNames":["innerFieldId"]}]}}]}'; + serverValidationManager.addPropertyError("myProperty", null, null, complexValidationMsg, null); + + //act + var err1 = serverValidationManager.getPropertyError("myProperty", null, null, null); + + //assert + expect(err1).not.toBeUndefined(); + expect(err1.propertyAlias).toEqual("myProperty"); + expect(err1.errorMsg).toEqual(complexValidationMsg); + + }); + + }); + describe('validation error subscriptions', function() { it('can subscribe to a field error', function() { diff --git a/src/Umbraco.Web/PropertyEditors/Validation/ValidationResultConverter.cs b/src/Umbraco.Web/PropertyEditors/Validation/ValidationResultConverter.cs index 6769d0bd08..ef3778bb75 100644 --- a/src/Umbraco.Web/PropertyEditors/Validation/ValidationResultConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/Validation/ValidationResultConverter.cs @@ -38,6 +38,9 @@ namespace Umbraco.Web.PropertyEditors.Validation if (validationResult is ComplexEditorValidationResult nestedResult && nestedResult.ValidationResults.Count > 0) { + // TODO: Change to the new validation structure + + var jo = new JObject(); // recurse to write out an array of ValidationResultCollection var obj = JArray.FromObject(nestedResult.ValidationResults, camelCaseSerializer); @@ -50,7 +53,10 @@ namespace Umbraco.Web.PropertyEditors.Validation var joPropertyType = new JObject(); // loop over property validations foreach (var propTypeResult in elementTypeValidationResult.ValidationResults) - { + { + + // TODO: I think here we could do the ModelState thing? instead of recursing? We'd just have to + // not recurse if it was the exact type of the base class ValidationResult and build up the ModelState values var ja = new JArray(); foreach (var result in propTypeResult.ValidationResults) {