mirror of
https://github.com/bitwarden/browser
synced 2024-12-27 02:14:24 +01:00
load cipher from state
This commit is contained in:
parent
2c87f12718
commit
4f79addb8a
@ -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<CipherView>('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();
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user