2018-08-16 21:11:09 +02:00
|
|
|
import { Location } from "@angular/common";
|
2018-04-05 04:59:42 +02:00
|
|
|
import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit } from "@angular/core";
|
2018-04-09 16:50:28 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2022-07-12 20:25:18 +02:00
|
|
|
import { firstValueFrom } from "rxjs";
|
2021-10-14 23:58:59 +02:00
|
|
|
import { first } from "rxjs/operators";
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-08-08 21:08:35 +02:00
|
|
|
import { VaultFilter } from "@bitwarden/angular/vault/vault-filter/models/vault-filter.model";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
|
|
|
|
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
|
|
|
import { SyncService } from "@bitwarden/common/abstractions/sync.service";
|
|
|
|
import { CipherType } from "@bitwarden/common/enums/cipherType";
|
|
|
|
import { TreeNode } from "@bitwarden/common/models/domain/treeNode";
|
|
|
|
import { CipherView } from "@bitwarden/common/models/view/cipherView";
|
|
|
|
import { CollectionView } from "@bitwarden/common/models/view/collectionView";
|
|
|
|
import { FolderView } from "@bitwarden/common/models/view/folderView";
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-02-24 18:14:04 +01:00
|
|
|
import { BrowserGroupingsComponentState } from "src/models/browserGroupingsComponentState";
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-02-24 18:14:04 +01:00
|
|
|
import { BrowserApi } from "../../browser/browserApi";
|
2022-01-27 22:22:51 +01:00
|
|
|
import { StateService } from "../../services/abstractions/state.service";
|
2022-05-09 14:19:18 +02:00
|
|
|
import { VaultFilterService } from "../../services/vaultFilter.service";
|
2018-04-09 20:17:58 +02:00
|
|
|
import { PopupUtilsService } from "../services/popup-utils.service";
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-05-09 14:19:18 +02:00
|
|
|
const ComponentId = "VaultComponent";
|
2018-04-06 21:33:20 +02:00
|
|
|
|
2018-04-05 04:59:42 +02:00
|
|
|
@Component({
|
2022-05-09 14:19:18 +02:00
|
|
|
selector: "app-vault-filter",
|
|
|
|
templateUrl: "vault-filter.component.html",
|
2018-04-05 04:59:42 +02:00
|
|
|
})
|
2022-05-09 14:19:18 +02:00
|
|
|
export class VaultFilterComponent implements OnInit, OnDestroy {
|
2021-04-23 10:45:20 +02:00
|
|
|
get showNoFolderCiphers(): boolean {
|
2021-12-21 15:43:35 +01:00
|
|
|
return (
|
2021-04-23 10:45:20 +02:00
|
|
|
this.noFolderCiphers != null &&
|
|
|
|
this.noFolderCiphers.length < this.noFolderListSize &&
|
|
|
|
this.collections.length === 0
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-23 10:45:20 +02:00
|
|
|
get folderCount(): number {
|
|
|
|
return this.nestedFolders.length - (this.showNoFolderCiphers ? 0 : 1);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2022-05-09 14:19:18 +02:00
|
|
|
folders: FolderView[];
|
|
|
|
nestedFolders: TreeNode<FolderView>[];
|
|
|
|
collections: CollectionView[];
|
|
|
|
nestedCollections: TreeNode<CollectionView>[];
|
|
|
|
loaded = false;
|
|
|
|
cipherType = CipherType;
|
2018-04-05 16:29:11 +02:00
|
|
|
ciphers: CipherView[];
|
|
|
|
favoriteCiphers: CipherView[];
|
2018-04-05 23:27:31 +02:00
|
|
|
noFolderCiphers: CipherView[];
|
2018-04-05 16:29:11 +02:00
|
|
|
folderCounts = new Map<string, number>();
|
|
|
|
collectionCounts = new Map<string, number>();
|
|
|
|
typeCounts = new Map<CipherType, number>();
|
2018-04-09 16:50:28 +02:00
|
|
|
searchText: string;
|
2022-01-27 22:22:51 +01:00
|
|
|
state: BrowserGroupingsComponentState;
|
2018-04-14 05:37:57 +02:00
|
|
|
showLeftHeader = true;
|
2018-08-13 17:53:16 +02:00
|
|
|
searchPending = false;
|
2019-03-14 03:54:18 +01:00
|
|
|
searchTypeSearch = false;
|
2020-04-13 17:32:56 +02:00
|
|
|
deletedCount = 0;
|
2022-05-09 14:19:18 +02:00
|
|
|
vaultFilter: VaultFilter;
|
|
|
|
selectedOrganization: string = null;
|
|
|
|
showCollections = true;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-12 21:56:27 +02:00
|
|
|
private loadedTimeout: number;
|
|
|
|
private selectedTimeout: number;
|
|
|
|
private preventSelected = false;
|
2018-04-14 05:22:20 +02:00
|
|
|
private noFolderListSize = 100;
|
2018-08-13 17:53:16 +02:00
|
|
|
private searchTimeout: any = null;
|
|
|
|
private hasSearched = false;
|
|
|
|
private hasLoadedAllCiphers = false;
|
2018-08-17 05:33:07 +02:00
|
|
|
private allCiphers: CipherView[] = null;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-05 16:29:11 +02:00
|
|
|
constructor(
|
2018-04-06 21:33:20 +02:00
|
|
|
private cipherService: CipherService,
|
|
|
|
private router: Router,
|
|
|
|
private ngZone: NgZone,
|
|
|
|
private broadcasterService: BroadcasterService,
|
2018-04-09 20:17:58 +02:00
|
|
|
private changeDetectorRef: ChangeDetectorRef,
|
|
|
|
private route: ActivatedRoute,
|
2018-04-11 04:49:19 +02:00
|
|
|
private popupUtils: PopupUtilsService,
|
2021-04-14 23:43:09 +02:00
|
|
|
private syncService: SyncService,
|
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private searchService: SearchService,
|
2022-01-27 22:22:51 +01:00
|
|
|
private location: Location,
|
2022-05-09 14:19:18 +02:00
|
|
|
private browserStateService: StateService,
|
|
|
|
private vaultFilterService: VaultFilterService
|
2021-12-21 15:43:35 +01:00
|
|
|
) {
|
2020-09-15 16:50:45 +02:00
|
|
|
this.noFolderListSize = 100;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:56:27 +02:00
|
|
|
async ngOnInit() {
|
2019-03-14 03:54:18 +01:00
|
|
|
this.searchTypeSearch = !this.platformUtilsService.isSafari();
|
2021-02-03 20:36:05 +01:00
|
|
|
this.showLeftHeader = !(
|
|
|
|
this.popupUtils.inSidebar(window) && this.platformUtilsService.isFirefox()
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.browserStateService.setBrowserCipherComponentState(null);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-09 20:17:58 +02:00
|
|
|
this.broadcasterService.subscribe(ComponentId, (message: any) => {
|
2018-04-06 21:33:20 +02:00
|
|
|
this.ngZone.run(async () => {
|
|
|
|
switch (message.command) {
|
|
|
|
case "syncCompleted":
|
2018-11-27 15:28:36 +01:00
|
|
|
window.setTimeout(() => {
|
|
|
|
this.load();
|
2021-12-21 15:43:35 +01:00
|
|
|
}, 500);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-04-23 10:45:20 +02:00
|
|
|
|
|
|
|
this.changeDetectorRef.detectChanges();
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-12 21:56:27 +02:00
|
|
|
const restoredScopeState = await this.restoreState();
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-04-23 10:45:20 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async (params) => {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.state = await this.browserStateService.getBrowserGroupingComponentState();
|
|
|
|
if (this.state?.searchText) {
|
2021-04-23 10:45:20 +02:00
|
|
|
this.searchText = this.state.searchText;
|
|
|
|
} else if (params.searchText) {
|
2018-04-09 16:50:28 +02:00
|
|
|
this.searchText = params.searchText;
|
2021-04-23 10:45:20 +02:00
|
|
|
this.location.replaceState("vault");
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 10:45:20 +02:00
|
|
|
if (!this.syncService.syncInProgress) {
|
2018-04-12 21:56:27 +02:00
|
|
|
this.load();
|
2021-12-21 15:43:35 +01:00
|
|
|
} else {
|
2021-04-23 10:45:20 +02:00
|
|
|
this.loadedTimeout = window.setTimeout(() => {
|
|
|
|
if (!this.loaded) {
|
2018-04-12 21:56:27 +02:00
|
|
|
this.load();
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2018-04-14 19:40:25 +02:00
|
|
|
}, 5000);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 10:45:20 +02:00
|
|
|
if (!this.syncService.syncInProgress || restoredScopeState) {
|
2022-01-27 22:22:51 +01:00
|
|
|
window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state?.scrollY), 0);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-23 10:45:20 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.loadedTimeout != null) {
|
|
|
|
window.clearTimeout(this.loadedTimeout);
|
|
|
|
}
|
|
|
|
if (this.selectedTimeout != null) {
|
|
|
|
window.clearTimeout(this.selectedTimeout);
|
|
|
|
}
|
2018-04-05 16:29:11 +02:00
|
|
|
this.saveState();
|
|
|
|
this.broadcasterService.unsubscribe(ComponentId);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-05 16:29:11 +02:00
|
|
|
async load() {
|
2022-05-09 14:19:18 +02:00
|
|
|
this.vaultFilter = this.vaultFilterService.getVaultFilter();
|
|
|
|
|
|
|
|
this.updateSelectedOrg();
|
|
|
|
await this.loadCollectionsAndFolders();
|
2018-08-13 17:53:16 +02:00
|
|
|
await this.loadCiphers();
|
2022-05-09 14:19:18 +02:00
|
|
|
|
2018-08-17 05:33:07 +02:00
|
|
|
if (this.showNoFolderCiphers && this.nestedFolders.length > 0) {
|
2018-04-05 16:29:11 +02:00
|
|
|
// Remove "No Folder" from folder listing
|
|
|
|
this.nestedFolders = this.nestedFolders.slice(0, this.nestedFolders.length - 1);
|
|
|
|
}
|
|
|
|
|
2022-05-09 14:19:18 +02:00
|
|
|
this.loaded = true;
|
2018-04-06 21:33:20 +02:00
|
|
|
}
|
|
|
|
|
2021-10-14 23:58:59 +02:00
|
|
|
async loadCiphers() {
|
2018-04-09 20:17:58 +02:00
|
|
|
this.allCiphers = await this.cipherService.getAllDecrypted();
|
2018-04-11 04:49:19 +02:00
|
|
|
if (!this.hasLoadedAllCiphers) {
|
2018-04-12 21:56:27 +02:00
|
|
|
this.hasLoadedAllCiphers = !this.searchService.isSearchable(this.searchText);
|
2018-04-06 21:33:20 +02:00
|
|
|
}
|
2018-08-13 17:53:16 +02:00
|
|
|
await this.search(null);
|
2022-05-09 14:19:18 +02:00
|
|
|
this.getCounts();
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-05-09 14:19:18 +02:00
|
|
|
async loadCollections() {
|
2022-05-16 18:18:04 +02:00
|
|
|
const allCollections = await this.vaultFilterService.buildCollections(
|
|
|
|
this.selectedOrganization
|
|
|
|
);
|
2022-05-09 14:19:18 +02:00
|
|
|
this.collections = allCollections.fullList;
|
|
|
|
this.nestedCollections = allCollections.nestedList;
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-05-09 14:19:18 +02:00
|
|
|
async loadFolders() {
|
2022-07-12 20:25:18 +02:00
|
|
|
const allFolders = await firstValueFrom(
|
|
|
|
this.vaultFilterService.buildNestedFolders(this.selectedOrganization)
|
|
|
|
);
|
2022-05-09 14:19:18 +02:00
|
|
|
this.folders = allFolders.fullList;
|
2022-07-12 20:25:18 +02:00
|
|
|
this.nestedFolders = allFolders.nestedList;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-09 20:17:58 +02:00
|
|
|
async search(timeout: number = null) {
|
|
|
|
this.searchPending = false;
|
2018-08-13 17:53:16 +02:00
|
|
|
if (this.searchTimeout != null) {
|
|
|
|
clearTimeout(this.searchTimeout);
|
2018-04-06 21:33:20 +02:00
|
|
|
}
|
2020-04-13 16:26:11 +02:00
|
|
|
const filterDeleted = (c: CipherView) => !c.isDeleted;
|
2018-08-13 17:53:16 +02:00
|
|
|
if (timeout == null) {
|
|
|
|
this.hasSearched = this.searchService.isSearchable(this.searchText);
|
2018-04-06 21:33:20 +02:00
|
|
|
this.ciphers = await this.searchService.searchCiphers(
|
2020-04-13 16:26:11 +02:00
|
|
|
this.searchText,
|
|
|
|
filterDeleted,
|
|
|
|
this.allCiphers
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2022-05-09 14:19:18 +02:00
|
|
|
this.ciphers = this.ciphers.filter(
|
|
|
|
(c) => !this.vaultFilterService.filterCipherForSelectedVault(c)
|
|
|
|
);
|
2021-12-21 15:43:35 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-08-13 17:53:16 +02:00
|
|
|
this.searchPending = true;
|
2018-04-06 21:33:20 +02:00
|
|
|
this.searchTimeout = setTimeout(async () => {
|
2018-04-12 21:56:27 +02:00
|
|
|
this.hasSearched = this.searchService.isSearchable(this.searchText);
|
|
|
|
if (!this.hasLoadedAllCiphers && !this.hasSearched) {
|
2018-04-05 16:29:11 +02:00
|
|
|
await this.loadCiphers();
|
2021-12-21 15:43:35 +01:00
|
|
|
} else {
|
2019-06-07 19:20:23 +02:00
|
|
|
this.ciphers = await this.searchService.searchCiphers(
|
2020-04-13 16:26:11 +02:00
|
|
|
this.searchText,
|
2019-06-07 19:20:23 +02:00
|
|
|
filterDeleted,
|
2020-04-13 16:26:11 +02:00
|
|
|
this.allCiphers
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
|
|
|
}
|
2022-05-09 14:19:18 +02:00
|
|
|
this.ciphers = this.ciphers.filter(
|
|
|
|
(c) => !this.vaultFilterService.filterCipherForSelectedVault(c)
|
|
|
|
);
|
2019-06-07 19:20:23 +02:00
|
|
|
this.searchPending = false;
|
2018-08-13 17:53:16 +02:00
|
|
|
}, timeout);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2019-06-07 19:20:23 +02:00
|
|
|
async selectType(type: CipherType) {
|
2018-04-05 21:56:52 +02:00
|
|
|
this.router.navigate(["/ciphers"], { queryParams: { type: type } });
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-09 20:17:58 +02:00
|
|
|
async selectFolder(folder: FolderView) {
|
2019-06-07 19:20:23 +02:00
|
|
|
this.router.navigate(["/ciphers"], { queryParams: { folderId: folder.id || "none" } });
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-09 20:17:58 +02:00
|
|
|
async selectCollection(collection: CollectionView) {
|
2019-06-07 19:20:23 +02:00
|
|
|
this.router.navigate(["/ciphers"], { queryParams: { collectionId: collection.id } });
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2020-04-13 16:26:11 +02:00
|
|
|
async selectTrash() {
|
2019-06-07 19:20:23 +02:00
|
|
|
this.router.navigate(["/ciphers"], { queryParams: { deleted: true } });
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-09 20:17:58 +02:00
|
|
|
async selectCipher(cipher: CipherView) {
|
2019-06-07 19:20:23 +02:00
|
|
|
this.selectedTimeout = window.setTimeout(() => {
|
|
|
|
if (!this.preventSelected) {
|
2018-04-05 21:35:56 +02:00
|
|
|
this.router.navigate(["/view-cipher"], { queryParams: { cipherId: cipher.id } });
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2018-04-05 21:35:56 +02:00
|
|
|
this.preventSelected = false;
|
2021-12-21 15:43:35 +01:00
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
|
2018-04-11 05:28:50 +02:00
|
|
|
async launchCipher(cipher: CipherView) {
|
2018-04-05 21:35:56 +02:00
|
|
|
if (cipher.type !== CipherType.Login || !cipher.login.canLaunch) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return;
|
2018-04-05 16:29:11 +02:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:56:27 +02:00
|
|
|
if (this.selectedTimeout != null) {
|
|
|
|
window.clearTimeout(this.selectedTimeout);
|
2018-04-05 04:59:42 +02:00
|
|
|
}
|
2018-08-13 17:53:16 +02:00
|
|
|
this.preventSelected = true;
|
2020-04-13 16:26:11 +02:00
|
|
|
await this.cipherService.updateLastLaunchedDate(cipher.id);
|
|
|
|
BrowserApi.createNewTab(cipher.login.launchUri);
|
|
|
|
if (this.popupUtils.inPopup(window)) {
|
2018-08-13 17:53:16 +02:00
|
|
|
BrowserApi.closePopup(window);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-09 20:17:58 +02:00
|
|
|
async addCipher() {
|
2022-05-17 23:03:57 +02:00
|
|
|
this.router.navigate(["/add-cipher"], {
|
|
|
|
queryParams: { selectedVault: this.vaultFilter.selectedOrganizationId },
|
|
|
|
});
|
2018-04-05 21:56:52 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-05-09 14:19:18 +02:00
|
|
|
async vaultFilterChanged() {
|
|
|
|
if (this.showSearching) {
|
|
|
|
await this.search();
|
|
|
|
}
|
|
|
|
this.updateSelectedOrg();
|
|
|
|
await this.loadCollectionsAndFolders();
|
|
|
|
this.getCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSelectedOrg() {
|
|
|
|
this.vaultFilter = this.vaultFilterService.getVaultFilter();
|
|
|
|
if (this.vaultFilter.selectedOrganizationId != null) {
|
|
|
|
this.selectedOrganization = this.vaultFilter.selectedOrganizationId;
|
|
|
|
} else {
|
|
|
|
this.selectedOrganization = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getCounts() {
|
|
|
|
let favoriteCiphers: CipherView[] = null;
|
|
|
|
let noFolderCiphers: CipherView[] = null;
|
|
|
|
const folderCounts = new Map<string, number>();
|
|
|
|
const collectionCounts = new Map<string, number>();
|
|
|
|
const typeCounts = new Map<CipherType, number>();
|
|
|
|
|
|
|
|
this.deletedCount = this.allCiphers.filter(
|
|
|
|
(c) => c.isDeleted && !this.vaultFilterService.filterCipherForSelectedVault(c)
|
|
|
|
).length;
|
|
|
|
|
|
|
|
this.ciphers?.forEach((c) => {
|
|
|
|
if (!this.vaultFilterService.filterCipherForSelectedVault(c)) {
|
|
|
|
if (c.isDeleted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (c.favorite) {
|
|
|
|
if (favoriteCiphers == null) {
|
|
|
|
favoriteCiphers = [];
|
|
|
|
}
|
|
|
|
favoriteCiphers.push(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c.folderId == null) {
|
|
|
|
if (noFolderCiphers == null) {
|
|
|
|
noFolderCiphers = [];
|
|
|
|
}
|
|
|
|
noFolderCiphers.push(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeCounts.has(c.type)) {
|
|
|
|
typeCounts.set(c.type, typeCounts.get(c.type) + 1);
|
|
|
|
} else {
|
|
|
|
typeCounts.set(c.type, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (folderCounts.has(c.folderId)) {
|
|
|
|
folderCounts.set(c.folderId, folderCounts.get(c.folderId) + 1);
|
|
|
|
} else {
|
|
|
|
folderCounts.set(c.folderId, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c.collectionIds != null) {
|
|
|
|
c.collectionIds.forEach((colId) => {
|
|
|
|
if (collectionCounts.has(colId)) {
|
|
|
|
collectionCounts.set(colId, collectionCounts.get(colId) + 1);
|
|
|
|
} else {
|
|
|
|
collectionCounts.set(colId, 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.favoriteCiphers = favoriteCiphers;
|
|
|
|
this.noFolderCiphers = noFolderCiphers;
|
|
|
|
this.typeCounts = typeCounts;
|
|
|
|
this.folderCounts = folderCounts;
|
|
|
|
this.collectionCounts = collectionCounts;
|
|
|
|
}
|
|
|
|
|
2018-04-05 21:56:52 +02:00
|
|
|
showSearching() {
|
2021-12-21 15:43:35 +01:00
|
|
|
return (
|
2018-04-05 21:56:52 +02:00
|
|
|
this.hasSearched || (!this.searchPending && this.searchService.isSearchable(this.searchText))
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
2018-04-05 21:56:52 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-05 21:56:52 +02:00
|
|
|
closeOnEsc(e: KeyboardEvent) {
|
|
|
|
// If input not empty, use browser default behavior of clearing input instead
|
|
|
|
if (e.key === "Escape" && (this.searchText == null || this.searchText === "")) {
|
|
|
|
BrowserApi.closePopup(window);
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:19:18 +02:00
|
|
|
private async loadCollectionsAndFolders() {
|
|
|
|
this.showCollections = !this.vaultFilter.myVaultOnly;
|
|
|
|
await this.loadFolders();
|
|
|
|
await this.loadCollections();
|
|
|
|
}
|
|
|
|
|
2018-04-09 20:17:58 +02:00
|
|
|
private async saveState() {
|
2018-04-12 21:56:27 +02:00
|
|
|
this.state = {
|
2018-04-09 20:17:58 +02:00
|
|
|
scrollY: this.popupUtils.getContentScrollY(window),
|
2018-04-05 21:35:56 +02:00
|
|
|
searchText: this.searchText,
|
2018-10-29 13:58:20 +01:00
|
|
|
favoriteCiphers: this.favoriteCiphers,
|
|
|
|
noFolderCiphers: this.noFolderCiphers,
|
2018-04-12 21:56:27 +02:00
|
|
|
ciphers: this.ciphers,
|
|
|
|
collectionCounts: this.collectionCounts,
|
2018-10-29 13:58:20 +01:00
|
|
|
folderCounts: this.folderCounts,
|
|
|
|
typeCounts: this.typeCounts,
|
2018-04-12 21:56:27 +02:00
|
|
|
folders: this.folders,
|
|
|
|
collections: this.collections,
|
2020-04-13 16:26:11 +02:00
|
|
|
deletedCount: this.deletedCount,
|
2018-10-29 13:58:20 +01:00
|
|
|
};
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.browserStateService.setBrowserGroupingComponentState(this.state);
|
2018-10-29 13:58:20 +01:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-10-29 13:58:20 +01:00
|
|
|
private async restoreState(): Promise<boolean> {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.state = await this.browserStateService.getBrowserGroupingComponentState();
|
|
|
|
if (this.state == null) {
|
2018-04-12 21:56:27 +02:00
|
|
|
return false;
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.favoriteCiphers != null) {
|
|
|
|
this.favoriteCiphers = this.state.favoriteCiphers;
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.noFolderCiphers != null) {
|
|
|
|
this.noFolderCiphers = this.state.noFolderCiphers;
|
2020-04-13 16:26:11 +02:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.ciphers != null) {
|
|
|
|
this.ciphers = this.state.ciphers;
|
2018-04-11 05:28:50 +02:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.collectionCounts != null) {
|
|
|
|
this.collectionCounts = this.state.collectionCounts;
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.folderCounts != null) {
|
|
|
|
this.folderCounts = this.state.folderCounts;
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.typeCounts != null) {
|
|
|
|
this.typeCounts = this.state.typeCounts;
|
2018-08-13 17:53:16 +02:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.folders != null) {
|
|
|
|
this.folders = this.state.folders;
|
2021-04-23 10:45:20 +02:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.collections != null) {
|
|
|
|
this.collections = this.state.collections;
|
2018-04-12 21:56:27 +02:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
if (this.state.deletedCount != null) {
|
|
|
|
this.deletedCount = this.state.deletedCount;
|
2018-04-09 20:17:58 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-12 21:56:27 +02:00
|
|
|
return true;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2018-04-05 04:59:42 +02:00
|
|
|
}
|