remove colorizeInvalid, fix table of content coloring on form error, validate form on click next

This commit is contained in:
mchouliara 2024-09-05 13:51:53 +03:00
parent c1be82d9f9
commit e068d5e566
6 changed files with 19 additions and 114 deletions

View File

@ -148,7 +148,6 @@
[links]="toCEntries" [links]="toCEntries"
[itemSelected]="selectedTocEntry" [itemSelected]="selectedTocEntry"
[viewOnly]="viewOnly" [viewOnly]="viewOnly"
[colorizeInvalid]="colorizeInvalid"
[showErrors]="showErrors" [showErrors]="showErrors"
(dataNeedsRefresh)="onDataNeedsRefresh($event)" (dataNeedsRefresh)="onDataNeedsRefresh($event)"
(itemClick)="displayItem($event)" (itemClick)="displayItem($event)"
@ -188,7 +187,7 @@
<div class="col-12"> <div class="col-12">
<button mat-button class="rounded-btn secondary" (click)="addNewEntry({parent:selectedTocEntry, childType: tocEntryEnumValues.Section})">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.PAGE-INFO.ACTIONS.CREATE-SECTION' | translate}}</button> <button mat-button class="rounded-btn secondary" (click)="addNewEntry({parent:selectedTocEntry, childType: tocEntryEnumValues.Section})">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.PAGE-INFO.ACTIONS.CREATE-SECTION' | translate}}</button>
</div> </div>
<mat-error *ngIf="selectedTocEntry.form.invalid && showErrors">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.ERROR-MESSAGES.FIELD-SELECT-AT-LEAST-ONE-REQUIRED' | translate}}</mat-error> <mat-error *ngIf="selectedTocEntry.form.touched && selectedTocEntry.form.invalid">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.ERROR-MESSAGES.FIELD-SELECT-AT-LEAST-ONE-REQUIRED' | translate}}</mat-error>
} }
</div> </div>
</formGroup> </formGroup>
@ -268,7 +267,8 @@
<mat-icon class="back-icon pointer">chevron_left</mat-icon> <mat-icon class="back-icon pointer">chevron_left</mat-icon>
{{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.PREVIOUS' | translate}} {{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.PREVIOUS' | translate}}
</button> </button>
<button *ngIf="stepper?.selectedIndex < (steps.length-1)" mat-button class="rounded-btn secondary ml-3" [@next_btn] (click)="stepper?.next();" [disabled]="!isStepCompleted(stepper?.selectedIndex)"> <button *ngIf="stepper?.selectedIndex < (steps.length-1)" mat-button class="rounded-btn secondary ml-3" [@next_btn] (click)="validateStep(stepper?.selectedIndex); stepper?.next();">
<!-- [disabled]="!isStepCompleted(stepper?.selectedIndex)" -->
<span>{{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.NEXT' | translate}}</span> <span>{{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.NEXT' | translate}}</span>
<mat-icon class="back-icon pointer" iconPositionEnd>chevron_right</mat-icon> <mat-icon class="back-icon pointer" iconPositionEnd>chevron_right</mat-icon>
</button> </button>

View File

@ -70,7 +70,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
steps: QueryList<CdkStep>; steps: QueryList<CdkStep>;
toCEntries: ToCEntry[]; toCEntries: ToCEntry[];
selectedTocEntry: ToCEntry; selectedTocEntry: ToCEntry;
colorizeInvalid: boolean = false;
tocEntryEnumValues = ToCEntryType; tocEntryEnumValues = ToCEntryType;
usersMap: Map<Guid, User> = new Map<Guid, User>(); usersMap: Map<Guid, User> = new Map<Guid, User>();
@ -445,11 +444,11 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
} }
validateStep(selectedIndex) { validateStep(selectedIndex) {
if (selectedIndex === 1) {//form description
if (this.formGroup.invalid) { if (this.formGroup.invalid) {
this.formService.touchAllFormFields(this.formGroup); this.formService.touchAllFormFields(this.formGroup);
this.checkFormValidation(selectedIndex); }
} }
} }
@ -1259,19 +1258,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
return (<UntypedFormArray>this.formGroup.get('definition').get('pages'))?.length; return (<UntypedFormArray>this.formGroup.get('definition').get('pages'))?.length;
} }
checkFormValidation(index: number) {
switch(index){
case 0: {
this.colorizeInvalid = true;
break;
}
case 1: {
this.showErrors = true;
break;
}
}
}
get progressStyle() { get progressStyle() {
const diff = 3; const diff = 3;

View File

@ -16,7 +16,6 @@
[draggingItemId]="draggingItemId" [draggingItemId]="draggingItemId"
[parentRootId]="ROOT_ID" [parentRootId]="ROOT_ID"
style="padding-right: 1em;" style="padding-right: 1em;"
[colorizeInvalid]="colorizeInvalid"
> >
</app-description-template-table-of-contents-internal-section> </app-description-template-table-of-contents-internal-section>
<div class="top-scroller table-scroller" [hidden]="!isDragging"> <div class="top-scroller table-scroller" [hidden]="!isDragging">

View File

@ -19,7 +19,6 @@ export class DescriptionTemplateTableOfContents extends BaseComponent implements
@Input() links: ToCEntry[]; @Input() links: ToCEntry[];
@Input() itemSelected: ToCEntry; @Input() itemSelected: ToCEntry;
@Input() colorizeInvalid: boolean = false;
@Input() viewOnly: boolean; @Input() viewOnly: boolean;
@Input() showErrors: boolean = false; @Input() showErrors: boolean = false;

View File

@ -3,8 +3,10 @@
<span class="table-label-element" <span class="table-label-element"
[ngClass]="{ [ngClass]="{
'table-label-element-active': itemSelected?.id == parentLink?.id, 'table-label-element-active': itemSelected?.id == parentLink?.id,
'text-danger': colorError() ||( (parentLink?.subEntriesType === tocEntryType.FieldSet )&& !colorError() && !selectedItemInLinks && parentLink?.form.invalid && colorizeInvalid && (itemSelected?.id != parentLink?.id) && !_findTocEntryById(itemSelected?.id, parentLink?.subEntries)), 'text-danger': parentLink.form?.touched && parentLink.form?.invalid,
'link-info-error': showErrors && !parentLink?.form?.valid
'link-info-error': showErrors && parentLink?.form?.invalid
}" }"
(click)="itemClicked(parentLink)" [ngStyle]="{'font-size' : (parentLink.type == tocEntryType.FieldSet? '.9rem':'1rem')}" [id]="'TABLE_ENTRY'+parentLink.id"> (click)="itemClicked(parentLink)" [ngStyle]="{'font-size' : (parentLink.type == tocEntryType.FieldSet? '.9rem':'1rem')}" [id]="'TABLE_ENTRY'+parentLink.id">
{{parentLink?.numbering}} {{parentLink?.form.get('title').value? parentLink?.form.get('title').value : 'DESCRIPTION-TEMPLATE-EDITOR.STEPS.GENERAL-INFO.UNTITLED' | translate}} {{parentLink?.numbering}} {{parentLink?.form.get('title').value? parentLink?.form.get('title').value : 'DESCRIPTION-TEMPLATE-EDITOR.STEPS.GENERAL-INFO.UNTITLED' | translate}}
@ -57,7 +59,6 @@
[isDragging]="isDragging" [isDragging]="isDragging"
[draggingItemId]="draggingItemId" [draggingItemId]="draggingItemId"
[parentRootId]="parentRootId" [parentRootId]="parentRootId"
[colorizeInvalid]="colorizeInvalid"
[showErrors]="showErrors" [showErrors]="showErrors"
(itemClick)="itemClicked($event)" (itemClick)="itemClicked($event)"
(removeEntry)="deleteEntry($event)" (removeEntry)="deleteEntry($event)"
@ -71,7 +72,7 @@
<ng-container *ngIf="!isDragging"> <ng-container *ngIf="!isDragging">
<ng-container *ngIf="selectedItemInLinks && (link.type != tocEntryType.Page) && isLast && (!viewOnly)"> <ng-container *ngIf="selectedItemInLinks && (link.type != tocEntryType.Page) && isLast && (!viewOnly)">
<button mat-button style="padding-left: 0px;" (click)="createNewEntry({childType:link.type,parent:parentLink})"> <button mat-button (click)="createNewEntry({childType:link.type,parent:parentLink})">
<ng-container [ngSwitch]="link.type"> <ng-container [ngSwitch]="link.type">
<ng-container *ngSwitchCase="tocEntryType.Section"> <ng-container *ngSwitchCase="tocEntryType.Section">
<div class="d-flex" style="align-items: center;"> <div class="d-flex" style="align-items: center;">
@ -110,7 +111,7 @@
<ng-container *ngIf="parentLink?.type != tocEntryType.FieldSet && !viewOnly && parentLink?.id == itemSelected?.id" > <ng-container *ngIf="parentLink?.type != tocEntryType.FieldSet && !viewOnly && parentLink?.id == itemSelected?.id" >
<div *ngIf="parentLink?.type == tocEntryType.Page; else notAPage" class="docs-link mt-0"> <div *ngIf="parentLink?.type == tocEntryType.Page; else notAPage" class="docs-link mt-0">
<div class="ml-3"> <div class="ml-3">
<button mat-button style="padding-left: 0px; display: block;" (click)="createNewEntry({childType:tocEntryType.Section,parent:parentLink})"> <button mat-button style="display: block;" (click)="createNewEntry({childType:tocEntryType.Section,parent:parentLink})">
<div class="d-flex" style="align-items: center;"> <div class="d-flex" style="align-items: center;">
<mat-icon color="accent" style="font-size: 1.6em;margin-left: -0.3em;">add</mat-icon> <mat-icon color="accent" style="font-size: 1.6em;margin-left: -0.3em;">add</mat-icon>
<!-- Create new subsection --> <!-- Create new subsection -->
@ -123,13 +124,13 @@
<div *ngIf="!links; else withSubItems" class="docs-link mt-0"> <div *ngIf="!links; else withSubItems" class="docs-link mt-0">
<div class="ml-3"> <div class="ml-3">
<!-- Give option to generate fieldset (only if parent is section) --> <!-- Give option to generate fieldset (only if parent is section) -->
<button *ngIf="parentLink.type == tocEntryType.Section" mat-button style="padding-left: 0px;" (click)="createNewEntry({childType:tocEntryType.FieldSet,parent:parentLink})"> <button *ngIf="parentLink.type == tocEntryType.Section" mat-button (click)="createNewEntry({childType:tocEntryType.FieldSet,parent:parentLink})">
<img src="/assets/images/editor/icons/add_input_set.svg" alt="" style="margin-left: -0.2em;" class="add-input-icon"> <img src="/assets/images/editor/icons/add_input_set.svg" alt="" style="margin-left: -0.2em;" class="add-input-icon">
{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.TOOLKIT.NEW-INPUT-SET' | translate}} {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.TOOLKIT.NEW-INPUT-SET' | translate}}
</button> </button>
<!-- Give option to generate section --> <!-- Give option to generate section -->
<button mat-button style="padding-left: 0px; display: block;" (click)="createNewEntry({childType:tocEntryType.Section,parent:parentLink})"> <button mat-button style="display: block;" (click)="createNewEntry({childType:tocEntryType.Section,parent:parentLink})">
<!-- Subsection + --> <!-- Subsection + -->
<div class="d-flex" style="align-items: center;"> <div class="d-flex" style="align-items: center;">
@ -147,7 +148,7 @@
<div class="ml-3"> <div class="ml-3">
<ng-container [ngSwitch]="linksType"> <ng-container [ngSwitch]="linksType">
<ng-container *ngSwitchCase="tocEntryType.Section"> <ng-container *ngSwitchCase="tocEntryType.Section">
<button mat-button style="padding-left: 0px; display: block;" (click)="createNewEntry({childType:tocEntryType.Section,parent:parentLink})"> <button mat-button style="display: block;" (click)="createNewEntry({childType:tocEntryType.Section,parent:parentLink})">
<div class="d-flex" style="align-items: center;"> <div class="d-flex" style="align-items: center;">
<mat-icon color="accent" style="font-size: 1.6em;margin-left: -0.3em;">add</mat-icon> <mat-icon color="accent" style="font-size: 1.6em;margin-left: -0.3em;">add</mat-icon>
<!-- Create new subsection --> <!-- Create new subsection -->
@ -156,7 +157,7 @@
</button> </button>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="tocEntryType.FieldSet"> <ng-container *ngSwitchCase="tocEntryType.FieldSet">
<button *ngIf="parentLink.type == tocEntryType.Section" mat-button style="padding-left: 0px;" (click)="createNewEntry({childType:tocEntryType.FieldSet,parent:parentLink})"> <button *ngIf="parentLink.type == tocEntryType.Section" mat-button (click)="createNewEntry({childType:tocEntryType.FieldSet,parent:parentLink})">
<img src="/assets/images/editor/icons/add_input_set.svg" alt="" style="margin-left: -0.2em;" class="add-input-icon"> <img src="/assets/images/editor/icons/add_input_set.svg" alt="" style="margin-left: -0.2em;" class="add-input-icon">
{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.TOOLKIT.NEW-INPUT-SET' | translate}} {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.TOOLKIT.NEW-INPUT-SET' | translate}}
</button> </button>
@ -171,7 +172,7 @@
<!-- Only for the page --> <!-- Only for the page -->
<div *ngIf="parentLink?.subEntriesType == tocEntryType.Page && !viewOnly"> <div *ngIf="parentLink?.subEntriesType == tocEntryType.Page && !viewOnly">
<button mat-button class="mt-2" (click)="createNewEntry({childType:parentLink.subEntriesType,parent:parentLink})" style="padding-left:0px"> <button mat-button class="mt-2" (click)="createNewEntry({childType:parentLink.subEntriesType,parent:parentLink})" >
<!-- <mat-icon>add</mat-icon> --> <!-- <mat-icon>add</mat-icon> -->
<div class="d-flex" style="align-items: center;"> <div class="d-flex" style="align-items: center;">
<mat-icon color="accent" style="font-size: 1.6em;margin-left: -0.3em;">add</mat-icon> <mat-icon color="accent" style="font-size: 1.6em;margin-left: -0.3em;">add</mat-icon>

View File

@ -29,7 +29,6 @@ export class DescriptionTemplateTableOfContentsInternalSection extends BaseCompo
@Input() draggingItemId: string; @Input() draggingItemId: string;
@Input() parentRootId: string; @Input() parentRootId: string;
@Input() colorizeInvalid: boolean = false;
@Input() viewOnly: boolean; @Input() viewOnly: boolean;
@Input() showErrors: boolean = false; @Input() showErrors: boolean = false;
@ -102,83 +101,4 @@ export class DescriptionTemplateTableOfContentsInternalSection extends BaseCompo
return tocEntryFound ? tocEntryFound : null; return tocEntryFound ? tocEntryFound : null;
} }
colorError(): boolean {
if (!this.colorizeInvalid) return false;
const form = this.parentLink.form;
if ((!form || form.valid || !form.touched) && this.parentLink.type !== this.tocEntryType.Page) return false;
const allFieldsAreTouched = this.allFieldsAreTouched(form);
//fieldset may have errros that are inside its controls and not in the fieldsetFormGroup
if (this.parentLink.type === this.tocEntryType.FieldSet && allFieldsAreTouched) return true;
if (form.errors && allFieldsAreTouched) return true;
//check if page has sections
if (this.parentLink.type === this.tocEntryType.Page && allFieldsAreTouched) {
const rootForm = form.root;
if (rootForm) {
const sections = rootForm.get('sections') as UntypedFormArray;
if (!sections.controls.find(section => section.get('page').value === this.parentLink.id)) {
return true;
}
}
}
//checking first child form controls if have errors
let hasErrors = false;
if (allFieldsAreTouched) {
if (form instanceof UntypedFormGroup) {
const formGroup = form as UntypedFormGroup;
const controls = Object.keys(formGroup.controls);
controls.forEach(control => {
if (formGroup.get(control).errors) {
hasErrors = true;
}
})
}
}
return hasErrors;
}
allFieldsAreTouched(aControl: AbstractControl) {//auto na testaroume
if (!aControl || aControl.untouched) return false;
if (aControl instanceof UntypedFormControl) {
return aControl.touched;
} else if (aControl instanceof UntypedFormGroup) {
const controlKeys = Object.keys((aControl as UntypedFormGroup).controls);
let areAllTouched = true;
controlKeys.forEach(key => {
if (!this.allFieldsAreTouched(aControl.get(key))) {
areAllTouched = false;
}
})
return areAllTouched;
} else if (aControl instanceof UntypedFormArray) {
const controls = (aControl as UntypedFormArray).controls;
let areAllTouched = true;
controls.forEach(control => {
if (!this.allFieldsAreTouched(control)) {
areAllTouched = false;
}
});
return areAllTouched;
}
return false;
}
} }