Add feature to add tags from the tag list to the search expression

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 29eb82e687
commit a50bb88ba8

@ -1,5 +1,11 @@
export type Tag = { export class Tag {
id: number, constructor(
name: string, public id: number,
namespace: string | undefined, public name: string,
public namespace: string | undefined
) {}
public getNormalizedOutput(): string {
return this.namespace ? this.namespace + ':' + this.name : this.name
}
}; };

@ -23,9 +23,9 @@
<div id="file-tag-list"> <div id="file-tag-list">
<h1>Selection Tags</h1> <h1>Selection Tags</h1>
<mat-selection-list [multiple]="false" *ngIf="tags.length > 0"> <mat-selection-list [multiple]="false" *ngIf="tags.length > 0" (selectionChange)="addSearchTagFromList($event)">
<mat-list-option <mat-list-option
*ngFor="let tag of tags">{{tag.namespace ? tag.namespace + ':' + tag.name : tag.name}}</mat-list-option> *ngFor="let tag of tags" [value]="tag.getNormalizedOutput()">{{tag.getNormalizedOutput()}}</mat-list-option>
</mat-selection-list> </mat-selection-list>
</div> </div>
</div> </div>

@ -9,6 +9,7 @@ import {TagService} from "../../services/tag/tag.service";
import {Tag} from "../../models/Tag"; import {Tag} from "../../models/Tag";
import {MatChipInputEvent} from "@angular/material/chips"; import {MatChipInputEvent} from "@angular/material/chips";
import {COMMA, ENTER} from "@angular/cdk/keycodes"; import {COMMA, ENTER} from "@angular/cdk/keycodes";
import {MatSelectionListChange} from "@angular/material/list";
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
@ -65,6 +66,15 @@ export class HomeComponent implements OnInit {
await this.fileService.findFiles(this.searchTags); await this.fileService.findFiles(this.searchTags);
} }
async addSearchTagFromList(event: MatSelectionListChange) {
if (event.options.length > 0) {
const tag = event.options[0].value;
this.searchTags.push(tag);
await this.fileService.findFiles(this.searchTags);
}
event.source.deselectAll();
}
async addSearchTag(event: MatChipInputEvent) { async addSearchTag(event: MatChipInputEvent) {
const tag = event.value.trim(); const tag = event.value.trim();
if (tag.length > 0) { if (tag.length > 0) {

@ -10,6 +10,7 @@ export class TagService {
constructor() { } constructor() { }
public async getTagsForFile(hash: string): Promise<Tag[]> { public async getTagsForFile(hash: string): Promise<Tag[]> {
return await invoke<Tag[]>("get_tags_for_file", {hash}); const tags = await invoke<Tag[]>("get_tags_for_file", {hash});
return tags.map(t => new Tag(t.id, t.name, t.namespace));
} }
} }

Loading…
Cancel
Save