mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ACS-7583] ACC tag rename get fail with some special char. (#9737)
This commit is contained in:
parent
ad1904ce41
commit
43d5df1a01
@ -381,7 +381,7 @@ describe('TagsCreatorComponent', () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should show error for prohibited characters', fakeAsync(() => {
|
it('should show error for prohibited characters', fakeAsync(() => {
|
||||||
typeTag('tag*"<>\\/?:|');
|
typeTag('tag*"<>\\/?:|{}()^');
|
||||||
component.tagNameControl.markAsTouched();
|
component.tagNameControl.markAsTouched();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const error = getFirstError();
|
const error = getFirstError();
|
||||||
|
@ -16,18 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { TagEntry, TagPaging } from '@alfresco/js-api';
|
import { TagEntry, TagPaging } from '@alfresco/js-api';
|
||||||
import {
|
import { Component, ElementRef, EventEmitter, HostBinding, Input, OnDestroy, OnInit, Output, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||||
Component,
|
|
||||||
ElementRef,
|
|
||||||
EventEmitter,
|
|
||||||
HostBinding,
|
|
||||||
Input,
|
|
||||||
OnDestroy,
|
|
||||||
OnInit,
|
|
||||||
Output,
|
|
||||||
ViewChild,
|
|
||||||
ViewEncapsulation
|
|
||||||
} from '@angular/core';
|
|
||||||
import { FormControl, Validators } from '@angular/forms';
|
import { FormControl, Validators } from '@angular/forms';
|
||||||
import { debounce, distinctUntilChanged, finalize, first, map, takeUntil, tap } from 'rxjs/operators';
|
import { debounce, distinctUntilChanged, finalize, first, map, takeUntil, tap } from 'rxjs/operators';
|
||||||
import { EMPTY, forkJoin, Observable, Subject, timer } from 'rxjs';
|
import { EMPTY, forkJoin, Observable, Subject, timer } from 'rxjs';
|
||||||
@ -142,12 +131,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
private _tags: string[] = [];
|
private _tags: string[] = [];
|
||||||
private _tagNameControl = new FormControl<string>(
|
private _tagNameControl = new FormControl<string>(
|
||||||
'',
|
'',
|
||||||
[
|
[this.validateIfNotAlreadyAdded.bind(this), Validators.required, this.validateEmptyTag, this.validateSpecialCharacters],
|
||||||
this.validateIfNotAlreadyAdded.bind(this),
|
|
||||||
Validators.required,
|
|
||||||
this.validateEmptyTag,
|
|
||||||
this.validateSpecialCharacters
|
|
||||||
],
|
|
||||||
this.validateIfNotExistingTag.bind(this)
|
this.validateIfNotExistingTag.bind(this)
|
||||||
);
|
);
|
||||||
private _tagNameControlVisible = false;
|
private _tagNameControlVisible = false;
|
||||||
@ -167,10 +151,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
@ViewChild('tagNameInput')
|
@ViewChild('tagNameInput')
|
||||||
private tagNameInputElement: ElementRef;
|
private tagNameInputElement: ElementRef;
|
||||||
|
|
||||||
constructor(
|
constructor(private tagService: TagService, private notificationService: NotificationService) {}
|
||||||
private tagService: TagService,
|
|
||||||
private notificationService: NotificationService
|
|
||||||
) {}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.tagNameControl.valueChanges
|
this.tagNameControl.valueChanges
|
||||||
@ -193,9 +174,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
)
|
)
|
||||||
.subscribe((name: string) => this.onTagNameControlValueChange(name));
|
.subscribe((name: string) => this.onTagNameControlValueChange(name));
|
||||||
|
|
||||||
this.tagNameControl.statusChanges
|
this.tagNameControl.statusChanges.pipe(takeUntil(this.onDestroy$)).subscribe(() => this.setTagNameControlErrorMessageKey());
|
||||||
.pipe(takeUntil(this.onDestroy$))
|
|
||||||
.subscribe(() => this.setTagNameControlErrorMessageKey());
|
|
||||||
|
|
||||||
this.setTagNameControlErrorMessageKey();
|
this.setTagNameControlErrorMessageKey();
|
||||||
}
|
}
|
||||||
@ -218,7 +197,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns `true` if tags empty and non editable state, otherwise `false`
|
* Returns `true` if tags empty and non editable state, otherwise `false`
|
||||||
*/
|
*/
|
||||||
get showEmptyTagMessage(): boolean {
|
get showEmptyTagMessage(): boolean {
|
||||||
return this.tags?.length === 0 && !this.tagNameControlVisible;
|
return this.tags?.length === 0 && !this.tagNameControlVisible;
|
||||||
}
|
}
|
||||||
@ -307,29 +286,31 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
forkJoin({
|
forkJoin({
|
||||||
exactResult: this.tagService.findTagByName(name),
|
exactResult: this.tagService.findTagByName(name),
|
||||||
searchedResult: this.tagService.searchTags(name, DEFAULT_TAGS_SORTING, false, 0, this.existingTagsListLimit)
|
searchedResult: this.tagService.searchTags(name, DEFAULT_TAGS_SORTING, false, 0, this.existingTagsListLimit)
|
||||||
}).pipe(
|
})
|
||||||
takeUntil(this.cancelExistingTagsLoading$),
|
.pipe(
|
||||||
finalize(() => (this._typing = false))
|
takeUntil(this.cancelExistingTagsLoading$),
|
||||||
).subscribe(({ exactResult, searchedResult }: {
|
finalize(() => (this._typing = false))
|
||||||
exactResult: TagEntry;
|
)
|
||||||
searchedResult: TagPaging;
|
.subscribe(
|
||||||
}) => {
|
({ exactResult, searchedResult }: { exactResult: TagEntry; searchedResult: TagPaging }) => {
|
||||||
if (exactResult) {
|
if (exactResult) {
|
||||||
this.existingExactTag = exactResult;
|
this.existingExactTag = exactResult;
|
||||||
this.removeExactTagFromSearchedResult(searchedResult);
|
this.removeExactTagFromSearchedResult(searchedResult);
|
||||||
searchedResult.list.entries.unshift(exactResult);
|
searchedResult.list.entries.unshift(exactResult);
|
||||||
} else {
|
} else {
|
||||||
this.existingExactTag = null;
|
this.existingExactTag = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._initialExistingTags = searchedResult.list.entries;
|
this._initialExistingTags = searchedResult.list.entries;
|
||||||
this.excludeAlreadyAddedTags(this._initialExistingTags);
|
this.excludeAlreadyAddedTags(this._initialExistingTags);
|
||||||
this.exactTagSet$.next();
|
this.exactTagSet$.next();
|
||||||
this._spinnerVisible = false;
|
this._spinnerVisible = false;
|
||||||
}, () => {
|
},
|
||||||
this.notificationService.showError('TAG.TAGS_CREATOR.ERRORS.FETCH_TAGS');
|
() => {
|
||||||
this._spinnerVisible = false;
|
this.notificationService.showError('TAG.TAGS_CREATOR.ERRORS.FETCH_TAGS');
|
||||||
});
|
this._spinnerVisible = false;
|
||||||
|
}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.existingExactTag = null;
|
this.existingExactTag = null;
|
||||||
this._spinnerVisible = false;
|
this._spinnerVisible = false;
|
||||||
@ -337,9 +318,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private removeExactTagFromSearchedResult(searchedResult: TagPaging): void {
|
private removeExactTagFromSearchedResult(searchedResult: TagPaging): void {
|
||||||
const exactTagIndex = searchedResult.list.entries.findIndex(
|
const exactTagIndex = searchedResult.list.entries.findIndex((row) => this.compareTags(row.entry.tag, this.existingExactTag.entry.tag));
|
||||||
(row) => this.compareTags(row.entry.tag, this.existingExactTag.entry.tag)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (exactTagIndex > -1) {
|
if (exactTagIndex > -1) {
|
||||||
searchedResult.list.entries.splice(exactTagIndex, 1);
|
searchedResult.list.entries.splice(exactTagIndex, 1);
|
||||||
@ -349,16 +328,14 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
private validateIfNotExistingTag(tagNameControl: FormControl<string>): Observable<TagNameControlErrors | null> {
|
private validateIfNotExistingTag(tagNameControl: FormControl<string>): Observable<TagNameControlErrors | null> {
|
||||||
return this.exactTagSet$.pipe(
|
return this.exactTagSet$.pipe(
|
||||||
map<void, TagNameControlErrors | null>(() =>
|
map<void, TagNameControlErrors | null>(() =>
|
||||||
this.compareTags(tagNameControl.value, this.existingExactTag?.entry?.tag) ? { duplicatedExistingTag: true }
|
this.compareTags(tagNameControl.value, this.existingExactTag?.entry?.tag) ? { duplicatedExistingTag: true } : null
|
||||||
: null
|
),
|
||||||
), first()
|
first()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private validateIfNotAlreadyAdded(tagNameControl: FormControl<string>): TagNameControlErrors | null {
|
private validateIfNotAlreadyAdded(tagNameControl: FormControl<string>): TagNameControlErrors | null {
|
||||||
return this.tags.some((tag) => this.compareTags(tag, tagNameControl.value))
|
return this.tags.some((tag) => this.compareTags(tag, tagNameControl.value)) ? { duplicatedAddedTag: true } : null;
|
||||||
? { duplicatedAddedTag: true }
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private compareTags(tagName1?: string, tagName2?: string): boolean {
|
private compareTags(tagName1?: string, tagName2?: string): boolean {
|
||||||
@ -366,16 +343,12 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private validateEmptyTag(tagNameControl: FormControl<string>): TagNameControlErrors | null {
|
private validateEmptyTag(tagNameControl: FormControl<string>): TagNameControlErrors | null {
|
||||||
return tagNameControl.value.length && !tagNameControl.value.trim()
|
return tagNameControl.value.length && !tagNameControl.value.trim() ? { emptyTag: true } : null;
|
||||||
? { emptyTag: true }
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private validateSpecialCharacters(tagNameControl: FormControl<string>): TagNameControlErrors | null {
|
private validateSpecialCharacters(tagNameControl: FormControl<string>): TagNameControlErrors | null {
|
||||||
const specialSymbolsRegex = /[':"\\|<>/?]/;
|
const specialSymbolsRegex = /[{}()^':"\\|<>/?]/;
|
||||||
return tagNameControl.value.length && specialSymbolsRegex.test(tagNameControl.value)
|
return tagNameControl.value.length && specialSymbolsRegex.test(tagNameControl.value) ? { specialCharacters: true } : null;
|
||||||
? { specialCharacters: true }
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private setTagNameControlErrorMessageKey(): void {
|
private setTagNameControlErrorMessageKey(): void {
|
||||||
@ -388,9 +361,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
private checkScrollbarVisibility(): void {
|
private checkScrollbarVisibility(): void {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this._tagsListScrollbarVisible =
|
this._tagsListScrollbarVisible = this.tagsListElement.nativeElement.scrollHeight > this.tagsListElement.nativeElement.clientHeight;
|
||||||
this.tagsListElement.nativeElement.scrollHeight >
|
|
||||||
this.tagsListElement.nativeElement.clientHeight;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,9 +370,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateExistingTagsListOnRemoveFromTagsToConfirm(tag: string) {
|
private updateExistingTagsListOnRemoveFromTagsToConfirm(tag: string) {
|
||||||
const entryForTagAddedToExistingTags = this._initialExistingTags?.find(
|
const entryForTagAddedToExistingTags = this._initialExistingTags?.find((tagEntry) => tagEntry.entry.tag === tag);
|
||||||
(tagEntry) => tagEntry.entry.tag === tag
|
|
||||||
);
|
|
||||||
if (entryForTagAddedToExistingTags) {
|
if (entryForTagAddedToExistingTags) {
|
||||||
this.existingTags.unshift(entryForTagAddedToExistingTags);
|
this.existingTags.unshift(entryForTagAddedToExistingTags);
|
||||||
if (this.existingExactTag) {
|
if (this.existingExactTag) {
|
||||||
@ -418,8 +387,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private sortExistingTags() {
|
private sortExistingTags() {
|
||||||
this.existingTags.sort((tagEntry1, tagEntry2) =>
|
this.existingTags.sort((tagEntry1, tagEntry2) => tagEntry1.entry.tag.localeCompare(tagEntry2.entry.tag));
|
||||||
tagEntry1.entry.tag.localeCompare(tagEntry2.entry.tag));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private excludeAlreadyAddedTags(tags: TagEntry[]) {
|
private excludeAlreadyAddedTags(tags: TagEntry[]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user