From 4280a76e148fb1df2b4e9e593a0be8671f0644f6 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Sun, 26 Dec 2021 23:47:40 +0100 Subject: [PATCH] Add frontend wildcard support TG-17 Signed-off-by: Trivernis --- mediarepo-ui/package.json | 2 +- mediarepo-ui/src-tauri/Cargo.lock | 2 +- mediarepo-ui/src-tauri/Cargo.toml | 2 +- mediarepo-ui/src-tauri/tauri.conf.json | 4 +-- .../input/tag-input/tag-input.component.html | 2 +- .../input/tag-input/tag-input.component.ts | 26 ++++++++++++++++--- .../file-search/file-search.component.html | 2 +- .../filter-dialog.component.html | 2 +- 8 files changed, 31 insertions(+), 11 deletions(-) diff --git a/mediarepo-ui/package.json b/mediarepo-ui/package.json index 973414c..9ac48dd 100644 --- a/mediarepo-ui/package.json +++ b/mediarepo-ui/package.json @@ -1,6 +1,6 @@ { "name": "mediarepo-ui", - "version": "0.10.0", + "version": "0.10.1", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/mediarepo-ui/src-tauri/Cargo.lock b/mediarepo-ui/src-tauri/Cargo.lock index 83f851b..a76437c 100644 --- a/mediarepo-ui/src-tauri/Cargo.lock +++ b/mediarepo-ui/src-tauri/Cargo.lock @@ -40,7 +40,7 @@ checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" [[package]] name = "app" -version = "0.10.0" +version = "0.10.1" dependencies = [ "mediarepo-api", "serde", diff --git a/mediarepo-ui/src-tauri/Cargo.toml b/mediarepo-ui/src-tauri/Cargo.toml index 8472d87..f44f16f 100644 --- a/mediarepo-ui/src-tauri/Cargo.toml +++ b/mediarepo-ui/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.10.0" +version = "0.10.1" description = "A Tauri App" authors = [ "you" ] license = "" diff --git a/mediarepo-ui/src-tauri/tauri.conf.json b/mediarepo-ui/src-tauri/tauri.conf.json index 246d8d2..bc302e1 100644 --- a/mediarepo-ui/src-tauri/tauri.conf.json +++ b/mediarepo-ui/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "package": { "productName": "mediarepo-ui", - "version": "0.10.0" + "version": "0.10.1" }, "build": { "distDir": "../dist/mediarepo-ui", @@ -26,7 +26,7 @@ "externalBin": [], "copyright": "", "category": "Productivity", - "shortDescription": "A media mangagement tool", + "shortDescription": "A media management tool", "longDescription": "", "deb": { "depends": [], diff --git a/mediarepo-ui/src/app/components/shared/input/tag-input/tag-input.component.html b/mediarepo-ui/src/app/components/shared/input/tag-input/tag-input.component.html index 53c8297..107971f 100644 --- a/mediarepo-ui/src/app/components/shared/input/tag-input/tag-input.component.html +++ b/mediarepo-ui/src/app/components/shared/input/tag-input/tag-input.component.html @@ -3,7 +3,7 @@ Enter a tag diff --git a/mediarepo-ui/src/app/components/shared/input/tag-input/tag-input.component.ts b/mediarepo-ui/src/app/components/shared/input/tag-input/tag-input.component.ts index b0628bc..9b9a3e6 100644 --- a/mediarepo-ui/src/app/components/shared/input/tag-input/tag-input.component.ts +++ b/mediarepo-ui/src/app/components/shared/input/tag-input/tag-input.component.ts @@ -24,6 +24,7 @@ export class TagInputComponent implements OnChanges { @Input() availableTags: Tag[] = []; @Input() allowNegation: boolean = false; @Input() allowInvalid: boolean = false; + @Input() allowWildcards: boolean = false; @Output() tagAdded = new EventEmitter(); @ViewChild("tagInput") tagInput!: ElementRef; @@ -48,8 +49,10 @@ export class TagInputComponent implements OnChanges { } } - public addTagByInput(event: any): void { - this.addTag(this.formControl.value); + public addTagByInput(event: KeyboardEvent): void { + if (event.key === "Enter") { + this.addTag(this.formControl.value); + } } public addTagByAutocomplete(event: MatAutocompleteSelectedEvent): void { @@ -70,18 +73,35 @@ export class TagInputComponent implements OnChanges { const negated = normalizedTag.startsWith("-") && this.allowNegation; normalizedTag = this.allowNegation ? normalizedTag.replace(/^-/, "") : normalizedTag; + const containsWildcard = normalizedTag.endsWith("*"); + normalizedTag = this.allowWildcards ? normalizedTag.replace(/\*\s*$/, + "") : normalizedTag; - return this.tagsForAutocomplete.filter( + const autocompleteTags = this.tagsForAutocomplete.filter( t => t.includes(normalizedTag)) .map(t => negated ? "-" + t : t) .sort((l, r) => this.compareSuggestionTags(normalizedTag, l, r)) .slice(0, 20); + + if (containsWildcard) { + autocompleteTags.unshift(this.normalizeTag(tag)); + } + + return autocompleteTags; } private checkTagValid(tag: string): boolean { if (this.allowNegation) { tag = tag.replace(/^-/, ""); } + if (tag.endsWith("*")) { + if (this.allowWildcards) { + return this.tagsForAutocomplete.findIndex( + t => t.startsWith(tag.trim().replace(/\*\s*$/, ""))) >= 0; + } else { + return false; + } + } return this.tagsForAutocomplete.includes(tag); } diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.html b/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.html index 7c67b14..7847689 100644 --- a/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.html +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/file-search.component.html @@ -14,7 +14,7 @@ -