Move more information to the tab state

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 018d1eb412
commit 02c013a1c3

@ -33,7 +33,7 @@
<div class="file-tag-list" fxFlex fxFlexAlign="start" fxFlexFill> <div class="file-tag-list" fxFlex fxFlexAlign="start" fxFlexFill>
<cdk-virtual-scroll-viewport itemSize="50" maxBufferPx="4000" minBufferPx="500"> <cdk-virtual-scroll-viewport itemSize="50" maxBufferPx="4000" minBufferPx="500">
<div (click)="addSearchTagAndSearch(tag.getNormalizedOutput())" <div (click)="addSearchTag(tag.getNormalizedOutput())"
(contextmenu)="contextMenuTag = tag; contextMenu.onContextMenu($event)" (contextmenu)="contextMenuTag = tag; contextMenu.onContextMenu($event)"
*cdkVirtualFor="let tag of contextTags" class="selectable-tag"> *cdkVirtualFor="let tag of contextTags" class="selectable-tag">
<app-tag-item [tag]="tag"></app-tag-item> <app-tag-item [tag]="tag"></app-tag-item>

@ -31,8 +31,7 @@ import {TabState} from "../../../../models/TabState.rs";
styleUrls: ["./file-search.component.scss"] styleUrls: ["./file-search.component.scss"]
}) })
export class FileSearchComponent implements AfterViewChecked, OnInit { export class FileSearchComponent implements AfterViewChecked, OnInit {
public sortExpression: SortKey[] = [new SortKey("FileImportedTime", public sortExpression: SortKey[] = [];
"Ascending", undefined)];
public filters: FilterExpression[] = []; public filters: FilterExpression[] = [];
@Input() availableTags: Tag[] = []; @Input() availableTags: Tag[] = [];
@ -54,6 +53,8 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
} }
public async ngOnInit() { public async ngOnInit() {
this.state.filters.subscribe(f => this.filters = f);
this.state.sortKeys.subscribe(s => this.sortExpression = s);
await this.searchForFiles(); await this.searchForFiles();
} }
@ -64,7 +65,7 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
public async searchForFiles() { public async searchForFiles() {
this.searchStartEvent.emit(); this.searchStartEvent.emit();
try { try {
await this.state.findFiles(this.filters, this.sortExpression); await this.state.findFiles();
} catch (err) { } catch (err) {
this.errorBroker.showError(err); this.errorBroker.showError(err);
} }
@ -79,11 +80,7 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
const index = this.filters.findIndex(t => t.partiallyEq(tag)); const index = this.filters.findIndex(t => t.partiallyEq(tag));
this.filters.splice(index, 1); this.filters.splice(index, 1);
} }
} this.state.setFilters(this.filters);
public async addSearchTagAndSearch(tag: string) {
this.addSearchTag(tag);
await this.searchForFiles();
} }
public getValidSearchTags(): Tag[] { public getValidSearchTags(): Tag[] {
@ -93,7 +90,7 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
public async removeAllSearchTags() { public async removeAllSearchTags() {
this.filters = []; this.filters = [];
await this.searchForFiles(); this.state.setFilters([]);
} }
public async removeFilterExpression(expr: FilterExpression) { public async removeFilterExpression(expr: FilterExpression) {
@ -101,7 +98,7 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
if (index >= 0) { if (index >= 0) {
this.filters.splice(index, 1); this.filters.splice(index, 1);
} }
await this.searchForFiles(); this.state.setFilters(this.filters);
} }
public openSortDialog() { public openSortDialog() {
@ -119,7 +116,7 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
openedDialog.afterClosed().subscribe(async (sortExpression) => { openedDialog.afterClosed().subscribe(async (sortExpression) => {
if (sortExpression) { if (sortExpression) {
this.sortExpression = sortExpression; this.sortExpression = sortExpression;
await this.searchForFiles(); this.state.setSortKeys(this.sortExpression);
} }
}); });
} }
@ -138,7 +135,7 @@ export class FileSearchComponent implements AfterViewChecked, OnInit {
filterDialog.afterClosed().subscribe(async (filterExpression) => { filterDialog.afterClosed().subscribe(async (filterExpression) => {
if (filterExpression !== undefined || filterExpression?.length > 0) { if (filterExpression !== undefined || filterExpression?.length > 0) {
this.filters = filterExpression; this.filters = filterExpression;
await this.searchForFiles(); this.state.setFilters(this.filters);
} }
}); });
} }

@ -4,11 +4,16 @@ import {FileService} from "../services/file/file.service";
import {File} from "./File"; import {File} from "./File";
import {FilterExpression} from "./FilterExpression"; import {FilterExpression} from "./FilterExpression";
import {SortKey} from "./SortKey"; import {SortKey} from "./SortKey";
import {debounceTime} from "rxjs/operators";
export class TabState { export class TabState {
public uuid: number; public uuid: number;
public category: TabCategory; public category: TabCategory;
public files = new BehaviorSubject<File[]>([]); public files = new BehaviorSubject<File[]>([]);
public filters = new BehaviorSubject<FilterExpression[]>([]);
public sortKeys = new BehaviorSubject<SortKey[]>(
[new SortKey("FileImportedTime",
"Ascending", undefined)]);
private fileService: FileService; private fileService: FileService;
@ -16,15 +21,23 @@ export class TabState {
this.category = category; this.category = category;
this.uuid = uuid; this.uuid = uuid;
this.fileService = fileService; this.fileService = fileService;
this.filters.pipe(debounceTime(500))
.subscribe(async () => await this.findFiles());
this.sortKeys.pipe(debounceTime(100))
.subscribe(async () => await this.findFiles());
} }
public async loadAllFiles() { public async findFiles() {
const files = await this.fileService.getAllFiles(); const files = await this.fileService.findFiles(this.filters.value,
this.sortKeys.value);
this.files.next(files); this.files.next(files);
} }
public async findFiles(filters: FilterExpression[], sortBy: SortKey[]) { public setFilters(filters: FilterExpression[]) {
const files = await this.fileService.findFiles(filters, sortBy); this.filters.next(filters);
this.files.next(files); }
public setSortKeys(keys: SortKey[]) {
this.sortKeys.next(keys)
} }
} }

Loading…
Cancel
Save