added form validation error state on description template save

This commit is contained in:
CITE\spapacharalampous 2024-08-12 12:00:41 +03:00
parent 98f6a70067
commit 2985c853b4
7 changed files with 50 additions and 16 deletions

View File

@ -145,14 +145,16 @@
<div class="row sticky-top table-container" style="top : 7em;"> <div class="row sticky-top table-container" style="top : 7em;">
<description-template-table-of-contents class="toc-pane-container col" style="margin-bottom: 2em;" <description-template-table-of-contents class="toc-pane-container col" style="margin-bottom: 2em;"
[links]="toCEntries" [links]="toCEntries"
(itemClick)="displayItem($event)" [itemSelected]="selectedTocEntry"
(createEntry)="addNewEntry($event)" [viewOnly]="formGroup.disabled"
(removeEntry)="onRemoveEntry($event)" [colorizeInvalid]="colorizeInvalid"
[itemSelected]="selectedTocEntry" [showErrors]="showErrors"
[viewOnly]="formGroup.disabled" (dataNeedsRefresh)="onDataNeedsRefresh($event)"
(dataNeedsRefresh)="onDataNeedsRefresh($event)" (itemClick)="displayItem($event)"
[colorizeInvalid]="colorizeInvalid"> (createEntry)="addNewEntry($event)"
(removeEntry)="onRemoveEntry($event)"
>
</description-template-table-of-contents> </description-template-table-of-contents>
</div> </div>
</div> </div>
@ -276,7 +278,7 @@
<ng-template #actions> <ng-template #actions>
<div> <div>
<button mat-raised-button class="template_action_btn mr-3" (click)="cancel()">{{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.CLOSE' | translate}}</button> <button mat-raised-button class="template_action_btn mr-3" (click)="cancel()">{{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.CLOSE' | translate}}</button>
<button [disabled]="!formGroup.valid" *ngIf="!formGroup.disabled && formGroup.get('status').value!=finalized" mat-raised-button class="template_action_btn save-btn" type="button"> <button *ngIf="!formGroup.disabled && formGroup.get('status').value!=finalized" mat-raised-button class="template_action_btn save-btn" type="button">
<span class="d-flex flex-row row"> <span class="d-flex flex-row row">
<span (click)="save(); formSubmit()" class="col">{{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.SAVE' | translate}}</span> <span (click)="save(); formSubmit()" class="col">{{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.SAVE' | translate}}</span>
<mat-divider [vertical]="true"></mat-divider> <mat-divider [vertical]="true"></mat-divider>
@ -286,8 +288,8 @@
</span> </span>
</button> </button>
<mat-menu #menuSave="matMenu"> <mat-menu #menuSave="matMenu">
<button [disabled]="!formGroup.valid" mat-menu-item (click)="saveWithClose(true)" type="button">{{ 'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.SAVE-AND-CLOSE' | translate }}</button> <button mat-menu-item (click)="saveWithClose(true)" type="button">{{ 'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.SAVE-AND-CLOSE' | translate }}</button>
<button [disabled]="!formGroup.valid" mat-menu-item (click)="saveWithClose(false)" type="button">{{ 'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.SAVE-AND-CONTINUE' | translate }}</button> <button mat-menu-item (click)="saveWithClose(false)" type="button">{{ 'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.SAVE-AND-CONTINUE' | translate }}</button>
</mat-menu> </mat-menu>
<button *ngIf="!formGroup.disabled && formGroup.get('status').value!= finalized && steps?.length-1 === stepper?.selectedIndex" [@finalize_btn] mat-button class="finalize-btn ml-3" [disabled]="!formGroup.valid" [class.invisible]="steps?.length-1 !== stepper?.selectedIndex" (click)="finalize()"> <button *ngIf="!formGroup.disabled && formGroup.get('status').value!= finalized && steps?.length-1 === stepper?.selectedIndex" [@finalize_btn] mat-button class="finalize-btn ml-3" [disabled]="!formGroup.valid" [class.invisible]="steps?.length-1 !== stepper?.selectedIndex" (click)="finalize()">

View File

@ -72,6 +72,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
isNewVersion = false; isNewVersion = false;
isClone = false; isClone = false;
showErrors: boolean = false;
steps: QueryList<CdkStep>; steps: QueryList<CdkStep>;
toCEntries: ToCEntry[]; toCEntries: ToCEntry[];
selectedTocEntry: ToCEntry; selectedTocEntry: ToCEntry;
@ -253,7 +254,10 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
this.descriptionTemplateService.persist(formData) this.descriptionTemplateService.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe( .pipe(takeUntil(this._destroyed)).subscribe(
complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete),
error => this.onCallbackError(error) error => {
this.onCallbackError(error);
if (error.status == 400) this.showErrors = true;
}
); );
} else if (this.isNewVersion == true && this.isNew == false && this.isClone == false) { } else if (this.isNewVersion == true && this.isNew == false && this.isClone == false) {
const formData = this.formService.getValue(this.formGroup.value) as NewVersionDescriptionTemplatePersist; const formData = this.formService.getValue(this.formGroup.value) as NewVersionDescriptionTemplatePersist;
@ -269,7 +273,11 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
formSubmit(onSuccess?: (response) => void): void { formSubmit(onSuccess?: (response) => void): void {
this.formService.removeAllBackEndErrors(this.formGroup); this.formService.removeAllBackEndErrors(this.formGroup);
this.formService.touchAllFormFields(this.formGroup); this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) { if (!this.isFormValid()) {
this.showErrors = true;
this.uiNotificationService.snackBarNotification(
this.language.instant("GENERAL.BACKEND-ERRORS.MODEL-VALIDATION"), SnackBarNotificationLevel.Error);
return; return;
} }

View File

@ -8,6 +8,7 @@
[parentLink]="{ subEntriesType: tocEntryType.Page, subEntries : links , id: ROOT_ID}" [parentLink]="{ subEntriesType: tocEntryType.Page, subEntries : links , id: ROOT_ID}"
[itemSelected]="itemSelected" [itemSelected]="itemSelected"
[viewOnly]="viewOnly" [viewOnly]="viewOnly"
[showErrors]="showErrors"
(dataNeedsRefresh)="onDataNeedsRefresh()" (dataNeedsRefresh)="onDataNeedsRefresh()"
[DRAGULA_ITEM_ID_PREFIX]="DRAGULA_ITEM_ID_PREFIX" [DRAGULA_ITEM_ID_PREFIX]="DRAGULA_ITEM_ID_PREFIX"
[overContainerId]="overcontainer" [overContainerId]="overcontainer"

View File

@ -21,7 +21,7 @@ export class DescriptionTemplateTableOfContents extends BaseComponent implements
@Input() itemSelected: ToCEntry; @Input() itemSelected: ToCEntry;
@Input() colorizeInvalid: boolean = false; @Input() colorizeInvalid: boolean = false;
@Input() viewOnly: boolean; @Input() viewOnly: boolean;
@Input() showErrors: boolean = false;
@Output() itemClick = new EventEmitter<ToCEntry>(); @Output() itemClick = new EventEmitter<ToCEntry>();
@Output() removeEntry = new EventEmitter<ToCEntry>(); @Output() removeEntry = new EventEmitter<ToCEntry>();
@ -38,7 +38,7 @@ export class DescriptionTemplateTableOfContents extends BaseComponent implements
private _dragStartedAt; private _dragStartedAt;
private VALID_DROP_TIME = 500;//ms private VALID_DROP_TIME = 500;//ms
overcontainer: string = null; overcontainer: string = null;
$clock = interval(10); $clock = interval(10);
scrollTableTop = false; scrollTableTop = false;
scrollTableBottom = false; scrollTableBottom = false;

View File

@ -1,6 +1,8 @@
<div class="table-item row align-items-center" *ngIf="!(parentLink.type == undefined)"> <div class="table-item row align-items-center" *ngIf="!(parentLink.type == undefined)">
<div class="col link-info"> <div class="col link-info">
<span class="table-label-element" [ngClass]="{'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))}" (click)="itemClicked(parentLink)" [ngStyle]="{'font-size' : (parentLink.type == tocEntryType.FieldSet? '.9rem':'1rem')}" [id]="'TABLE_ENTRY'+parentLink.id"> <span class="table-label-element"
[ngClass]="{'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)), 'link-info-error': showErrors && !parentLink?.form?.valid}"
(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}}
<ng-container *ngIf="!parentLink.form.get('title').value" [ngSwitch]="parentLink.type"> <ng-container *ngIf="!parentLink.form.get('title').value" [ngSwitch]="parentLink.type">
<ng-container *ngSwitchCase="tocEntryType.FieldSet"> <ng-container *ngSwitchCase="tocEntryType.FieldSet">
@ -41,7 +43,23 @@
<div class="docs-link mt-0"> <div class="docs-link mt-0">
<div [ngClass]="{'ml-3': link.type != tocEntryType.Page }"> <div [ngClass]="{'ml-3': link.type != tocEntryType.Page }">
<app-description-template-table-of-contents-internal-section [links]="link.subEntries" (itemClick)="itemClicked($event)" (removeEntry)="deleteEntry($event)" [parentLink]="link" [itemSelected]="itemSelected" (createFooEntry)="createNewEntry($event)" [viewOnly]="viewOnly" (dataNeedsRefresh)="onDataNeedsRefresh()" [DRAGULA_ITEM_ID_PREFIX]="DRAGULA_ITEM_ID_PREFIX" [overContainerId]="overContainerId" [isDragging]="isDragging" [draggingItemId]="draggingItemId" [parentRootId]="parentRootId" [colorizeInvalid]="colorizeInvalid"> <app-description-template-table-of-contents-internal-section
[links]="link.subEntries"
[parentLink]="link"
[itemSelected]="itemSelected"
[viewOnly]="viewOnly"
[DRAGULA_ITEM_ID_PREFIX]="DRAGULA_ITEM_ID_PREFIX"
[overContainerId]="overContainerId"
[isDragging]="isDragging"
[draggingItemId]="draggingItemId"
[parentRootId]="parentRootId"
[colorizeInvalid]="colorizeInvalid"
[showErrors]="showErrors"
(itemClick)="itemClicked($event)"
(removeEntry)="deleteEntry($event)"
(createFooEntry)="createNewEntry($event)"
(dataNeedsRefresh)="onDataNeedsRefresh()"
>
</app-description-template-table-of-contents-internal-section> </app-description-template-table-of-contents-internal-section>

View File

@ -46,4 +46,8 @@ $yellow: var(--secondary-color);
} }
.add-input-icon{ .add-input-icon{
width: 20px; width: 20px;
}
.link-info-error {
color: red;
} }

View File

@ -32,6 +32,7 @@ export class DescriptionTemplateTableOfContentsInternalSection extends BaseCompo
@Input() colorizeInvalid: boolean = false; @Input() colorizeInvalid: boolean = false;
@Input() viewOnly: boolean; @Input() viewOnly: boolean;
@Input() showErrors: boolean = false;
constructor( constructor(
@Inject(DOCUMENT) private _document: Document) { @Inject(DOCUMENT) private _document: Document) {