Files
clients/libs/angular/src/components/vault-items.component.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
2.6 KiB
TypeScript
Raw Normal View History

import { Directive, EventEmitter, Input, Output } from "@angular/core";
2022-06-14 17:10:53 +02:00
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { Organization } from "@bitwarden/common/models/domain/organization";
import { CipherView } from "@bitwarden/common/models/view/cipher.view";
@Directive()
export class VaultItemsComponent {
@Input() activeCipherId: string = null;
@Output() onCipherClicked = new EventEmitter<CipherView>();
@Output() onCipherRightClicked = new EventEmitter<CipherView>();
@Output() onAddCipher = new EventEmitter();
@Output() onAddCipherOptions = new EventEmitter();
2021-12-16 13:36:21 +01:00
2022-02-22 15:39:11 +01:00
loaded = false;
ciphers: CipherView[] = [];
searchText: string;
searchPlaceholder: string = null;
2018-08-22 22:35:18 -04:00
filter: (cipher: CipherView) => boolean = null;
2022-02-22 15:39:11 +01:00
deleted = false;
organization: Organization;
accessEvents = false;
2021-12-16 13:36:21 +01:00
2018-08-13 11:52:55 -04:00
protected searchPending = false;
2021-12-16 13:36:21 +01:00
private searchTimeout: any = null;
2021-12-16 13:36:21 +01:00
constructor(protected searchService: SearchService) {}
2021-12-16 13:36:21 +01:00
2022-02-22 15:39:11 +01:00
async load(filter: (cipher: CipherView) => boolean = null, deleted = false) {
this.deleted = deleted || false;
await this.applyFilter(filter);
this.loaded = true;
}
2021-12-16 13:36:21 +01:00
2022-02-22 15:39:11 +01:00
async reload(filter: (cipher: CipherView) => boolean = null, deleted = false) {
this.loaded = false;
await this.load(filter, deleted);
}
2021-12-16 13:36:21 +01:00
async refresh() {
await this.reload(this.filter, this.deleted);
}
2021-12-16 13:36:21 +01:00
async applyFilter(filter: (cipher: CipherView) => boolean = null) {
2018-07-03 23:33:15 -04:00
this.filter = filter;
2018-08-13 11:52:55 -04:00
await this.search(null);
}
2021-12-16 13:36:21 +01:00
async search(timeout: number = null, indexedCiphers?: CipherView[]) {
2018-08-13 11:52:55 -04:00
this.searchPending = false;
if (this.searchTimeout != null) {
clearTimeout(this.searchTimeout);
2018-07-03 23:33:15 -04:00
}
if (timeout == null) {
await this.doSearch(indexedCiphers);
return;
}
2018-08-13 11:52:55 -04:00
this.searchPending = true;
this.searchTimeout = setTimeout(async () => {
2021-08-11 06:36:16 +10:00
await this.doSearch(indexedCiphers);
2018-08-13 11:52:55 -04:00
this.searchPending = false;
}, timeout);
2021-12-16 13:36:21 +01:00
}
selectCipher(cipher: CipherView) {
this.onCipherClicked.emit(cipher);
2021-12-16 13:36:21 +01:00
}
rightClickCipher(cipher: CipherView) {
this.onCipherRightClicked.emit(cipher);
2021-12-16 13:36:21 +01:00
}
addCipher() {
this.onAddCipher.emit();
2021-12-16 13:36:21 +01:00
}
addCipherOptions() {
this.onAddCipherOptions.emit();
2021-12-16 13:36:21 +01:00
}
isSearching() {
return !this.searchPending && this.searchService.isSearchable(this.searchText);
2021-12-16 13:36:21 +01:00
}
protected deletedFilter: (cipher: CipherView) => boolean = (c) => c.isDeleted === this.deleted;
2021-12-16 13:36:21 +01:00
protected async doSearch(indexedCiphers?: CipherView[]) {
this.ciphers = await this.searchService.searchCiphers(
this.searchText,
[this.filter, this.deletedFilter],
indexedCiphers
2021-12-16 13:36:21 +01:00
);
}
}