diff --git a/projects/multidirectory-app/src/app/components/modals/components/dialogs/entity-properties-dialog/entity-properties-dialog.component.html b/projects/multidirectory-app/src/app/components/modals/components/dialogs/entity-properties-dialog/entity-properties-dialog.component.html index 1a44bed5..97bc966d 100644 --- a/projects/multidirectory-app/src/app/components/modals/components/dialogs/entity-properties-dialog/entity-properties-dialog.component.html +++ b/projects/multidirectory-app/src/app/components/modals/components/dialogs/entity-properties-dialog/entity-properties-dialog.component.html @@ -5,7 +5,7 @@
@switch (entityType) { @case (EntityTypes.User) { - + } @case (EntityTypes.Group) { @@ -25,8 +25,8 @@ {{ 'properties-modal.close' | transloco }} - {{ 'properties-modal.approve' | transloco }} + {{ 'properties-modal.approve' | transloco }}
diff --git a/projects/multidirectory-app/src/app/components/modals/components/dialogs/entity-properties-dialog/entity-properties-dialog.component.ts b/projects/multidirectory-app/src/app/components/modals/components/dialogs/entity-properties-dialog/entity-properties-dialog.component.ts index f5f075d9..8da67c7d 100644 --- a/projects/multidirectory-app/src/app/components/modals/components/dialogs/entity-properties-dialog/entity-properties-dialog.component.ts +++ b/projects/multidirectory-app/src/app/components/modals/components/dialogs/entity-properties-dialog/entity-properties-dialog.component.ts @@ -50,6 +50,7 @@ import { LdapEntryType } from '@models/core/ldap/ldap-entry-type'; export class EntityPropertiesDialogComponent implements OnInit { dialogData: EntityPropertiesDialogData = inject(DIALOG_DATA); + @ViewChild('userProps') userProps!: UserPropertiesComponent; @ViewChild(DialogComponent, { static: true }) dialogComponent!: DialogComponent; EntityTypes = LdapEntryType; @@ -87,7 +88,7 @@ export class EntityPropertiesDialogComponent implements OnInit { this.dialogComponent.showSpinner(); const updateRequest = this.attributeService.createAttributeUpdateRequest(this.accessor); - if (updateRequest.changes.length == 0) { + if (updateRequest.changes.length === 0 || !this.userProps?.generalPropertiesValid) { this.dialogComponent.hideSpinner(); this.close(); diff --git a/projects/multidirectory-app/src/app/core/validators/domainformat.directive.ts b/projects/multidirectory-app/src/app/core/validators/domainformat.directive.ts index c808d221..186de1a6 100644 --- a/projects/multidirectory-app/src/app/core/validators/domainformat.directive.ts +++ b/projects/multidirectory-app/src/app/core/validators/domainformat.directive.ts @@ -25,6 +25,9 @@ export class DomainFormatValidatorDirective implements Validator { patternValidator = new PatternValidator(); validate(control: AbstractControl): ValidationErrors | null { + if (!control.value) { + return null; + } const result = new RegExp(this.domainPattern()).test(control.value); return result ? null : { DomainFormat: this.domainErrorMessage() }; } diff --git a/projects/multidirectory-app/src/app/core/validators/max-length.directive.ts b/projects/multidirectory-app/src/app/core/validators/max-length.directive.ts index bf09535b..4fdbb778 100644 --- a/projects/multidirectory-app/src/app/core/validators/max-length.directive.ts +++ b/projects/multidirectory-app/src/app/core/validators/max-length.directive.ts @@ -36,7 +36,10 @@ export class MaxLengthValidatorDirective implements Validator { return null; } - const exceededMaxLength = this.maxLength ? value.length > this.maxLength : false; + // todo: убрать в рамках рефакторинга форм + const normalizedValue = value instanceof Array ? value[0] : value; + + const exceededMaxLength = this.maxLength ? normalizedValue.length > this.maxLength : false; return exceededMaxLength ? { MaxLengthExceeded: this.maxLengthErrorMessage } : null; } diff --git a/projects/multidirectory-app/src/app/core/validators/required-with-message.directive.ts b/projects/multidirectory-app/src/app/core/validators/required-with-message.directive.ts index 57fa2ca6..5ef3d135 100644 --- a/projects/multidirectory-app/src/app/core/validators/required-with-message.directive.ts +++ b/projects/multidirectory-app/src/app/core/validators/required-with-message.directive.ts @@ -23,12 +23,13 @@ export class RequiredWithMessageDirective extends RequiredValidator { override validate(control: AbstractControl): ValidationErrors | null { const appRequiredErrorLabel = this.appRequiredErrorLabel(); - return control.value !== null && control.value !== undefined && control.value !== '' + const normalizedValue = control.value instanceof Array ? control.value[0] : control.value; + return normalizedValue !== null && normalizedValue !== undefined && normalizedValue !== '' ? null : { - required: appRequiredErrorLabel - ? appRequiredErrorLabel - : translate('error-message.required'), - }; + required: appRequiredErrorLabel + ? appRequiredErrorLabel + : translate('error-message.required'), + }; } } diff --git a/projects/multidirectory-app/src/app/features/forms/user-create/general-info/general-info.component.html b/projects/multidirectory-app/src/app/features/forms/user-create/general-info/general-info.component.html index 62a595af..460c411d 100644 --- a/projects/multidirectory-app/src/app/features/forms/user-create/general-info/general-info.component.html +++ b/projects/multidirectory-app/src/app/features/forms/user-create/general-info/general-info.component.html @@ -9,6 +9,7 @@ appRequired class="col-span-1 w-full" name="first-name" + [maxLength]="256" (change)="onNameChange()" [(ngModel)]="setupRequest.firstName" > @@ -19,6 +20,7 @@ @@ -32,6 +34,7 @@ @@ -45,6 +48,7 @@ @@ -57,6 +61,7 @@ @@ -70,6 +75,7 @@ @@ -83,6 +89,7 @@ diff --git a/projects/multidirectory-app/src/app/features/forms/user-create/general-info/general-info.component.ts b/projects/multidirectory-app/src/app/features/forms/user-create/general-info/general-info.component.ts index d3bcc5d7..ff4c64fb 100644 --- a/projects/multidirectory-app/src/app/features/forms/user-create/general-info/general-info.component.ts +++ b/projects/multidirectory-app/src/app/features/forms/user-create/general-info/general-info.component.ts @@ -25,6 +25,7 @@ import { TextboxComponent, } from 'multidirectory-ui-kit'; import { from, Subject, take, takeUntil } from 'rxjs'; +import { MaxLengthValidatorDirective } from '@core/validators/max-length.directive'; @Component({ selector: 'app-user-create-general-info', @@ -39,6 +40,7 @@ import { from, Subject, take, takeUntil } from 'rxjs'; DropdownComponent, MdFormComponent, CommonModule, + MaxLengthValidatorDirective ], }) export class UserCreateGeneralInfoComponent implements OnInit, AfterViewInit, OnDestroy { diff --git a/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/general/user-properties-general.component.html b/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/general/user-properties-general.component.html index 05dd238a..3131be27 100644 --- a/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/general/user-properties-general.component.html +++ b/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/general/user-properties-general.component.html @@ -9,102 +9,108 @@
- -
- - + + +
+ + - - -
+ + +
- -
- - -
+ +
+ + +
- -
- - -
+ +
+ + +
- -
- - -
+ +
+ + +
- -
- - -
+ +
+ + +
-
+
- -
- - - - {{ 'user-properties-generals.other' | transloco }} - -
+ +
+ + + + {{ 'user-properties-generals.other' | transloco }} + +
- -
- - -
+ +
+ + +
- -
- - - - {{ 'user-properties-generals.other' | transloco }} - -
+ +
+ + + + {{ 'user-properties-generals.other' | transloco }} + +
+ } diff --git a/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/general/user-properties-general.component.ts b/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/general/user-properties-general.component.ts index 122b94f6..83082931 100644 --- a/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/general/user-properties-general.component.ts +++ b/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/general/user-properties-general.component.ts @@ -1,10 +1,10 @@ -import { Component, inject, Input } from '@angular/core'; -import { AbstractControl, FormsModule, ValidationErrors, ValidatorFn } from '@angular/forms'; +import { Component, inject, Input, ViewChild, AfterViewInit } from '@angular/core'; +import { FormsModule } from '@angular/forms'; import { LdapAttributes } from '@core/ldap/ldap-attributes/ldap-attributes'; import { RequiredWithMessageDirective } from '@core/validators/required-with-message.directive'; import { AvatarUploadComponent } from '@features/ldap-properties/avatar-upload/avatar-upload.component'; import { translate, TranslocoPipe } from '@jsverse/transloco'; -import { ButtonComponent, TextboxComponent } from 'multidirectory-ui-kit'; +import { ButtonComponent, TextboxComponent, MdFormComponent } from 'multidirectory-ui-kit'; import { ToastrService } from 'ngx-toastr'; import { AttributeListDialogComponent } from '../../../../components/modals/components/dialogs/attribute-list-dialog/attribute-list-dialog.component'; import { @@ -14,6 +14,7 @@ import { import { DialogService } from '../../../../components/modals/services/dialog.service'; import { ValidationFunctions } from '@core/validators/validator-functions'; import { DomainFormatValidatorDirective } from '@core/validators/domainformat.directive'; +import { MaxLengthValidatorDirective } from '@core/validators/max-length.directive'; @Component({ selector: 'app-user-properties-general', @@ -22,18 +23,25 @@ import { DomainFormatValidatorDirective } from '@core/validators/domainformat.di imports: [ AvatarUploadComponent, TextboxComponent, + MdFormComponent, FormsModule, RequiredWithMessageDirective, TranslocoPipe, ButtonComponent, DomainFormatValidatorDirective, + MaxLengthValidatorDirective, ], }) -export class UserPropertiesGeneralComponent { +export class UserPropertiesGeneralComponent implements AfterViewInit { private dialogService: DialogService = inject(DialogService); @Input() accessor: LdapAttributes | null = null; + @ViewChild('form') userPropsForm!: MdFormComponent; toastr = inject(ToastrService); + ngAfterViewInit() { + this.userPropsForm?.validate(); + } + changeOtherAttributeList(title: string, field: string) { if (!this.accessor) { return; @@ -66,4 +74,11 @@ export class UserPropertiesGeneralComponent { this.accessor![field] = result; }); } + + get formValid(): boolean { + if (!this.userPropsForm) { + return true; + } + return this.userPropsForm.valid; + } } diff --git a/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/user-properties.component.html b/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/user-properties.component.html index 6dacf7d0..d915cc92 100644 --- a/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/user-properties.component.html +++ b/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/user-properties.component.html @@ -23,7 +23,7 @@ {{ 'user-properties-tabs.password-policy' | transloco }} - + diff --git a/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/user-properties.component.ts b/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/user-properties.component.ts index 9906910b..e75ce1ee 100644 --- a/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/user-properties.component.ts +++ b/projects/multidirectory-app/src/app/features/ldap-properties/user-properties/user-properties.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectorRef, Component, inject, input } from '@angular/core'; +import {ChangeDetectorRef, Component, inject, input, ViewChild} from '@angular/core'; import { LdapAttributes } from '@core/ldap/ldap-attributes/ldap-attributes'; import { TranslocoPipe } from '@jsverse/transloco'; import { TabComponent, TabDirective, TabPaneComponent } from 'multidirectory-ui-kit'; @@ -25,10 +25,11 @@ import { UserPropertiesProfileComponent } from './profile/user-properties-profil UserPropertiesProfileComponent, UserPropertiesAccountComponent, MemberOfComponent, - PasswordPolicyComponent, + PasswordPolicyComponent ], }) export class UserPropertiesComponent { + @ViewChild('ug') generalProperties!: UserPropertiesGeneralComponent; private cdr = inject(ChangeDetectorRef); readonly accessor = input.required(); properties?: any[]; @@ -40,4 +41,11 @@ export class UserPropertiesComponent { onTabChanged() { this.cdr.detectChanges(); } + + get generalPropertiesValid(): boolean { + if (!this.generalProperties) { + return true; + } + return this.generalProperties.formValid; + } }