From 9e8873e5c7716f06bd228a10906d0765bfe575a4 Mon Sep 17 00:00:00 2001 From: Vincent Salucci Date: Fri, 20 Mar 2020 17:07:19 -0500 Subject: [PATCH] Apply save changes prompt to groupings --- src/app/vault/groupings.component.ts | 25 +++++++ src/app/vault/vault.component.ts | 108 +++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/src/app/vault/groupings.component.ts b/src/app/vault/groupings.component.ts index cb69405f..50b303ff 100644 --- a/src/app/vault/groupings.component.ts +++ b/src/app/vault/groupings.component.ts @@ -7,6 +7,11 @@ import { UserService } from 'jslib/abstractions/user.service'; import { GroupingsComponent as BaseGroupingsComponent } from 'jslib/angular/components/groupings.component'; +import { CipherType } from 'jslib/enums/cipherType'; + +import { CollectionView } from 'jslib/models/view/collectionView'; +import { FolderView } from 'jslib/models/view/folderView'; + @Component({ selector: 'app-vault-groupings', templateUrl: 'groupings.component.html', @@ -16,4 +21,24 @@ export class GroupingsComponent extends BaseGroupingsComponent { storageService: StorageService, userService: UserService) { super(collectionService, folderService, storageService, userService); } + + selectAll() { + this.onAllClicked.emit(); + } + + selectFavorites() { + this.onFavoritesClicked.emit(); + } + + selectType(type: CipherType) { + this.onCipherTypeClicked.emit(type); + } + + selectFolder(folder: FolderView) { + this.onFolderClicked.emit(folder); + } + + selectCollection(collection: CollectionView) { + this.onCollectionClicked.emit(collection); + } } diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index ef28bb59..25ce903e 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -484,6 +484,21 @@ export class VaultComponent implements OnInit, OnDestroy { } async clearGroupingFilters() { + if (this.groupingsComponent.selectedAll) { + return; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.groupingsComponent != null) { + this.groupingsComponent.clearSelections(); + this.groupingsComponent.selectedAll = true; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + this.ciphersComponent.searchPlaceholder = this.i18nService.t('searchVault'); await this.ciphersComponent.reload(); this.clearFilters(); @@ -491,6 +506,21 @@ export class VaultComponent implements OnInit, OnDestroy { } async filterFavorites() { + if (this.groupingsComponent.selectedFavorites) { + return; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.groupingsComponent != null) { + this.groupingsComponent.clearSelections(); + this.groupingsComponent.selectedFavorites = true; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + this.ciphersComponent.searchPlaceholder = this.i18nService.t('searchFavorites'); await this.ciphersComponent.reload((c) => c.favorite); this.clearFilters(); @@ -499,6 +529,21 @@ export class VaultComponent implements OnInit, OnDestroy { } async filterCipherType(type: CipherType) { + if (this.groupingsComponent.selectedType === type) { + return; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.groupingsComponent != null) { + this.groupingsComponent.clearSelections(); + this.groupingsComponent.selectedType = type; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + this.ciphersComponent.searchPlaceholder = this.i18nService.t('searchType'); await this.ciphersComponent.reload((c) => c.type === type); this.clearFilters(); @@ -507,6 +552,22 @@ export class VaultComponent implements OnInit, OnDestroy { } async filterFolder(folderId: string) { + if (this.groupingsComponent.selectedFolderId === folderId) { + return; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.groupingsComponent != null) { + this.groupingsComponent.clearSelections(); + this.groupingsComponent.selectedFolder = true; + this.groupingsComponent.selectedFolderId = folderId; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + folderId = folderId === 'none' ? null : folderId; this.ciphersComponent.searchPlaceholder = this.i18nService.t('searchFolder'); await this.ciphersComponent.reload((c) => c.folderId === folderId); @@ -516,6 +577,21 @@ export class VaultComponent implements OnInit, OnDestroy { } async filterCollection(collectionId: string) { + if (this.groupingsComponent.selectedCollectionId === collectionId) { + return; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.groupingsComponent != null) { + this.groupingsComponent.clearSelections(); + this.groupingsComponent.selectedCollectionId = collectionId; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + this.ciphersComponent.searchPlaceholder = this.i18nService.t('searchCollection'); await this.ciphersComponent.reload((c) => c.collectionIds != null && c.collectionIds.indexOf(collectionId) > -1); @@ -526,6 +602,14 @@ export class VaultComponent implements OnInit, OnDestroy { } async openPasswordGenerator(showSelect: boolean) { + if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + if (this.modal != null) { this.modal.close(); } @@ -549,6 +633,14 @@ export class VaultComponent implements OnInit, OnDestroy { } async openExportVault() { + if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + if (this.modal != null) { this.modal.close(); } @@ -567,6 +659,14 @@ export class VaultComponent implements OnInit, OnDestroy { } async addFolder() { + if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + if (this.modal != null) { this.modal.close(); } @@ -587,6 +687,14 @@ export class VaultComponent implements OnInit, OnDestroy { } async editFolder(folderId: string) { + if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; + } + + if (this.action === 'add' || this.action === 'edit' || this.action === 'clone') { + this.cancelledAddEdit(this.addEditComponent.cipher); + } + if (this.modal != null) { this.modal.close(); }