From 4f79addb8a05fd829c4aebc5999e1cf9ba510410 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 9 Apr 2018 17:35:56 -0400 Subject: [PATCH] load cipher from state --- src/angular/components/add-edit.component.ts | 34 ++++++++++++------- .../password-generator.component.ts | 12 +------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/angular/components/add-edit.component.ts b/src/angular/components/add-edit.component.ts index 91ad981176..f0681f7b0c 100644 --- a/src/angular/components/add-edit.component.ts +++ b/src/angular/components/add-edit.component.ts @@ -17,6 +17,7 @@ import { CipherService } from '../../abstractions/cipher.service'; import { FolderService } from '../../abstractions/folder.service'; import { I18nService } from '../../abstractions/i18n.service'; import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; +import { StateService } from '../../abstractions/state.service'; import { CardView } from '../../models/view/cardView'; import { CipherView } from '../../models/view/cipherView'; @@ -58,7 +59,7 @@ export class AddEditComponent { constructor(protected cipherService: CipherService, protected folderService: FolderService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected analytics: Angulartics2, protected toasterService: ToasterService, - protected auditService: AuditService) { + protected auditService: AuditService, protected stateService: StateService) { this.typeOptions = [ { name: i18nService.t('typeLogin'), value: CipherType.Login }, { name: i18nService.t('typeCard'), value: CipherType.Card }, @@ -117,23 +118,30 @@ export class AddEditComponent { async load() { this.editMode = this.cipherId != null; - if (this.editMode) { this.editMode = true; this.title = this.i18nService.t('editItem'); - const cipher = await this.cipherService.get(this.cipherId); - this.cipher = await cipher.decrypt(); } else { this.title = this.i18nService.t('addItem'); - this.cipher = new CipherView(); - this.cipher.folderId = this.folderId; - this.cipher.type = this.type == null ? CipherType.Login : this.type; - this.cipher.login = new LoginView(); - this.cipher.login.uris = [new LoginUriView()]; - this.cipher.card = new CardView(); - this.cipher.identity = new IdentityView(); - this.cipher.secureNote = new SecureNoteView(); - this.cipher.secureNote.type = SecureNoteType.Generic; + } + + this.cipher = await this.stateService.get('addEditCipher'); + await this.stateService.remove('addEditCipher'); + if (this.cipher == null) { + if (this.editMode) { + const cipher = await this.cipherService.get(this.cipherId); + this.cipher = await cipher.decrypt(); + } else { + this.cipher = new CipherView(); + this.cipher.folderId = this.folderId; + this.cipher.type = this.type == null ? CipherType.Login : this.type; + this.cipher.login = new LoginView(); + this.cipher.login.uris = [new LoginUriView()]; + this.cipher.card = new CardView(); + this.cipher.identity = new IdentityView(); + this.cipher.secureNote = new SecureNoteView(); + this.cipher.secureNote.type = SecureNoteType.Generic; + } } this.folders = await this.folderService.getAllDecrypted(); diff --git a/src/angular/components/password-generator.component.ts b/src/angular/components/password-generator.component.ts index 4bd133ff00..7ca52070e0 100644 --- a/src/angular/components/password-generator.component.ts +++ b/src/angular/components/password-generator.component.ts @@ -2,10 +2,8 @@ import { ToasterService } from 'angular2-toaster'; import { Angulartics2 } from 'angulartics2'; import { - ChangeDetectorRef, EventEmitter, Input, - NgZone, OnInit, Output, } from '@angular/core'; @@ -25,8 +23,7 @@ export class PasswordGeneratorComponent implements OnInit { constructor(protected passwordGenerationService: PasswordGenerationService, protected analytics: Angulartics2, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, - protected toasterService: ToasterService, protected ngZone: NgZone, - protected changeDetectorRef: ChangeDetectorRef) { } + protected toasterService: ToasterService) { } async ngOnInit() { this.options = await this.passwordGenerationService.getOptions(); @@ -116,11 +113,4 @@ export class PasswordGeneratorComponent implements OnInit { this.options.minSpecial = this.options.length - this.options.minNumber; } } - - private functionWithChangeDetection(func: Function) { - this.ngZone.run(async () => { - func(); - this.changeDetectorRef.detectChanges(); - }); - } }