[ACA-1957] Create Library - check existent site title by field (#765)

* clean form controls

* check found site by title field
This commit is contained in:
Cilibiu Bogdan 2018-10-30 13:48:42 +02:00 committed by Denys Vuika
parent 0b65ff46a0
commit fd692b6b8c
2 changed files with 13 additions and 5 deletions

View File

@ -9,7 +9,7 @@
placeholder="{{ 'LIBRARY.DIALOG.FORM.NAME' | translate }}" placeholder="{{ 'LIBRARY.DIALOG.FORM.NAME' | translate }}"
required required
matInput matInput
[formControl]="form.controls['title']" formControlName="title"
/> />
<mat-hint *ngIf="libraryTitleExists">{{ 'LIBRARY.HINTS.SITE_TITLE_EXISTS' | translate }}</mat-hint> <mat-hint *ngIf="libraryTitleExists">{{ 'LIBRARY.HINTS.SITE_TITLE_EXISTS' | translate }}</mat-hint>
@ -23,7 +23,7 @@
required required
placeholder="{{ 'LIBRARY.DIALOG.FORM.SITE_ID' | translate }}" placeholder="{{ 'LIBRARY.DIALOG.FORM.SITE_ID' | translate }}"
matInput matInput
[formControl]="form.controls['id']" formControlName="id"
/> />
<mat-error *ngIf="form.controls['id'].errors?.message"> <mat-error *ngIf="form.controls['id'].errors?.message">
@ -40,7 +40,7 @@
matInput matInput
placeholder="{{ 'LIBRARY.DIALOG.FORM.DESCRIPTION' | translate }}" placeholder="{{ 'LIBRARY.DIALOG.FORM.DESCRIPTION' | translate }}"
rows="3" rows="3"
[formControl]="form.controls['description']"></textarea> formControlName="description"></textarea>
<mat-error *ngIf="form.controls['description'].hasError('maxlength')"> <mat-error *ngIf="form.controls['description'].hasError('maxlength')">
{{ 'LIBRARY.ERRORS.DESCRIPTION_TOO_LONG' | translate }} {{ 'LIBRARY.ERRORS.DESCRIPTION_TOO_LONG' | translate }}

View File

@ -182,13 +182,21 @@ export class LibraryDialogComponent implements OnInit, OnDestroy {
private async checkLibraryNameExists(libraryTitle: string) { private async checkLibraryNameExists(libraryTitle: string) {
const { entries } = (await this.findLibraryByTitle(libraryTitle)).list; const { entries } = (await this.findLibraryByTitle(libraryTitle)).list;
this.libraryTitleExists = !!entries.length;
if (entries.length) {
this.libraryTitleExists = entries[0].entry.title === libraryTitle;
} else {
this.libraryTitleExists = false;
}
} }
private findLibraryByTitle(libraryTitle: string): Promise<SitePaging> { private findLibraryByTitle(libraryTitle: string): Promise<SitePaging> {
return this.alfrescoApiService return this.alfrescoApiService
.getInstance() .getInstance()
.core.queriesApi.findSites(libraryTitle) .core.queriesApi.findSites(libraryTitle, {
maxItems: 1,
fields: ['title']
})
.catch(() => ({ list: { entries: [] } })); .catch(() => ({ list: { entries: [] } }));
} }
} }