|
|
@ -81,8 +81,8 @@ export class GfTagsSelectorComponent |
|
|
public constructor() { |
|
|
public constructor() { |
|
|
this.tagInputControl.valueChanges |
|
|
this.tagInputControl.valueChanges |
|
|
.pipe(takeUntilDestroyed()) |
|
|
.pipe(takeUntilDestroyed()) |
|
|
.subscribe((value) => { |
|
|
.subscribe(() => { |
|
|
this.updateFilters(value ?? ''); |
|
|
this.updateFilters(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
addIcons({ addCircleOutline, closeOutline }); |
|
|
addIcons({ addCircleOutline, closeOutline }); |
|
|
@ -162,9 +162,8 @@ export class GfTagsSelectorComponent |
|
|
this.updateFilters(); |
|
|
this.updateFilters(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private filterTags(query: string = ''): SelectedTag[] { |
|
|
private filterTags(query: string): SelectedTag[] { |
|
|
const tags = this.tagsSelected() ?? []; |
|
|
const tagIds = this.getTagsSelectedAndReadOnly().map(({ id }) => { |
|
|
const tagIds = [...tags, ...(this.tagsReadOnly ?? [])].map(({ id }) => { |
|
|
|
|
|
return id; |
|
|
return id; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
@ -180,7 +179,7 @@ export class GfTagsSelectorComponent |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getTagNameToCreate(query: string = ''): string | null { |
|
|
private getTagNameToCreate(query: string): string | null { |
|
|
const name = query.trim(); |
|
|
const name = query.trim(); |
|
|
|
|
|
|
|
|
if (!name) { |
|
|
if (!name) { |
|
|
@ -189,8 +188,7 @@ export class GfTagsSelectorComponent |
|
|
|
|
|
|
|
|
const isExistingTagName = [ |
|
|
const isExistingTagName = [ |
|
|
...(this.tagsAvailable ?? []), |
|
|
...(this.tagsAvailable ?? []), |
|
|
...(this.tagsReadOnly ?? []), |
|
|
...this.getTagsSelectedAndReadOnly() |
|
|
...(this.tagsSelected() ?? []) |
|
|
|
|
|
].some((tag) => { |
|
|
].some((tag) => { |
|
|
return tag.name.toLowerCase() === name.toLowerCase(); |
|
|
return tag.name.toLowerCase() === name.toLowerCase(); |
|
|
}); |
|
|
}); |
|
|
@ -198,6 +196,10 @@ export class GfTagsSelectorComponent |
|
|
return isExistingTagName ? null : name; |
|
|
return isExistingTagName ? null : name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getTagsSelectedAndReadOnly(): SelectedTag[] { |
|
|
|
|
|
return [...this.tagsSelected(), ...(this.tagsReadOnly ?? [])]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
private onChange = (_value: SelectedTag[]): void => { |
|
|
private onChange = (_value: SelectedTag[]): void => { |
|
|
// ControlValueAccessor onChange callback
|
|
|
// ControlValueAccessor onChange callback
|
|
|
@ -207,7 +209,9 @@ export class GfTagsSelectorComponent |
|
|
// ControlValueAccessor onTouched callback
|
|
|
// ControlValueAccessor onTouched callback
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
private updateFilters(query: string = '') { |
|
|
private updateFilters() { |
|
|
|
|
|
const query = this.tagInputControl.value ?? ''; |
|
|
|
|
|
|
|
|
this.filteredOptions.next(this.filterTags(query)); |
|
|
this.filteredOptions.next(this.filterTags(query)); |
|
|
this.tagNameToCreate.set(this.getTagNameToCreate(query)); |
|
|
this.tagNameToCreate.set(this.getTagNameToCreate(query)); |
|
|
} |
|
|
} |
|
|
|