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";
|
2021-10-15 00:59:43 +02:00
|
|
|
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";
|
2022-04-25 15:41:44 +02:00
|
|
|
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";
|
2021-06-07 20:13:58 +02:00
|
|
|
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 {
|
2020-08-17 16:04:38 +02:00
|
|
|
@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 })
|
2018-07-12 17:34:51 +02:00
|
|
|
updateKeyModalRef: ViewContainerRef;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-02-24 12:10:07 +01:00
|
|
|
favorites = false;
|
2021-04-27 18:49:02 +02:00
|
|
|
type: CipherType = null;
|
|
|
|
folderId: string = null;
|
|
|
|
collectionId: string = null;
|
2018-07-12 17:34:51 +02:00
|
|
|
showVerifyEmail = false;
|
|
|
|
showBrowserOutdated = false;
|
|
|
|
showUpdateKey = false;
|
2018-07-20 16:44:17 +02:00
|
|
|
showPremiumCallout = false;
|
2021-04-27 18:49:02 +02:00
|
|
|
showProviders = false;
|
2022-02-24 12:10:07 +01:00
|
|
|
deleted = false;
|
2021-04-27 18:49:02 +02:00
|
|
|
trashCleanupWarning: string = null;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-04-27 18:49:02 +02:00
|
|
|
constructor(
|
2018-06-26 18:03:11 +02:00
|
|
|
private syncService: SyncService,
|
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,
|
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,
|
2021-12-14 17:10:26 +01:00
|
|
|
private platformUtilsService: PlatformUtilsService,
|
2019-03-19 17:44:22 +01:00
|
|
|
private broadcasterService: BroadcasterService,
|
2020-04-08 22:48:30 +02:00
|
|
|
private ngZone: NgZone,
|
2021-12-14 17:10:26 +01:00
|
|
|
private stateService: StateService,
|
|
|
|
private organizationService: OrganizationService,
|
2022-04-25 15:41:44 +02:00
|
|
|
private providerService: ProviderService,
|
|
|
|
private cipherService: CipherService
|
2021-12-17 15:57:11 +01:00
|
|
|
) {}
|
|
|
|
|
2020-04-08 22:48:30 +02:00
|
|
|
async ngOnInit() {
|
|
|
|
this.showVerifyEmail = !(await this.tokenService.getEmailVerified());
|
2018-12-20 16:06:40 +01:00
|
|
|
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) {
|
2018-12-20 16:06:40 +01:00
|
|
|
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 {
|
2020-04-08 22:48:30 +02:00
|
|
|
if (params.deleted) {
|
|
|
|
this.groupingsComponent.selectedTrash = true;
|
|
|
|
await this.filterDeleted();
|
2018-06-06 23:25:57 +02:00
|
|
|
} else if (params.favorites) {
|
2018-07-04 15:55:52 +02:00
|
|
|
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;
|
2021-02-03 18:41:33 +01:00
|
|
|
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;
|
2021-02-03 18:41:33 +01:00
|
|
|
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;
|
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
|
|
|
}
|
|
|
|
|
2022-04-25 15:41:44 +02: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",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
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) {
|
2021-08-27 14:50:58 +02:00
|
|
|
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
|
|
|
}
|
2021-08-27 14:50:58 +02:00
|
|
|
break;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-08-27 14:50:58 +02:00
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02: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");
|
2021-02-03 18:41:33 +01:00
|
|
|
await this.ciphersComponent.reload((c) => c.favorite);
|
2020-04-08 22:48:30 +02:00
|
|
|
this.clearFilters();
|
2018-06-09 19:29:30 +02:00
|
|
|
this.favorites = true;
|
2020-04-08 22:48:30 +02:00
|
|
|
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;
|
2020-04-08 22:48:30 +02:00
|
|
|
this.ciphersComponent.deleted = true;
|
2018-06-07 15:05:25 +02:00
|
|
|
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchTrash");
|
2021-02-03 18:41:33 +01:00
|
|
|
await this.ciphersComponent.reload(null, true);
|
2018-06-06 23:25:57 +02:00
|
|
|
this.clearFilters();
|
2020-04-08 22:48:30 +02:00
|
|
|
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) {
|
2018-07-04 15:55:52 +02:00
|
|
|
this.ciphersComponent.showAddNew = true;
|
2018-06-07 15:05:25 +02:00
|
|
|
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchType");
|
2021-02-03 18:41:33 +01:00
|
|
|
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");
|
2021-02-03 18:41:33 +01:00
|
|
|
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");
|
2021-02-03 18:41:33 +01:00
|
|
|
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();
|
2021-02-03 18:41:33 +01:00
|
|
|
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();
|
2018-08-29 15:22:28 +02:00
|
|
|
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) {
|
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
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +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
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.onClosed.subscribe(async () => {
|
2018-06-09 19:29:30 +02:00
|
|
|
if (madeAttachmentChanges) {
|
2021-08-27 14:50:58 +02:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02: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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02: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() {
|
2021-08-27 14:50:58 +02:00
|
|
|
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) {
|
2021-08-27 14:50:58 +02:00
|
|
|
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 () => {
|
2021-02-03 18:41:33 +01:00
|
|
|
modal.close();
|
|
|
|
await this.groupingsComponent.loadFolders();
|
2021-08-27 14:50:58 +02:00
|
|
|
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
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async addCipher() {
|
|
|
|
const component = await this.editCipher(null);
|
2020-02-10 20:03:36 +01:00
|
|
|
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(
|
2020-04-08 22:48:30 +02:00
|
|
|
(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;
|
2020-04-08 22:48:30 +02:00
|
|
|
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) {
|
2022-04-25 15:41:44 +02:00
|
|
|
return this.editCipherId(cipher?.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
async editCipherId(id: string) {
|
2018-06-06 23:25:57 +02:00
|
|
|
const [modal, childComponent] = await this.modalService.openViewRef(
|
2020-04-08 22:48:30 +02:00
|
|
|
AddEditComponent,
|
|
|
|
this.cipherAddEditModalRef,
|
2021-08-27 14:50:58 +02:00
|
|
|
(comp) => {
|
2022-04-25 15:41:44 +02:00
|
|
|
comp.cipherId = id;
|
2022-02-24 12:10:07 +01:00
|
|
|
comp.onSavedCipher.subscribe(async () => {
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
2018-11-30 16:28:46 +01:00
|
|
|
await this.ciphersComponent.refresh();
|
|
|
|
});
|
2022-02-24 12:10:07 +01:00
|
|
|
comp.onDeletedCipher.subscribe(async () => {
|
2021-08-27 14:50:58 +02:00
|
|
|
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 () => {
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-04-25 15:41:44 +02: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
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02: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
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02: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;
|
2021-02-03 18:41:33 +01:00
|
|
|
this.collectionId = null;
|
2018-06-06 23:25:57 +02:00
|
|
|
this.favorites = false;
|
|
|
|
this.type = null;
|
2020-04-08 22:48:30 +02:00
|
|
|
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
|
|
|
|
2018-11-30 16:28:46 +01:00
|
|
|
this.router.navigate([], {
|
|
|
|
relativeTo: this.route,
|
|
|
|
queryParams: queryParams,
|
2022-04-25 15:41:44 +02:00
|
|
|
queryParamsHandling: "merge",
|
2018-11-30 16:28:46 +01:00
|
|
|
replaceUrl: true,
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
2018-06-05 05:10:41 +02:00
|
|
|
}
|