1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-13 01:58:44 +02:00

load cipher from state

This commit is contained in:
Kyle Spearrin 2018-04-09 17:35:56 -04:00
parent 2c87f12718
commit 4f79addb8a
2 changed files with 22 additions and 24 deletions

View File

@ -17,6 +17,7 @@ import { CipherService } from '../../abstractions/cipher.service';
import { FolderService } from '../../abstractions/folder.service'; import { FolderService } from '../../abstractions/folder.service';
import { I18nService } from '../../abstractions/i18n.service'; import { I18nService } from '../../abstractions/i18n.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
import { StateService } from '../../abstractions/state.service';
import { CardView } from '../../models/view/cardView'; import { CardView } from '../../models/view/cardView';
import { CipherView } from '../../models/view/cipherView'; import { CipherView } from '../../models/view/cipherView';
@ -58,7 +59,7 @@ export class AddEditComponent {
constructor(protected cipherService: CipherService, protected folderService: FolderService, constructor(protected cipherService: CipherService, protected folderService: FolderService,
protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
protected analytics: Angulartics2, protected toasterService: ToasterService, protected analytics: Angulartics2, protected toasterService: ToasterService,
protected auditService: AuditService) { protected auditService: AuditService, protected stateService: StateService) {
this.typeOptions = [ this.typeOptions = [
{ name: i18nService.t('typeLogin'), value: CipherType.Login }, { name: i18nService.t('typeLogin'), value: CipherType.Login },
{ name: i18nService.t('typeCard'), value: CipherType.Card }, { name: i18nService.t('typeCard'), value: CipherType.Card },
@ -117,23 +118,30 @@ export class AddEditComponent {
async load() { async load() {
this.editMode = this.cipherId != null; this.editMode = this.cipherId != null;
if (this.editMode) { if (this.editMode) {
this.editMode = true; this.editMode = true;
this.title = this.i18nService.t('editItem'); this.title = this.i18nService.t('editItem');
const cipher = await this.cipherService.get(this.cipherId);
this.cipher = await cipher.decrypt();
} else { } else {
this.title = this.i18nService.t('addItem'); 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 = await this.stateService.get<CipherView>('addEditCipher');
this.cipher.login = new LoginView(); await this.stateService.remove('addEditCipher');
this.cipher.login.uris = [new LoginUriView()]; if (this.cipher == null) {
this.cipher.card = new CardView(); if (this.editMode) {
this.cipher.identity = new IdentityView(); const cipher = await this.cipherService.get(this.cipherId);
this.cipher.secureNote = new SecureNoteView(); this.cipher = await cipher.decrypt();
this.cipher.secureNote.type = SecureNoteType.Generic; } 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(); this.folders = await this.folderService.getAllDecrypted();

View File

@ -2,10 +2,8 @@ import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { import {
ChangeDetectorRef,
EventEmitter, EventEmitter,
Input, Input,
NgZone,
OnInit, OnInit,
Output, Output,
} from '@angular/core'; } from '@angular/core';
@ -25,8 +23,7 @@ export class PasswordGeneratorComponent implements OnInit {
constructor(protected passwordGenerationService: PasswordGenerationService, protected analytics: Angulartics2, constructor(protected passwordGenerationService: PasswordGenerationService, protected analytics: Angulartics2,
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
protected toasterService: ToasterService, protected ngZone: NgZone, protected toasterService: ToasterService) { }
protected changeDetectorRef: ChangeDetectorRef) { }
async ngOnInit() { async ngOnInit() {
this.options = await this.passwordGenerationService.getOptions(); this.options = await this.passwordGenerationService.getOptions();
@ -116,11 +113,4 @@ export class PasswordGeneratorComponent implements OnInit {
this.options.minSpecial = this.options.length - this.options.minNumber; this.options.minSpecial = this.options.length - this.options.minNumber;
} }
} }
private functionWithChangeDetection(func: Function) {
this.ngZone.run(async () => {
func();
this.changeDetectorRef.detectChanges();
});
}
} }