1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

search service implementation with lunr

This commit is contained in:
Kyle Spearrin
2018-08-13 09:42:52 -04:00
parent 4ca7a9709e
commit b724448081
7 changed files with 169 additions and 58 deletions

View File

@@ -4,7 +4,7 @@ import {
Output,
} from '@angular/core';
import { CipherService } from '../../abstractions/cipher.service';
import { SearchService } from '../../abstractions/search.service';
import { CipherView } from '../../models/view/cipherView';
@@ -23,11 +23,12 @@ export class CiphersComponent {
protected allCiphers: CipherView[] = [];
protected filter: (cipher: CipherView) => boolean = null;
constructor(protected cipherService: CipherService) { }
private searchTimeout: any = null;
constructor(protected searchService: SearchService) { }
async load(filter: (cipher: CipherView) => boolean = null) {
this.allCiphers = await this.cipherService.getAllDecrypted();
this.applyFilter(filter);
await this.applyFilter(filter);
this.loaded = true;
}
@@ -37,13 +38,18 @@ export class CiphersComponent {
await this.load(this.filter);
}
applyFilter(filter: (cipher: CipherView) => boolean = null) {
async applyFilter(filter: (cipher: CipherView) => boolean = null) {
this.filter = filter;
if (this.filter == null) {
this.ciphers = this.allCiphers;
} else {
this.ciphers = this.allCiphers.filter(this.filter);
await this.search(0);
}
search(timeout: number = 0) {
if (this.searchTimeout != null) {
clearTimeout(this.searchTimeout);
}
this.searchTimeout = setTimeout(async () => {
this.ciphers = await this.searchService.searchCiphers(this.searchText, this.filter);
}, timeout);
}
selectCipher(cipher: CipherView) {