mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-06-02 17:34:51 +00:00
[ACA-1957] Create Library - warn existing library title name (#763)
* hint existing library title name * unsubscribe
This commit is contained in:
parent
66769fc0c8
commit
eb034e59a9
@ -12,6 +12,7 @@
|
|||||||
[formControl]="form.controls['title']"
|
[formControl]="form.controls['title']"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<mat-hint *ngIf="libraryTitleExists">{{ 'LIBRARY.HINTS.SITE_TITLE_EXISTS' | translate }}</mat-hint>
|
||||||
<mat-error *ngIf="form.controls['title'].hasError('maxlength')">
|
<mat-error *ngIf="form.controls['title'].hasError('maxlength')">
|
||||||
{{ 'LIBRARY.ERRORS.DESCRIPTION_TOO_LONG' | translate }}
|
{{ 'LIBRARY.ERRORS.DESCRIPTION_TOO_LONG' | translate }}
|
||||||
</mat-error>
|
</mat-error>
|
||||||
|
@ -12,6 +12,10 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mat-form-field {
|
||||||
|
padding-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.actions-buttons {
|
.actions-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
@ -15,28 +15,38 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable, Subject } from 'rxjs';
|
||||||
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
|
import {
|
||||||
|
Component,
|
||||||
|
OnInit,
|
||||||
|
Output,
|
||||||
|
EventEmitter,
|
||||||
|
OnDestroy
|
||||||
|
} from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
import { MatDialogRef } from '@angular/material';
|
import { MatDialogRef } from '@angular/material';
|
||||||
import { SiteBody, SiteEntry } from 'alfresco-js-api';
|
import { SiteBody, SiteEntry, SitePaging } from 'alfresco-js-api';
|
||||||
import { ContentApiService } from '../../services/content-api.service';
|
import { ContentApiService } from '../../services/content-api.service';
|
||||||
import { SiteIdValidator, forbidSpecialCharacters } from './form.validators';
|
import { SiteIdValidator, forbidSpecialCharacters } from './form.validators';
|
||||||
import { debounceTime } from 'rxjs/operators';
|
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||||
|
import { debounceTime, mergeMap, takeUntil } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-library-dialog',
|
selector: 'app-library-dialog',
|
||||||
styleUrls: ['./library.dialog.scss'],
|
styleUrls: ['./library.dialog.scss'],
|
||||||
templateUrl: './library.dialog.html'
|
templateUrl: './library.dialog.html'
|
||||||
})
|
})
|
||||||
export class LibraryDialogComponent implements OnInit {
|
export class LibraryDialogComponent implements OnInit, OnDestroy {
|
||||||
@Output()
|
@Output()
|
||||||
error: EventEmitter<any> = new EventEmitter<any>();
|
error: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
success: EventEmitter<any> = new EventEmitter<any>();
|
success: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
|
onDestroy$: Subject<boolean> = new Subject<boolean>();
|
||||||
|
|
||||||
createTitle = 'LIBRARY.DIALOG.CREATE_TITLE';
|
createTitle = 'LIBRARY.DIALOG.CREATE_TITLE';
|
||||||
|
libraryTitleExists = false;
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
visibilityOption: any;
|
visibilityOption: any;
|
||||||
visibilityOptions = [
|
visibilityOptions = [
|
||||||
@ -50,6 +60,7 @@ export class LibraryDialogComponent implements OnInit {
|
|||||||
];
|
];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private alfrescoApiService: AlfrescoApiService,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private dialog: MatDialogRef<LibraryDialogComponent>,
|
private dialog: MatDialogRef<LibraryDialogComponent>,
|
||||||
private contentApi: ContentApiService
|
private contentApi: ContentApiService
|
||||||
@ -75,19 +86,28 @@ export class LibraryDialogComponent implements OnInit {
|
|||||||
this.visibilityOption = this.visibilityOptions[0].value;
|
this.visibilityOption = this.visibilityOptions[0].value;
|
||||||
|
|
||||||
this.form.controls['title'].valueChanges
|
this.form.controls['title'].valueChanges
|
||||||
.pipe(debounceTime(300))
|
.pipe(
|
||||||
.subscribe((titleValue: string) => {
|
debounceTime(300),
|
||||||
if (!titleValue.trim().length) {
|
mergeMap(title => this.checkLibraryNameExists(title), title => title),
|
||||||
|
takeUntil(this.onDestroy$)
|
||||||
|
)
|
||||||
|
.subscribe((title: string) => {
|
||||||
|
if (!title.trim().length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.form.controls['id'].dirty) {
|
if (!this.form.controls['id'].dirty) {
|
||||||
this.form.patchValue({ id: this.sanitize(titleValue.trim()) });
|
this.form.patchValue({ id: this.sanitize(title.trim()) });
|
||||||
this.form.controls['id'].markAsTouched();
|
this.form.controls['id'].markAsTouched();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.onDestroy$.next(true);
|
||||||
|
this.onDestroy$.complete();
|
||||||
|
}
|
||||||
|
|
||||||
get title(): string {
|
get title(): string {
|
||||||
const { title } = this.form.value;
|
const { title } = this.form.value;
|
||||||
|
|
||||||
@ -159,4 +179,16 @@ export class LibraryDialogComponent implements OnInit {
|
|||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async checkLibraryNameExists(libraryTitle: string) {
|
||||||
|
const { entries } = (await this.findLibraryByTitle(libraryTitle)).list;
|
||||||
|
this.libraryTitleExists = !!entries.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
private findLibraryByTitle(libraryTitle: string): Promise<SitePaging> {
|
||||||
|
return this.alfrescoApiService
|
||||||
|
.getInstance()
|
||||||
|
.core.queriesApi.findSites(libraryTitle)
|
||||||
|
.catch(() => ({ list: { entries: [] } }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,6 +298,9 @@
|
|||||||
"PUBLIC": "Public",
|
"PUBLIC": "Public",
|
||||||
"MODERATED": "Moderated"
|
"MODERATED": "Moderated"
|
||||||
},
|
},
|
||||||
|
"HINTS": {
|
||||||
|
"SITE_TITLE_EXISTS": "Library name already in use"
|
||||||
|
},
|
||||||
"ERRORS": {
|
"ERRORS": {
|
||||||
"GENERIC": "We hit a problem",
|
"GENERIC": "We hit a problem",
|
||||||
"EXISTENT_SITE": "This Library ID isn't available. Try a different Library ID.",
|
"EXISTENT_SITE": "This Library ID isn't available. Try a different Library ID.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user