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 = {
id: number,
name: string,
namespace: string | undefined,
export class Tag {
constructor(
public id: number,
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">
<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
*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>
</div>
</div>

@ -9,6 +9,7 @@ import {TagService} from "../../services/tag/tag.service";
import {Tag} from "../../models/Tag";
import {MatChipInputEvent} from "@angular/material/chips";
import {COMMA, ENTER} from "@angular/cdk/keycodes";
import {MatSelectionListChange} from "@angular/material/list";
@Component({
selector: 'app-home',
@ -65,6 +66,15 @@ export class HomeComponent implements OnInit {
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) {
const tag = event.value.trim();
if (tag.length > 0) {

@ -10,6 +10,7 @@ export class TagService {
constructor() { }
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