From b8383ad5d950ebaf39d039710634a9798cb793a5 Mon Sep 17 00:00:00 2001 From: Elias Papavasileiou Date: Sat, 7 Mar 2020 16:59:17 +0200 Subject: [PATCH] Cleanup and refactor methods --- src/app/vault/vault.component.ts | 6 +---- src/app/vault/view.component.ts | 38 +++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index b5361bb5..a81036dc 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -44,11 +44,8 @@ import { EventService } from 'jslib/abstractions/event.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; -import { StorageService } from 'jslib/abstractions/storage.service'; import { SyncService } from 'jslib/abstractions/sync.service'; -import { ElectronConstants } from 'jslib/electron/electronConstants'; - const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours const BroadcasterSubscriptionId = 'VaultComponent'; @@ -87,8 +84,7 @@ export class VaultComponent implements OnInit, OnDestroy { private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef, private ngZone: NgZone, private syncService: SyncService, private analytics: Angulartics2, private toasterService: ToasterService, private messagingService: MessagingService, - private platformUtilsService: PlatformUtilsService, private eventService: EventService, - private storageService: StorageService) { } + private platformUtilsService: PlatformUtilsService, private eventService: EventService) { } async ngOnInit() { this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => { diff --git a/src/app/vault/view.component.ts b/src/app/vault/view.component.ts index 2a913c29..b06ef08e 100644 --- a/src/app/vault/view.component.ts +++ b/src/app/vault/view.component.ts @@ -7,6 +7,8 @@ import { Output, } from '@angular/core'; +import { EventType } from 'jslib/enums/eventType'; + import { AuditService } from 'jslib/abstractions/audit.service'; import { CipherService } from 'jslib/abstractions/cipher.service'; import { CryptoService } from 'jslib/abstractions/crypto.service'; @@ -25,6 +27,8 @@ import { ViewComponent as BaseViewComponent } from 'jslib/angular/components/vie import { CipherView } from 'jslib/models/view/cipherView'; +import { ElectronConstants } from 'jslib/electron/electronConstants'; + @Component({ selector: 'app-vault-view', templateUrl: 'view.component.html', @@ -38,10 +42,9 @@ export class ViewComponent extends BaseViewComponent implements OnChanges { auditService: AuditService, broadcasterService: BroadcasterService, ngZone: NgZone, changeDetectorRef: ChangeDetectorRef, userService: UserService, eventService: EventService, - messagingService: MessagingService, storageService: StorageService) { + protected messagingService: MessagingService, protected storageService: StorageService) { super(cipherService, totpService, tokenService, i18nService, cryptoService, platformUtilsService, - auditService, window, broadcasterService, ngZone, changeDetectorRef, userService, eventService, - messagingService, storageService); + auditService, window, broadcasterService, ngZone, changeDetectorRef, userService, eventService); } async ngOnChanges() { @@ -52,4 +55,33 @@ export class ViewComponent extends BaseViewComponent implements OnChanges { this.platformUtilsService.eventTrack('View Password History'); this.onViewCipherPasswordHistory.emit(this.cipher); } + + copy(value: string, typeI18nKey: string, aType: string) { + if (value == null) { + return; + } + + this.platformUtilsService.eventTrack('Copied ' + aType); + const copyOptions = this.win != null ? { window: this.win } : null; + this.platformUtilsService.copyToClipboard(value, copyOptions); + this.platformUtilsService.showToast('info', null, + this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey))); + this.minimizeIfNeeded(); + + if (typeI18nKey === 'password') { + this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, this.cipherId); + } else if (typeI18nKey === 'securityCode') { + this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, this.cipherId); + } else if (aType === 'H_Field') { + this.eventService.collect(EventType.Cipher_ClientCopiedHiddenField, this.cipherId); + } + } + + public async minimizeIfNeeded(): Promise { + const shouldMinimize = + await this.storageService.get(ElectronConstants.minimizeOnCopyToClipboardKey); + if (shouldMinimize) { + this.messagingService.send('minimize'); + } + } }