bitwarden-estensione-browser/src/app/vault/vault.component.ts

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

425 lines
14 KiB
TypeScript
Raw Normal View History

2018-06-05 05:10:41 +02:00
import {
2018-08-21 04:21:13 +02:00
ChangeDetectorRef,
2018-06-05 05:10:41 +02:00
Component,
2018-08-21 04:21:13 +02:00
NgZone,
OnDestroy,
2018-06-06 23:25:57 +02:00
OnInit,
ViewChild,
ViewContainerRef,
2018-06-05 05:10:41 +02:00
} from "@angular/core";
2018-06-06 23:25:57 +02:00
import { ActivatedRoute, Router } from "@angular/router";
import { first } from "rxjs/operators";
2021-12-17 15:57:11 +01:00
2022-02-24 12:10:07 +01:00
import { ModalService } from "jslib-angular/services/modal.service";
import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service";
import { CipherService } from "jslib-common/abstractions/cipher.service";
2022-02-24 12:10:07 +01:00
import { CryptoService } from "jslib-common/abstractions/crypto.service";
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { MessagingService } from "jslib-common/abstractions/messaging.service";
import { OrganizationService } from "jslib-common/abstractions/organization.service";
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
import { ProviderService } from "jslib-common/abstractions/provider.service";
import { StateService } from "jslib-common/abstractions/state.service";
import { SyncService } from "jslib-common/abstractions/sync.service";
import { TokenService } from "jslib-common/abstractions/token.service";
import { CipherType } from "jslib-common/enums/cipherType";
import { CipherView } from "jslib-common/models/view/cipherView";
2021-12-17 15:57:11 +01:00
2018-07-11 17:39:48 +02:00
import { OrganizationsComponent } from "../settings/organizations.component";
2018-07-17 23:22:51 +02:00
import { UpdateKeyComponent } from "../settings/update-key.component";
2022-02-24 12:10:07 +01:00
2018-06-07 05:23:14 +02:00
import { AddEditComponent } from "./add-edit.component";
2018-06-06 23:25:57 +02:00
import { AttachmentsComponent } from "./attachments.component";
import { CiphersComponent } from "./ciphers.component";
2018-06-12 19:08:47 +02:00
import { CollectionsComponent } from "./collections.component";
2018-06-06 23:25:57 +02:00
import { FolderAddEditComponent } from "./folder-add-edit.component";
import { GroupingsComponent } from "./groupings.component";
2018-06-12 19:08:47 +02:00
import { ShareComponent } from "./share.component";
2021-12-17 15:57:11 +01:00
2018-08-21 04:21:13 +02:00
const BroadcasterSubscriptionId = "VaultComponent";
2018-06-05 05:10:41 +02:00
@Component({
selector: "app-vault",
templateUrl: "vault.component.html",
})
2018-08-21 04:21:13 +02:00
export class VaultComponent implements OnInit, OnDestroy {
@ViewChild(GroupingsComponent, { static: true }) groupingsComponent: GroupingsComponent;
@ViewChild(CiphersComponent, { static: true }) ciphersComponent: CiphersComponent;
@ViewChild(OrganizationsComponent, { static: true })
organizationsComponent: OrganizationsComponent;
@ViewChild("attachments", { read: ViewContainerRef, static: true })
attachmentsModalRef: ViewContainerRef;
@ViewChild("folderAddEdit", { read: ViewContainerRef, static: true })
folderAddEditModalRef: ViewContainerRef;
@ViewChild("cipherAddEdit", { read: ViewContainerRef, static: true })
cipherAddEditModalRef: ViewContainerRef;
@ViewChild("share", { read: ViewContainerRef, static: true }) shareModalRef: ViewContainerRef;
@ViewChild("collections", { read: ViewContainerRef, static: true })
collectionsModalRef: ViewContainerRef;
2018-06-06 23:25:57 +02:00
@ViewChild("updateKeyTemplate", { read: ViewContainerRef, static: true })
updateKeyModalRef: ViewContainerRef;
2021-12-17 15:57:11 +01:00
2022-02-24 12:10:07 +01:00
favorites = false;
type: CipherType = null;
folderId: string = null;
collectionId: string = null;
showVerifyEmail = false;
showBrowserOutdated = false;
showUpdateKey = false;
2018-07-20 16:44:17 +02:00
showPremiumCallout = false;
showProviders = false;
2022-02-24 12:10:07 +01:00
deleted = false;
trashCleanupWarning: string = null;
2021-12-17 15:57:11 +01:00
constructor(
2018-06-26 18:03:11 +02:00
private syncService: SyncService,
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
private route: ActivatedRoute,
private router: Router,
private changeDetectorRef: ChangeDetectorRef,
private i18nService: I18nService,
2018-08-31 23:23:36 +02:00
private modalService: ModalService,
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
private tokenService: TokenService,
private cryptoService: CryptoService,
2018-06-06 23:25:57 +02:00
private messagingService: MessagingService,
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
private platformUtilsService: PlatformUtilsService,
2019-03-19 17:44:22 +01:00
private broadcasterService: BroadcasterService,
private ngZone: NgZone,
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
private stateService: StateService,
private organizationService: OrganizationService,
private providerService: ProviderService,
private cipherService: CipherService
2021-12-17 15:57:11 +01:00
) {}
async ngOnInit() {
this.showVerifyEmail = !(await this.tokenService.getEmailVerified());
this.showBrowserOutdated = window.navigator.userAgent.indexOf("MSIE") !== -1;
this.trashCleanupWarning = this.i18nService.t(
this.platformUtilsService.isSelfHost()
? "trashCleanupWarningSelfHosted"
2018-08-31 23:23:36 +02:00
: "trashCleanupWarning"
2021-12-17 15:57:11 +01:00
);
2018-08-31 23:23:36 +02:00
this.route.queryParams.pipe(first()).subscribe(async (params) => {
await this.syncService.fullSync(false);
2021-12-17 15:57:11 +01:00
2018-08-31 23:23:36 +02:00
const canAccessPremium = await this.stateService.getCanAccessPremium();
this.showPremiumCallout =
!this.showVerifyEmail && !canAccessPremium && !this.platformUtilsService.isSelfHost();
2021-12-17 15:57:11 +01:00
2018-08-31 23:23:36 +02:00
this.showProviders = (await this.providerService.getAll()).length > 0;
2021-12-17 15:57:11 +01:00
2018-06-07 15:05:25 +02:00
await Promise.all([this.groupingsComponent.load(), this.organizationsComponent.load()]);
this.showUpdateKey = !(await this.cryptoService.hasEncKey());
2021-12-17 15:57:11 +01:00
2018-06-07 15:05:25 +02:00
if (params == null) {
this.groupingsComponent.selectedAll = true;
2019-03-19 17:44:22 +01:00
await this.ciphersComponent.reload();
2018-06-06 23:25:57 +02:00
} else {
if (params.deleted) {
this.groupingsComponent.selectedTrash = true;
await this.filterDeleted();
2018-06-06 23:25:57 +02:00
} else if (params.favorites) {
this.groupingsComponent.selectedFavorites = true;
2018-06-07 15:05:25 +02:00
await this.filterFavorites();
} else if (params.type) {
const t = parseInt(params.type, null);
this.groupingsComponent.selectedType = t;
await this.filterCipherType(t);
2018-06-06 23:25:57 +02:00
} else if (params.folderId) {
2018-06-07 15:05:25 +02:00
this.groupingsComponent.selectedFolder = true;
this.groupingsComponent.selectedFolderId = params.folderId;
2018-06-06 23:25:57 +02:00
await this.filterFolder(params.folderId);
} else if (params.collectionId) {
2018-06-07 15:05:25 +02:00
this.groupingsComponent.selectedCollectionId = params.collectionId;
2018-06-06 23:25:57 +02:00
await this.filterCollection(params.collectionId);
2018-06-07 05:00:57 +02:00
} else {
this.groupingsComponent.selectedAll = true;
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
await this.ciphersComponent.reload();
2018-07-18 15:21:23 +02:00
}
2021-12-17 15:57:11 +01:00
}
this.route.queryParams.subscribe(async (params) => {
if (params.cipherId) {
if ((await this.cipherService.get(params.cipherId)) != null) {
this.editCipherId(params.cipherId);
} else {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccurred"),
this.i18nService.t("unknownCipher")
);
this.router.navigate([], {
queryParams: { cipherId: null },
queryParamsHandling: "merge",
});
}
}
});
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
this.ngZone.run(async () => {
switch (message.command) {
case "syncCompleted":
2018-08-31 23:23:36 +02:00
if (message.successfully) {
await Promise.all([
this.groupingsComponent.load(),
this.organizationsComponent.load(),
this.ciphersComponent.load(this.ciphersComponent.filter),
]);
this.changeDetectorRef.detectChanges();
2021-12-17 15:57:11 +01:00
}
break;
2021-12-17 15:57:11 +01:00
}
});
2021-12-17 15:57:11 +01:00
});
});
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
2021-12-17 15:57:11 +01:00
}
async clearGroupingFilters() {
this.ciphersComponent.showAddNew = true;
2018-06-09 19:29:30 +02:00
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchVault");
await this.ciphersComponent.reload();
2018-06-06 23:25:57 +02:00
this.clearFilters();
this.go();
2018-06-09 19:29:30 +02:00
}
2021-12-17 15:57:11 +01:00
2018-06-09 19:29:30 +02:00
async filterFavorites() {
this.ciphersComponent.showAddNew = true;
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchFavorites");
await this.ciphersComponent.reload((c) => c.favorite);
this.clearFilters();
2018-06-09 19:29:30 +02:00
this.favorites = true;
this.go();
2021-12-17 15:57:11 +01:00
}
2018-06-06 23:25:57 +02:00
async filterDeleted() {
2018-06-09 19:29:30 +02:00
this.ciphersComponent.showAddNew = false;
this.ciphersComponent.deleted = true;
2018-06-07 15:05:25 +02:00
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchTrash");
await this.ciphersComponent.reload(null, true);
2018-06-06 23:25:57 +02:00
this.clearFilters();
this.deleted = true;
2018-06-06 23:25:57 +02:00
this.go();
2021-12-17 15:57:11 +01:00
}
2018-06-06 23:25:57 +02:00
async filterCipherType(type: CipherType) {
this.ciphersComponent.showAddNew = true;
2018-06-07 15:05:25 +02:00
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchType");
await this.ciphersComponent.reload((c) => c.type === type);
2018-06-06 23:25:57 +02:00
this.clearFilters();
this.type = type;
this.go();
2021-12-17 15:57:11 +01:00
}
2018-06-06 23:25:57 +02:00
async filterFolder(folderId: string) {
2018-10-22 22:46:48 +02:00
this.ciphersComponent.showAddNew = true;
2018-06-06 23:25:57 +02:00
folderId = folderId === "none" ? null : folderId;
2018-06-07 15:05:25 +02:00
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchFolder");
await this.ciphersComponent.reload((c) => c.folderId === folderId);
2018-06-06 23:25:57 +02:00
this.clearFilters();
2018-06-07 05:23:14 +02:00
this.folderId = folderId == null ? "none" : folderId;
2018-06-06 23:25:57 +02:00
this.go();
2021-12-17 15:57:11 +01:00
}
2018-06-06 23:25:57 +02:00
async filterCollection(collectionId: string) {
2018-10-22 22:46:48 +02:00
this.ciphersComponent.showAddNew = true;
2018-06-07 15:05:25 +02:00
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchCollection");
await this.ciphersComponent.reload(
(c) => c.collectionIds != null && c.collectionIds.indexOf(collectionId) > -1
2021-12-17 15:57:11 +01:00
);
2018-06-06 23:25:57 +02:00
this.clearFilters();
this.collectionId = collectionId;
2018-06-06 23:25:57 +02:00
this.go();
2021-12-17 15:57:11 +01:00
}
2018-06-07 05:00:57 +02:00
filterSearchText(searchText: string) {
2018-06-07 15:05:25 +02:00
this.ciphersComponent.searchText = searchText;
2018-08-13 22:27:17 +02:00
this.ciphersComponent.search(200);
2021-12-17 15:57:11 +01:00
}
2018-06-09 19:29:30 +02:00
async editCipherAttachments(cipher: CipherView) {
const canAccessPremium = await this.stateService.getCanAccessPremium();
if (cipher.organizationId == null && !canAccessPremium) {
2018-07-18 15:21:23 +02:00
this.messagingService.send("premiumRequired");
2021-12-17 15:57:11 +01:00
return;
2018-07-18 15:21:23 +02:00
} else if (cipher.organizationId != null) {
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
const org = await this.organizationService.get(cipher.organizationId);
2018-06-09 19:29:30 +02:00
if (org != null && (org.maxStorageGb == null || org.maxStorageGb === 0)) {
2018-07-18 15:21:23 +02:00
this.messagingService.send("upgradeOrganization", {
organizationId: cipher.organizationId,
2018-06-06 23:25:57 +02:00
});
2021-12-17 15:57:11 +01:00
return;
}
2018-06-06 23:25:57 +02:00
}
let madeAttachmentChanges = false;
const [modal] = await this.modalService.openViewRef(
AttachmentsComponent,
this.attachmentsModalRef,
(comp) => {
comp.cipherId = cipher.id;
comp.onUploadedAttachment.subscribe(() => (madeAttachmentChanges = true));
comp.onDeletedAttachment.subscribe(() => (madeAttachmentChanges = true));
comp.onReuploadedAttachment.subscribe(() => (madeAttachmentChanges = true));
2021-12-17 15:57:11 +01:00
}
);
modal.onClosed.subscribe(async () => {
2018-06-09 19:29:30 +02:00
if (madeAttachmentChanges) {
await this.ciphersComponent.refresh();
2021-12-17 15:57:11 +01:00
}
2018-06-09 19:29:30 +02:00
madeAttachmentChanges = false;
2021-12-17 15:57:11 +01:00
});
}
async shareCipher(cipher: CipherView) {
const [modal] = await this.modalService.openViewRef(
ShareComponent,
this.shareModalRef,
(comp) => {
comp.cipherId = cipher.id;
comp.onSharedCipher.subscribe(async () => {
modal.close();
await this.ciphersComponent.refresh();
2018-06-12 17:46:11 +02:00
});
}
2021-12-17 15:57:11 +01:00
);
}
async editCipherCollections(cipher: CipherView) {
const [modal] = await this.modalService.openViewRef(
CollectionsComponent,
this.collectionsModalRef,
(comp) => {
comp.cipherId = cipher.id;
comp.onSavedCollections.subscribe(async () => {
modal.close();
await this.ciphersComponent.refresh();
2018-06-12 19:08:47 +02:00
});
}
2021-12-17 15:57:11 +01:00
);
}
2018-06-06 23:25:57 +02:00
async addFolder() {
const [modal] = await this.modalService.openViewRef(
FolderAddEditComponent,
this.folderAddEditModalRef,
(comp) => {
comp.folderId = null;
comp.onSavedFolder.subscribe(async () => {
modal.close();
await this.groupingsComponent.loadFolders();
2018-06-06 23:25:57 +02:00
});
}
2021-12-17 15:57:11 +01:00
);
}
2018-06-06 23:25:57 +02:00
async editFolder(folderId: string) {
const [modal] = await this.modalService.openViewRef(
FolderAddEditComponent,
this.folderAddEditModalRef,
(comp) => {
comp.folderId = folderId;
comp.onSavedFolder.subscribe(async () => {
modal.close();
await this.groupingsComponent.loadFolders();
2018-06-06 23:25:57 +02:00
});
2018-06-07 05:23:14 +02:00
comp.onDeletedFolder.subscribe(async () => {
modal.close();
await this.groupingsComponent.loadFolders();
await this.filterFolder("none");
this.groupingsComponent.selectedFolderId = null;
2018-06-07 05:23:14 +02:00
});
2021-12-17 15:57:11 +01:00
}
2018-06-07 05:23:14 +02:00
);
}
2021-12-17 15:57:11 +01:00
async addCipher() {
const component = await this.editCipher(null);
component.type = this.type;
2018-06-06 23:25:57 +02:00
component.folderId = this.folderId === "none" ? null : this.folderId;
if (this.collectionId != null) {
const collection = this.groupingsComponent.collections.filter(
(c) => c.id === this.collectionId
2021-12-17 15:57:11 +01:00
);
2018-10-22 22:46:48 +02:00
if (collection.length > 0) {
component.organizationId = collection[0].organizationId;
component.collectionIds = [this.collectionId];
2021-12-17 15:57:11 +01:00
}
2018-06-06 23:25:57 +02:00
}
2021-12-17 15:57:11 +01:00
}
2018-06-06 23:25:57 +02:00
async editCipher(cipher: CipherView) {
return this.editCipherId(cipher?.id);
}
async editCipherId(id: string) {
2018-06-06 23:25:57 +02:00
const [modal, childComponent] = await this.modalService.openViewRef(
AddEditComponent,
this.cipherAddEditModalRef,
(comp) => {
comp.cipherId = id;
2022-02-24 12:10:07 +01:00
comp.onSavedCipher.subscribe(async () => {
modal.close();
await this.ciphersComponent.refresh();
});
2022-02-24 12:10:07 +01:00
comp.onDeletedCipher.subscribe(async () => {
modal.close();
await this.ciphersComponent.refresh();
2021-12-17 15:57:11 +01:00
});
2022-02-24 12:10:07 +01:00
comp.onRestoredCipher.subscribe(async () => {
modal.close();
await this.ciphersComponent.refresh();
2021-12-17 15:57:11 +01:00
});
}
);
modal.onClosedPromise().then(() => {
this.route.params;
this.router.navigate([], { queryParams: { cipherId: null }, queryParamsHandling: "merge" });
});
2018-06-07 05:23:14 +02:00
return childComponent;
2021-12-17 15:57:11 +01:00
}
async cloneCipher(cipher: CipherView) {
const component = await this.editCipher(cipher);
2018-10-22 22:46:48 +02:00
component.cloneMode = true;
2021-12-17 15:57:11 +01:00
}
async updateKey() {
await this.modalService.openViewRef(UpdateKeyComponent, this.updateKeyModalRef);
2021-12-17 15:57:11 +01:00
}
2018-06-06 23:25:57 +02:00
private clearFilters() {
2018-06-07 05:23:14 +02:00
this.folderId = null;
this.collectionId = null;
2018-06-06 23:25:57 +02:00
this.favorites = false;
this.type = null;
this.deleted = false;
2021-12-17 15:57:11 +01:00
}
2018-06-06 23:25:57 +02:00
private go(queryParams: any = null) {
if (queryParams == null) {
queryParams = {
favorites: this.favorites ? true : null,
type: this.type,
folderId: this.folderId,
2018-10-22 22:46:48 +02:00
collectionId: this.collectionId,
2018-06-06 23:25:57 +02:00
deleted: this.deleted ? true : null,
2021-12-17 15:57:11 +01:00
};
2018-06-06 23:25:57 +02:00
}
2021-12-17 15:57:11 +01:00
this.router.navigate([], {
relativeTo: this.route,
queryParams: queryParams,
queryParamsHandling: "merge",
replaceUrl: true,
2021-12-17 15:57:11 +01:00
});
}
2018-06-05 05:10:41 +02:00
}