From 337a7ba59f686a5fe8c52d34f3290bbd6ea66669 Mon Sep 17 00:00:00 2001 From: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Date: Tue, 28 Jan 2020 16:19:50 -0600 Subject: [PATCH] [jslib] Updated shared components for cipher cloning (#60) --- src/angular/components/add-edit.component.ts | 24 ++++++++++++++++---- src/angular/components/view.component.ts | 5 ++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/angular/components/add-edit.component.ts b/src/angular/components/add-edit.component.ts index 451abce825..f25186f84f 100644 --- a/src/angular/components/add-edit.component.ts +++ b/src/angular/components/add-edit.component.ts @@ -42,6 +42,7 @@ import { SecureNoteView } from '../../models/view/secureNoteView'; import { Utils } from '../../misc/utils'; export class AddEditComponent implements OnInit { + @Input() cloneMode: boolean = false; @Input() folderId: string = null; @Input() cipherId: string; @Input() type: CipherType; @@ -160,7 +161,12 @@ export class AddEditComponent implements OnInit { this.editMode = this.cipherId != null; if (this.editMode) { this.editMode = true; - this.title = this.i18nService.t('editItem'); + if (this.cloneMode) { + this.cloneMode = true; + this.title = this.i18nService.t('addItem'); + } else{ + this.title = this.i18nService.t('editItem'); + } } else { this.title = this.i18nService.t('addItem'); } @@ -176,6 +182,11 @@ export class AddEditComponent implements OnInit { if (this.editMode) { const cipher = await this.loadCipher(); this.cipher = await cipher.decrypt(); + + // Adjust Cipher Name if Cloning + if (this.cloneMode) { + this.cipher.name += " - " + this.i18nService.t('clone'); + } } else { this.cipher = new CipherView(); this.cipher.organizationId = this.organizationId == null ? null : this.organizationId; @@ -227,16 +238,21 @@ export class AddEditComponent implements OnInit { this.collections.filter((c) => (c as any).checked).map((c) => c.id); } + // Clear current Cipher Id to trigger "Add" cipher flow + if (this.cloneMode) { + this.cipher.id = null; + } + const cipher = await this.encryptCipher(); try { this.formPromise = this.saveCipher(cipher); await this.formPromise; this.cipher.id = cipher.id; - this.platformUtilsService.eventTrack(this.editMode ? 'Edited Cipher' : 'Added Cipher'); + this.platformUtilsService.eventTrack(this.editMode && !this.cloneMode ? 'Edited Cipher' : 'Added Cipher'); this.platformUtilsService.showToast('success', null, - this.i18nService.t(this.editMode ? 'editedItem' : 'addedItem')); + this.i18nService.t(this.editMode && !this.cloneMode ? 'editedItem' : 'addedItem')); this.onSavedCipher.emit(this.cipher); - this.messagingService.send(this.editMode ? 'editedCipher' : 'addedCipher'); + this.messagingService.send(this.editMode && !this.cloneMode ? 'editedCipher' : 'addedCipher'); return true; } catch { } diff --git a/src/angular/components/view.component.ts b/src/angular/components/view.component.ts index 431c4d3786..a0d6076483 100644 --- a/src/angular/components/view.component.ts +++ b/src/angular/components/view.component.ts @@ -33,6 +33,7 @@ const BroadcasterSubscriptionId = 'ViewComponent'; export class ViewComponent implements OnDestroy, OnInit { @Input() cipherId: string; @Output() onEditCipher = new EventEmitter(); + @Output() onCloneCipher = new EventEmitter(); cipher: CipherView; showPassword: boolean; @@ -105,6 +106,10 @@ export class ViewComponent implements OnDestroy, OnInit { this.onEditCipher.emit(this.cipher); } + clone() { + this.onCloneCipher.emit(this.cipher); + } + togglePassword() { this.platformUtilsService.eventTrack('Toggled Password'); this.showPassword = !this.showPassword;