You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
4.2 KiB
TypeScript
134 lines
4.2 KiB
TypeScript
3 years ago
|
import {
|
||
3 years ago
|
AfterViewChecked,
|
||
|
Component,
|
||
|
ElementRef,
|
||
|
EventEmitter,
|
||
|
Input,
|
||
|
OnInit,
|
||
|
Output,
|
||
|
ViewChild
|
||
|
} from "@angular/core";
|
||
3 years ago
|
import {FileService} from "../../../../services/file/file.service";
|
||
|
import {TagQuery} from "../../../../models/TagQuery";
|
||
|
import {SortKey} from "../../../../models/SortKey";
|
||
3 years ago
|
import {MatDialog} from "@angular/material/dialog";
|
||
3 years ago
|
import {SortDialogComponent} from "./sort-dialog/sort-dialog.component";
|
||
3 years ago
|
import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service";
|
||
3 years ago
|
import {
|
||
3 years ago
|
FilterExpression,
|
||
|
SingleFilterExpression
|
||
3 years ago
|
} from "../../../../models/FilterExpression";
|
||
3 years ago
|
import {FilterDialogComponent} from "./filter-dialog/filter-dialog.component";
|
||
3 years ago
|
import {Tag} from "../../../../models/Tag";
|
||
3 years ago
|
|
||
3 years ago
|
|
||
3 years ago
|
@Component({
|
||
3 years ago
|
selector: "app-file-search",
|
||
|
templateUrl: "./file-search.component.html",
|
||
|
styleUrls: ["./file-search.component.scss"]
|
||
3 years ago
|
})
|
||
3 years ago
|
export class FileSearchComponent implements AfterViewChecked, OnInit {
|
||
3 years ago
|
public sortExpression: SortKey[] = [new SortKey("FileImportedTime",
|
||
|
"Ascending", undefined)];
|
||
|
public filters: FilterExpression[] = [];
|
||
3 years ago
|
|
||
3 years ago
|
@Input() availableTags: Tag[] = [];
|
||
|
@Output() searchStartEvent = new EventEmitter<void>();
|
||
|
@Output() searchEndEvent = new EventEmitter<void>();
|
||
3 years ago
|
|
||
3 years ago
|
@ViewChild("tagInput") tagInput!: ElementRef<HTMLInputElement>;
|
||
|
@ViewChild("tagInputList") inputList!: ElementRef;
|
||
3 years ago
|
|
||
3 years ago
|
constructor(
|
||
|
private errorBroker: ErrorBrokerService,
|
||
|
private fileService: FileService,
|
||
|
public dialog: MatDialog
|
||
|
) {
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public async ngOnInit() {
|
||
|
await this.searchForFiles();
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public ngAfterViewChecked(): void {
|
||
|
this.inputList.nativeElement.scrollLeft = this.inputList.nativeElement.scrollWidth;
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public async searchForFiles() {
|
||
|
this.searchStartEvent.emit();
|
||
|
try {
|
||
|
await this.fileService.findFiles(this.filters, this.sortExpression);
|
||
|
} catch (err) {
|
||
|
this.errorBroker.showError(err);
|
||
|
}
|
||
|
this.searchEndEvent.emit();
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public addSearchTag(tag: string) {
|
||
|
this.filters.push(new SingleFilterExpression(TagQuery.fromString(tag)));
|
||
|
tag = tag.replace(/^-/g, "");
|
||
3 years ago
|
|
||
3 years ago
|
if (this.filters.filter(t => t.partiallyEq(tag)).length > 1) {
|
||
|
const index = this.filters.findIndex(t => t.partiallyEq(tag));
|
||
|
this.filters.splice(index, 1);
|
||
|
}
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public getValidSearchTags(): Tag[] {
|
||
|
return this.availableTags.filter(t => this.filters.findIndex(
|
||
|
f => f.partiallyEq(t.getNormalizedOutput())) < 0);
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
public async removeAllSearchTags() {
|
||
|
this.filters = [];
|
||
3 years ago
|
await this.searchForFiles();
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public async removeFilterExpression(expr: FilterExpression) {
|
||
|
const index = this.filters.indexOf(expr);
|
||
|
if (index >= 0) {
|
||
|
this.filters.splice(index, 1);
|
||
|
}
|
||
3 years ago
|
await this.searchForFiles();
|
||
3 years ago
|
}
|
||
|
|
||
|
public openSortDialog() {
|
||
|
const sortEntries = this.sortExpression.map(
|
||
|
key => JSON.parse(JSON.stringify(key))).map(
|
||
|
key => new SortKey(key.sortType, key.sortDirection,
|
||
|
key.namespaceName))
|
||
|
const openedDialog = this.dialog.open(SortDialogComponent, {
|
||
|
minWidth: "40vw",
|
||
|
data: {
|
||
|
sortEntries,
|
||
|
},
|
||
|
disableClose: true,
|
||
|
});
|
||
|
openedDialog.afterClosed().subscribe(async (sortExpression) => {
|
||
|
if (sortExpression) {
|
||
|
this.sortExpression = sortExpression;
|
||
|
await this.searchForFiles();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public openFilterDialog(): void {
|
||
|
const filterEntries = this.filters.map(f => f.clone());
|
||
|
const filterDialog = this.dialog.open(FilterDialogComponent, {
|
||
|
minWidth: "25vw",
|
||
|
maxHeight: "80vh",
|
||
|
data: {
|
||
|
filterEntries,
|
||
|
availableTags: this.availableTags,
|
||
|
},
|
||
|
disableClose: true,
|
||
|
});
|
||
|
filterDialog.afterClosed().subscribe(async (filterExpression) => {
|
||
|
if (filterExpression !== undefined || filterExpression?.length > 0) {
|
||
|
this.filters = filterExpression;
|
||
|
await this.searchForFiles();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
3 years ago
|
}
|