From b07858243b7d6eb404e7b39a01ddf9a045135657 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Wed, 9 Sep 2020 13:43:01 +0200 Subject: [PATCH] do highlight errors in editor tabs --- zero.Core/Api/ApplicationsApi.cs | 4 +-- zero.Core/Validation/ApplicationValidator.cs | 7 ++-- .../Validation/BackofficeUserValidator.cs | 8 ++--- zero.Core/Validation/MediaFolderValidator.cs | 5 ++- zero.Web.UI/App/components/forms/error.vue | 6 ++-- zero.Web.UI/App/components/forms/form.vue | 36 +++++++++++++++---- zero.Web.UI/App/components/tabs/tab.vue | 19 +++++++++- zero.Web.UI/App/components/tabs/tabs.vue | 4 +-- zero.Web.UI/App/renderers/application.js | 10 ++++-- zero.Web.UI/App/renderers/user.js | 6 ++-- zero.Web/Controllers/UsersController.cs | 9 +---- 11 files changed, 79 insertions(+), 35 deletions(-) diff --git a/zero.Core/Api/ApplicationsApi.cs b/zero.Core/Api/ApplicationsApi.cs index 81f06daf..2b74576b 100644 --- a/zero.Core/Api/ApplicationsApi.cs +++ b/zero.Core/Api/ApplicationsApi.cs @@ -13,9 +13,9 @@ namespace zero.Core.Api IValidator Validator; - public ApplicationsApi(IBackofficeStore store) : base(store) + public ApplicationsApi(IBackofficeStore store, IValidator validator) : base(store) { - Validator = null; + Validator = validator; } diff --git a/zero.Core/Validation/ApplicationValidator.cs b/zero.Core/Validation/ApplicationValidator.cs index 55ef4208..d0aab8cb 100644 --- a/zero.Core/Validation/ApplicationValidator.cs +++ b/zero.Core/Validation/ApplicationValidator.cs @@ -1,16 +1,17 @@ using FluentValidation; using zero.Core.Entities; -using zero.Core.Entities.Setup; using zero.Core.Extensions; namespace zero.Core.Validation { - public class ApplicationValidator : AbstractValidator + public class ApplicationValidator : ZeroValidator { public ApplicationValidator() { //RuleFor(x => x.Code).Length(2); - RuleFor(x => x.Name).NotEmpty().Length(2, 120); + RuleFor(x => x.Name).NotEmpty().Length(2, 50); + RuleFor(x => x.FullName).MaximumLength(120); + RuleFor(x => x.Email).Email().NotEmpty().MaximumLength(120); RuleFor(x => x.Domains).NotEmpty(); } } diff --git a/zero.Core/Validation/BackofficeUserValidator.cs b/zero.Core/Validation/BackofficeUserValidator.cs index d468e303..2a23a6e9 100644 --- a/zero.Core/Validation/BackofficeUserValidator.cs +++ b/zero.Core/Validation/BackofficeUserValidator.cs @@ -4,14 +4,14 @@ using zero.Core.Extensions; namespace zero.Core.Validation { - public class BackofficeUserValidator : AbstractValidator + public class BackofficeUserValidator : ZeroValidator { public BackofficeUserValidator(bool isCreate = false) { - RuleFor(x => x.Name).NotEmpty(); - RuleFor(x => x.Email).Email(); + RuleFor(x => x.Name).Length(2, 80); + RuleFor(x => x.Email).NotEmpty().Email().MaximumLength(120); RuleFor(x => x.PasswordHash).NotEmpty(); - RuleFor(x => x.LanguageId).NotEmpty(); // TODO only allow available languages + RuleFor(x => x.LanguageId).NotEmpty(); RuleFor(x => x.Roles).NotEmpty(); if (isCreate) diff --git a/zero.Core/Validation/MediaFolderValidator.cs b/zero.Core/Validation/MediaFolderValidator.cs index f449642a..f7ca42c6 100644 --- a/zero.Core/Validation/MediaFolderValidator.cs +++ b/zero.Core/Validation/MediaFolderValidator.cs @@ -1,14 +1,17 @@ using FluentValidation; +using zero.Core.Api; using zero.Core.Entities; +using zero.Core.Extensions; namespace zero.Core.Validation { public class MediaFolderValidator : ZeroValidator { - public MediaFolderValidator() + public MediaFolderValidator(IBackofficeStore store) { RuleFor(x => x.Name).Length(2, 80); RuleFor(x => x.IsActive).Equal(true); + RuleFor(x => x.ParentId).Exists(store); } } } \ No newline at end of file diff --git a/zero.Web.UI/App/components/forms/error.vue b/zero.Web.UI/App/components/forms/error.vue index cb36db58..aded7dfb 100644 --- a/zero.Web.UI/App/components/forms/error.vue +++ b/zero.Web.UI/App/components/forms/error.vue @@ -46,11 +46,11 @@ methods: { // set and display errors - set(errors, append) + setErrors(errors, append) { if (!errors) { - return this.clear(); + return this.clearErrors(); } if (!_isArray(errors)) @@ -78,7 +78,7 @@ // clear errors and hide - clear() + clearErrors() { this.errors = []; } diff --git a/zero.Web.UI/App/components/forms/form.vue b/zero.Web.UI/App/components/forms/form.vue index 22a2e7a3..060988ef 100644 --- a/zero.Web.UI/App/components/forms/form.vue +++ b/zero.Web.UI/App/components/forms/form.vue @@ -275,7 +275,12 @@ { this.getErrorComponents().forEach(component => { - component.clear(); + component.clearErrors(); + + if (component.tab) + { + component.tab.clearErrors(); + } }); }, @@ -305,7 +310,12 @@ if (field && errorGroups[field]) { handledGroups.push(field); - component.set(errorGroups[field]); + component.setErrors(errorGroups[field]); + + if (component.tab) + { + component.tab.setErrors(true); + } } }); @@ -318,7 +328,12 @@ { if (component.catchRemaining || component.catchAll) { - component.set(errorGroup, true); + component.setErrors(errorGroup, true); + + if (component.tab) + { + component.tab.setErrors(true); + } } }); } @@ -332,17 +347,26 @@ let errorComponents = []; // find components which can output errors - let traverseChildren = parent => + let traverseChildren = (parent, tab) => { parent.$children.forEach(component => { if (this.errorComponents.indexOf(component.$options.name) > -1) { - errorComponents.push(component); + errorComponents.push({ + name: component.$options.name, + field: component.field, + catchAll: component.catchAll, + catchRemaining: component.catchRemaining, + component: component, + setErrors: component.setErrors, + clearErrors: component.clearErrors, + tab: tab + }); } else { - traverseChildren(component); + traverseChildren(component, tab || (component.$options.name === 'uiTab' ? component : null)); } }); }; diff --git a/zero.Web.UI/App/components/tabs/tab.vue b/zero.Web.UI/App/components/tabs/tab.vue index 3260417e..745c466c 100644 --- a/zero.Web.UI/App/components/tabs/tab.vue +++ b/zero.Web.UI/App/components/tabs/tab.vue @@ -6,6 +6,8 @@ \ No newline at end of file diff --git a/zero.Web.UI/App/components/tabs/tabs.vue b/zero.Web.UI/App/components/tabs/tabs.vue index 68bbbff6..602f702f 100644 --- a/zero.Web.UI/App/components/tabs/tabs.vue +++ b/zero.Web.UI/App/components/tabs/tabs.vue @@ -1,9 +1,9 @@