mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-08-14 17:58:21 +00:00
[ACS-9374] Simplify HTML by handling error state in TypeScript
This commit is contained in:
@@ -574,7 +574,7 @@
|
|||||||
"FILES": "Files",
|
"FILES": "Files",
|
||||||
"FOLDERS": "Folders",
|
"FOLDERS": "Folders",
|
||||||
"LIBRARIES": "Libraries",
|
"LIBRARIES": "Libraries",
|
||||||
"HINT": "Search input must have at least 2 alphanumeric characters.",
|
"MIN_LENGTH": "Search input must have at least 2 alphanumeric characters.",
|
||||||
"REQUIRED": "Search input is required.",
|
"REQUIRED": "Search input is required.",
|
||||||
"WHITESPACE": "Search input cannot be only whitespace."
|
"WHITESPACE": "Search input cannot be only whitespace."
|
||||||
},
|
},
|
||||||
|
@@ -29,9 +29,9 @@ import { MatButtonModule } from '@angular/material/button';
|
|||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
import { MatInputModule } from '@angular/material/input';
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
import { FormControl, FormsModule, ReactiveFormsModule, StatusChangeEvent, TouchedChangeEvent, Validators } from '@angular/forms';
|
||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
import { noWhitespaceValidator } from 'projects/aca-shared/src/lib/validators/no-whitespace.validator';
|
import { noWhitespaceValidator } from '@alfresco/aca-shared';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
imports: [CommonModule, TranslatePipe, MatButtonModule, MatIconModule, MatFormFieldModule, MatInputModule, FormsModule, ReactiveFormsModule],
|
imports: [CommonModule, TranslatePipe, MatButtonModule, MatIconModule, MatFormFieldModule, MatInputModule, FormsModule, ReactiveFormsModule],
|
||||||
@@ -48,6 +48,13 @@ export class SearchInputControlComponent implements OnInit {
|
|||||||
@Input()
|
@Input()
|
||||||
inputType = 'text';
|
inputType = 'text';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the search is constrained by libraries.
|
||||||
|
* If true, specific error messaging or validation behavior may be triggered.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
hasLibrariesConstraint: boolean;
|
||||||
|
|
||||||
/** Emitted when the search is submitted pressing ENTER button.
|
/** Emitted when the search is submitted pressing ENTER button.
|
||||||
* The search term is provided as value of the event.
|
* The search term is provided as value of the event.
|
||||||
*/
|
*/
|
||||||
@@ -63,6 +70,10 @@ export class SearchInputControlComponent implements OnInit {
|
|||||||
@Output()
|
@Output()
|
||||||
searchChange: EventEmitter<string> = new EventEmitter();
|
searchChange: EventEmitter<string> = new EventEmitter();
|
||||||
|
|
||||||
|
/** Emitted when the input control has a validation error. */
|
||||||
|
@Output()
|
||||||
|
validationError = new EventEmitter<string>();
|
||||||
|
|
||||||
@ViewChild('searchInput', { static: true })
|
@ViewChild('searchInput', { static: true })
|
||||||
searchInput: ElementRef;
|
searchInput: ElementRef;
|
||||||
|
|
||||||
@@ -81,6 +92,25 @@ export class SearchInputControlComponent implements OnInit {
|
|||||||
this.searchFieldFormControl.markAsTouched();
|
this.searchFieldFormControl.markAsTouched();
|
||||||
this.searchChange.emit(searchTermValue);
|
this.searchChange.emit(searchTermValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.searchFieldFormControl.events.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((event) => {
|
||||||
|
if (event instanceof TouchedChangeEvent || event instanceof StatusChangeEvent) {
|
||||||
|
if (this.searchFieldFormControl.touched) {
|
||||||
|
const errors = this.searchFieldFormControl.errors;
|
||||||
|
if (errors?.whitespace) {
|
||||||
|
this.validationError.emit('SEARCH.INPUT.WHITESPACE');
|
||||||
|
} else if (this.hasLibrariesConstraint) {
|
||||||
|
this.validationError.emit('SEARCH.INPUT.MIN_LENGTH');
|
||||||
|
} else if (errors?.required) {
|
||||||
|
this.validationError.emit('SEARCH.INPUT.REQUIRED');
|
||||||
|
} else {
|
||||||
|
this.validationError.emit('');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.validationError.emit('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openDropdown() {
|
openDropdown() {
|
||||||
|
@@ -35,21 +35,11 @@
|
|||||||
(click)="$event.stopPropagation()"
|
(click)="$event.stopPropagation()"
|
||||||
(submit)="onSearchSubmit($event)"
|
(submit)="onSearchSubmit($event)"
|
||||||
(searchChange)="onSearchChange($event)"
|
(searchChange)="onSearchChange($event)"
|
||||||
|
(validationError)="error = $event"
|
||||||
|
[hasLibrariesConstraint]="hasLibrariesConstraint"
|
||||||
/>
|
/>
|
||||||
<mat-error *ngIf="searchInputControl.searchFieldFormControl.touched" class="app-search-error">
|
<mat-error *ngIf="error" class="app-search-error">
|
||||||
<ng-container *ngIf="hasLibrariesConstraint; else checkRequired">
|
{{ error | translate }}
|
||||||
{{ 'SEARCH.INPUT.HINT' | translate }}
|
|
||||||
</ng-container>
|
|
||||||
<ng-template #checkRequired>
|
|
||||||
<ng-container *ngIf="searchInputControl.searchFieldFormControl.errors?.required; else checkWhitespace">
|
|
||||||
{{ 'SEARCH.INPUT.REQUIRED' | translate }}
|
|
||||||
</ng-container>
|
|
||||||
</ng-template>
|
|
||||||
<ng-template #checkWhitespace>
|
|
||||||
<ng-container *ngIf="searchInputControl.searchFieldFormControl.errors?.whitespace">
|
|
||||||
{{ 'SEARCH.INPUT.WHITESPACE' | translate }}
|
|
||||||
</ng-container>
|
|
||||||
</ng-template>
|
|
||||||
</mat-error>
|
</mat-error>
|
||||||
<div id="search-options" class="app-search-options">
|
<div id="search-options" class="app-search-options">
|
||||||
<mat-checkbox *ngFor="let option of searchOptions"
|
<mat-checkbox *ngFor="let option of searchOptions"
|
||||||
|
@@ -74,6 +74,7 @@ export class SearchInputComponent implements OnInit, OnDestroy {
|
|||||||
hasLibrariesConstraint = false;
|
hasLibrariesConstraint = false;
|
||||||
searchOnChange: boolean;
|
searchOnChange: boolean;
|
||||||
isTrimmedWordEmpty = false;
|
isTrimmedWordEmpty = false;
|
||||||
|
error = '';
|
||||||
|
|
||||||
searchedWord: string = null;
|
searchedWord: string = null;
|
||||||
searchOptions: Array<SearchOptionModel> = [
|
searchOptions: Array<SearchOptionModel> = [
|
||||||
|
@@ -40,6 +40,7 @@ export * from './lib/components/document-base-page/document-base-page.component'
|
|||||||
export * from './lib/components/document-base-page/document-base-page.service';
|
export * from './lib/components/document-base-page/document-base-page.service';
|
||||||
export * from './lib/components/open-in-app/open-in-app.component';
|
export * from './lib/components/open-in-app/open-in-app.component';
|
||||||
export * from './lib/constants';
|
export * from './lib/constants';
|
||||||
|
|
||||||
export * from './lib/directives/contextmenu/contextmenu.directive';
|
export * from './lib/directives/contextmenu/contextmenu.directive';
|
||||||
export * from './lib/directives/pagination.directive';
|
export * from './lib/directives/pagination.directive';
|
||||||
|
|
||||||
@@ -60,5 +61,8 @@ export * from './lib/services/app-settings.service';
|
|||||||
export * from './lib/services/user-profile.service';
|
export * from './lib/services/user-profile.service';
|
||||||
export * from './lib/services/navigation-history.service';
|
export * from './lib/services/navigation-history.service';
|
||||||
|
|
||||||
export * from './lib/utils/node.utils';
|
|
||||||
export * from './lib/testing/lib-testing-module';
|
export * from './lib/testing/lib-testing-module';
|
||||||
|
|
||||||
|
export * from './lib/utils/node.utils';
|
||||||
|
|
||||||
|
export * from './lib/validators/no-whitespace.validator';
|
||||||
|
Reference in New Issue
Block a user