Add frontend wildcard support

TG-17

Signed-off-by: Trivernis <trivernis@protonmail.com>
pull/4/head
Trivernis 3 years ago
parent 3527a12e5d
commit 4280a76e14

@ -1,6 +1,6 @@
{ {
"name": "mediarepo-ui", "name": "mediarepo-ui",
"version": "0.10.0", "version": "0.10.1",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve", "start": "ng serve",

@ -40,7 +40,7 @@ checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
[[package]] [[package]]
name = "app" name = "app"
version = "0.10.0" version = "0.10.1"
dependencies = [ dependencies = [
"mediarepo-api", "mediarepo-api",
"serde", "serde",

@ -1,6 +1,6 @@
[package] [package]
name = "app" name = "app"
version = "0.10.0" version = "0.10.1"
description = "A Tauri App" description = "A Tauri App"
authors = [ "you" ] authors = [ "you" ]
license = "" license = ""

@ -1,7 +1,7 @@
{ {
"package": { "package": {
"productName": "mediarepo-ui", "productName": "mediarepo-ui",
"version": "0.10.0" "version": "0.10.1"
}, },
"build": { "build": {
"distDir": "../dist/mediarepo-ui", "distDir": "../dist/mediarepo-ui",
@ -26,7 +26,7 @@
"externalBin": [], "externalBin": [],
"copyright": "", "copyright": "",
"category": "Productivity", "category": "Productivity",
"shortDescription": "A media mangagement tool", "shortDescription": "A media management tool",
"longDescription": "", "longDescription": "",
"deb": { "deb": {
"depends": [], "depends": [],

@ -3,7 +3,7 @@
Enter a tag Enter a tag
</mat-label> </mat-label>
<input #tagInput <input #tagInput
(keydown.enter)="addTagByInput($event)" (keydown)="addTagByInput($event)"
[formControl]="formControl" [formControl]="formControl"
[matAutocomplete]="auto" [matAutocomplete]="auto"
matInput> matInput>

@ -24,6 +24,7 @@ export class TagInputComponent implements OnChanges {
@Input() availableTags: Tag[] = []; @Input() availableTags: Tag[] = [];
@Input() allowNegation: boolean = false; @Input() allowNegation: boolean = false;
@Input() allowInvalid: boolean = false; @Input() allowInvalid: boolean = false;
@Input() allowWildcards: boolean = false;
@Output() tagAdded = new EventEmitter<string>(); @Output() tagAdded = new EventEmitter<string>();
@ViewChild("tagInput") tagInput!: ElementRef<HTMLInputElement>; @ViewChild("tagInput") tagInput!: ElementRef<HTMLInputElement>;
@ -48,9 +49,11 @@ export class TagInputComponent implements OnChanges {
} }
} }
public addTagByInput(event: any): void { public addTagByInput(event: KeyboardEvent): void {
if (event.key === "Enter") {
this.addTag(this.formControl.value); this.addTag(this.formControl.value);
} }
}
public addTagByAutocomplete(event: MatAutocompleteSelectedEvent): void { public addTagByAutocomplete(event: MatAutocompleteSelectedEvent): void {
this.addTag(event.option.value); this.addTag(event.option.value);
@ -70,18 +73,35 @@ export class TagInputComponent implements OnChanges {
const negated = normalizedTag.startsWith("-") && this.allowNegation; const negated = normalizedTag.startsWith("-") && this.allowNegation;
normalizedTag = this.allowNegation ? normalizedTag.replace(/^-/, normalizedTag = this.allowNegation ? normalizedTag.replace(/^-/,
"") : normalizedTag; "") : 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)) t => t.includes(normalizedTag))
.map(t => negated ? "-" + t : t) .map(t => negated ? "-" + t : t)
.sort((l, r) => this.compareSuggestionTags(normalizedTag, l, r)) .sort((l, r) => this.compareSuggestionTags(normalizedTag, l, r))
.slice(0, 20); .slice(0, 20);
if (containsWildcard) {
autocompleteTags.unshift(this.normalizeTag(tag));
}
return autocompleteTags;
} }
private checkTagValid(tag: string): boolean { private checkTagValid(tag: string): boolean {
if (this.allowNegation) { if (this.allowNegation) {
tag = tag.replace(/^-/, ""); 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); return this.tagsForAutocomplete.includes(tag);
} }

@ -14,7 +14,7 @@
</button> </button>
</div> </div>
<app-tag-input (tagAdded)="addSearchTag($event); searchForFiles()" [allowNegation]="true" <app-tag-input [allowWildcards]="true" (tagAdded)="addSearchTag($event); searchForFiles()" [allowNegation]="true"
[availableTags]="getValidSearchTags()" [availableTags]="getValidSearchTags()"
class="full-width"> class="full-width">
<button (click)="openFilterDialog()" class="filter-dialog-button" mat-button> <button (click)="openFilterDialog()" class="filter-dialog-button" mat-button>

@ -13,7 +13,7 @@
</mat-list> </mat-list>
</div> </div>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<app-tag-input (tagAdded)="this.addFilter($event)" [allowNegation]="true" [availableTags]="this.availableTags" <app-tag-input [allowWildcards]="true" (tagAdded)="this.addFilter($event)" [allowNegation]="true" [availableTags]="this.availableTags"
class="tag-input"></app-tag-input> class="tag-input"></app-tag-input>
</div> </div>
<div class="dialog-actions" mat-dialog-actions> <div class="dialog-actions" mat-dialog-actions>

Loading…
Cancel
Save